Skip to contentSkip to conversation

add new hwmon-core interface v2

RFC In review Lucas Stach 3 participants 7 messages Sep 15, 2011 – Sep 18, 2011 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

RFC 1/2 add new hwmon-core interface v2

Hello Guenter and others,

I reworked my first proposal of the hwmon-core API and would like to get some feedback.

After switching to a table based approach, as suggested by Jonathan Cameron, the actual code is pretty minimal, most of the code are definitions on how the sysfs has to look like and enums for the interface. It got a lot cleaner and maintainable this way.

All in all it's about 800 LOC and should enable a noticeable reduction in code size for drivers using it; quantity could be named after porting the first drivers.

Please review and give some feedback if you find the time. I want to bring this forward and port over the adt7475 driver, but first I have to know if you think the new API has a chance to take off. In a second mail you will find some stupid dummy driver which shows how to use the new API.

Thanks,
Lucas
---

This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.

---
 drivers/hwmon/Makefile     |    1 +
 drivers/hwmon/hwmon-core.c |  479 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/hwmon-core.h |  321 +++++++++++++++++++++++++++++
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/hwmon-core.c
 create mode 100644 include/linux/hwmon-core.h
drivers/hwmon/Makefile +1 -0
index 3c9ccef..3d5b395 100644
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_HWMON)		+= hwmon.o
+obj-$(CONFIG_HWMON)		+= hwmon-core.o
 obj-$(CONFIG_HWMON_VID)		+= hwmon-vid.o
 
 # APCI drivers
drivers/hwmon/hwmon-core.c new file +375 -0

375 lines not on this page · raw message

include/linux/hwmon-core.h new file +321 -0

321 lines not on this page · raw message

Signature · 8 lines
1.7.6



_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Hi Lucas,

Quoted 14 lines · Lucas Stach

Hello Guenter and others,

I reworked my first proposal of the hwmon-core API and would like to get some feedback.

After switching to a table based approach, as suggested by Jonathan Cameron, the actual code is pretty minimal, most of the code are definitions on how the sysfs has to look like and enums for the interface. It got a lot cleaner and maintainable this way.

All in all it's about 800 LOC and should enable a noticeable reduction in code size for drivers using it; quantity could be named after porting the first drivers.

Quoted 6 lines

Please review and give some feedback if you find the time. I want to bring this forward and port over the adt7475 driver, but first I have to know if you think the new API has a chance to take off. In a second mail you will find some stupid dummy driver which shows how to use the new API.

Approach seems much better then before. However, checkpatch reports:

total: 132 errors, 80 warnings, 1004 lines checked

NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or
scripts/cleanfile

Please clean up and resubmit; with that many style errors, it is difficult, at least for me, to read the code, much less to find the real problems.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw

RFC 1/2 add new hwmon-core interface v3

In reply to Lucas Stach

v3: now checkpatch clean (doh!)
Many of the errors were caused by my attempt to make all these definitions readable. Now I think I have a good compromise between readability and making checkpatch happy.

This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.

---
 drivers/hwmon/Makefile     |    1 +
 drivers/hwmon/hwmon-core.c |  459 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/hwmon-core.h |  322 +++++++++++++++++++++++++++++++
 3 files changed, 782 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/hwmon-core.c
 create mode 100644 include/linux/hwmon-core.h
drivers/hwmon/Makefile +1 -0
index 3c9ccef..3d5b395 100644
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_HWMON)		+= hwmon.o
+obj-$(CONFIG_HWMON)		+= hwmon-core.o
 obj-$(CONFIG_HWMON_VID)		+= hwmon-vid.o
 
 # APCI drivers
drivers/hwmon/hwmon-core.c new file +459 -0

459 lines not on this page · raw message

include/linux/hwmon-core.h new file +322 -0

322 lines not on this page · raw message

Signature · 8 lines
1.7.6



_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw

Re: [lm-sensors] [RFC 1/2] add new hwmon-core interface v3

In reply to Lucas Stach

Hi,

Quoted 8 lines · Lucas Stach

