commit | b5922b11e3d4e2ef6dc0a2eac1530a8b3e6433f8 | [log] [tgz] |
---|---|---|
author | Chau Ly <chaul@amperecomputing.com> | Wed Apr 16 07:52:30 2025 +0000 |
committer | Andrew Jeffery <andrew@codeconstruct.com.au> | Wed May 14 01:20:07 2025 +0000 |
tree | d6c831eaf84fbe953af66bed193b55c01f4030a3 | |
parent | db26db28a402253f147d43e04384df9eead76ca4 [diff] |
Utils: Avoid createInventoryAssoc for destroyed sensors PSU sensors call `createInventoryAssoc` in their constructors to initialize Association interfaces. This function involves an async call to `GetSubTree` to get the chassis paths on D-Bus for its need. Therefore, the Association interface of type `std::shared_ptr<sdbusplus::asio::dbus_interface>` will only be initialized after `GetSubTree` returns, not before the sensor's constructor finishes. `createInventoryAssoc` passes a shared pointer of type `sdbusplus::asio::dbus_interface` to the lambda callback of GetSubTree. Therefore, it will still retain the stored object of this shared pointer until the callback finishes. This results in the initialization of the Association interface to D-Bus even after the sensor was destroyed. This interface will only be removed when this callback finishes. Although the sensor's destructor calls `objServer.remove_interface(association)`, this only removes the interface from the object server's interface list [1], not the interface itself, which was created with `std::make_shared` [2] by a `objServer.add_interface(...)` call in the sensor's constructor. This commit enlists std::weak_ptr in this process, so nothing will share the ownership of this interface with the sensor class outside its scope. Tested: Let a PSU sensor object be destroyed before the Association interface is registered for that sensor path on D-Bus. After that, there shall be no pair of interfacesAdded and interfacesRemoved signals of the Association interface on the sensor path on D-Bus. [1]: https://github.com/openbmc/sdbusplus/blob/f2cc743735e1cfea65e765619b1d8334b22932e6/include/sdbusplus/asio/object_server.hpp#L900 [2]: https://github.com/openbmc/sdbusplus/blob/f2cc743735e1cfea65e765619b1d8334b22932e6/include/sdbusplus/asio/object_server.hpp#L858 Signed-off-by: Chau Ly <chaul@amperecomputing.com> Change-Id: I50bd04b2c6d61c39f6890cf63b471d6c2ba9aa59
dbus-sensors is a collection of sensor applications that provide the xyz.openbmc_project.Sensor collection of interfaces. They read sensor values from hwmon, d-bus, or direct driver access to provide readings. Some advance non-sensor features such as fan presence, pwm control, and automatic cpu detection (x86) are also supported.
runtime re-configurable from d-bus (entity-manager or the like)
isolated: each sensor type is isolated into its own daemon, so a bug in one sensor is unlikely to affect another, and single sensor modifications are possible
async single-threaded: uses sdbusplus/asio bindings
multiple data inputs: hwmon, d-bus, direct driver access
A typical dbus-sensors object support the following dbus interfaces:
Path /xyz/openbmc_project/sensors/<type>/<sensor_name> Interfaces xyz.openbmc_project.Sensor.Value xyz.openbmc_project.Sensor.Threshold.Critical xyz.openbmc_project.Sensor.Threshold.Warning xyz.openbmc_project.State.Decorator.Availability xyz.openbmc_project.State.Decorator.OperationalStatus xyz.openbmc_project.Association.Definitions
Sensor interfaces collection are described here.
Consumer examples of these interfaces are Redfish, Phosphor-Pid-Control, IPMI SDR.
dbus-sensor daemons are reactors that dynamically create and update sensors configuration when system configuration gets updated.
Using asio timers and async calls, dbus-sensor daemons read sensor values and check thresholds periodically. PropertiesChanged signals will be broadcasted for other services to consume when value or threshold status change. OperationStatus is set to false if the sensor is determined to be faulty.
A simple sensor example can be found here.
Sensor devices are described using Exposes records in configuration file. Name and Type fields are required. Different sensor types have different fields. Refer to entity manager schema for complete list.
ADC sensors are sensors based on an Analog to Digital Converter. They are read via the Linux kernel Industrial I/O subsystem (IIO).
One of the more common use cases within OpenBMC is for reading these sensors from the ADC on the Aspeed ASTXX cards.
To utilize ADC sensors feature within OpenBMC you must first define and enable it within the kernel device tree.
When using a common OpenBMC device like the AST2600 you will find a "adc0" and "adc1" section in the aspeed-g6.dtsi file. These are disabled by default so in your system-specific dts you would enable and configure what you want with something like this:
iio-hwmon { compatible = "iio-hwmon"; io-channels = <&adc0 0>; ... } &adc0 { status = "okay"; ... }; &adc1 { status = "okay"; ... };
Note that this is not meant to be an exhaustive list on the nuances of configuring a device tree but really to point users in the general direction.
You will then create an entity-manager configuration file that is of type "ADC" A very simple example would like look this:
"Index": 0, "Name": "P12V", "PowerState": "Always", "ScaleFactor": 1.0, "Type": "ADC"
When your system is booted, a "in0_input" file will be created within the hwmon subsystem (/sys/class/hwmon/hwmonX). The adcsensor application will scan d-bus for any ADC entity-manager objects, look up their "Index" value, and try to match that with the hwmon inY_input files. When it finds a match it will create a d-bus sensor under the xyz.openbmc_project.ADCSensor service. The sensor will be periodically updated based on readings from the hwmon file.