From patchwork Thu Jul 12 20:17:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 141836 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1932132ljj; Thu, 12 Jul 2018 13:17:27 -0700 (PDT) X-Received: by 2002:a62:c410:: with SMTP id y16-v6mr3855369pff.161.1531426647095; Thu, 12 Jul 2018 13:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531426647; cv=none; d=google.com; s=arc-20160816; b=FvectAYJy5YktIhIKS6ARE7FhcrNDfYq/7YddgkNacX7LfXBwpFVUWRflIQ4nsoJkk Jc2olPf3A9gmWwbSG7HCU2SRjYCKUQwZC0+QbKBNQMa643PqSjF4HuC8ZF3EwuWZu487 Fwwj5D3l0E1LHlrHSUk2wgNRt11ZALOGZNVzd5ZJL53ONGkFNf+Xpee6JqTmoUJ/aarn Sh7Q84RuPKS5yv7qebSDBhoLYJnswEKpH5yFaQ62HKLOKVLQkLhzYWGHc+1XpbziNGwe Pqw+pKDjfwnIEqLH3J5riylcSyMhZGBDVgJ2RMJ7Hjm8ulMYLe7FIrUbZhJdYahcTQ+Z GK9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=dAwq1mkAVXiY0/cfgYJalGRPhrDv9DLxOQ4uYGDmhxI=; b=RWzNaJ56qEX0rDJn9jeK+lTHHns6DwRW/J+VXxgnIZb6D0uT3gjIIz5GS8bE4y3Nqp XiFnqga/qo8xKJM3HpCeYpZC9UHO0gfW8gvOx/60ChibMNcyIFgum6rSXPyPfEeGMGZy lsyc5kCzojrxS9uYHTabPE+BM7H2fZqU5hz4vXwQz08OQ2F43ALs7gvILyox0k9zlxF/ Wyf59Hu3lsj7FA3z2xPxUa1caUKqMLcKuUQe5jiew3rLVoenbyfenc03frLs8sgiMxBt 7iG1j+Sef9wIfXHZhPeai0xJGEc7aMuwUhoE/0r9iTkq0FjIXQ3bZR3VqC96NbwdXHZp hAoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jOsn/rV2"; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s3-v6sor2190776pgn.405.2018.07.12.13.17.26 for (Google Transport Security); Thu, 12 Jul 2018 13:17:27 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jOsn/rV2"; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dAwq1mkAVXiY0/cfgYJalGRPhrDv9DLxOQ4uYGDmhxI=; b=jOsn/rV269hQMYahSiYnGT0KhcbsEoeFGeTe9e1CA1Z7T7K9amJ4xyA3/4wDXr4YjN YJbM2THUiDBHdGyZureu1f5z3XWdnM9asZhCWrKOzY1TZQuZzxPGA1zLsatvGBE3McNU KbXWA6SF0W09rwSf78pD9JMUD8lt+IfJTlyvQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dAwq1mkAVXiY0/cfgYJalGRPhrDv9DLxOQ4uYGDmhxI=; b=pwLYLUsV28VomzAB2SH+xXk7r6qSuVJrLDepokzyFJ0QLTVlEse4E1jPhr6cXqz1T3 LbrUZj2bCb0i4kchmHNiTs+CMGPSQpQrImKjR2gGZ/ZKQdsZqVJ9EqcJuGblgH3gmmUt 8WnrlxZeTdE51EbITRSclM5iEGQIuViuc3JiVvnxldoeDlhtX3KBXO08hhAGiMBv0763 gp6R90jOS9fLs3G2kT5Vwb5vcgRE8sb48A9KqXuDDYqOdypsbo+XF13lRPqFPqRS3Tv2 vkA0vuWpkxAkUUbEkXUhT+k28M322iznBdKHwe0QxLFr+r7lO3jEbWXIdPcfLvfQuz7K FceA== X-Gm-Message-State: AOUpUlEjzU/YVl5CnkIm592OMHP1P8Z0jL7/SpEDfOp6WAfCY236G7F0 R6ecOJszAXVDFj5dyYH9l9lkIgoB X-Google-Smtp-Source: AAOMgpcxXG8zppfEzhP4X7Dd4URpMRKbWeb5IjdvmXArLCfXaO9YnvcfjBkG6Eekx6+xGOlyyW6BOQ== X-Received: by 2002:a63:c742:: with SMTP id v2-v6mr3351953pgg.331.1531426646491; Thu, 12 Jul 2018 13:17:26 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id e7-v6sm22647000pgc.55.2018.07.12.13.17.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Jul 2018 13:17:25 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH 1/2] selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress Date: Thu, 12 Jul 2018 13:17:20 -0700 Message-Id: <1531426641-20076-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531426641-20076-1-git-send-email-john.stultz@linaro.org> References: <1531426641-20076-1-git-send-email-john.stultz@linaro.org> In the past we've warned when ADJ_OFFSET was in progress, usually caused by ntpd or some other time adjusting daemon running in non steady sate, which can cause the skew calculations to be incorrect. Thus, this patch checks to see if the clock was being adjusted when we fail so that we don't cause false negatives. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Suggested-by: Miroslav Lichvar Signed-off-by: John Stultz --- v2: Widened the checks to look for other clock adjustments that could happen, as suggested by Miroslav v3: Fixed up commit message --- tools/testing/selftests/timers/raw_skew.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.7.4 diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c index ca6cd14..dcf73c5 100644 --- a/tools/testing/selftests/timers/raw_skew.c +++ b/tools/testing/selftests/timers/raw_skew.c @@ -134,6 +134,11 @@ int main(int argv, char **argc) printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000))); if (llabs(eppm - ppm) > 1000) { + if (tx1.offset || tx2.offset || + tx1.freq != tx2.freq || tx1.tick != tx2.tick) { + printf(" [SKIP]\n"); + return ksft_exit_skip("The clock was adjusted externally. Shutdown NTPd or other time sync daemons\n"); + } printf(" [FAILED]\n"); return ksft_exit_fail(); } From patchwork Thu Jul 12 20:17:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 141837 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1932156ljj; Thu, 12 Jul 2018 13:17:29 -0700 (PDT) X-Received: by 2002:a63:89c7:: with SMTP id v190-v6mr3301762pgd.194.1531426648620; Thu, 12 Jul 2018 13:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531426648; cv=none; d=google.com; s=arc-20160816; b=j1q/gY9TwcnmmfJH1e3N28ANpcnOQLsLShGBwjSW77nv8C1BXFRr2PwFa6Wu5z9UFa 00yEqDpIAT8LSl/TwGJKmbtkhEUVwEbsathxsHf41mJCBmE30O0tdDZArTk0aE2GwlyB 4tcTd3wfpjm9Q4/BbvMc44JfAckAkaYvvDnuzIN40QXFEswf1GFi4tWEtP6L37hAepOd 6BENEFcC8CeIncQ1EWktAduYGPN90XC6Lj+gWNeSWOTcBaqQehv42uNcxetz0UhmoPue /uGbnFze76WAd54PgKkrfLF+D72o00aTypMIXa6dTHThbxqbqEP/LZk18JnNWl0WhiYu HDhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=9bUP2F3+OSzuN3gwWFejoa3QoGwS6wuL+2HP34SBFLE=; b=QFrkx6sPk1iI37gHTvU26a3c6SV/8zRKXOY/1efv3BLeC6AGEtecZZjFWJ41fBgxUD /sLt/PNg1ya0hhm6uhuXJcvn1CXQ59iPqT2ohxJnn+sVpjyIAe8Dp2kxGzST6wcwqE0n thzA0MbJRuZoCqvWZJWXpbUQ7cddQBjLt16c7+4HIcpm8VxEyCM0igkikLrcnHbk8vP1 jRK+rniaE6kL7kGmYe8MOL2WtWlEEKMH9kqADn+czXiPMtovJwc3bUJYAx4Hr7nLIcOK oNbIOVDif08JPIFWABHo9chh6MvHVR+wlFUHsPvDM8sbsaWlCPjkcc8Bmu45KRPbT+ix rmMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QBC2vYnx; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v24-v6sor5931380pgc.173.2018.07.12.13.17.28 for (Google Transport Security); Thu, 12 Jul 2018 13:17:28 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QBC2vYnx; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9bUP2F3+OSzuN3gwWFejoa3QoGwS6wuL+2HP34SBFLE=; b=QBC2vYnxv6kQX3Iyk6/8NcPcoO6V/FaxCBhB/+oa97WPxylrjsk3Vun1OrW7LlGJWK B/UQjh/QpIBNg6ERC1YBsmULpAikOCRZf32kIs9y0AOxyPjwQ6fmJnfk5RkuJfoFfojp 0qsZHWNKzkJYOQhi5Usi989nxPzWBSQBrMu1w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9bUP2F3+OSzuN3gwWFejoa3QoGwS6wuL+2HP34SBFLE=; b=EmIK2jBFZOX/+BL61hIB+uI5SCwMOXg/6VS3b6t8dBA4TZQBd0vyqLlPXjKIkrtF5n ke/FW+0STI+EM0KEtSm4YG1wdugSKtXH1KV6cMPki2q+ObUVZRLEEO/5gYuQRIrWdpfl 9AbI+3cAodv3ArFlKcES/DcKdD2Yt8hXkDvWEVf7TKu9/kZzq4lgq1Z121iKz3uVFpW1 /M5+EvPouzEXNlWkaQggSjznGN7V1vbZ8bNracCQPazWQUhbeCtSGTORLOdA/KwjLZxR rt2H4tsERZ60aWKijWjNkQnZAcDmtVa132KDSmrgoNu/+S01bFAeCuag4G7xn/Bz/V4t 5M4w== X-Gm-Message-State: AOUpUlFj+/umFw16yLf6YqA5PQTsMzNFHTz9L98UQPIVnllyqzdHgvuY znMoTv7DhszSmc/3Ou3lKPztyfAN X-Google-Smtp-Source: AAOMgpcsSn6IDnOhjquzZ1SxsUjitGKATZI9w972Wk3uQQxFhlSOrhn8DoxKxPu4KGEyVNbe7YmcdQ== X-Received: by 2002:a63:bc0a:: with SMTP id q10-v6mr3382301pge.70.1531426648118; Thu, 12 Jul 2018 13:17:28 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:600:5100:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id e7-v6sm22647000pgc.55.2018.07.12.13.17.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Jul 2018 13:17:27 -0700 (PDT) From: John Stultz To: lkml Cc: Miroslav Lichvar , Thomas Gleixner , Ingo Molnar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 2/2] timekeeping: Update multiplier when NTP frequency is set directly Date: Thu, 12 Jul 2018 13:17:21 -0700 Message-Id: <1531426641-20076-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531426641-20076-1-git-send-email-john.stultz@linaro.org> References: <1531426641-20076-1-git-send-email-john.stultz@linaro.org> From: Miroslav Lichvar When the NTP frequency is set directly from userspace using the ADJ_FREQUENCY or ADJ_TICK timex mode, immediately update the timekeeper's multiplier instead of waiting for the next tick. This removes a hidden non-deterministic delay in setting of the frequency and allows an extremely tight control of the system clock with update rates close to or even exceeding the kernel HZ. The update is limited to archs using modern timekeeping (!ARCH_USES_GETTIMEOFFSET). Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Miroslav Lichvar Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 4786df9..6772011 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -34,6 +34,14 @@ #define TK_MIRROR (1 << 1) #define TK_CLOCK_WAS_SET (1 << 2) +enum timekeeping_adv_mode { + /* Update timekeeper when a tick has passed */ + TK_ADV_TICK, + + /* Update timekeeper on a direct frequency change */ + TK_ADV_FREQ +}; + /* * The most important data for readout fits into a single 64 byte * cache line. @@ -2021,11 +2029,11 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset, return offset; } -/** - * update_wall_time - Uses the current clocksource to increment the wall time - * +/* + * timekeeping_advance - Updates the timekeeper to the current time and + * current NTP tick length */ -void update_wall_time(void) +static void timekeeping_advance(enum timekeeping_adv_mode mode) { struct timekeeper *real_tk = &tk_core.timekeeper; struct timekeeper *tk = &shadow_timekeeper; @@ -2042,14 +2050,17 @@ void update_wall_time(void) #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET offset = real_tk->cycle_interval; + + if (mode != TK_ADV_TICK) + goto out; #else offset = clocksource_delta(tk_clock_read(&tk->tkr_mono), tk->tkr_mono.cycle_last, tk->tkr_mono.mask); -#endif /* Check if there's really nothing to do */ - if (offset < real_tk->cycle_interval) + if (offset < real_tk->cycle_interval && mode == TK_ADV_TICK) goto out; +#endif /* Do some additional sanity checking */ timekeeping_check_update(tk, offset); @@ -2106,6 +2117,15 @@ void update_wall_time(void) } /** + * update_wall_time - Uses the current clocksource to increment the wall time + * + */ +void update_wall_time(void) +{ + timekeeping_advance(TK_ADV_TICK); +} + +/** * getboottime64 - Return the real time of system boot. * @ts: pointer to the timespec64 to be set * @@ -2327,6 +2347,10 @@ int do_adjtimex(struct timex *txc) write_seqcount_end(&tk_core.seq); raw_spin_unlock_irqrestore(&timekeeper_lock, flags); + /* Update the multiplier immediately if frequency was set directly */ + if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK)) + timekeeping_advance(TK_ADV_FREQ); + if (tai != orig_tai) clock_was_set();