[PATCH] drm/xe/hwmon: Refactor xe hwmon

Matt Roper matthew.d.roper at intel.com
Mon Jan 29 19:55:18 UTC 2024


On Fri, Jan 26, 2024 at 10:04:01AM -0500, Dong, Zhanjun wrote:
> 
> 
> On 2024-01-26 2:48 a.m., Karthik Poosa wrote:
> > Check latest platform first in xe_hwmon_get_reg.
> > Move PVC registers to xe_mchbar_regs.h.
> > 
> > Fixes: fb1b70607f73 ("drm/xe/hwmon: Expose power attributes")
> > Suggested-by: Matt Roper <matthew.d.roper at intel.com>
> > Signed-off-by: Karthik Poosa <karthik.poosa at intel.com>
> > ---
> >   drivers/gpu/drm/xe/regs/xe_gt_regs.h     |  6 ------
> >   drivers/gpu/drm/xe/regs/xe_mchbar_regs.h |  6 ++++++
> >   drivers/gpu/drm/xe/xe_hwmon.c            | 24 ++++++++++++------------
> >   3 files changed, 18 insertions(+), 18 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/xe/regs/xe_gt_regs.h b/drivers/gpu/drm/xe/regs/xe_gt_regs.h
> > index cd27480f6486..15ac2d284d48 100644
> > --- a/drivers/gpu/drm/xe/regs/xe_gt_regs.h
> > +++ b/drivers/gpu/drm/xe/regs/xe_gt_regs.h
> > @@ -490,10 +490,4 @@
> >   #define   GT_CS_MASTER_ERROR_INTERRUPT		REG_BIT(3)
> >   #define   GT_RENDER_USER_INTERRUPT		REG_BIT(0)
> > -#define PVC_GT0_PACKAGE_ENERGY_STATUS		XE_REG(0x281004)
> > -#define PVC_GT0_PACKAGE_RAPL_LIMIT		XE_REG(0x281008)
> > -#define PVC_GT0_PACKAGE_POWER_SKU_UNIT		XE_REG(0x281068)
> > -#define PVC_GT0_PLATFORM_ENERGY_STATUS		XE_REG(0x28106c)
> > -#define PVC_GT0_PACKAGE_POWER_SKU		XE_REG(0x281080)
> > -
> >   #endif
> > diff --git a/drivers/gpu/drm/xe/regs/xe_mchbar_regs.h b/drivers/gpu/drm/xe/regs/xe_mchbar_regs.h
> > index 519dd1067a19..97652b4297ff 100644
> > --- a/drivers/gpu/drm/xe/regs/xe_mchbar_regs.h
> > +++ b/drivers/gpu/drm/xe/regs/xe_mchbar_regs.h
> > @@ -41,4 +41,10 @@
> >   #define   PKG_PWR_LIM_1_TIME_X			REG_GENMASK(23, 22)
> >   #define   PKG_PWR_LIM_1_TIME_Y			REG_GENMASK(21, 17)
> > +#define PVC_GT0_PACKAGE_ENERGY_STATUS           XE_REG(0x281004)
> > +#define PVC_GT0_PACKAGE_RAPL_LIMIT              XE_REG(0x281008)
> > +#define PVC_GT0_PACKAGE_POWER_SKU_UNIT          XE_REG(0x281068)
> > +#define PVC_GT0_PLATFORM_ENERGY_STATUS          XE_REG(0x28106c)
> > +#define PVC_GT0_PACKAGE_POWER_SKU               XE_REG(0x281080)
> > +
> >   #endif /* _XE_MCHBAR_REGS_H_ */
> > diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> > index 89c6f7f84b5a..c19a0daf7fd7 100644
> > --- a/drivers/gpu/drm/xe/xe_hwmon.c
> > +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> > @@ -77,32 +77,32 @@ static u32 xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg)
> >   	switch (hwmon_reg) {
> >   	case REG_PKG_RAPL_LIMIT:
> > -		if (xe->info.platform == XE_DG2)
> > -			reg = PCU_CR_PACKAGE_RAPL_LIMIT;
> > -		else if (xe->info.platform == XE_PVC)
> > +		if (xe->info.platform == XE_PVC)
> >   			reg = PVC_GT0_PACKAGE_RAPL_LIMIT;
> > +		else if (xe->info.platform == XE_DG2)
> > +			reg = PCU_CR_PACKAGE_RAPL_LIMIT;
> >   		break;
> >   	case REG_PKG_POWER_SKU:
> > -		if (xe->info.platform == XE_DG2)
> > -			reg = PCU_CR_PACKAGE_POWER_SKU;
> > -		else if (xe->info.platform == XE_PVC)
> > +		if (xe->info.platform == XE_PVC)
> >   			reg = PVC_GT0_PACKAGE_POWER_SKU;
> > +		else if (xe->info.platform == XE_DG2)
> > +			reg = PCU_CR_PACKAGE_POWER_SKU;
> >   		break;
> >   	case REG_PKG_POWER_SKU_UNIT:
> > -		if (xe->info.platform == XE_DG2)
> > -			reg = PCU_CR_PACKAGE_POWER_SKU_UNIT;
> > -		else if (xe->info.platform == XE_PVC)
> > +		if (xe->info.platform == XE_PVC)
> >   			reg = PVC_GT0_PACKAGE_POWER_SKU_UNIT;
> > +		else if (xe->info.platform == XE_DG2)
> > +			reg = PCU_CR_PACKAGE_POWER_SKU_UNIT;
> >   		break;
> >   	case REG_GT_PERF_STATUS:
> >   		if (xe->info.platform == XE_DG2)
> >   			reg = GT_PERF_STATUS;
> >   		break;
> >   	case REG_PKG_ENERGY_STATUS:
> > -		if (xe->info.platform == XE_DG2)
> > -			reg = PCU_CR_PACKAGE_ENERGY_STATUS;
> > -		else if (xe->info.platform == XE_PVC)
> > +		if (xe->info.platform == XE_PVC)
> >   			reg = PVC_GT0_PLATFORM_ENERGY_STATUS;
> > +		else if (xe->info.platform == XE_DG2)
> > +			reg = PCU_CR_PACKAGE_ENERGY_STATUS;
> I see concerns about check latest platform first, while for PVC vs DG2, I
> guess the sales for DG2 should be much more than PVC, should we consider
> that factor?

The convention in Xe (and in i915) is that the newest platform should
always come first in if/else ladders and case statements.  That's purely
for code consistency and to help avoid mistakes when new platforms are
added in the future.  We don't try to do micro-optimizations based on
which platform is more widely sold or anything like that.


Matt

> 
> And, above is equal to a read from 5x2 table, reference by array index might
> be more easy to read and expand in the future, and no more if/else needed.
> 
> Regards,
> Zhanjun Dong
> >   		break;
> >   	default:
> >   		drm_warn(&xe->drm, "Unknown xe hwmon reg id: %d\n", hwmon_reg);

-- 
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation


More information about the Intel-xe mailing list