All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Nirmoy Das <nirmoy.das@intel.com>, intel-gfx@lists.freedesktop.org
Cc: matthew.d.roper@intel.com, chris.p.wilson@linux.intel.com,
	andi.shyti@intel.com, Chris Wilson <chris.p.wilson@intel.com>,
	Nirmoy Das <nirmoy.das@intel.com>
Subject: Re: [Intel-gfx] [PATCH 1/7] drm/i915: Lift runtime-pm acquire callbacks out of intel_wakeref.mutex
Date: Wed, 20 Sep 2023 12:03:40 +0300	[thread overview]
Message-ID: <87ttrprzbn.fsf@intel.com> (raw)
In-Reply-To: <20230918170257.8586-2-nirmoy.das@intel.com>

On Mon, 18 Sep 2023, Nirmoy Das <nirmoy.das@intel.com> wrote:
> From: Chris Wilson <chris.p.wilson@intel.com>
>
> When runtime pm is first woken, it will synchronously call the
> registered callbacks for the device. These callbacks
> may pull in their own forest of locks, which we do not want to
> conflate with the intel_wakeref.mutex. A second minor benefit to
> reducing the coverage of the mutex, is that it will reduce
> contention for frequent sleeps and wakes (such as when being used
> for soft-rc6).
>
> Signed-off-by: Chris Wilson <chris.p.wilson@intel.com>
> Signed-off-by: Nirmoy Das <nirmoy.das@intel.com>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>

Is this patch a dependency on the subsequent patches in the series? If
yes, what's the rationale? If not, please submit separately. None of
this is is obvious in the commit messages.

