Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: Re: [PATCH v11 2/4] drm/xe: Add locks in gtidle code
Date: Fri, 20 Dec 2024 13:09:04 -0800	[thread overview]
Message-ID: <Z2Xc8GpN297TI169@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20241220205927.441082-3-vinay.belgaumkar@intel.com>

On Fri, Dec 20, 2024 at 12:59:25PM -0800, Vinay Belgaumkar wrote:
> Another entry point is added so PMU code can call into the gtidle
> method for residency. Add locking so that parallel calls to this
> method from sysfs and PMU don't give inconsistent gtidle states
> for c6 residency.
> 
> Suggested-by: Lucas De Marchi <lucas.demarchi@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Lucas De Marchi <lucas.demarchi@intel.com>
> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_gt_idle.c       | 23 ++++++++++++++++++++---
>  drivers/gpu/drm/xe/xe_gt_idle.h       |  1 +
>  drivers/gpu/drm/xe/xe_gt_idle_types.h |  3 +++
>  3 files changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_idle.c b/drivers/gpu/drm/xe/xe_gt_idle.c
> index fd80afeef56a..1f32ac964abe 100644
> --- a/drivers/gpu/drm/xe/xe_gt_idle.c
> +++ b/drivers/gpu/drm/xe/xe_gt_idle.c
> @@ -69,6 +69,8 @@ static u64 get_residency_ms(struct xe_gt_idle *gtidle, u64 cur_residency)
>  {
>  	u64 delta, overflow_residency, prev_residency;
>  
> +	lockdep_assert_held(&gtidle->lock);
> +
>  	overflow_residency = BIT_ULL(32);
>  
>  	/*
> @@ -273,8 +275,21 @@ static ssize_t idle_status_show(struct device *dev,
>  
>  	return sysfs_emit(buff, "%s\n", gt_idle_state_to_string(state));
>  }
> -static DEVICE_ATTR_RO(idle_status);
>  
> +u64 xe_gt_idle_residency_msec(struct xe_gt_idle *gtidle)
> +{
> +	struct xe_guc_pc *pc = gtidle_to_pc(gtidle);
> +	u64 residency;
> +	unsigned long flags;
> +
> +	raw_spin_lock_irqsave(&gtidle->lock, flags);

Why raw spin lock rather than just spin lock?

Matt

> +	residency = get_residency_ms(gtidle, gtidle->idle_residency(pc));
> +	raw_spin_unlock_irqrestore(&gtidle->lock, flags);
> +
> +	return residency;
> +}
> +
> +static DEVICE_ATTR_RO(idle_status);
>  static ssize_t idle_residency_ms_show(struct device *dev,
>  				      struct device_attribute *attr, char *buff)
>  {
> @@ -283,10 +298,10 @@ static ssize_t idle_residency_ms_show(struct device *dev,
>  	u64 residency;
>  
>  	xe_pm_runtime_get(pc_to_xe(pc));
> -	residency = gtidle->idle_residency(pc);
> +	residency = xe_gt_idle_residency_msec(gtidle);
>  	xe_pm_runtime_put(pc_to_xe(pc));
>  
> -	return sysfs_emit(buff, "%llu\n", get_residency_ms(gtidle, residency));
> +	return sysfs_emit(buff, "%llu\n", residency);
>  }
>  static DEVICE_ATTR_RO(idle_residency_ms);
>  
> @@ -329,6 +344,8 @@ int xe_gt_idle_init(struct xe_gt_idle *gtidle)
>  	if (!kobj)
>  		return -ENOMEM;
>  
> +	raw_spin_lock_init(&gtidle->lock);
> +
>  	if (xe_gt_is_media_type(gt)) {
>  		snprintf(gtidle->name, sizeof(gtidle->name), "gt%d-mc", gt->info.id);
>  		gtidle->idle_residency = xe_guc_pc_mc6_residency;
> diff --git a/drivers/gpu/drm/xe/xe_gt_idle.h b/drivers/gpu/drm/xe/xe_gt_idle.h
> index 4455a6501cb0..591a01e181bc 100644
> --- a/drivers/gpu/drm/xe/xe_gt_idle.h
> +++ b/drivers/gpu/drm/xe/xe_gt_idle.h
> @@ -17,5 +17,6 @@ void xe_gt_idle_disable_c6(struct xe_gt *gt);
>  void xe_gt_idle_enable_pg(struct xe_gt *gt);
>  void xe_gt_idle_disable_pg(struct xe_gt *gt);
>  int xe_gt_idle_pg_print(struct xe_gt *gt, struct drm_printer *p);
> +u64 xe_gt_idle_residency_msec(struct xe_gt_idle *gtidle);
>  
>  #endif /* _XE_GT_IDLE_H_ */
> diff --git a/drivers/gpu/drm/xe/xe_gt_idle_types.h b/drivers/gpu/drm/xe/xe_gt_idle_types.h
> index b8b297a3f884..a3667c567f8a 100644
> --- a/drivers/gpu/drm/xe/xe_gt_idle_types.h
> +++ b/drivers/gpu/drm/xe/xe_gt_idle_types.h
> @@ -6,6 +6,7 @@
>  #ifndef _XE_GT_IDLE_SYSFS_TYPES_H_
>  #define _XE_GT_IDLE_SYSFS_TYPES_H_
>  
> +#include <linux/spinlock.h>
>  #include <linux/types.h>
>  
>  struct xe_guc_pc;
> @@ -31,6 +32,8 @@ struct xe_gt_idle {
>  	u64 cur_residency;
>  	/** @prev_residency: previous residency counter */
>  	u64 prev_residency;
> +	/** @lock: Lock protecting idle residency counters */
> +	raw_spinlock_t lock;
>  	/** @idle_status: get the current idle state */
>  	enum xe_gt_idle_state (*idle_status)(struct xe_guc_pc *pc);
>  	/** @idle_residency: get idle residency counter */
> -- 
> 2.38.1
> 

  reply	other threads:[~2024-12-20 21:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-20 20:59 [PATCH v11 0/4] drm/xe/pmu: PMU interface for Xe Vinay Belgaumkar
2024-12-20 20:59 ` [PATCH v11 1/4] drm/xe/pmu: Enable PMU interface Vinay Belgaumkar
2025-01-03  8:00   ` Riana Tauro
2024-12-20 20:59 ` [PATCH v11 2/4] drm/xe: Add locks in gtidle code Vinay Belgaumkar
2024-12-20 21:09   ` Matthew Brost [this message]
2024-12-20 21:15     ` Belgaumkar, Vinay
2024-12-20 22:09       ` Lucas De Marchi
2024-12-20 20:59 ` [PATCH v11 3/4] drm/xe/pmu: Add GT C6 events Vinay Belgaumkar
2024-12-20 20:59 ` [PATCH v11 4/4] drm/xe/pmu: Add GT frequency events Vinay Belgaumkar
2024-12-20 21:07 ` ✓ CI.Patch_applied: success for drm/xe/pmu: PMU interface for Xe (rev11) Patchwork
2024-12-20 21:07 ` ✗ CI.checkpatch: warning " Patchwork
2024-12-20 21:09 ` ✓ CI.KUnit: success " Patchwork
2024-12-20 21:27 ` ✓ CI.Build: " Patchwork
2024-12-20 21:29 ` ✓ CI.Hooks: " Patchwork
2024-12-20 21:31 ` ✓ CI.checksparse: " Patchwork
2024-12-20 22:03 ` ✓ Xe.CI.BAT: " Patchwork
2024-12-22  3:26 ` ✗ Xe.CI.Full: 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=Z2Xc8GpN297TI169@lstrano-desk.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=vinay.belgaumkar@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