xref: /openbmc/phosphor-state-manager/README.md (revision e56feb492ef70295d49b6856cd649c1bf13a86eb)
1d6fe3150SAndrew Geissler# Phosphor State Manager Documentation
2d6fe3150SAndrew Geissler
3d6fe3150SAndrew GeisslerThis repository contains the software responsible for tracking and controlling
42138f45cSAndrew Geisslerthe state of different objects within OpenBMC. This currently includes the BMC,
52138f45cSAndrew GeisslerChassis, Host, and Hypervisor. The most critical feature of
6c4c702c9SAndrew Geisslerphosphor-state-manager (PSM) software is its support for requests to power on
7c4c702c9SAndrew Geisslerand off the system by the user.
8d6fe3150SAndrew Geissler
9d6fe3150SAndrew GeisslerThis software also enforces any restore policy (i.e. auto power on system after
10d6fe3150SAndrew Geisslera system power event or bmc reset) and ensures its states are updated correctly
11d6fe3150SAndrew Geisslerin situations where the BMC is rebooted and the chassis or host are in
12d6fe3150SAndrew Geissleron/running states.
13d6fe3150SAndrew Geissler
14d6fe3150SAndrew GeisslerThis repository also provides a command line tool, obmcutil, which provides
15d6fe3150SAndrew Geisslerbasic command line support to query and control phosphor-state-manager
16d6fe3150SAndrew Geisslerapplications running within an OpenBMC system. This tool itself runs within an
17d6fe3150SAndrew GeisslerOpenBMC system and utilizes D-Bus APIs. These D-Bus APIs are used for
18d6fe3150SAndrew Geisslerdevelopment and debug and are not intended for end users.
19d6fe3150SAndrew Geissler
20d6fe3150SAndrew GeisslerAs with all OpenBMC applications, interfaces and properties within
211b83babfSPatrick Williamsphosphor-state-manager are D-Bus interfaces. These interfaces are then used by
221b83babfSPatrick Williamsexternal interface protocols, such as Redfish and IPMI, to report and control
231b83babfSPatrick Williamsstate to/by the end user.
24d6fe3150SAndrew Geissler
25d6fe3150SAndrew Geissler## State Tracking and Control
26d6fe3150SAndrew Geissler
27d6fe3150SAndrew Geisslerphosphor-state-manager makes extensive use of systemd. There is a writeup
28d6fe3150SAndrew Geissler[here][1] with an overview of systemd and its use by OpenBMC.
29d6fe3150SAndrew Geissler
30c4c702c9SAndrew Geisslerphosphor-state-manager monitors for systemd targets to complete as a trigger to
31c4c702c9SAndrew Geisslerupdating the its corresponding D-Bus property. When using PSM, a user must
32c4c702c9SAndrew Geisslerensure all generic services installed within the PSM targets complete
33c4c702c9SAndrew Geisslersuccessfully in order to have PSM properly report states.
34c4c702c9SAndrew Geissler
35d6fe3150SAndrew Geisslerphosphor-state-manager follows some basics design guidelines in its
36d6fe3150SAndrew Geisslerimplementation and use of systemd:
371b83babfSPatrick Williams
38d6fe3150SAndrew Geissler- Keep the different objects as independent as possible (host, chassis, bmc)
39c4c702c9SAndrew Geissler- Use systemd targets for everything and keep the code within PSM minimal
40d6fe3150SAndrew Geissler- Ensure it can support required external interfaces, but don't necessarily
41d6fe3150SAndrew Geissler  create 1x1 mappings otherwise every external interface will end up with its
42d6fe3150SAndrew Geissler  own special chassis or host state request
43d6fe3150SAndrew Geissler- If something like a hard power off can be done by just turning off the
44d6fe3150SAndrew Geissler  chassis, don't provide a command in the host to do the same thing
45d6fe3150SAndrew Geissler
46d6fe3150SAndrew Geisslerphosphor-state-manager implements states and state requests as defined in
47d6fe3150SAndrew Geisslerphosphor-dbus-interfaces for each object it supports.
481b83babfSPatrick Williams
49c4c702c9SAndrew Geissler- [bmc][2]: The BMC has very minimal states. It is `NotReady` when first started
50c4c702c9SAndrew Geissler  and `Ready` once all services within the default.target have executed. It is
51c4c702c9SAndrew Geissler  `Quiesced` when a critical service has entered the failed state. The only
52c4c702c9SAndrew Geissler  state change request you can make of the BMC is for it to reboot itself.
53c4c702c9SAndrew Geissler  - CurrentBMCState: NotReady, Ready, Quiesced
54d6fe3150SAndrew Geissler  - RequestedBMCTransition: Reboot
55c4c702c9SAndrew Geissler  - Monitored systemd targets: multi-user.target and
5614560f5bSAndrew Geissler    obmc-bmc-service-quiesce\@.target
57d6fe3150SAndrew Geissler- [chassis][3]: The chassis represents the physical hardware in which the system
58d6fe3150SAndrew Geissler  is contained. It usually has the power supplies, fans, and other hardware
59c4c702c9SAndrew Geissler  associated with it. It can be either `On`, `Off`, or in a fail state. A
60c4c702c9SAndrew Geissler  `BrownOut` state indicates there is not enough chassis power to fully power on
61c4c702c9SAndrew Geissler  and `UninterruptiblePowerSupply` indicates the chassis is running on a UPS.
62c4c702c9SAndrew Geissler  - CurrentPowerState: On, Off, BrownOut, UninterruptiblePowerSupply
63d6fe3150SAndrew Geissler  - RequestedPowerTransition: On, Off
6414560f5bSAndrew Geissler  - Monitored systemd targets: obmc-chassis-poweron\@.target,
6514560f5bSAndrew Geissler    obmc-chassis-poweroff\@.target
66d6fe3150SAndrew Geissler- [host][4]: The host represents the software running on the system. In most
67d6fe3150SAndrew Geissler  cases this is an operating system of some sort. The host can be `Off`,
681b83babfSPatrick Williams  `Running`, `TransitioningToRunning`, `TransitioningToOff`, `Quiesced`(error
691b83babfSPatrick Williams  condition), or in `DiagnosticMode`(collecting diagnostic data for a failure)
70eab2ea34SAndrew Geissler  - CurrentHostState: Off, Running, TransitioningToRunning, TransitioningToOff,
71eab2ea34SAndrew Geissler    Quiesced, DiagnosticMode
72c9844634SAndrew Geissler  - RequestedHostTransition: Off, On, Reboot, GracefulWarmReboot,
73c9844634SAndrew Geissler    ForceWarmReboot
7414560f5bSAndrew Geissler  - Monitored systemd targets: obmc-host-startmin\@.target,
7514560f5bSAndrew Geissler    obmc-host-stop\@.target, obmc-host-quiesce\@.target,
7614560f5bSAndrew Geissler    obmc-host-diagnostic-mode\@.target
772138f45cSAndrew Geissler- [hypervisor][4]: The hypervisor is an optional package systems can install
782138f45cSAndrew Geissler  which tracks the state of the hypervisor on the system. This state manager
792138f45cSAndrew Geissler  object implements a limited subset of the host D-Bus interface.
802138f45cSAndrew Geissler  - CurrentHostState: Standby, TransitionToRunning, Running, Off, Quiesced
812138f45cSAndrew Geissler  - RequestedHostTransition: On
82d6fe3150SAndrew Geissler
83c4c702c9SAndrew GeisslerAs noted above, PSM provides a command line tool, [obmcutil][5], which takes a
84c4c702c9SAndrew Geissler`state` parameter. This will use D-Bus commands to retrieve the above states and
85c4c702c9SAndrew Geisslerpresent them to the user. It also provides other commands which will send the
86c4c702c9SAndrew Geisslerappropriate D-Bus commands to the above properties to power on/off the chassis
87c4c702c9SAndrew Geisslerand host (see `obmcutil --help` within an OpenBMC system).
88d6fe3150SAndrew Geissler
89d6fe3150SAndrew GeisslerThe above objects also implement other D-Bus objects like power on hours, boot
90d6fe3150SAndrew Geisslerprogress, reboot attempts, and operating system status. These D-Bus objects are
91d6fe3150SAndrew Geissleralso defined out in the phosphor-dbus-interfaces repository.
92d6fe3150SAndrew Geissler
93d6fe3150SAndrew Geissler## Restore Policy on Power Events
94d6fe3150SAndrew Geissler
95d6fe3150SAndrew GeisslerThe [RestorePolicy][6] defines the behavior the user wants when the BMC is
961b83babfSPatrick Williamsreset. If the chassis or host is on/running then this service will not run. If
97c4c702c9SAndrew Geisslerthey are off then the `RestorePolicy` will be read and executed by PSM code.
98d6fe3150SAndrew Geissler
99*e56feb49SAndrew GeisslerThe `PowerRestoreDelay` property within the interface defines how long the
100*e56feb49SAndrew Geisslerservice will wait before issuing the power on request.
101*e56feb49SAndrew Geissler
102*e56feb49SAndrew Geissler## Only Allow System Boot When BMC Ready
103*e56feb49SAndrew Geissler
104*e56feb49SAndrew GeisslerThere is an optional `only-allow-boot-when-bmc-ready` feature which can be
105*e56feb49SAndrew Geisslerenabled within PSM that will not allow chassis or host operations (other then
106*e56feb49SAndrew Geissler`Off` requests) if the BMC is not in a `Ready` state. Care should be taken to
107*e56feb49SAndrew Geisslerensure `PowerRestoreDelay` is set to a suitable value to ensure the BMC reaches
108*e56feb49SAndrew Geissler`Ready` before the power restore function requests the power on.
109*e56feb49SAndrew Geissler
110d6fe3150SAndrew Geissler## BMC Reset with Host and/or Chassis On
111d6fe3150SAndrew Geissler
112d6fe3150SAndrew GeisslerIn situations where the BMC is reset and the chassis and host are on and
113d6fe3150SAndrew Geisslerrunning, its critical that the BMC software do two things:
1141b83babfSPatrick Williams
115d6fe3150SAndrew Geissler- Never impact the state of the system (causing a power off of a running system
116d6fe3150SAndrew Geissler  is very bad)
117d6fe3150SAndrew Geissler- Ensure the BMC, Chassis, and Host states accurately represent the state of the
118d6fe3150SAndrew Geissler  system.
119d6fe3150SAndrew Geissler
120d6fe3150SAndrew GeisslerNote that some of this logic is provided via service files in system-specific
1211b83babfSPatrick Williamsmeta layers. That is because the logic to determine if the chassis is on or if
1221b83babfSPatrick Williamsthe host is running can vary from system to system. The requirement to create
1231b83babfSPatrick Williamsthe files defined below and ensure the common targets go active is a must for
1241b83babfSPatrick Williamsanyone wishing to enable this feature.
125d6fe3150SAndrew Geissler
126d6fe3150SAndrew Geisslerphosphor-state-manager discovers state vs. trying to cache and save states. This
127d6fe3150SAndrew Geisslerensure it's always getting the most accurate state information. It discovers the
128d6fe3150SAndrew Geisslerchassis state by checking the `pgood` value from the power application. If it
129d6fe3150SAndrew Geisslerdetermines that power is on then it will do the following:
1301b83babfSPatrick Williams
131d6fe3150SAndrew Geissler- Create a file called /run/openbmc/chassis@0-on
132d6fe3150SAndrew Geissler  - The presence of this file tells the services to alter their behavior because
133d6fe3150SAndrew Geissler    the chassis is already powered on
13414560f5bSAndrew Geissler- Start the obmc-chassis-poweron\@0.target
135d6fe3150SAndrew Geissler  - The majority of services in this target will "fake start" due to the file
136d6fe3150SAndrew Geissler    being present. They will report to systemd that they started and ran
137d6fe3150SAndrew Geissler    successfully but they actually do nothing. This is what you would want in
138d6fe3150SAndrew Geissler    this case. Power is already on so you don't want to run the services to turn
13914560f5bSAndrew Geissler    power on. You do want to get the obmc-chassis-poweron\@0.target in the
14014560f5bSAndrew Geissler    Active state though so that the chassis object within PSM will correctly
14114560f5bSAndrew Geissler    report that the chassis is `On`
142d6fe3150SAndrew Geissler- Start a service to check if the host is on
143d6fe3150SAndrew Geissler
14414560f5bSAndrew GeisslerThe chassis@0-on file is removed once the obmc-chassis-poweron\@0.target becomes
1454a4c1a69SAndrew Geissleractive (i.e. all service have been successfully started which are wanted or
1464a4c1a69SAndrew Geisslerrequired by this target).
147d6fe3150SAndrew Geissler
148d6fe3150SAndrew GeisslerThe logic to check if the host is on sends a command to the host, and if a
149d6fe3150SAndrew Geisslerresponse is received then similar logic to chassis is done:
1501b83babfSPatrick Williams
151d6fe3150SAndrew Geissler- Create a file called /run/openbmc/host@0-on
15214560f5bSAndrew Geissler- Start the obmc-host-start\@0.target
153d6fe3150SAndrew Geissler  - Similar to above, most services will not run due to the file being created
154d6fe3150SAndrew Geissler    and their service files implementing a
155d6fe3150SAndrew Geissler    "ConditionPathExists=!/run/openbmc/host@0-request"
156d6fe3150SAndrew Geissler
15714560f5bSAndrew GeisslerThe host@0-on file is removed once the obmc-host-start\@0.target and
15814560f5bSAndrew Geisslerobmc-host-startmin\@0.target become active (i.e. all service have been
1594a4c1a69SAndrew Geisslersuccessfully started which are wanted or required by these targets).
160d6fe3150SAndrew Geissler
161d6fe3150SAndrew Geissler## Building the Code
1621b83babfSPatrick Williams
1634640d48eSAndrew GeisslerTo build this package, do the following steps:
1644640d48eSAndrew Geissler
16582f23534SPatrick Williams1. `meson setup build`
16682f23534SPatrick Williams2. `ninja -C build`
1674640d48eSAndrew Geissler
1684640d48eSAndrew GeisslerTo clean the repository again run `rm -rf build`.
169d6fe3150SAndrew Geissler
170a6e7bbf0SGunnar Mills[1]: https://github.com/openbmc/docs/blob/master/architecture/openbmc-systemd.md
1711b83babfSPatrick Williams[2]:
1721b83babfSPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/BMC.interface.yaml
1731b83babfSPatrick Williams[3]:
1741b83babfSPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/Chassis.interface.yaml
1751b83babfSPatrick Williams[4]:
1761b83babfSPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/State/Host.interface.yaml
177d6fe3150SAndrew Geissler[5]: https://github.com/openbmc/phosphor-state-manager/blob/master/obmcutil
1781b83babfSPatrick Williams[6]:
1791b83babfSPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Control/Power/RestorePolicy.interface.yaml
180