3

I have a Debian Buster system which has the Kernel compiled without the CONFIG_RTC_SYSTOHC since I DO NOT want the 11-minute kernel mode to be on. However, I wanted to check if this change actually worked.

So I checked the status field from the output of adjtimex --print command. The status field is 24577 or 0b110000000000001.

According to the man page here - https://linux.die.net/man/8/adjtimex, it seems that the 64 bit of the status field is not set, which according to here: https://access.redhat.com/solutions/55432 means that the 11-minute mode is on.

This is contradictory to what I expected when I compiled the kernel with the CONFIG_RTC_SYSTOHC as not set. How can I reliably check if the 11-minute mode is actually turned off, or am I interpreting the output of adjtimex incorrectly?

1 Answer 1

6

(Just to clear possible confusion by anyone reading this answer: when Linux is running, there are (usually) two clocks: the "main" clock is the system clock, which is usually CPU-based. The other clock is the persistent hardware clock (RTC). When the system is shut down, the system clock loses its time and only the persistent hardware clock keeps the correct wall-clock time.)

The primary meaning of the 64 bit of the status field of adjtimex is "the system clock is/is not being synchronized by NTP or other time source". The 11-minute mode used to be tightly coupled to that: if the system clock was being syncronized, then the RTC would be updated every 11 minutes; if not, then it wouldn't be.

The option to disable system clock-to-RTC transfer every 11 minutes by CONFIG_RTC_SYSTOHC was a later addition.

Disabling CONFIG_RTC_SYSTOHC cuts the connection between the system clock synchronization and RTC 11-minute updates. You can check the relevant kernel source code, which in Debian Buster's standard 4.19.xx kernel is the function sync_rtc_clock() in kernel/time/ntp.c at line #532. You can see that when CONFIG_RTC_SYSTOHC is not set, the function returns early without doing anything:

static void sync_rtc_clock(void)
{
    unsigned long target_nsec;
    struct timespec64 adjust, now;
    int rc;

    if (!IS_ENABLED(CONFIG_RTC_SYSTOHC))   <--- If CONFIG_RTC_SYSTOHC is not enabled,
        return;                           <--- return immediately.

    ktime_get_real_ts64(&now);

    adjust = now;
    if (persistent_clock_is_local)
        adjust.tv_sec -= (sys_tz.tz_minuteswest * 60);

    /*
     * The current RTC in use will provide the target_nsec it wants to be
     * called at, and does rtc_tv_nsec_ok internally.
     */
    rc = rtc_set_ntp_time(adjust, &target_nsec);
    if (rc == -ENODEV)
        return;

    sched_sync_hw_clock(now, target_nsec, rc);
}

In other words, disabling CONFIG_RTC_SYSTOHC makes the 11-minute mode effectively a no-op.

More experimentally, you could use the kernel profiling tools to monitor the rtc_set_time() function over a suitable multiple of 11 minutes and see how often it gets called. If you find the answer is 0 times, you'll know that the hardware RTC clock is not being adjusted by 11-minute mode nor by anything else.

3
  • +1! Does CONFIG_RTC_SYSTOHC = n disable the 11-minute mode only or does this as well disable the sync at shutdown time as possibly requested in /etc/conf.d/hwclock by a statement clock_systohc="YES" ? Commented Feb 28, 2022 at 10:37
  • Or even running hwclock --systohc ? Commented Feb 28, 2022 at 10:47
  • 2
    @MC68020 The CONFIG_RTC_SYSTOHC only controls the effect of kernel 11-minute mode; it is not a generic "write protection switch" for the RTC. As the sync at shutdown and any explicit hwclock --systohc are user-space operations that require root permissions anyway, the administrator can always opt to not do those operations in the first place, e.g. by setting the clock_systohc in the /etc/conf.d/hwclock file you mentioned to "no", and by otherwise choosing to not run hwclock --systohc. Commented Feb 28, 2022 at 10:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.