Avoid redundant virtual sensor updates on unchanged values

This patch fixes a potential memory growth issue caused by handling
PropertyChanged signals without checking whether the new value
differs from the previous one.

Previously, the virtual sensor's `updateVirtualSensor()` method was
called unconditionally whenever a "Value" property change signal was
received. If a large number of D-Bus PropertyChanged signals were
forged or triggered in rapid succession with the same value (e.g.,
during stress testing), this could result in frequent unnecessary
updates, which in turn caused increased memory usage in both the
sensor process and the dbus-broker.

With this change, the handler now compares the new value with the
current stored value and only invokes `updateVirtualSensor()` when
there is a real change.

This mitigates unnecessary CPU and memory load in high signal traffic
scenarios.

Change-Id: I345188fa9e361b2cc972cdbb40c911be89a5d661
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
1 file changed
tree: 2d23b525f1f18b0f049f455940bc2d3111f7b794
  1. subprojects/
  2. test/
  3. .clang-format
  4. .clang-tidy
  5. .editorconfig
  6. .gitignore
  7. .prettierrc.yaml
  8. calculate.cpp
  9. calculate.hpp
  10. dbusSensor.cpp
  11. dbusSensor.hpp
  12. dbusUtils.cpp
  13. dbusUtils.hpp
  14. exprtkTools.hpp
  15. LICENSE
  16. main.cpp
  17. meson.build
  18. meson.options
  19. OWNERS
  20. phosphor-virtual-sensor.service.in
  21. README.md
  22. thresholds.hpp
  23. virtual_sensor_config.json
  24. virtualSensor.cpp
  25. virtualSensor.hpp
README.md

phosphor-virtual-sensor

phosphor-virtual-sensor reads the configuration file virtual_sensor_config.json from one of three locations:

  1. The current directory.
  2. /var/lib/phosphor-virtual-sensor
  3. /usr/share/phosphor-virtual-sensor

By default the repository will install a sample config into (3).

There are two types of data in this file.

virtual sensor configuration information

See virtual_sensor_config.json in this repository for an example. Sensors added this way can use any expression that is accepted by exprtk.

information to get a virtual sensor configuration from D-Bus

For example:

{
  "Desc": {
    "Config": "D-Bus"
  }
}

Sensors added this way can only use a set of restricted calculations. Currently supported types are Average, Maximum, Minimum, Sum and ModifiedMedian.

The virtual sensor configuration information needs to be added into the relevant hardware configuration file in entity-manager. This method of adding a virtual sensor allows a recipe that builds for different hardware configurations to have different virtual sensors for each configuration.

The virtual sensor configuration in entity manager follows a different format to the JSON in virtual_sensor_config.json (specified in entity-manager/schemas/VirtualSensor.json).