Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_SCHED_CLOCK_H
0003 #define _LINUX_SCHED_CLOCK_H
0004 
0005 #include <linux/smp.h>
0006 
0007 /*
0008  * Do not use outside of architecture code which knows its limitations.
0009  *
0010  * sched_clock() has no promise of monotonicity or bounded drift between
0011  * CPUs, use (which you should not) requires disabling IRQs.
0012  *
0013  * Please use one of the three interfaces below.
0014  */
0015 extern unsigned long long notrace sched_clock(void);
0016 
0017 /*
0018  * See the comment in kernel/sched/clock.c
0019  */
0020 extern u64 running_clock(void);
0021 extern u64 sched_clock_cpu(int cpu);
0022 
0023 
0024 extern void sched_clock_init(void);
0025 
0026 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
0027 static inline void sched_clock_tick(void)
0028 {
0029 }
0030 
0031 static inline void clear_sched_clock_stable(void)
0032 {
0033 }
0034 
0035 static inline void sched_clock_idle_sleep_event(void)
0036 {
0037 }
0038 
0039 static inline void sched_clock_idle_wakeup_event(void)
0040 {
0041 }
0042 
0043 static inline u64 cpu_clock(int cpu)
0044 {
0045     return sched_clock();
0046 }
0047 
0048 static inline u64 local_clock(void)
0049 {
0050     return sched_clock();
0051 }
0052 #else
0053 extern int sched_clock_stable(void);
0054 extern void clear_sched_clock_stable(void);
0055 
0056 /*
0057  * When sched_clock_stable(), __sched_clock_offset provides the offset
0058  * between local_clock() and sched_clock().
0059  */
0060 extern u64 __sched_clock_offset;
0061 
0062 extern void sched_clock_tick(void);
0063 extern void sched_clock_tick_stable(void);
0064 extern void sched_clock_idle_sleep_event(void);
0065 extern void sched_clock_idle_wakeup_event(void);
0066 
0067 /*
0068  * As outlined in clock.c, provides a fast, high resolution, nanosecond
0069  * time source that is monotonic per cpu argument and has bounded drift
0070  * between cpus.
0071  *
0072  * ######################### BIG FAT WARNING ##########################
0073  * # when comparing cpu_clock(i) to cpu_clock(j) for i != j, time can #
0074  * # go backwards !!                                                  #
0075  * ####################################################################
0076  */
0077 static inline u64 cpu_clock(int cpu)
0078 {
0079     return sched_clock_cpu(cpu);
0080 }
0081 
0082 static inline u64 local_clock(void)
0083 {
0084     return sched_clock_cpu(raw_smp_processor_id());
0085 }
0086 #endif
0087 
0088 #ifdef CONFIG_IRQ_TIME_ACCOUNTING
0089 /*
0090  * An i/f to runtime opt-in for irq time accounting based off of sched_clock.
0091  * The reason for this explicit opt-in is not to have perf penalty with
0092  * slow sched_clocks.
0093  */
0094 extern void enable_sched_clock_irqtime(void);
0095 extern void disable_sched_clock_irqtime(void);
0096 #else
0097 static inline void enable_sched_clock_irqtime(void) {}
0098 static inline void disable_sched_clock_irqtime(void) {}
0099 #endif
0100 
0101 #endif /* _LINUX_SCHED_CLOCK_H */