xref: /OK3568_Linux_fs/kernel/include/linux/sched_clock.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * sched_clock.h: support for extending counters to full 64-bit ns counter
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun #ifndef LINUX_SCHED_CLOCK
6*4882a593Smuzhiyun #define LINUX_SCHED_CLOCK
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifdef CONFIG_GENERIC_SCHED_CLOCK
9*4882a593Smuzhiyun /**
10*4882a593Smuzhiyun  * struct clock_read_data - data required to read from sched_clock()
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * @epoch_ns:		sched_clock() value at last update
13*4882a593Smuzhiyun  * @epoch_cyc:		Clock cycle value at last update.
14*4882a593Smuzhiyun  * @sched_clock_mask:   Bitmask for two's complement subtraction of non 64bit
15*4882a593Smuzhiyun  *			clocks.
16*4882a593Smuzhiyun  * @read_sched_clock:	Current clock source (or dummy source when suspended).
17*4882a593Smuzhiyun  * @mult:		Multipler for scaled math conversion.
18*4882a593Smuzhiyun  * @shift:		Shift value for scaled math conversion.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Care must be taken when updating this structure; it is read by
21*4882a593Smuzhiyun  * some very hot code paths. It occupies <=40 bytes and, when combined
22*4882a593Smuzhiyun  * with the seqcount used to synchronize access, comfortably fits into
23*4882a593Smuzhiyun  * a 64 byte cache line.
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun struct clock_read_data {
26*4882a593Smuzhiyun 	u64 epoch_ns;
27*4882a593Smuzhiyun 	u64 epoch_cyc;
28*4882a593Smuzhiyun 	u64 sched_clock_mask;
29*4882a593Smuzhiyun 	u64 (*read_sched_clock)(void);
30*4882a593Smuzhiyun 	u32 mult;
31*4882a593Smuzhiyun 	u32 shift;
32*4882a593Smuzhiyun };
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun extern struct clock_read_data *sched_clock_read_begin(unsigned int *seq);
35*4882a593Smuzhiyun extern int sched_clock_read_retry(unsigned int seq);
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun extern void generic_sched_clock_init(void);
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun extern void sched_clock_register(u64 (*read)(void), int bits,
40*4882a593Smuzhiyun 				 unsigned long rate);
41*4882a593Smuzhiyun #else
generic_sched_clock_init(void)42*4882a593Smuzhiyun static inline void generic_sched_clock_init(void) { }
43*4882a593Smuzhiyun 
sched_clock_register(u64 (* read)(void),int bits,unsigned long rate)44*4882a593Smuzhiyun static inline void sched_clock_register(u64 (*read)(void), int bits,
45*4882a593Smuzhiyun 					unsigned long rate)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun #endif
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #endif
51