Support averaging power values

Support new env variables 'AVERAGE_power* = "true"' in hwmon config file.
When this env variable is set, power value is the calculated average value.
Otherwise, power value is from power*_input by default.
The new average of power is calculated since the last time the sensor's
values were changed and read.

average =
(cur_average*cur_average_interval - pre_average*pre_average_interval) /
(cur_average_interval - pre_average_interval)

hwmon config example:
AVERAGE_power2 = "true"
AVERAGE_power3 = "true"
AVERAGE_power4 = "true"

Tested: Set AVERAGE_power* in p0 OCC hwmon conf but not in p1 OCC hwmon conf,
then get power sensor info with restapi to check the values.
1. The values of p0*power are all average values.
2. The values of p1*power are all input values.

Note:
Delete $(CODE_COVERAGE_CPPFLAGS) in AM_CPPFLAGS in test/Makefile.am.
This option will define NDEBUG during configuration, then assert in
code doesn't work.

Resolves: openbmc/openbmc#3187
Signed-off-by: Carol Wang <wangkair@cn.ibm.com>
Change-Id: I8d97a7b2905c79cd4f2c276b32e7f5590ffc0483
10 files changed
tree: fc22c6063dea6253a0092cd3dc6208e40cfb4f1d
  1. msl/
  2. test/
  3. tools/
  4. .clang-format
  5. .gitignore
  6. .lcovrc
  7. average.cpp
  8. average.hpp
  9. bootstrap.sh
  10. configure.ac
  11. env.cpp
  12. env.hpp
  13. fan_pwm.cpp
  14. fan_pwm.hpp
  15. fan_speed.cpp
  16. fan_speed.hpp
  17. gpio_handle.cpp
  18. gpio_handle.hpp
  19. hwmon.cpp
  20. hwmon.hpp
  21. hwmonio.cpp
  22. hwmonio.hpp
  23. interface.hpp
  24. LICENSE
  25. mainloop.cpp
  26. mainloop.hpp
  27. MAINTAINERS
  28. Makefile.am
  29. readd.cpp
  30. README.iio.md
  31. README.md
  32. sensor.cpp
  33. sensor.hpp
  34. sensorset.cpp
  35. sensorset.hpp
  36. sysfs.cpp
  37. sysfs.hpp
  38. targets.hpp
  39. thresholds.hpp
  40. types.hpp
  41. util.hpp
README.md

Exposes generic hwmon entries as DBus objects. More information can be found at Sensor Architecture

To Build

To build this package, do the following steps:

    1. ./bootstrap.sh
    2. ./configure ${CONFIGURE_FLAGS}
    3. make

To clean the repository run `./bootstrap.sh clean`.

D-Bus bus names

To enable the use of Linux features like cgroups prioritization and
udev/systemd control, one instance of phosphor-hwmon is intended to
be run per hwmon sysfs class instance.

This requires an algorithm for selecting a stable, well-known D-Bus busname.

The algorithm is <PREFIX>-<ID>.Hwmon<N> where PREFIX is an autoconf
configurable prefix (BUSNAME_PREFIX, xyz.openbmc_project by default),
ID is a std::hash of the /sys/devices path backing the hwmon class
instance, and N is the implemented phosphor-hwmon D-Bus API version.