[systemd-devel] use RTC date/time to set system date time

Lennart Poettering lennart at poettering.net
Mon Mar 1 15:59:13 UTC 2021


On Mo, 01.03.21 14:52, Michał Zegan (webczat_200 at poczta.onet.pl) wrote:

> Someone should really find a way to make it cooperate well with modular
> rtcs.
> It's popping up over and over and over and over again and no one is/will
> build all rtc drivers into the kernel.

To my knowledge the kernel these days can also sync from the RTC if
the RTC is loaded as module, as long as the device is named "rtc0".

But this stuff is racy of course if the RTC is compiled as module and
you care for generic hw, that might or might not have an RTC: we
cannot gues swhether an RTC will show up or not in that case,
i.e. whether there is an RTC connected and whether there's a driver
for it. Hence we time-{set|sync}.target cannot possibly wait for it to
show up since it might mean we have to wait indefinitely...

My recommendation: if you have embedded hw you should kow your hw,
hence compile it in. Time is such a basic concept, it's something that
should just work, and not require userspace interference to work.

If you really don't want to compile it in, and love the extra
headaches this involves, then make sure you run a recent kernel that
can sync the system clock to RTC even when the module is loaded
later. And then manually add an ordering dep to time-set.target to
wait for /dev/rtc0, since that is the target that should be delayed
until the RTC shows up and is probed:

    mkdir -p /etc/systemd/system/time-set.target.d
    cat > /etc/systemd/system/time-set.target.d/wait-for-rtc0.conf <<EOF
    [Unit]
    Wants=dev-rtc0.device
    After=dev-rtc0.device
    EOF

And:

    mkdir -p /etc/udev/rules.d/
    cat > /etc/udev/rules.d/70-rtc-systemd.rules <<EOF
    ACTION!="remove",SUBSYSTEM=="rtc",TAG+="systemd"
    EOF

i.e. the latter makes sure there are .device units for your /dev/rtc
devices, the former then tells time-set.target to wait for it to show
up.

(both untested, ymmv)

And yes, you need to do this manually on your system. We cannot
possibly know whether it's worth waiting for an RTC or not,
generically.

But really, just figure out what your hw is and link the driver into
the kernel. It saves you a lot of headaches, and kernel timestamps
won't be crap initially.

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list