xref: /openbmc/phosphor-state-manager/README.md (revision d6fe3150e1949fbada806d271644eb7590535047)
1*d6fe3150SAndrew Geissler# Phosphor State Manager Documentation
2*d6fe3150SAndrew Geissler
3*d6fe3150SAndrew GeisslerThis repository contains the software responsible for tracking and controlling
4*d6fe3150SAndrew Geisslerthe state of different objects within OpenBMC. This currently includes the
5*d6fe3150SAndrew GeisslerBMC, Chassis, and Host. The most critical feature of phosphor-state-manager
6*d6fe3150SAndrew Geisslersoftware is its support for requests to power on and off the system by the user.
7*d6fe3150SAndrew Geissler
8*d6fe3150SAndrew GeisslerThis software also enforces any restore policy (i.e. auto power on system after
9*d6fe3150SAndrew Geisslera system power event or bmc reset) and ensures its states are updated correctly
10*d6fe3150SAndrew Geisslerin situations where the BMC is rebooted and the chassis or host are in
11*d6fe3150SAndrew Geissleron/running states.
12*d6fe3150SAndrew Geissler
13*d6fe3150SAndrew GeisslerThis repository also provides a command line tool, obmcutil, which provides
14*d6fe3150SAndrew Geisslerbasic command line support to query and control phosphor-state-manager
15*d6fe3150SAndrew Geisslerapplications running within an OpenBMC system. This tool itself runs within an
16*d6fe3150SAndrew GeisslerOpenBMC system and utilizes D-Bus APIs. These D-Bus APIs are used for
17*d6fe3150SAndrew Geisslerdevelopment and debug and are not intended for end users.
18*d6fe3150SAndrew Geissler
19*d6fe3150SAndrew GeisslerAs with all OpenBMC applications, interfaces and properties within
20*d6fe3150SAndrew Geisslerphosphor-state-manager are D-Bus interfaces. These interfaces are then used
21*d6fe3150SAndrew Geisslerby external interface protocols, such as Redfish and IPMI, to report and
22*d6fe3150SAndrew Geisslercontrol state to/by the end user.
23*d6fe3150SAndrew Geissler
24*d6fe3150SAndrew Geissler## State Tracking and Control
25*d6fe3150SAndrew Geissler
26*d6fe3150SAndrew Geisslerphosphor-state-manager makes extensive use of systemd. There is a writeup
27*d6fe3150SAndrew Geissler[here][1] with an overview of systemd and its use by OpenBMC.
28*d6fe3150SAndrew Geissler
29*d6fe3150SAndrew Geisslerphosphor-state-manager follows some basics design guidelines in its
30*d6fe3150SAndrew Geisslerimplementation and use of systemd:
31*d6fe3150SAndrew Geissler- Keep the different objects as independent as possible (host, chassis, bmc)
32*d6fe3150SAndrew Geissler- Use systemd targets for everything and keep the code within
33*d6fe3150SAndrew Geissler  phosphor-state-manager minimal
34*d6fe3150SAndrew Geissler- Ensure it can support required external interfaces, but don't necessarily
35*d6fe3150SAndrew Geissler  create 1x1 mappings otherwise every external interface will end up with its
36*d6fe3150SAndrew Geissler  own special chassis or host state request
37*d6fe3150SAndrew Geissler- If something like a hard power off can be done by just turning off the
38*d6fe3150SAndrew Geissler  chassis, don't provide a command in the host to do the same thing
39*d6fe3150SAndrew Geissler
40*d6fe3150SAndrew Geisslerphosphor-state-manager implements states and state requests as defined in
41*d6fe3150SAndrew Geisslerphosphor-dbus-interfaces for each object it supports.
42*d6fe3150SAndrew Geissler- [bmc][2]: The BMC has very minimal states. It is `Ready` once all services
43*d6fe3150SAndrew Geissler  within the default.target have executed. The only state change request you
44*d6fe3150SAndrew Geissler  can make of the BMC is for it to reboot itself.
45*d6fe3150SAndrew Geissler  - CurrentBMCState: NotReady, Ready
46*d6fe3150SAndrew Geissler  - RequestedBMCTransition: Reboot
47*d6fe3150SAndrew Geissler- [chassis][3]: The chassis represents the physical hardware in which the system
48*d6fe3150SAndrew Geissler  is contained. It usually has the power supplies, fans, and other hardware
49*d6fe3150SAndrew Geissler  associated with it. It can be either `On` or `Off`.
50*d6fe3150SAndrew Geissler  - CurrentPowerState: On, Off
51*d6fe3150SAndrew Geissler  - RequestedPowerTransition: On, Off
52*d6fe3150SAndrew Geissler- [host][4]: The host represents the software running on the system. In most
53*d6fe3150SAndrew Geissler  cases this is an operating system of some sort. The host can be `Off`,
54*d6fe3150SAndrew Geissler  `Running`, or `Quiesced`(error condition)
55*d6fe3150SAndrew Geissler  - CurrentHostState: Off, Running, Quiesced
56*d6fe3150SAndrew Geissler  - RequestedHostTransition: Off, On, Reboot
57*d6fe3150SAndrew Geissler
58*d6fe3150SAndrew GeisslerAs noted above, phosphor-state-manager provides a command line tool,
59*d6fe3150SAndrew Geissler[obmcutil][5], which takes a `state` parameter. This will use D-Bus commands to
60*d6fe3150SAndrew Geisslerretrieve the above states and present them to the user. It also provides other
61*d6fe3150SAndrew Geisslercommands which will send the appropriate D-Bus commands to the above properties
62*d6fe3150SAndrew Geisslerto power on/off the chassis and host (see `obmcutil --help` within an OpenBMC
63*d6fe3150SAndrew Geisslersystem).
64*d6fe3150SAndrew Geissler
65*d6fe3150SAndrew GeisslerThe above objects also implement other D-Bus objects like power on hours, boot
66*d6fe3150SAndrew Geisslerprogress, reboot attempts, and operating system status. These D-Bus objects are
67*d6fe3150SAndrew Geissleralso defined out in the phosphor-dbus-interfaces repository.
68*d6fe3150SAndrew Geissler
69*d6fe3150SAndrew Geissler## Restore Policy on Power Events
70*d6fe3150SAndrew Geissler
71*d6fe3150SAndrew GeisslerThe [RestorePolicy][6] defines the behavior the user wants when the BMC is
72*d6fe3150SAndrew Geisslerreset. If the chassis or host is on/running then this service will not run.
73*d6fe3150SAndrew GeisslerIf they are off then the `RestorePolicy` will be read and executed by
74*d6fe3150SAndrew Geisslerphosphor-state-manager code.
75*d6fe3150SAndrew Geissler
76*d6fe3150SAndrew Geissler## BMC Reset with Host and/or Chassis On
77*d6fe3150SAndrew Geissler
78*d6fe3150SAndrew GeisslerIn situations where the BMC is reset and the chassis and host are on and
79*d6fe3150SAndrew Geisslerrunning, its critical that the BMC software do two things:
80*d6fe3150SAndrew Geissler- Never impact the state of the system (causing a power off of a running system
81*d6fe3150SAndrew Geissleris very bad)
82*d6fe3150SAndrew Geissler- Ensure the BMC, Chassis, and Host states accurately represent the state of the
83*d6fe3150SAndrew Geisslersystem.
84*d6fe3150SAndrew Geissler
85*d6fe3150SAndrew GeisslerNote that some of this logic is provided via service files in system-specific
86*d6fe3150SAndrew Geisslermeta layers. That is because the logic to determine if the chassis is on or
87*d6fe3150SAndrew Geisslerif the host is running can vary from system to system. The requirement to
88*d6fe3150SAndrew Geisslercreate the files defined below and ensure the common targets go active is a
89*d6fe3150SAndrew Geisslermust for anyone wishing to enable this feature.
90*d6fe3150SAndrew Geissler
91*d6fe3150SAndrew Geisslerphosphor-state-manager discovers state vs. trying to cache and save states. This
92*d6fe3150SAndrew Geisslerensure it's always getting the most accurate state information. It discovers the
93*d6fe3150SAndrew Geisslerchassis state by checking the `pgood` value from the power application. If it
94*d6fe3150SAndrew Geisslerdetermines that power is on then it will do the following:
95*d6fe3150SAndrew Geissler- Create a file called /run/openbmc/chassis@0-on
96*d6fe3150SAndrew Geissler  - The presence of this file tells the services to alter their behavior because
97*d6fe3150SAndrew Geissler    the chassis is already powered on
98*d6fe3150SAndrew Geissler- Start the obmc-chassis-poweron@0.target
99*d6fe3150SAndrew Geissler  - The majority of services in this target will "fake start" due to the file
100*d6fe3150SAndrew Geissler    being present. They will report to systemd that they started and ran
101*d6fe3150SAndrew Geissler    successfully but they actually do nothing. This is what you would want in
102*d6fe3150SAndrew Geissler    this case. Power is already on so you don't want to run the services to turn
103*d6fe3150SAndrew Geissler    power on. You do want to get the obmc-chassis-poweron@0.target in the Active
104*d6fe3150SAndrew Geissler    state though so that the chassis object within phosphor-state-manager will
105*d6fe3150SAndrew Geissler    correctly report that the chassis is `On`
106*d6fe3150SAndrew Geissler- Start a service to check if the host is on
107*d6fe3150SAndrew Geissler
108*d6fe3150SAndrew GeisslerThe chassis@0-on file is removed when power is removed from the chassis.
109*d6fe3150SAndrew Geissler
110*d6fe3150SAndrew GeisslerThe logic to check if the host is on sends a command to the host, and if a
111*d6fe3150SAndrew Geisslerresponse is received then similar logic to chassis is done:
112*d6fe3150SAndrew Geissler- Create a file called /run/openbmc/host@0-on
113*d6fe3150SAndrew Geissler- Start the obmc-host-start@0.target
114*d6fe3150SAndrew Geissler  - Similar to above, most services will not run due to the file being created
115*d6fe3150SAndrew Geissler    and their service files implementing a
116*d6fe3150SAndrew Geissler    "ConditionPathExists=!/run/openbmc/host@0-request"
117*d6fe3150SAndrew Geissler
118*d6fe3150SAndrew GeisslerThe host@0-on file is removed when the host is stopped.
119*d6fe3150SAndrew Geissler
120*d6fe3150SAndrew Geissler## Building the Code
121*d6fe3150SAndrew Geissler```
122*d6fe3150SAndrew Geissler./bootstrap.sh
123*d6fe3150SAndrew Geissler./configure ${CONFIGURE_FLAGS} && make
124*d6fe3150SAndrew Geissler```
125*d6fe3150SAndrew Geissler
126*d6fe3150SAndrew Geissler[1]: https://github.com/openbmc/docs/blob/master/openbmc-systemd.md
127*d6fe3150SAndrew Geissler[2]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/State/BMC.interface.yaml
128*d6fe3150SAndrew Geissler[3]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/State/Chassis.interface.yaml
129*d6fe3150SAndrew Geissler[4]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/State/Host.interface.yaml
130*d6fe3150SAndrew Geissler[5]: https://github.com/openbmc/phosphor-state-manager/blob/master/obmcutil
131*d6fe3150SAndrew Geissler[6]: https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Control/Power/RestorePolicy.interface.yaml
132