From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 08/32] drm/i915: Introduce struct intel_wakeref
Date: Wed, 17 Apr 2019 10:45:15 +0100 [thread overview]
Message-ID: <ab87711e-bc4e-c2a8-0005-207cbdaf4487@linux.intel.com> (raw)
In-Reply-To: <20190417075657.19456-8-chris@chris-wilson.co.uk>
On 17/04/2019 08:56, Chris Wilson wrote:
> For controlling runtime pm of the GT and engines, we would like to have
> a callback to do extra work the first time we wake up and the last time
> we drop the wakeref. This first/last access needs serialisation and so
> we encompass a mutex with the regular intel_wakeref_t tracker.
>
> v2: Drop the _once naming and report the errors.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc; Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
> drivers/gpu/drm/i915/Makefile | 1 +
> drivers/gpu/drm/i915/Makefile.header-test | 3 +-
> drivers/gpu/drm/i915/i915_drv.h | 3 +-
> drivers/gpu/drm/i915/intel_wakeref.c | 61 ++++++++++
> drivers/gpu/drm/i915/intel_wakeref.h | 133 ++++++++++++++++++++++
> 5 files changed, 198 insertions(+), 3 deletions(-)
> create mode 100644 drivers/gpu/drm/i915/intel_wakeref.c
> create mode 100644 drivers/gpu/drm/i915/intel_wakeref.h
>
> diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
> index 40130cf5c003..233bad5e361f 100644
> --- a/drivers/gpu/drm/i915/Makefile
> +++ b/drivers/gpu/drm/i915/Makefile
> @@ -50,6 +50,7 @@ i915-y += i915_drv.o \
> intel_device_info.o \
> intel_pm.o \
> intel_runtime_pm.o \
> + intel_wakeref.o \
> intel_uncore.o
>
> # core library code
> diff --git a/drivers/gpu/drm/i915/Makefile.header-test b/drivers/gpu/drm/i915/Makefile.header-test
> index 96a5d90629ec..e6b3e7588860 100644
> --- a/drivers/gpu/drm/i915/Makefile.header-test
> +++ b/drivers/gpu/drm/i915/Makefile.header-test
> @@ -31,7 +31,8 @@ header_test := \
> intel_psr.h \
> intel_sdvo.h \
> intel_sprite.h \
> - intel_tv.h
> + intel_tv.h \
> + intel_wakeref.h
>
> quiet_cmd_header_test = HDRTEST $@
> cmd_header_test = echo "\#include \"$(<F)\"" > $@
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index fad5306f07da..62a7e91acd7f 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -74,6 +74,7 @@
> #include "intel_opregion.h"
> #include "intel_uc.h"
> #include "intel_uncore.h"
> +#include "intel_wakeref.h"
> #include "intel_wopcm.h"
>
> #include "i915_gem.h"
> @@ -134,8 +135,6 @@ bool i915_error_injected(void);
> __i915_printk(i915, i915_error_injected() ? KERN_DEBUG : KERN_ERR, \
> fmt, ##__VA_ARGS__)
>
> -typedef depot_stack_handle_t intel_wakeref_t;
> -
> enum hpd_pin {
> HPD_NONE = 0,
> HPD_TV = HPD_NONE, /* TV is known to be unreliable */
> diff --git a/drivers/gpu/drm/i915/intel_wakeref.c b/drivers/gpu/drm/i915/intel_wakeref.c
> new file mode 100644
> index 000000000000..1f94bc4ff9e4
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/intel_wakeref.c
> @@ -0,0 +1,61 @@
> +/*
> + * SPDX-License-Identifier: MIT
> + *
> + * Copyright © 2019 Intel Corporation
> + */
> +
> +#include "intel_drv.h"
> +#include "intel_wakeref.h"
> +
> +int __intel_wakeref_get_first(struct drm_i915_private *i915,
> + struct intel_wakeref *wf,
> + int (*fn)(struct intel_wakeref *wf))
> +{
> + /*
> + * Treat get/put as different subclasses, as we may need to run
> + * the put callback from under the shrinker and do not want to
> + * cross-contanimate that callback with any extra work performed
> + * upon acquiring the wakeref.
> + */
> + mutex_lock_nested(&wf->mutex, SINGLE_DEPTH_NESTING);
> + if (!atomic_read(&wf->count)) {
> + int err;
> +
> + wf->wakeref = intel_runtime_pm_get(i915);
> +
> + err = fn(wf);
> + if (unlikely(err)) {
> + intel_runtime_pm_put(i915, wf->wakeref);
> + mutex_unlock(&wf->mutex);
> + return err;
> + }
> +
> + smp_mb__before_atomic(); /* release wf->count */
> + }
> + atomic_inc(&wf->count);
> + mutex_unlock(&wf->mutex);
> +
> + return 0;
> +}
> +
> +int __intel_wakeref_put_last(struct drm_i915_private *i915,
> + struct intel_wakeref *wf,
> + int (*fn)(struct intel_wakeref *wf))
> +{
> + int err;
> +
> + err = fn(wf);
> + if (likely(!err))
> + intel_runtime_pm_put(i915, wf->wakeref);
> + else
> + atomic_inc(&wf->count);
> + mutex_unlock(&wf->mutex);
> +
> + return err;
> +}
> +
> +void __intel_wakeref_init(struct intel_wakeref *wf, struct lock_class_key *key)
> +{
> + __mutex_init(&wf->mutex, "wakeref", key);
> + atomic_set(&wf->count, 0);
> +}
> diff --git a/drivers/gpu/drm/i915/intel_wakeref.h b/drivers/gpu/drm/i915/intel_wakeref.h
> new file mode 100644
> index 000000000000..a979d638344b
> --- /dev/null
> +++ b/drivers/gpu/drm/i915/intel_wakeref.h
> @@ -0,0 +1,133 @@
> +/*
> + * SPDX-License-Identifier: MIT
> + *
> + * Copyright © 2019 Intel Corporation
> + */
> +
> +#ifndef INTEL_WAKEREF_H
> +#define INTEL_WAKEREF_H
> +
> +#include <linux/atomic.h>
> +#include <linux/mutex.h>
> +#include <linux/stackdepot.h>
> +
> +struct drm_i915_private;
> +
> +typedef depot_stack_handle_t intel_wakeref_t;
> +
> +struct intel_wakeref {
> + atomic_t count;
> + struct mutex mutex;
> + intel_wakeref_t wakeref;
> +};
> +
> +void __intel_wakeref_init(struct intel_wakeref *wf,
> + struct lock_class_key *key);
> +#define intel_wakeref_init(wf) do { \
> + static struct lock_class_key __key; \
> + \
> + __intel_wakeref_init((wf), &__key); \
> +} while (0)
> +
> +int __intel_wakeref_get_first(struct drm_i915_private *i915,
> + struct intel_wakeref *wf,
> + int (*fn)(struct intel_wakeref *wf));
> +int __intel_wakeref_put_last(struct drm_i915_private *i915,
> + struct intel_wakeref *wf,
> + int (*fn)(struct intel_wakeref *wf));
> +
> +/**
> + * intel_wakeref_get: Acquire the wakeref
> + * @i915: the drm_i915_private device
> + * @wf: the wakeref
> + * @fn: callback for acquired the wakeref, called only on first acquire.
> + *
> + * Acquire a hold on the wakeref. The first user to do so, will acquire
> + * the runtime pm wakeref and then call the @fn underneath the wakeref
> + * mutex.
> + *
> + * Note that @fn is allowed to fail, in which case the runtime-pm wakeref
> + * will be released and the acquisition unwound, and an error reported.
> + *
> + * Returns: 0 if the wakeref was acquired successfully, or a negative error
> + * code otherwise.
> + */
> +static inline int
> +intel_wakeref_get(struct drm_i915_private *i915,
> + struct intel_wakeref *wf,
> + int (*fn)(struct intel_wakeref *wf))
> +{
> + if (unlikely(!atomic_inc_not_zero(&wf->count)))
> + return __intel_wakeref_get_first(i915, wf, fn);
> +
> + return 0;
> +}
> +
> +/**
> + * intel_wakeref_put: Release the wakeref
> + * @i915: the drm_i915_private device
> + * @wf: the wakeref
> + * @fn: callback for releasing the wakeref, called only on final release.
> + *
> + * Release our hold on the wakeref. When there are no more users,
> + * the runtime pm wakeref will be released after the @fn callback is called
> + * underneath the wakeref mutex.
> + *
> + * Note that @fn is allowed to fail, in which case the runtime-pm wakeref
> + * is retained and an error reported.
> + *
> + * Returns: 0 if the wakeref was released successfully, or a negative error
> + * code otherwise.
> + */
> +static inline int
> +intel_wakeref_put(struct drm_i915_private *i915,
> + struct intel_wakeref *wf,
> + int (*fn)(struct intel_wakeref *wf))
> +{
> + if (atomic_dec_and_mutex_lock(&wf->count, &wf->mutex))
> + return __intel_wakeref_put_last(i915, wf, fn);
> +
> + return 0;
> +}
> +
> +/**
> + * intel_wakeref_lock: Lock the wakeref (mutex)
> + * @wf: the wakeref
> + *
> + * Locks the wakeref to prevent it being acquired or released. New users
> + * can still adjust the counter, but the wakeref itself (and callback)
> + * cannot be acquired or released.
> + */
> +static inline void
> +intel_wakeref_lock(struct intel_wakeref *wf)
> + __acquires(wf->mutex)
> +{
> + mutex_lock(&wf->mutex);
> +}
> +
> +/**
> + * intel_wakeref_unlock: Unlock the wakeref
> + * @wf: the wakeref
> + *
> + * Releases a previously acquired intel_wakeref_lock().
> + */
> +static inline void
> +intel_wakeref_unlock(struct intel_wakeref *wf)
> + __releases(wf->mutex)
> +{
> + mutex_unlock(&wf->mutex);
> +}
> +
> +/**
> + * intel_wakeref_active: Query whether the wakeref is currently held
> + * @wf: the wakeref
> + *
> + * Returns: true if the wakeref is currently held.
> + */
> +static inline bool
> +intel_wakeref_active(struct intel_wakeref *wf)
> +{
> + return atomic_read(&wf->count);
> +}
> +
> +#endif /* INTEL_WAKEREF_H */
>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-04-17 9:45 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-17 7:56 [PATCH 01/32] drm/i915: Seal races between async GPU cancellation, retirement and signaling Chris Wilson
2019-04-17 7:56 ` [PATCH 02/32] drm/i915: Verify workarounds immediately after application Chris Wilson
2019-04-17 7:56 ` [PATCH 03/32] drm/i915: Verify the engine workarounds stick on application Chris Wilson
2019-04-17 7:56 ` [PATCH 04/32] drm/i915: Make workaround verification *optional* Chris Wilson
2019-04-17 9:37 ` Tvrtko Ursulin
2019-04-17 7:56 ` [PATCH 05/32] drm/i915/selftests: Verify whitelist of context registers Chris Wilson
2019-04-17 7:56 ` [PATCH 06/32] drm/i915: Store the default sseu setup on the engine Chris Wilson
2019-04-17 9:40 ` Tvrtko Ursulin
2019-04-24 9:45 ` Chris Wilson
2019-04-17 7:56 ` [PATCH 07/32] drm/i915: Move GraphicsTechnology files under gt/ Chris Wilson
2019-04-17 9:42 ` Tvrtko Ursulin
2019-04-18 12:04 ` Joonas Lahtinen
2019-04-23 8:57 ` Joonas Lahtinen
2019-04-23 9:40 ` Jani Nikula
2019-04-23 16:46 ` Rodrigo Vivi
2019-04-17 7:56 ` [PATCH 08/32] drm/i915: Introduce struct intel_wakeref Chris Wilson
2019-04-17 9:45 ` Tvrtko Ursulin [this message]
2019-04-17 7:56 ` [PATCH 09/32] drm/i915: Pull the GEM powermangement coupling into its own file Chris Wilson
2019-04-17 7:56 ` [PATCH 10/32] drm/i915: Introduce context->enter() and context->exit() Chris Wilson
2019-04-17 7:56 ` [PATCH 11/32] drm/i915: Pass intel_context to i915_request_create() Chris Wilson
2019-04-17 7:56 ` [PATCH 12/32] drm/i915: Invert the GEM wakeref hierarchy Chris Wilson
2019-04-18 12:42 ` Tvrtko Ursulin
2019-04-18 13:07 ` Chris Wilson
2019-04-18 13:22 ` Chris Wilson
2019-04-23 13:02 ` Tvrtko Ursulin
2019-04-17 7:56 ` [PATCH 13/32] drm/i915/gvt: Pin the per-engine GVT shadow contexts Chris Wilson
2019-04-17 7:56 ` [PATCH 14/32] drm/i915: Explicitly pin the logical context for execbuf Chris Wilson
2019-04-17 7:56 ` [PATCH 15/32] drm/i915: Export intel_context_instance() Chris Wilson
2019-04-17 7:56 ` [PATCH 16/32] drm/i915/selftests: Use the real kernel context for sseu isolation tests Chris Wilson
2019-04-17 7:56 ` [PATCH 17/32] drm/i915/selftests: Pass around intel_context for sseu Chris Wilson
2019-04-17 7:56 ` [PATCH 18/32] drm/i915: Pass intel_context to intel_context_pin_lock() Chris Wilson
2019-04-17 7:56 ` [PATCH 19/32] drm/i915: Split engine setup/init into two phases Chris Wilson
2019-04-17 7:56 ` [PATCH 20/32] drm/i915: Switch back to an array of logical per-engine HW contexts Chris Wilson
2019-04-17 7:56 ` [PATCH 21/32] drm/i915: Remove intel_context.active_link Chris Wilson
2019-04-17 9:47 ` Tvrtko Ursulin
2019-04-17 7:56 ` [PATCH 22/32] drm/i915: Move i915_request_alloc into selftests/ Chris Wilson
2019-04-17 7:56 ` [PATCH 23/32] drm/i915: Allow multiple user handles to the same VM Chris Wilson
2019-04-17 7:56 ` [PATCH 24/32] drm/i915: Restore control over ppgtt for context creation ABI Chris Wilson
2019-04-17 7:56 ` [PATCH 25/32] drm/i915: Allow a context to define its set of engines Chris Wilson
2019-04-17 9:50 ` Tvrtko Ursulin
2019-04-17 7:56 ` [PATCH 26/32] drm/i915: Re-expose SINGLE_TIMELINE flags for context creation Chris Wilson
2019-04-17 7:56 ` [PATCH 27/32] drm/i915: Allow userspace to clone contexts on creation Chris Wilson
2019-04-17 9:50 ` Tvrtko Ursulin
2019-04-17 7:56 ` [PATCH 28/32] drm/i915: Load balancing across a virtual engine Chris Wilson
2019-04-17 11:26 ` Tvrtko Ursulin
2019-04-17 13:51 ` Chris Wilson
2019-04-17 7:56 ` [PATCH 29/32] drm/i915: Apply an execution_mask to the virtual_engine Chris Wilson
2019-04-17 11:43 ` Tvrtko Ursulin
2019-04-17 11:57 ` Chris Wilson
2019-04-17 12:35 ` Tvrtko Ursulin
2019-04-17 12:46 ` Chris Wilson
2019-04-17 13:32 ` Tvrtko Ursulin
2019-04-18 7:24 ` Chris Wilson
2019-04-17 7:56 ` [PATCH 30/32] drm/i915: Extend execution fence to support a callback Chris Wilson
2019-04-17 7:56 ` [PATCH 31/32] drm/i915/execlists: Virtual engine bonding Chris Wilson
2019-04-18 6:47 ` Tvrtko Ursulin
2019-04-18 6:57 ` Chris Wilson
2019-04-18 8:57 ` Tvrtko Ursulin
2019-04-18 9:13 ` Chris Wilson
2019-04-18 9:50 ` Tvrtko Ursulin
2019-04-18 9:59 ` Chris Wilson
2019-04-18 10:24 ` Tvrtko Ursulin
2019-04-17 7:56 ` [PATCH 32/32] drm/i915: Allow specification of parallel execbuf Chris Wilson
2019-04-17 8:46 ` [PATCH 01/32] drm/i915: Seal races between async GPU cancellation, retirement and signaling Chris Wilson
2019-04-17 11:33 ` ✗ Fi.CI.BAT: failure for series starting with [01/32] " Patchwork
2019-04-18 10:32 ` [PATCH 01/32] " Tvrtko Ursulin
2019-04-18 10:40 ` Chris Wilson
2019-04-23 12:59 ` Tvrtko Ursulin
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=ab87711e-bc4e-c2a8-0005-207cbdaf4487@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox