public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Raag Jadav <raag.jadav@intel.com>
To: "Nilawar, Badal" <badal.nilawar@intel.com>
Cc: jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com, tursulin@ursulin.net, airlied@gmail.com,
	daniel@ffwll.ch, linux@roeck-us.net, andi.shyti@linux.intel.com,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	anshuman.gupta@intel.com, riana.tauro@intel.com,
	ashutosh.dixit@intel.com, karthik.poosa@intel.com,
	andriy.shevchenko@linux.intel.com
Subject: Re: [PATCH v4] drm/i915/hwmon: expose fan speed
Date: Fri, 9 Aug 2024 13:10:52 +0300	[thread overview]
Message-ID: <ZrXrLPgN0tDutnGb@black.fi.intel.com> (raw)
In-Reply-To: <23dc7824-50cd-4ba3-be5a-df141e8fe69a@intel.com>

On Fri, Aug 09, 2024 at 03:03:20PM +0530, Nilawar, Badal wrote:
> 
> 
> On 09-08-2024 11:45, Raag Jadav wrote:
> > Add hwmon support for fan1_input attribute, which will expose fan speed
> > in RPM. With this in place we can monitor fan speed using lm-sensors tool.
> > 
> > $ sensors
> > i915-pci-0300
> > Adapter: PCI adapter
> > in0:         653.00 mV
> > fan1:        3833 RPM
> > power1:           N/A  (max =  43.00 W)
> > energy1:      32.02 kJ
> > 
> > v2:
> > - Add mutex protection
> > - Handle overflow
> > - Add ABI documentation
> > - Aesthetic adjustments (Riana)
> > 
> > v3:
> > - Declare rotations as "long" and drop redundant casting
> > - Change date and version in ABI documentation
> > - Add commenter name in changelog (Riana)
> > 
> > v4:
> > - Fix wakeref leak
> > - Drop switch case and simplify hwm_fan_xx() (Andi)
> > 
> > Signed-off-by: Raag Jadav <raag.jadav@intel.com>
> > Reviewed-by: Riana Tauro <riana.tauro@intel.com>
> > ---
> >   .../ABI/testing/sysfs-driver-intel-i915-hwmon |  8 ++
> >   drivers/gpu/drm/i915/gt/intel_gt_regs.h       |  2 +
> >   drivers/gpu/drm/i915/i915_hwmon.c             | 81 +++++++++++++++++++
> >   3 files changed, 91 insertions(+)
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-driver-intel-i915-hwmon b/Documentation/ABI/testing/sysfs-driver-intel-i915-hwmon
> > index 92fe7c5c5ac1..be4141a7522f 100644
> > --- a/Documentation/ABI/testing/sysfs-driver-intel-i915-hwmon
> > +++ b/Documentation/ABI/testing/sysfs-driver-intel-i915-hwmon
> > @@ -75,3 +75,11 @@ Description:	RO. Energy input of device or gt in microjoules.
> >   		for the gt.
> >   		Only supported for particular Intel i915 graphics platforms.
> > +
> > +What:		/sys/bus/pci/drivers/i915/.../hwmon/hwmon<i>/fan1_input
> > +Date:		November 2024
> Why November?

This is expected to land upstream in next cycle right?

