linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] drm/i915: use DEVICE_ATTR_RO macro
@ 2021-05-28 10:04 YueHaibing
  2021-06-01  9:15 ` [Intel-gfx] " Tvrtko Ursulin
  0 siblings, 1 reply; 3+ messages in thread
From: YueHaibing @ 2021-05-28 10:04 UTC (permalink / raw)
  To: jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied, daniel,
	chris, tvrtko.ursulin
  Cc: intel-gfx, dri-devel, linux-kernel, YueHaibing

Use DEVICE_ATTR_RO() helper instead of plain DEVICE_ATTR(),
which makes the code a bit shorter and easier to read.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/gpu/drm/i915/i915_pmu.c   |  8 +++-----
 drivers/gpu/drm/i915/i915_sysfs.c | 30 +++++++++++++++---------------
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
index 41651ac255fa..fb215929b05b 100644
--- a/drivers/gpu/drm/i915/i915_pmu.c
+++ b/drivers/gpu/drm/i915/i915_pmu.c
@@ -834,15 +834,13 @@ static ssize_t i915_pmu_event_show(struct device *dev,
 	return sprintf(buf, "config=0x%lx\n", eattr->val);
 }
 
-static ssize_t
-i915_pmu_get_attr_cpumask(struct device *dev,
-			  struct device_attribute *attr,
-			  char *buf)
+static ssize_t cpumask_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
 {
 	return cpumap_print_to_pagebuf(true, buf, &i915_pmu_cpumask);
 }
 
-static DEVICE_ATTR(cpumask, 0444, i915_pmu_get_attr_cpumask, NULL);
+static DEVICE_ATTR_RO(cpumask);
 
 static struct attribute *i915_cpumask_attrs[] = {
 	&dev_attr_cpumask.attr,
diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
index 4c6b5d52b5ca..183517d1a73d 100644
--- a/drivers/gpu/drm/i915/i915_sysfs.c
+++ b/drivers/gpu/drm/i915/i915_sysfs.c
@@ -58,8 +58,8 @@ static u32 calc_residency(struct drm_i915_private *dev_priv,
 	return DIV_ROUND_CLOSEST_ULL(res, 1000);
 }
 
-static ssize_t
-show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf)
+static ssize_t rc6_enable_show(struct device *kdev,
+			       struct device_attribute *attr, char *buf)
 {
 	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
 	unsigned int mask;
@@ -75,43 +75,43 @@ show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf)
 	return sysfs_emit(buf, "%x\n", mask);
 }
 
-static ssize_t
-show_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf)
+static ssize_t rc6_residency_ms_show(struct device *kdev,
+				     struct device_attribute *attr, char *buf)
 {
 	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
 	u32 rc6_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6);
 	return sysfs_emit(buf, "%u\n", rc6_residency);
 }
 
-static ssize_t
-show_rc6p_ms(struct device *kdev, struct device_attribute *attr, char *buf)
+static ssize_t rc6p_residency_ms_show(struct device *kdev,
+				      struct device_attribute *attr, char *buf)
 {
 	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
 	u32 rc6p_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6p);
 	return sysfs_emit(buf, "%u\n", rc6p_residency);
 }
 
-static ssize_t
-show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, char *buf)
+static ssize_t rc6pp_residency_ms_show(struct device *kdev,
+				       struct device_attribute *attr, char *buf)
 {
 	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
 	u32 rc6pp_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6pp);
 	return sysfs_emit(buf, "%u\n", rc6pp_residency);
 }
 
-static ssize_t
-show_media_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf)
+static ssize_t media_rc6_residency_ms_show(struct device *kdev,
+					   struct device_attribute *attr, char *buf)
 {
 	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
 	u32 rc6_residency = calc_residency(dev_priv, VLV_GT_MEDIA_RC6);
 	return sysfs_emit(buf, "%u\n", rc6_residency);
 }
 
-static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL);
-static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL);
-static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL);
-static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL);
-static DEVICE_ATTR(media_rc6_residency_ms, S_IRUGO, show_media_rc6_ms, NULL);
+static DEVICE_ATTR_RO(rc6_enable);
+static DEVICE_ATTR_RO(rc6_residency_ms);
+static DEVICE_ATTR_RO(rc6p_residency_ms);
+static DEVICE_ATTR_RO(rc6pp_residency_ms);
+static DEVICE_ATTR_RO(media_rc6_residency_ms);
 
 static struct attribute *rc6_attrs[] = {
 	&dev_attr_rc6_enable.attr,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Intel-gfx] [PATCH -next] drm/i915: use DEVICE_ATTR_RO macro
  2021-05-28 10:04 [PATCH -next] drm/i915: use DEVICE_ATTR_RO macro YueHaibing
@ 2021-06-01  9:15 ` Tvrtko Ursulin
  2021-06-02  9:48   ` Tvrtko Ursulin
  0 siblings, 1 reply; 3+ messages in thread
From: Tvrtko Ursulin @ 2021-06-01  9:15 UTC (permalink / raw)
  To: YueHaibing, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
	daniel, chris, tvrtko.ursulin
  Cc: intel-gfx, linux-kernel, dri-devel


On 28/05/2021 11:04, YueHaibing wrote:
> Use DEVICE_ATTR_RO() helper instead of plain DEVICE_ATTR(),
> which makes the code a bit shorter and easier to read.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>   drivers/gpu/drm/i915/i915_pmu.c   |  8 +++-----
>   drivers/gpu/drm/i915/i915_sysfs.c | 30 +++++++++++++++---------------
>   2 files changed, 18 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
> index 41651ac255fa..fb215929b05b 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.c
> +++ b/drivers/gpu/drm/i915/i915_pmu.c
> @@ -834,15 +834,13 @@ static ssize_t i915_pmu_event_show(struct device *dev,
>   	return sprintf(buf, "config=0x%lx\n", eattr->val);
>   }
>   
> -static ssize_t
> -i915_pmu_get_attr_cpumask(struct device *dev,
> -			  struct device_attribute *attr,
> -			  char *buf)
> +static ssize_t cpumask_show(struct device *dev,
> +			    struct device_attribute *attr, char *buf)
>   {
>   	return cpumap_print_to_pagebuf(true, buf, &i915_pmu_cpumask);
>   }
>   
> -static DEVICE_ATTR(cpumask, 0444, i915_pmu_get_attr_cpumask, NULL);
> +static DEVICE_ATTR_RO(cpumask);
>   
>   static struct attribute *i915_cpumask_attrs[] = {
>   	&dev_attr_cpumask.attr,
> diff --git a/drivers/gpu/drm/i915/i915_sysfs.c b/drivers/gpu/drm/i915/i915_sysfs.c
> index 4c6b5d52b5ca..183517d1a73d 100644
> --- a/drivers/gpu/drm/i915/i915_sysfs.c
> +++ b/drivers/gpu/drm/i915/i915_sysfs.c
> @@ -58,8 +58,8 @@ static u32 calc_residency(struct drm_i915_private *dev_priv,
>   	return DIV_ROUND_CLOSEST_ULL(res, 1000);
>   }
>   
> -static ssize_t
> -show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf)
> +static ssize_t rc6_enable_show(struct device *kdev,
> +			       struct device_attribute *attr, char *buf)
>   {
>   	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>   	unsigned int mask;
> @@ -75,43 +75,43 @@ show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf)
>   	return sysfs_emit(buf, "%x\n", mask);
>   }
>   
> -static ssize_t
> -show_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf)
> +static ssize_t rc6_residency_ms_show(struct device *kdev,
> +				     struct device_attribute *attr, char *buf)
>   {
>   	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>   	u32 rc6_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6);
>   	return sysfs_emit(buf, "%u\n", rc6_residency);
>   }
>   
> -static ssize_t
> -show_rc6p_ms(struct device *kdev, struct device_attribute *attr, char *buf)
> +static ssize_t rc6p_residency_ms_show(struct device *kdev,
> +				      struct device_attribute *attr, char *buf)
>   {
>   	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>   	u32 rc6p_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6p);
>   	return sysfs_emit(buf, "%u\n", rc6p_residency);
>   }
>   
> -static ssize_t
> -show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, char *buf)
> +static ssize_t rc6pp_residency_ms_show(struct device *kdev,
> +				       struct device_attribute *attr, char *buf)
>   {
>   	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>   	u32 rc6pp_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6pp);
>   	return sysfs_emit(buf, "%u\n", rc6pp_residency);
>   }
>   
> -static ssize_t
> -show_media_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf)
> +static ssize_t media_rc6_residency_ms_show(struct device *kdev,
> +					   struct device_attribute *attr, char *buf)
>   {
>   	struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>   	u32 rc6_residency = calc_residency(dev_priv, VLV_GT_MEDIA_RC6);
>   	return sysfs_emit(buf, "%u\n", rc6_residency);
>   }
>   
> -static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL);
> -static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL);
> -static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL);
> -static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL);
> -static DEVICE_ATTR(media_rc6_residency_ms, S_IRUGO, show_media_rc6_ms, NULL);
> +static DEVICE_ATTR_RO(rc6_enable);
> +static DEVICE_ATTR_RO(rc6_residency_ms);
> +static DEVICE_ATTR_RO(rc6p_residency_ms);
> +static DEVICE_ATTR_RO(rc6pp_residency_ms);
> +static DEVICE_ATTR_RO(media_rc6_residency_ms);
>   
>   static struct attribute *rc6_attrs[] = {
>   	&dev_attr_rc6_enable.attr,
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Intel-gfx] [PATCH -next] drm/i915: use DEVICE_ATTR_RO macro
  2021-06-01  9:15 ` [Intel-gfx] " Tvrtko Ursulin
