diff mbox series

[v3,2/3] drm/i915/hwmon: Add helper function to obtain energy values

Message ID 20221121072946.1013463-3-riana.tauro@intel.com (mailing list archive)
State New, archived
Headers show
Series Add hwmon support for dgfx selftests | expand

Commit Message

Riana Tauro Nov. 21, 2022, 7:29 a.m. UTC
Add an interface to obtain hwmon energy values. This is used
by selftest to verify power consumption

v2 : use i915_hwmon prefix (Anshuman)
v3 : re-use is_visible function of energy to remove
     redundant code (Anshuman)

Signed-off-by: Riana Tauro <riana.tauro@intel.com>
---
 drivers/gpu/drm/i915/i915_hwmon.c | 17 +++++++++++++++++
 drivers/gpu/drm/i915/i915_hwmon.h |  1 +
 2 files changed, 18 insertions(+)

Comments

Gupta, Anshuman Nov. 21, 2022, 7:59 a.m. UTC | #1
> -----Original Message-----
> From: Tauro, Riana <riana.tauro@intel.com>
> Sent: Monday, November 21, 2022 1:00 PM
> To: intel-gfx@lists.freedesktop.org
> Cc: Tauro, Riana <riana.tauro@intel.com>; Gupta, Anshuman
> <anshuman.gupta@intel.com>; Dixit, Ashutosh <ashutosh.dixit@intel.com>;
> Tangudu, Tilak <tilak.tangudu@intel.com>; Nilawar, Badal
> <badal.nilawar@intel.com>
> Subject: [PATCH v3 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
> 
> v2 : use i915_hwmon prefix (Anshuman)
> v3 : re-use is_visible function of energy to remove
>      redundant code (Anshuman)
> 
> Signed-off-by: Riana Tauro <riana.tauro@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_hwmon.c | 17 +++++++++++++++++
> drivers/gpu/drm/i915/i915_hwmon.h |  1 +
>  2 files changed, 18 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.c
> b/drivers/gpu/drm/i915/i915_hwmon.c
> index c588a17f97e9..d45d1cbce886 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.c
> +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> @@ -442,6 +442,23 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32
> attr, long *val)
>  	}
>  }
> 
> +/*
> + * i915_hwmon_get_energy - obtains energy value
> + * Returns: 0 on success or a negative error code  */ int
Adding comment for exported function should be Kennel Doc comments.
https://docs.kernel.org/doc-guide/kernel-doc.html
With that 
Reviewed-by: Anshuman Gupta <anshuman.gupta@intel.com>
> +i915_hwmon_get_energy(struct drm_i915_private *i915, long *energy) {
> +	struct i915_hwmon *hwmon = i915->hwmon;
> +	struct hwm_drvdata *ddat = &hwmon->ddat;
> +
> +	if (!hwm_energy_is_visible(ddat, hwmon_energy_input))
> +		return -EOPNOTSUPP;
> +
> +	hwm_energy(ddat, energy);
> +	return 0;
> +}
> +
>  static umode_t
>  hwm_curr_is_visible(const struct hwm_drvdata *ddat, u32 attr)  { diff --git
> a/drivers/gpu/drm/i915/i915_hwmon.h
> b/drivers/gpu/drm/i915/i915_hwmon.h
> index 7ca9cf2c34c9..a6c8efeb868d 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_hwmon_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
Dixit, Ashutosh Nov. 22, 2022, 2:35 a.m. UTC | #2
On Sun, 20 Nov 2022 23:29:45 -0800, Riana Tauro wrote:
>
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.h b/drivers/gpu/drm/i915/i915_hwmon.h
> index 7ca9cf2c34c9..a6c8efeb868d 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_hwmon_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) { };

What about the #else case?
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
index c588a17f97e9..d45d1cbce886 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.c
+++ b/drivers/gpu/drm/i915/i915_hwmon.c
@@ -442,6 +442,23 @@  hwm_energy_read(struct hwm_drvdata *ddat, u32 attr, long *val)
 	}
 }
 
+/*
+ * i915_hwmon_get_energy - obtains energy value
+ * Returns: 0 on success or a negative error code
+ */
+int
+i915_hwmon_get_energy(struct drm_i915_private *i915, long *energy)
+{
+	struct i915_hwmon *hwmon = i915->hwmon;
+	struct hwm_drvdata *ddat = &hwmon->ddat;
+
+	if (!hwm_energy_is_visible(ddat, hwmon_energy_input))
+		return -EOPNOTSUPP;
+
+	hwm_energy(ddat, energy);
+	return 0;
+}
+
 static umode_t
 hwm_curr_is_visible(const struct hwm_drvdata *ddat, u32 attr)
 {
diff --git a/drivers/gpu/drm/i915/i915_hwmon.h b/drivers/gpu/drm/i915/i915_hwmon.h
index 7ca9cf2c34c9..a6c8efeb868d 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_hwmon_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) { };