From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF8661865EB; Wed, 11 Sep 2024 13:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; cv=none; b=FBUDyqQA5NWH6tT+tXVtBoGOMp1kMYnB9r37F/sszpx85aImdYKTcakEqG8h7wT3FYOzxl9muHV13ZpRDjLBftvV35qDlOHFMjrKIez2+7ys1ZBueTnfwTHELIBuZVg5MAEHIbXOmnpzXtuuIg8v8I8Hb/cVfQMzrRxga1ellZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; c=relaxed/simple; bh=Wf9b5D6j4GtT8RassJRaMpL+mQLmkJWXlGbrXD+YtCc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QYroOAb9i9VjSbBiF1BmIKHnBmYTYzAb9TYSZsIF7xP1tr5lSrJ/glRB/OVAnD8Mt2YP7ROi+KDHOcPUCRIsgeHt1LP93lr0Z+pmg5C/igKYHgGBEICFTK1emQ366LicnpuprCcSIwGbllEynUHGo2JJqWOntprmc7Q39GqcnQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=g0WPTC45; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8bD0e7tc; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="g0WPTC45"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8bD0e7tc" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YjMH1BugHsm7FWKzyGipxzR/HsoVCdW/cbwZAnSod9k=; b=g0WPTC45M7csLuOht7OIIzcJwhlcn8PVQ/n1bMvOsSR17zDlg6PTtZZX/vYGR3/58ZGDPB +lOj0o1m1EAEzN0ksVpHTXqnibYFyAvEl1dr4fpNn0Pdra8ho/ExG5+mJev3Znyhng8S41 maejdIxqpVI62HWczUdUntpHeCVrdTHFFVYsYzON2PPUW3DLz2t6jZ0+SSl3/PEI7+jUN8 N+nRzLIZ1aLL5k/JQve41IUVaJEUN00xVISgIZf0a2SUPQY/EcEjDDq0zjzgxktQi8mGjF SsPlj0oTbib8i3NXUzhoHvrlE5ah4kfpV7VtPlHTpMXXQhm5qKzlY97ewUCVCw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YjMH1BugHsm7FWKzyGipxzR/HsoVCdW/cbwZAnSod9k=; b=8bD0e7tc6EKtti3u25E6UGo7j5czay2mDcDW/mNTjqwdB1KVvBeBJ8V1AtJSyidWKWg/Mf D4g8q2lPci02EnCg== Date: Wed, 11 Sep 2024 15:17:37 +0200 Subject: [PATCH 01/21] ntp: Remove unused tick_nsec Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-1-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner tick_nsec is only updated in the NTP core, but there are no users. Remove it. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- arch/x86/include/asm/timer.h | 2 -- include/linux/timex.h | 1 - kernel/time/ntp.c | 8 ++------ 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h index 7365dd4acffb..23baf8c9b34c 100644 --- a/arch/x86/include/asm/timer.h +++ b/arch/x86/include/asm/timer.h @@ -6,8 +6,6 @@ #include #include =20 -#define TICK_SIZE (tick_nsec / 1000) - unsigned long long native_sched_clock(void); extern void recalibrate_cpu_khz(void); =20 diff --git a/include/linux/timex.h b/include/linux/timex.h index 3871b06bd302..7f7a12fd8200 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -145,7 +145,6 @@ unsigned long random_get_entropy_fallback(void); * estimated error =3D NTP dispersion. */ extern unsigned long tick_usec; /* USER_HZ period (usec) */ -extern unsigned long tick_nsec; /* SHIFTED_HZ period (nsec) */ =20 /* Required to safely shift negative values */ #define shift_right(x, s) ({ \ diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 8d2dd214ec68..0dba1179d81d 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -33,9 +33,6 @@ /* USER_HZ period (usecs): */ unsigned long tick_usec =3D USER_TICK_USEC; =20 -/* SHIFTED_HZ period (nsecs): */ -unsigned long tick_nsec; - static u64 tick_length; static u64 tick_length_base; =20 @@ -253,8 +250,8 @@ static inline int ntp_synced(void) */ =20 /* - * Update (tick_length, tick_length_base, tick_nsec), based - * on (tick_usec, ntp_tick_adj, time_freq): + * Update tick_length and tick_length_base, based on tick_usec, ntp_tick_a= dj and + * time_freq: */ static void ntp_update_frequency(void) { @@ -267,7 +264,6 @@ static void ntp_update_frequency(void) second_length +=3D ntp_tick_adj; second_length +=3D time_freq; =20 - tick_nsec =3D div_u64(second_length, HZ) >> NTP_SCALE_SHIFT; new_base =3D div_u64(second_length, NTP_INTERVAL_FREQ); =20 /* --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF9761885BA; Wed, 11 Sep 2024 13:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; cv=none; b=EIGEZlt2RGXikXd44MSsLYGdlkSnG5is4X8MKtTpsbs7iTLp1b8Fw6+apEZTzyoAeEnJ8KYfJNFqhitlBUB3mxH6WIktIas1T8xBoqlbwW4s9yKuBKOB77OuUE8ZYHoyVOl3WotypGeA2nBLm10JsrjsOm8o37H6sElvu0N/fbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; c=relaxed/simple; bh=Gs6TIXLeUjG4fKw4xPe2jcwyoi6PVKidrGkI3LXAN38=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ATAv4T6pClz2f635dVJWRZesNgZ9Xi9EkkOZCmVQXdeNla33DmJBGRGxCyncSQ2jm53qHng7NCngT8gAEcxViGzPO5iEwgprzncnrfkfb4Lu7HlIGd/FDlcufH6s1rIHAgIOTxVwsUjwZARk8MJU8yS+dEPflysMbPjy9rLMLW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PDaUN+uT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xbnGAfVX; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PDaUN+uT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xbnGAfVX" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CupHS51cjv4Y/d3KwHj+m1FSExruPPTR+LTby/r2ODQ=; b=PDaUN+uTjH4ELqQ4E891Hj1lfMWWCGwdfx7r0+knTdAliu/TT84ZQAoZtd6paEY52W85O7 lo2qeF9DbCk9VzX6dcM1/TunGKouWNfDEPfw86ZqONG4mKK/cUbxIhZFWofBmkhR90+RCX aYSnbB5Lj8Jh2wOrITdn8cwUkzcsaEa13CzQQKYnNJKYZqEFwJr88GuzdtTDFFgA2T9nbE I4ud10/aoJP9oyHx3gSD2A4Ze7ISOachYVJ42H8UooBw5eeJQ43Hi104oOGqVWOFyqhaOb c9qNpzVx8nlfSBl2XPCVKzKB7sC+8CSpNyq/sBtlCYumfi5Gjo4DsO2K9N6bOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CupHS51cjv4Y/d3KwHj+m1FSExruPPTR+LTby/r2ODQ=; b=xbnGAfVXFq7LvnwN26eT5oQHcQ6arWsSAyg+alVSlXnaM7fPDOdJpHZYgdITECH1jg/4mQ FEAEjWtYEvBggFCw== Date: Wed, 11 Sep 2024 15:17:38 +0200 Subject: [PATCH 02/21] ntp: Make tick_usec static Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-2-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner There are no users of tick_usec outside of the NTP core code. Therefore make tick_usec static. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- include/linux/timex.h | 7 ------- kernel/time/ntp.c | 5 ++++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/linux/timex.h b/include/linux/timex.h index 7f7a12fd8200..4ee32eff3f22 100644 --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -139,13 +139,6 @@ unsigned long random_get_entropy_fallback(void); #define MAXSEC 2048 /* max interval between updates (s) */ #define NTP_PHASE_LIMIT ((MAXPHASE / NSEC_PER_USEC) << 5) /* beyond max. d= ispersion */ =20 -/* - * kernel variables - * Note: maximum error =3D NTP sync distance =3D dispersion + delay / 2; - * estimated error =3D NTP dispersion. - */ -extern unsigned long tick_usec; /* USER_HZ period (usec) */ - /* Required to safely shift negative values */ #define shift_right(x, s) ({ \ __typeof__(x) __x =3D (x); \ diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 0dba1179d81d..8e68a85996f7 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -31,7 +31,7 @@ =20 =20 /* USER_HZ period (usecs): */ -unsigned long tick_usec =3D USER_TICK_USEC; +static unsigned long tick_usec =3D USER_TICK_USEC; =20 static u64 tick_length; static u64 tick_length_base; @@ -44,6 +44,9 @@ static u64 tick_length_base; =20 /* * phase-lock loop variables + * + * Note: maximum error =3D NTP sync distance =3D dispersion + delay / 2; + * estimated error =3D NTP dispersion. */ =20 /* --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8F83188924; Wed, 11 Sep 2024 13:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; cv=none; b=pezYMzQosvks/c6B5acKzdkvmpH48CTlgLMRJ0dHpGSGf7RORinwcviN6BKRS1lrNzooV7DPZuwLBM3guY289n0xxsL2pJWZGrMAisGj7Erdw3I4rtUk8/ivp3EB8JN6oZUgFu0vXRjxEUx8fAFIDgl+m2FSyl7P/ZD/8PsXuJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; c=relaxed/simple; bh=fgDIxovmR+O6gyO4iQm1kvPpi2Rc+D+6v0cg0aS1+4A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y9ZosJ4PP2B54wWx1MzMdk/Mo0ULQxaaUnAwpZXcTessW1g2agILrNmzG5yWnuBABRAQpU6Bc1h9dupbn+EWtbVcSgNMusa87bTduxwip6nudgTgOZ8cr59e1cdZNXzC3J0ag4CcAUaijxd2Jj/ffZH+6jbZtCVVRPcITxHFZUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jRg0x5V8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=93zpju5x; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jRg0x5V8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="93zpju5x" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wQ8k8a4/pacG0om765Mucc7+Qw1DbjOAO73zMGi/Ls4=; b=jRg0x5V8K/B8oeoM9S3q34lKD37vW8aoEmV0VOA98wePzQ9Y2Q6Kl6LIm6rF8FtFOiEOyW ZLfhJNWZOsYj4/uqhIY7YRid0cf9TrWXoD6CPu05Ip+QN+d8oLJlN6UP+kIj2XQMsidlki 6HfiWSsmnO+wLOjz2ej3qawFAitw+sgPtZcpBix3i9vktk7UqRXfSx4ID1usMkpMg8AwOt rHWVXt+hsUt4ZrGp4CmolLdwarcdMhnsi6wJUZIXNos4LEw9PEzTemaTL7Cne6HGXY33Wj RceY/yOJmBpsUyY405UqPBET1D8Olt9izH89l+N0Q3QGt7u/vfwwBOyKtyCohw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wQ8k8a4/pacG0om765Mucc7+Qw1DbjOAO73zMGi/Ls4=; b=93zpju5xEQSDZvvb9gS9W3dZ5S1hhCy9G/Gh7glqAKTV69s7uLiwP3LRvnJcAX6wOGFw7N 76RceADw73UDuOBA== Date: Wed, 11 Sep 2024 15:17:39 +0200 Subject: [PATCH 03/21] ntp: Clean up comments Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-3-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Usage of different comment formatting makes fast reading and parsing the code harder. There are several multi-line comments which do not follow the coding style by starting with a line only containing '/*'. There are also comments which do not start with capitals. Clean up all those comments to be consistent and remove comments which document the obvious. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 144 +++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 8e68a85996f7..99213d931f63 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -119,7 +119,8 @@ static long pps_stbcnt; /* stability limit exceeded */ static long pps_errcnt; /* calibration errors */ =20 =20 -/* PPS kernel consumer compensates the whole phase error immediately. +/* + * PPS kernel consumer compensates the whole phase error immediately. * Otherwise, reduce the offset by a fixed factor times the time constant. */ static inline s64 ntp_offset_chunk(s64 offset) @@ -132,8 +133,7 @@ static inline s64 ntp_offset_chunk(s64 offset) =20 static inline void pps_reset_freq_interval(void) { - /* the PPS calibration interval may end - surprisingly early */ + /* The PPS calibration interval may end surprisingly early */ pps_shift =3D PPS_INTMIN; pps_intcnt =3D 0; } @@ -151,9 +151,9 @@ static inline void pps_clear(void) pps_freq =3D 0; } =20 -/* Decrease pps_valid to indicate that another second has passed since - * the last PPS signal. When it reaches 0, indicate that PPS signal is - * missing. +/* + * Decrease pps_valid to indicate that another second has passed since the + * last PPS signal. When it reaches 0, indicate that PPS signal is missing. */ static inline void pps_dec_valid(void) { @@ -174,17 +174,21 @@ static inline void pps_set_freq(s64 freq) static inline int is_error_status(int status) { return (status & (STA_UNSYNC|STA_CLOCKERR)) - /* PPS signal lost when either PPS time or - * PPS frequency synchronization requested + /* + * PPS signal lost when either PPS time or PPS frequency + * synchronization requested */ || ((status & (STA_PPSFREQ|STA_PPSTIME)) && !(status & STA_PPSSIGNAL)) - /* PPS jitter exceeded when - * PPS time synchronization requested */ + /* + * PPS jitter exceeded when PPS time synchronization + * requested + */ || ((status & (STA_PPSTIME|STA_PPSJITTER)) =3D=3D (STA_PPSTIME|STA_PPSJITTER)) - /* PPS wander exceeded or calibration error when - * PPS frequency synchronization requested + /* + * PPS wander exceeded or calibration error when PPS + * frequency synchronization requested */ || ((status & STA_PPSFREQ) && (status & (STA_PPSWANDER|STA_PPSERROR))); @@ -270,8 +274,8 @@ static void ntp_update_frequency(void) new_base =3D div_u64(second_length, NTP_INTERVAL_FREQ); =20 /* - * Don't wait for the next second_overflow, apply - * the change to the tick length immediately: + * Don't wait for the next second_overflow, apply the change to the + * tick length immediately: */ tick_length +=3D new_base - tick_length_base; tick_length_base =3D new_base; @@ -307,10 +311,7 @@ static void ntp_update_offset(long offset) offset *=3D NSEC_PER_USEC; } =20 - /* - * Scale the phase adjustment and - * clamp to the operating range. - */ + /* Scale the phase adjustment and clamp to the operating range. */ offset =3D clamp(offset, -MAXPHASE, MAXPHASE); =20 /* @@ -349,7 +350,8 @@ static void ntp_update_offset(long offset) */ void ntp_clear(void) { - time_adjust =3D 0; /* stop active adjtime() */ + /* Stop active adjtime() */ + time_adjust =3D 0; time_status |=3D STA_UNSYNC; time_maxerror =3D NTP_PHASE_LIMIT; time_esterror =3D NTP_PHASE_LIMIT; @@ -387,7 +389,7 @@ ktime_t ntp_get_next_leap(void) } =20 /* - * this routine handles the overflow of the microsecond field + * This routine handles the overflow of the microsecond field * * The tricky bits of code to handle the accurate clock support * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame. @@ -452,7 +454,6 @@ int second_overflow(time64_t secs) break; } =20 - /* Bump the maxerror field */ time_maxerror +=3D MAXFREQ / NSEC_PER_USEC; if (time_maxerror > NTP_PHASE_LIMIT) { @@ -688,7 +689,7 @@ static inline void process_adj_status(const struct __ke= rnel_timex *txc) time_state =3D TIME_OK; time_status =3D STA_UNSYNC; ntp_next_leap_sec =3D TIME64_MAX; - /* restart PPS frequency calibration */ + /* Restart PPS frequency calibration */ pps_reset_freq_interval(); } =20 @@ -699,7 +700,7 @@ static inline void process_adj_status(const struct __ke= rnel_timex *txc) if (!(time_status & STA_PLL) && (txc->status & STA_PLL)) time_reftime =3D __ktime_get_real_seconds(); =20 - /* only set allowed bits */ + /* Only set allowed bits */ time_status &=3D STA_RONLY; time_status |=3D txc->status & ~STA_RONLY; } @@ -721,7 +722,7 @@ static inline void process_adjtimex_modes(const struct = __kernel_timex *txc, time_freq =3D txc->freq * PPM_SCALE; time_freq =3D min(time_freq, MAXFREQ_SCALED); time_freq =3D max(time_freq, -MAXFREQ_SCALED); - /* update pps_freq */ + /* Update pps_freq */ pps_set_freq(time_freq); } =20 @@ -754,7 +755,7 @@ static inline void process_adjtimex_modes(const struct = __kernel_timex *txc, =20 =20 /* - * adjtimex mainly allows reading (and writing, if superuser) of + * adjtimex() mainly allows reading (and writing, if superuser) of * kernel time-keeping variables. used by xntpd. */ int __do_adjtimex(struct __kernel_timex *txc, const struct timespec64 *ts, @@ -798,8 +799,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, txc->offset =3D (u32)txc->offset / NSEC_PER_USEC; } =20 - result =3D time_state; /* mostly `TIME_OK' */ - /* check for errors */ + result =3D time_state; if (is_error_status(time_status)) result =3D TIME_ERROR; =20 @@ -814,7 +814,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, txc->tick =3D tick_usec; txc->tai =3D *time_tai; =20 - /* fill PPS status fields */ + /* Fill PPS status fields */ pps_fill_timex(txc); =20 txc->time.tv_sec =3D ts->tv_sec; @@ -845,17 +845,21 @@ int __do_adjtimex(struct __kernel_timex *txc, const s= truct timespec64 *ts, =20 #ifdef CONFIG_NTP_PPS =20 -/* actually struct pps_normtime is good old struct timespec, but it is +/* + * struct pps_normtime is basically a struct timespec, but it is * semantically different (and it is the reason why it was invented): * pps_normtime.nsec has a range of ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] - * while timespec.tv_nsec has a range of [0, NSEC_PER_SEC) */ + * while timespec.tv_nsec has a range of [0, NSEC_PER_SEC) + */ struct pps_normtime { s64 sec; /* seconds */ long nsec; /* nanoseconds */ }; =20 -/* normalize the timestamp so that nsec is in the - ( -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval */ +/* + * Normalize the timestamp so that nsec is in the + * [ -NSEC_PER_SEC / 2, NSEC_PER_SEC / 2 ] interval + */ static inline struct pps_normtime pps_normalize_ts(struct timespec64 ts) { struct pps_normtime norm =3D { @@ -871,7 +875,7 @@ static inline struct pps_normtime pps_normalize_ts(stru= ct timespec64 ts) return norm; } =20 -/* get current phase correction and jitter */ +/* Get current phase correction and jitter */ static inline long pps_phase_filter_get(long *jitter) { *jitter =3D pps_tf[0] - pps_tf[1]; @@ -882,7 +886,7 @@ static inline long pps_phase_filter_get(long *jitter) return pps_tf[0]; } =20 -/* add the sample to the phase filter */ +/* Add the sample to the phase filter */ static inline void pps_phase_filter_add(long err) { pps_tf[2] =3D pps_tf[1]; @@ -890,8 +894,9 @@ static inline void pps_phase_filter_add(long err) pps_tf[0] =3D err; } =20 -/* decrease frequency calibration interval length. - * It is halved after four consecutive unstable intervals. +/* + * Decrease frequency calibration interval length. It is halved after four + * consecutive unstable intervals. */ static inline void pps_dec_freq_interval(void) { @@ -904,8 +909,9 @@ static inline void pps_dec_freq_interval(void) } } =20 -/* increase frequency calibration interval length. - * It is doubled after four consecutive stable intervals. +/* + * Increase frequency calibration interval length. It is doubled after + * four consecutive stable intervals. */ static inline void pps_inc_freq_interval(void) { @@ -918,7 +924,8 @@ static inline void pps_inc_freq_interval(void) } } =20 -/* update clock frequency based on MONOTONIC_RAW clock PPS signal +/* + * Update clock frequency based on MONOTONIC_RAW clock PPS signal * timestamps * * At the end of the calibration interval the difference between the @@ -932,7 +939,7 @@ static long hardpps_update_freq(struct pps_normtime fre= q_norm) long delta, delta_mod; s64 ftemp; =20 - /* check if the frequency interval was too long */ + /* Check if the frequency interval was too long */ if (freq_norm.sec > (2 << pps_shift)) { time_status |=3D STA_PPSERROR; pps_errcnt++; @@ -943,9 +950,10 @@ static long hardpps_update_freq(struct pps_normtime fr= eq_norm) return 0; } =20 - /* here the raw frequency offset and wander (stability) is - * calculated. If the wander is less than the wander threshold - * the interval is increased; otherwise it is decreased. + /* + * Here the raw frequency offset and wander (stability) is + * calculated. If the wander is less than the wander threshold the + * interval is increased; otherwise it is decreased. */ ftemp =3D div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT, freq_norm.sec); @@ -957,13 +965,14 @@ static long hardpps_update_freq(struct pps_normtime f= req_norm) time_status |=3D STA_PPSWANDER; pps_stbcnt++; pps_dec_freq_interval(); - } else { /* good sample */ + } else { + /* Good sample */ pps_inc_freq_interval(); } =20 - /* the stability metric is calculated as the average of recent - * frequency changes, but is used only for performance - * monitoring + /* + * The stability metric is calculated as the average of recent + * frequency changes, but is used only for performance monitoring */ delta_mod =3D delta; if (delta_mod < 0) @@ -972,7 +981,7 @@ static long hardpps_update_freq(struct pps_normtime fre= q_norm) (NTP_SCALE_SHIFT - SHIFT_USEC), NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; =20 - /* if enabled, the system clock frequency is updated */ + /* If enabled, the system clock frequency is updated */ if ((time_status & STA_PPSFREQ) !=3D 0 && (time_status & STA_FREQHOLD) =3D=3D 0) { time_freq =3D pps_freq; @@ -982,17 +991,18 @@ static long hardpps_update_freq(struct pps_normtime f= req_norm) return delta; } =20 -/* correct REALTIME clock phase error against PPS signal */ +/* Correct REALTIME clock phase error against PPS signal */ static void hardpps_update_phase(long error) { long correction =3D -error; long jitter; =20 - /* add the sample to the median filter */ + /* Add the sample to the median filter */ pps_phase_filter_add(correction); correction =3D pps_phase_filter_get(&jitter); =20 - /* Nominal jitter is due to PPS signal noise. If it exceeds the + /* + * Nominal jitter is due to PPS signal noise. If it exceeds the * threshold, the sample is discarded; otherwise, if so enabled, * the time offset is updated. */ @@ -1003,13 +1013,13 @@ static void hardpps_update_phase(long error) time_status |=3D STA_PPSJITTER; pps_jitcnt++; } else if (time_status & STA_PPSTIME) { - /* correct the time using the phase offset */ + /* Correct the time using the phase offset */ time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); - /* cancel running adjtime() */ + /* Cancel running adjtime() */ time_adjust =3D 0; } - /* update jitter */ + /* Update jitter */ pps_jitter +=3D (jitter - pps_jitter) >> PPS_INTMIN; } =20 @@ -1031,41 +1041,43 @@ void __hardpps(const struct timespec64 *phase_ts, c= onst struct timespec64 *raw_t =20 pts_norm =3D pps_normalize_ts(*phase_ts); =20 - /* clear the error bits, they will be set again if needed */ + /* Clear the error bits, they will be set again if needed */ time_status &=3D ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); =20 - /* indicate signal presence */ + /* Indicate signal presence */ time_status |=3D STA_PPSSIGNAL; pps_valid =3D PPS_VALID; =20 - /* when called for the first time, - * just start the frequency interval */ + /* + * When called for the first time, just start the frequency + * interval + */ if (unlikely(pps_fbase.tv_sec =3D=3D 0)) { pps_fbase =3D *raw_ts; return; } =20 - /* ok, now we have a base for frequency calculation */ + /* Ok, now we have a base for frequency calculation */ freq_norm =3D pps_normalize_ts(timespec64_sub(*raw_ts, pps_fbase)); =20 - /* check that the signal is in the range - * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */ + /* + * Check that the signal is in the range + * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it + */ if ((freq_norm.sec =3D=3D 0) || (freq_norm.nsec > MAXFREQ * freq_norm.sec) || (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { time_status |=3D STA_PPSJITTER; - /* restart the frequency calibration interval */ + /* Restart the frequency calibration interval */ pps_fbase =3D *raw_ts; printk_deferred(KERN_ERR "hardpps: PPSJITTER: bad pulse\n"); return; } =20 - /* signal is ok */ - - /* check if the current frequency interval is finished */ + /* Signal is ok. Check if the current frequency interval is finished */ if (freq_norm.sec >=3D (1 << pps_shift)) { pps_calcnt++; - /* restart the frequency calibration interval */ + /* Restart the frequency calibration interval */ pps_fbase =3D *raw_ts; hardpps_update_freq(freq_norm); } --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF9221885B0; Wed, 11 Sep 2024 13:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; cv=none; b=j4+3e1agNylATtOfMOKAdnXHIpZlMxE/Ounu3y7dD1capX5Yav0WF1FW/f995FT2uP06WbHQHo1aDc644w0EynryyHLRuDjTYOEfVEZrC4Kc1yrze+5KXgoqTCbLfOmeJS92FjfbS1j10+mg+7ntt3j1ViFJzytWDsowhlvcRAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060680; c=relaxed/simple; bh=g9zzwz4V5Qs8RbYfmTH/7d0rG1Do/CrzNfnYcKbCxXw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=agRpsT5PLgPrUSG9qQHd6UV/hV8gxZGLxNjHLp6p7trxnBpdR36ZM+YTIr2pspl8mmw2Da9lwXf0GPBQwFhCcO9apu65C4cQe5ndHhebTqzsqigZgfOTXkTWCZlPkSIVHtKVaYRaMiOqSKyQxxtNBPeCIFfa6649KLhn6Z1udkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JaiWKAbz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ha/E7eV9; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JaiWKAbz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ha/E7eV9" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DfZBbYk+dRlXllU+uOF1Xktt71qqtzKN1W0IDd61nkM=; b=JaiWKAbzkmlwIHtyMxu1F2IQh1bIm1Zs3YJt887qUbLh6oQP7fiQ+p4jvVGdwvJWB1F4R8 /cf1beDZoMaXUwnxAIcnPIKMVl2hwZeXB+LM1hREcBuJZ7Zs00HUK9Wsqzm7/OMmhKXnQl ix6TOOoeIQZ9CYizZb1QszrPZbhNDumkZzslAQ1saCNlmQAAfUSVn4JL1sum3FGNjXfHSE +PBFGMCtY7glUOPhZQiDAKEWx//Ei6M0UlQr1rT0s14H+KKekIUGqoUjKMYQl05/YNk0EG Vb66PGUsq6CgpqI5MeeinRzuizEi2yxlwMvNjs6ksttfamNhGPAU/vRGDINKpw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DfZBbYk+dRlXllU+uOF1Xktt71qqtzKN1W0IDd61nkM=; b=Ha/E7eV99Wb0WjT4w99EPCwz+ad1nWBL/mfwQJbqiVD0ew52N+pRjCsXZzfxAjLgDc/ix9 61XkacB8LMvwRwAw== Date: Wed, 11 Sep 2024 15:17:40 +0200 Subject: [PATCH 04/21] ntp: Cleanup formatting of code Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-4-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen Code is partially formatted in a creative way which makes reading harder. Examples are function calls over several lines where the indentation does not start at the same height then the open bracket after the function name. Improve formatting but do not make a functional change. Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 99213d931f63..eca9de85b0a7 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -428,8 +428,7 @@ int second_overflow(time64_t secs) } else if (secs =3D=3D ntp_next_leap_sec) { leap =3D -1; time_state =3D TIME_OOP; - printk(KERN_NOTICE - "Clock: inserting leap second 23:59:60 UTC\n"); + pr_notice("Clock: inserting leap second 23:59:60 UTC\n"); } break; case TIME_DEL: @@ -440,8 +439,7 @@ int second_overflow(time64_t secs) leap =3D 1; ntp_next_leap_sec =3D TIME64_MAX; time_state =3D TIME_WAIT; - printk(KERN_NOTICE - "Clock: deleting leap second 23:59:59 UTC\n"); + pr_notice("Clock: deleting leap second 23:59:59 UTC\n"); } break; case TIME_OOP: @@ -834,10 +832,8 @@ int __do_adjtimex(struct __kernel_timex *txc, const st= ruct timespec64 *ts, txc->tai--; txc->time.tv_sec++; } - if ((time_state =3D=3D TIME_OOP) && - (ts->tv_sec =3D=3D ntp_next_leap_sec)) { + if ((time_state =3D=3D TIME_OOP) && (ts->tv_sec =3D=3D ntp_next_leap_sec= )) result =3D TIME_WAIT; - } } =20 return result; @@ -944,9 +940,8 @@ static long hardpps_update_freq(struct pps_normtime fre= q_norm) time_status |=3D STA_PPSERROR; pps_errcnt++; pps_dec_freq_interval(); - printk_deferred(KERN_ERR - "hardpps: PPSERROR: interval too long - %lld s\n", - freq_norm.sec); + printk_deferred(KERN_ERR "hardpps: PPSERROR: interval too long - %lld s\= n", + freq_norm.sec); return 0; } =20 @@ -960,8 +955,7 @@ static long hardpps_update_freq(struct pps_normtime fre= q_norm) delta =3D shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT); pps_freq =3D ftemp; if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { - printk_deferred(KERN_WARNING - "hardpps: PPSWANDER: change=3D%ld\n", delta); + printk_deferred(KERN_WARNING "hardpps: PPSWANDER: change=3D%ld\n", delta= ); time_status |=3D STA_PPSWANDER; pps_stbcnt++; pps_dec_freq_interval(); @@ -977,13 +971,11 @@ static long hardpps_update_freq(struct pps_normtime f= req_norm) delta_mod =3D delta; if (delta_mod < 0) delta_mod =3D -delta_mod; - pps_stabil +=3D (div_s64(((s64)delta_mod) << - (NTP_SCALE_SHIFT - SHIFT_USEC), - NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; + pps_stabil +=3D (div_s64(((s64)delta_mod) << (NTP_SCALE_SHIFT - SHIFT_USE= C), + NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; =20 /* If enabled, the system clock frequency is updated */ - if ((time_status & STA_PPSFREQ) !=3D 0 && - (time_status & STA_FREQHOLD) =3D=3D 0) { + if ((time_status & STA_PPSFREQ) && !(time_status & STA_FREQHOLD)) { time_freq =3D pps_freq; ntp_update_frequency(); } @@ -1007,15 +999,13 @@ static void hardpps_update_phase(long error) * the time offset is updated. */ if (jitter > (pps_jitter << PPS_POPCORN)) { - printk_deferred(KERN_WARNING - "hardpps: PPSJITTER: jitter=3D%ld, limit=3D%ld\n", + printk_deferred(KERN_WARNING "hardpps: PPSJITTER: jitter=3D%ld, limit=3D= %ld\n", jitter, (pps_jitter << PPS_POPCORN)); time_status |=3D STA_PPSJITTER; pps_jitcnt++; } else if (time_status & STA_PPSTIME) { /* Correct the time using the phase offset */ - time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, - NTP_INTERVAL_FREQ); + time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, NTP_INTERV= AL_FREQ); /* Cancel running adjtime() */ time_adjust =3D 0; } @@ -1064,9 +1054,8 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t * Check that the signal is in the range * [1s - MAXFREQ us, 1s + MAXFREQ us], otherwise reject it */ - if ((freq_norm.sec =3D=3D 0) || - (freq_norm.nsec > MAXFREQ * freq_norm.sec) || - (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { + if ((freq_norm.sec =3D=3D 0) || (freq_norm.nsec > MAXFREQ * freq_norm.sec= ) || + (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { time_status |=3D STA_PPSJITTER; /* Restart the frequency calibration interval */ pps_fbase =3D *raw_ts; --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C201319E986; Wed, 11 Sep 2024 13:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060683; cv=none; b=OHWCtdtgWtTnKvcYfS9dqcR62KqnlhhYvsUi74437xapuZ3l7YHOsrVSiLc2HcM/jVnKRvz1fyzsZ55jdnqR8eyHjPqc7lwKbEeZybYx1a5Zc+6ReiZjEBu3sw94lRaCaWsWIEvK8gp9+XiVw6usWYeKt9n9889xyaJyDiDmALw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060683; c=relaxed/simple; bh=bolCJSlXPwuNlLvo9JrEUkdBWj4DuVyS3W2/UOuZbPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VK0kETbAyR1rpzFScQl4eg/o0ZcmRf3yzgKzYWZ5rd7tkwtrQy+ypm6xtf9ds0SGjIIe8RgRr38D0DZl9Tq96BGusfToWt0FCRXUbvEMmQk+wG6GY92yt14sFd8aW1UGtlacfeoW08QrdOpBjPCgARZTXjo+mNzPw3+7ccgxwt8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jOhRNoy5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oPcsAEUM; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jOhRNoy5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oPcsAEUM" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ofWg+DYj+lK66Y5L8QFevXKM3R5+RFLSO92Pm6cRBfI=; b=jOhRNoy5M744JOe7ROY/REPakveJNnE3MAcrVVBzIczx7tAwebt1iOmbwEaweAU5D403vS jKwM3MAllBcSE4K4uORr3Nv1DxvaBAdyLQRPftG/KbvvrPjPdv/73o1+QS9pWjuBZ+5uXi E4OhQQ7Gx/yXxwhBU07t3ij7T5e7H6taOAQf53mMhtfOf1M0oh0WXZNfNa6aJzzJRohrMJ 9VprXkJtczoUnQCvamievIDw1IrFnC1knlHm2qcFpGUpOiiigb5THv86W+LgJINvl3J8TU 2+zBsr3cfOrgybmzLRyMcdphH/8+7xbgxmaMwCAGe89XKLE3yYP4yDyX+ByZmg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ofWg+DYj+lK66Y5L8QFevXKM3R5+RFLSO92Pm6cRBfI=; b=oPcsAEUMf5auH04uRtUMNgxgfo0FH2xGJFErDmvZpY0O32jOY3TL093S3NTchUvMbH/0MM NoRx5NhPRxtI02DA== Date: Wed, 11 Sep 2024 15:17:41 +0200 Subject: [PATCH 05/21] ntp: Convert functions with only two states to bool Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-5-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner is_error_status() and ntp_synced() return whether a state is set or not. Both functions use unsigned int for it even if it would be a perfect job for a bool. Use bool instead of unsigned int. And while at it, move ntp_synced() function to the place where it is used. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index eca9de85b0a7..ef758aafdfd5 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -171,7 +171,7 @@ static inline void pps_set_freq(s64 freq) pps_freq =3D freq; } =20 -static inline int is_error_status(int status) +static inline bool is_error_status(int status) { return (status & (STA_UNSYNC|STA_CLOCKERR)) /* @@ -221,7 +221,7 @@ static inline void pps_clear(void) {} static inline void pps_dec_valid(void) {} static inline void pps_set_freq(s64 freq) {} =20 -static inline int is_error_status(int status) +static inline bool is_error_status(int status) { return status & (STA_UNSYNC|STA_CLOCKERR); } @@ -241,21 +241,6 @@ static inline void pps_fill_timex(struct __kernel_time= x *txc) =20 #endif /* CONFIG_NTP_PPS */ =20 - -/** - * ntp_synced - Returns 1 if the NTP status is not UNSYNC - * - */ -static inline int ntp_synced(void) -{ - return !(time_status & STA_UNSYNC); -} - - -/* - * NTP methods: - */ - /* * Update tick_length and tick_length_base, based on tick_usec, ntp_tick_a= dj and * time_freq: @@ -609,6 +594,15 @@ static inline int update_rtc(struct timespec64 *to_set= , unsigned long *offset_ns } #endif =20 +/** + * ntp_synced - Tells whether the NTP status is not UNSYNC + * Returns: true if not UNSYNC, false otherwise + */ +static inline bool ntp_synced(void) +{ + return !(time_status & STA_UNSYNC); +} + /* * If we have an externally synchronized Linux clock, then update RTC clock * accordingly every ~11 minutes. Generally RTCs can only store second --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1FAA19E985; Wed, 11 Sep 2024 13:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; cv=none; b=Nt1QSHmiw8izJZJFYeb2Y/lcGLZBqPQISE40frM9e/bYHf5yyT60FsCRu3doAa7nMERgx0J1gC3wSe2WO2f4Y1Ny0AlSnUTnqR/Md0F6YJVQVotAiA8RXR+Lj1P93qO9ZOVqP8ipujq6SzM8XDfC/P1sPDYX1Wy6Di9vbTGDYIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; c=relaxed/simple; bh=DxyIwMaHDieZQX7yhTkZsEz0L/cwOK2r+4KMCcUTp34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cNLIYMImwjDIw3+Ac9AswA9cz8ZBDWyJWiDQ/bQD7FILEAfsAhscODJCQfKdTsWUK22Lsl3jqinJ8+KmqqCPgGQrC4xSS3MVPX+PYrxxIE7tWDH1VtORHj4g1YtB58n65pxsFOdTH6A5nt3z5IYW+Qx0tr3svRogdQZ+tQ1lGZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ACObcXxr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gu01vqI9; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ACObcXxr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gu01vqI9" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2PJShJDr/Fg/BGDALZOu0lQbepTLwabMWlBkQ3Alb4=; b=ACObcXxryO2USimGGyer3fpm6vQHX6CCHJpT9Ut1FNwBFBz8CmwLxqn8wQj+0ldwsYy3Pm scaxEB9s4XyaY0DXzF3ym+cSh7EVlVEm26yXVDq3gP647tPWFggu6t+RHydcKnpGMMZOYc krX84IYs50bPhS28QRwgZHL+TindZnpTiE/yKszAkTJCTCiITKVlox6rUu5FVJBVjAOT4g M6LvIQcpNSsvVlUO4ajRrfR4OKHFGM3E+qT4+isQN3mwWpbYsE6eCiEYUOdZJBw/Y2Q+fD pLbnHyHY1GYgFyJViS1IoBOtndKbLu0FwNJWoO9dPzaqEUsFOWL6qwmVbCtZ5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2PJShJDr/Fg/BGDALZOu0lQbepTLwabMWlBkQ3Alb4=; b=gu01vqI9Byw4mFkdag5m6SLPYo4JsLvtlOlNZOH+eCwSOT5KMSq3LL0sl/q2VoxsVAX3/p uMydbqtJ//hkIGDg== Date: Wed, 11 Sep 2024 15:17:42 +0200 Subject: [PATCH 06/21] ntp: Read reference time only once Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-6-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner The reference time is required twice in ntp_update_offset(). It will not change in the meantime as the calling code holds the timekeeper lock. Read it only once and store it into a local variable. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index ef758aafdfd5..477cb08062bc 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -283,9 +283,8 @@ static inline s64 ntp_update_offset_fll(s64 offset64, l= ong secs) =20 static void ntp_update_offset(long offset) { - s64 freq_adj; - s64 offset64; - long secs; + s64 freq_adj, offset64; + long secs, real_secs; =20 if (!(time_status & STA_PLL)) return; @@ -303,11 +302,12 @@ static void ntp_update_offset(long offset) * Select how the frequency is to be controlled * and in which mode (PLL or FLL). */ - secs =3D (long)(__ktime_get_real_seconds() - time_reftime); + real_secs =3D __ktime_get_real_seconds(); + secs =3D (long)(real_secs - time_reftime); if (unlikely(time_status & STA_FREQHOLD)) secs =3D 0; =20 - time_reftime =3D __ktime_get_real_seconds(); + time_reftime =3D real_secs; =20 offset64 =3D offset; freq_adj =3D ntp_update_offset_fll(offset64, secs); --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0D9B19E98C; Wed, 11 Sep 2024 13:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060683; cv=none; b=OSrdDaywivh47cU2SOhjn6NXEh/mtQstAsIwxGZhn/6M3W4ESWxTMbnVFnMPYda+DVTr/fsaOvfoK8KRk+BLoSJGYZ4/dWX7qiTBX27DGpmtVfymCqD+38ACaq+LxsXxtWdGw8UYAHd8KlDULccAuFopmhpZ8QooMyb+XcYof0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060683; c=relaxed/simple; bh=031nbNNh15p2+Nc2smc3wdle/5MlfTElDr4SLgtVumg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z4ehWWty9U36SwY1HmJzzitmSz1HvEQ4UMmXbuWdpSffnahHpOSlEa7PPll//2TfaxpbE9f1SbKu4p6undRjzPYfNn0NAbgnkVbFk66gWHwtY7gnieIvbBdVtBn9knAxZh566rzR3A7F2iJJfF1ZnVyT5py8vYFwDDLebkMusaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OapWP18H; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=K/5Pzt0E; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OapWP18H"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K/5Pzt0E" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gweTRhv1XfM5ayJMavZ8lkpktxTkQkmd6055R9JLJi4=; b=OapWP18HiOalUs1pbvw5QGOMrSRsl3bblnRaINDe15jVEreIE7lm7EXXNDSym59VLI67YA KD3Jw8NpnarZH2MVmg1HqbGrfTRHuTJqYlBvL0AJ2/czAH+IU4ab+YmW4KyOg87pcf3OAy qYEt/IMq6/FaJmMqfviY7XKLe6heBYL92+fGmA4C2Tg/f2/uGaq0ZxPtmtmPzAR0T+QKiR qfkXoQyNlN0uaxYjgGor9c8I2Hraz776/4H0/9GsT3A+Ice3sQAq2YC63s4EN74TnrdKrL 6Tc+wXbeZ7KG7ToNOOGVerzxJ2L5g22t3BqoK7zrhZ0qC6sRFuKBFde2HdKZKA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gweTRhv1XfM5ayJMavZ8lkpktxTkQkmd6055R9JLJi4=; b=K/5Pzt0EJYWMBxmZJvxEHcfhQGS/AInBYrCXGBoXvBOJ+/Z7wRl8Js+2EW+nWbaErpMEKx Oml+QUqSN8WSS8BA== Date: Wed, 11 Sep 2024 15:17:43 +0200 Subject: [PATCH 07/21] ntp: Introduce struct ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-7-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner All NTP data is held in static variables. That prevents the NTP code from being reuasble for non-system time timekeepers, e.g. per PTP clock timekeeping. Introduce struct ntp_data and move tick_usec into it for a start. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 65 ++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 477cb08062bc..0222f8e46081 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -22,16 +22,19 @@ #include "ntp_internal.h" #include "timekeeping_internal.h" =20 - -/* - * NTP timekeeping variables: +/** + * struct ntp_data - Structure holding all NTP related state + * @tick_usec: USER_HZ period in microseconds * - * Note: All of the NTP state is protected by the timekeeping locks. + * Protected by the timekeeping locks. */ +struct ntp_data { + unsigned long tick_usec; +}; =20 - -/* USER_HZ period (usecs): */ -static unsigned long tick_usec =3D USER_TICK_USEC; +static struct ntp_data tk_ntp_data =3D { + .tick_usec =3D USER_TICK_USEC, +}; =20 static u64 tick_length; static u64 tick_length_base; @@ -245,13 +248,11 @@ static inline void pps_fill_timex(struct __kernel_tim= ex *txc) * Update tick_length and tick_length_base, based on tick_usec, ntp_tick_a= dj and * time_freq: */ -static void ntp_update_frequency(void) +static void ntp_update_frequency(struct ntp_data *ntpdata) { - u64 second_length; - u64 new_base; + u64 second_length, new_base, tick_usec =3D (u64)ntpdata->tick_usec; =20 - second_length =3D (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) - << NTP_SCALE_SHIFT; + second_length =3D (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) << NTP_SCA= LE_SHIFT; =20 second_length +=3D ntp_tick_adj; second_length +=3D time_freq; @@ -330,10 +331,7 @@ static void ntp_update_offset(long offset) time_offset =3D div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); } =20 -/** - * ntp_clear - Clears the NTP state variables - */ -void ntp_clear(void) +static void __ntp_clear(struct ntp_data *ntpdata) { /* Stop active adjtime() */ time_adjust =3D 0; @@ -341,7 +339,7 @@ void ntp_clear(void) time_maxerror =3D NTP_PHASE_LIMIT; time_esterror =3D NTP_PHASE_LIMIT; =20 - ntp_update_frequency(); + ntp_update_frequency(ntpdata); =20 tick_length =3D tick_length_base; time_offset =3D 0; @@ -351,6 +349,14 @@ void ntp_clear(void) pps_clear(); } =20 +/** + * ntp_clear - Clears the NTP state variables + */ +void ntp_clear(void) +{ + __ntp_clear(&tk_ntp_data); +} + =20 u64 ntp_tick_length(void) { @@ -698,7 +704,7 @@ static inline void process_adj_status(const struct __ke= rnel_timex *txc) } =20 =20 -static inline void process_adjtimex_modes(const struct __kernel_timex *txc, +static inline void process_adjtimex_modes(struct ntp_data *ntpdata, const = struct __kernel_timex *txc, s32 *time_tai) { if (txc->modes & ADJ_STATUS) @@ -739,13 +745,12 @@ static inline void process_adjtimex_modes(const struc= t __kernel_timex *txc, ntp_update_offset(txc->offset); =20 if (txc->modes & ADJ_TICK) - tick_usec =3D txc->tick; + ntpdata->tick_usec =3D txc->tick; =20 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET)) - ntp_update_frequency(); + ntp_update_frequency(ntpdata); } =20 - /* * adjtimex() mainly allows reading (and writing, if superuser) of * kernel time-keeping variables. used by xntpd. @@ -753,6 +758,7 @@ static inline void process_adjtimex_modes(const struct = __kernel_timex *txc, int __do_adjtimex(struct __kernel_timex *txc, const struct timespec64 *ts, s32 *time_tai, struct audit_ntp_data *ad) { + struct ntp_data *ntpdata =3D &tk_ntp_data; int result; =20 if (txc->modes & ADJ_ADJTIME) { @@ -761,7 +767,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, if (!(txc->modes & ADJ_OFFSET_READONLY)) { /* adjtime() is independent from ntp_adjtime() */ time_adjust =3D txc->offset; - ntp_update_frequency(); + ntp_update_frequency(ntpdata); =20 audit_ntp_set_old(ad, AUDIT_NTP_ADJUST, save_adjust); audit_ntp_set_new(ad, AUDIT_NTP_ADJUST, time_adjust); @@ -774,15 +780,15 @@ int __do_adjtimex(struct __kernel_timex *txc, const s= truct timespec64 *ts, audit_ntp_set_old(ad, AUDIT_NTP_FREQ, time_freq); audit_ntp_set_old(ad, AUDIT_NTP_STATUS, time_status); audit_ntp_set_old(ad, AUDIT_NTP_TAI, *time_tai); - audit_ntp_set_old(ad, AUDIT_NTP_TICK, tick_usec); + audit_ntp_set_old(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); =20 - process_adjtimex_modes(txc, time_tai); + process_adjtimex_modes(ntpdata, txc, time_tai); =20 audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, time_offset); audit_ntp_set_new(ad, AUDIT_NTP_FREQ, time_freq); audit_ntp_set_new(ad, AUDIT_NTP_STATUS, time_status); audit_ntp_set_new(ad, AUDIT_NTP_TAI, *time_tai); - audit_ntp_set_new(ad, AUDIT_NTP_TICK, tick_usec); + audit_ntp_set_new(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); } =20 txc->offset =3D shift_right(time_offset * NTP_INTERVAL_FREQ, @@ -803,7 +809,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, txc->constant =3D time_constant; txc->precision =3D 1; txc->tolerance =3D MAXFREQ_SCALED / PPM_SCALE; - txc->tick =3D tick_usec; + txc->tick =3D ntpdata->tick_usec; txc->tai =3D *time_tai; =20 /* Fill PPS status fields */ @@ -924,7 +930,7 @@ static inline void pps_inc_freq_interval(void) * too long, the data are discarded. * Returns the difference between old and new frequency values. */ -static long hardpps_update_freq(struct pps_normtime freq_norm) +static long hardpps_update_freq(struct ntp_data *ntpdata, struct pps_normt= ime freq_norm) { long delta, delta_mod; s64 ftemp; @@ -971,7 +977,7 @@ static long hardpps_update_freq(struct pps_normtime fre= q_norm) /* If enabled, the system clock frequency is updated */ if ((time_status & STA_PPSFREQ) && !(time_status & STA_FREQHOLD)) { time_freq =3D pps_freq; - ntp_update_frequency(); + ntp_update_frequency(ntpdata); } =20 return delta; @@ -1022,6 +1028,7 @@ static void hardpps_update_phase(long error) void __hardpps(const struct timespec64 *phase_ts, const struct timespec64 = *raw_ts) { struct pps_normtime pts_norm, freq_norm; + struct ntp_data *ntpdata =3D &tk_ntp_data; =20 pts_norm =3D pps_normalize_ts(*phase_ts); =20 @@ -1062,7 +1069,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t pps_calcnt++; /* Restart the frequency calibration interval */ pps_fbase =3D *raw_ts; - hardpps_update_freq(freq_norm); + hardpps_update_freq(ntpdata, freq_norm); } =20 hardpps_update_phase(pts_norm.nsec); --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C208F19E987; Wed, 11 Sep 2024 13:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060683; cv=none; b=QHq0m2FdhCDAIrbWeibDm5Cb0MJ7WDTgbeSxVYjHe9nsxhWfJXCEwkJEBzkip4DKc/5/hVbTS87cPrQ9qZcOVvVdjw7OvJJLUZbOn8U+FlZs9LzzYGGqWrBCOxWhzmp79jl08OikjtmHmN6dSsI92C5gfQfwR36pwq4dUFPeW0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060683; c=relaxed/simple; bh=mCkP05nPR2dyDok4kENhzn3NK6WJPqM9b98DanQBSbM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rC1ZzRdXXPpC2hrwVXSm4zkRpPBGS+sI6vBeMNdneE1rB0ABiNKyXej1w2tA9nFLO08fOqP6PEozhuoAGs+FawkXbf3olHr1MItSyG0uPM6r7EZQVncS6L+fnFdWRG4oS2Cg6zThW01getuzsRXyH1sMy6X8ECt2sSwfDxCFaPY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bCmXi7J5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6MElUGtg; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bCmXi7J5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6MElUGtg" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FXNbwrHSXrnt15cm/AG2lq5xxPwSA6Sw6Z+iK16YEl4=; b=bCmXi7J5XCTZybj6XotgijL59RRzQElfNnzlBGwypOlxhKBSMZyExG73PVhky0qVx2Bv2v rNRwaKYlm7cnPSo8ut/fSa7b4aezJ+7gkuklhqjmW68/oEyu7jomW5+jbdLFRkZAOr8VAQ KQKjHAW9T6CIOEZH6hubHU06pCL5np3AAbv9/h1Lc+Ns/VgdKrZqtHDU+Qpxykim4KRuRB Q/28IqoCKTF6jOchJcPFEbGWl5j+EtNAKBWKtbS2XKEofQG2ze46FxK6wIkx+hJDkJQMd5 Odpgvd86nkq2mKeWLOsXbjDRceiSsCAqWfJV4YaLcIvjULKsN+p5VB2M0u58cQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FXNbwrHSXrnt15cm/AG2lq5xxPwSA6Sw6Z+iK16YEl4=; b=6MElUGtgL40/wWZRCCuL+LvhI12CBqe3qcpsRdFuNLZULjlqC21ws+/1dDp8JcXLB6PJx6 z49rOkUyxmHxssDQ== Date: Wed, 11 Sep 2024 15:17:44 +0200 Subject: [PATCH 08/21] ntp: Move tick_length* into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-8-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 0222f8e46081..6c5f684328c8 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -25,20 +25,21 @@ /** * struct ntp_data - Structure holding all NTP related state * @tick_usec: USER_HZ period in microseconds + * @tick_length: Adjusted tick length + * @tick_length_base: Base value for @tick_length * * Protected by the timekeeping locks. */ struct ntp_data { unsigned long tick_usec; + u64 tick_length; + u64 tick_length_base; }; =20 static struct ntp_data tk_ntp_data =3D { .tick_usec =3D USER_TICK_USEC, }; =20 -static u64 tick_length; -static u64 tick_length_base; - #define SECS_PER_DAY 86400 #define MAX_TICKADJ 500LL /* usecs */ #define MAX_TICKADJ_SCALED \ @@ -263,8 +264,8 @@ static void ntp_update_frequency(struct ntp_data *ntpda= ta) * Don't wait for the next second_overflow, apply the change to the * tick length immediately: */ - tick_length +=3D new_base - tick_length_base; - tick_length_base =3D new_base; + ntpdata->tick_length +=3D new_base - ntpdata->tick_length_base; + ntpdata->tick_length_base =3D new_base; } =20 static inline s64 ntp_update_offset_fll(s64 offset64, long secs) @@ -341,8 +342,8 @@ static void __ntp_clear(struct ntp_data *ntpdata) =20 ntp_update_frequency(ntpdata); =20 - tick_length =3D tick_length_base; - time_offset =3D 0; + ntpdata->tick_length =3D ntpdata->tick_length_base; + time_offset =3D 0; =20 ntp_next_leap_sec =3D TIME64_MAX; /* Clear PPS state variables */ @@ -360,7 +361,7 @@ void ntp_clear(void) =20 u64 ntp_tick_length(void) { - return tick_length; + return tk_ntp_data.tick_length; } =20 /** @@ -391,6 +392,7 @@ ktime_t ntp_get_next_leap(void) */ int second_overflow(time64_t secs) { + struct ntp_data *ntpdata =3D &tk_ntp_data; s64 delta; int leap =3D 0; s32 rem; @@ -451,11 +453,11 @@ int second_overflow(time64_t secs) } =20 /* Compute the phase adjustment for the next second */ - tick_length =3D tick_length_base; + ntpdata->tick_length =3D ntpdata->tick_length_base; =20 - delta =3D ntp_offset_chunk(time_offset); - time_offset -=3D delta; - tick_length +=3D delta; + delta =3D ntp_offset_chunk(time_offset); + time_offset -=3D delta; + ntpdata->tick_length +=3D delta; =20 /* Check PPS signal */ pps_dec_valid(); @@ -465,18 +467,18 @@ int second_overflow(time64_t secs) =20 if (time_adjust > MAX_TICKADJ) { time_adjust -=3D MAX_TICKADJ; - tick_length +=3D MAX_TICKADJ_SCALED; + ntpdata->tick_length +=3D MAX_TICKADJ_SCALED; goto out; } =20 if (time_adjust < -MAX_TICKADJ) { time_adjust +=3D MAX_TICKADJ; - tick_length -=3D MAX_TICKADJ_SCALED; + ntpdata->tick_length -=3D MAX_TICKADJ_SCALED; goto out; } =20 - tick_length +=3D (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVAL_FREQ) - << NTP_SCALE_SHIFT; + ntpdata->tick_length +=3D (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVA= L_FREQ) + << NTP_SCALE_SHIFT; time_adjust =3D 0; =20 out: --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B45119EEB7; Wed, 11 Sep 2024 13:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060685; cv=none; b=ddf/lQ2lJYF1faaKPioELvDyrb4uPlqeFUsRLBFtPp5CHftFXa629IpjJnRfUSmODzihJMrzSdfp6j8+tuBYml/1FYL2VHFHLa2S08fbh6/MdposSt2C1hEve8qpGa362piyG8CMZqZ5iAc3GknZBFoJyzIZ6sK0uqyYyGCDfXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060685; c=relaxed/simple; bh=ZoDFUf51l3H/WcLUcto7GVyoIeSg8tr4rsTPyE8PgEA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i6IPLMoOWA+bwZ/ScB+1druQOVDmVZtfUEEt6BetsiCdnt16cPkrTy8hB52FTYbh1yLS3hL8f+YBI+zrL/OJPxThMHffpFul9uvZBelhrSikEq/2v9UNS8TwY4CphuW6hsudVnBGVbL0Vv1SQK3fMvGNzeKwNyv/AonQNNFYgQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YvfEe/zG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=702zThgt; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YvfEe/zG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="702zThgt" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RlMdE3TYxqwLQSPlWb5h5InAD5kxN3qEYqa3UzZv1H4=; b=YvfEe/zGyYVbCBvGYLsDPbElSggfoeheuMRR89HFnIc4zinbMBuGHTJcvjEUUk7b/XUrKJ 3tpuYCAAaB4XDxFQ0FV+F0E9RPs8C+pNvSoCi0vPlEsT9LoscQe4ZjkRZcirIMOqkLoflL +CwQdtGjM/3iCvLHWxAiNU1HBgoKzQkPbK6VC7Db2TwXYnw5+jwuCpJWgb84yTRYSn9yX4 wCFHxXaw3H/UT9+5+6Ke+y82o+19g0vyY+yJai6bvwB7apqtNo5Off4QLEIJwd3bY+lENE FVBNLmGvZ0kBXLPlvw2KmzRBTYwXVjtNXje6hZW4YT35C8jGxFm5lqZzjtFe9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RlMdE3TYxqwLQSPlWb5h5InAD5kxN3qEYqa3UzZv1H4=; b=702zThgtCf5z/yjodhZKpcCXV5FOjH0Uvr6FuG3TPmUg/ivBDs9J007iGs3X6wG7aUYnRm 4lIOXN6jHFOSWGDg== Date: Wed, 11 Sep 2024 15:17:45 +0200 Subject: [PATCH 09/21] ntp: Move tick_stat* into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-9-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 175 ++++++++++++++++++++++++++------------------------= ---- 1 file changed, 85 insertions(+), 90 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 6c5f684328c8..6d87f9889b03 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -27,6 +27,8 @@ * @tick_usec: USER_HZ period in microseconds * @tick_length: Adjusted tick length * @tick_length_base: Base value for @tick_length + * @time_state: State of the clock synchronization + * @time_status: Clock status bits * * Protected by the timekeeping locks. */ @@ -34,10 +36,14 @@ struct ntp_data { unsigned long tick_usec; u64 tick_length; u64 tick_length_base; + int time_state; + int time_status; }; =20 static struct ntp_data tk_ntp_data =3D { .tick_usec =3D USER_TICK_USEC, + .time_state =3D TIME_OK, + .time_status =3D STA_UNSYNC, }; =20 #define SECS_PER_DAY 86400 @@ -53,16 +59,6 @@ static struct ntp_data tk_ntp_data =3D { * estimated error =3D NTP dispersion. */ =20 -/* - * clock synchronization status - * - * (TIME_ERROR prevents overwriting the CMOS clock) - */ -static int time_state =3D TIME_OK; - -/* clock status bits: */ -static int time_status =3D STA_UNSYNC; - /* time adjustment (nsecs): */ static s64 time_offset; =20 @@ -127,9 +123,9 @@ static long pps_errcnt; /* calibration errors */ * PPS kernel consumer compensates the whole phase error immediately. * Otherwise, reduce the offset by a fixed factor times the time constant. */ -static inline s64 ntp_offset_chunk(s64 offset) +static inline s64 ntp_offset_chunk(struct ntp_data *ntpdata, s64 offset) { - if (time_status & STA_PPSTIME && time_status & STA_PPSSIGNAL) + if (ntpdata->time_status & STA_PPSTIME && ntpdata->time_status & STA_PPSS= IGNAL) return offset; else return shift_right(offset, SHIFT_PLL + time_constant); @@ -159,13 +155,13 @@ static inline void pps_clear(void) * Decrease pps_valid to indicate that another second has passed since the * last PPS signal. When it reaches 0, indicate that PPS signal is missing. */ -static inline void pps_dec_valid(void) +static inline void pps_dec_valid(struct ntp_data *ntpdata) { if (pps_valid > 0) pps_valid--; else { - time_status &=3D ~(STA_PPSSIGNAL | STA_PPSJITTER | - STA_PPSWANDER | STA_PPSERROR); + ntpdata->time_status &=3D ~(STA_PPSSIGNAL | STA_PPSJITTER | + STA_PPSWANDER | STA_PPSERROR); pps_clear(); } } @@ -198,12 +194,12 @@ static inline bool is_error_status(int status) && (status & (STA_PPSWANDER|STA_PPSERROR))); } =20 -static inline void pps_fill_timex(struct __kernel_timex *txc) +static inline void pps_fill_timex(struct ntp_data *ntpdata, struct __kerne= l_timex *txc) { txc->ppsfreq =3D shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) * PPM_SCALE_INV, NTP_SCALE_SHIFT); txc->jitter =3D pps_jitter; - if (!(time_status & STA_NANO)) + if (!(ntpdata->time_status & STA_NANO)) txc->jitter =3D pps_jitter / NSEC_PER_USEC; txc->shift =3D pps_shift; txc->stabil =3D pps_stabil; @@ -215,14 +211,14 @@ static inline void pps_fill_timex(struct __kernel_tim= ex *txc) =20 #else /* !CONFIG_NTP_PPS */ =20 -static inline s64 ntp_offset_chunk(s64 offset) +static inline s64 ntp_offset_chunk(struct ntp_data *ntp, s64 offset) { return shift_right(offset, SHIFT_PLL + time_constant); } =20 static inline void pps_reset_freq_interval(void) {} static inline void pps_clear(void) {} -static inline void pps_dec_valid(void) {} +static inline void pps_dec_valid(struct ntp_data *ntpdata) {} static inline void pps_set_freq(s64 freq) {} =20 static inline bool is_error_status(int status) @@ -230,7 +226,7 @@ static inline bool is_error_status(int status) return status & (STA_UNSYNC|STA_CLOCKERR); } =20 -static inline void pps_fill_timex(struct __kernel_timex *txc) +static inline void pps_fill_timex(struct ntp_data *ntpdata, struct __kerne= l_timex *txc) { /* PPS is not implemented, so these are zero */ txc->ppsfreq =3D 0; @@ -268,30 +264,30 @@ static void ntp_update_frequency(struct ntp_data *ntp= data) ntpdata->tick_length_base =3D new_base; } =20 -static inline s64 ntp_update_offset_fll(s64 offset64, long secs) +static inline s64 ntp_update_offset_fll(struct ntp_data *ntpdata, s64 offs= et64, long secs) { - time_status &=3D ~STA_MODE; + ntpdata->time_status &=3D ~STA_MODE; =20 if (secs < MINSEC) return 0; =20 - if (!(time_status & STA_FLL) && (secs <=3D MAXSEC)) + if (!(ntpdata->time_status & STA_FLL) && (secs <=3D MAXSEC)) return 0; =20 - time_status |=3D STA_MODE; + ntpdata->time_status |=3D STA_MODE; =20 return div64_long(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs); } =20 -static void ntp_update_offset(long offset) +static void ntp_update_offset(struct ntp_data *ntpdata, long offset) { s64 freq_adj, offset64; long secs, real_secs; =20 - if (!(time_status & STA_PLL)) + if (!(ntpdata->time_status & STA_PLL)) return; =20 - if (!(time_status & STA_NANO)) { + if (!(ntpdata->time_status & STA_NANO)) { /* Make sure the multiplication below won't overflow */ offset =3D clamp(offset, -USEC_PER_SEC, USEC_PER_SEC); offset *=3D NSEC_PER_USEC; @@ -306,13 +302,13 @@ static void ntp_update_offset(long offset) */ real_secs =3D __ktime_get_real_seconds(); secs =3D (long)(real_secs - time_reftime); - if (unlikely(time_status & STA_FREQHOLD)) + if (unlikely(ntpdata->time_status & STA_FREQHOLD)) secs =3D 0; =20 time_reftime =3D real_secs; =20 offset64 =3D offset; - freq_adj =3D ntp_update_offset_fll(offset64, secs); + freq_adj =3D ntp_update_offset_fll(ntpdata, offset64, secs); =20 /* * Clamp update interval to reduce PLL gain with low @@ -335,10 +331,10 @@ static void ntp_update_offset(long offset) static void __ntp_clear(struct ntp_data *ntpdata) { /* Stop active adjtime() */ - time_adjust =3D 0; - time_status |=3D STA_UNSYNC; - time_maxerror =3D NTP_PHASE_LIMIT; - time_esterror =3D NTP_PHASE_LIMIT; + time_adjust =3D 0; + ntpdata->time_status |=3D STA_UNSYNC; + time_maxerror =3D NTP_PHASE_LIMIT; + time_esterror =3D NTP_PHASE_LIMIT; =20 ntp_update_frequency(ntpdata); =20 @@ -372,9 +368,10 @@ u64 ntp_tick_length(void) */ ktime_t ntp_get_next_leap(void) { + struct ntp_data *ntpdata =3D &tk_ntp_data; ktime_t ret; =20 - if ((time_state =3D=3D TIME_INS) && (time_status & STA_INS)) + if ((ntpdata->time_state =3D=3D TIME_INS) && (ntpdata->time_status & STA_= INS)) return ktime_set(ntp_next_leap_sec, 0); ret =3D KTIME_MAX; return ret; @@ -402,46 +399,46 @@ int second_overflow(time64_t secs) * day, the system clock is set back one second; if in leap-delete * state, the system clock is set ahead one second. */ - switch (time_state) { + switch (ntpdata->time_state) { case TIME_OK: - if (time_status & STA_INS) { - time_state =3D TIME_INS; + if (ntpdata->time_status & STA_INS) { + ntpdata->time_state =3D TIME_INS; div_s64_rem(secs, SECS_PER_DAY, &rem); ntp_next_leap_sec =3D secs + SECS_PER_DAY - rem; - } else if (time_status & STA_DEL) { - time_state =3D TIME_DEL; + } else if (ntpdata->time_status & STA_DEL) { + ntpdata->time_state =3D TIME_DEL; div_s64_rem(secs + 1, SECS_PER_DAY, &rem); ntp_next_leap_sec =3D secs + SECS_PER_DAY - rem; } break; case TIME_INS: - if (!(time_status & STA_INS)) { + if (!(ntpdata->time_status & STA_INS)) { ntp_next_leap_sec =3D TIME64_MAX; - time_state =3D TIME_OK; + ntpdata->time_state =3D TIME_OK; } else if (secs =3D=3D ntp_next_leap_sec) { leap =3D -1; - time_state =3D TIME_OOP; + ntpdata->time_state =3D TIME_OOP; pr_notice("Clock: inserting leap second 23:59:60 UTC\n"); } break; case TIME_DEL: - if (!(time_status & STA_DEL)) { + if (!(ntpdata->time_status & STA_DEL)) { ntp_next_leap_sec =3D TIME64_MAX; - time_state =3D TIME_OK; + ntpdata->time_state =3D TIME_OK; } else if (secs =3D=3D ntp_next_leap_sec) { leap =3D 1; ntp_next_leap_sec =3D TIME64_MAX; - time_state =3D TIME_WAIT; + ntpdata->time_state =3D TIME_WAIT; pr_notice("Clock: deleting leap second 23:59:59 UTC\n"); } break; case TIME_OOP: ntp_next_leap_sec =3D TIME64_MAX; - time_state =3D TIME_WAIT; + ntpdata->time_state =3D TIME_WAIT; break; case TIME_WAIT: - if (!(time_status & (STA_INS | STA_DEL))) - time_state =3D TIME_OK; + if (!(ntpdata->time_status & (STA_INS | STA_DEL))) + ntpdata->time_state =3D TIME_OK; break; } =20 @@ -449,18 +446,18 @@ int second_overflow(time64_t secs) time_maxerror +=3D MAXFREQ / NSEC_PER_USEC; if (time_maxerror > NTP_PHASE_LIMIT) { time_maxerror =3D NTP_PHASE_LIMIT; - time_status |=3D STA_UNSYNC; + ntpdata->time_status |=3D STA_UNSYNC; } =20 /* Compute the phase adjustment for the next second */ ntpdata->tick_length =3D ntpdata->tick_length_base; =20 - delta =3D ntp_offset_chunk(time_offset); + delta =3D ntp_offset_chunk(ntpdata, time_offset); time_offset -=3D delta; ntpdata->tick_length +=3D delta; =20 /* Check PPS signal */ - pps_dec_valid(); + pps_dec_valid(ntpdata); =20 if (!time_adjust) goto out; @@ -608,7 +605,7 @@ static inline int update_rtc(struct timespec64 *to_set,= unsigned long *offset_ns */ static inline bool ntp_synced(void) { - return !(time_status & STA_UNSYNC); + return !(tk_ntp_data.time_status & STA_UNSYNC); } =20 /* @@ -683,11 +680,11 @@ static inline void __init ntp_init_cmos_sync(void) { } /* * Propagate a new txc->status value into the NTP state: */ -static inline void process_adj_status(const struct __kernel_timex *txc) +static inline void process_adj_status(struct ntp_data *ntpdata, const stru= ct __kernel_timex *txc) { - if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) { - time_state =3D TIME_OK; - time_status =3D STA_UNSYNC; + if ((ntpdata->time_status & STA_PLL) && !(txc->status & STA_PLL)) { + ntpdata->time_state =3D TIME_OK; + ntpdata->time_status =3D STA_UNSYNC; ntp_next_leap_sec =3D TIME64_MAX; /* Restart PPS frequency calibration */ pps_reset_freq_interval(); @@ -697,26 +694,25 @@ static inline void process_adj_status(const struct __= kernel_timex *txc) * If we turn on PLL adjustments then reset the * reference time to current time. */ - if (!(time_status & STA_PLL) && (txc->status & STA_PLL)) + if (!(ntpdata->time_status & STA_PLL) && (txc->status & STA_PLL)) time_reftime =3D __ktime_get_real_seconds(); =20 - /* Only set allowed bits */ - time_status &=3D STA_RONLY; - time_status |=3D txc->status & ~STA_RONLY; + /* only set allowed bits */ + ntpdata->time_status &=3D STA_RONLY; + ntpdata->time_status |=3D txc->status & ~STA_RONLY; } =20 - static inline void process_adjtimex_modes(struct ntp_data *ntpdata, const = struct __kernel_timex *txc, s32 *time_tai) { if (txc->modes & ADJ_STATUS) - process_adj_status(txc); + process_adj_status(ntpdata, txc); =20 if (txc->modes & ADJ_NANO) - time_status |=3D STA_NANO; + ntpdata->time_status |=3D STA_NANO; =20 if (txc->modes & ADJ_MICRO) - time_status &=3D ~STA_NANO; + ntpdata->time_status &=3D ~STA_NANO; =20 if (txc->modes & ADJ_FREQUENCY) { time_freq =3D txc->freq * PPM_SCALE; @@ -734,17 +730,16 @@ static inline void process_adjtimex_modes(struct ntp_= data *ntpdata, const struct =20 if (txc->modes & ADJ_TIMECONST) { time_constant =3D clamp(txc->constant, 0, MAXTC); - if (!(time_status & STA_NANO)) + if (!(ntpdata->time_status & STA_NANO)) time_constant +=3D 4; time_constant =3D clamp(time_constant, 0, MAXTC); } =20 - if (txc->modes & ADJ_TAI && - txc->constant >=3D 0 && txc->constant <=3D MAX_TAI_OFFSET) + if (txc->modes & ADJ_TAI && txc->constant >=3D 0 && txc->constant <=3D MA= X_TAI_OFFSET) *time_tai =3D txc->constant; =20 if (txc->modes & ADJ_OFFSET) - ntp_update_offset(txc->offset); + ntp_update_offset(ntpdata, txc->offset); =20 if (txc->modes & ADJ_TICK) ntpdata->tick_usec =3D txc->tick; @@ -780,7 +775,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, if (txc->modes) { audit_ntp_set_old(ad, AUDIT_NTP_OFFSET, time_offset); audit_ntp_set_old(ad, AUDIT_NTP_FREQ, time_freq); - audit_ntp_set_old(ad, AUDIT_NTP_STATUS, time_status); + audit_ntp_set_old(ad, AUDIT_NTP_STATUS, ntpdata->time_status); audit_ntp_set_old(ad, AUDIT_NTP_TAI, *time_tai); audit_ntp_set_old(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); =20 @@ -788,26 +783,26 @@ int __do_adjtimex(struct __kernel_timex *txc, const s= truct timespec64 *ts, =20 audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, time_offset); audit_ntp_set_new(ad, AUDIT_NTP_FREQ, time_freq); - audit_ntp_set_new(ad, AUDIT_NTP_STATUS, time_status); + audit_ntp_set_new(ad, AUDIT_NTP_STATUS, ntpdata->time_status); audit_ntp_set_new(ad, AUDIT_NTP_TAI, *time_tai); audit_ntp_set_new(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); } =20 txc->offset =3D shift_right(time_offset * NTP_INTERVAL_FREQ, NTP_SCALE_SHIFT); - if (!(time_status & STA_NANO)) + if (!(ntpdata->time_status & STA_NANO)) txc->offset =3D (u32)txc->offset / NSEC_PER_USEC; } =20 - result =3D time_state; - if (is_error_status(time_status)) + result =3D ntpdata->time_state; + if (is_error_status(ntpdata->time_status)) result =3D TIME_ERROR; =20 txc->freq =3D shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * PPM_SCALE_INV, NTP_SCALE_SHIFT); txc->maxerror =3D time_maxerror; txc->esterror =3D time_esterror; - txc->status =3D time_status; + txc->status =3D ntpdata->time_status; txc->constant =3D time_constant; txc->precision =3D 1; txc->tolerance =3D MAXFREQ_SCALED / PPM_SCALE; @@ -815,26 +810,26 @@ int __do_adjtimex(struct __kernel_timex *txc, const s= truct timespec64 *ts, txc->tai =3D *time_tai; =20 /* Fill PPS status fields */ - pps_fill_timex(txc); + pps_fill_timex(ntpdata, txc); =20 txc->time.tv_sec =3D ts->tv_sec; txc->time.tv_usec =3D ts->tv_nsec; - if (!(time_status & STA_NANO)) + if (!(ntpdata->time_status & STA_NANO)) txc->time.tv_usec =3D ts->tv_nsec / NSEC_PER_USEC; =20 /* Handle leapsec adjustments */ if (unlikely(ts->tv_sec >=3D ntp_next_leap_sec)) { - if ((time_state =3D=3D TIME_INS) && (time_status & STA_INS)) { + if ((ntpdata->time_state =3D=3D TIME_INS) && (ntpdata->time_status & STA= _INS)) { result =3D TIME_OOP; txc->tai++; txc->time.tv_sec--; } - if ((time_state =3D=3D TIME_DEL) && (time_status & STA_DEL)) { + if ((ntpdata->time_state =3D=3D TIME_DEL) && (ntpdata->time_status & STA= _DEL)) { result =3D TIME_WAIT; txc->tai--; txc->time.tv_sec++; } - if ((time_state =3D=3D TIME_OOP) && (ts->tv_sec =3D=3D ntp_next_leap_sec= )) + if ((ntpdata->time_state =3D=3D TIME_OOP) && (ts->tv_sec =3D=3D ntp_next= _leap_sec)) result =3D TIME_WAIT; } =20 @@ -939,7 +934,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr =20 /* Check if the frequency interval was too long */ if (freq_norm.sec > (2 << pps_shift)) { - time_status |=3D STA_PPSERROR; + ntpdata->time_status |=3D STA_PPSERROR; pps_errcnt++; pps_dec_freq_interval(); printk_deferred(KERN_ERR "hardpps: PPSERROR: interval too long - %lld s\= n", @@ -958,7 +953,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr pps_freq =3D ftemp; if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { printk_deferred(KERN_WARNING "hardpps: PPSWANDER: change=3D%ld\n", delta= ); - time_status |=3D STA_PPSWANDER; + ntpdata->time_status |=3D STA_PPSWANDER; pps_stbcnt++; pps_dec_freq_interval(); } else { @@ -977,7 +972,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; =20 /* If enabled, the system clock frequency is updated */ - if ((time_status & STA_PPSFREQ) && !(time_status & STA_FREQHOLD)) { + if ((ntpdata->time_status & STA_PPSFREQ) && !(ntpdata->time_status & STA_= FREQHOLD)) { time_freq =3D pps_freq; ntp_update_frequency(ntpdata); } @@ -986,7 +981,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr } =20 /* Correct REALTIME clock phase error against PPS signal */ -static void hardpps_update_phase(long error) +static void hardpps_update_phase(struct ntp_data *ntpdata, long error) { long correction =3D -error; long jitter; @@ -1003,9 +998,9 @@ static void hardpps_update_phase(long error) if (jitter > (pps_jitter << PPS_POPCORN)) { printk_deferred(KERN_WARNING "hardpps: PPSJITTER: jitter=3D%ld, limit=3D= %ld\n", jitter, (pps_jitter << PPS_POPCORN)); - time_status |=3D STA_PPSJITTER; + ntpdata->time_status |=3D STA_PPSJITTER; pps_jitcnt++; - } else if (time_status & STA_PPSTIME) { + } else if (ntpdata->time_status & STA_PPSTIME) { /* Correct the time using the phase offset */ time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, NTP_INTERV= AL_FREQ); /* Cancel running adjtime() */ @@ -1035,10 +1030,10 @@ void __hardpps(const struct timespec64 *phase_ts, c= onst struct timespec64 *raw_t pts_norm =3D pps_normalize_ts(*phase_ts); =20 /* Clear the error bits, they will be set again if needed */ - time_status &=3D ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); + ntpdata->time_status &=3D ~(STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); =20 - /* Indicate signal presence */ - time_status |=3D STA_PPSSIGNAL; + /* indicate signal presence */ + ntpdata->time_status |=3D STA_PPSSIGNAL; pps_valid =3D PPS_VALID; =20 /* @@ -1059,7 +1054,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t */ if ((freq_norm.sec =3D=3D 0) || (freq_norm.nsec > MAXFREQ * freq_norm.sec= ) || (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { - time_status |=3D STA_PPSJITTER; + ntpdata->time_status |=3D STA_PPSJITTER; /* Restart the frequency calibration interval */ pps_fbase =3D *raw_ts; printk_deferred(KERN_ERR "hardpps: PPSJITTER: bad pulse\n"); @@ -1074,7 +1069,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t hardpps_update_freq(ntpdata, freq_norm); } =20 - hardpps_update_phase(pts_norm.nsec); + hardpps_update_phase(ntpdata, pts_norm.nsec); =20 } #endif /* CONFIG_NTP_PPS */ --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66B8719F113; Wed, 11 Sep 2024 13:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; cv=none; b=GXqbaOnQ7C8qykB37rjuF0j9O4bq1x/MJcZvn+Drw6CPLp/kQH4Lvf5U/438A1gZhaLKozsPg8Nkhn0ktiW5nLSHB/QqEdK29zrX+AhxAG4OdwuWuY89s7gwnMd/RcNQE7CbBAntZQlyA0ZEaS0smzoqGIrhrGSA/qybKhgjrUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; c=relaxed/simple; bh=/7/cQAm6c+VPpGB6sKQdsbs/hZBQbnWXfQzfOGAwiIM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t1h2AIg14v9gySHmOIjx9yJfEkdCdb6hKDvgicNfhatXB53W9za+SmLJzIO34+jGT319efTIPd9tPlRvZLpCa8awbatVjolbmLWmYpc7TZP/FrjtecsiztNmkRLPt40ju/dBlGQMNSUSCGtzaC3yN37uikDE3xA22pLJvP2ozoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hVuuMAxA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EowkjqiW; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hVuuMAxA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EowkjqiW" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7lZv5r6K6oZyhr+iRfkcuHOJPu2YKVlua/RSxGakRPM=; b=hVuuMAxApqiO5ajaHwDX2xjKahenSeZJyrdg8ZKRcngzhIPH3zeyDNY5bLSwIVk9w3BE0w YNesnVIoWHcMg6y644BDETXAhttqwoK2s2VjUtQye8ikQcjjX9DhbbKu20K9kcAVXcHeb4 ecb9fFYusDlgMs4gtMbRNuH6WrXd6yK2ekE6GqkcjZrnGX6JrDPdrpDQWDSVeJbIvJ9r8x sBtDCgh5K23nPiX5+dAdWrw9/ug3BA1qOIGtIdLx2fkUHpPA6kNUHxFlwmltSjUJag53BB yIFzldYoiCDJTEgW100ffBRHuSL1Y6f0sorD/Afo7NogL/gw+jzHxMU1CfuyZQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7lZv5r6K6oZyhr+iRfkcuHOJPu2YKVlua/RSxGakRPM=; b=EowkjqiWV6bdXsll6744888CaF8nu08CBmOlezXZzMCgjceyDWGuDahiEwZRi8G33mdXyZ PrXaxaWUrBJETrCw== Date: Wed, 11 Sep 2024 15:17:46 +0200 Subject: [PATCH 10/21] ntp: Move time_offset/constant into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-10-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 6d87f9889b03..ffe65b0d0a5e 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -29,6 +29,8 @@ * @tick_length_base: Base value for @tick_length * @time_state: State of the clock synchronization * @time_status: Clock status bits + * @time_offset: Time adjustment in nanoseconds + * @time_constant: PLL time constant * * Protected by the timekeeping locks. */ @@ -38,12 +40,15 @@ struct ntp_data { u64 tick_length_base; int time_state; int time_status; + s64 time_offset; + long time_constant; }; =20 static struct ntp_data tk_ntp_data =3D { .tick_usec =3D USER_TICK_USEC, .time_state =3D TIME_OK, .time_status =3D STA_UNSYNC, + .time_constant =3D 2, }; =20 #define SECS_PER_DAY 86400 @@ -59,12 +64,6 @@ static struct ntp_data tk_ntp_data =3D { * estimated error =3D NTP dispersion. */ =20 -/* time adjustment (nsecs): */ -static s64 time_offset; - -/* pll time constant: */ -static long time_constant =3D 2; - /* maximum error (usecs): */ static long time_maxerror =3D NTP_PHASE_LIMIT; =20 @@ -128,7 +127,7 @@ static inline s64 ntp_offset_chunk(struct ntp_data *ntp= data, s64 offset) if (ntpdata->time_status & STA_PPSTIME && ntpdata->time_status & STA_PPSS= IGNAL) return offset; else - return shift_right(offset, SHIFT_PLL + time_constant); + return shift_right(offset, SHIFT_PLL + ntpdata->time_constant); } =20 static inline void pps_reset_freq_interval(void) @@ -211,9 +210,9 @@ static inline void pps_fill_timex(struct ntp_data *ntpd= ata, struct __kernel_time =20 #else /* !CONFIG_NTP_PPS */ =20 -static inline s64 ntp_offset_chunk(struct ntp_data *ntp, s64 offset) +static inline s64 ntp_offset_chunk(struct ntp_data *ntpdata, s64 offset) { - return shift_right(offset, SHIFT_PLL + time_constant); + return shift_right(offset, SHIFT_PLL + ntpdata->time_constant); } =20 static inline void pps_reset_freq_interval(void) {} @@ -315,17 +314,17 @@ static void ntp_update_offset(struct ntp_data *ntpdat= a, long offset) * sampling rate (e.g. intermittent network connection) * to avoid instability. */ - if (unlikely(secs > 1 << (SHIFT_PLL + 1 + time_constant))) - secs =3D 1 << (SHIFT_PLL + 1 + time_constant); + if (unlikely(secs > 1 << (SHIFT_PLL + 1 + ntpdata->time_constant))) + secs =3D 1 << (SHIFT_PLL + 1 + ntpdata->time_constant); =20 freq_adj +=3D (offset64 * secs) << - (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant)); + (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + ntpdata->time_constant)); =20 freq_adj =3D min(freq_adj + time_freq, MAXFREQ_SCALED); =20 time_freq =3D max(freq_adj, -MAXFREQ_SCALED); =20 - time_offset =3D div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); + ntpdata->time_offset =3D div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVA= L_FREQ); } =20 static void __ntp_clear(struct ntp_data *ntpdata) @@ -339,7 +338,7 @@ static void __ntp_clear(struct ntp_data *ntpdata) ntp_update_frequency(ntpdata); =20 ntpdata->tick_length =3D ntpdata->tick_length_base; - time_offset =3D 0; + ntpdata->time_offset =3D 0; =20 ntp_next_leap_sec =3D TIME64_MAX; /* Clear PPS state variables */ @@ -452,8 +451,8 @@ int second_overflow(time64_t secs) /* Compute the phase adjustment for the next second */ ntpdata->tick_length =3D ntpdata->tick_length_base; =20 - delta =3D ntp_offset_chunk(ntpdata, time_offset); - time_offset -=3D delta; + delta =3D ntp_offset_chunk(ntpdata, ntpdata->time_offset); + ntpdata->time_offset -=3D delta; ntpdata->tick_length +=3D delta; =20 /* Check PPS signal */ @@ -729,10 +728,10 @@ static inline void process_adjtimex_modes(struct ntp_= data *ntpdata, const struct time_esterror =3D clamp(txc->esterror, 0, NTP_PHASE_LIMIT); =20 if (txc->modes & ADJ_TIMECONST) { - time_constant =3D clamp(txc->constant, 0, MAXTC); + ntpdata->time_constant =3D clamp(txc->constant, 0, MAXTC); if (!(ntpdata->time_status & STA_NANO)) - time_constant +=3D 4; - time_constant =3D clamp(time_constant, 0, MAXTC); + ntpdata->time_constant +=3D 4; + ntpdata->time_constant =3D clamp(ntpdata->time_constant, 0, MAXTC); } =20 if (txc->modes & ADJ_TAI && txc->constant >=3D 0 && txc->constant <=3D MA= X_TAI_OFFSET) @@ -773,7 +772,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, } else { /* If there are input parameters, then process them: */ if (txc->modes) { - audit_ntp_set_old(ad, AUDIT_NTP_OFFSET, time_offset); + audit_ntp_set_old(ad, AUDIT_NTP_OFFSET, ntpdata->time_offset); audit_ntp_set_old(ad, AUDIT_NTP_FREQ, time_freq); audit_ntp_set_old(ad, AUDIT_NTP_STATUS, ntpdata->time_status); audit_ntp_set_old(ad, AUDIT_NTP_TAI, *time_tai); @@ -781,15 +780,14 @@ int __do_adjtimex(struct __kernel_timex *txc, const s= truct timespec64 *ts, =20 process_adjtimex_modes(ntpdata, txc, time_tai); =20 - audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, time_offset); + audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, ntpdata->time_offset); audit_ntp_set_new(ad, AUDIT_NTP_FREQ, time_freq); audit_ntp_set_new(ad, AUDIT_NTP_STATUS, ntpdata->time_status); audit_ntp_set_new(ad, AUDIT_NTP_TAI, *time_tai); audit_ntp_set_new(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); } =20 - txc->offset =3D shift_right(time_offset * NTP_INTERVAL_FREQ, - NTP_SCALE_SHIFT); + txc->offset =3D shift_right(ntpdata->time_offset * NTP_INTERVAL_FREQ, NT= P_SCALE_SHIFT); if (!(ntpdata->time_status & STA_NANO)) txc->offset =3D (u32)txc->offset / NSEC_PER_USEC; } @@ -803,7 +801,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, txc->maxerror =3D time_maxerror; txc->esterror =3D time_esterror; txc->status =3D ntpdata->time_status; - txc->constant =3D time_constant; + txc->constant =3D ntpdata->time_constant; txc->precision =3D 1; txc->tolerance =3D MAXFREQ_SCALED / PPM_SCALE; txc->tick =3D ntpdata->tick_usec; @@ -1002,7 +1000,8 @@ static void hardpps_update_phase(struct ntp_data *ntp= data, long error) pps_jitcnt++; } else if (ntpdata->time_status & STA_PPSTIME) { /* Correct the time using the phase offset */ - time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, NTP_INTERV= AL_FREQ); + ntpdata->time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, + NTP_INTERVAL_FREQ); /* Cancel running adjtime() */ time_adjust =3D 0; } --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72C3919F116; Wed, 11 Sep 2024 13:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; cv=none; b=PqThcSbiXbzkPRbJnKVgPCXZOlggufDDiIWZcycpb5vCNHvRGAxbI2qKbIi2aaCutYFBc50r+fRLL64+WKKYj+ZdT9fYAkpyCE8CoV9CEAs6rtYz8Vazvov6QwGMfdkafgoPgEdn692ZD8JKVAajkA7+kwXSr+fzGN1286C0Nqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; c=relaxed/simple; bh=fxuqjESSmaBDIDApA5ps5eZRN5Xh5lwLTP7Vupi8Ek0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=btktTa1vFELXY9482Rv1Q2i2pT3IZiUx+aeJXzbftiZ4yXeJ20J/QEoVegphymzyKknnX7Fifj4n3SS0yF/VlhjTGdQ+hHD11y9ypGsgZRpUKY2J5qzUAOjOiQoZo3zhRahQmQHZ34g8JSFSwQE3U3f+JD1dyL46lcAaSzYnn8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ESQ6KKtJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+dt+no9/; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ESQ6KKtJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+dt+no9/" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GdjTQH4O8tthP8ZOo2pIJZpAoNz8pjgmrz7cqZqSXfw=; b=ESQ6KKtJ1Y5Z83pTLpTO6l5VQuT7EIJUP8XY3mjcTOv4dDP8TccQv+UK135EEzhx6ukzGB JMRPvTXytglK0kiRJlijTpk+UFoDRTryOxkKrzp8Ys0E2NpKqo37JMiT06zOfuUUEAagfP WbZ6mnGwyj3tAjBvoOADr3MNnql/pG5SBUY3WAEGMzCL88Wy4MMGzEFjMfxkR+g65UUvgV UpSqJAmoTQWbUqe+567g9xuREzn2oXy04iHKcJQdPSJlPmGgkJ/Zzzi0wRdrAuy8UTOIwH l3XydmxgFP9sAVUrzDE2m2PxA6wgomTRQLggeMVZoPUJFuntBr7x5tu6DDCVMA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GdjTQH4O8tthP8ZOo2pIJZpAoNz8pjgmrz7cqZqSXfw=; b=+dt+no9/4E3hxgHpPirevZ08xMEJT1t03tsr1gRr/UytzAUZxcynojSuxi1oFJJhh0sKZW mkhX7bw46DEWk2Cw== Date: Wed, 11 Sep 2024 15:17:47 +0200 Subject: [PATCH 11/21] ntp: Move time_max/esterror into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-11-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index ffe65b0d0a5e..15708ac4d0fb 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -31,6 +31,9 @@ * @time_status: Clock status bits * @time_offset: Time adjustment in nanoseconds * @time_constant: PLL time constant + * @time_maxerror: Maximum error in microseconds holding the NTP sync dist= ance + * (NTP dispersion + delay / 2) + * @time_esterror: Estimated error in microseconds holding NTP dispersion * * Protected by the timekeeping locks. */ @@ -42,6 +45,8 @@ struct ntp_data { int time_status; s64 time_offset; long time_constant; + long time_maxerror; + long time_esterror; }; =20 static struct ntp_data tk_ntp_data =3D { @@ -49,6 +54,8 @@ static struct ntp_data tk_ntp_data =3D { .time_state =3D TIME_OK, .time_status =3D STA_UNSYNC, .time_constant =3D 2, + .time_maxerror =3D NTP_PHASE_LIMIT, + .time_esterror =3D NTP_PHASE_LIMIT, }; =20 #define SECS_PER_DAY 86400 @@ -57,19 +64,6 @@ static struct ntp_data tk_ntp_data =3D { (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) #define MAX_TAI_OFFSET 100000 =20 -/* - * phase-lock loop variables - * - * Note: maximum error =3D NTP sync distance =3D dispersion + delay / 2; - * estimated error =3D NTP dispersion. - */ - -/* maximum error (usecs): */ -static long time_maxerror =3D NTP_PHASE_LIMIT; - -/* estimated error (usecs): */ -static long time_esterror =3D NTP_PHASE_LIMIT; - /* frequency offset (scaled nsecs/secs): */ static s64 time_freq; =20 @@ -332,8 +326,8 @@ static void __ntp_clear(struct ntp_data *ntpdata) /* Stop active adjtime() */ time_adjust =3D 0; ntpdata->time_status |=3D STA_UNSYNC; - time_maxerror =3D NTP_PHASE_LIMIT; - time_esterror =3D NTP_PHASE_LIMIT; + ntpdata->time_maxerror =3D NTP_PHASE_LIMIT; + ntpdata->time_esterror =3D NTP_PHASE_LIMIT; =20 ntp_update_frequency(ntpdata); =20 @@ -442,9 +436,9 @@ int second_overflow(time64_t secs) } =20 /* Bump the maxerror field */ - time_maxerror +=3D MAXFREQ / NSEC_PER_USEC; - if (time_maxerror > NTP_PHASE_LIMIT) { - time_maxerror =3D NTP_PHASE_LIMIT; + ntpdata->time_maxerror +=3D MAXFREQ / NSEC_PER_USEC; + if (ntpdata->time_maxerror > NTP_PHASE_LIMIT) { + ntpdata->time_maxerror =3D NTP_PHASE_LIMIT; ntpdata->time_status |=3D STA_UNSYNC; } =20 @@ -722,10 +716,10 @@ static inline void process_adjtimex_modes(struct ntp_= data *ntpdata, const struct } =20 if (txc->modes & ADJ_MAXERROR) - time_maxerror =3D clamp(txc->maxerror, 0, NTP_PHASE_LIMIT); + ntpdata->time_maxerror =3D clamp(txc->maxerror, 0, NTP_PHASE_LIMIT); =20 if (txc->modes & ADJ_ESTERROR) - time_esterror =3D clamp(txc->esterror, 0, NTP_PHASE_LIMIT); + ntpdata->time_esterror =3D clamp(txc->esterror, 0, NTP_PHASE_LIMIT); =20 if (txc->modes & ADJ_TIMECONST) { ntpdata->time_constant =3D clamp(txc->constant, 0, MAXTC); @@ -798,8 +792,8 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, =20 txc->freq =3D shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * PPM_SCALE_INV, NTP_SCALE_SHIFT); - txc->maxerror =3D time_maxerror; - txc->esterror =3D time_esterror; + txc->maxerror =3D ntpdata->time_maxerror; + txc->esterror =3D ntpdata->time_esterror; txc->status =3D ntpdata->time_status; txc->constant =3D ntpdata->time_constant; txc->precision =3D 1; --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74F8419F118; Wed, 11 Sep 2024 13:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; cv=none; b=N5XbKZAUKXhm0eO4faiCqjZitA6kBI5jNERWaifgIvaIV/LKCDeEDWzH6z6AkJPRh4GN79rhPEPx1x1nnP2oU5DARyEuHwVYvqfE9Y8cn4c3+wQJGJZs7BPfSDzjtkpQrNTx4YekQblAVUileB1pQx9mILlOlhYUDp4XtbGSVYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; c=relaxed/simple; bh=Rj4Iu1ivde6gV8wW8KPvKBS5NFsza5Un5CoSREx1120=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mlkRPaiMzLxkXfwgdLQnQLdG7OykFxMeFc8CoepBExD4tIEZLJFhXZ+BnSpTvsNvW/lhPuz1BPPPzKEOVLokPIMBAy8buU73I57lo9ISMMxaGYMeG3d6Nk6KcM27b8SorNXfgsQaZe9ApDjbtpsuDPjpTCIuk4fYd/4c/4M82Oo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2Xkh/odF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZByxKeqt; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2Xkh/odF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZByxKeqt" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3JbFFqKg305Ne707gN78UaOX7MWoUKFNnyExemYAgsE=; b=2Xkh/odFz/6wodewFhveVTTfuam42vNGd4E5/YG3fMvTqvauHBE5wmm0jJm7WTPrYcwHtC qMK5Mf9ivfhuBLsESdmj/1EwW/exVNm3noZz6m99y4Fv8VmnA65S2tk7nJOJeWB+CtVQDI IyCNPbI5SF67YPakcl10GzDGgI9N8H5Fe+c4JDlXP/w8O/DSsVfgIgpLbQTOHFn7BwRfzj gWl6qQStwYXZ9WQu0QrQ5B4sARJVuUWbGT//zWsJQBgefSo7f3HIp+bM/blC6aa35pIlmw H3fTNrTF6+qQARLRMoKkj6HyX32zSDWJMg0W06BGf3LBsfmE7VJOauliRK/1mg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3JbFFqKg305Ne707gN78UaOX7MWoUKFNnyExemYAgsE=; b=ZByxKeqtp0dfEgwHe+Y2euLo7oytXy7Xu17awyydeQ81XkAKxpH26BVpFZP1siUOdKTr2b CpfOP15jsJPpVCDw== Date: Wed, 11 Sep 2024 15:17:48 +0200 Subject: [PATCH 12/21] ntp: Move time_freq/reftime into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-12-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 15708ac4d0fb..47c4f3e3562c 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -34,6 +34,8 @@ * @time_maxerror: Maximum error in microseconds holding the NTP sync dist= ance * (NTP dispersion + delay / 2) * @time_esterror: Estimated error in microseconds holding NTP dispersion + * @time_freq: Frequency offset scaled nsecs/secs + * @time_reftime: Time at last adjustment in seconds * * Protected by the timekeeping locks. */ @@ -47,6 +49,8 @@ struct ntp_data { long time_constant; long time_maxerror; long time_esterror; + s64 time_freq; + time64_t time_reftime; }; =20 static struct ntp_data tk_ntp_data =3D { @@ -64,12 +68,6 @@ static struct ntp_data tk_ntp_data =3D { (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) #define MAX_TAI_OFFSET 100000 =20 -/* frequency offset (scaled nsecs/secs): */ -static s64 time_freq; - -/* time at last adjustment (secs): */ -static time64_t time_reftime; - static long time_adjust; =20 /* constant (boot-param configurable) NTP tick adjustment (upscaled) */ @@ -245,7 +243,7 @@ static void ntp_update_frequency(struct ntp_data *ntpda= ta) second_length =3D (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) << NTP_SCA= LE_SHIFT; =20 second_length +=3D ntp_tick_adj; - second_length +=3D time_freq; + second_length +=3D ntpdata->time_freq; =20 new_base =3D div_u64(second_length, NTP_INTERVAL_FREQ); =20 @@ -294,11 +292,11 @@ static void ntp_update_offset(struct ntp_data *ntpdat= a, long offset) * and in which mode (PLL or FLL). */ real_secs =3D __ktime_get_real_seconds(); - secs =3D (long)(real_secs - time_reftime); + secs =3D (long)(real_secs - ntpdata->time_reftime); if (unlikely(ntpdata->time_status & STA_FREQHOLD)) secs =3D 0; =20 - time_reftime =3D real_secs; + ntpdata->time_reftime =3D real_secs; =20 offset64 =3D offset; freq_adj =3D ntp_update_offset_fll(ntpdata, offset64, secs); @@ -314,9 +312,9 @@ static void ntp_update_offset(struct ntp_data *ntpdata,= long offset) freq_adj +=3D (offset64 * secs) << (NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + ntpdata->time_constant)); =20 - freq_adj =3D min(freq_adj + time_freq, MAXFREQ_SCALED); + freq_adj =3D min(freq_adj + ntpdata->time_freq, MAXFREQ_SCALED); =20 - time_freq =3D max(freq_adj, -MAXFREQ_SCALED); + ntpdata->time_freq =3D max(freq_adj, -MAXFREQ_SCALED); =20 ntpdata->time_offset =3D div_s64(offset64 << NTP_SCALE_SHIFT, NTP_INTERVA= L_FREQ); } @@ -688,7 +686,7 @@ static inline void process_adj_status(struct ntp_data *= ntpdata, const struct __k * reference time to current time. */ if (!(ntpdata->time_status & STA_PLL) && (txc->status & STA_PLL)) - time_reftime =3D __ktime_get_real_seconds(); + ntpdata->time_reftime =3D __ktime_get_real_seconds(); =20 /* only set allowed bits */ ntpdata->time_status &=3D STA_RONLY; @@ -708,11 +706,11 @@ static inline void process_adjtimex_modes(struct ntp_= data *ntpdata, const struct ntpdata->time_status &=3D ~STA_NANO; =20 if (txc->modes & ADJ_FREQUENCY) { - time_freq =3D txc->freq * PPM_SCALE; - time_freq =3D min(time_freq, MAXFREQ_SCALED); - time_freq =3D max(time_freq, -MAXFREQ_SCALED); + ntpdata->time_freq =3D txc->freq * PPM_SCALE; + ntpdata->time_freq =3D min(ntpdata->time_freq, MAXFREQ_SCALED); + ntpdata->time_freq =3D max(ntpdata->time_freq, -MAXFREQ_SCALED); /* Update pps_freq */ - pps_set_freq(time_freq); + pps_set_freq(ntpdata->time_freq); } =20 if (txc->modes & ADJ_MAXERROR) @@ -767,7 +765,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, /* If there are input parameters, then process them: */ if (txc->modes) { audit_ntp_set_old(ad, AUDIT_NTP_OFFSET, ntpdata->time_offset); - audit_ntp_set_old(ad, AUDIT_NTP_FREQ, time_freq); + audit_ntp_set_old(ad, AUDIT_NTP_FREQ, ntpdata->time_freq); audit_ntp_set_old(ad, AUDIT_NTP_STATUS, ntpdata->time_status); audit_ntp_set_old(ad, AUDIT_NTP_TAI, *time_tai); audit_ntp_set_old(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); @@ -775,7 +773,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, process_adjtimex_modes(ntpdata, txc, time_tai); =20 audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, ntpdata->time_offset); - audit_ntp_set_new(ad, AUDIT_NTP_FREQ, time_freq); + audit_ntp_set_new(ad, AUDIT_NTP_FREQ, ntpdata->time_freq); audit_ntp_set_new(ad, AUDIT_NTP_STATUS, ntpdata->time_status); audit_ntp_set_new(ad, AUDIT_NTP_TAI, *time_tai); audit_ntp_set_new(ad, AUDIT_NTP_TICK, ntpdata->tick_usec); @@ -790,7 +788,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, if (is_error_status(ntpdata->time_status)) result =3D TIME_ERROR; =20 - txc->freq =3D shift_right((time_freq >> PPM_SCALE_INV_SHIFT) * + txc->freq =3D shift_right((ntpdata->time_freq >> PPM_SCALE_INV_SHIFT) * PPM_SCALE_INV, NTP_SCALE_SHIFT); txc->maxerror =3D ntpdata->time_maxerror; txc->esterror =3D ntpdata->time_esterror; @@ -965,7 +963,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr =20 /* If enabled, the system clock frequency is updated */ if ((ntpdata->time_status & STA_PPSFREQ) && !(ntpdata->time_status & STA_= FREQHOLD)) { - time_freq =3D pps_freq; + ntpdata->time_freq =3D pps_freq; ntp_update_frequency(ntpdata); } =20 --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3F4619F129; Wed, 11 Sep 2024 13:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; cv=none; b=Dngr5MUlShnhnobwEuwFROmf9a9Y/tRPyee4UWhQBC56pD1Mp+vj0mdwksPpKoI0J/REYY3yQGe2pxgiqponHcLXoW5dT/CHJIEyXPskTGzOPhPIUSs8XYyVVh99/75zUH1IpyrQnRpV/uqzLjbfBwoZ7N+bctOzzbPYN5OVPEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060684; c=relaxed/simple; bh=jsqZHMaVbEUBlf/RHWWugEVvet0Uz87Fq3mIOLizCU4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EKkvT/1COwv7N3lnk+52Q8pWt7y+0nKB0LtDRv5pml52M/M+bKrn1bjUaEJx08CeSxbjBgCNh6naXnKhAjjDMBWGX3i4EcR9XEKATgOFdtZ1Ogidon6m2uwR4wTzp0aQGWOZyOnDul9ZnocU13R0pyZVc54sjq8ngLaYIYurBrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lsmu3AIr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3CekEdgG; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lsmu3AIr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3CekEdgG" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qESDq10j/CueXRLwup3LiuwuvM4fTxM0INR84EcUb0g=; b=lsmu3AIrnf4Htb+DkwSXu1tWpalAoy1gO+im6Xyp4pQ4coqiVMSVC5e4PFZvlvE5kIvHv4 IRLtj2gmCZ/BYb6lbV70/a9mdsQ9PbQZTZyXmVkyRNN/njd7/QwPbzohu8RxpEc5T2C2ap JNZAWZh3rpJXvzm1M93cvuEW7t2O3b4Yb5Cem3r7oIUw46sCcy0XLVXciB93xLBgUPiLh7 y5CBc+rApmYAp74Hh2+0Af8E4iGO9jTvNZ3yPkviGBPr/LgByBRniWcFosz+n1vMUkLF4P zSTPtDgdjH8/zge9C3S/ahokj090t9PpouhN+jYJZWzz8EEN4whKa/4kqC5XBg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060677; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qESDq10j/CueXRLwup3LiuwuvM4fTxM0INR84EcUb0g=; b=3CekEdgGcG2y2IC/wtrUsYo6sYVt9qwDf/t5ayct+YjYADewNQoVWhIYBiPDWR+fRGEYfw RxAza4UDC7V/8oBA== Date: Wed, 11 Sep 2024 15:17:49 +0200 Subject: [PATCH 13/21] ntp: Move time_adj/ntp_tick_adj into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-13-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen Acked-by: John Stultz --- kernel/time/ntp.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 47c4f3e3562c..3897f1e79d8d 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -36,6 +36,8 @@ * @time_esterror: Estimated error in microseconds holding NTP dispersion * @time_freq: Frequency offset scaled nsecs/secs * @time_reftime: Time at last adjustment in seconds + * @time_adjust: Adjustment value + * @ntp_tick_adj: Constant boot-param configurable NTP tick adjustment (up= scaled) * * Protected by the timekeeping locks. */ @@ -51,6 +53,8 @@ struct ntp_data { long time_esterror; s64 time_freq; time64_t time_reftime; + long time_adjust; + s64 ntp_tick_adj; }; =20 static struct ntp_data tk_ntp_data =3D { @@ -68,11 +72,6 @@ static struct ntp_data tk_ntp_data =3D { (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) #define MAX_TAI_OFFSET 100000 =20 -static long time_adjust; - -/* constant (boot-param configurable) NTP tick adjustment (upscaled) */ -static s64 ntp_tick_adj; - /* second value of the next pending leapsecond, or TIME64_MAX if no leap */ static time64_t ntp_next_leap_sec =3D TIME64_MAX; =20 @@ -242,7 +241,7 @@ static void ntp_update_frequency(struct ntp_data *ntpda= ta) =20 second_length =3D (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) << NTP_SCA= LE_SHIFT; =20 - second_length +=3D ntp_tick_adj; + second_length +=3D ntpdata->ntp_tick_adj; second_length +=3D ntpdata->time_freq; =20 new_base =3D div_u64(second_length, NTP_INTERVAL_FREQ); @@ -322,7 +321,7 @@ static void ntp_update_offset(struct ntp_data *ntpdata,= long offset) static void __ntp_clear(struct ntp_data *ntpdata) { /* Stop active adjtime() */ - time_adjust =3D 0; + ntpdata->time_adjust =3D 0; ntpdata->time_status |=3D STA_UNSYNC; ntpdata->time_maxerror =3D NTP_PHASE_LIMIT; ntpdata->time_esterror =3D NTP_PHASE_LIMIT; @@ -450,24 +449,24 @@ int second_overflow(time64_t secs) /* Check PPS signal */ pps_dec_valid(ntpdata); =20 - if (!time_adjust) + if (!ntpdata->time_adjust) goto out; =20 - if (time_adjust > MAX_TICKADJ) { - time_adjust -=3D MAX_TICKADJ; + if (ntpdata->time_adjust > MAX_TICKADJ) { + ntpdata->time_adjust -=3D MAX_TICKADJ; ntpdata->tick_length +=3D MAX_TICKADJ_SCALED; goto out; } =20 - if (time_adjust < -MAX_TICKADJ) { - time_adjust +=3D MAX_TICKADJ; + if (ntpdata->time_adjust < -MAX_TICKADJ) { + ntpdata->time_adjust +=3D MAX_TICKADJ; ntpdata->tick_length -=3D MAX_TICKADJ_SCALED; goto out; } =20 - ntpdata->tick_length +=3D (s64)(time_adjust * NSEC_PER_USEC / NTP_INTERVA= L_FREQ) + ntpdata->tick_length +=3D (s64)(ntpdata->time_adjust * NSEC_PER_USEC / NT= P_INTERVAL_FREQ) << NTP_SCALE_SHIFT; - time_adjust =3D 0; + ntpdata->time_adjust =3D 0; =20 out: return leap; @@ -750,15 +749,15 @@ int __do_adjtimex(struct __kernel_timex *txc, const s= truct timespec64 *ts, int result; =20 if (txc->modes & ADJ_ADJTIME) { - long save_adjust =3D time_adjust; + long save_adjust =3D ntpdata->time_adjust; =20 if (!(txc->modes & ADJ_OFFSET_READONLY)) { /* adjtime() is independent from ntp_adjtime() */ - time_adjust =3D txc->offset; + ntpdata->time_adjust =3D txc->offset; ntp_update_frequency(ntpdata); =20 audit_ntp_set_old(ad, AUDIT_NTP_ADJUST, save_adjust); - audit_ntp_set_new(ad, AUDIT_NTP_ADJUST, time_adjust); + audit_ntp_set_new(ad, AUDIT_NTP_ADJUST, ntpdata->time_adjust); } txc->offset =3D save_adjust; } else { @@ -995,7 +994,7 @@ static void hardpps_update_phase(struct ntp_data *ntpda= ta, long error) ntpdata->time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ); /* Cancel running adjtime() */ - time_adjust =3D 0; + ntpdata->time_adjust =3D 0; } /* Update jitter */ pps_jitter +=3D (jitter - pps_jitter) >> PPS_INTMIN; @@ -1067,11 +1066,11 @@ void __hardpps(const struct timespec64 *phase_ts, c= onst struct timespec64 *raw_t =20 static int __init ntp_tick_adj_setup(char *str) { - int rc =3D kstrtos64(str, 0, &ntp_tick_adj); + int rc =3D kstrtos64(str, 0, &tk_ntp_data.ntp_tick_adj); if (rc) return rc; =20 - ntp_tick_adj <<=3D NTP_SCALE_SHIFT; + tk_ntp_data.ntp_tick_adj <<=3D NTP_SCALE_SHIFT; return 1; } =20 --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9459919F124; Wed, 11 Sep 2024 13:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060686; cv=none; b=eDrVAmDil0XnVSN5AyMuVvxFdNrMRHSXL8xgv9y/C38qjeJXL5BtGH/i12kDXK7an+b7J/SXHRBNdjpb0FgDH+GrCk8hzB4mpoyick+mC0by5sJ3vYIrCgp7c+egio9U+EMq83OIyzUFZWmxsyk1oxnYS1G02BQXh+gT3V18Xxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060686; c=relaxed/simple; bh=rrH2HOeGNlvk94ShHjgd4MvbCcMR04y0tGNHaHGvSAQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Co9ubJdBzc+NxcwNRF4l8jum6fx3zljykVCxTGrqc1N4HKr8ZLpg1jYKnoUR25qntWTH9ygTmXJYV/O46lKHli+1EJZOMwdKcCwxNbk9TQisbdiYKoTwpSHmAtTeTmi9qTZQn3R7qPr83c7HL2Mx2J+WItU5HrrAy8nZXWNICxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aq+b+vgQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fNRKCCkB; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aq+b+vgQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fNRKCCkB" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J13jbXKjKQTFx7S8usEk2kQMsr0CFAC0l+gr2iTtBHQ=; b=aq+b+vgQR9v9vCSD8NLDa6PyxhIVIT6lsJBC2YO1LdqvqTAke/lG8TpwlRAIMiwu3QC3wz cQkM9OhY+83LwgO5Bvjo+22QSL2Gxr9DxRFeAiDZSkcpPYMXM+l2O6zdbRc9oWlVUYj7UU RlY7XjuS1bKZtTp/gM35LCnJedOEA5efPeu4JxacFpRIpPduPk8VY/BiM/5/puOv2tGHAm wiLocnCZDgtObMIM6SemT5cGWZhuSEPynxNjW+nLpKhOC9D14Yqn0BwgcKwZIXgJIaeHf0 8dVLXDlGA/Yl/viVurRhrOIxlBfHNDbQ686kTwi7XIW70BOc46otg/qVLmyixA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J13jbXKjKQTFx7S8usEk2kQMsr0CFAC0l+gr2iTtBHQ=; b=fNRKCCkBkCRMFhlaukbGh1xUQg4vxmKZqhPjwgZvz7jbvTvDG3a3h3P32AJs2pJ+Qyc0S5 IBlhHzrD/VxjuxDA== Date: Wed, 11 Sep 2024 15:17:50 +0200 Subject: [PATCH 14/21] ntp: Move ntp_next_leap_sec into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-14-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 3897f1e79d8d..33d52b9dbff6 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -38,6 +38,7 @@ * @time_reftime: Time at last adjustment in seconds * @time_adjust: Adjustment value * @ntp_tick_adj: Constant boot-param configurable NTP tick adjustment (up= scaled) + * @ntp_next_leap_sec: Second value of the next pending leapsecond, or TIM= E64_MAX if no leap * * Protected by the timekeeping locks. */ @@ -55,6 +56,7 @@ struct ntp_data { time64_t time_reftime; long time_adjust; s64 ntp_tick_adj; + time64_t ntp_next_leap_sec; }; =20 static struct ntp_data tk_ntp_data =3D { @@ -64,6 +66,7 @@ static struct ntp_data tk_ntp_data =3D { .time_constant =3D 2, .time_maxerror =3D NTP_PHASE_LIMIT, .time_esterror =3D NTP_PHASE_LIMIT, + .ntp_next_leap_sec =3D TIME64_MAX, }; =20 #define SECS_PER_DAY 86400 @@ -72,9 +75,6 @@ static struct ntp_data tk_ntp_data =3D { (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ) #define MAX_TAI_OFFSET 100000 =20 -/* second value of the next pending leapsecond, or TIME64_MAX if no leap */ -static time64_t ntp_next_leap_sec =3D TIME64_MAX; - #ifdef CONFIG_NTP_PPS =20 /* @@ -331,7 +331,7 @@ static void __ntp_clear(struct ntp_data *ntpdata) ntpdata->tick_length =3D ntpdata->tick_length_base; ntpdata->time_offset =3D 0; =20 - ntp_next_leap_sec =3D TIME64_MAX; + ntpdata->ntp_next_leap_sec =3D TIME64_MAX; /* Clear PPS state variables */ pps_clear(); } @@ -362,7 +362,7 @@ ktime_t ntp_get_next_leap(void) ktime_t ret; =20 if ((ntpdata->time_state =3D=3D TIME_INS) && (ntpdata->time_status & STA_= INS)) - return ktime_set(ntp_next_leap_sec, 0); + return ktime_set(ntpdata->ntp_next_leap_sec, 0); ret =3D KTIME_MAX; return ret; } @@ -394,18 +394,18 @@ int second_overflow(time64_t secs) if (ntpdata->time_status & STA_INS) { ntpdata->time_state =3D TIME_INS; div_s64_rem(secs, SECS_PER_DAY, &rem); - ntp_next_leap_sec =3D secs + SECS_PER_DAY - rem; + ntpdata->ntp_next_leap_sec =3D secs + SECS_PER_DAY - rem; } else if (ntpdata->time_status & STA_DEL) { ntpdata->time_state =3D TIME_DEL; div_s64_rem(secs + 1, SECS_PER_DAY, &rem); - ntp_next_leap_sec =3D secs + SECS_PER_DAY - rem; + ntpdata->ntp_next_leap_sec =3D secs + SECS_PER_DAY - rem; } break; case TIME_INS: if (!(ntpdata->time_status & STA_INS)) { - ntp_next_leap_sec =3D TIME64_MAX; + ntpdata->ntp_next_leap_sec =3D TIME64_MAX; ntpdata->time_state =3D TIME_OK; - } else if (secs =3D=3D ntp_next_leap_sec) { + } else if (secs =3D=3D ntpdata->ntp_next_leap_sec) { leap =3D -1; ntpdata->time_state =3D TIME_OOP; pr_notice("Clock: inserting leap second 23:59:60 UTC\n"); @@ -413,17 +413,17 @@ int second_overflow(time64_t secs) break; case TIME_DEL: if (!(ntpdata->time_status & STA_DEL)) { - ntp_next_leap_sec =3D TIME64_MAX; + ntpdata->ntp_next_leap_sec =3D TIME64_MAX; ntpdata->time_state =3D TIME_OK; - } else if (secs =3D=3D ntp_next_leap_sec) { + } else if (secs =3D=3D ntpdata->ntp_next_leap_sec) { leap =3D 1; - ntp_next_leap_sec =3D TIME64_MAX; + ntpdata->ntp_next_leap_sec =3D TIME64_MAX; ntpdata->time_state =3D TIME_WAIT; pr_notice("Clock: deleting leap second 23:59:59 UTC\n"); } break; case TIME_OOP: - ntp_next_leap_sec =3D TIME64_MAX; + ntpdata->ntp_next_leap_sec =3D TIME64_MAX; ntpdata->time_state =3D TIME_WAIT; break; case TIME_WAIT: @@ -675,7 +675,7 @@ static inline void process_adj_status(struct ntp_data *= ntpdata, const struct __k if ((ntpdata->time_status & STA_PLL) && !(txc->status & STA_PLL)) { ntpdata->time_state =3D TIME_OK; ntpdata->time_status =3D STA_UNSYNC; - ntp_next_leap_sec =3D TIME64_MAX; + ntpdata->ntp_next_leap_sec =3D TIME64_MAX; /* Restart PPS frequency calibration */ pps_reset_freq_interval(); } @@ -807,7 +807,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, txc->time.tv_usec =3D ts->tv_nsec / NSEC_PER_USEC; =20 /* Handle leapsec adjustments */ - if (unlikely(ts->tv_sec >=3D ntp_next_leap_sec)) { + if (unlikely(ts->tv_sec >=3D ntpdata->ntp_next_leap_sec)) { if ((ntpdata->time_state =3D=3D TIME_INS) && (ntpdata->time_status & STA= _INS)) { result =3D TIME_OOP; txc->tai++; @@ -818,7 +818,7 @@ int __do_adjtimex(struct __kernel_timex *txc, const str= uct timespec64 *ts, txc->tai--; txc->time.tv_sec++; } - if ((ntpdata->time_state =3D=3D TIME_OOP) && (ts->tv_sec =3D=3D ntp_next= _leap_sec)) + if ((ntpdata->time_state =3D=3D TIME_OOP) && (ts->tv_sec =3D=3D ntpdata-= >ntp_next_leap_sec)) result =3D TIME_WAIT; } =20 --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDAE41A2C21; Wed, 11 Sep 2024 13:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060686; cv=none; b=SnSH2J8bidBVJGBkJ/vx8OgM0O+ACIE2ckH5Nrw9pZ2DU3FqT5HynRnlXmiq3KNhe6zE+t4NtTBW+yEMih3+uHfrgzKOyEJqGLA1a/eL82i9QVMcIE6qbZnWybXNRAHWMhSQ7Ge7LSCVWR3l49rSR6moLR1nDkoxQG3ECIZRoiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060686; c=relaxed/simple; bh=Gc9aUrMgiGw/PU4IgdgohutjQq8cr8HMfVVNTNoSqso=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HRWJ74xzYlAzFdP8u8gTNqawjmgt92yzz1xwfHw/qlDZq1LB1b0OWWZRtFugtdi4oG2evmYK9rcZ7f5N6SRRcMFob57om5QVLmYErQe23SamDEnF5Cjiof6CLG4YxgTefZY3sokQ917roxDXRay3vstChBrEJ1IHs7Ywm+Z1fJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pQARM0HI; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BLacdNDC; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pQARM0HI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BLacdNDC" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mcIY7gmIL3iEzEpBJg1/mDIpAsK46bssX6oGGBFRDUs=; b=pQARM0HIOtkDgmsJgLPAz+u1vCuFLZ5kkbdZeXDTJqu9njbKOFEBPfzzUybgYtjw5ly8Yn IHx7i4/sw9a1t1SkFgbhLu7FRurHiHZ4CBHe+EwfZEs/hL9k5RteLRlVypmnnWyfPkdByD v7BUQP0utGdMCzQuTXPoN/up7iOnTY2CQbGMim3V/KRTAxnUx2qoPDU7hAnTNA6y7twBXu EAxzFycin5k1PAiKjF6Tm+dacygzEi6eQSdb46k4hUyJ2ixgn0Z+LImGGZtI/wEzCjTITq MtLaVlwEmkKwPFX18+ZcaJEtx+hs3EB5bHOEbF9V1sWqW315CQgxPf/OOdKr+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mcIY7gmIL3iEzEpBJg1/mDIpAsK46bssX6oGGBFRDUs=; b=BLacdNDCGa6o2bxxq7cOI9qRLM3cgqtb9iPtofx7Xse5SL6q5ldjj1QKSXSJMxdCSofDxz arHymV5G319x1iCA== Date: Wed, 11 Sep 2024 15:17:51 +0200 Subject: [PATCH 15/21] ntp: Move pps_valid into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-15-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 33d52b9dbff6..35cca57e017e 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -40,6 +40,8 @@ * @ntp_tick_adj: Constant boot-param configurable NTP tick adjustment (up= scaled) * @ntp_next_leap_sec: Second value of the next pending leapsecond, or TIM= E64_MAX if no leap * + * @pps_valid: PPS signal watchdog counter + * * Protected by the timekeeping locks. */ struct ntp_data { @@ -57,6 +59,9 @@ struct ntp_data { long time_adjust; s64 ntp_tick_adj; time64_t ntp_next_leap_sec; +#ifdef CONFIG_NTP_PPS + int pps_valid; +#endif }; =20 static struct ntp_data tk_ntp_data =3D { @@ -91,7 +96,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -static int pps_valid; /* signal watchdog counter */ static long pps_tf[3]; /* phase median filter */ static long pps_jitter; /* current jitter (ns) */ static struct timespec64 pps_fbase; /* beginning of the last freq interval= */ @@ -147,9 +151,9 @@ static inline void pps_clear(void) */ static inline void pps_dec_valid(struct ntp_data *ntpdata) { - if (pps_valid > 0) - pps_valid--; - else { + if (ntpdata->pps_valid > 0) { + ntpdata->pps_valid--; + } else { ntpdata->time_status &=3D ~(STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); pps_clear(); @@ -1024,7 +1028,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t =20 /* indicate signal presence */ ntpdata->time_status |=3D STA_PPSSIGNAL; - pps_valid =3D PPS_VALID; + ntpdata->pps_valid =3D PPS_VALID; =20 /* * When called for the first time, just start the frequency --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDE3C1A2C22; Wed, 11 Sep 2024 13:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; cv=none; b=QwdBbSk2yYp6GZaiXb6miQOkQaqc1rGdfvt/H/PzASb3vO82oveeYz2st9hCD8DRjxJMedJT/z9z9oOylvbO9wnEi9jZx6MvKfdsGu8EjKOGknkcqiGZZ+VOwf8rpnUSwgBP9TbKwntCytNyKOGDLCFPg5GQWgGn0nIE0HnHjOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; c=relaxed/simple; bh=C8saRYIZL/cdOQgteWmZjtYfUl7VFXa2cWqwRJ2E79c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OLmiFqJMJ4skUKNC5RNg5KcKqiMNTBEu4Epv9VUdpuv6Ns5UE7dw4v6B+UJMtvWfw16QxjMSRwA3Rkd9iVENzyIlZo88IS1KL6vRasLFLitsH8aje+OYYV0btcU8dsWiwBAWo98EqvQxtAz29xkFegqB4e1iB2YLEMZPPtvBmrI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tGcsSz0/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=H/ALmm0o; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tGcsSz0/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="H/ALmm0o" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U/ZdMb3Rii3xovOcXYYtYucy702sAeLJbbsZ53Bdr6I=; b=tGcsSz0/jIuXLiwQCt4a9vt4xDdZ60icLjW4hkfglM2hb+0dCyrbfyX1LET7G9qbj6DN9v lRyRlGnimD9qxR+m2GhLziE5XJR3wsM52A0iZuWoxBS+1YBRIvOT55SFOznQmE5UzYW/67 QzmSBuQNMRacmOwddGg0v4BPuyIxp2u0ZlFSS8cib1Nyb8JDCvhUg3+tan1MN9Xe3kfrYl KmLvavgE6krfye9meZuHZ70MG9r6e8B/p8VmGr05VWiz2IC/2Z2oKhr/8N3LnQEMeTYLTh mCBzKoHLwgJEAIz4waoIcsch2NUju8ioFVBaqWmQCKNDP+tDW/gW6ZODT6gWmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U/ZdMb3Rii3xovOcXYYtYucy702sAeLJbbsZ53Bdr6I=; b=H/ALmm0onkwNYxRZLrxkvKg74RRiB4gYtsj1cTxppCoYjz7gl9gIscaNrZSZHvqf+P5Fie 6uYaDh0QZyZr+XCQ== Date: Wed, 11 Sep 2024 15:17:52 +0200 Subject: [PATCH 16/21] ntp: Move pps_ft into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-16-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 35cca57e017e..22fece642c61 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -41,6 +41,7 @@ * @ntp_next_leap_sec: Second value of the next pending leapsecond, or TIM= E64_MAX if no leap * * @pps_valid: PPS signal watchdog counter + * @pps_tf: PPS phase median filter * * Protected by the timekeeping locks. */ @@ -61,6 +62,7 @@ struct ntp_data { time64_t ntp_next_leap_sec; #ifdef CONFIG_NTP_PPS int pps_valid; + long pps_tf[3]; #endif }; =20 @@ -96,7 +98,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -static long pps_tf[3]; /* phase median filter */ static long pps_jitter; /* current jitter (ns) */ static struct timespec64 pps_fbase; /* beginning of the last freq interval= */ static int pps_shift; /* current interval duration (s) (shift) */ @@ -134,13 +135,14 @@ static inline void pps_reset_freq_interval(void) =20 /** * pps_clear - Clears the PPS state variables + * @ntpdata: Pointer to ntp data */ -static inline void pps_clear(void) +static inline void pps_clear(struct ntp_data *ntpdata) { pps_reset_freq_interval(); - pps_tf[0] =3D 0; - pps_tf[1] =3D 0; - pps_tf[2] =3D 0; + ntpdata->pps_tf[0] =3D 0; + ntpdata->pps_tf[1] =3D 0; + ntpdata->pps_tf[2] =3D 0; pps_fbase.tv_sec =3D pps_fbase.tv_nsec =3D 0; pps_freq =3D 0; } @@ -156,7 +158,7 @@ static inline void pps_dec_valid(struct ntp_data *ntpda= ta) } else { ntpdata->time_status &=3D ~(STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR); - pps_clear(); + pps_clear(ntpdata); } } =20 @@ -211,7 +213,7 @@ static inline s64 ntp_offset_chunk(struct ntp_data *ntp= data, s64 offset) } =20 static inline void pps_reset_freq_interval(void) {} -static inline void pps_clear(void) {} +static inline void pps_clear(struct ntp_data *ntpdata) {} static inline void pps_dec_valid(struct ntp_data *ntpdata) {} static inline void pps_set_freq(s64 freq) {} =20 @@ -337,7 +339,7 @@ static void __ntp_clear(struct ntp_data *ntpdata) =20 ntpdata->ntp_next_leap_sec =3D TIME64_MAX; /* Clear PPS state variables */ - pps_clear(); + pps_clear(ntpdata); } =20 /** @@ -862,22 +864,22 @@ static inline struct pps_normtime pps_normalize_ts(st= ruct timespec64 ts) } =20 /* Get current phase correction and jitter */ -static inline long pps_phase_filter_get(long *jitter) +static inline long pps_phase_filter_get(struct ntp_data *ntpdata, long *ji= tter) { - *jitter =3D pps_tf[0] - pps_tf[1]; + *jitter =3D ntpdata->pps_tf[0] - ntpdata->pps_tf[1]; if (*jitter < 0) *jitter =3D -*jitter; =20 /* TODO: test various filters */ - return pps_tf[0]; + return ntpdata->pps_tf[0]; } =20 /* Add the sample to the phase filter */ -static inline void pps_phase_filter_add(long err) +static inline void pps_phase_filter_add(struct ntp_data *ntpdata, long err) { - pps_tf[2] =3D pps_tf[1]; - pps_tf[1] =3D pps_tf[0]; - pps_tf[0] =3D err; + ntpdata->pps_tf[2] =3D ntpdata->pps_tf[1]; + ntpdata->pps_tf[1] =3D ntpdata->pps_tf[0]; + ntpdata->pps_tf[0] =3D err; } =20 /* @@ -980,8 +982,8 @@ static void hardpps_update_phase(struct ntp_data *ntpda= ta, long error) long jitter; =20 /* Add the sample to the median filter */ - pps_phase_filter_add(correction); - correction =3D pps_phase_filter_get(&jitter); + pps_phase_filter_add(ntpdata, correction); + correction =3D pps_phase_filter_get(ntpdata, &jitter); =20 /* * Nominal jitter is due to PPS signal noise. If it exceeds the --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 430671A3046; Wed, 11 Sep 2024 13:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; cv=none; b=VE7BeZM6jUgnWW+sDz4pcWPlNhsyYexBZTIwhqAFjG+rDAS2JuVqRq2Cf98zvJi/7KvJ9aWKpaRqH1pQDUZ4SqEt5W/9GMcnJ2R76xeZ0tKHOrXX2Yvs2shVsy29kwypvHE15s2HJKoX9CNSvmjpOGjxfUkGJmXmhfCONJvAMKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; c=relaxed/simple; bh=0wr+8h/5XCURJQUuDf8LL1W0iId7el4UT8pZeG/QkQ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OLv+Z+vaY5rbYE7eLjauEQhZ85GGXAUiElKgR4SlQcgq8xfDO48OGZo5o1M/VK43ZF9129NGvStM27yNPLyYA7reh7kWzEWmTZJLP2/qYXMkGe3F4Hx1FYJ56/82lnVHhAL2sOPO8nuOy+V9VcgckvHsOnz7SCwcow0oGDVCvIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yvtg4F0i; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CxpmAFUn; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yvtg4F0i"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CxpmAFUn" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OJuu8I0S4GSTOuMTha6kS7r2SciKCa+eSe56eLnPxgA=; b=yvtg4F0irMVprRIgYq11XoRbwVzDPj0dQL02z1jriknAHWMj5CpR0Q9HIHDcuIPrUBPl7B 5wBRhS0WYQgO7XHNvb38W9JYP0X+zXAcSeJfKappRncE+4ksxvtELgqwVSjk6DMlxMoNM3 mk1OUDGXbi09JV4qoihGu9Awz5tg3Agh5M9ZuqFpGsGdKvyH5sSu5GK9J7TOLL1TxgQT7m HR0G28gLVaaeiTN24QI6zRWyJ1uvA8zn639IJVoQ347o+dK/GQ5CJEWFp7jcx19q88JTm5 xK9nuVHxKezgEzDDMtV2a4/B2KrlFtZDRPJ03H1yGpF88BBJTdWfOHEHhyrdqA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OJuu8I0S4GSTOuMTha6kS7r2SciKCa+eSe56eLnPxgA=; b=CxpmAFUnwWgkseGPkWHhKXhSbfcVDMGHvKDQOY+JDslpLGUAXfsWOps0v5FTwtGt3zTzuy N1nEkEB9g37WgzAg== Date: Wed, 11 Sep 2024 15:17:53 +0200 Subject: [PATCH 17/21] ntp: Move pps_jitter into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-17-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 22fece642c61..dc1e1d5dbd9c 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -42,6 +42,7 @@ * * @pps_valid: PPS signal watchdog counter * @pps_tf: PPS phase median filter + * @pps_jitter: PPS current jitter in nanoseconds * * Protected by the timekeeping locks. */ @@ -63,6 +64,7 @@ struct ntp_data { #ifdef CONFIG_NTP_PPS int pps_valid; long pps_tf[3]; + long pps_jitter; #endif }; =20 @@ -98,7 +100,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -static long pps_jitter; /* current jitter (ns) */ static struct timespec64 pps_fbase; /* beginning of the last freq interval= */ static int pps_shift; /* current interval duration (s) (shift) */ static int pps_intcnt; /* interval counter */ @@ -194,9 +195,9 @@ static inline void pps_fill_timex(struct ntp_data *ntpd= ata, struct __kernel_time { txc->ppsfreq =3D shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) * PPM_SCALE_INV, NTP_SCALE_SHIFT); - txc->jitter =3D pps_jitter; + txc->jitter =3D ntpdata->pps_jitter; if (!(ntpdata->time_status & STA_NANO)) - txc->jitter =3D pps_jitter / NSEC_PER_USEC; + txc->jitter =3D ntpdata->pps_jitter / NSEC_PER_USEC; txc->shift =3D pps_shift; txc->stabil =3D pps_stabil; txc->jitcnt =3D pps_jitcnt; @@ -990,9 +991,9 @@ static void hardpps_update_phase(struct ntp_data *ntpda= ta, long error) * threshold, the sample is discarded; otherwise, if so enabled, * the time offset is updated. */ - if (jitter > (pps_jitter << PPS_POPCORN)) { + if (jitter > (ntpdata->pps_jitter << PPS_POPCORN)) { printk_deferred(KERN_WARNING "hardpps: PPSJITTER: jitter=3D%ld, limit=3D= %ld\n", - jitter, (pps_jitter << PPS_POPCORN)); + jitter, (ntpdata->pps_jitter << PPS_POPCORN)); ntpdata->time_status |=3D STA_PPSJITTER; pps_jitcnt++; } else if (ntpdata->time_status & STA_PPSTIME) { @@ -1003,7 +1004,7 @@ static void hardpps_update_phase(struct ntp_data *ntp= data, long error) ntpdata->time_adjust =3D 0; } /* Update jitter */ - pps_jitter +=3D (jitter - pps_jitter) >> PPS_INTMIN; + ntpdata->pps_jitter +=3D (jitter - ntpdata->pps_jitter) >> PPS_INTMIN; } =20 /* --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEB4A1A302C; Wed, 11 Sep 2024 13:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; cv=none; b=R7NQZF9UaURjyzBVYij6Qzqp6keUSUvSPxViXbDiqD3NtvT9EjBXtGWiVt3uHHKcYwCQzcNC/QcgopmOa/qyv7yoaX26knn410d8JdHuYZniZ8bVbS8qufe2GeI1T4u+SvK6TiY7lzuon0889XsjLLHiwUrfS6deKCiHZUtr8KQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; c=relaxed/simple; bh=cO0WwuBORNRr4DJ+2v55yt8Uz/VW8LcRxoPZ1XMRmI8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pgugQZzFiXbYWW45WKMgbj4cue3Vw6Yzz/KRm+pjop8EdOZoq8zLuWtou2i8SwBp7ZtlAUXgnMgLxJNLzEMEyFktgxMtf7p75QEAnIRgRF6KkaQRgX2ZpJZ3xXtUZG/6kYJjnvVwO8kB6kyuORgKVkj1uEfbrwNilcYHE6wgjTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k5NfIYDF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rOIk4Pm7; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k5NfIYDF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rOIk4Pm7" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4nRltMZR0dP0dLpb0fek0WqDhnqEMxFw2mHWlD6JFf4=; b=k5NfIYDFWEuE7v2OUawmbqrcy9Ui/yVyoMumpHYAwpJlrJe4s3VaD/jdFWHPMV2wWfVa56 u/672/hdQlRBHmhpkn9/3zpBmyd6wqdfI3A7mrG6HHX9G1LmCpm2DIwKQwIqlrUEmGuloC LlVNZ5hN+f1E6/99PA7+K1YriRvkU5uu8RrhVgjxX+AXtNHBYdxlFKdk7yrETTjrX3zDIo WHiteiwTRayxjOI78e7OKR/s9MeEHMzZZTxdBgAc5sum5D9uhF/4Qakz8hKqU5QxO1lCzw UvTqkbDCahLHjRQCR9dxsD0OMdftpNZ55/uaWYMGF6p3ynuQJ0+0XNfi8r6eiA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4nRltMZR0dP0dLpb0fek0WqDhnqEMxFw2mHWlD6JFf4=; b=rOIk4Pm7Sr5M5QHl4BH1Z6B8Z+UQRuI9sMP8OFdSAW7lNza5b6XYtpG3OvLSxsjgetwu4g zaasA9M4X/NIU6Dg== Date: Wed, 11 Sep 2024 15:17:54 +0200 Subject: [PATCH 18/21] ntp: Move pps_fbase into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-18-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index dc1e1d5dbd9c..4098c38fbc3f 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -43,6 +43,7 @@ * @pps_valid: PPS signal watchdog counter * @pps_tf: PPS phase median filter * @pps_jitter: PPS current jitter in nanoseconds + * @pps_fbase: PPS beginning of the last freq interval * * Protected by the timekeeping locks. */ @@ -65,6 +66,7 @@ struct ntp_data { int pps_valid; long pps_tf[3]; long pps_jitter; + struct timespec64 pps_fbase; #endif }; =20 @@ -100,7 +102,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -static struct timespec64 pps_fbase; /* beginning of the last freq interval= */ static int pps_shift; /* current interval duration (s) (shift) */ static int pps_intcnt; /* interval counter */ static s64 pps_freq; /* frequency offset (scaled ns/s) */ @@ -144,7 +145,7 @@ static inline void pps_clear(struct ntp_data *ntpdata) ntpdata->pps_tf[0] =3D 0; ntpdata->pps_tf[1] =3D 0; ntpdata->pps_tf[2] =3D 0; - pps_fbase.tv_sec =3D pps_fbase.tv_nsec =3D 0; + ntpdata->pps_fbase.tv_sec =3D ntpdata->pps_fbase.tv_nsec =3D 0; pps_freq =3D 0; } =20 @@ -1037,13 +1038,13 @@ void __hardpps(const struct timespec64 *phase_ts, c= onst struct timespec64 *raw_t * When called for the first time, just start the frequency * interval */ - if (unlikely(pps_fbase.tv_sec =3D=3D 0)) { - pps_fbase =3D *raw_ts; + if (unlikely(ntpdata->pps_fbase.tv_sec =3D=3D 0)) { + ntpdata->pps_fbase =3D *raw_ts; return; } =20 /* Ok, now we have a base for frequency calculation */ - freq_norm =3D pps_normalize_ts(timespec64_sub(*raw_ts, pps_fbase)); + freq_norm =3D pps_normalize_ts(timespec64_sub(*raw_ts, ntpdata->pps_fbase= )); =20 /* * Check that the signal is in the range @@ -1053,7 +1054,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t (freq_norm.nsec < -MAXFREQ * freq_norm.sec)) { ntpdata->time_status |=3D STA_PPSJITTER; /* Restart the frequency calibration interval */ - pps_fbase =3D *raw_ts; + ntpdata->pps_fbase =3D *raw_ts; printk_deferred(KERN_ERR "hardpps: PPSJITTER: bad pulse\n"); return; } @@ -1062,7 +1063,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t if (freq_norm.sec >=3D (1 << pps_shift)) { pps_calcnt++; /* Restart the frequency calibration interval */ - pps_fbase =3D *raw_ts; + ntpdata->pps_fbase =3D *raw_ts; hardpps_update_freq(ntpdata, freq_norm); } =20 --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45E511A3051; Wed, 11 Sep 2024 13:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; cv=none; b=pKe04Y8MOu66j57bKkMbMfNNeVgEndOJfWMHoRQXPHFQ2mS3W8YK6E2vVFGlMhv2Hnfq9FWcIfcaFDyLS+iw+Pu8HYPA/FZ9DUw4IDhm8o+vwJSbrpvl6Sx8Yp47WK6d6FcPB/Xy8DtKwtGqse5R10ZXja/EMEbNB9R3ro+fLfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060687; c=relaxed/simple; bh=eSg2kys+qhJ4H0MpPX7XpiRTKHXw4HN6JdOB83qasiE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kdPa+ZcLLCHyUlCdcql0UeS31QUlbuB7j6Am0HMV1GLFh4lOSI7GuBi6AEReJA43+EZ510dtyqAcjqlBYE0yZBPtbyXcrtk9T/J7PJZOZFFHLAYUpHFg3QILy+uo3giBrsTJacZD6NCzzvmizaG3gYZ+/GGVjfgQPIhWn0p/qvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XzokRvqJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CP9l3ZB5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XzokRvqJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CP9l3ZB5" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z+kzeJnB8RrwCnaPcVHIZ7Wr6xgho4DYO3+HePvWiis=; b=XzokRvqJXtt+1DZidm+hk8t9LNS7g5KKbqjzhyREYO8tV2DWKIC3vK1+HCxcNUZNLiWBub oEEZ7W/1MpwAUgw9rc7WDNxo6dXDL+IfEVZHiO80T+qLM7HZgsJvdmwr/PM46wEVjEaw3Y ZAcdKipThEYhTEOxMAgYxrAxzrttfvaDDBGVDh1WeE5sBIrwjkd/K5mQgoFXPHDlk4F9YJ czF7f+jI4vnrcgsOfQfpi52T6iUpZKzn1+5CrV2OlZOhtwoaULwPMu5Pll0J88J4Xv0Gks OA+hy0I3q9gmAcA0I3MWczkBANBJ1CsTEKSbG0b3zkm2Bq/0YF7kN+OdtloONw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060679; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z+kzeJnB8RrwCnaPcVHIZ7Wr6xgho4DYO3+HePvWiis=; b=CP9l3ZB5tyFj6xK0I+iPTTOLui+9Ld8TUsPeTR6MhnLq6iS8x0DTmMp/P3m0oBkkgcvDlb BRfeGKXIFEDu56Bw== Date: Wed, 11 Sep 2024 15:17:55 +0200 Subject: [PATCH 19/21] ntp: Move pps_shift/intcnt into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-19-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 54 ++++++++++++++++++++++++++++-----------------------= --- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 4098c38fbc3f..a9103b08d1ec 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -44,6 +44,8 @@ * @pps_tf: PPS phase median filter * @pps_jitter: PPS current jitter in nanoseconds * @pps_fbase: PPS beginning of the last freq interval + * @pps_shift: PPS current interval duration in seconds (shift value) + * @pps_intcnt: PPS interval counter * * Protected by the timekeeping locks. */ @@ -67,6 +69,8 @@ struct ntp_data { long pps_tf[3]; long pps_jitter; struct timespec64 pps_fbase; + int pps_shift; + int pps_intcnt; #endif }; =20 @@ -102,8 +106,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -static int pps_shift; /* current interval duration (s) (shift) */ -static int pps_intcnt; /* interval counter */ static s64 pps_freq; /* frequency offset (scaled ns/s) */ static long pps_stabil; /* current stability (scaled ns/s) */ =20 @@ -128,11 +130,11 @@ static inline s64 ntp_offset_chunk(struct ntp_data *n= tpdata, s64 offset) return shift_right(offset, SHIFT_PLL + ntpdata->time_constant); } =20 -static inline void pps_reset_freq_interval(void) +static inline void pps_reset_freq_interval(struct ntp_data *ntpdata) { /* The PPS calibration interval may end surprisingly early */ - pps_shift =3D PPS_INTMIN; - pps_intcnt =3D 0; + ntpdata->pps_shift =3D PPS_INTMIN; + ntpdata->pps_intcnt =3D 0; } =20 /** @@ -141,7 +143,7 @@ static inline void pps_reset_freq_interval(void) */ static inline void pps_clear(struct ntp_data *ntpdata) { - pps_reset_freq_interval(); + pps_reset_freq_interval(ntpdata); ntpdata->pps_tf[0] =3D 0; ntpdata->pps_tf[1] =3D 0; ntpdata->pps_tf[2] =3D 0; @@ -199,7 +201,7 @@ static inline void pps_fill_timex(struct ntp_data *ntpd= ata, struct __kernel_time txc->jitter =3D ntpdata->pps_jitter; if (!(ntpdata->time_status & STA_NANO)) txc->jitter =3D ntpdata->pps_jitter / NSEC_PER_USEC; - txc->shift =3D pps_shift; + txc->shift =3D ntpdata->pps_shift; txc->stabil =3D pps_stabil; txc->jitcnt =3D pps_jitcnt; txc->calcnt =3D pps_calcnt; @@ -214,7 +216,7 @@ static inline s64 ntp_offset_chunk(struct ntp_data *ntp= data, s64 offset) return shift_right(offset, SHIFT_PLL + ntpdata->time_constant); } =20 -static inline void pps_reset_freq_interval(void) {} +static inline void pps_reset_freq_interval(struct ntp_data *ntpdata) {} static inline void pps_clear(struct ntp_data *ntpdata) {} static inline void pps_dec_valid(struct ntp_data *ntpdata) {} static inline void pps_set_freq(s64 freq) {} @@ -685,7 +687,7 @@ static inline void process_adj_status(struct ntp_data *= ntpdata, const struct __k ntpdata->time_status =3D STA_UNSYNC; ntpdata->ntp_next_leap_sec =3D TIME64_MAX; /* Restart PPS frequency calibration */ - pps_reset_freq_interval(); + pps_reset_freq_interval(ntpdata); } =20 /* @@ -888,13 +890,13 @@ static inline void pps_phase_filter_add(struct ntp_da= ta *ntpdata, long err) * Decrease frequency calibration interval length. It is halved after four * consecutive unstable intervals. */ -static inline void pps_dec_freq_interval(void) +static inline void pps_dec_freq_interval(struct ntp_data *ntpdata) { - if (--pps_intcnt <=3D -PPS_INTCOUNT) { - pps_intcnt =3D -PPS_INTCOUNT; - if (pps_shift > PPS_INTMIN) { - pps_shift--; - pps_intcnt =3D 0; + if (--ntpdata->pps_intcnt <=3D -PPS_INTCOUNT) { + ntpdata->pps_intcnt =3D -PPS_INTCOUNT; + if (ntpdata->pps_shift > PPS_INTMIN) { + ntpdata->pps_shift--; + ntpdata->pps_intcnt =3D 0; } } } @@ -903,13 +905,13 @@ static inline void pps_dec_freq_interval(void) * Increase frequency calibration interval length. It is doubled after * four consecutive stable intervals. */ -static inline void pps_inc_freq_interval(void) +static inline void pps_inc_freq_interval(struct ntp_data *ntpdata) { - if (++pps_intcnt >=3D PPS_INTCOUNT) { - pps_intcnt =3D PPS_INTCOUNT; - if (pps_shift < PPS_INTMAX) { - pps_shift++; - pps_intcnt =3D 0; + if (++ntpdata->pps_intcnt >=3D PPS_INTCOUNT) { + ntpdata->pps_intcnt =3D PPS_INTCOUNT; + if (ntpdata->pps_shift < PPS_INTMAX) { + ntpdata->pps_shift++; + ntpdata->pps_intcnt =3D 0; } } } @@ -930,10 +932,10 @@ static long hardpps_update_freq(struct ntp_data *ntpd= ata, struct pps_normtime fr s64 ftemp; =20 /* Check if the frequency interval was too long */ - if (freq_norm.sec > (2 << pps_shift)) { + if (freq_norm.sec > (2 << ntpdata->pps_shift)) { ntpdata->time_status |=3D STA_PPSERROR; pps_errcnt++; - pps_dec_freq_interval(); + pps_dec_freq_interval(ntpdata); printk_deferred(KERN_ERR "hardpps: PPSERROR: interval too long - %lld s\= n", freq_norm.sec); return 0; @@ -952,10 +954,10 @@ static long hardpps_update_freq(struct ntp_data *ntpd= ata, struct pps_normtime fr printk_deferred(KERN_WARNING "hardpps: PPSWANDER: change=3D%ld\n", delta= ); ntpdata->time_status |=3D STA_PPSWANDER; pps_stbcnt++; - pps_dec_freq_interval(); + pps_dec_freq_interval(ntpdata); } else { /* Good sample */ - pps_inc_freq_interval(); + pps_inc_freq_interval(ntpdata); } =20 /* @@ -1060,7 +1062,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t } =20 /* Signal is ok. Check if the current frequency interval is finished */ - if (freq_norm.sec >=3D (1 << pps_shift)) { + if (freq_norm.sec >=3D (1 << ntpdata->pps_shift)) { pps_calcnt++; /* Restart the frequency calibration interval */ ntpdata->pps_fbase =3D *raw_ts; --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 806EC1A38DB; Wed, 11 Sep 2024 13:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060688; cv=none; b=B+u+pPOelYkiyGgXHwGuC1Dh1zx2JoJZL4ni5o3QvrPaKnL/uUo/SBtkQ07uYmaZbtuJnZHhAocTlEhGdmJYREocRVtZJUasmBH1e3LO1+j5EFULfXZ4tkp5+FRLAC/x/8Y4ZPK4MIzyUnMvRTGY6EtaKWhAGKGC2HHHyvvU4h4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060688; c=relaxed/simple; bh=kzKWAP0j/HyYybXXxBLd7Q5U6wtVkXfbHlOu03qp20k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Hrc5NdHl04HFCno0iJBMfvXqvlw+68upsUU+tmJ5akrWyCo2J0SQF15pZql2wHA1H4j+3mcqzoh37gl2eYoZYR2nz0dMdRXCYq0hHpYxnq1yn/QY0HbtYSmGbZh/vM4sdQ2hEJ3PN3k/l6B3RVX2cEfdF+FlUVQ0gSBUtoH9Z+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uljgJJMj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KEYsffcZ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uljgJJMj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KEYsffcZ" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lhnQyQlNdW/rX+y0sX1hWAWJJZILP74ZXR46RGRAe+I=; b=uljgJJMj8dvi/J8wR2g2zx8zngPS8R9cAFW+x0uDZVcZJZvEtDwdzYt/91RIpgn09V9SKv gBKQZZrYfnMBlyr0BobtV+TmDCN97Aj83xGWNdHRSc9ntvTMbtjVEE9iSRR8BWP9QTITQi tFSFCDJxBjhzPh2i9O/WvKTNuDBKrSjw8lM/1kUV7xQOLCOLXk+XzrBVmV4u2cBG01vawT MhfBW3hEExVMiSVK6AQGUF8dg/TGLXG6GtpO4gtjr2ji9GrXdGwo78Ig7qMNflgFJmg/CR gSTkS3a/UEPWF1tM9+lWj9f8ZeA1+V0r+icnHtvUWtmB6h+CmUlaa8jjE9TnHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lhnQyQlNdW/rX+y0sX1hWAWJJZILP74ZXR46RGRAe+I=; b=KEYsffcZdOoDj9FuxFPEiAtnisngBH3XUWejyR6aJEsqNX/Dws5kTpcBO4OdZSv/NrTZCP WuvHz+HJAVQrDKCQ== Date: Wed, 11 Sep 2024 15:17:56 +0200 Subject: [PATCH 20/21] ntp: Move pps_freq/stabil into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-20-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Continue the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index a9103b08d1ec..c3089d8be0f7 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -46,6 +46,8 @@ * @pps_fbase: PPS beginning of the last freq interval * @pps_shift: PPS current interval duration in seconds (shift value) * @pps_intcnt: PPS interval counter + * @pps_freq: PPS frequency offset in scaled ns/s + * @pps_stabil: PPS current stability in scaled ns/s * * Protected by the timekeeping locks. */ @@ -71,6 +73,8 @@ struct ntp_data { struct timespec64 pps_fbase; int pps_shift; int pps_intcnt; + s64 pps_freq; + long pps_stabil; #endif }; =20 @@ -106,9 +110,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -static s64 pps_freq; /* frequency offset (scaled ns/s) */ -static long pps_stabil; /* current stability (scaled ns/s) */ - /* * PPS signal quality monitors */ @@ -148,7 +149,7 @@ static inline void pps_clear(struct ntp_data *ntpdata) ntpdata->pps_tf[1] =3D 0; ntpdata->pps_tf[2] =3D 0; ntpdata->pps_fbase.tv_sec =3D ntpdata->pps_fbase.tv_nsec =3D 0; - pps_freq =3D 0; + ntpdata->pps_freq =3D 0; } =20 /* @@ -166,9 +167,9 @@ static inline void pps_dec_valid(struct ntp_data *ntpda= ta) } } =20 -static inline void pps_set_freq(s64 freq) +static inline void pps_set_freq(struct ntp_data *ntpdata) { - pps_freq =3D freq; + ntpdata->pps_freq =3D ntpdata->time_freq; } =20 static inline bool is_error_status(int status) @@ -196,13 +197,13 @@ static inline bool is_error_status(int status) =20 static inline void pps_fill_timex(struct ntp_data *ntpdata, struct __kerne= l_timex *txc) { - txc->ppsfreq =3D shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) * + txc->ppsfreq =3D shift_right((ntpdata->pps_freq >> PPM_SCALE_INV_SHIFT= ) * PPM_SCALE_INV, NTP_SCALE_SHIFT); txc->jitter =3D ntpdata->pps_jitter; if (!(ntpdata->time_status & STA_NANO)) txc->jitter =3D ntpdata->pps_jitter / NSEC_PER_USEC; txc->shift =3D ntpdata->pps_shift; - txc->stabil =3D pps_stabil; + txc->stabil =3D ntpdata->pps_stabil; txc->jitcnt =3D pps_jitcnt; txc->calcnt =3D pps_calcnt; txc->errcnt =3D pps_errcnt; @@ -219,7 +220,7 @@ static inline s64 ntp_offset_chunk(struct ntp_data *ntp= data, s64 offset) static inline void pps_reset_freq_interval(struct ntp_data *ntpdata) {} static inline void pps_clear(struct ntp_data *ntpdata) {} static inline void pps_dec_valid(struct ntp_data *ntpdata) {} -static inline void pps_set_freq(s64 freq) {} +static inline void pps_set_freq(struct ntp_data *ntpdata) {} =20 static inline bool is_error_status(int status) { @@ -719,7 +720,7 @@ static inline void process_adjtimex_modes(struct ntp_da= ta *ntpdata, const struct ntpdata->time_freq =3D min(ntpdata->time_freq, MAXFREQ_SCALED); ntpdata->time_freq =3D max(ntpdata->time_freq, -MAXFREQ_SCALED); /* Update pps_freq */ - pps_set_freq(ntpdata->time_freq); + pps_set_freq(ntpdata); } =20 if (txc->modes & ADJ_MAXERROR) @@ -948,8 +949,8 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr */ ftemp =3D div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT, freq_norm.sec); - delta =3D shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT); - pps_freq =3D ftemp; + delta =3D shift_right(ftemp - ntpdata->pps_freq, NTP_SCALE_SHIFT); + ntpdata->pps_freq =3D ftemp; if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { printk_deferred(KERN_WARNING "hardpps: PPSWANDER: change=3D%ld\n", delta= ); ntpdata->time_status |=3D STA_PPSWANDER; @@ -967,12 +968,12 @@ static long hardpps_update_freq(struct ntp_data *ntpd= ata, struct pps_normtime fr delta_mod =3D delta; if (delta_mod < 0) delta_mod =3D -delta_mod; - pps_stabil +=3D (div_s64(((s64)delta_mod) << (NTP_SCALE_SHIFT - SHIFT_USE= C), - NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN; + ntpdata->pps_stabil +=3D (div_s64(((s64)delta_mod) << (NTP_SCALE_SHIFT - = SHIFT_USEC), + NSEC_PER_USEC) - ntpdata->pps_stabil) >> PPS_INTMIN; =20 /* If enabled, the system clock frequency is updated */ if ((ntpdata->time_status & STA_PPSFREQ) && !(ntpdata->time_status & STA_= FREQHOLD)) { - ntpdata->time_freq =3D pps_freq; + ntpdata->time_freq =3D ntpdata->pps_freq; ntp_update_frequency(ntpdata); } =20 --=20 2.39.2 From nobody Sat Nov 30 05:28:31 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2E911A3AB3; Wed, 11 Sep 2024 13:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060688; cv=none; b=MRslGkBw6C9VpZuG9Uac7preJa2WzRzeW+Ic6UDgzHjpGI8LZcLhX9Dn/HvEhdbd8TkOZZdWSGDLJ6qCyrJr/qB//lvvNyeu7ZqUqYqbyyiZJUKwNeHIiMEWDIvlrHoQRWFBJV0kpukQONIoGURGlL64azINypRDdi9kRXMLSgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726060688; c=relaxed/simple; bh=cg2PM211DmAM8vwNyyfctOBpXOxyEn3IDg9VxjRMYA0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mwi2OL3LZ6nuTtECuduQkeupUPnYQ+Zp1J7xZtX+w9ewj2+wbtMcEOVmDld64hPndaLTH3hQyqRXqK6xmgv4ADF6F0drGq+u3H0TGqFffnOZFAyXdeYj+K78hSnFwmtsC9CQ+Vj6iPpxhRKc+L/1nI9KP+daDFACNjToT9NqlZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bui4WZRS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5E38U+n8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bui4WZRS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5E38U+n8" From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1726060680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WI2cVBehM4PSxc5rOEnLQmGjNkeoiI7dtjBCguJbkM0=; b=bui4WZRSjaen6LSXlR60ad3uGIxj3a9CJ/f4590OmMxSmHvGAKXYwBWMBRM+zX5NIlw8LB +Z14pHB2ipmWz8Dx9lvIRZrbskwPFkxCkiv/hOCG9yRYO3ACJwSRXf01nOHxsSk4z/LRWb ijxOz+TzmknjWZCM2KvhaC0g/Y77uiBMxlD8hkdV352M/a9gK+mHvx4MvdfnImHuQICeUC vy04SsZgMnScdhXWy96qkUkKCHmU/wZSJxhfgQpU3DD9YdTdzN3sGZiXR24y7nxiD0YKH7 JxiWhdlo4WwW8g5FvG8fmGiu7O5+gPYJ7bhjDUuGbyUV8o2xGA8fdRT+Ls6uQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1726060680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WI2cVBehM4PSxc5rOEnLQmGjNkeoiI7dtjBCguJbkM0=; b=5E38U+n8OGQsnDRDhQ/VQZJedSZYkMquasple8yZL5aP1SOiXlmzlA0gMRsSSdtHcoLbX2 n+DE3KOwPx0V4xCg== Date: Wed, 11 Sep 2024 15:17:57 +0200 Subject: [PATCH 21/21] ntp: Move pps monitors into ntp_data Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-21-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-0-2d52f4e13476@linutronix.de> To: John Stultz , Frederic Weisbecker , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Miroslav Lichvar , Richard Cochran , Christopher S Hall , Anna-Maria Behnsen From: Thomas Gleixner Finalize the conversion from static variables to struct based data. No functional change. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Behnsen --- kernel/time/ntp.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index c3089d8be0f7..a2f57599a815 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -48,6 +48,10 @@ * @pps_intcnt: PPS interval counter * @pps_freq: PPS frequency offset in scaled ns/s * @pps_stabil: PPS current stability in scaled ns/s + * @pps_calcnt: PPS monitor: calibration intervals + * @pps_jitcnt: PPS monitor: jitter limit exceeded + * @pps_stbcnt: PPS monitor: stability limit exceeded + * @pps_errcnt: PPS monitor: calibration errors * * Protected by the timekeeping locks. */ @@ -75,6 +79,10 @@ struct ntp_data { int pps_intcnt; s64 pps_freq; long pps_stabil; + long pps_calcnt; + long pps_jitcnt; + long pps_stbcnt; + long pps_errcnt; #endif }; =20 @@ -110,15 +118,6 @@ static struct ntp_data tk_ntp_data =3D { intervals to decrease it */ #define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */ =20 -/* - * PPS signal quality monitors - */ -static long pps_calcnt; /* calibration intervals */ -static long pps_jitcnt; /* jitter limit exceeded */ -static long pps_stbcnt; /* stability limit exceeded */ -static long pps_errcnt; /* calibration errors */ - - /* * PPS kernel consumer compensates the whole phase error immediately. * Otherwise, reduce the offset by a fixed factor times the time constant. @@ -204,10 +203,10 @@ static inline void pps_fill_timex(struct ntp_data *nt= pdata, struct __kernel_time txc->jitter =3D ntpdata->pps_jitter / NSEC_PER_USEC; txc->shift =3D ntpdata->pps_shift; txc->stabil =3D ntpdata->pps_stabil; - txc->jitcnt =3D pps_jitcnt; - txc->calcnt =3D pps_calcnt; - txc->errcnt =3D pps_errcnt; - txc->stbcnt =3D pps_stbcnt; + txc->jitcnt =3D ntpdata->pps_jitcnt; + txc->calcnt =3D ntpdata->pps_calcnt; + txc->errcnt =3D ntpdata->pps_errcnt; + txc->stbcnt =3D ntpdata->pps_stbcnt; } =20 #else /* !CONFIG_NTP_PPS */ @@ -935,7 +934,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr /* Check if the frequency interval was too long */ if (freq_norm.sec > (2 << ntpdata->pps_shift)) { ntpdata->time_status |=3D STA_PPSERROR; - pps_errcnt++; + ntpdata->pps_errcnt++; pps_dec_freq_interval(ntpdata); printk_deferred(KERN_ERR "hardpps: PPSERROR: interval too long - %lld s\= n", freq_norm.sec); @@ -954,7 +953,7 @@ static long hardpps_update_freq(struct ntp_data *ntpdat= a, struct pps_normtime fr if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { printk_deferred(KERN_WARNING "hardpps: PPSWANDER: change=3D%ld\n", delta= ); ntpdata->time_status |=3D STA_PPSWANDER; - pps_stbcnt++; + ntpdata->pps_stbcnt++; pps_dec_freq_interval(ntpdata); } else { /* Good sample */ @@ -999,7 +998,7 @@ static void hardpps_update_phase(struct ntp_data *ntpda= ta, long error) printk_deferred(KERN_WARNING "hardpps: PPSJITTER: jitter=3D%ld, limit=3D= %ld\n", jitter, (ntpdata->pps_jitter << PPS_POPCORN)); ntpdata->time_status |=3D STA_PPSJITTER; - pps_jitcnt++; + ntpdata->pps_jitcnt++; } else if (ntpdata->time_status & STA_PPSTIME) { /* Correct the time using the phase offset */ ntpdata->time_offset =3D div_s64(((s64)correction) << NTP_SCALE_SHIFT, @@ -1064,7 +1063,7 @@ void __hardpps(const struct timespec64 *phase_ts, con= st struct timespec64 *raw_t =20 /* Signal is ok. Check if the current frequency interval is finished */ if (freq_norm.sec >=3D (1 << ntpdata->pps_shift)) { - pps_calcnt++; + ntpdata->pps_calcnt++; /* Restart the frequency calibration interval */ ntpdata->pps_fbase =3D *raw_ts; hardpps_update_freq(ntpdata, freq_norm); --=20 2.39.2