Skip to content

Commit 64c3613

Browse files
anna-marialxKAGA-KOKO
authored andcommitted
vdso/gettimeofday: Prepare do_hres() for introduction of struct vdso_clock
To support multiple PTP clocks, the VDSO data structure needs to be reworked. All clock specific data will end up in struct vdso_clock and in struct vdso_time_data there will be array of VDSO clocks. At the moment, vdso_clock is simply a define which maps vdso_clock to vdso_time_data. Prepare for the rework of these structures by adding a struct vdso_clock pointer argument to do_hres(), and replace the struct vdso_time_data pointer with the new pointer argument where applicable. No functional change. Signed-off-by: Anna-Maria Behnsen <[email protected]> Signed-off-by: Nam Cao <[email protected]> Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent cddb82d commit 64c3613

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lib/vdso/gettimeofday.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ static __always_inline int do_hres_timens(const struct vdso_time_data *vdns, clo
139139
}
140140
#endif
141141

142-
static __always_inline int do_hres(const struct vdso_time_data *vd, clockid_t clk,
143-
struct __kernel_timespec *ts)
142+
static __always_inline
143+
int do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc,
144+
clockid_t clk, struct __kernel_timespec *ts)
144145
{
145-
const struct vdso_timestamp *vdso_ts = &vd->basetime[clk];
146+
const struct vdso_timestamp *vdso_ts = &vc->basetime[clk];
146147
u64 cycles, sec, ns;
147148
u32 seq;
148149

@@ -154,31 +155,31 @@ static __always_inline int do_hres(const struct vdso_time_data *vd, clockid_t cl
154155
/*
155156
* Open coded function vdso_read_begin() to handle
156157
* VDSO_CLOCKMODE_TIMENS. Time namespace enabled tasks have a
157-
* special VVAR page installed which has vd->seq set to 1 and
158-
* vd->clock_mode set to VDSO_CLOCKMODE_TIMENS. For non time
158+
* special VVAR page installed which has vc->seq set to 1 and
159+
* vc->clock_mode set to VDSO_CLOCKMODE_TIMENS. For non time
159160
* namespace affected tasks this does not affect performance
160-
* because if vd->seq is odd, i.e. a concurrent update is in
161-
* progress the extra check for vd->clock_mode is just a few
162-
* extra instructions while spin waiting for vd->seq to become
161+
* because if vc->seq is odd, i.e. a concurrent update is in
162+
* progress the extra check for vc->clock_mode is just a few
163+
* extra instructions while spin waiting for vc->seq to become
163164
* even again.
164165
*/
165-
while (unlikely((seq = READ_ONCE(vd->seq)) & 1)) {
166+
while (unlikely((seq = READ_ONCE(vc->seq)) & 1)) {
166167
if (IS_ENABLED(CONFIG_TIME_NS) &&
167-
vd->clock_mode == VDSO_CLOCKMODE_TIMENS)
168+
vc->clock_mode == VDSO_CLOCKMODE_TIMENS)
168169
return do_hres_timens(vd, clk, ts);
169170
cpu_relax();
170171
}
171172
smp_rmb();
172173

173-
if (unlikely(!vdso_clocksource_ok(vd)))
174+
if (unlikely(!vdso_clocksource_ok(vc)))
174175
return -1;
175176

176-
cycles = __arch_get_hw_counter(vd->clock_mode, vd);
177+
cycles = __arch_get_hw_counter(vc->clock_mode, vd);
177178
if (unlikely(!vdso_cycles_ok(cycles)))
178179
return -1;
179-
ns = vdso_calc_ns(vd, cycles, vdso_ts->nsec);
180+
ns = vdso_calc_ns(vc, cycles, vdso_ts->nsec);
180181
sec = vdso_ts->sec;
181-
} while (unlikely(vdso_read_retry(vd, seq)));
182+
} while (unlikely(vdso_read_retry(vc, seq)));
182183

183184
/*
184185
* Do this outside the loop: a race inside the loop could result
@@ -278,7 +279,7 @@ __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t clock,
278279
else
279280
return -1;
280281

281-
return do_hres(vc, clock, ts);
282+
return do_hres(vd, vc, clock, ts);
282283
}
283284

284285
static __maybe_unused int
@@ -334,7 +335,7 @@ __cvdso_gettimeofday_data(const struct vdso_time_data *vd,
334335
if (likely(tv != NULL)) {
335336
struct __kernel_timespec ts;
336337

337-
if (do_hres(&vc[CS_HRES_COARSE], CLOCK_REALTIME, &ts))
338+
if (do_hres(vd, &vc[CS_HRES_COARSE], CLOCK_REALTIME, &ts))
338339
return gettimeofday_fallback(tv, tz);
339340

340341
tv->tv_sec = ts.tv_sec;

0 commit comments

Comments
 (0)