Skip to contentSkip to conversation

hwmon: (acpi_power_meter): Convert to hwmon_device_register_with_info

RFC PATCH In review Zhang Rui 2 participants 8 messages May 11, 2022 – May 12, 2022 Hardware monitoring

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

RFC PATCH 1/1 hwmon: (acpi_power_meter): Convert to hwmon_device_register_with_info

The acpi_power_meter driver doesn't create any standard hwmon sysfs attributes under its hwmon device node, but instead, the driver has its own code to create the hwmon style sysfs attributes in the ACPI device node of the ACPI Power Meter device.
I'm not clear why it was designed in that way.

In order to elimite

[   79.960333] power_meter ACPI000D:00: hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().

convert the driver to use the new API, no chip_info or sysfs_groups parameter needed.

The only difference brought by this patch is that the "name" attribute will be created under the hwmon device node. Not sure if this matters or not.

---
 drivers/hwmon/acpi_power_meter.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +2 -1
index c405a5869581..81a982dda5af 100644
@@ -890,7 +890,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	if (res)
 		goto exit_free_capability;
 
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+				ACPI_POWER_METER_NAME, NULL, NULL, NULL);
 	if (IS_ERR(resource->hwmon_dev)) {
 		res = PTR_ERR(resource->hwmon_dev);
 		goto exit_remove;
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 8 lines · Zhang Rui

The acpi_power_meter driver doesn't create any standard hwmon sysfs attributes under its hwmon device node, but instead, the driver has its own code to create the hwmon style sysfs attributes in the ACPI device node of the ACPI Power Meter device.
I'm not clear why it was designed in that way.

In order to elimite

[   79.960333] power_meter ACPI000D:00: hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
Quoted 8 lines

convert the driver to use the new API, no chip_info or sysfs_groups parameter needed.

The only difference brought by this patch is that the "name" attribute will be created under the hwmon device node. Not sure if this matters or not.

No, this is not a conversion and not acceptable. Corentin Labbe is working on the real thing. See
https://patchwork.kernel.org/project/linux-hwmon/patch/[email protected]/

Guenter

Quoted 18 lines
---
  drivers/hwmon/acpi_power_meter.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +2 -1
index c405a5869581..81a982dda5af 100644
@@ -890,7 +890,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
  	if (res)
  		goto exit_free_capability;
 
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
+				ACPI_POWER_METER_NAME, NULL, NULL, NULL);
  	if (IS_ERR(resource->hwmon_dev)) {
  		res = PTR_ERR(resource->hwmon_dev);
  		goto exit_remove;
author
#2 lore raw

Hi, Guenter,

Quoted 22 lines · Guenter Roeck
Quoted 21 lines · Zhang Rui

The acpi_power_meter driver doesn't create any standard hwmon sysfs attributes under its hwmon device node, but instead, the driver has its
own code to create the hwmon style sysfs attributes in the ACPI device
node of the ACPI Power Meter device.
I'm not clear why it was designed in that way.

In order to elimite

[   79.960333] power_meter ACPI000D:00: hwmon_device_register() is

deprecated. Please convert the driver to use hwmon_device_register_with_info().
convert the driver to use the new API, no chip_info or sysfs_groups parameter needed.

The only difference brought by this patch is that the "name" attribute
will be created under the hwmon device node. Not sure if this matters or
not.

Quoted 5 lines
Quoted 1 line

No, this is not a conversion and not acceptable. Corentin Labbe is working on the real thing. See

https://patchwork.kernel.org/project/linux-hwmon/patch/[email protected]/

Quoted 2 lines

Thanks for the pointer. And this was my original intension about how to do the conversion.

But then I realized that, just like I described in the changelog, the original sysfs attributes in this driver, although they're hwmon style, but they are actually located under the ACPI device node. And the patch above will move them to the hwmon device node, right?

With any patch, this is what I got under the hwmon device node

# ls /sys/class/hwmon/hwmon0/        
device  power  subsystem  uevent

and this is what I got under the ACPI device node

# ls /sys/class/hwmon/hwmon0/device/
driver  hid  hwmon  measures  modalias  name  path  physical_node  powe
r  power1_model_number  power1_oem_info  power1_serial_number  status  
subsystem  uevent  uid

Plus, in that patch, I don't see how to handle the power meter capabilities change, i.e. METER_NOTIFY_CONFIG event, in acpi_power_meter_notify().
According to the previous logic, we may need to remove/add different attributes based on the new capabilities.

In section 10.4.1 of ACPI Spec 6.4, it says that the _PMC information "remains constant unless either the power meter's firmware or the BMC hardware changes, at which time the platform is required to send Notify(power_meter, 0x80) for the OSPM to re-evaluate _PMC"

If this could happen in real life, we cannot rely on a fixed hwmon_chip_info and attribute_groups at driver registration phase.

thanks,
rui

Quoted 28 lines

Guenter

Quoted 22 lines
---
  drivers/hwmon/acpi_power_meter.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/acpi_power_meter.c +2 -1
index c405a5869581..81a982dda5af 100644
@@ -890,7 +890,8 @@ static int acpi_power_meter_add(struct
 acpi_device *device)
  	if (res)
  		goto exit_free_capability;
 
-	resource->hwmon_dev = hwmon_device_register(&device->dev);
+	resource->hwmon_dev = hwmon_device_register_with_info(&device-
 >dev,
+				ACPI_POWER_METER_NAME, NULL, NULL,
 NULL);
  	if (IS_ERR(resource->hwmon_dev)) {
  		res = PTR_ERR(resource->hwmon_dev);
  		goto exit_remove;
maintainer
#3 lore raw
Quoted 42 lines · Zhang Rui

Hi, Guenter,

Quoted 22 lines · Guenter Roeck
Quoted 21 lines · Zhang Rui

The acpi_power_meter driver doesn't create any standard hwmon sysfs attributes under its hwmon device node, but instead, the driver has its
own code to create the hwmon style sysfs attributes in the ACPI device
node of the ACPI Power Meter device.
I'm not clear why it was designed in that way.

In order to elimite

[   79.960333] power_meter ACPI000D:00: hwmon_device_register() is

deprecated. Please convert the driver to use hwmon_device_register_with_info().
convert the driver to use the new API, no chip_info or sysfs_groups parameter needed.

The only difference brought by this patch is that the "name" attribute
will be created under the hwmon device node. Not sure if this matters or
not.

Quoted 5 lines
Quoted 1 line

No, this is not a conversion and not acceptable. Corentin Labbe is working on the real thing. See

https://patchwork.kernel.org/project/linux-hwmon/patch/[email protected]/

Quoted 2 lines

Thanks for the pointer. And this was my original intension about how to do the conversion.

But then I realized that, just like I described in the changelog, the original sysfs attributes in this driver, although they're hwmon style, but they are actually located under the ACPI device node. And the patch above will move them to the hwmon device node, right?

With any patch, this is what I got under the hwmon device node

Quoted 9 lines
# ls /sys/class/hwmon/hwmon0/
device  power  subsystem  uevent

and this is what I got under the ACPI device node

# ls /sys/class/hwmon/hwmon0/device/
driver  hid  hwmon  measures  modalias  name  path  physical_node  powe
r  power1_model_number  power1_oem_info  power1_serial_number  status
subsystem  uevent  uid

That is part of the conversion to any of the new APIs, and intentional. If that is unacceptable for some reason, you'll have to stick with the old API and accept the warning. Abusing the new APIs is not acceptable.

Quoted 6 lines

Plus, in that patch, I don't see how to handle the power meter capabilities change, i.e. METER_NOTIFY_CONFIG event, in acpi_power_meter_notify().
According to the previous logic, we may need to remove/add different attributes based on the new capabilities.

Quoted 8 lines

In section 10.4.1 of ACPI Spec 6.4, it says that the _PMC information "remains constant unless either the power meter's firmware or the BMC hardware changes, at which time the platform is required to send Notify(power_meter, 0x80) for the OSPM to re-evaluate _PMC"

If this could happen in real life, we cannot rely on a fixed hwmon_chip_info and attribute_groups at driver registration phase.

You have a point. However, if anything, that means that we might have to improve/extend the hwmon API to make attributes visible or invisible dynamically (ie add an API call such as hwmon_update_visibility() and have it call sysfs_update_groups()).

Thanks,
Guenter

maintainer
#4 lore raw

On 5/11/22 09:53, Guenter Roeck wrote:
[ ... ]

Quoted 9 lines
Quoted 3 lines

If this could happen in real life, we cannot rely on a fixed hwmon_chip_info and attribute_groups at driver registration phase.

You have a point. However, if anything, that means that we might have to improve/extend the hwmon API to make attributes visible or invisible dynamically (ie add an API call such as hwmon_update_visibility() and have it call sysfs_update_groups()).

Actually, adding a new API function isn't even necessary. A call to sysfs_update_groups(hwdev->groups) (where hwdev is the device pointer returned by the hwmon registration function) should do.

We could still add an api function for clarity, but all it would do would be to execute that call. That would be cleaner, but it isn't technically necessary.

Thanks,
Guenter

author
#5 lore raw
Quoted 16 lines · Guenter Roeck

On 5/11/22 09:53, Guenter Roeck wrote:
[ ... ]

Quoted 5 lines
Quoted 4 lines

If this could happen in real life, we cannot rely on a fixed hwmon_chip_info and attribute_groups at driver registration phase.

Quoted 7 lines

You have a point. However, if anything, that means that we might have
to improve/extend the hwmon API to make attributes visible or invisible
dynamically (ie add an API call such as hwmon_update_visibility() and have it call sysfs_update_groups()).

Quoted 7 lines

Actually, adding a new API function isn't even necessary. A call to sysfs_update_groups(hwdev->groups) (where hwdev is the device pointer returned by the hwmon registration function) should do.

We could still add an api function for clarity, but all it would do would be to execute that call. That would be cleaner, but it isn't technically necessary.

Agreed.
Calling sysfs_update_groups() should be sufficient.

Given that Labbe already has done a lot of work on this conversion, I will leave this to Labbe.

thanks,
rui

author
#6 lore raw
In reply to Guenter Roeck
Quoted 30 lines · Guenter Roeck
Quoted 29 lines · Zhang Rui

Hi, Guenter,

Quoted 26 lines · Guenter Roeck
Quoted 25 lines · Zhang Rui

The acpi_power_meter driver doesn't create any standard hwmon sysfs
attributes under its hwmon device node, but instead, the driver has
its
own code to create the hwmon style sysfs attributes in the ACPI device
node of the ACPI Power Meter device.
I'm not clear why it was designed in that way.

In order to elimite

[   79.960333] power_meter ACPI000D:00: hwmon_device_register()

is
deprecated. Please convert the driver to use hwmon_device_register_with_info().
convert the driver to use the new API, no chip_info or sysfs_groups
parameter needed.

The only difference brought by this patch is that the "name" attribute
will be created under the hwmon device node. Not sure if this matters or
not.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, this is not a conversion and not acceptable. Corentin Labbe is
working on the real thing. See

https://patchwork.kernel.org/project/linux-hwmon/patch/[email protected]/

Quoted 26 lines
Quoted 17 lines
Quoted 2 lines

Thanks for the pointer. And this was my original intension about how to
do the conversion.

But then I realized that, just like I described in the changelog, the original sysfs attributes in this driver, although they're hwmon
style, but they are actually located under the ACPI device node. And the patch above will move them to the hwmon device node, right?

With any patch, this is what I got under the hwmon device node

# ls /sys/class/hwmon/hwmon0/
device  power  subsystem  uevent
Quoted 8 lines

and this is what I got under the ACPI device node

# ls /sys/class/hwmon/hwmon0/device/
driver  hid  hwmon  measures  modalias  name  path  physical_node  
powe
r  power1_model_number  power1_oem_info  power1_serial_number  stat
us
subsystem  uevent  uid
Quoted 6 lines

That is part of the conversion to any of the new APIs, and intentional.
If that is unacceptable for some reason, you'll have to stick with the old
API and accept the warning. Abusing the new APIs is not acceptable.

I don't know why these attributes were put under the ACPI device node, and if it is okay to move the location. This is part of the reason that I'm sending this as RFC.
But if moving them back to hwmon device node doesn't break anything, surely I'd vote for this.

thanks,
rui

maintainer
#7 lore raw
Quoted 73 lines · Zhang Rui
Quoted 30 lines · Guenter Roeck
Quoted 29 lines · Zhang Rui

Hi, Guenter,

Quoted 26 lines · Guenter Roeck
Quoted 25 lines · Zhang Rui

The acpi_power_meter driver doesn't create any standard hwmon sysfs
attributes under its hwmon device node, but instead, the driver has
its
own code to create the hwmon style sysfs attributes in the ACPI device
node of the ACPI Power Meter device.
I'm not clear why it was designed in that way.

In order to elimite

[   79.960333] power_meter ACPI000D:00: hwmon_device_register()

is
deprecated. Please convert the driver to use hwmon_device_register_with_info().
convert the driver to use the new API, no chip_info or sysfs_groups
parameter needed.

The only difference brought by this patch is that the "name" attribute
will be created under the hwmon device node. Not sure if this matters or
not.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, this is not a conversion and not acceptable. Corentin Labbe is
working on the real thing. See

https://patchwork.kernel.org/project/linux-hwmon/patch/[email protected]/

Quoted 26 lines
Quoted 17 lines
Quoted 2 lines

Thanks for the pointer. And this was my original intension about how to
do the conversion.

But then I realized that, just like I described in the changelog, the original sysfs attributes in this driver, although they're hwmon
style, but they are actually located under the ACPI device node. And the patch above will move them to the hwmon device node, right?

With any patch, this is what I got under the hwmon device node

# ls /sys/class/hwmon/hwmon0/
device  power  subsystem  uevent
Quoted 8 lines

and this is what I got under the ACPI device node

# ls /sys/class/hwmon/hwmon0/device/
driver  hid  hwmon  measures  modalias  name  path  physical_node
powe
r  power1_model_number  power1_oem_info  power1_serial_number  stat
us
subsystem  uevent  uid
Quoted 6 lines

That is part of the conversion to any of the new APIs, and intentional.
If that is unacceptable for some reason, you'll have to stick with the old
API and accept the warning. Abusing the new APIs is not acceptable.

Quoted 6 lines

I don't know why these attributes were put under the ACPI device node, and if it is okay to move the location. This is part of the reason that I'm sending this as RFC.
But if moving them back to hwmon device node doesn't break anything, surely I'd vote for this.

Applications should never access sysfs attributes directly but use libsensors, which handles both locations. So far none of the conversions caused any problems, so let's assume that this one doesn't cause problems either.

Thanks,
Guenter