v3: now checkpatch clean (doh!)
Many of the errors were caused by my attempt to make all these definitions readable. Now I think I have a good compromise between readability and making checkpatch happy.

This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.

First of all a big thanks for working on this, having a way for other in-kernel drivers to access hwmon devices is a much needed feature for proper gpu power management.

However I'm afraid that the current implementation needs some work. My biggest reason to nack this at this time is that it is not flexible enough.

My biggest concern wrt flexibility is that the current code assumes that all temperature / voltage / fan sensors of a hwmon ic have the same capabilities (and thus the same sysfs attributes) that is simply not true. On for example the f71882fg (and other models supported by that driver), only one of the 3 - 9 voltage inputs has an alarm capability, and thus alarm and max attributes.

Another concern is that it always assumes 1 dimensional indexing, but if you look at automatic fan control related sysfs attributes (which your code currently does not seem to support), then there is 2 dimensional indexing going on there, for each fan or temperature (depending on if the thresholds one can configure are bound to a fan input/output, or to a temp input) one can set multiple thresholds (and per threshold a corresponding pwm duty cycle). One could simply see this as 1 dimensional with a lot of attributes, but it would be much better (and easier from the driver pov) to implement this 2 dimensional.

For a good idea of how complicated a hwmon driver can grow when it comes to having a wild mix of sysfs attributes, where the type of attributes can vary from one channel to the next take a look at the f71882fg driver, if your code can handle converting that to the new hwmon-core interface (and preferably clean up the driver while doing so), then it has the needed flexibility.

An other issue you need to tackle is non continuous indexes. Some drivers have the ability to handle large amounts of channels, for example the sch5636 has upto 5 voltage inputs, 16 temperatures and 8 fans. Almost no motherboard will use these all, and the BIOS should program the chip to disable unused channels, we read this information back and only add sysfs attributes for enabled channels, which can lead to having fan1 and fan6 but nothing in between. Note that when you've per sensor rather then per channel caps, you can essentially handle this for free, since an unused index can simply be a channel without any caps.

And one last nitpick wrt the current implementation:

drivers/hwmon/hwmon-core.c line 264

Quoted 12 lines
drivers/hwmon/hwmon-core.c new file +12 -0
+static ssize_t get_num(struct device *dev,
+		       struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct hwmon_device_attribute *hw_attr = to_hwmon_device_attr(attr);
+	struct hwmon_device_instance *hw_dev = hw_attr->hw_dev_inst;
+	int value, ret;
+	ret = hw_dev->get_numeric_attr(hw_dev->inst_data,
+				       hw_attr->attr_enum, attr->index,&value);
+	if (ret)
+		return ret;
+	ret = snprintf(buf, PAGE_SIZE, "%u\n", value);

value is a signed int, so that should be %d, and we really want that as things like negative temperatures are possible.

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw

Re: [lm-sensors] [RFC 1/2] add new hwmon-core interface v3

In reply to Lucas Stach

Hello Hans,

Am Freitag, den 16.09.2011, 10:37 +0200 schrieb Hans de Goede:

Quoted 16 lines

Hi,

Quoted 8 lines · Lucas Stach

v3: now checkpatch clean (doh!)
Many of the errors were caused by my attempt to make all these definitions readable. Now I think I have a good compromise between readability and making checkpatch happy.

This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.

First of all a big thanks for working on this, having a way for other in-kernel drivers to access hwmon devices is a much needed feature for proper gpu power management.

Quoted 8 lines

However I'm afraid that the current implementation needs some work. My biggest reason to nack this at this time is that it is not flexible enough.

My biggest concern wrt flexibility is that the current code assumes that all temperature / voltage / fan sensors of a hwmon ic have the same capabilities (and thus the same sysfs attributes) that is simply not true. On for example the f71882fg (and other models supported by that driver), only one of the 3 - 9 voltage inputs has an alarm capability, and thus alarm and max attributes.

Handling different caps on every channel will make the interface a bit more complicated, as I don't want to waste too much space for the caps, but it should be doable with reasonable effort.

Quoted 9 lines

Another concern is that it always assumes 1 dimensional indexing, but if you look at automatic fan control related sysfs attributes (which your code currently does not seem to support), then there is 2 dimensional indexing going on there, for each fan or temperature (depending on if the thresholds one can configure are bound to a fan input/output, or to a temp input) one can set multiple thresholds (and per threshold a corresponding pwm duty cycle). One could simply see this as 1 dimensional with a lot of attributes, but it would be much better (and easier from the driver pov) to implement this 2 dimensional.

Really it's the other way around. It doesn't support trip point handling as I haven't implemented 2 dimensional indexing. :)

Originally I wanted to do this in a second iteration of the interface, but if you say I'm generally moving in the right direction I will happily incorporate support for 2d entries in a v4 of this patch.

Quoted 6 lines

For a good idea of how complicated a hwmon driver can grow when it comes to having a wild mix of sysfs attributes, where the type of attributes can vary from one channel to the next take a look at the f71882fg driver, if your code can handle converting that to the new hwmon-core interface (and preferably clean up the driver while doing so), then it has the needed flexibility.

Ok, will take a look at this. Hopefully I'm not too depressed afterwards to work on. ;)

Quoted 10 lines

An other issue you need to tackle is non continuous indexes. Some drivers have the ability to handle large amounts of channels, for example the sch5636 has upto 5 voltage inputs, 16 temperatures and 8 fans. Almost no motherboard will use these all, and the BIOS should program the chip to disable unused channels, we read this information back and only add sysfs attributes for enabled channels, which can lead to having fan1 and fan6 but nothing in between. Note that when you've per sensor rather then per channel caps, you can essentially handle this for free, since an unused index can simply be a channel without any caps.

Do we really have to reflect the hole in sensor numbering? Isn't it enough to only expose the supported number of channels in the interface and do the remapping index->channel within the driver? This would be simple with the current interface, as you can reflect this mapping in the inst_data, which is passed around. Is there any application or use-case relying on the numbering hole being existent?

Quoted 17 lines

And one last nitpick wrt the current implementation:

drivers/hwmon/hwmon-core.c line 264

Quoted 12 lines
drivers/hwmon/hwmon-core.c new file +12 -0
+static ssize_t get_num(struct device *dev,
+		       struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct hwmon_device_attribute *hw_attr = to_hwmon_device_attr(attr);
+	struct hwmon_device_instance *hw_dev = hw_attr->hw_dev_inst;
+	int value, ret;
+	ret = hw_dev->get_numeric_attr(hw_dev->inst_data,
+				       hw_attr->attr_enum, attr->index,&value);
+	if (ret)
+		return ret;
+	ret = snprintf(buf, PAGE_SIZE, "%u\n", value);

value is a signed int, so that should be %d, and we really want that as things like negative temperatures are possible.

Ok, this is a no brainer for v4.

Thanks for your feedback,
Lucas

Quoted 9 lines

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#5 lore raw

Re: [lm-sensors] [RFC 1/2] add new hwmon-core interface v3

In reply to Lucas Stach

Hi Hans,

Quoted 40 lines · Hans de Goede

Hi,

Quoted 8 lines · Lucas Stach

v3: now checkpatch clean (doh!)
Many of the errors were caused by my attempt to make all these definitions readable. Now I think I have a good compromise between readability and making checkpatch happy.

This adds a new hwmon-core interface to centralize sysfs handling and enable cooperation with other in-kernel drivers.

First of all a big thanks for working on this, having a way for other in-kernel drivers to access hwmon devices is a much needed feature for proper gpu power management.

However I'm afraid that the current implementation needs some work. My biggest reason to nack this at this time is that it is not flexible enough.

My biggest concern wrt flexibility is that the current code assumes that all temperature / voltage / fan sensors of a hwmon ic have the same capabilities (and thus the same sysfs attributes) that is simply not true. On for example the f71882fg (and other models supported by that driver), only one of the 3 - 9 voltage inputs has an alarm capability, and thus alarm and max attributes.

Another concern is that it always assumes 1 dimensional indexing, but if you look at automatic fan control related sysfs attributes (which your code currently does not seem to support), then there is 2 dimensional indexing going on there, for each fan or temperature (depending on if the thresholds one can configure are bound to a fan input/output, or to a temp input) one can set multiple thresholds (and per threshold a corresponding pwm duty cycle). One could simply see this as 1 dimensional with a lot of attributes, but it would be much better (and easier from the driver pov) to implement this 2 dimensional.

For a good idea of how complicated a hwmon driver can grow when it comes to having a wild mix of sysfs attributes, where the type of attributes can vary from one channel to the next take a look at the f71882fg driver, if your code can handle converting that to the new hwmon-core interface (and preferably clean up the driver while doing so), then it has the needed flexibility.

Quoted 10 lines

An other issue you need to tackle is non continuous indexes. Some drivers have the ability to handle large amounts of channels, for example the sch5636 has upto 5 voltage inputs, 16 temperatures and 8 fans. Almost no motherboard will use these all, and the BIOS should program the chip to disable unused channels, we read this information back and only add sysfs attributes for enabled channels, which can lead to having fan1 and fan6 but nothing in between. Note that when you've per sensor rather then per channel caps, you can essentially handle this for free, since an unused index can simply be a channel without any caps.

Excellent summary. Exactly my concerns as well. Another example for high complexity is pmbus drivers, thoigh that is probably a bit extreme.

To get this patchset approved, I think we'll have to have a couple of the drivers converted to the new interface, to see if it works and is flexible enough to be useful, and if it really reduces complexity on the driver level.

Quoted 17 lines

And one last nitpick wrt the current implementation:

drivers/hwmon/hwmon-core.c line 264

Quoted 12 lines
drivers/hwmon/hwmon-core.c new file +12 -0
+static ssize_t get_num(struct device *dev,
+		       struct device_attribute *devattr, char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+	struct hwmon_device_attribute *hw_attr = to_hwmon_device_attr(attr);
+	struct hwmon_device_instance *hw_dev = hw_attr->hw_dev_inst;
+	int value, ret;
+	ret = hw_dev->get_numeric_attr(hw_dev->inst_data,
+				       hw_attr->attr_enum, attr->index,&value);
+	if (ret)
+		return ret;
+	ret = snprintf(buf, PAGE_SIZE, "%u\n", value);

value is a signed int, so that should be %d, and we really want that as things like negative temperatures are possible.

Not just temperatures. Oddly enough, some DC-DC converters report negative currents under low load.

Another nitpick: The set function does not check for errors.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#6 lore raw

Re: [lm-sensors] [RFC 1/2] add new hwmon-core interface v3

In reply to Lucas Stach

Hi,

Quoted 2 lines · Lucas Stach

Hello Hans,

<snip snip>

Quoted 10 lines
Quoted 9 lines

An other issue you need to tackle is non continuous indexes. Some drivers have the ability to handle large amounts of channels, for example the sch5636 has upto 5 voltage inputs, 16 temperatures and 8 fans. Almost no motherboard will use these all, and the BIOS should program the chip to disable unused channels, we read this information back and only add sysfs attributes for enabled channels, which can lead to having fan1 and fan6 but nothing in between. Note that when you've per sensor rather then per channel caps, you can essentially handle this for free, since an unused index can simply be a channel without any caps.

Quoted 6 lines

Do we really have to reflect the hole in sensor numbering? Isn't it enough to only expose the supported number of channels in the interface and do the remapping index->channel within the driver? This would be simple with the current interface, as you can reflect this mapping in the inst_data, which is passed around. Is there any application or use-case relying on the numbering hole being existent?

Having holes makes things a lot more KISS on the sensor driver side, besides that drivers with holes in their numbering already exist, we cannot simply change the numbering as that would be breaking the user kernelspace API, so either we need to support holes in the numbering, or we will never be able to convert those drivers to the new core...

Regards,

Hans

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors