From: j.glisse@gmail.com
To: dri-devel@lists.freedesktop.org
Cc: "Christian König" <deathsimple@vodafone.de>,
"Jerome Glisse" <jglisse@redhat.com>
Subject: [PATCH 10/18] drm/radeon: define new SA interface v2
Date: Fri, 4 May 2012 18:43:51 -0400 [thread overview]
Message-ID: <1336171439-7672-11-git-send-email-j.glisse@gmail.com> (raw)
In-Reply-To: <1336171439-7672-1-git-send-email-j.glisse@gmail.com>
From: Christian König <deathsimple@vodafone.de>
Define the interface without modifying the allocation
algorithm in any way.
v2: rebase on top of fence new uint64 patch
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Christian König <deathsimple@vodafone.de>
---
drivers/gpu/drm/radeon/radeon.h | 1 +
drivers/gpu/drm/radeon/radeon_gart.c | 6 +-
drivers/gpu/drm/radeon/radeon_object.h | 5 +-
drivers/gpu/drm/radeon/radeon_ring.c | 8 ++--
drivers/gpu/drm/radeon/radeon_sa.c | 60 ++++++++++++++++++++++++----
drivers/gpu/drm/radeon/radeon_semaphore.c | 2 +-
6 files changed, 63 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 3519a52..c78f15b 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -398,6 +398,7 @@ struct radeon_sa_bo {
struct radeon_sa_manager *manager;
unsigned soffset;
unsigned eoffset;
+ struct radeon_fence *fence;
};
/*
diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c
index c5789ef..53dba8e 100644
--- a/drivers/gpu/drm/radeon/radeon_gart.c
+++ b/drivers/gpu/drm/radeon/radeon_gart.c
@@ -326,7 +326,7 @@ static void radeon_vm_unbind_locked(struct radeon_device *rdev,
rdev->vm_manager.use_bitmap &= ~(1 << vm->id);
list_del_init(&vm->list);
vm->id = -1;
- radeon_sa_bo_free(rdev, &vm->sa_bo);
+ radeon_sa_bo_free(rdev, &vm->sa_bo, NULL);
vm->pt = NULL;
list_for_each_entry(bo_va, &vm->va, vm_list) {
@@ -395,7 +395,7 @@ int radeon_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm)
retry:
r = radeon_sa_bo_new(rdev, &rdev->vm_manager.sa_manager, &vm->sa_bo,
RADEON_GPU_PAGE_ALIGN(vm->last_pfn * 8),
- RADEON_GPU_PAGE_SIZE);
+ RADEON_GPU_PAGE_SIZE, false);
if (r) {
if (list_empty(&rdev->vm_manager.lru_vm)) {
return r;
@@ -426,7 +426,7 @@ retry_id:
/* do hw bind */
r = rdev->vm_manager.funcs->bind(rdev, vm, id);
if (r) {
- radeon_sa_bo_free(rdev, &vm->sa_bo);
+ radeon_sa_bo_free(rdev, &vm->sa_bo, NULL);
return r;
}
rdev->vm_manager.use_bitmap |= 1 << id;
diff --git a/drivers/gpu/drm/radeon/radeon_object.h b/drivers/gpu/drm/radeon/radeon_object.h
index 4fc7f07..befec7d 100644
--- a/drivers/gpu/drm/radeon/radeon_object.h
+++ b/drivers/gpu/drm/radeon/radeon_object.h
@@ -169,9 +169,10 @@ extern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
extern int radeon_sa_bo_new(struct radeon_device *rdev,
struct radeon_sa_manager *sa_manager,
struct radeon_sa_bo **sa_bo,
- unsigned size, unsigned align);
+ unsigned size, unsigned align, bool block);
extern void radeon_sa_bo_free(struct radeon_device *rdev,
- struct radeon_sa_bo **sa_bo);
+ struct radeon_sa_bo **sa_bo,
+ struct radeon_fence *fence);
#if defined(CONFIG_DEBUG_FS)
extern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
struct seq_file *m);
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 739554c..c84af9c 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -85,7 +85,7 @@ bool radeon_ib_try_free(struct radeon_device *rdev, struct radeon_ib *ib)
if (ib->fence && ib->fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
if (radeon_fence_signaled(ib->fence)) {
radeon_fence_unref(&ib->fence);
- radeon_sa_bo_free(rdev, &ib->sa_bo);
+ radeon_sa_bo_free(rdev, &ib->sa_bo, NULL);
done = true;
}
}
@@ -124,7 +124,7 @@ retry:
if (rdev->ib_pool.ibs[idx].fence == NULL) {
r = radeon_sa_bo_new(rdev, &rdev->ib_pool.sa_manager,
&rdev->ib_pool.ibs[idx].sa_bo,
- size, 256);
+ size, 256, false);
if (!r) {
*ib = &rdev->ib_pool.ibs[idx];
(*ib)->ptr = radeon_sa_bo_cpu_addr((*ib)->sa_bo);
@@ -173,7 +173,7 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
}
radeon_mutex_lock(&rdev->ib_pool.mutex);
if (tmp->fence && tmp->fence->seq == RADEON_FENCE_NOTEMITED_SEQ) {
- radeon_sa_bo_free(rdev, &tmp->sa_bo);
+ radeon_sa_bo_free(rdev, &tmp->sa_bo, NULL);
radeon_fence_unref(&tmp->fence);
}
radeon_mutex_unlock(&rdev->ib_pool.mutex);
@@ -247,7 +247,7 @@ void radeon_ib_pool_fini(struct radeon_device *rdev)
radeon_mutex_lock(&rdev->ib_pool.mutex);
if (rdev->ib_pool.ready) {
for (i = 0; i < RADEON_IB_POOL_SIZE; i++) {
- radeon_sa_bo_free(rdev, &rdev->ib_pool.ibs[i].sa_bo);
+ radeon_sa_bo_free(rdev, &rdev->ib_pool.ibs[i].sa_bo, NULL);
radeon_fence_unref(&rdev->ib_pool.ibs[i].fence);
}
radeon_sa_bo_manager_fini(rdev, &rdev->ib_pool.sa_manager);
diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c
index 625f2d4..bc4ef87 100644
--- a/drivers/gpu/drm/radeon/radeon_sa.c
+++ b/drivers/gpu/drm/radeon/radeon_sa.c
@@ -129,20 +129,32 @@ int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
*
* Alignment can't be bigger than page size
*/
+
+static void radeon_sa_bo_remove_locked(struct radeon_sa_bo *sa_bo)
+{
+ list_del(&sa_bo->list);
+ radeon_fence_unref(&sa_bo->fence);
+ kfree(sa_bo);
+}
+
int radeon_sa_bo_new(struct radeon_device *rdev,
struct radeon_sa_manager *sa_manager,
struct radeon_sa_bo **sa_bo,
- unsigned size, unsigned align)
+ unsigned size, unsigned align, bool block)
{
- struct radeon_sa_bo *tmp;
+ struct radeon_fence *fence = NULL;
+ struct radeon_sa_bo *tmp, *next;
struct list_head *head;
unsigned offset = 0, wasted = 0;
+ int r;
BUG_ON(align > RADEON_GPU_PAGE_SIZE);
BUG_ON(size > sa_manager->size);
*sa_bo = kmalloc(sizeof(struct radeon_sa_bo), GFP_KERNEL);
+retry:
+
spin_lock(&sa_manager->lock);
/* no one ? */
@@ -153,7 +165,17 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
/* look for a hole big enough */
offset = 0;
- list_for_each_entry(tmp, &sa_manager->sa_bo, list) {
+ list_for_each_entry_safe(tmp, next, &sa_manager->sa_bo, list) {
+ /* try to free this object */
+ if (tmp->fence) {
+ if (radeon_fence_signaled(tmp->fence)) {
+ radeon_sa_bo_remove_locked(tmp);
+ continue;
+ } else {
+ fence = tmp->fence;
+ }
+ }
+
/* room before this object ? */
if (offset < tmp->soffset && (tmp->soffset - offset) >= size) {
head = tmp->list.prev;
@@ -178,6 +200,13 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
if ((sa_manager->size - offset) < size) {
/* failed to find somethings big enough */
spin_unlock(&sa_manager->lock);
+ if (block && fence) {
+ r = radeon_fence_wait(fence, false);
+ if (r)
+ return r;
+
+ goto retry;
+ }
kfree(*sa_bo);
*sa_bo = NULL;
return -ENOMEM;
@@ -192,15 +221,22 @@ out:
return 0;
}
-void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo **sa_bo)
+void radeon_sa_bo_free(struct radeon_device *rdev, struct radeon_sa_bo **sa_bo,
+ struct radeon_fence *fence)
{
+ struct radeon_sa_manager *sa_manager;
+
if (!sa_bo || !*sa_bo)
return;
- spin_lock(&(*sa_bo)->manager->lock);
- list_del_init(&(*sa_bo)->list);
- spin_unlock(&(*sa_bo)->manager->lock);
- kfree(*sa_bo);
+ sa_manager = (*sa_bo)->manager;
+ spin_lock(&sa_manager->lock);
+ if (fence && fence->seq && fence->seq < RADEON_FENCE_NOTEMITED_SEQ) {
+ (*sa_bo)->fence = radeon_fence_ref(fence);
+ } else {
+ radeon_sa_bo_remove_locked(*sa_bo);
+ }
+ spin_unlock(&sa_manager->lock);
*sa_bo = NULL;
}
@@ -212,8 +248,14 @@ void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
spin_lock(&sa_manager->lock);
list_for_each_entry(i, &sa_manager->sa_bo, list) {
- seq_printf(m, "[%08x %08x] size %4d [%p]\n",
+ seq_printf(m, "[%08x %08x] size %4d (%p)",
i->soffset, i->eoffset, i->eoffset - i->soffset, i);
+ if (i->fence) {
+ seq_printf(m, " protected by %Ld (%p)\n",
+ i->fence->seq, i->fence);
+ } else {
+ seq_printf(m, "\n");
+ }
}
spin_unlock(&sa_manager->lock);
}
diff --git a/drivers/gpu/drm/radeon/radeon_semaphore.c b/drivers/gpu/drm/radeon/radeon_semaphore.c
index d518d32..dbde874 100644
--- a/drivers/gpu/drm/radeon/radeon_semaphore.c
+++ b/drivers/gpu/drm/radeon/radeon_semaphore.c
@@ -72,7 +72,7 @@ static int radeon_semaphore_add_bo(struct radeon_device *rdev)
static void radeon_semaphore_del_bo_locked(struct radeon_device *rdev,
struct radeon_semaphore_bo *bo)
{
- radeon_sa_bo_free(rdev, &bo->ib->sa_bo);
+ radeon_sa_bo_free(rdev, &bo->ib->sa_bo, NULL);
radeon_fence_unref(&bo->ib->fence);
list_del(&bo->list);
kfree(bo);
--
1.7.7.6
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2012-05-04 22:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-04 22:43 [RFC] fence, sa allocator, ib pool, semaphore rework j.glisse
2012-05-04 22:43 ` [PATCH 01/18] drm/radeon: replace the per ring mutex with a global one j.glisse
2012-05-04 22:43 ` [PATCH 02/18] drm/radeon: convert fence to uint64_t v3 j.glisse
2012-05-04 22:43 ` [PATCH 03/18] drm/radeon: rework fence handling, drop fence list v5 j.glisse
2012-05-04 22:43 ` [PATCH 04/18] drm/radeon: hold ring emission mutex for lockup detection j.glisse
2012-05-04 22:43 ` [PATCH 05/18] drm/radeon: use inline functions to calc sa_bo addr j.glisse
2012-05-04 22:43 ` [PATCH 06/18] drm/radeon: add proper locking to the SA v3 j.glisse
2012-05-04 22:43 ` [PATCH 07/18] drm/radeon: add sub allocator debugfs file j.glisse
2012-05-04 22:43 ` [PATCH 08/18] drm/radeon: keep start and end offset in the SA j.glisse
2012-05-04 22:43 ` [PATCH 09/18] drm/radeon: make sa bo a stand alone object j.glisse
2012-05-04 22:43 ` j.glisse [this message]
2012-05-04 22:43 ` [PATCH 11/18] drm/radeon: use one wait queue for all rings add fence_wait_any j.glisse
2012-05-04 22:43 ` [PATCH 12/18] drm/radeon: multiple ring allocator j.glisse
2012-05-04 22:43 ` [PATCH 13/18] drm/radeon: simplify semaphore handling v2 j.glisse
2012-05-04 22:43 ` [PATCH 14/18] drm/radeon: rip out the ib pool j.glisse
2012-05-04 22:43 ` [PATCH 15/18] drm/radeon: immediately remove ttm-move semaphore j.glisse
2012-05-04 22:43 ` [PATCH 16/18] drm/radeon: move the semaphore from the fence into the ib j.glisse
2012-05-04 22:43 ` [PATCH 17/18] drm/radeon: remove r600 blit mutex v2 j.glisse
2012-05-04 22:43 ` [PATCH 18/18] drm/radeon: make the ib an inline object j.glisse
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=1336171439-7672-11-git-send-email-j.glisse@gmail.com \
--to=j.glisse@gmail.com \
--cc=deathsimple@vodafone.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=jglisse@redhat.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