@@ -87,6 +87,26 @@ static __always_inline void vdso_set_timespec(struct __kernel_timespec *ts, u64
8787 ts -> tv_nsec = ns ;
8888}
8989
90+ static __always_inline
91+ bool vdso_get_timestamp (const struct vdso_time_data * vd , const struct vdso_clock * vc ,
92+ unsigned int clkidx , u64 * sec , u64 * ns )
93+ {
94+ const struct vdso_timestamp * vdso_ts = & vc -> basetime [clkidx ];
95+ u64 cycles ;
96+
97+ if (unlikely (!vdso_clocksource_ok (vc )))
98+ return false;
99+
100+ cycles = __arch_get_hw_counter (vc -> clock_mode , vd );
101+ if (unlikely (!vdso_cycles_ok (cycles )))
102+ return false;
103+
104+ * ns = vdso_calc_ns (vc , cycles , vdso_ts -> nsec );
105+ * sec = vdso_ts -> sec ;
106+
107+ return true;
108+ }
109+
90110#ifdef CONFIG_TIME_NS
91111
92112#ifdef CONFIG_GENERIC_VDSO_DATA_STORE
@@ -104,28 +124,20 @@ bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *
104124 const struct vdso_time_data * vd = __arch_get_vdso_u_timens_data (vdns );
105125 const struct timens_offset * offs = & vcns -> offset [clk ];
106126 const struct vdso_clock * vc = vd -> clock_data ;
107- const struct vdso_timestamp * vdso_ts ;
108- u64 cycles , ns ;
109127 u32 seq ;
110128 s64 sec ;
129+ u64 ns ;
111130
112131 if (clk != CLOCK_MONOTONIC_RAW )
113132 vc = & vc [CS_HRES_COARSE ];
114133 else
115134 vc = & vc [CS_RAW ];
116- vdso_ts = & vc -> basetime [clk ];
117135
118136 do {
119137 seq = vdso_read_begin (vc );
120138
121- if (unlikely (!vdso_clocksource_ok (vc )))
122- return false;
123-
124- cycles = __arch_get_hw_counter (vc -> clock_mode , vd );
125- if (unlikely (!vdso_cycles_ok (cycles )))
139+ if (!vdso_get_timestamp (vd , vc , clk , & sec , & ns ))
126140 return false;
127- ns = vdso_calc_ns (vc , cycles , vdso_ts -> nsec );
128- sec = vdso_ts -> sec ;
129141 } while (unlikely (vdso_read_retry (vc , seq )));
130142
131143 /* Add the namespace offset */
@@ -155,8 +167,7 @@ static __always_inline
155167bool do_hres (const struct vdso_time_data * vd , const struct vdso_clock * vc ,
156168 clockid_t clk , struct __kernel_timespec * ts )
157169{
158- const struct vdso_timestamp * vdso_ts = & vc -> basetime [clk ];
159- u64 cycles , sec , ns ;
170+ u64 sec , ns ;
160171 u32 seq ;
161172
162173 /* Allows to compile the high resolution parts out */
@@ -183,14 +194,8 @@ bool do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc,
183194 }
184195 smp_rmb ();
185196
186- if (unlikely (! vdso_clocksource_ok ( vc ) ))
197+ if (! vdso_get_timestamp ( vd , vc , clk , & sec , & ns ))
187198 return false;
188-
189- cycles = __arch_get_hw_counter (vc -> clock_mode , vd );
190- if (unlikely (!vdso_cycles_ok (cycles )))
191- return false;
192- ns = vdso_calc_ns (vc , cycles , vdso_ts -> nsec );
193- sec = vdso_ts -> sec ;
194199 } while (unlikely (vdso_read_retry (vc , seq )));
195200
196201 vdso_set_timespec (ts , sec , ns );
0 commit comments