All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Francisco Jerez <currojerez@riseup.net>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/4] drm/i915: Flush all user surfaces prior to first use
Date: Tue, 12 Nov 2019 09:38:53 +0000	[thread overview]
Message-ID: <157355153362.9322.13504100342675878774@skylake-alporthouse-com> (raw)
In-Reply-To: <878ssnqid7.fsf@riseup.net>

Quoting Francisco Jerez (2019-07-24 21:37:24)
> Chris Wilson <chris@chris-wilson.co.uk> writes:
> 
> > Since userspace has the ability to bypass the CPU cache from within its
> > unprivileged command stream, we have to flush the CPU cache to memory
> > in order to overwrite the previous contents on creation.
> >
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Cc: stablevger.kernel.org
> > ---
> >  drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 26 ++++++-----------------
> >  1 file changed, 7 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> > index d2a1158868e7..f752b326d399 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> > @@ -459,7 +459,6 @@ i915_gem_object_create_shmem(struct drm_i915_private *i915, u64 size)
> >  {
> >       struct drm_i915_gem_object *obj;
> >       struct address_space *mapping;
> > -     unsigned int cache_level;
> >       gfp_t mask;
> >       int ret;
> >  
> > @@ -498,24 +497,13 @@ i915_gem_object_create_shmem(struct drm_i915_private *i915, u64 size)
> >       obj->write_domain = I915_GEM_DOMAIN_CPU;
> >       obj->read_domains = I915_GEM_DOMAIN_CPU;
> >  
> > -     if (HAS_LLC(i915))
> > -             /* On some devices, we can have the GPU use the LLC (the CPU
> > -              * cache) for about a 10% performance improvement
> > -              * compared to uncached.  Graphics requests other than
> > -              * display scanout are coherent with the CPU in
> > -              * accessing this cache.  This means in this mode we
> > -              * don't need to clflush on the CPU side, and on the
> > -              * GPU side we only need to flush internal caches to
> > -              * get data visible to the CPU.
> > -              *
> > -              * However, we maintain the display planes as UC, and so
> > -              * need to rebind when first used as such.
> > -              */
> > -             cache_level = I915_CACHE_LLC;
> > -     else
> > -             cache_level = I915_CACHE_NONE;
> > -
> > -     i915_gem_object_set_cache_coherency(obj, cache_level);
> > +     /*
> > +      * Note that userspace has control over cache-bypass
> > +      * via its command stream, so even on LLC architectures
> > +      * we have to flush out the CPU cache to memory to
> > +      * clear previous contents.
> > +      */
> > +     i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
> >  
> 
> I'm not sure if you've seen my comments about this in an internal thread
> you were CC'ed to: I don't think this patch will have the intended
> effect.  The various clflushes this could trigger before the first use
> of the buffer are conditional on "obj->cache_dirty &
> ~obj->cache_coherent", which will always be false on LLC platforms
> AFAICT, because on those platforms i915_gem_object_set_cache_coherency()
> will always set bit 0 of obj->cache_coherent.

You only need to flush the stale written-to cachelines, so that the page
content is correct on reuse of the foreign struct page. After that point,
the CPU cache is managed by the client.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Francisco Jerez <currojerez@riseup.net>, intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/i915: Flush all user surfaces prior to first use
Date: Tue, 12 Nov 2019 09:38:53 +0000	[thread overview]
Message-ID: <157355153362.9322.13504100342675878774@skylake-alporthouse-com> (raw)
Message-ID: <20191112093853.gXZpXlyq7gGqWKtgWmnDxH6xsXd9rxLWTqeowgV3hTE@z> (raw)
In-Reply-To: <878ssnqid7.fsf@riseup.net>

Quoting Francisco Jerez (2019-07-24 21:37:24)
> Chris Wilson <chris@chris-wilson.co.uk> writes:
> 
> > Since userspace has the ability to bypass the CPU cache from within its
> > unprivileged command stream, we have to flush the CPU cache to memory
> > in order to overwrite the previous contents on creation.
> >
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Cc: stablevger.kernel.org
> > ---
> >  drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 26 ++++++-----------------
> >  1 file changed, 7 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> > index d2a1158868e7..f752b326d399 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
> > @@ -459,7 +459,6 @@ i915_gem_object_create_shmem(struct drm_i915_private *i915, u64 size)
> >  {
> >       struct drm_i915_gem_object *obj;
> >       struct address_space *mapping;
> > -     unsigned int cache_level;
> >       gfp_t mask;
> >       int ret;
> >  
> > @@ -498,24 +497,13 @@ i915_gem_object_create_shmem(struct drm_i915_private *i915, u64 size)
> >       obj->write_domain = I915_GEM_DOMAIN_CPU;
> >       obj->read_domains = I915_GEM_DOMAIN_CPU;
> >  
> > -     if (HAS_LLC(i915))
> > -             /* On some devices, we can have the GPU use the LLC (the CPU
> > -              * cache) for about a 10% performance improvement
> > -              * compared to uncached.  Graphics requests other than
> > -              * display scanout are coherent with the CPU in
> > -              * accessing this cache.  This means in this mode we
> > -              * don't need to clflush on the CPU side, and on the
> > -              * GPU side we only need to flush internal caches to
> > -              * get data visible to the CPU.
> > -              *
> > -              * However, we maintain the display planes as UC, and so
> > -              * need to rebind when first used as such.
> > -              */
> > -             cache_level = I915_CACHE_LLC;
> > -     else
> > -             cache_level = I915_CACHE_NONE;
> > -
> > -     i915_gem_object_set_cache_coherency(obj, cache_level);
> > +     /*
> > +      * Note that userspace has control over cache-bypass
> > +      * via its command stream, so even on LLC architectures
> > +      * we have to flush out the CPU cache to memory to
> > +      * clear previous contents.
> > +      */
> > +     i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
> >  
> 
> I'm not sure if you've seen my comments about this in an internal thread
> you were CC'ed to: I don't think this patch will have the intended
> effect.  The various clflushes this could trigger before the first use
> of the buffer are conditional on "obj->cache_dirty &
> ~obj->cache_coherent", which will always be false on LLC platforms
> AFAICT, because on those platforms i915_gem_object_set_cache_coherency()
> will always set bit 0 of obj->cache_coherent.

You only need to flush the stale written-to cachelines, so that the page
content is correct on reuse of the foreign struct page. After that point,
the CPU cache is managed by the client.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-11-12  9:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-18 14:54 [PATCH 1/4] drm/i915: Drop wmb() inside pread_gtt Chris Wilson
2019-07-18 14:54 ` [PATCH 2/4] drm/i915: Use maximum write flush for pwrite_gtt Chris Wilson
2019-07-18 18:28   ` Ville Syrjälä
2019-07-18 19:19     ` Chris Wilson
2019-07-19  0:45   ` Sasha Levin
2019-07-18 14:54 ` [PATCH 3/4] drm/i915: Flush all user surfaces prior to first use Chris Wilson
2019-07-19 10:01   ` Joonas Lahtinen
2019-07-19 10:18   ` Lionel Landwerlin
2019-07-19 10:21     ` Chris Wilson
2019-07-19 22:55       ` Jason Ekstrand
2019-07-20 10:49         ` Chris Wilson
2019-07-24 20:37   ` Francisco Jerez
2019-11-12  9:38     ` Chris Wilson [this message]
2019-11-12  9:38       ` [Intel-gfx] " Chris Wilson
2019-11-12 19:58       ` Francisco Jerez
2019-11-12 19:58         ` [Intel-gfx] " Francisco Jerez
2019-07-18 14:54 ` [PATCH 4/4] drm/i915: Flush stale cachelines on set-cache-level Chris Wilson
2019-07-19 10:03   ` Joonas Lahtinen
2019-07-19 10:03     ` Joonas Lahtinen
2019-11-12  9:09   ` [Intel-gfx] " Daniel Vetter
2019-11-12  9:09     ` Daniel Vetter
2019-11-12  9:09     ` Daniel Vetter
2019-11-12  9:42     ` Chris Wilson
2019-11-12  9:42       ` Chris Wilson
2019-11-12 10:57       ` Daniel Vetter
2019-11-12 10:57         ` Daniel Vetter
2019-11-12 12:08         ` Daniel Vetter
2019-11-12 12:08           ` Daniel Vetter
2019-07-18 15:35 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [1/4] drm/i915: Drop wmb() inside pread_gtt Patchwork
2019-07-18 16:22 ` ✓ Fi.CI.BAT: success " Patchwork
2019-07-18 17:29 ` ✓ Fi.CI.IGT: " Patchwork
2019-07-18 18:23 ` [PATCH 1/4] " Ville Syrjälä

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=157355153362.9322.13504100342675878774@skylake-alporthouse-com \
    --to=chris@chris-wilson.co.uk \
    --cc=currojerez@riseup.net \
    --cc=intel-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.