@ 2021-06-02  9:48   ` Tvrtko Ursulin
  0 siblings, 0 replies; 3+ messages in thread
From: Tvrtko Ursulin @ 2021-06-02  9:48 UTC (permalink / raw)
  To: YueHaibing, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
	daniel, chris, tvrtko.ursulin
  Cc: intel-gfx, linux-kernel, dri-devel


On 01/06/2021 10:15, Tvrtko Ursulin wrote:
> 
> On 28/05/2021 11:04, YueHaibing wrote:
>> Use DEVICE_ATTR_RO() helper instead of plain DEVICE_ATTR(),
>> which makes the code a bit shorter and easier to read.
>>
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>>   drivers/gpu/drm/i915/i915_pmu.c   |  8 +++-----
>>   drivers/gpu/drm/i915/i915_sysfs.c | 30 +++++++++++++++---------------
>>   2 files changed, 18 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_pmu.c 
>> b/drivers/gpu/drm/i915/i915_pmu.c
>> index 41651ac255fa..fb215929b05b 100644
>> --- a/drivers/gpu/drm/i915/i915_pmu.c
>> +++ b/drivers/gpu/drm/i915/i915_pmu.c
>> @@ -834,15 +834,13 @@ static ssize_t i915_pmu_event_show(struct device 
>> *dev,
>>       return sprintf(buf, "config=0x%lx\n", eattr->val);
>>   }
>> -static ssize_t
>> -i915_pmu_get_attr_cpumask(struct device *dev,
>> -              struct device_attribute *attr,
>> -              char *buf)
>> +static ssize_t cpumask_show(struct device *dev,
>> +                struct device_attribute *attr, char *buf)
>>   {
>>       return cpumap_print_to_pagebuf(true, buf, &i915_pmu_cpumask);
>>   }
>> -static DEVICE_ATTR(cpumask, 0444, i915_pmu_get_attr_cpumask, NULL);
>> +static DEVICE_ATTR_RO(cpumask);
>>   static struct attribute *i915_cpumask_attrs[] = {
>>       &dev_attr_cpumask.attr,
>> diff --git a/drivers/gpu/drm/i915/i915_sysfs.c 
>> b/drivers/gpu/drm/i915/i915_sysfs.c
>> index 4c6b5d52b5ca..183517d1a73d 100644
>> --- a/drivers/gpu/drm/i915/i915_sysfs.c
>> +++ b/drivers/gpu/drm/i915/i915_sysfs.c
>> @@ -58,8 +58,8 @@ static u32 calc_residency(struct drm_i915_private 
>> *dev_priv,
>>       return DIV_ROUND_CLOSEST_ULL(res, 1000);
>>   }
>> -static ssize_t
>> -show_rc6_mask(struct device *kdev, struct device_attribute *attr, 
>> char *buf)
>> +static ssize_t rc6_enable_show(struct device *kdev,
>> +                   struct device_attribute *attr, char *buf)
>>   {
>>       struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>>       unsigned int mask;
>> @@ -75,43 +75,43 @@ show_rc6_mask(struct device *kdev, struct 
>> device_attribute *attr, char *buf)
>>       return sysfs_emit(buf, "%x\n", mask);
>>   }
>> -static ssize_t
>> -show_rc6_ms(struct device *kdev, struct device_attribute *attr, char 
>> *buf)
>> +static ssize_t rc6_residency_ms_show(struct device *kdev,
>> +                     struct device_attribute *attr, char *buf)
>>   {
>>       struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>>       u32 rc6_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6);
>>       return sysfs_emit(buf, "%u\n", rc6_residency);
>>   }
>> -static ssize_t
>> -show_rc6p_ms(struct device *kdev, struct device_attribute *attr, char 
>> *buf)
>> +static ssize_t rc6p_residency_ms_show(struct device *kdev,
>> +                      struct device_attribute *attr, char *buf)
>>   {
>>       struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>>       u32 rc6p_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6p);
>>       return sysfs_emit(buf, "%u\n", rc6p_residency);
>>   }
>> -static ssize_t
>> -show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, 
>> char *buf)
>> +static ssize_t rc6pp_residency_ms_show(struct device *kdev,
>> +                       struct device_attribute *attr, char *buf)
>>   {
>>       struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>>       u32 rc6pp_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6pp);
>>       return sysfs_emit(buf, "%u\n", rc6pp_residency);
>>   }
>> -static ssize_t
>> -show_media_rc6_ms(struct device *kdev, struct device_attribute *attr, 
>> char *buf)
>> +static ssize_t media_rc6_residency_ms_show(struct device *kdev,
>> +                       struct device_attribute *attr, char *buf)
>>   {
>>       struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev);
>>       u32 rc6_residency = calc_residency(dev_priv, VLV_GT_MEDIA_RC6);
>>       return sysfs_emit(buf, "%u\n", rc6_residency);
>>   }
>> -static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL);
>> -static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL);
>> -static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL);
>> -static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL);
>> -static DEVICE_ATTR(media_rc6_residency_ms, S_IRUGO, 
>> show_media_rc6_ms, NULL);
>> +static DEVICE_ATTR_RO(rc6_enable);
>> +static DEVICE_ATTR_RO(rc6_residency_ms);
>> +static DEVICE_ATTR_RO(rc6p_residency_ms);
>> +static DEVICE_ATTR_RO(rc6pp_residency_ms);
>> +static DEVICE_ATTR_RO(media_rc6_residency_ms);
>>   static struct attribute *rc6_attrs[] = {
>>       &dev_attr_rc6_enable.attr,
>>
> 
> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Pushed thanks for the patch!

Regards,

Tvrtko

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-02  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 10:04 [PATCH -next] drm/i915: use DEVICE_ATTR_RO macro YueHaibing
2021-06-01  9:15 ` [Intel-gfx] " Tvrtko Ursulin
2021-06-02  9:48   ` Tvrtko Ursulin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).