intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: <intel-gfx@lists.freedesktop.org>, <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v2 6/6] drm/i915: switch intel_wakeref_t underlying type to struct ref_tracker *
Date: Thu, 26 Sep 2024 16:52:21 -0400	[thread overview]
Message-ID: <ZvXJhUdZI6gJYj2L@intel.com> (raw)
In-Reply-To: <cca2b0631f816ad90461aa1bf4fe3f80c0e13464.1726680898.git.jani.nikula@intel.com>

On Wed, Sep 18, 2024 at 08:35:48PM +0300, Jani Nikula wrote:
> For intel_wakeref_t, opaque is reasonable, but disguising the underlying
> struct ref_tracker * as an unsigned long is not so great. Update the
> typedef to remove one level of disguise.
> 
> Although the kernel coding style strongly discourages pointer typedefs,
> it's a better alternative, and an incremental improvement on the status
> quo. It provides much better type safety than an unsigned long could,
> and prevents passing magic -1 instead of INTEL_WAKEREF_DEF. Moreover, it
> provides a gradual path for replacing intel_wakeref_t with struct
> ref_tracker * if desired.
> 
> As an extra safety measure, check for error pointers in
> intel_ref_tracker_free() before passing them on to ref_tracker_free(),
> to catch any mistakes with mock gt special wakeref value.

After this would be easy to get a coccinelle or sed
to use ref_tracker directly and kill the typedef?

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
>  drivers/gpu/drm/i915/gt/intel_gt_pm.h            |  2 +-
>  drivers/gpu/drm/i915/intel_wakeref.h             | 16 +++++++++-------
>  .../drm/xe/compat-i915-headers/intel_wakeref.h   |  4 ++--
>  3 files changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gt/intel_gt_pm.h b/drivers/gpu/drm/i915/gt/intel_gt_pm.h
> index fef8d5d288f8..dcbfc09194b7 100644
> --- a/drivers/gpu/drm/i915/gt/intel_gt_pm.h
> +++ b/drivers/gpu/drm/i915/gt/intel_gt_pm.h
> @@ -105,7 +105,7 @@ int intel_gt_runtime_resume(struct intel_gt *gt);
>  
>  ktime_t intel_gt_get_awake_time(const struct intel_gt *gt);
>  
> -#define INTEL_WAKEREF_MOCK_GT ((intel_wakeref_t)-ENODEV)
> +#define INTEL_WAKEREF_MOCK_GT ERR_PTR(-ENODEV)
>  
>  static inline bool is_mock_gt(const struct intel_gt *gt)
>  {
> diff --git a/drivers/gpu/drm/i915/intel_wakeref.h b/drivers/gpu/drm/i915/intel_wakeref.h
> index 3944587a5e78..48836ef52d40 100644
> --- a/drivers/gpu/drm/i915/intel_wakeref.h
> +++ b/drivers/gpu/drm/i915/intel_wakeref.h
> @@ -21,7 +21,7 @@
>  #include <linux/timer.h>
>  #include <linux/workqueue.h>
>  
> -typedef unsigned long intel_wakeref_t;
> +typedef struct ref_tracker *intel_wakeref_t;
>  
>  #define INTEL_REFTRACK_DEAD_COUNT 16
>  #define INTEL_REFTRACK_PRINT_LIMIT 16
> @@ -273,7 +273,7 @@ __intel_wakeref_defer_park(struct intel_wakeref *wf)
>   */
>  int intel_wakeref_wait_for_idle(struct intel_wakeref *wf);
>  
> -#define INTEL_WAKEREF_DEF ((intel_wakeref_t)(-1))
> +#define INTEL_WAKEREF_DEF ERR_PTR(-ENOENT)
>  
>  static inline intel_wakeref_t intel_ref_tracker_alloc(struct ref_tracker_dir *dir)
>  {
> @@ -281,17 +281,19 @@ static inline intel_wakeref_t intel_ref_tracker_alloc(struct ref_tracker_dir *di
>  
>  	ref_tracker_alloc(dir, &user, GFP_NOWAIT);
>  
> -	return (intel_wakeref_t)user ?: INTEL_WAKEREF_DEF;
> +	return user ?: INTEL_WAKEREF_DEF;
>  }
>  
>  static inline void intel_ref_tracker_free(struct ref_tracker_dir *dir,
> -					  intel_wakeref_t handle)
> +					  intel_wakeref_t wakeref)
>  {
> -	struct ref_tracker *user;
> +	if (wakeref == INTEL_WAKEREF_DEF)
> +		wakeref = NULL;
>  
> -	user = (handle == INTEL_WAKEREF_DEF) ? NULL : (void *)handle;
> +	if (WARN_ON(IS_ERR(wakeref)))
> +		return;
>  
> -	ref_tracker_free(dir, &user);
> +	ref_tracker_free(dir, &wakeref);
>  }
>  
>  void intel_ref_tracker_show(struct ref_tracker_dir *dir,
> diff --git a/drivers/gpu/drm/xe/compat-i915-headers/intel_wakeref.h b/drivers/gpu/drm/xe/compat-i915-headers/intel_wakeref.h
> index 5c139ba144a6..2a32faea9db5 100644
> --- a/drivers/gpu/drm/xe/compat-i915-headers/intel_wakeref.h
> +++ b/drivers/gpu/drm/xe/compat-i915-headers/intel_wakeref.h
> @@ -5,6 +5,6 @@
>  
>  #include <linux/types.h>
>  
> -typedef unsigned long intel_wakeref_t;
> +typedef struct ref_tracker *intel_wakeref_t;
>  
> -#define INTEL_WAKEREF_DEF ((intel_wakeref_t)(-1))
> +#define INTEL_WAKEREF_DEF ERR_PTR(-ENOENT)
> -- 
> 2.39.2
> 

  reply	other threads:[~2024-09-26 20:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18 17:35 [PATCH v2 0/6] drm/i915: wakeref fixes and improvements Jani Nikula
2024-09-18 17:35 ` [PATCH v2 1/6] drm/i915/gem: fix bitwise and logical AND mixup Jani Nikula
2024-09-26 20:40   ` Rodrigo Vivi
2024-09-27  8:38     ` Jani Nikula
2024-09-30 13:54       ` Jani Nikula
2024-09-30 14:23         ` Matthew Auld
2024-09-30 14:58           ` Jani Nikula
2024-09-18 17:35 ` [PATCH v2 2/6] drm/i915: use INTEL_WAKEREF_DEF instead of magic -1 for intel_wakeref_t Jani Nikula
2024-09-26 20:45   ` Rodrigo Vivi
2024-09-18 17:35 ` [PATCH v2 3/6] drm/i915/display: return 0 instead of false for disabled power wakeref Jani Nikula
2024-09-26 20:46   ` Rodrigo Vivi
2024-09-18 17:35 ` [PATCH v2 4/6] drm/i915/gt: add a macro for mock gt wakeref special value and use it Jani Nikula
2024-09-26 20:49   ` Rodrigo Vivi
2024-09-18 17:35 ` [PATCH v2 5/6] drm/i915/audio: be explicit about intel_wakeref_t conversions Jani Nikula
2024-09-26 20:49   ` Rodrigo Vivi
2024-09-18 17:35 ` [PATCH v2 6/6] drm/i915: switch intel_wakeref_t underlying type to struct ref_tracker * Jani Nikula
2024-09-26 20:52   ` Rodrigo Vivi [this message]
2024-09-18 18:24 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: wakeref fixes and improvements (rev2) Patchwork
2024-09-18 18:24 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-09-18 18:36 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-09-18 21:37 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: wakeref fixes and improvements (rev3) Patchwork
2024-09-18 21:37 ` ✗ Fi.CI.SPARSE: " Patchwork
2024-09-18 21:46 ` ✓ Fi.CI.BAT: success " Patchwork
2024-09-19  9:25 ` ✗ Fi.CI.IGT: failure " 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=ZvXJhUdZI6gJYj2L@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).