From: "Michel Dänzer" <michel@daenzer.net>
To: amd-gfx@lists.freedesktop.org
Cc: Emil Velikov <emil.l.velikov@gmail.com>, dri-devel@lists.freedesktop.org
Subject: [PATCH libdrm 7/9] amdgpu: Use normal integers for device / core BO reference counting
Date: Mon, 24 Jun 2019 18:54:04 +0200 [thread overview]
Message-ID: <20190624165406.13682-8-michel@daenzer.net> (raw)
In-Reply-To: <20190624165406.13682-1-michel@daenzer.net>
From: Michel Dänzer <michel.daenzer@amd.com>
The dev_mutex / dev->bo_table_mutex is always locked when accessing the
reference counts, so no need for atomic operations.
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
---
amdgpu/amdgpu_bo.c | 6 +++---
amdgpu/amdgpu_device.c | 18 ++++++++++--------
amdgpu/amdgpu_internal.h | 6 +++---
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 8d42db90..f40df484 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -65,7 +65,7 @@ static int amdgpu_core_bo_create(struct amdgpu_core_device *dev,
return r;
}
- atomic_set(&bo->refcount, 1);
+ bo->refcount = 1;
bo->alloc_size = size;
bo->handle = handle;
pthread_mutex_init(&bo->cpu_access_mutex, NULL);
@@ -95,7 +95,7 @@ static int amdgpu_bo_create(amdgpu_device_handle user_dev,
goto out;
}
}
- atomic_inc(&bo->refcount);
+ bo->refcount++;
} else {
r = amdgpu_core_bo_create(dev, size, handle, &bo);
if (r)
@@ -467,7 +467,7 @@ static void amdgpu_core_bo_free(struct amdgpu_bo *user_bo)
struct amdgpu_core_device *dev = user_bo->dev->core;
struct amdgpu_core_bo *bo = user_bo->core;
- if (update_references(&bo->refcount, NULL)) {
+ if (--bo->refcount == 0) {
/* Remove the buffer from the hash tables. */
handle_table_remove(&dev->bo_handles, bo->handle);
diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c
index 8d9a85c2..8a99b8bb 100644
--- a/amdgpu/amdgpu_device.c
+++ b/amdgpu/amdgpu_device.c
@@ -72,6 +72,9 @@ static int fd_compare(int fd1, int fd2)
static void amdgpu_device_free(struct amdgpu_core_device *dev)
{
+ if (--dev->refcount > 0)
+ return;
+
close(dev->fd);
amdgpu_vamgr_deinit(&dev->vamgr_32);
@@ -112,7 +115,7 @@ static int amdgpu_device_init(amdgpu_device_handle user_dev)
break;
if (dev_iter) {
- atomic_inc(&dev_iter->core->refcount);
+ dev_iter->core->refcount++;
user_dev->core = dev_iter->core;
return 0;
}
@@ -123,7 +126,7 @@ static int amdgpu_device_init(amdgpu_device_handle user_dev)
return -ENOMEM;
}
- atomic_set(&dev->refcount, 1);
+ dev->refcount = 1;
pthread_mutex_init(&dev->bo_table_mutex, NULL);
dev->fd = user_dev->user_fd;
@@ -199,7 +202,7 @@ drm_public int amdgpu_device_initialize(int fd,
for (user_dev = dev_list; user_dev; user_dev = user_dev->next) {
if (same_file_description(user_dev->user_fd, fd)) {
- atomic_inc(&user_dev->refcount);
+ user_dev->refcount++;
goto out;
}
}
@@ -233,7 +236,7 @@ drm_public int amdgpu_device_initialize(int fd,
goto cleanup;
}
- atomic_set(&user_dev->refcount, 1);
+ user_dev->refcount = 1;
user_dev->next = dev_list;
dev_list = user_dev;
@@ -248,7 +251,7 @@ out:
cleanup:
if (!user_dev->core || user_dev->user_fd != user_dev->core->fd)
close(user_dev->user_fd);
- if (user_dev->core && update_references(&user_dev->core->refcount, NULL))
+ if (user_dev->core)
amdgpu_device_free(user_dev->core);
free(user_dev);
pthread_mutex_unlock(&dev_mutex);
@@ -261,7 +264,7 @@ drm_public int amdgpu_device_deinitialize(amdgpu_device_handle user_dev)
pthread_mutex_lock(&dev_mutex);
- if (update_references(&user_dev->refcount, NULL)) {
+ if (--user_dev->refcount == 0) {
struct amdgpu_device **node = &dev_list;
while (*node != user_dev && (*node)->next)
@@ -271,8 +274,7 @@ drm_public int amdgpu_device_deinitialize(amdgpu_device_handle user_dev)
if (user_dev->user_fd != dev->fd)
close(user_dev->user_fd);
- if (update_references(&dev->refcount, NULL))
- amdgpu_device_free(dev);
+ amdgpu_device_free(dev);
free(user_dev);
}
diff --git a/amdgpu/amdgpu_internal.h b/amdgpu/amdgpu_internal.h
index 686d50ec..70566f98 100644
--- a/amdgpu/amdgpu_internal.h
+++ b/amdgpu/amdgpu_internal.h
@@ -65,7 +65,7 @@ struct amdgpu_va {
};
struct amdgpu_core_device {
- atomic_t refcount;
+ int refcount;
int fd;
unsigned major_version;
unsigned minor_version;
@@ -90,14 +90,14 @@ struct amdgpu_core_device {
};
struct amdgpu_device {
- atomic_t refcount;
+ int refcount;
int user_fd;
struct amdgpu_core_device *core;
struct amdgpu_device *next;
};
struct amdgpu_core_bo {
- atomic_t refcount;
+ int refcount;
amdgpu_bo_handle user_bos;
uint64_t alloc_size;
--
2.20.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-06-24 16:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-24 16:53 [PATCH libdrm 0/9] amdgpu: Michel Dänzer
[not found] ` <20190624165406.13682-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
2019-06-24 16:53 ` [PATCH libdrm 1/9] amdgpu: Pass file descriptor directly to amdgpu_close_kms_handle Michel Dänzer
2019-06-28 17:11 ` Emil Velikov
2019-06-24 16:53 ` [PATCH libdrm 2/9] amdgpu: Add BO handle to table in amdgpu_bo_create Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 3/9] amdgpu: Rename fd_mutex/list to dev_mutex/list Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 8/9] amdgpu: Drop refcount member from struct amdgpu_core_bo/device Michel Dänzer
2019-06-24 16:54 ` [PATCH mesa 9/9] winsys/amdgpu: Use amdgpu_bo_handle_type_kms_user for API KMS handles Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 4/9] amdgpu: Add struct amdgpu_core_device and amdgpu_core_bo Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 5/9] amdgpu: Add amdgpu_bo_handle_type_kms_user Michel Dänzer
2019-06-24 16:54 ` [PATCH libdrm 6/9] amdgpu: Re-use an existing amdgpu_device when possible Michel Dänzer
2019-06-24 16:54 ` Michel Dänzer [this message]
2019-06-24 17:31 ` [PATCH libdrm 0/9] amdgpu: Christian König
[not found] ` <b48aae10-c1db-b76b-ddde-9c0a47028633-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-06-25 8:02 ` Michel Dänzer
2019-06-25 9:44 ` Koenig, Christian
[not found] ` <78d5a7c1-8534-7917-58bc-1827dff106c8-5C7GfCeVMHo@public.gmane.org>
2019-06-25 10:07 ` Michel Dänzer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190624165406.13682-8-michel@daenzer.net \
--to=michel@daenzer.net \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox