mbox series

[v3,0/2] hwmon: scmi: Scale values to target desired HWMON units

Message ID 20190507230917.21659-1-f.fainelli@gmail.com (mailing list archive)
Headers show
Series hwmon: scmi: Scale values to target desired HWMON units | expand

Message

Florian Fainelli May 7, 2019, 11:09 p.m. UTC
Hi Sudeep, Guenter,

This patch series adds support for scaling SCMI sensor values read from
firmware. Sudeep, let me know if you think we should be treating scale
== 0 as a special value to preserve some firmware compatibility (not
that this would be desired).

Changes in v3:

- add a local __pow10 function to scmi-hwmon.c while a plan to provide
  a generic function is figured out.
- add check on power > 18 which would overflow a 64-bit unsigned integer
- use div64_u64() to properly divide a 64-bit quantity with an unsigned
  64-bit quantity

Changes in v2:

- added a helper function in kernel.h: __pow10()
- made the scale in scmi_sensor_info an s8 type, added defines for
  checking the sign bit and sign extending with a mask
- simplify computations in hwmon driver


Florian Fainelli (2):
  firmware: arm_scmi: Fetch and store sensor scale
  hwmon: scmi: Scale values to target desired HWMON units

 drivers/firmware/arm_scmi/sensors.c |  6 ++++
 drivers/hwmon/scmi-hwmon.c          | 43 ++++++++++++++++++++++++++++-
 include/linux/scmi_protocol.h       |  1 +
 3 files changed, 49 insertions(+), 1 deletion(-)

Comments

Sudeep Holla May 8, 2019, 11:35 a.m. UTC | #1
On Tue, May 07, 2019 at 04:09:15PM -0700, Florian Fainelli wrote:
> Hi Sudeep, Guenter,
> 
> This patch series adds support for scaling SCMI sensor values read from
> firmware. Sudeep, let me know if you think we should be treating scale
> == 0 as a special value to preserve some firmware compatibility (not
> that this would be desired).

So are we providing raw values from sensors.c and handling conversion
in hwmon layer ? I was thinking of just providing converted values
to hwmon just in case if the scaling thing change in future with
newer versions of SCMI. I am fine either way, just trying to keep
hwmon-scmi simpler. I will check if scale = 0 needs to be treated as
special(I don't think so, but will read the spec)

--
Regards,
Sudeep
Florian Fainelli May 8, 2019, 4:26 p.m. UTC | #2
On 5/8/19 4:35 AM, Sudeep Holla wrote:
> On Tue, May 07, 2019 at 04:09:15PM -0700, Florian Fainelli wrote:
>> Hi Sudeep, Guenter,
>>
>> This patch series adds support for scaling SCMI sensor values read from
>> firmware. Sudeep, let me know if you think we should be treating scale
>> == 0 as a special value to preserve some firmware compatibility (not
>> that this would be desired).
> 
> So are we providing raw values from sensors.c and handling conversion
> in hwmon layer ? I was thinking of just providing converted values
> to hwmon just in case if the scaling thing change in future with
> newer versions of SCMI.

These are the reasons why I went with doing the scaling in scmi-hwmon.c:

- scmi-hwmon.c is where we know the target units that should be matching
the HWMON conventions, if we put that scaling into sensors.c that would
be a layering violation IMHO

- within sensors.c we don't have a struct scmi_sensor_info to work with
when called with reading_get, we have a sensor_id, so we would have to
look up the id to struct scmi_sensor_info which is an additional loop,
doing this in scmi-hwmon.c gives us access to that structure directly

- scmi-sensors.c is also the location where the mapping between SCMI
sensor type to HWMON sensor type is done, so if we need to update the
scale from one to the other, we would rather do that where the mapping
is already done, which goes back to the first item.

> I am fine either way, just trying to keep
> hwmon-scmi simpler. I will check if scale = 0 needs to be treated as
> special(I don't think so, but will read the spec)

My concern is not so much with the spec but with assumptions SCMI
firmware writes might have made while populating sensor values. The spec
does not indicate any special treatment about a particular unit power of
10 scale being done or not, and a power of 0 = 1, so that should work okay.

Thanks for taking a look!
Guenter Roeck May 8, 2019, 4:37 p.m. UTC | #3
On Wed, May 08, 2019 at 09:26:10AM -0700, Florian Fainelli wrote:
> On 5/8/19 4:35 AM, Sudeep Holla wrote:
> > On Tue, May 07, 2019 at 04:09:15PM -0700, Florian Fainelli wrote:
> >> Hi Sudeep, Guenter,
> >>
> >> This patch series adds support for scaling SCMI sensor values read from
> >> firmware. Sudeep, let me know if you think we should be treating scale
> >> == 0 as a special value to preserve some firmware compatibility (not
> >> that this would be desired).
> > 
> > So are we providing raw values from sensors.c and handling conversion
> > in hwmon layer ? I was thinking of just providing converted values
> > to hwmon just in case if the scaling thing change in future with
> > newer versions of SCMI.
> 
> These are the reasons why I went with doing the scaling in scmi-hwmon.c:
> 
> - scmi-hwmon.c is where we know the target units that should be matching
> the HWMON conventions, if we put that scaling into sensors.c that would
> be a layering violation IMHO
> 
> - within sensors.c we don't have a struct scmi_sensor_info to work with
> when called with reading_get, we have a sensor_id, so we would have to
> look up the id to struct scmi_sensor_info which is an additional loop,
> doing this in scmi-hwmon.c gives us access to that structure directly
> 
> - scmi-sensors.c is also the location where the mapping between SCMI
> sensor type to HWMON sensor type is done, so if we need to update the
> scale from one to the other, we would rather do that where the mapping
> is already done, which goes back to the first item.
> 
> > I am fine either way, just trying to keep
> > hwmon-scmi simpler. I will check if scale = 0 needs to be treated as
> > special(I don't think so, but will read the spec)
> 
> My concern is not so much with the spec but with assumptions SCMI
> firmware writes might have made while populating sensor values. The spec
> does not indicate any special treatment about a particular unit power of
> 10 scale being done or not, and a power of 0 = 1, so that should work okay.
> 

FWIW, I agree with Florian. hwmon decides which units it wants to use.
Anything else would have to be more complicated: hwmon would have to request
the scale from SCMI, and SCMI would have to adjust its reported value based
on that. It is much easier to just take what we get and adjust internally.

Thanks,
Guenter