All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: Mika Kuoppala <mika.kuoppala@linux.intel.com>,
	intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 1/5] drm/i915: Wrap tasklet_struct for abuse
Date: Wed, 09 May 2018 14:51:56 +0100	[thread overview]
Message-ID: <152587391627.8613.10312136071207898459@mail.alporthouse.com> (raw)
In-Reply-To: <87wowd9c5d.fsf@gaia.fi.intel.com>

Quoting Mika Kuoppala (2018-05-09 14:44:30)
> Chris Wilson <chris@chris-wilson.co.uk> writes:
> 
> > In the next few patches, we want to abuse tasklet to avoid ksoftirqd
> > latency along critical paths. To make that abuse easily to swallow,
> > first coat the tasklet in a little syntactic sugar.
> >
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > ---
> >  drivers/gpu/drm/i915/i915_gem.c             |  8 +--
> >  drivers/gpu/drm/i915/i915_irq.c             |  2 +-
> >  drivers/gpu/drm/i915/i915_tasklet.h         | 78 +++++++++++++++++++++
> >  drivers/gpu/drm/i915/intel_engine_cs.c      | 11 ++-
> >  drivers/gpu/drm/i915/intel_guc_submission.c |  8 +--
> >  drivers/gpu/drm/i915/intel_lrc.c            | 18 ++---
> >  drivers/gpu/drm/i915/intel_ringbuffer.h     |  3 +-
> >  7 files changed, 104 insertions(+), 24 deletions(-)
> >  create mode 100644 drivers/gpu/drm/i915/i915_tasklet.h
> >
> > diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> > index 89bf5d67cb74..98481e150e61 100644
> > --- a/drivers/gpu/drm/i915/i915_gem.c
> > +++ b/drivers/gpu/drm/i915/i915_gem.c
> > @@ -3043,9 +3043,9 @@ i915_gem_reset_prepare_engine(struct intel_engine_cs *engine)
> >        * common case of recursively being called from set-wedged from inside
> >        * i915_reset.
> >        */
> > -     if (!atomic_read(&engine->execlists.tasklet.count))
> > -             tasklet_kill(&engine->execlists.tasklet);
> > -     tasklet_disable(&engine->execlists.tasklet);
> > +     if (i915_tasklet_is_enabled(&engine->execlists.tasklet))
> > +             i915_tasklet_flush(&engine->execlists.tasklet);
> > +     i915_tasklet_disable(&engine->execlists.tasklet);
> >  
> >       /*
> >        * We're using worker to queue preemption requests from the tasklet in
> > @@ -3265,7 +3265,7 @@ void i915_gem_reset(struct drm_i915_private *dev_priv,
> >  
> >  void i915_gem_reset_finish_engine(struct intel_engine_cs *engine)
> >  {
> > -     tasklet_enable(&engine->execlists.tasklet);
> > +     i915_tasklet_enable(&engine->execlists.tasklet);
> >       kthread_unpark(engine->breadcrumbs.signaler);
> >  
> >       intel_uncore_forcewake_put(engine->i915, FORCEWAKE_ALL);
> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> > index f9bc3aaa90d0..f8aff5a5aa83 100644
> > --- a/drivers/gpu/drm/i915/i915_irq.c
> > +++ b/drivers/gpu/drm/i915/i915_irq.c
> > @@ -1477,7 +1477,7 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
> >       }
> >  
> >       if (tasklet)
> > -             tasklet_hi_schedule(&execlists->tasklet);
> > +             i915_tasklet_schedule(&execlists->tasklet);
> >  }
> >  
> >  static void gen8_gt_irq_ack(struct drm_i915_private *i915,
> > diff --git a/drivers/gpu/drm/i915/i915_tasklet.h b/drivers/gpu/drm/i915/i915_tasklet.h
> > new file mode 100644
> > index 000000000000..c9f41a5ebb91
> > --- /dev/null
> > +++ b/drivers/gpu/drm/i915/i915_tasklet.h
> > @@ -0,0 +1,78 @@
> > +/*
> > + * SPDX-License-Identifier: GPL-2.0
> > + *
> > + * Copyright © 2018 Intel Corporation
> > + */
> > +
> > +#ifndef _I915_TASKLET_H_
> > +#define _I915_TASKLET_H_
> > +
> > +#include <linux/atomic.h>
> > +#include <linux/interrupt.h>
> > +
> > +/**
> > + * struct i915_tasklet - wrapper around tasklet_struct
> > + *
> > + * We want to abuse tasklets slightly, such as calling them directly. In some
> > + * cases, this requires some auxiliary tracking so subclass the tasklet_struct
> > + * so that we have a central place and helpers.
> > + */
> > +struct i915_tasklet {
> > +     struct tasklet_struct base;
> > +};
> > +
> > +static inline void i915_tasklet_init(struct i915_tasklet *t,
> > +                                  void (*func)(unsigned long),
> > +                                  unsigned long data)
> > +{
> > +     tasklet_init(&t->base, func, data);
> > +}
> > +
> > +static inline bool i915_tasklet_is_scheduled(const struct i915_tasklet *t)
> > +{
> > +     return test_bit(TASKLET_STATE_SCHED, &t->base.state);
> > +}
> > +
> > +static inline bool i915_tasklet_is_locked(const struct i915_tasklet *t)
> 
> why not is_running() ?

