There are a few hwmon sensors support different operating modes,
for example, one-shot and continuous modes. So it's probably not
a bad idea to abstract a mode sysfs node as a common feature in
the hwmon core.
Right beside the hwmon device name, this patch adds a new sysfs
attribute named "mode" and "available_modes" for user to check
and configure the operating mode. For hwmon device drivers that
implemented the _with_info API, the change also adds an optional
hwmon_mode structure in hwmon_chip_info structure so that those
drivers can pass mode related information.
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
Documentation/hwmon/sysfs-interface | 15 +++++
drivers/hwmon/hwmon.c | 87 ++++++++++++++++++++++++++---
include/linux/hwmon.h | 24 ++++++++
3 files changed, 119 insertions(+), 7 deletions(-)
@@ -92,6 +92,21 @@ name The chip name. I2C devices get this attribute created automatically. RO+available_modes The available operating modes of the chip.+ This should be short, lowercase string, not containing+ whitespace, or the wildcard character '*'.+ This attribute shows all the available of the operating modes,+ for example, "power-down" "one-shot" and "continuous".+ RO++mode The current operating mode of the chip.+ This should be short, lowercase string, not containing+ whitespace, or the wildcard character '*'.+ This attribute shows the current operating mode of the chip.+ Writing a valid string from the list of available_modes will+ configure the chip to the corresponding operating mode.+ RW+ update_interval The interval at which the chip will update readings. Unit: millisecond RW
The hwmon core now has a new optional mode interface. So this patch
just implements this mode support so that user space can check and
configure via sysfs node its operating modes: power-down, one-shot,
and continuous modes.
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
drivers/hwmon/ina3221.c | 64 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
Hi Nicolin,
On 10/09/2018 09:33 PM, Nicolin Chen wrote:
quoted hunk
There are a few hwmon sensors support different operating modes,
for example, one-shot and continuous modes. So it's probably not
a bad idea to abstract a mode sysfs node as a common feature in
the hwmon core.
Right beside the hwmon device name, this patch adds a new sysfs
attribute named "mode" and "available_modes" for user to check
and configure the operating mode. For hwmon device drivers that
implemented the _with_info API, the change also adds an optional
hwmon_mode structure in hwmon_chip_info structure so that those
drivers can pass mode related information.
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
Documentation/hwmon/sysfs-interface | 15 +++++
drivers/hwmon/hwmon.c | 87 ++++++++++++++++++++++++++---
include/linux/hwmon.h | 24 ++++++++
3 files changed, 119 insertions(+), 7 deletions(-)
@@ -92,6 +92,21 @@ name The chip name. I2C devices get this attribute created automatically. RO+available_modes The available operating modes of the chip.+ This should be short, lowercase string, not containing+ whitespace, or the wildcard character '*'.+ This attribute shows all the available of the operating modes,+ for example, "power-down" "one-shot" and "continuous".+ RO++mode The current operating mode of the chip.+ This should be short, lowercase string, not containing+ whitespace, or the wildcard character '*'.+ This attribute shows the current operating mode of the chip.+ Writing a valid string from the list of available_modes will+ configure the chip to the corresponding operating mode.+ RW+
No, sorry.
This is not a well defined ABI: The modes would be under full and arbitrary
control by drivers, and be completely driver dependent. It isn't just the sysfs
attribute that makes the ABI, it is also the contents.
Also, being able to set the mode itself (for whatever definition of mode)
is of questionable value. This is not only for the modes suggested here, but
for other possible modes such as comparator mode vs. interrupt mode (which,
if configurable, should be via platform data or devicetree node entries).
For the modes suggested here, more in the other patch.
In short, NACK. I am open to enhancing the ABI, but I don't see the value
of this attribute.
Guenter
quoted hunk
update_interval The interval at which the chip will update readings.
Unit: millisecond
RW
Hi Nicolin,
On 10/09/2018 09:33 PM, Nicolin Chen wrote:
The hwmon core now has a new optional mode interface. So this patch
just implements this mode support so that user space can check and
configure via sysfs node its operating modes: power-down, one-shot,
and continuous modes.
One-shot mode on its own does not make sense or add value: It would require
explicit driver support to trigger a reading, wait for the result, and
report it back to the user. If the intent here is to have the user write the
mode (which triggers the one-shot reading), wait a bit, and then read the
results, that doesn't make sense because standard userspace applications
won't know that. Also, that would be unsynchronized - one has to read the
CVRF bit in the mask/enable register to know if the reading is complete.
The effort to do all this using CPU cycles would in most if not all cases
outweigh any perceived power savings. As such, I just don't see the
practical use case.
power-down mode effectively reinvents runtime power management (runtime
suspend/resume support) and is thus simply unacceptable.
I am open to help explore adding support for runtime power management
to the hwmon subsystem, but that would be less than straightforward and
require an actual use case to warrant the effort.
As such, NACK, sorry.
Thanks,
Guenter
Hi Guenter,
On Wed, Oct 10, 2018 at 06:08:30AM -0700, Guenter Roeck wrote:
quoted
+available_modes The available operating modes of the chip.
+ This should be short, lowercase string, not containing
+ whitespace, or the wildcard character '*'.
+ This attribute shows all the available of the operating modes,
+ for example, "power-down" "one-shot" and "continuous".
+ RO
+
+mode The current operating mode of the chip.
+ This should be short, lowercase string, not containing
+ whitespace, or the wildcard character '*'.
+ This attribute shows the current operating mode of the chip.
+ Writing a valid string from the list of available_modes will
+ configure the chip to the corresponding operating mode.
+ RW
+
This is not a well defined ABI: The modes would be under full and arbitrary
control by drivers, and be completely driver dependent. It isn't just the sysfs
attribute that makes the ABI, it is also the contents.
Also, being able to set the mode itself (for whatever definition of mode)
is of questionable value. This is not only for the modes suggested here, but
for other possible modes such as comparator mode vs. interrupt mode (which,
if configurable, should be via platform data or devicetree node entries).
For the modes suggested here, more in the other patch.
I could foresee an objection here but still wrote the change after
seeing quite a few drivers (especially TI's chips) share the same
pattern for operating modes: power-down, one-shot and continuous.
For example, I could add it to ina3221 driver instead of touching
the core code, but later I would do the same for the ina2xx driver
(just received a board having ina230/226.)
Although I don't mind doing this and will put it to ina3221 driver
in v2, yet maybe we could think about a better way to abstract it?
Thank you
Nicolin
------
In short, NACK. I am open to enhancing the ABI, but I don't see the value
of this attribute.
Guenter
quoted
update_interval The interval at which the chip will update readings.
Unit: millisecond
RW
Hi Nicolin,
On Wed, Oct 10, 2018 at 02:13:57PM -0700, Nicolin Chen wrote:
Hi Guenter,
On Wed, Oct 10, 2018 at 06:08:30AM -0700, Guenter Roeck wrote:
quoted
quoted
+available_modes The available operating modes of the chip.
+ This should be short, lowercase string, not containing
+ whitespace, or the wildcard character '*'.
+ This attribute shows all the available of the operating modes,
+ for example, "power-down" "one-shot" and "continuous".
+ RO
+
+mode The current operating mode of the chip.
+ This should be short, lowercase string, not containing
+ whitespace, or the wildcard character '*'.
+ This attribute shows the current operating mode of the chip.
+ Writing a valid string from the list of available_modes will
+ configure the chip to the corresponding operating mode.
+ RW
+
quoted
This is not a well defined ABI: The modes would be under full and arbitrary
control by drivers, and be completely driver dependent. It isn't just the sysfs
attribute that makes the ABI, it is also the contents.
quoted
Also, being able to set the mode itself (for whatever definition of mode)
is of questionable value. This is not only for the modes suggested here, but
for other possible modes such as comparator mode vs. interrupt mode (which,
if configurable, should be via platform data or devicetree node entries).
For the modes suggested here, more in the other patch.
I could foresee an objection here but still wrote the change after
seeing quite a few drivers (especially TI's chips) share the same
pattern for operating modes: power-down, one-shot and continuous.
For example, I could add it to ina3221 driver instead of touching
the core code, but later I would do the same for the ina2xx driver
(just received a board having ina230/226.)
Most hardware monitoring chips have the functionality. That doesn't
mean that it makes sense to use/expose it.
Although I don't mind doing this and will put it to ina3221 driver
in v2, yet maybe we could think about a better way to abstract it?
My comments to patch 2/2 still apply. Powerdown duplicates existing and
standardized functionality, one-shot mode is not as simple as just enabling
the mode, and I find it quite unlikely to one-shot mode would actually
save any energy.
Thanks,
Guenter
Hello Guenter,
On Wed, Oct 10, 2018 at 06:22:39AM -0700, Guenter Roeck wrote:
quoted
The hwmon core now has a new optional mode interface. So this patch
just implements this mode support so that user space can check and
configure via sysfs node its operating modes: power-down, one-shot,
and continuous modes.
One-shot mode on its own does not make sense or add value: It would require
explicit driver support to trigger a reading, wait for the result, and
report it back to the user. If the intent here is to have the user write the
mode (which triggers the one-shot reading), wait a bit, and then read the
results, that doesn't make sense because standard userspace applications
won't know that. Also, that would be unsynchronized - one has to read the
CVRF bit in the mask/enable register to know if the reading is complete.
I think I oversimplified the one-shot mode here and you are right:
there should be a one-shot reading routine; the conversion time in
the configuration register also needs to be taken care of.
The effort to do all this using CPU cycles would in most if not all cases
outweigh any perceived power savings. As such, I just don't see the
practical use case.
It really depends on the use case and how often the one-shot gets
triggered. For battery-powered devices, running in the continuous
mode does consume considerable power based on the measurement from
our power folks. If a system is running in a power sensitive mode,
while it still needs to occasionally check the inputs, it could be
a use case for one-shot mode, though it's purely a user decision.
power-down mode effectively reinvents runtime power management (runtime
suspend/resume support) and is thus simply unacceptable.
Similar to one-shot, if a system is in a low power mode where it
doesn't want to check the inputs anymore, I feel the user space
could at least make the decision to turn on/off the chips, I am
not quite sure if the generic runtime PM system already has this
kind of support though.
I am open to help explore adding support for runtime power management
to the hwmon subsystem, but that would be less than straightforward and
require an actual use case to warrant the effort.
Is there any feasible solution from your point of view?
Thanks
Nicolin
----
Hi Nicolin,
On Wed, Oct 10, 2018 at 04:09:07PM -0700, Nicolin Chen wrote:
Hello Guenter,
On Wed, Oct 10, 2018 at 06:22:39AM -0700, Guenter Roeck wrote:
quoted
quoted
The hwmon core now has a new optional mode interface. So this patch
just implements this mode support so that user space can check and
configure via sysfs node its operating modes: power-down, one-shot,
and continuous modes.
quoted
One-shot mode on its own does not make sense or add value: It would require
explicit driver support to trigger a reading, wait for the result, and
report it back to the user. If the intent here is to have the user write the
mode (which triggers the one-shot reading), wait a bit, and then read the
results, that doesn't make sense because standard userspace applications
won't know that. Also, that would be unsynchronized - one has to read the
CVRF bit in the mask/enable register to know if the reading is complete.
I think I oversimplified the one-shot mode here and you are right:
there should be a one-shot reading routine; the conversion time in
the configuration register also needs to be taken care of.
quoted
The effort to do all this using CPU cycles would in most if not all cases
outweigh any perceived power savings. As such, I just don't see the
practical use case.
It really depends on the use case and how often the one-shot gets
triggered. For battery-powered devices, running in the continuous
mode does consume considerable power based on the measurement from
our power folks. If a system is running in a power sensitive mode,
while it still needs to occasionally check the inputs, it could be
a use case for one-shot mode, though it's purely a user decision.
That would actually be a use case for runtime power management.
The power used by a modern sensor chip is miniscule compared
to the power consumed by other components in the system,
which may explain why no one bothered looking into runtime
power management for sensors.
This is also an argument against any device or subsystem specific solution:
Users will want to be able to control power consumption for all devices
in the system, not just for sensors. A device specific power control
mechanism would, from user space perspective, be a nightmare.
quoted
power-down mode effectively reinvents runtime power management (runtime
suspend/resume support) and is thus simply unacceptable.
Similar to one-shot, if a system is in a low power mode where it
doesn't want to check the inputs anymore, I feel the user space
could at least make the decision to turn on/off the chips, I am
not quite sure if the generic runtime PM system already has this
kind of support though.
Please look up "runtime power management". It provides the basic
mechanism to turn off / disable a device if it is not used. The point
here is that the basic mechanism is there, even though it may not
be perfect. If it is not perfect, it needs to be improved.
Implementing a per-subsystem alternate method would be the wrong
approach.
quoted
I am open to help explore adding support for runtime power management
to the hwmon subsystem, but that would be less than straightforward and
require an actual use case to warrant the effort.
Is there any feasible solution from your point of view?
You mean to implement runtime suspend/resume for hwmon drivers,
or some other approach ? As for implementing it in hwmon drivers,
I don't know; I don't recall this ever coming up, and never
thought about it. This is where the use case comes in - if done,
it has to be done properly, which will require some thinking and
a substantial amount of time. It simply does not make sense to
spend time on that effort if there is no actual use case.
Implementing an alternate mechanism is simply a no-go.
Guenter
Hi Guenter,
On Wed, Oct 10, 2018 at 04:43:00PM -0700, Guenter Roeck wrote:
quoted
quoted
The effort to do all this using CPU cycles would in most if not all cases
outweigh any perceived power savings. As such, I just don't see the
practical use case.
It really depends on the use case and how often the one-shot gets
triggered. For battery-powered devices, running in the continuous
mode does consume considerable power based on the measurement from
our power folks. If a system is running in a power sensitive mode,
while it still needs to occasionally check the inputs, it could be
a use case for one-shot mode, though it's purely a user decision.
That would actually be a use case for runtime power management.
The power used by a modern sensor chip is miniscule compared
to the power consumed by other components in the system,
which may explain why no one bothered looking into runtime
power management for sensors.
This is also an argument against any device or subsystem specific solution:
Users will want to be able to control power consumption for all devices
in the system, not just for sensors. A device specific power control
mechanism would, from user space perspective, be a nightmare.
That makes sense to me. Actually we wanted a solution more on the
driver side so that user space doesn't need to be involved. But our
downstream solution (switching different modes when certain number
of CPUs get hot plugged in/out) wasn't accepted years ago by other
subsystem maintainers, being commented that it's a user decision,
IIRC. So I thought that having a sysfs node might be a generic way
for "user decision". But I guess I should have tried to seek for a
solution in the kernel like runtime PM as you said.
quoted
quoted
power-down mode effectively reinvents runtime power management (runtime
suspend/resume support) and is thus simply unacceptable.
Similar to one-shot, if a system is in a low power mode where it
doesn't want to check the inputs anymore, I feel the user space
could at least make the decision to turn on/off the chips, I am
not quite sure if the generic runtime PM system already has this
kind of support though.
Please look up "runtime power management". It provides the basic
mechanism to turn off / disable a device if it is not used. The point
here is that the basic mechanism is there, even though it may not
be perfect. If it is not perfect, it needs to be improved.
Implementing a per-subsystem alternate method would be the wrong
approach.
I have implemented runtime PM suspend/resume in other drivers but
what I know is that it relies on someone to call get_sync and put
functions accordingly and it doesn't seem to have built-in system
level low-power or power-sensitive mode for those use cases that
I mentioned previously. But I agree with your point and will take
a closer look.
One more question here, and this might sound a bit abuse of using
the existing hwmon ABI: would it sound plausible to you that the
driver powers down the chip when all three channels get disabled
via in[123]_enable nodes? :)
Thanks
Nicolin
On Wed, Oct 10, 2018 at 05:24:12PM -0700, Nicolin Chen wrote:
Hi Guenter,
On Wed, Oct 10, 2018 at 04:43:00PM -0700, Guenter Roeck wrote:
quoted
quoted
quoted
The effort to do all this using CPU cycles would in most if not all cases
outweigh any perceived power savings. As such, I just don't see the
practical use case.
It really depends on the use case and how often the one-shot gets
triggered. For battery-powered devices, running in the continuous
mode does consume considerable power based on the measurement from
our power folks. If a system is running in a power sensitive mode,
while it still needs to occasionally check the inputs, it could be
a use case for one-shot mode, though it's purely a user decision.
That would actually be a use case for runtime power management.
The power used by a modern sensor chip is miniscule compared
to the power consumed by other components in the system,
which may explain why no one bothered looking into runtime
power management for sensors.
This is also an argument against any device or subsystem specific solution:
Users will want to be able to control power consumption for all devices
in the system, not just for sensors. A device specific power control
mechanism would, from user space perspective, be a nightmare.
That makes sense to me. Actually we wanted a solution more on the
driver side so that user space doesn't need to be involved. But our
downstream solution (switching different modes when certain number
of CPUs get hot plugged in/out) wasn't accepted years ago by other
subsystem maintainers, being commented that it's a user decision,
IIRC. So I thought that having a sysfs node might be a generic way
for "user decision". But I guess I should have tried to seek for a
solution in the kernel like runtime PM as you said.
quoted
quoted
quoted
power-down mode effectively reinvents runtime power management (runtime
suspend/resume support) and is thus simply unacceptable.
Similar to one-shot, if a system is in a low power mode where it
doesn't want to check the inputs anymore, I feel the user space
could at least make the decision to turn on/off the chips, I am
not quite sure if the generic runtime PM system already has this
kind of support though.
Please look up "runtime power management". It provides the basic
mechanism to turn off / disable a device if it is not used. The point
here is that the basic mechanism is there, even though it may not
be perfect. If it is not perfect, it needs to be improved.
Implementing a per-subsystem alternate method would be the wrong
approach.
I have implemented runtime PM suspend/resume in other drivers but
what I know is that it relies on someone to call get_sync and put
functions accordingly and it doesn't seem to have built-in system
level low-power or power-sensitive mode for those use cases that
I mentioned previously. But I agree with your point and will take
a closer look.
One more question here, and this might sound a bit abuse of using
the existing hwmon ABI: would it sound plausible to you that the
driver powers down the chip when all three channels get disabled
via in[123]_enable nodes? :)
On Thu, Oct 11, 2018 at 12:31:52PM -0700, Guenter Roeck wrote:
quoted
One more question here, and this might sound a bit abuse of using
the existing hwmon ABI: would it sound plausible to you that the
driver powers down the chip when all three channels get disabled
via in[123]_enable nodes? :)
I would not call that an abuse, no.
Hmm..do you mean that you aren't in favor of powering down the chip
after all channels get disabled?
I was thinking about having pm_runtime_get_sync()/put() for channel
enabling/disabling routine of in[123]_enable.
Thanks
Nicolin
Hi Nicolin,
On Thu, Oct 11, 2018 at 12:36:59PM -0700, Nicolin Chen wrote:
On Thu, Oct 11, 2018 at 12:31:52PM -0700, Guenter Roeck wrote:
quoted
quoted
One more question here, and this might sound a bit abuse of using
the existing hwmon ABI: would it sound plausible to you that the
driver powers down the chip when all three channels get disabled
via in[123]_enable nodes? :)
I would not call that an abuse, no.
Hmm..do you mean that you aren't in favor of powering down the chip
after all channels get disabled?
No, I was trying to say that I would be ok with powering down the chip.
I was thinking about having pm_runtime_get_sync()/put() for channel
enabling/disabling routine of in[123]_enable.
Not sure if that would work. It might end up waking the chip when a
sysfs attribute is accessed. It might be worth a try, though.
It might also be possible to utilize userspace runtime attributes,
like setting runtime_enabled and setting the idle time before the sensor
shuts down. It would probably be necessary to implement not only
activating the sensor, though - we would also need to to ensure that
the first reading after activation waits until the first read is
complete.
Guenter
On Thu, Oct 11, 2018 at 12:50:25PM -0700, Guenter Roeck wrote:
Hi Nicolin,
On Thu, Oct 11, 2018 at 12:36:59PM -0700, Nicolin Chen wrote:
quoted
On Thu, Oct 11, 2018 at 12:31:52PM -0700, Guenter Roeck wrote:
quoted
quoted
One more question here, and this might sound a bit abuse of using
the existing hwmon ABI: would it sound plausible to you that the
driver powers down the chip when all three channels get disabled
via in[123]_enable nodes? :)
I would not call that an abuse, no.
Hmm..do you mean that you aren't in favor of powering down the chip
after all channels get disabled?
No, I was trying to say that I would be ok with powering down the chip.
Great!
quoted
I was thinking about having pm_runtime_get_sync()/put() for channel
enabling/disabling routine of in[123]_enable.
Not sure if that would work. It might end up waking the chip when a
sysfs attribute is accessed. It might be worth a try, though.
It might also be possible to utilize userspace runtime attributes,
like setting runtime_enabled and setting the idle time before the sensor
shuts down. It would probably be necessary to implement not only
activating the sensor, though - we would also need to to ensure that
the first reading after activation waits until the first read is
complete.