]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ptp: ptp_vmclock: return TAI not UTC
authorDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 30 Jan 2026 17:36:06 +0000 (17:36 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 3 Feb 2026 02:06:01 +0000 (18:06 -0800)
To output UTC would involve complex calculations about whether the time
elapsed since the reference time has crossed the end of the month when
a leap second takes effect. I've prototyped that, but it made me sad.

Much better to report TAI, which is what PHCs should do anyway.
And much much simpler.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Tested-by: Takahiro Itazuri <itazur@amazon.com>
Link: https://patch.msgid.link/20260130173704.12575-8-itazur@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/ptp/ptp_vmclock.c

index b6e9d4c96ba0be3f52f5c47da3e60b4062276e4a..c7c75e19f4dd838cf6450f8fa2a2bd53c542223c 100644 (file)
@@ -83,13 +83,13 @@ static uint64_t mul_u64_u64_shr_add_u64(uint64_t *res_hi, uint64_t delta,
 
 static bool tai_adjust(struct vmclock_abi *clk, uint64_t *sec)
 {
-       if (likely(clk->time_type == VMCLOCK_TIME_UTC))
+       if (clk->time_type == VMCLOCK_TIME_TAI)
                return true;
 
-       if (clk->time_type == VMCLOCK_TIME_TAI &&
+       if (clk->time_type == VMCLOCK_TIME_UTC &&
            (le64_to_cpu(clk->flags) & VMCLOCK_FLAG_TAI_OFFSET_VALID)) {
                if (sec)
-                       *sec += (int16_t)le16_to_cpu(clk->tai_offset_sec);
+                       *sec -= (int16_t)le16_to_cpu(clk->tai_offset_sec);
                return true;
        }
        return false;
@@ -350,9 +350,9 @@ static struct ptp_clock *vmclock_ptp_register(struct device *dev,
                return NULL;
        }
 
-       /* Only UTC, or TAI with offset */
+       /* Accept TAI directly, or UTC with valid offset for conversion to TAI */
        if (!tai_adjust(st->clk, NULL)) {
-               dev_info(dev, "vmclock does not provide unambiguous UTC\n");
+               dev_info(dev, "vmclock does not provide unambiguous time\n");
                return NULL;
        }