Because I didn't want to resend the series immediately. It's confusing
because it's set by tasklet_trylock and cleared by tasklet_unlock.

> > +     return test_bit(TASKLET_STATE_RUN, &t->base.state);
> > +}
> > +
> > +static inline bool i915_tasklet_is_enabled(const struct i915_tasklet *t)
> > +{
> > +     return likely(!atomic_read(&t->base.count));
> 
> I am concerned that we bury the sign of racy nature out of sight and
> then it comes and bites us.

Oh, I wouldn't worry about that, just wait until you see what comes
later :-p

> > +static inline void i915_tasklet_set_func(struct i915_tasklet *t,
> > +                                      void (*func)(unsigned long data),
> > +                                      unsigned long data)
> > +{
> > +     tasklet_disable(&t->base);
> 
> What does the disable/enable pair buy us here?
> 

I was thinking about being clear about the ordering.

> It looks that you want trylock and unlock
> so that you can safely change the func/data.

As you point out, the lock is tasklet_disable, the trylock is just a
trylock. Embrace the insanity, let it flow through you.
-Chris
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2018-05-09 13:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09 12:04 [PATCH v3 1/5] drm/i915: Wrap tasklet_struct for abuse Chris Wilson
2018-05-09 12:04 ` [PATCH v3 2/5] drm/i915: Combine tasklet_kill and tasklet_disable Chris Wilson
2018-05-09 13:54   ` Mika Kuoppala
2018-05-09 14:02     ` Chris Wilson
2018-05-09 14:10       ` Chris Wilson
2018-05-09 12:04 ` [PATCH v3 3/5] drm/i915/execlists: Direct submit onto idle engines Chris Wilson
2018-05-09 12:04 ` [PATCH v3 4/5] drm/i915/execlists: Direct submission from irq handler Chris Wilson
2018-05-09 12:04 ` [PATCH v3 5/5] drm/i915: Speed up idle detection by kicking the tasklets Chris Wilson
2018-05-09 12:28 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [v3,1/5] drm/i915: Wrap tasklet_struct for abuse Patchwork
2018-05-09 12:30 ` ✗ Fi.CI.SPARSE: " Patchwork
2018-05-09 12:44 ` ✓ Fi.CI.BAT: success " Patchwork
2018-05-09 13:44 ` [PATCH v3 1/5] " Mika Kuoppala
2018-05-09 13:51   ` Chris Wilson [this message]
2018-05-09 14:26 ` ✓ Fi.CI.IGT: success for series starting with [v3,1/5] " Patchwork

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=152587391627.8613.10312136071207898459@mail.alporthouse.com \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@linux.intel.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 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.