xref: /openbmc/phosphor-time-manager/README.md (revision a37e123008c50b28a520b531df3542f45067636b)
16903277cSLei YU# Introduction
2e81151feSPatrick Williams
3383b7120SGunnar Mills`phosphor-time-manager` is the time manager service that implements D-Bus
4e81151feSPatrick Williamsinterface `xyz/openbmc_project/Time/EpochTime.interface.yaml`. The user can get
5e81151feSPatrick Williamsor set the BMC's time via this interface.
6d04eeabbSRatan Gupta
7d04eeabbSRatan Gupta## Configuration
8d04eeabbSRatan Gupta
9e81151feSPatrick Williamsphosphor-time-manager is configured by setting `-D` flags that correspond to
10*a37e1230SGeorge Liuoptions in `phosphor-time-manager/meson.options`. The option names become C++
11*a37e1230SGeorge Liupreprocessor symbols that control which code is compiled into the program.
12e81151feSPatrick Williams
13e81151feSPatrick Williams- Compile phosphor-time-manager with default options:
14d04eeabbSRatan Gupta
153a87010dSGeorge Liu  ```bash
166facad52SPavithra Barithaya     meson setup builddir
17d04eeabbSRatan Gupta     ninja -C builddir
18d04eeabbSRatan Gupta  ```
19e81151feSPatrick Williams
20e81151feSPatrick Williams- Compile phosphor-time-manager with some configurable options:
21d04eeabbSRatan Gupta
223a87010dSGeorge Liu  ```bash
236facad52SPavithra Barithaya     meson setup builddir -Dbuildtype=minsize  -Dtests=disabled
24dd42c7faSPavithra Barithaya     ninja -C builddir
25d04eeabbSRatan Gupta  ```
26e81151feSPatrick Williams
27e81151feSPatrick Williams- Generate test coverage report:
28d04eeabbSRatan Gupta
293a87010dSGeorge Liu  ```bash
306facad52SPavithra Barithaya     meson setup builddir -Db_coverage=true -Dtests=enabled
31d04eeabbSRatan Gupta     ninja coverage -C builddir test
32d04eeabbSRatan Gupta  ```
33d04eeabbSRatan Gupta
346903277cSLei YU### General usage
35e81151feSPatrick Williams
363c2f4496SGeorge LiuThe service `xyz.openbmc_project.Time.Manager` provides an object on D-Bus:
37e81151feSPatrick Williams
38e81151feSPatrick Williams- /xyz/openbmc_project/time/bmc
396903277cSLei YU
406903277cSLei YUwhere each object implements interface `xyz.openbmc_project.Time.EpochTime`.
416903277cSLei YU
42e81151feSPatrick WilliamsThe user can directly get or set the property `Elapsed` of the objects to get or
43e81151feSPatrick Williamsset the time. For example on an authenticated session:
446903277cSLei YU
45e81151feSPatrick Williams- To get BMC's time:
46e81151feSPatrick Williams
473a87010dSGeorge Liu  ```bash
486903277cSLei YU  ### With busctl on BMC
496903277cSLei YU  busctl get-property xyz.openbmc_project.Time.Manager \
506903277cSLei YU      /xyz/openbmc_project/time/bmc xyz.openbmc_project.Time.EpochTime Elapsed
516903277cSLei YU
526903277cSLei YU  ### With REST API on remote host
53a111b9f3SAndrew Geissler  curl -b cjar -k https://${BMC_IP}/xyz/openbmc_project/time/bmc
546903277cSLei YU  ```
55e81151feSPatrick Williams
56e81151feSPatrick Williams- To set BMC's time:
57e81151feSPatrick Williams
583a87010dSGeorge Liu  ```bash
596903277cSLei YU  ### With busctl on BMC
606903277cSLei YU  busctl set-property xyz.openbmc_project.Time.Manager \
613c2f4496SGeorge Liu      /xyz/openbmc_project/time/bmc xyz.openbmc_project.Time.EpochTime \
626903277cSLei YU      Elapsed t <value-in-microseconds>
636903277cSLei YU
646903277cSLei YU  ### With REST API on remote host
656903277cSLei YU  curl -b cjar -k -H "Content-Type: application/json" -X PUT \
666903277cSLei YU      -d '{"data": 1487304700000000}' \
673c2f4496SGeorge Liu      https://${BMC_IP}/xyz/openbmc_project/time/bmc/attr/Elapsed
686903277cSLei YU  ```
696903277cSLei YU
706903277cSLei YU### Time settings
716903277cSLei YU
72e81151feSPatrick WilliamsGetting BMC time is always allowed, but setting the time may not be allowed
73e81151feSPatrick Williamsdepending on the below two settings in the settings manager.
74e81151feSPatrick Williams
75e81151feSPatrick Williams- TimeSyncMethod
76e81151feSPatrick Williams  - NTP: The time is set via NTP server.
77e81151feSPatrick Williams  - MANUAL: The time is set manually.
786903277cSLei YU
796903277cSLei YUA summary of which cases the time can be set on BMC or HOST:
807d05550dSLei YU
81e81151feSPatrick Williams| Mode   | Set BMC Time |
82e81151feSPatrick Williams| ------ | ------------ |
83e81151feSPatrick Williams| NTP    | Fail to set  |
84e81151feSPatrick Williams| MANUAL | OK           |
856903277cSLei YU
86e81151feSPatrick Williams- To set an NTP [server](https://tf.nist.gov/tf-cgi/servers.cgi):
87e81151feSPatrick Williams
883a87010dSGeorge Liu  ```bash
89a111b9f3SAndrew Geissler  ### With busctl on BMC
90a111b9f3SAndrew Geissler  busctl set-property  xyz.openbmc_project.Network \
91a111b9f3SAndrew Geissler     /xyz/openbmc_project/network/eth0 \
92a111b9f3SAndrew Geissler     xyz.openbmc_project.Network.EthernetInterface NTPServers \
93a111b9f3SAndrew Geissler     as 1 "<ntp_server>"
94a111b9f3SAndrew Geissler
95a111b9f3SAndrew Geissler  ### With REST API on remote host
96a111b9f3SAndrew Geissler  curl -c cjar -b cjar -k -H "Content-Type: application/json" -X  PUT  -d \
97a111b9f3SAndrew Geissler      '{"data": ["<ntp_server>"] }' \
98a111b9f3SAndrew Geissler      https://${BMC_IP}/xyz/openbmc_project/network/eth0/attr/NTPServers
99a111b9f3SAndrew Geissler  ```
100a111b9f3SAndrew Geissler
101e81151feSPatrick Williams- To go into NTP mode
102e81151feSPatrick Williams
1033a87010dSGeorge Liu  ```bash
104a111b9f3SAndrew Geissler  ### With busctl on BMC
105a111b9f3SAndrew Geissler  busctl set-property xyz.openbmc_project.Settings \
106a111b9f3SAndrew Geissler      /xyz/openbmc_project/time/sync_method xyz.openbmc_project.Time.Synchronization \
107a111b9f3SAndrew Geissler      TimeSyncMethod s "xyz.openbmc_project.Time.Synchronization.Method.NTP"
108a111b9f3SAndrew Geissler
109a111b9f3SAndrew Geissler  ### With REST API on remote host
110a111b9f3SAndrew Geissler  curl -c cjar -b cjar -k -H "Content-Type: application/json" -X  PUT  -d \
111a111b9f3SAndrew Geissler      '{"data": "xyz.openbmc_project.Time.Synchronization.Method.NTP" }' \
112a111b9f3SAndrew Geissler      https://${BMC_IP}/xyz/openbmc_project/time/sync_method/attr/TimeSyncMethod
113a111b9f3SAndrew Geissler  ```
114a111b9f3SAndrew Geissler
115a8741b56SLei YU### Special note on changing NTP setting
116e81151feSPatrick Williams
117e81151feSPatrick WilliamsStarting from OpenBMC 2.6 (with systemd v239), systemd's timedated introduces a
118e81151feSPatrick Williamsnew beahvior that it checks the NTP services' status during setting time,
119a8741b56SLei YUinstead of checking the NTP setting:
120a8741b56SLei YU
121e81151feSPatrick Williams- When NTP server is set to disabled, and the NTP service is stopping but not
122a8741b56SLei YU  stopped, setting time will get an error.
123a8741b56SLei YU
124a8741b56SLei YUIn OpenBMC 2.4 (with systemd v236), the above will always succeed.
125a8741b56SLei YU
126a8741b56SLei YUThis results in [openbmc/openbmc#3459][1], and the related test cases are
127a8741b56SLei YUupdated to cooperate with this behavior change.
128a8741b56SLei YU
129a8741b56SLei YU[1]: https://github.com/openbmc/openbmc/issues/3459
130