[PATCH 20/21] ntp: Move pps_freq/stabil into ntp_data

From: Anna-Maria Behnsen
Date: Wed Sep 11 2024 - 09:24:03 EST


From: Thomas Gleixner <tglx@xxxxxxxxxxxxx>

Continue the conversion from static variables to struct based data.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Anna-Maria Behnsen <anna-maria@xxxxxxxxxxxxx>
---
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
};

@@ -106,9 +110,6 @@ static struct ntp_data tk_ntp_data = {
intervals to decrease it */
#define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */

-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] = 0;
ntpdata->pps_tf[2] = 0;
ntpdata->pps_fbase.tv_sec = ntpdata->pps_fbase.tv_nsec = 0;
- pps_freq = 0;
+ ntpdata->pps_freq = 0;
}

/*
@@ -166,9 +167,9 @@ 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)
{
- pps_freq = freq;
+ ntpdata->pps_freq = ntpdata->time_freq;
}

static inline bool is_error_status(int status)
@@ -196,13 +197,13 @@ static inline bool is_error_status(int status)

static inline void pps_fill_timex(struct ntp_data *ntpdata, struct __kernel_timex *txc)
{
- txc->ppsfreq = shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) *
+ txc->ppsfreq = shift_right((ntpdata->pps_freq >> PPM_SCALE_INV_SHIFT) *
PPM_SCALE_INV, NTP_SCALE_SHIFT);
txc->jitter = ntpdata->pps_jitter;
if (!(ntpdata->time_status & STA_NANO))
txc->jitter = ntpdata->pps_jitter / NSEC_PER_USEC;
txc->shift = ntpdata->pps_shift;
- txc->stabil = pps_stabil;
+ txc->stabil = ntpdata->pps_stabil;
txc->jitcnt = pps_jitcnt;
txc->calcnt = pps_calcnt;
txc->errcnt = pps_errcnt;
@@ -219,7 +220,7 @@ static inline s64 ntp_offset_chunk(struct ntp_data *ntpdata, 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) {}

static inline bool is_error_status(int status)
{
@@ -719,7 +720,7 @@ static inline void process_adjtimex_modes(struct ntp_data *ntpdata, const struct
ntpdata->time_freq = min(ntpdata->time_freq, MAXFREQ_SCALED);
ntpdata->time_freq = max(ntpdata->time_freq, -MAXFREQ_SCALED);
/* Update pps_freq */
- pps_set_freq(ntpdata->time_freq);
+ pps_set_freq(ntpdata);
}

if (txc->modes & ADJ_MAXERROR)
@@ -948,8 +949,8 @@ static long hardpps_update_freq(struct ntp_data *ntpdata, struct pps_normtime fr
*/
ftemp = div_s64(((s64)(-freq_norm.nsec)) << NTP_SCALE_SHIFT,
freq_norm.sec);
- delta = shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT);
- pps_freq = ftemp;
+ delta = shift_right(ftemp - ntpdata->pps_freq, NTP_SCALE_SHIFT);
+ ntpdata->pps_freq = ftemp;
if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) {
printk_deferred(KERN_WARNING "hardpps: PPSWANDER: change=%ld\n", delta);
ntpdata->time_status |= STA_PPSWANDER;
@@ -967,12 +968,12 @@ static long hardpps_update_freq(struct ntp_data *ntpdata, struct pps_normtime fr
delta_mod = delta;
if (delta_mod < 0)
delta_mod = -delta_mod;
- pps_stabil += (div_s64(((s64)delta_mod) << (NTP_SCALE_SHIFT - SHIFT_USEC),
- NSEC_PER_USEC) - pps_stabil) >> PPS_INTMIN;
+ ntpdata->pps_stabil += (div_s64(((s64)delta_mod) << (NTP_SCALE_SHIFT - SHIFT_USEC),
+ NSEC_PER_USEC) - ntpdata->pps_stabil) >> PPS_INTMIN;

/* If enabled, the system clock frequency is updated */
if ((ntpdata->time_status & STA_PPSFREQ) && !(ntpdata->time_status & STA_FREQHOLD)) {
- ntpdata->time_freq = pps_freq;
+ ntpdata->time_freq = ntpdata->pps_freq;
ntp_update_frequency(ntpdata);
}


--
2.39.2