From nobody Thu Nov 28 08:46:46 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 40A731D1517; Wed, 2 Oct 2024 15:44:56 +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=1727883898; cv=none; b=uM3TqpGPqrerubeytWzfVZstvJahx+G5WZvTnNJ1Cj9YQlZFLn3TyjyWpr3rIjCjNbwAI5lMFXbbNgkJAQ3XSk4rJrt0db4GV7nFTBNSUyvTuNWT3BrbmtaasFzMT9ptU6Fyfcag1iNrbzUxN3hdkTiQEorZmcJ4XWCyiHPu394= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727883898; c=relaxed/simple; bh=ut/N+HQRdEb+VskrPpEE5zSmDpXCtEB+/zRcwngNaXU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=M9qjcgsbSXq5SEi4OfSgEDZrCy1AhJSyaJYN6PQvSGlaYFTMMvi0fUrIEySXHV3llwhENBhvPDlnhNFtRDqAHd+6FeMYc+TQRnShEA7CPmGjReobiqUQX/4wYBRuVKG+C0KiFyGIdpwcgxtnefYzT9MT/JXgig2j2lXX5gNUnag= 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=4lj5KIwu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eFG7of0J; 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="4lj5KIwu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eFG7of0J" Date: Wed, 02 Oct 2024 15:44:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1727883894; h=from:from:sender:sender:reply-to: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=jOi8vpsK5bCIebMym2YIJFZ5FYfSbu8TZs0jqhARSTs=; b=4lj5KIwuAZc02QTNw4eRtYtdBklzaVItaPZeIEDxQRECeZgQz93KQj55UMqeGXCywPSZCv Yk2qWDB+CpCIYfs/ge267DGA5RSgAOq5wUZAlr78D9QziqJo7XWq8pAAO8tDQ54RYTa3Ob ARXYOksn8mumYEL9RwTcYDCcQ8eP/XIyoahhMAqHXlzcZeB/WJVIm8j+f39WOy7H2BQvTh KatHjrWCaZ9DmUDfHr60FVmZHdCuMWBEDHy+8NDh6wne240uRZ//cZwRwFGQImkIwlnE2Y z/1EvVMwYUqk2Fsf6XCtIUy3T6neP2smvEsX1nipUxZhXSApHWugJDD9hJmKSA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1727883894; h=from:from:sender:sender:reply-to: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=jOi8vpsK5bCIebMym2YIJFZ5FYfSbu8TZs0jqhARSTs=; b=eFG7of0JSNwHhBo04I3vihMQhe1oF54rZeYznVa5yCISpneu4TNuZpUXVCKoTTAeD9/J+/ 7Km9RmanzKnJUKCw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: timers/core] ntp: Introduce struct ntp_data Cc: Thomas Gleixner , "Anna-Maria Behnsen" , John Stultz , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-7-2d52f4e13476@linutronix.de> References: <20240911-devel-anna-maria-b4-timers-ptp-ntp-v1-7-2d52f4e13476@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <172788389420.1442.14137586674389222703.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the timers/core branch of tip: Commit-ID: 68f66f97c5689825012877f58df65964056d4b5d Gitweb: https://git.kernel.org/tip/68f66f97c5689825012877f58df659640= 56d4b5d Author: Thomas Gleixner AuthorDate: Wed, 11 Sep 2024 15:17:43 +02:00 Committer: Thomas Gleixner CommitterDate: Wed, 02 Oct 2024 16:53:39 +02:00 ntp: Introduce struct ntp_data 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 Signed-off-by: Thomas Gleixner Acked-by: John Stultz Link: https://lore.kernel.org/all/20240911-devel-anna-maria-b4-timers-ptp-n= tp-v1-7-2d52f4e13476@linutronix.de --- 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 0bfd07d..f95f233 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) { @@ -706,7 +712,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) @@ -747,13 +753,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. @@ -761,6 +766,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) { @@ -769,7 +775,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); @@ -782,15 +788,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, @@ -811,7 +817,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 */ @@ -932,7 +938,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; @@ -979,7 +985,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; @@ -1030,6 +1036,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 @@ -1070,7 +1077,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);