From: Jordan Crouse <jcrouse@codeaurora.org>
To: freedreno@lists.freedesktop.org
Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: [PATCH 09/11] drm/msm: Shadow current pointer in the ring until command is complete
Date: Mon, 6 Feb 2017 10:39:37 -0700 [thread overview]
Message-ID: <1486402779-9024-10-git-send-email-jcrouse@codeaurora.org> (raw)
In-Reply-To: <1486402779-9024-1-git-send-email-jcrouse@codeaurora.org>
Add a shadow pointer to track the current command being written into
the ring. Don't commit it as 'cur' until the command is submitted.
Because 'cur' is used to construct the software copy of the wptr this
ensures that somebody peeking in on the ring doesn't assume that a
command is inflight while it is being written. This isn't a huge deal
with a single ring (though technically the hangcheck could assume
the system is prematurely busy when it isn't) but it will be rather
important for preemption where the decision to preempt is based
on a non-empty ringbuffer. Without a shadow an aggressive preemption
scheme could assume that the ringbuffer is non empty and switch to it
before the CPU is done writing the command and boom.
Even though preemption won't be supported for all targets because of
the way the code is organized it is simpler to make this generic for
all targets. The extra load for non-preemption targets should be
minimal.
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
---
drivers/gpu/drm/msm/adreno/adreno_gpu.c | 9 +++++++--
drivers/gpu/drm/msm/msm_ringbuffer.c | 1 +
drivers/gpu/drm/msm/msm_ringbuffer.h | 12 ++++++++----
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
index f5c2bad..44a95ea 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
@@ -144,6 +144,7 @@ void adreno_recover(struct msm_gpu *gpu)
continue;
ring->cur = ring->start;
+ ring->next = ring->start;
/* reset completed fence seqno, discard anything pending: */
adreno_gpu->memptrs->fence[ring->id] = ring->completed_fence;
@@ -240,12 +241,15 @@ void adreno_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
uint32_t wptr;
+ /* Copy the shadow to the actual register */
+ ring->cur = ring->next;
+
/*
* Mask wptr value that we calculate to fit in the HW range. This is
* to account for the possibility that the last command fit exactly into
* the ringbuffer and rb->next hasn't wrapped to zero yet
*/
- wptr = get_wptr(ring) % (MSM_GPU_RINGBUFFER_SZ >> 2);
+ wptr = (ring->cur - ring->start) % (MSM_GPU_RINGBUFFER_SZ >> 2);
/* ensure writes to ringbuffer have hit system memory: */
mb();
@@ -366,7 +370,8 @@ static uint32_t ring_freewords(struct msm_ringbuffer *ring)
{
struct adreno_gpu *adreno_gpu = to_adreno_gpu(ring->gpu);
uint32_t size = MSM_GPU_RINGBUFFER_SZ >> 2;
- uint32_t wptr = get_wptr(ring);
+ /* Use ring->next to calculate free size */
+ uint32_t wptr = ring->next - ring->start;
uint32_t rptr = get_rptr(adreno_gpu, ring);
return (rptr + (size - 1) - wptr) % size;
}
diff --git a/drivers/gpu/drm/msm/msm_ringbuffer.c b/drivers/gpu/drm/msm/msm_ringbuffer.c
index 2ab31c7..b885979 100644
--- a/drivers/gpu/drm/msm/msm_ringbuffer.c
+++ b/drivers/gpu/drm/msm/msm_ringbuffer.c
@@ -47,6 +47,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id)
goto fail;
}
ring->end = ring->start + (MSM_GPU_RINGBUFFER_SZ >> 2);
+ ring->next = ring->start;
ring->cur = ring->start;
return ring;
diff --git a/drivers/gpu/drm/msm/msm_ringbuffer.h b/drivers/gpu/drm/msm/msm_ringbuffer.h
index 4eb05fe..865b21a 100644
--- a/drivers/gpu/drm/msm/msm_ringbuffer.h
+++ b/drivers/gpu/drm/msm/msm_ringbuffer.h
@@ -24,7 +24,7 @@ struct msm_ringbuffer {
struct msm_gpu *gpu;
int id;
struct drm_gem_object *bo;
- uint32_t *start, *end, *cur;
+ uint32_t *start, *end, *cur, *next;
uint64_t iova;
/* last_fence == completed_fence --> no pending work */
uint32_t last_fence;
@@ -39,9 +39,13 @@ struct msm_ringbuffer {
static inline void
OUT_RING(struct msm_ringbuffer *ring, uint32_t data)
{
- if (ring->cur == ring->end)
- ring->cur = ring->start;
- *(ring->cur++) = data;
+ /*
+ * ring->next points to the current command being written - it won't be
+ * committed as ring->cur until the flush
+ */
+ if (ring->next == ring->end)
+ ring->next = ring->start;
+ *(ring->next++) = data;
}
#endif /* __MSM_RINGBUFFER_H__ */
--
1.9.1
next prev parent reply other threads:[~2017-02-06 17:39 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-06 17:39 [PATCH 00/11] drm/msm: A5XX preemption Jordan Crouse
2017-02-06 17:39 ` [PATCH 03/11] drm/msm: Add hint to DRM_IOCTL_MSM_GEM_INFO to return an object IOVA Jordan Crouse
2017-02-06 19:20 ` Emil Velikov
[not found] ` <CACvgo513+d19O2rzZ8NXEFgojUQkm2XPae-AdOXXReLM_a1euw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-06 19:57 ` Rob Clark
[not found] ` <CAF6AEGvUoW2695_HjgfGbpbPaSnOB2gfPa=3UMTDGvom+DxcwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-06 20:24 ` Emil Velikov
2017-02-06 21:01 ` Rob Clark
2017-02-06 17:39 ` [PATCH 04/11] drm/msm: Remove idle function hook Jordan Crouse
2017-02-06 17:39 ` [PATCH 05/11] drm/msm: get an iova from the address space instead of an id Jordan Crouse
2017-02-09 5:01 ` Archit Taneja
2017-02-06 17:39 ` [PATCH 06/11] drm/msm: Add a struct to pass configuration to msm_gpu_init() Jordan Crouse
2017-02-06 17:39 ` [PATCH 07/11] drm/msm: Remove memptrs->wptr Jordan Crouse
2017-02-06 17:39 ` [PATCH 08/11] drm/msm: Support multiple ringbuffers Jordan Crouse
2017-02-06 17:39 ` Jordan Crouse [this message]
2017-02-06 17:39 ` [PATCH 10/11] drm/msm: Make the value of RB_CNTL (almost) generic Jordan Crouse
2017-02-06 17:39 ` [PATCH 11/11] drm/msm: Implement preemption for A5XX targets Jordan Crouse
[not found] ` <1486402779-9024-12-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-02-08 20:30 ` Stephen Boyd
[not found] ` <8696f3b7-1fbd-309a-1d68-b2f8ad89a30c-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-02-08 23:00 ` Jordan Crouse
2017-02-09 0:03 ` Stephen Boyd
2017-02-06 17:59 ` [PATCH 00/11] drm/msm: A5XX preemption Daniel Vetter
2017-02-06 18:23 ` Daniel Stone
2017-02-06 18:29 ` [Intel-gfx] " Rob Clark
2017-02-06 18:29 ` Alex Deucher
[not found] ` <1486402779-9024-1-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-02-06 17:39 ` [PATCH 01/11] drm/msm: Make sure to detach the MMU during GPU cleanup Jordan Crouse
2017-02-06 17:39 ` [PATCH 02/11] drm/msm: Improve the zap shader Jordan Crouse
2017-03-07 16:58 ` [v2] [PATCH 00/11] drm/msm: A5XX preemption Jordan Crouse
2017-03-07 16:58 ` [PATCH 01/11] drm/msm: Make sure to detach the MMU during GPU cleanup Jordan Crouse
[not found] ` <1488905900-6603-1-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-03-07 16:58 ` [PATCH 02/11] drm/msm: Improve the zap shader Jordan Crouse
2017-03-07 16:58 ` [PATCH 03/11] drm/msm: Remove idle function hook Jordan Crouse
2017-03-07 16:58 ` [PATCH 04/11] drm/msm: Add hint to DRM_IOCTL_MSM_GEM_INFO to return an object IOVA Jordan Crouse
2017-03-07 16:58 ` [PATCH 05/11] drm/msm: get an iova from the address space instead of an id Jordan Crouse
2017-03-07 16:58 ` [PATCH 06/11] drm/msm: Add a struct to pass configuration to msm_gpu_init() Jordan Crouse
2017-03-07 16:58 ` [PATCH 07/11] drm/msm: Remove memptrs->wptr Jordan Crouse
2017-03-07 16:58 ` [PATCH 08/11] drm/msm: Support multiple ringbuffers Jordan Crouse
2017-03-07 16:58 ` [PATCH 09/11] drm/msm: Shadow current pointer in the ring until command is complete Jordan Crouse
2017-03-07 16:58 ` [PATCH 10/11] drm/msm: Make the value of RB_CNTL (almost) generic Jordan Crouse
2017-03-07 16:58 ` [PATCH 11/11] drm/msm: Implement preemption for A5XX targets Jordan Crouse
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=1486402779-9024-10-git-send-email-jcrouse@codeaurora.org \
--to=jcrouse@codeaurora.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=linux-arm-msm@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).