> > +KernelVersion:	6.12
> > +Contact:	intel-gfx@lists.freedesktop.org
> > +Description:	RO. Fan speed of device in RPM.
> > +
> > +		Only supported for particular Intel i915 graphics platforms.
> > diff --git a/drivers/gpu/drm/i915/gt/intel_gt_regs.h b/drivers/gpu/drm/i915/gt/intel_gt_regs.h
> > index e42b3a5d4e63..57a3c83d3655 100644
> > --- a/drivers/gpu/drm/i915/gt/intel_gt_regs.h
> > +++ b/drivers/gpu/drm/i915/gt/intel_gt_regs.h
> > @@ -1553,6 +1553,8 @@
> >   #define VLV_RENDER_C0_COUNT			_MMIO(0x138118)
> >   #define VLV_MEDIA_C0_COUNT			_MMIO(0x13811c)
> > +#define PCU_PWM_FAN_SPEED			_MMIO(0x138140)
> > +
> >   #define GEN12_RPSTAT1				_MMIO(0x1381b4)
> >   #define   GEN12_VOLTAGE_MASK			REG_GENMASK(10, 0)
> >   #define   GEN12_CAGF_MASK			REG_GENMASK(19, 11)
> > diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
> > index 49db3e09826c..bafa5a11ed0f 100644
> > --- a/drivers/gpu/drm/i915/i915_hwmon.c
> > +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> > @@ -36,6 +36,7 @@ struct hwm_reg {
> >   	i915_reg_t pkg_rapl_limit;
> >   	i915_reg_t energy_status_all;
> >   	i915_reg_t energy_status_tile;
> > +	i915_reg_t fan_speed;
> >   };
> >   struct hwm_energy_info {
> > @@ -43,11 +44,17 @@ struct hwm_energy_info {
> >   	long accum_energy;			/* Accumulated energy for energy1_input */
> >   };
> > +struct hwm_fan_info {
> > +	u32 reg_val_prev;
> > +	u32 time_prev;
> > +};
> > +
> >   struct hwm_drvdata {
> >   	struct i915_hwmon *hwmon;
> >   	struct intel_uncore *uncore;
> >   	struct device *hwmon_dev;
> >   	struct hwm_energy_info ei;		/*  Energy info for energy1_input */
> > +	struct hwm_fan_info fi;			/*  Fan info for fan1_input */
> >   	char name[12];
> >   	int gt_n;
> >   	bool reset_in_progress;
> > @@ -276,6 +283,7 @@ static const struct hwmon_channel_info * const hwm_info[] = {
> >   	HWMON_CHANNEL_INFO(power, HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_CRIT),
> >   	HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT),
> >   	HWMON_CHANNEL_INFO(curr, HWMON_C_CRIT),
> > +	HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
> >   	NULL
> >   };
> > @@ -613,6 +621,63 @@ hwm_curr_write(struct hwm_drvdata *ddat, u32 attr, long val)
> >   	}
> >   }
> > +static umode_t
> > +hwm_fan_is_visible(const struct hwm_drvdata *ddat, u32 attr)
> > +{
> > +	struct i915_hwmon *hwmon = ddat->hwmon;
> > +
> > +	return attr == hwmon_fan_input &&
> > +	       i915_mmio_reg_valid(hwmon->rg.fan_speed) ? 0444 : 0;
> > +}
> > +
> > +static int
> > +hwm_fan_read(struct hwm_drvdata *ddat, u32 attr, long *val)
> > +{
> > +	struct i915_hwmon *hwmon = ddat->hwmon;
> > +	struct hwm_fan_info *fi = &ddat->fi;
> > +	u32 reg_val, pulses, time, time_now;
> > +	intel_wakeref_t wakeref;
> > +	long rotations;
> > +	int ret = 0;
> > +
> > +	if (attr != hwmon_fan_input)
> > +		return -EOPNOTSUPP;
> Using a switch case in rev3 is more logical here. It will also simplify
> adding more fan attributes in the future. This is why switch cases are used
> in other parts of the file.

Current support is for DG1 and DG2, which do not include any other features
that can be supported by fan attributes.

Raag

  reply	other threads:[~2024-08-09 10:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09  6:15 [PATCH v4] drm/i915/hwmon: expose fan speed Raag Jadav
2024-08-09  9:33 ` Nilawar, Badal
2024-08-09 10:10   ` Raag Jadav [this message]
2024-08-09 10:16   ` Andi Shyti
2024-08-14  8:37     ` Nilawar, Badal
2024-08-19  6:50       ` Raag Jadav
2024-08-19 15:22         ` Andi Shyti
2024-08-09 11:48 ` Andy Shevchenko
2024-08-09 11:57   ` Andi Shyti
2024-08-20  9:00     ` Raag Jadav
2024-08-20 21:49       ` Rodrigo Vivi
2024-08-21  3:52         ` Raag Jadav
2024-08-21 11:39           ` Andy Shevchenko
2024-08-21 11:38         ` Andy Shevchenko
2024-08-09 14:55   ` Raag Jadav
2024-08-13 11:23   ` Raag Jadav
2024-08-13 11:47     ` Andy Shevchenko
2024-08-13 12:53       ` Raag Jadav
2024-08-13 13:07         ` Andy Shevchenko

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=ZrXrLPgN0tDutnGb@black.fi.intel.com \
    --to=raag.jadav@intel.com \
    --cc=airlied@gmail.com \
    --cc=andi.shyti@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=ashutosh.dixit@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=karthik.poosa@intel.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=tursulin@ursulin.net \
    /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