[Intel-gfx] [PATCH 2/3] drm/i915/hwmon: Add helper function to obtain energy values

Gupta, Anshuman anshuman.gupta at intel.com
Wed Oct 19 13:14:50 UTC 2022



> -----Original Message-----
> From: Tauro, Riana <riana.tauro at intel.com>
> Sent: Wednesday, October 19, 2022 11:34 AM
> To: intel-gfx at lists.freedesktop.org
> Cc: Tauro, Riana <riana.tauro at intel.com>; Gupta, Anshuman
> <anshuman.gupta at intel.com>; Dixit, Ashutosh <ashutosh.dixit at intel.com>;
> Nilawar, Badal <badal.nilawar at intel.com>; Tangudu, Tilak
> <tilak.tangudu at intel.com>
> Subject: [PATCH 2/3] drm/i915/hwmon: Add helper function to obtain
> energy values
> 
> Add an interface to obtain hwmon energy values. This is used by selftest to
> verify power consumption
> 
> Signed-off-by: Riana Tauro <riana.tauro at intel.com>
> ---
>  drivers/gpu/drm/i915/i915_hwmon.c | 23 ++++++++++++++++++++---
> drivers/gpu/drm/i915/i915_hwmon.h |  1 +
>  2 files changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.c
> b/drivers/gpu/drm/i915/i915_hwmon.c
> index 9e9781493025..1eb85cd96171 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.c
> +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> @@ -138,7 +138,7 @@ hwm_field_scale_and_write(struct hwm_drvdata
> *ddat, i915_reg_t rgadr,
>   * hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before
>   * energy1_input overflows. This at 1000 W is an overflow duration of 278
> years.
>   */
> -static void
> +static int
>  hwm_energy(struct hwm_drvdata *ddat, long *energy)  {
>  	struct intel_uncore *uncore = ddat->uncore; @@ -153,6 +153,9 @@
> hwm_energy(struct hwm_drvdata *ddat, long *energy)
>  	else
>  		rgaddr = hwmon->rg.energy_status_all;
> 
> +	if (!i915_mmio_reg_valid(rgaddr))
> +		return -EOPNOTSUPP;
	We can check above in the exported API function then we don't need to change the function
	Prototype.
> +
>  	mutex_lock(&hwmon->hwmon_lock);
> 
>  	with_intel_runtime_pm(uncore->rpm, wakeref) @@ -167,6 +170,21
> @@ hwm_energy(struct hwm_drvdata *ddat, long *energy)
>  	*energy = mul_u64_u32_shr(ei->accum_energy, SF_ENERGY,
>  				  hwmon->scl_shift_energy);
>  	mutex_unlock(&hwmon->hwmon_lock);
> +
> +	return 0;
> +}
> +
> +/*
> + * i915_hwm_get_energy - obtains energy value
> + * Returns: 0 on success or a negative error code  */ int
> +i915_hwm_get_energy(struct drm_i915_private *i915, long *energy) {
Please keep i915_hwmon prefix.
Br,
Anshuman Gupta.
> +	struct i915_hwmon *hwmon = i915->hwmon;
> +	struct hwm_drvdata *ddat = &hwmon->ddat;
> +
> +	return hwm_energy(ddat, energy);
>  }
> 
>  static ssize_t
> @@ -441,8 +459,7 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32
> attr, long *val)  {
>  	switch (attr) {
>  	case hwmon_energy_input:
> -		hwm_energy(ddat, val);
> -		return 0;
> +		return hwm_energy(ddat, val);
>  	default:
>  		return -EOPNOTSUPP;
>  	}
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.h
> b/drivers/gpu/drm/i915/i915_hwmon.h
> index 7ca9cf2c34c9..fa3b13568b37 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.h
> +++ b/drivers/gpu/drm/i915/i915_hwmon.h
> @@ -12,6 +12,7 @@ struct drm_i915_private;  #if
> IS_REACHABLE(CONFIG_HWMON)  void i915_hwmon_register(struct
> drm_i915_private *i915);  void i915_hwmon_unregister(struct
> drm_i915_private *i915);
> +int i915_hwm_get_energy(struct drm_i915_private *i915, long *energy);
>  #else
>  static inline void i915_hwmon_register(struct drm_i915_private *i915) { };
> static inline void i915_hwmon_unregister(struct drm_i915_private *i915) { };
> --
> 2.25.1



More information about the Intel-gfx mailing list