blob: 750a92c9db7e360e9d50bdedf4cbe0a6289f666f [file] [log] [blame]
Peter Zijlstra3e51f332008-05-03 18:29:28 +02001/*
2 * sched_clock for unstable cpu clocks
3 *
Peter Zijlstra90eec102015-11-16 11:08:45 +01004 * Copyright (C) 2008 Red Hat, Inc., Peter Zijlstra
Peter Zijlstra3e51f332008-05-03 18:29:28 +02005 *
Steven Rostedtc300ba22008-07-09 00:15:33 -04006 * Updates and enhancements:
7 * Copyright (C) 2008 Red Hat, Inc. Steven Rostedt <srostedt@redhat.com>
8 *
Peter Zijlstra3e51f332008-05-03 18:29:28 +02009 * Based on code by:
10 * Ingo Molnar <mingo@redhat.com>
11 * Guillaume Chazarain <guichaz@gmail.com>
12 *
Peter Zijlstrac6763292010-05-25 10:48:51 +020013 *
14 * What:
15 *
16 * cpu_clock(i) provides a fast (execution time) high resolution
17 * clock with bounded drift between CPUs. The value of cpu_clock(i)
18 * is monotonic for constant i. The timestamp returned is in nanoseconds.
19 *
20 * ######################### BIG FAT WARNING ##########################
21 * # when comparing cpu_clock(i) to cpu_clock(j) for i != j, time can #
22 * # go backwards !! #
23 * ####################################################################
24 *
25 * There is no strict promise about the base, although it tends to start
26 * at 0 on boot (but people really shouldn't rely on that).
27 *
28 * cpu_clock(i) -- can be used from any context, including NMI.
Peter Zijlstrac6763292010-05-25 10:48:51 +020029 * local_clock() -- is cpu_clock() on the current cpu.
30 *
Peter Zijlstraef08f0f2013-11-28 19:31:23 +010031 * sched_clock_cpu(i)
32 *
Peter Zijlstrac6763292010-05-25 10:48:51 +020033 * How:
34 *
35 * The implementation either uses sched_clock() when
36 * !CONFIG_HAVE_UNSTABLE_SCHED_CLOCK, which means in that case the
37 * sched_clock() is assumed to provide these properties (mostly it means
38 * the architecture provides a globally synchronized highres time source).
39 *
40 * Otherwise it tries to create a semi stable clock from a mixture of other
41 * clocks, including:
42 *
43 * - GTOD (clock monotomic)
Peter Zijlstra3e51f332008-05-03 18:29:28 +020044 * - sched_clock()
45 * - explicit idle events
46 *
Peter Zijlstrac6763292010-05-25 10:48:51 +020047 * We use GTOD as base and use sched_clock() deltas to improve resolution. The
48 * deltas are filtered to provide monotonicity and keeping it within an
49 * expected window.
Peter Zijlstra3e51f332008-05-03 18:29:28 +020050 *
51 * Furthermore, explicit sleep and wakeup hooks allow us to account for time
52 * that is otherwise invisible (TSC gets stopped).
53 *
Peter Zijlstra3e51f332008-05-03 18:29:28 +020054 */
Peter Zijlstra3e51f332008-05-03 18:29:28 +020055#include <linux/spinlock.h>
Ingo Molnar6409c4d2008-05-12 21:21:14 +020056#include <linux/hardirq.h>
Paul Gortmaker9984de12011-05-23 14:51:41 -040057#include <linux/export.h>
Ingo Molnarb3425012009-02-26 20:20:29 +010058#include <linux/percpu.h>
59#include <linux/ktime.h>
60#include <linux/sched.h>
Ingo Molnar38b8d202017-02-08 18:51:31 +010061#include <linux/nmi.h>
Ingo Molnare6017572017-02-01 16:36:40 +010062#include <linux/sched/clock.h>
Peter Zijlstra35af99e2013-11-28 19:38:42 +010063#include <linux/static_key.h>
Peter Zijlstra6577e422013-12-11 18:55:53 +010064#include <linux/workqueue.h>
Gideon Israel Dsouza52f5684c2014-04-07 15:39:20 -070065#include <linux/compiler.h>
Frederic Weisbecker4f49b902015-07-22 17:03:52 +020066#include <linux/tick.h>
Peter Zijlstra3e51f332008-05-03 18:29:28 +020067
Hugh Dickins2c3d1032008-07-25 19:45:00 +010068/*
69 * Scheduler clock - returns current time in nanosec units.
70 * This is default implementation.
71 * Architectures and sub-architectures can override this.
72 */
Gideon Israel Dsouza52f5684c2014-04-07 15:39:20 -070073unsigned long long __weak sched_clock(void)
Hugh Dickins2c3d1032008-07-25 19:45:00 +010074{
Ron92d23f72009-05-08 22:54:49 +093075 return (unsigned long long)(jiffies - INITIAL_JIFFIES)
76 * (NSEC_PER_SEC / HZ);
Hugh Dickins2c3d1032008-07-25 19:45:00 +010077}
Divyesh Shahb6ac23af2010-04-15 08:54:59 +020078EXPORT_SYMBOL_GPL(sched_clock);
Peter Zijlstra3e51f332008-05-03 18:29:28 +020079
Peter Zijlstra5bb6b1e2010-11-19 21:11:09 +010080__read_mostly int sched_clock_running;
Peter Zijlstrac1955a32008-08-11 08:59:03 +020081
Peter Zijlstra9881b022016-12-15 13:35:52 +010082void sched_clock_init(void)
83{
84 sched_clock_running = 1;
85}
86
Peter Zijlstra3e51f332008-05-03 18:29:28 +020087#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
Peter Zijlstraacb04052017-01-19 14:36:33 +010088/*
89 * We must start with !__sched_clock_stable because the unstable -> stable
90 * transition is accurate, while the stable -> unstable transition is not.
91 *
92 * Similarly we start with __sched_clock_stable_early, thereby assuming we
93 * will become stable, such that there's only a single 1 -> 0 transition.
94 */
Peter Zijlstra555570d72016-12-15 13:21:58 +010095static DEFINE_STATIC_KEY_FALSE(__sched_clock_stable);
Peter Zijlstraacb04052017-01-19 14:36:33 +010096static int __sched_clock_stable_early = 1;
Peter Zijlstra35af99e2013-11-28 19:38:42 +010097
Peter Zijlstra5680d802016-12-15 13:36:17 +010098/*
Peter Zijlstra698eff62017-03-17 12:48:18 +010099 * We want: ktime_get_ns() + __gtod_offset == sched_clock() + __sched_clock_offset
Peter Zijlstra5680d802016-12-15 13:36:17 +0100100 */
Peter Zijlstra698eff62017-03-17 12:48:18 +0100101__read_mostly u64 __sched_clock_offset;
102static __read_mostly u64 __gtod_offset;
Peter Zijlstra5680d802016-12-15 13:36:17 +0100103
104struct sched_clock_data {
105 u64 tick_raw;
106 u64 tick_gtod;
107 u64 clock;
108};
109
110static DEFINE_PER_CPU_SHARED_ALIGNED(struct sched_clock_data, sched_clock_data);
111
112static inline struct sched_clock_data *this_scd(void)
113{
114 return this_cpu_ptr(&sched_clock_data);
115}
116
117static inline struct sched_clock_data *cpu_sdc(int cpu)
118{
119 return &per_cpu(sched_clock_data, cpu);
120}
121
Peter Zijlstra35af99e2013-11-28 19:38:42 +0100122int sched_clock_stable(void)
123{
Peter Zijlstra555570d72016-12-15 13:21:58 +0100124 return static_branch_likely(&__sched_clock_stable);
Peter Zijlstrad375b4e2014-01-22 12:59:18 +0100125}
126
Peter Zijlstracf15ca82017-04-21 12:11:53 +0200127static void __scd_stamp(struct sched_clock_data *scd)
128{
129 scd->tick_gtod = ktime_get_ns();
130 scd->tick_raw = sched_clock();
131}
132
Peter Zijlstrad375b4e2014-01-22 12:59:18 +0100133static void __set_sched_clock_stable(void)
134{
Peter Zijlstra5680d802016-12-15 13:36:17 +0100135 struct sched_clock_data *scd = this_scd();
136
137 /*
138 * Attempt to make the (initial) unstable->stable transition continuous.
139 */
Peter Zijlstra698eff62017-03-17 12:48:18 +0100140 __sched_clock_offset = (scd->tick_gtod + __gtod_offset) - (scd->tick_raw);
Peter Zijlstra5680d802016-12-15 13:36:17 +0100141
142 printk(KERN_INFO "sched_clock: Marking stable (%lld, %lld)->(%lld, %lld)\n",
Peter Zijlstra698eff62017-03-17 12:48:18 +0100143 scd->tick_gtod, __gtod_offset,
144 scd->tick_raw, __sched_clock_offset);
Peter Zijlstra5680d802016-12-15 13:36:17 +0100145
Peter Zijlstra555570d72016-12-15 13:21:58 +0100146 static_branch_enable(&__sched_clock_stable);
Frederic Weisbecker4f49b902015-07-22 17:03:52 +0200147 tick_dep_clear(TICK_DEP_BIT_CLOCK_UNSTABLE);
Peter Zijlstra35af99e2013-11-28 19:38:42 +0100148}
149
Peter Zijlstracf15ca82017-04-21 12:11:53 +0200150/*
151 * If we ever get here, we're screwed, because we found out -- typically after
152 * the fact -- that TSC wasn't good. This means all our clocksources (including
153 * ktime) could have reported wrong values.
154 *
155 * What we do here is an attempt to fix up and continue sort of where we left
156 * off in a coherent manner.
157 *
158 * The only way to fully avoid random clock jumps is to boot with:
159 * "tsc=unstable".
160 */
Peter Zijlstra71fdb702017-03-13 13:46:21 +0100161static void __sched_clock_work(struct work_struct *work)
162{
Peter Zijlstracf15ca82017-04-21 12:11:53 +0200163 struct sched_clock_data *scd;
164 int cpu;
165
166 /* take a current timestamp and set 'now' */
167 preempt_disable();
168 scd = this_scd();
169 __scd_stamp(scd);
170 scd->clock = scd->tick_gtod + __gtod_offset;
171 preempt_enable();
172
173 /* clone to all CPUs */
174 for_each_possible_cpu(cpu)
175 per_cpu(sched_clock_data, cpu) = *scd;
176
177 printk(KERN_INFO "sched_clock: Marking unstable (%lld, %lld)<-(%lld, %lld)\n",
178 scd->tick_gtod, __gtod_offset,
179 scd->tick_raw, __sched_clock_offset);
180
Peter Zijlstra71fdb702017-03-13 13:46:21 +0100181 static_branch_disable(&__sched_clock_stable);
182}
183
184static DECLARE_WORK(sched_clock_work, __sched_clock_work);
185
186static void __clear_sched_clock_stable(void)
Peter Zijlstra35af99e2013-11-28 19:38:42 +0100187{
Peter Zijlstracf15ca82017-04-21 12:11:53 +0200188 if (!sched_clock_stable())
189 return;
Peter Zijlstra5680d802016-12-15 13:36:17 +0100190
Frederic Weisbecker4f49b902015-07-22 17:03:52 +0200191 tick_dep_set(TICK_DEP_BIT_CLOCK_UNSTABLE);
Peter Zijlstracf15ca82017-04-21 12:11:53 +0200192 schedule_work(&sched_clock_work);
Peter Zijlstra71fdb702017-03-13 13:46:21 +0100193}
Peter Zijlstra6577e422013-12-11 18:55:53 +0100194
195void clear_sched_clock_stable(void)
196{
Peter Zijlstrad375b4e2014-01-22 12:59:18 +0100197 __sched_clock_stable_early = 0;
198
Peter Zijlstra9881b022016-12-15 13:35:52 +0100199 smp_mb(); /* matches sched_clock_init_late() */
Peter Zijlstrad375b4e2014-01-22 12:59:18 +0100200
Peter Zijlstra9881b022016-12-15 13:35:52 +0100201 if (sched_clock_running == 2)
Peter Zijlstra71fdb702017-03-13 13:46:21 +0100202 __clear_sched_clock_stable();
Peter Zijlstra6577e422013-12-11 18:55:53 +0100203}
204
Peter Zijlstra9881b022016-12-15 13:35:52 +0100205void sched_clock_init_late(void)
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200206{
Peter Zijlstra9881b022016-12-15 13:35:52 +0100207 sched_clock_running = 2;
Peter Zijlstrad375b4e2014-01-22 12:59:18 +0100208 /*
209 * Ensure that it is impossible to not do a static_key update.
210 *
211 * Either {set,clear}_sched_clock_stable() must see sched_clock_running
212 * and do the update, or we must see their __sched_clock_stable_early
213 * and do the update, or both.
214 */
215 smp_mb(); /* matches {set,clear}_sched_clock_stable() */
216
217 if (__sched_clock_stable_early)
218 __set_sched_clock_stable();
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200219}
220
221/*
Ingo Molnarb3425012009-02-26 20:20:29 +0100222 * min, max except they take wrapping into account
Peter Zijlstra354879b2008-08-25 17:15:34 +0200223 */
224
225static inline u64 wrap_min(u64 x, u64 y)
226{
227 return (s64)(x - y) < 0 ? x : y;
228}
229
230static inline u64 wrap_max(u64 x, u64 y)
231{
232 return (s64)(x - y) > 0 ? x : y;
233}
234
235/*
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200236 * update the percpu scd from the raw @now value
237 *
238 * - filter out backward motion
Peter Zijlstra354879b2008-08-25 17:15:34 +0200239 * - use the GTOD tick value to create a window to filter crazy TSC values
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200240 */
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200241static u64 sched_clock_local(struct sched_clock_data *scd)
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200242{
Pavel Tatashin7b09cc52017-03-22 16:24:17 -0400243 u64 now, clock, old_clock, min_clock, max_clock, gtod;
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200244 s64 delta;
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200245
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200246again:
247 now = sched_clock();
248 delta = now - scd->tick_raw;
Peter Zijlstra354879b2008-08-25 17:15:34 +0200249 if (unlikely(delta < 0))
250 delta = 0;
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200251
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200252 old_clock = scd->clock;
253
Peter Zijlstra354879b2008-08-25 17:15:34 +0200254 /*
255 * scd->clock = clamp(scd->tick_gtod + delta,
Ingo Molnarb3425012009-02-26 20:20:29 +0100256 * max(scd->tick_gtod, scd->clock),
257 * scd->tick_gtod + TICK_NSEC);
Peter Zijlstra354879b2008-08-25 17:15:34 +0200258 */
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200259
Pavel Tatashin7b09cc52017-03-22 16:24:17 -0400260 gtod = scd->tick_gtod + __gtod_offset;
261 clock = gtod + delta;
262 min_clock = wrap_max(gtod, old_clock);
263 max_clock = wrap_max(old_clock, gtod + TICK_NSEC);
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200264
Peter Zijlstra354879b2008-08-25 17:15:34 +0200265 clock = wrap_max(clock, min_clock);
266 clock = wrap_min(clock, max_clock);
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200267
Eric Dumazet152f9d02009-09-30 20:36:19 +0200268 if (cmpxchg64(&scd->clock, old_clock, clock) != old_clock)
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200269 goto again;
Ingo Molnar56b90612008-07-30 10:15:55 +0200270
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200271 return clock;
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200272}
273
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200274static u64 sched_clock_remote(struct sched_clock_data *scd)
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200275{
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200276 struct sched_clock_data *my_scd = this_scd();
277 u64 this_clock, remote_clock;
278 u64 *ptr, old_val, val;
279
Thomas Gleixnera1cbcaa2013-04-06 10:10:27 +0200280#if BITS_PER_LONG != 64
281again:
282 /*
283 * Careful here: The local and the remote clock values need to
284 * be read out atomic as we need to compare the values and
285 * then update either the local or the remote side. So the
286 * cmpxchg64 below only protects one readout.
287 *
288 * We must reread via sched_clock_local() in the retry case on
289 * 32bit as an NMI could use sched_clock_local() via the
290 * tracer and hit between the readout of
291 * the low32bit and the high 32bit portion.
292 */
293 this_clock = sched_clock_local(my_scd);
294 /*
295 * We must enforce atomic readout on 32bit, otherwise the
296 * update on the remote cpu can hit inbetween the readout of
297 * the low32bit and the high 32bit portion.
298 */
299 remote_clock = cmpxchg64(&scd->clock, 0, 0);
300#else
301 /*
302 * On 64bit the read of [my]scd->clock is atomic versus the
303 * update, so we can avoid the above 32bit dance.
304 */
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200305 sched_clock_local(my_scd);
306again:
307 this_clock = my_scd->clock;
308 remote_clock = scd->clock;
Thomas Gleixnera1cbcaa2013-04-06 10:10:27 +0200309#endif
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200310
311 /*
312 * Use the opportunity that we have both locks
313 * taken to couple the two clocks: we take the
314 * larger time as the latest time for both
315 * runqueues. (this creates monotonic movement)
316 */
317 if (likely((s64)(remote_clock - this_clock) < 0)) {
318 ptr = &scd->clock;
319 old_val = remote_clock;
320 val = this_clock;
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200321 } else {
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200322 /*
323 * Should be rare, but possible:
324 */
325 ptr = &my_scd->clock;
326 old_val = this_clock;
327 val = remote_clock;
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200328 }
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200329
Eric Dumazet152f9d02009-09-30 20:36:19 +0200330 if (cmpxchg64(ptr, old_val, val) != old_val)
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200331 goto again;
332
333 return val;
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200334}
335
Peter Zijlstrac6763292010-05-25 10:48:51 +0200336/*
337 * Similar to cpu_clock(), but requires local IRQs to be disabled.
338 *
339 * See cpu_clock().
340 */
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200341u64 sched_clock_cpu(int cpu)
342{
Ingo Molnarb3425012009-02-26 20:20:29 +0100343 struct sched_clock_data *scd;
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200344 u64 clock;
345
Peter Zijlstra35af99e2013-11-28 19:38:42 +0100346 if (sched_clock_stable())
Peter Zijlstra698eff62017-03-17 12:48:18 +0100347 return sched_clock() + __sched_clock_offset;
Peter Zijlstraa3817592008-05-29 10:07:15 +0200348
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200349 if (unlikely(!sched_clock_running))
350 return 0ull;
351
Fernando Luis Vazquez Cao96b3d282014-03-06 14:25:28 +0900352 preempt_disable_notrace();
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200353 scd = cpu_sdc(cpu);
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200354
Peter Zijlstradef0a9b2009-09-18 20:14:01 +0200355 if (cpu != smp_processor_id())
356 clock = sched_clock_remote(scd);
357 else
358 clock = sched_clock_local(scd);
Fernando Luis Vazquez Cao96b3d282014-03-06 14:25:28 +0900359 preempt_enable_notrace();
Ingo Molnare4e4e532008-04-14 08:50:02 +0200360
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200361 return clock;
362}
Daniel Lezcano2c923e92016-04-11 16:38:34 +0200363EXPORT_SYMBOL_GPL(sched_clock_cpu);
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200364
365void sched_clock_tick(void)
366{
Peter Zijlstra8325d9c2009-02-26 21:40:16 +0100367 struct sched_clock_data *scd;
Peter Zijlstraa3817592008-05-29 10:07:15 +0200368
Peter Zijlstrab421b222017-04-21 12:14:13 +0200369 if (sched_clock_stable())
370 return;
371
372 if (unlikely(!sched_clock_running))
373 return;
374
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200375 WARN_ON_ONCE(!irqs_disabled());
376
Peter Zijlstra8325d9c2009-02-26 21:40:16 +0100377 scd = this_scd();
Peter Zijlstracf15ca82017-04-21 12:11:53 +0200378 __scd_stamp(scd);
Peter Zijlstrab421b222017-04-21 12:14:13 +0200379 sched_clock_local(scd);
380}
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200381
Peter Zijlstrab421b222017-04-21 12:14:13 +0200382void sched_clock_tick_stable(void)
383{
384 u64 gtod, clock;
385
386 if (!sched_clock_stable())
387 return;
388
389 /*
390 * Called under watchdog_lock.
391 *
392 * The watchdog just found this TSC to (still) be stable, so now is a
393 * good moment to update our __gtod_offset. Because once we find the
394 * TSC to be unstable, any computation will be computing crap.
395 */
396 local_irq_disable();
397 gtod = ktime_get_ns();
398 clock = sched_clock();
399 __gtod_offset = (clock + __sched_clock_offset) - gtod;
400 local_irq_enable();
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200401}
402
403/*
404 * We are going deep-idle (irqs are disabled):
405 */
406void sched_clock_idle_sleep_event(void)
407{
408 sched_clock_cpu(smp_processor_id());
409}
410EXPORT_SYMBOL_GPL(sched_clock_idle_sleep_event);
411
412/*
Peter Zijlstraac1e8432017-04-21 12:26:23 +0200413 * We just idled; resync with ktime. (called with irqs disabled):
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200414 */
Peter Zijlstraac1e8432017-04-21 12:26:23 +0200415void sched_clock_idle_wakeup_event(void)
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200416{
Thomas Gleixner1c5745a2008-12-22 23:05:28 +0100417 if (timekeeping_suspended)
418 return;
419
Peter Zijlstra354879b2008-08-25 17:15:34 +0200420 sched_clock_tick();
Tejun Heo03e0d462015-12-08 11:28:04 -0500421 touch_softlockup_watchdog_sched();
Peter Zijlstra3e51f332008-05-03 18:29:28 +0200422}
423EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
424
Peter Zijlstra8325d9c2009-02-26 21:40:16 +0100425#else /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
426
Peter Zijlstra8325d9c2009-02-26 21:40:16 +0100427u64 sched_clock_cpu(int cpu)
428{
429 if (unlikely(!sched_clock_running))
430 return 0;
431
432 return sched_clock();
433}
Peter Zijlstra9881b022016-12-15 13:35:52 +0100434
David Millerb9f8fcd2009-12-13 18:25:02 -0800435#endif /* CONFIG_HAVE_UNSTABLE_SCHED_CLOCK */
436
Cyril Bur545a2bf2015-02-12 15:01:24 -0800437/*
438 * Running clock - returns the time that has elapsed while a guest has been
439 * running.
440 * On a guest this value should be local_clock minus the time the guest was
441 * suspended by the hypervisor (for any reason).
442 * On bare metal this function should return the same as local_clock.
443 * Architectures and sub-architectures can override this.
444 */
445u64 __weak running_clock(void)
446{
447 return local_clock();
448}