How openbmc/phosphor-state-manager works
Project Type and Purpose
• This is a system‐level daemon suite for OpenBMC called “phosphor-state-manager” (PSM). It is not a web app or microservices platform but a collection of C++ daemons that track and control hardware/OS states (BMC, chassis, host, hypervisor). It integrates tightly with systemd and D-Bus, exposes state via D-Bus interfaces, and provides a CLI tool (obmcutil) for debugging.
File‐Structure Analysis
Top‐level
• C++ source files (*.cpp, *.hpp) and Meson build files (meson.build, meson.options)
• obmcutil CLI binary source
• Service/target unit definitions under service_files/ and target_files/
• Configuration and defaults in data/
• Helper scripts in scripts/
Subcomponents
• One state manager per object: bmc_state_manager, chassis_state_manager, host_state_manager, hypervisor_state_manager, plus auxiliary daemons like discover_system_state, scheduled_host_transition, host_condition_gpio
• Systemd abstractions: service parser, target parser/signals
• Tests under test/
• Third‐party libs in subprojects/
Key Architectural Insights from README
• PSM uses systemd targets as triggers: targets represent power‐on/off workflows.
• Each state manager monitors specific targets, updates its D-Bus property when targets transition.
• Restore policies and conditional boot‐when‐BMC‐ready are implemented by PSM code coordinating systemd.
• D-Bus is the control API; external interfaces (Redfish, IPMI) sit above D-Bus.
• CLI tool (obmcutil) calls into these same D-Bus interfaces.
• Hardware interactions: chassis “pgood” sensor, host via GPIO or host controller commands.
• Hardware Layer
– Chassis Power Supply & Sensors (pgood)
– Host Board (OS, “host on” signal)
• systemd Orchestration Layer
– Service Units (phosphor-* services)
– Target Units (obmc-chassis-poweron@.target, obmc-host-start@.target, etc.)
• phosphor‐state‐manager Daemons
– bmc_state_manager
– chassis_state_manager
– host_state_manager
– hypervisor_state_manager
– discover_system_state, scheduled_host_transition, host_condition_gpio
• D‐Bus IPC Layer
– xyz.openbmc_project.State.* interfaces
– RestorePolicy interface
• Control & External Interfaces
– obmcutil CLI
– Redfish/IPMI adapter daemons (outside repo)
1. On boot, systemd fires default.target → PSM daemons register for target‐complete signals
2. Target completion → DBus signals → PSM updates D-Bus state properties
3. PSM receiving a state‐request (via D-Bus) → invokes systemd StartUnit on corresponding target
4. systemd starts service units → they perform hardware actions (turn on PSU, manipulate GPIO)
5. Hardware feedback (pgood, GPIO read) → discover_system_state or host_condition_gpio → signals back via D-Bus
6. obmcutil ↔ D-Bus → queries or requests state transitions
c. Architectural Patterns & Principles
• Event-driven: systemd events drive state transitions
• Separation of concerns: one daemon per managed object
• Minimal code: use systemd targets for orchestration, keep PSM logic lean
• Discover, don’t cache: read true hardware state at run time
d. Key Technologies & Frameworks
• C++17, Meson/Ninja build
• sdbusplus / phosphor‐dbus‐interfaces
• systemd (units, targets)
• JSON for default configurations (data/*.json)
• GoogleTest for unit tests
Essential Elements to Capture
• Per‐object daemons and their monitored targets
• systemd’s role as workflow engine
• D-Bus interface layer and external API consumers
• Hardware feedback loops (pgood, GPIO)
• Config/data inputs (JSON defaults, meson options)