public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 4/4] drm/i915: Review the memory barriers around CPU access to buffers
Date: Fri, 19 Oct 2012 21:48:50 +0100	[thread overview]
Message-ID: <b94cdc$716d2n@fmsmga001.fm.intel.com> (raw)
In-Reply-To: <20121011125215.06109af9@jbarnes-desktop>

On Thu, 11 Oct 2012 12:52:15 -0700, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> On Tue,  9 Oct 2012 19:24:40 +0100
> Chris Wilson <chris@chris-wilson.co.uk> wrote:
> 
> > We need to treat the GPU core as a distinct processor and so apply the
> > same SMP memory barriers. In this case, in addition to flushing the
> > chipset cache, which is a no-op on LLC platforms, apply a write barrier
> > beforehand. And then when we invalidate the CPU cache, make sure the
> > memory is coherent (again this was a no-op on LLC platforms).
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> >  drivers/char/agp/intel-gtt.c    |    1 +
> >  drivers/gpu/drm/i915/i915_gem.c |    1 +
> >  2 files changed, 2 insertions(+)
> > 
> > diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
> > index 8b0f6d19..1223128 100644
> > --- a/drivers/char/agp/intel-gtt.c
> > +++ b/drivers/char/agp/intel-gtt.c
> > @@ -1706,6 +1706,7 @@ EXPORT_SYMBOL(intel_gtt_get);
> >  
> >  void intel_gtt_chipset_flush(void)
> >  {
> > +	wmb();
> >  	if (intel_private.driver->chipset_flush)
> >  		intel_private.driver->chipset_flush();
> >  }
> > diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> > index ed8d21a..b1ebb88 100644
> > --- a/drivers/gpu/drm/i915/i915_gem.c
> > +++ b/drivers/gpu/drm/i915/i915_gem.c
> > @@ -3528,6 +3528,7 @@ i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write)
> >  	/* Flush the CPU cache if it's still invalid. */
> >  	if ((obj->base.read_domains & I915_GEM_DOMAIN_CPU) == 0) {
> >  		i915_gem_clflush_object(obj);
> > +		mb(); /* in case the clflush above is optimised away */
> >  
> >  		obj->base.read_domains |= I915_GEM_DOMAIN_CPU;
> >  	}
> 
> These need more comments too.
> 
> I think the first is to make sure any previous loads have completed
> before we start using the new object?  If so, don't we want reads to
> complete first too?

The flush is only used to make sure the writes written from the CPU hit
the cache and/or chipset buffers before we flush them from the chipset
buffer. Userspace is welcome to race read/writes between cores and the
GPU, and there is nothing we can do to prevent that without adopting a
strict coherency model.

Also note that in the past I have proposed this wmb() to fix some
observed incoherency in the cursor sprite: #21442.
 
> The second one looks unnecessary.  If the object isn't in the CPU
> domain, there should be no loads/stores against it right?

Just depends on the programming model between CPU/GPU. The barrier is
there to make sure all the writes into the shared cache from another
core (the gpu in this case) is complete before we begin our reads.
Assuming that the GPU behaves as another core...
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

  reply	other threads:[~2012-10-19 20:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6c3329lntgg@orsmga002.jf.intel.com>
2012-10-09 18:24 ` [PATCH 1/4] drm/i915: Only insert the mb() before updating the fence parameter Chris Wilson
2012-10-09 18:24   ` [PATCH 2/4] drm/i915: Only apply the mb() when flushing the GTT domain during a finish Chris Wilson
2012-10-11 19:43     ` Jesse Barnes
2013-01-19 13:40       ` Daniel Vetter
2012-10-09 18:24   ` [PATCH 3/4] drm/i915: Insert a full mb() before reading the seqno from the status page Chris Wilson
2012-10-11 19:46     ` Jesse Barnes
2012-10-19 20:40       ` Chris Wilson
2012-10-19 20:52         ` Jesse Barnes
2013-01-19 12:02           ` Chris Wilson
2012-10-09 18:24   ` [PATCH 4/4] drm/i915: Review the memory barriers around CPU access to buffers Chris Wilson
2012-10-11 19:52     ` Jesse Barnes
2012-10-19 20:48       ` Chris Wilson [this message]
2012-10-11 20:46     ` Daniel Vetter
2012-10-11 19:41   ` [PATCH 1/4] drm/i915: Only insert the mb() before updating the fence parameter Jesse Barnes

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='b94cdc$716d2n@fmsmga001.fm.intel.com' \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jbarnes@virtuousgeek.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