Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3729420pxy; Mon, 26 Apr 2021 08:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5/IKr3FVLuxRmBmgDQsGG60PbhJMoVZovbsB9Cwp1n2BiT7+miqmG0rk44TvmP2fqY8ap X-Received: by 2002:a05:6a00:c8:b029:260:f25a:f2ef with SMTP id e8-20020a056a0000c8b0290260f25af2efmr18021717pfj.78.1619450787379; Mon, 26 Apr 2021 08:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619450787; cv=none; d=google.com; s=arc-20160816; b=XmokQ8ZGbxK7DdHm/gFrqmVDec/XodgdFiowb0lJb2o7HSGzW1gybRGJ9+vKvMNQ7q 0AmJMfmXLhzUzJaww16FIoCof05bdLs7lVh7JzDvWSLMCoiRiMvSi+bILAou4sZoph25 dNOiXnc4LaTSTITkyWldGsDx23wl7P4mNsDmyoarcoNhJqW0D9jg3/0n7mkp61m0ukEm HHDOwzNAmnaKxhV7jJajdJesBUG0a+sTCX/LdDPfuAlhGXpR/iflmsN/smjqqIPik3aB 4/9Ksh83foyZYlEu2TAY1s4Nw6YHK5dyU1c4AdmG5pJ1PajUs6KtxIYgkmmsJzAZ06BH TS7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=xiVxwvznQtWDdjoVY3Udm6XQlMygW/gD/4cDfs+nen4=; b=qWd505zfIx5YfsOs1Z2MkLyV57jMHZpwvXwo8poNPMuo+2nt83BSQVphzYar9k+/yc l3YcELMs9FOLOIt8xXyBK19Kxqayt9edKyik0p/e6kTwHDZE01qDF9QjU/2bS8cBRe4+ 6kqLJtoxa9vRyB5f1PRQA2mp8iFzkNOGD0bJAXbADJP9vSboZ4G5KHpUaX8aHdMvmzLA yqsE3RKL+MRL6lMBezdFiUHQYgTAMnHD5mfsVDxJ07cS6XrB1tODzFnHoMHBNU0Qqfh/ 8q2tfHU8YQ8uSh35m0jM+nyFuYO5zNHXBfPZLp3BoypxhYI/HlH0GVGvhmdajz0qjPpg F6LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uw2qP6wd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c9si18982736pga.53.2021.04.26.08.26.13; Mon, 26 Apr 2021 08:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uw2qP6wd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234079AbhDZP0N (ORCPT + 99 others); Mon, 26 Apr 2021 11:26:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233919AbhDZP0L (ORCPT ); Mon, 26 Apr 2021 11:26:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05D1C61396; Mon, 26 Apr 2021 15:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619450730; bh=z8sBKtTH9XsU/Y+TciCRxZQUbTCh1nmv68f/Vjlbxbg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=uw2qP6wdKqvS003T8T2yFJ9sW7aZ8CXGH+vp3q322ciDYlCUeJE/S1f0MPrxF6xOj HDEvjy0HCdCMFq2CSLLL/bmdYtDBq+Rv10qiVHKfVhtsGwwJFTDQYCoSbtHbwZ3/9k pDVxI57Iy3ILfLzv6Bt9o1fnt5D/mYATdOF3RJxZxspvtzT86GVx3gORQAS0jFdux8 iaskystrBQwIbxXbjjYX6tM+1NSSnB/wEoYzBDzflJv84TYi2hLgHsUFqP7e+9ddq/ 5FdLTXikUtZLoiY7nRfYY9/mpvciI82wy/5QH/KvkK6CFjE5LG3EMcL5sxgss4oL9I fkLgA/Xg8AXxA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 5E4EC5C0121; Mon, 26 Apr 2021 08:25:29 -0700 (PDT) Date: Mon, 26 Apr 2021 08:25:29 -0700 From: "Paul E. McKenney" To: Feng Tang Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, john.stultz@linaro.org, sboyd@kernel.org, corbet@lwn.net, Mark.Rutland@arm.com, maz@kernel.org, kernel-team@fb.com, neeraju@codeaurora.org, ak@linux.intel.com, zhengjun.xing@intel.com, Xing Zhengjun Subject: Re: [PATCH v10 clocksource 6/7] clocksource: Forgive tsc_early pre-calibration drift Message-ID: <20210426152529.GX975577@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210425224540.GA1312438@paulmck-ThinkPad-P17-Gen-1> <20210425224709.1312655-6-paulmck@kernel.org> <20210426150127.GB23119@shbuild999.sh.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210426150127.GB23119@shbuild999.sh.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 26, 2021 at 11:01:27PM +0800, Feng Tang wrote: > Hi Paul, > > On Sun, Apr 25, 2021 at 03:47:07PM -0700, Paul E. McKenney wrote: > > Because the x86 tsc_early clocksource is given a quick and semi-accurate > > calibration (by design!), it might have drift rates well in excess of > > the 0.1% limit that is in the process of being adopted. > > > > Therefore, add a max_drift field to the clocksource structure that, when > > non-zero, specifies the maximum allowable drift rate in nanoseconds over > > a half-second period. The tsc_early clocksource initializes this to five > > miliseconds, which corresponds to the 1% drift rate limit suggested by > > Xing Zhengjun. This max_drift field is intended only for early boot, > > so clocksource_watchdog() splats if it encounters a non-zero value in > > this field more than 60 seconds after boot, inspired by a suggestion by > > Thomas Gleixner. > > > > This was tested by setting the clocksource_tsc ->max_drift field to 1, > > which, as expected, resulted in a clock-skew event. > > We've run the same last for this v10, and those 'unstable' thing [1] can > not be reproduced! Good to hear! ;-) > We've reported one case that tsc can be wrongly judged as 'unstable' > by 'refined-jiffies' watchdog [1], while reducing the threshold could > make it easier to be triggered. > > It could be reproduced on the a plaform with a 115200 serial console, > and hpet been disabled (several x86 platforms has this), add > 'initcall_debug' cmdline parameter to get more debug message, we can > see: > > [ 1.134197] clocksource: timekeeping watchdog on CPU1: Marking clocksource 'tsc-early' as unstable because the skew is too large: > [ 1.134214] clocksource: 'refined-jiffies' wd_nesc: 500000000 wd_now: ffff8b35 wd_last: ffff8b03 mask: ffffffff > [ 1.134217] clocksource: 'tsc-early' cs_nsec: 507537855 cs_now: 4e63c9d09 cs_last: 4bebd81f5 mask: ffffffffffffffff > [ 1.134220] clocksource: No current clocksource. > [ 1.134222] tsc: Marking TSC unstable due to clocksource watchdog Just to make sure I understand: "could be reproduced" as in this is the result from v9, and v10 avoids this, correct? Thanx, Paul > [1]. https://lore.kernel.org/lkml/20210420064934.GE31773@xsang-OptiPlex-9020/ > [2]. https://lore.kernel.org/lkml/20201126012421.GA92582@shbuild999.sh.intel.com/ > > Thanks, > Feng > > > Cc: John Stultz > > Cc: Thomas Gleixner > > Cc: Stephen Boyd > > Cc: Jonathan Corbet > > Cc: Mark Rutland > > Cc: Marc Zyngier > > Cc: Andi Kleen > > Cc: Xing Zhengjun > > Cc: Feng Tang > > Signed-off-by: Paul E. McKenney > > --- > > arch/x86/kernel/tsc.c | 1 + > > include/linux/clocksource.h | 5 +++++ > > kernel/time/clocksource.c | 19 ++++++++++++++++++- > > 3 files changed, 24 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c > > index 56289170753c..7192b8950322 100644 > > --- a/arch/x86/kernel/tsc.c > > +++ b/arch/x86/kernel/tsc.c > > @@ -1127,6 +1127,7 @@ static int tsc_cs_enable(struct clocksource *cs) > > static struct clocksource clocksource_tsc_early = { > > .name = "tsc-early", > > .rating = 299, > > + .max_drift = 5 * NSEC_PER_MSEC, > > .read = read_tsc, > > .mask = CLOCKSOURCE_MASK(64), > > .flags = CLOCK_SOURCE_IS_CONTINUOUS | > > diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h > > index 83a3ebff7456..07d25a158d7a 100644 > > --- a/include/linux/clocksource.h > > +++ b/include/linux/clocksource.h > > @@ -42,6 +42,10 @@ struct module; > > * @shift: Cycle to nanosecond divisor (power of two) > > * @max_idle_ns: Maximum idle time permitted by the clocksource (nsecs) > > * @maxadj: Maximum adjustment value to mult (~11%) > > + * @max_drift: Maximum drift rate in nanoseconds per half second. > > + * Zero says to use default WATCHDOG_THRESHOLD. > > + * A non-zero value for ->max_drift more than 60 seconds after boot > > + * will result in a splat. > > * @archdata: Optional arch-specific data > > * @max_cycles: Maximum safe cycle value which won't overflow on > > * multiplication > > @@ -93,6 +97,7 @@ struct clocksource { > > u32 shift; > > u64 max_idle_ns; > > u32 maxadj; > > + u32 max_drift; > > #ifdef CONFIG_ARCH_CLOCKSOURCE_DATA > > struct arch_clocksource_data archdata; > > #endif > > diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c > > index f71f375df544..070b09dab815 100644 > > --- a/kernel/time/clocksource.c > > +++ b/kernel/time/clocksource.c > > @@ -126,6 +126,7 @@ static void __clocksource_change_rating(struct clocksource *cs, int rating); > > */ > > #define WATCHDOG_INTERVAL (HZ >> 1) > > #define WATCHDOG_THRESHOLD (NSEC_PER_SEC >> 4) > > +#define WATCHDOG_SYNC_FORGIVENESS (HZ * 60UL) > > > > /* > > * Maximum permissible delay between two readouts of the watchdog > > @@ -377,6 +378,7 @@ static void clocksource_watchdog(struct timer_list *unused) > > int next_cpu, reset_pending; > > int64_t wd_nsec, cs_nsec; > > struct clocksource *cs; > > + u32 md; > > > > spin_lock(&watchdog_lock); > > if (!watchdog_running) > > @@ -423,7 +425,22 @@ static void clocksource_watchdog(struct timer_list *unused) > > continue; > > > > /* Check the deviation from the watchdog clocksource. */ > > - if (abs(cs_nsec - wd_nsec) > WATCHDOG_THRESHOLD) { > > + if (!cs->max_drift) { > > + md = WATCHDOG_THRESHOLD; > > + } else { > > + static unsigned long first_jiffies; > > + static bool beenhere; > > + > > + if (beenhere) { > > + WARN_ON_ONCE(time_after(jiffies, > > + first_jiffies + WATCHDOG_SYNC_FORGIVENESS)); > > + } else { > > + beenhere = true; > > + first_jiffies = jiffies; > > + } > > + md = cs->max_drift; > > + } > > + if (abs(cs_nsec - wd_nsec) > md) { > > pr_warn("timekeeping watchdog on CPU%d: Marking clocksource '%s' as unstable because the skew is too large:\n", > > smp_processor_id(), cs->name); > > pr_warn(" '%s' wd_now: %llx wd_last: %llx mask: %llx\n", > > -- > > 2.31.1.189.g2e36527f23