xref: /openbmc/docs/designs/virtual-sensors.md (revision f4febd002df578bad816239b70950f84ea4567e8)
1448ac2bdSVijay Khemka### Virtual sensors
2448ac2bdSVijay Khemka
3*f4febd00SPatrick WilliamsAuthor: Vijay Khemka <vijaykhemka@fb.com>; <vijay!>
4448ac2bdSVijay Khemka
5*f4febd00SPatrick WilliamsCreated: 2020-05-13
6448ac2bdSVijay Khemka
7448ac2bdSVijay Khemka## Problem Description
8*f4febd00SPatrick Williams
9*f4febd00SPatrick WilliamsThere are some sensors in the system whose values are derived from actual sensor
10*f4febd00SPatrick Williamsdata and some other factor like fan speed for temperature sensors, some complex
11*f4febd00SPatrick Williamsand non standard scale factors or some other algorithmic calculations. Some of
12*f4febd00SPatrick WilliamsVirtual sensor examples are:
13448ac2bdSVijay Khemka
14448ac2bdSVijay Khemka1. Airflow: Function of Fan RPM reported in units of cubic-feet per second.
15448ac2bdSVijay Khemka2. Voltage delta between two ADC inputs. When the actual diff is what which
16448ac2bdSVijay Khemka   should not cross a threshold.
17448ac2bdSVijay Khemka3. Power consumption when we have Energy/time.
18448ac2bdSVijay Khemka
19*f4febd00SPatrick WilliamsThis design will allow to generate a new virtual sensors which are defined to be
20*f4febd00SPatrick Williamsspecific manipulation/function of existing sensors.
21448ac2bdSVijay Khemka
22448ac2bdSVijay Khemka## Background and References
23*f4febd00SPatrick Williams
24448ac2bdSVijay KhemkaNone.
25448ac2bdSVijay Khemka
26448ac2bdSVijay Khemka## Requirements
27*f4febd00SPatrick Williams
28448ac2bdSVijay KhemkaThis should implement a new virtual sensor for every given sensor and update
29*f4febd00SPatrick Williamsthem as per changes in existing sensors. This implementation should provide
30*f4febd00SPatrick Williams
31*f4febd00SPatrick Williams- a daemon to create and monitor each sensor defined in config file and update
32*f4febd00SPatrick Williams  them based on value change in each given sensor.
33448ac2bdSVijay Khemka- Every virtual sensor will be waiting for event for change in dbus value of
34448ac2bdSVijay Khemka  each sensor parameter and will update this sensor.
35*f4febd00SPatrick Williams- Sensor parameter can be any sensor dbus path and it also supports chaining of
36*f4febd00SPatrick Williams  virtual sensors.
37*f4febd00SPatrick Williams- a dbus interface like other sensors to allow other services to access its data
38448ac2bdSVijay Khemka- capability to read parameter details from config file
39448ac2bdSVijay Khemka- capability to read a algorithm string from config file and use the same
40448ac2bdSVijay Khemka  algorithm in calculating value for new virtual sensor
41448ac2bdSVijay Khemka
42448ac2bdSVijay Khemka## Proposed Design
43448ac2bdSVijay Khemka
44*f4febd00SPatrick WilliamsCreate a D-bus service "xyz.openbmc_project.VirtualSensor" with object paths for
45*f4febd00SPatrick Williamseach sensor: "/xyz/openbmc_project/sensor/temperature/sensor_name"
46*f4febd00SPatrick Williams
47*f4febd00SPatrick WilliamsThere is a JSON configuration file for name, old path and algorithm. For
48*f4febd00SPatrick Williamsexample,
49448ac2bdSVijay Khemka
50448ac2bdSVijay Khemka```json
51448ac2bdSVijay Khemka  {
5217c41bd5SVijay Khemka    "Desc" :
5317c41bd5SVijay Khemka    {
54448ac2bdSVijay Khemka        "Name" : "Virtual_Inlet_Temp",
5517c41bd5SVijay Khemka        "SensorType" : "temperature"
5617c41bd5SVijay Khemka    },
57448ac2bdSVijay Khemka    "Params":
58448ac2bdSVijay Khemka    {
5917c41bd5SVijay Khemka      "ConstParam" :
6017c41bd5SVijay Khemka      [
6117c41bd5SVijay Khemka        {
6217c41bd5SVijay Khemka          "ParamName" : "P1",
6317c41bd5SVijay Khemka          "Value" : 1.1
6417c41bd5SVijay Khemka        }
6517c41bd5SVijay Khemka      ],
6617c41bd5SVijay Khemka      "DbusParam" :
6717c41bd5SVijay Khemka      [
6817c41bd5SVijay Khemka        {
6917c41bd5SVijay Khemka          "ParamName" : "P2",
7017c41bd5SVijay Khemka          "Desc" :
7117c41bd5SVijay Khemka          {
7217c41bd5SVijay Khemka              "Name" : "MB_INLET_TEMP",
7317c41bd5SVijay Khemka              "SensorType" : "temperature"
7417c41bd5SVijay Khemka          }
75448ac2bdSVijay Khemka        },
7617c41bd5SVijay Khemka        {
7717c41bd5SVijay Khemka          "ParamName" : "P3",
7817c41bd5SVijay Khemka          "Desc" :
7917c41bd5SVijay Khemka          {
8017c41bd5SVijay Khemka            "Name" : "MB_FAN0_TACH",
8117c41bd5SVijay Khemka            "SensorType" : "fan_tach"
8217c41bd5SVijay Khemka          }
8317c41bd5SVijay Khemka        }
8417c41bd5SVijay Khemka      ]
8517c41bd5SVijay Khemka    },
8617c41bd5SVijay Khemka    "Expression": "P1 + P2 + 5 - P3 * 0.1",
87448ac2bdSVijay Khemka    "Thresholds":
88448ac2bdSVijay Khemka    {
89448ac2bdSVijay Khemka      "CriticalHigh": 90,
90448ac2bdSVijay Khemka      "CriticalLow": 20,
91448ac2bdSVijay Khemka      "WarningHigh": 70,
92448ac2bdSVijay Khemka      "WarningLow": 30
93448ac2bdSVijay Khemka    }
94448ac2bdSVijay Khemka  }
95448ac2bdSVijay Khemka
9617c41bd5SVijay KhemkaDesc:       It defines name and unit of a sensor. Main Desc object defines
9717c41bd5SVijay Khemka            details about new virtual sensor and inside DbusParam object,
9817c41bd5SVijay Khemka            it defines details about existing dbus sensors.
99448ac2bdSVijay KhemkaName:       Name of virtual sensor
10017c41bd5SVijay KhemkaSensorType: Unit type of sensors and supported
10117c41bd5SVijay KhemkaExpression: An algorithm to be used to calculate sensor value
10217c41bd5SVijay KhemkaParams:     There are currently 2 types of parameter supported ConstParam
10317c41bd5SVijay Khemka            and DbusParam. Every pamas should have a name to be reffered
10417c41bd5SVijay Khemka            in expression
10517c41bd5SVijay KhemkaConstParam: This is a parameter which has a constant value defined here
10617c41bd5SVijay KhemkaDbusParam:  This is an existing/virtual sensor which is listed in dbus and
10717c41bd5SVijay Khemka            it's value can be read from dbus path
108448ac2bdSVijay KhemkaThresholds: It has critical and warning high/low value to monitor sensor
109448ac2bdSVijay Khemka            value and used as per sensor interface defined in
110448ac2bdSVijay Khemka            phosphor-dbus-interfaces.
111448ac2bdSVijay Khemka
112448ac2bdSVijay Khemka```
113*f4febd00SPatrick Williams
114448ac2bdSVijay Khemka## Alternatives Considered
115*f4febd00SPatrick Williams
116448ac2bdSVijay KhemkaNone
117448ac2bdSVijay Khemka
118448ac2bdSVijay Khemka## Impacts
119*f4febd00SPatrick Williams
120*f4febd00SPatrick WilliamsThis application is monitoring existing sensors whenever they change values then
121*f4febd00SPatrick Williamsonly it will update this sensors so impact should be very minimal.
122448ac2bdSVijay Khemka
123448ac2bdSVijay Khemka## Testing
124*f4febd00SPatrick Williams
125*f4febd00SPatrick WilliamsTesting can be done by monitoring data read from dbus interface over a period of
126*f4febd00SPatrick Williamstime and also can see these data if it changes by comparing with given sensors.
127