> ---
>  drivers/gpu/drm/i915/intel_wakeref.c | 43 ++++++++++++++--------------
>  1 file changed, 21 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_wakeref.c b/drivers/gpu/drm/i915/intel_wakeref.c
> index 718f2f1b6174..af7b4cb5b4d7 100644
> --- a/drivers/gpu/drm/i915/intel_wakeref.c
> +++ b/drivers/gpu/drm/i915/intel_wakeref.c
> @@ -10,21 +10,11 @@
>  #include "intel_wakeref.h"
>  #include "i915_drv.h"
>  
> -static void rpm_get(struct intel_wakeref *wf)
> -{
> -	wf->wakeref = intel_runtime_pm_get(&wf->i915->runtime_pm);
> -}
> -
> -static void rpm_put(struct intel_wakeref *wf)
> -{
> -	intel_wakeref_t wakeref = fetch_and_zero(&wf->wakeref);
> -
> -	intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
> -	INTEL_WAKEREF_BUG_ON(!wakeref);
> -}
> -
>  int __intel_wakeref_get_first(struct intel_wakeref *wf)
>  {
> +	intel_wakeref_t wakeref = intel_runtime_pm_get(&wf->i915->runtime_pm);

No non-trivial function calls in the initializer please.

> +	int err = 0;

Until now err was only for handling error returns. If it's also for
returning success, it should probably be named ret.

> +
>  	/*
>  	 * Treat get/put as different subclasses, as we may need to run
>  	 * the put callback from under the shrinker and do not want to
> @@ -32,41 +22,50 @@ int __intel_wakeref_get_first(struct intel_wakeref *wf)
>  	 * upon acquiring the wakeref.
>  	 */
>  	mutex_lock_nested(&wf->mutex, SINGLE_DEPTH_NESTING);
> -	if (!atomic_read(&wf->count)) {
> -		int err;
>  
> -		rpm_get(wf);
> +	if (likely(!atomic_read(&wf->count))) {

Adding the likely should be a separate patch with rationale, not a
random drive-by change. (And maybe it just should not be added at all.)

> +		INTEL_WAKEREF_BUG_ON(wf->wakeref);
> +		wf->wakeref = fetch_and_zero(&wakeref);

fetch_and_zero() should just die. All it does here is make things more
confusing, not less. Please don't add new users.

The get and put helpers could probably stay, modified, to make this more
readable.

>  
>  		err = wf->ops->get(wf);
>  		if (unlikely(err)) {
> -			rpm_put(wf);
> -			mutex_unlock(&wf->mutex);
> -			return err;
> +			wakeref = xchg(&wf->wakeref, 0);
> +			wake_up_var(&wf->wakeref);

e.g. here this bit is duplicated in ____intel_wakeref_put_last().

> +			goto unlock;
>  		}
>  
>  		smp_mb__before_atomic(); /* release wf->count */
>  	}
>  	atomic_inc(&wf->count);
> +	INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
> +
> +unlock:
>  	mutex_unlock(&wf->mutex);
> +	if (unlikely(wakeref))
> +		intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
>  
> -	INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
> -	return 0;
> +	return err;
>  }
>  
>  static void ____intel_wakeref_put_last(struct intel_wakeref *wf)
>  {
> +	intel_wakeref_t wakeref = 0;
> +
>  	INTEL_WAKEREF_BUG_ON(atomic_read(&wf->count) <= 0);
>  	if (unlikely(!atomic_dec_and_test(&wf->count)))
>  		goto unlock;
>  
>  	/* ops->put() must reschedule its own release on error/deferral */
>  	if (likely(!wf->ops->put(wf))) {
> -		rpm_put(wf);
> +		INTEL_WAKEREF_BUG_ON(!wf->wakeref);
> +		wakeref = xchg(&wf->wakeref, 0);
>  		wake_up_var(&wf->wakeref);
>  	}
>  
>  unlock:
>  	mutex_unlock(&wf->mutex);
> +	if (wakeref)
> +		intel_runtime_pm_put(&wf->i915->runtime_pm, wakeref);
>  }
>  
>  void __intel_wakeref_put_last(struct intel_wakeref *wf, unsigned long flags)

-- 
Jani Nikula, Intel

  reply	other threads:[~2023-09-20  9:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 17:02 [Intel-gfx] [PATCH 0/7] Update GGTT with MI_UPDATE_GTT on MTL Nirmoy Das
2023-09-18 17:02 ` [Intel-gfx] [PATCH 1/7] drm/i915: Lift runtime-pm acquire callbacks out of intel_wakeref.mutex Nirmoy Das
2023-09-20  9:03   ` Jani Nikula [this message]
2023-09-20 15:41     ` Nirmoy Das
2023-09-22 10:49     ` Andi Shyti
2023-09-18 17:02 ` [Intel-gfx] [PATCH 2/7] drm/i915: Create a kernel context for GGTT updates Nirmoy Das
2023-09-21 10:20   ` Andi Shyti
2023-09-21 13:18     ` Andi Shyti
2023-09-18 17:02 ` [Intel-gfx] [PATCH 3/7] drm/i915: Implement for_each_sgt_daddr_next Nirmoy Das
2023-09-21 13:06   ` Andi Shyti
2023-09-18 17:02 ` [Intel-gfx] [PATCH 4/7] drm/i915: Parameterize binder context creation Nirmoy Das
2023-09-21 13:08   ` Andi Shyti
2023-09-18 17:02 ` [Intel-gfx] [PATCH 5/7] drm/i915: Implement GGTT update method with MI_UPDATE_GTT Nirmoy Das
2023-09-21 13:09   ` Andi Shyti
2023-09-18 17:02 ` [Intel-gfx] [PATCH 6/7] drm/i915: Toggle binder context ready status Nirmoy Das
2023-09-21 13:23   ` Andi Shyti
2023-09-18 17:02 ` [Intel-gfx] [PATCH 7/7] drm/i915: Enable GGTT updates with binder in MTL Nirmoy Das
2023-09-20  9:02   ` Gwan-gyeong Mun
2023-09-21 13:25   ` Andi Shyti
2023-09-18 23:53 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Update GGTT with MI_UPDATE_GTT on MTL (rev6) Patchwork
2023-09-18 23:53 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-09-19  0:10 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-09-19 14:31 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Update GGTT with MI_UPDATE_GTT on MTL (rev7) Patchwork
2023-09-19 14:32 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-09-19 14:49 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2023-09-20 20:51 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Update GGTT with MI_UPDATE_GTT on MTL (rev8) Patchwork
2023-09-20 20:51 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-09-20 21:05 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-09-21  3:57 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2023-09-22 21:30 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for Update GGTT with MI_UPDATE_GTT on MTL (rev9) Patchwork
2023-09-22 21:30 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2023-09-15  8:34 [Intel-gfx] [PATCH 0/7] Update GGTT with MI_UPDATE_GTT on MTL Nirmoy Das
2023-09-15  8:34 ` [Intel-gfx] [PATCH 1/7] drm/i915: Lift runtime-pm acquire callbacks out of intel_wakeref.mutex Nirmoy Das
2023-09-13 13:09 [Intel-gfx] [PATCH 0/7] Update GGTT with MI_UPDATE_GTT on MTL Nirmoy Das
2023-09-13 13:09 ` [Intel-gfx] [PATCH 1/7] drm/i915: Lift runtime-pm acquire callbacks out of intel_wakeref.mutex Nirmoy Das

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=87ttrprzbn.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=andi.shyti@intel.com \
    --cc=chris.p.wilson@intel.com \
    --cc=chris.p.wilson@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.d.roper@intel.com \
    --cc=nirmoy.das@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.