aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/clocksource.h16
-rw-r--r--include/linux/sched_clock.h12
-rw-r--r--include/linux/time.h26
3 files changed, 46 insertions, 8 deletions
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 7784b597e959..6013021a3b39 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -62,12 +62,18 @@ struct module;
62 * @suspend: suspend function for the clocksource, if necessary 62 * @suspend: suspend function for the clocksource, if necessary
63 * @resume: resume function for the clocksource, if necessary 63 * @resume: resume function for the clocksource, if necessary
64 * @owner: module reference, must be set by clocksource in modules 64 * @owner: module reference, must be set by clocksource in modules
65 *
66 * Note: This struct is not used in hotpathes of the timekeeping code
67 * because the timekeeper caches the hot path fields in its own data
68 * structure, so no line cache alignment is required,
69 *
70 * The pointer to the clocksource itself is handed to the read
71 * callback. If you need extra information there you can wrap struct
72 * clocksource into your own struct. Depending on the amount of
73 * information you need you should consider to cache line align that
74 * structure.
65 */ 75 */
66struct clocksource { 76struct clocksource {
67 /*
68 * Hotpath data, fits in a single cache line when the
69 * clocksource itself is cacheline aligned.
70 */
71 cycle_t (*read)(struct clocksource *cs); 77 cycle_t (*read)(struct clocksource *cs);
72 cycle_t mask; 78 cycle_t mask;
73 u32 mult; 79 u32 mult;
@@ -95,7 +101,7 @@ struct clocksource {
95 cycle_t wd_last; 101 cycle_t wd_last;
96#endif 102#endif
97 struct module *owner; 103 struct module *owner;
98} ____cacheline_aligned; 104};
99 105
100/* 106/*
101 * Clock source flags bits:: 107 * Clock source flags bits::
diff --git a/include/linux/sched_clock.h b/include/linux/sched_clock.h
index efa931c5cef1..411b52e424e1 100644
--- a/include/linux/sched_clock.h
+++ b/include/linux/sched_clock.h
@@ -10,11 +10,17 @@
10 10
11#ifdef CONFIG_GENERIC_SCHED_CLOCK 11#ifdef CONFIG_GENERIC_SCHED_CLOCK
12extern void sched_clock_postinit(void); 12extern void sched_clock_postinit(void);
13#else
14static inline void sched_clock_postinit(void) { }
15#endif
16 13
17extern void sched_clock_register(u64 (*read)(void), int bits, 14extern void sched_clock_register(u64 (*read)(void), int bits,
18 unsigned long rate); 15 unsigned long rate);
16#else
17static inline void sched_clock_postinit(void) { }
18
19static inline void sched_clock_register(u64 (*read)(void), int bits,
20 unsigned long rate)
21{
22 ;
23}
24#endif
19 25
20#endif 26#endif
diff --git a/include/linux/time.h b/include/linux/time.h
index beebe3a02d43..297f09f23896 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -125,6 +125,32 @@ static inline bool timeval_valid(const struct timeval *tv)
125 125
126extern struct timespec timespec_trunc(struct timespec t, unsigned gran); 126extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
127 127
128/*
129 * Validates if a timespec/timeval used to inject a time offset is valid.
130 * Offsets can be postive or negative. The value of the timeval/timespec
131 * is the sum of its fields, but *NOTE*: the field tv_usec/tv_nsec must
132 * always be non-negative.
133 */
134static inline bool timeval_inject_offset_valid(const struct timeval *tv)
135{
136 /* We don't check the tv_sec as it can be positive or negative */
137
138 /* Can't have more microseconds then a second */
139 if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC)
140 return false;
141 return true;
142}
143
144static inline bool timespec_inject_offset_valid(const struct timespec *ts)
145{
146 /* We don't check the tv_sec as it can be positive or negative */
147
148 /* Can't have more nanoseconds then a second */
149 if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC)
150 return false;
151 return true;
152}
153
128#define CURRENT_TIME (current_kernel_time()) 154#define CURRENT_TIME (current_kernel_time())
129#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 }) 155#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 })
130 156