diff options
author | Magnus Damm <damm@igel.co.jp> | 2009-04-21 15:24:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-21 16:41:47 -0400 |
commit | 4614e6adafa2c5e6c3a9c245af2807fa7bc5117a (patch) | |
tree | e4bb5eeaa252ede053abc6b3c4d15c4127ce7a32 | |
parent | 8e19608e8b5c001e4a66ce482edc474f05fb7355 (diff) |
clocksource: add enable() and disable() callbacks
Add enable() and disable() callbacks for clocksources.
This allows us to put unused clocksources in power save mode. The
functions clocksource_enable() and clocksource_disable() wrap the
callbacks and are inserted in the timekeeping code to enable before use
and disable after switching to a new clocksource.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
Acked-by: John Stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/clocksource.h | 31 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 12 |
2 files changed, 40 insertions, 3 deletions
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 0d96cde9ee5d..5a40d14daa9f 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h | |||
@@ -144,6 +144,8 @@ extern u64 timecounter_cyc2time(struct timecounter *tc, | |||
144 | * The ideal clocksource. A must-use where | 144 | * The ideal clocksource. A must-use where |
145 | * available. | 145 | * available. |
146 | * @read: returns a cycle value, passes clocksource as argument | 146 | * @read: returns a cycle value, passes clocksource as argument |
147 | * @enable: optional function to enable the clocksource | ||
148 | * @disable: optional function to disable the clocksource | ||
147 | * @mask: bitmask for two's complement | 149 | * @mask: bitmask for two's complement |
148 | * subtraction of non 64 bit counters | 150 | * subtraction of non 64 bit counters |
149 | * @mult: cycle to nanosecond multiplier (adjusted by NTP) | 151 | * @mult: cycle to nanosecond multiplier (adjusted by NTP) |
@@ -163,6 +165,8 @@ struct clocksource { | |||
163 | struct list_head list; | 165 | struct list_head list; |
164 | int rating; | 166 | int rating; |
165 | cycle_t (*read)(struct clocksource *cs); | 167 | cycle_t (*read)(struct clocksource *cs); |
168 | int (*enable)(struct clocksource *cs); | ||
169 | void (*disable)(struct clocksource *cs); | ||
166 | cycle_t mask; | 170 | cycle_t mask; |
167 | u32 mult; | 171 | u32 mult; |
168 | u32 mult_orig; | 172 | u32 mult_orig; |
@@ -275,6 +279,33 @@ static inline cycle_t clocksource_read(struct clocksource *cs) | |||
275 | } | 279 | } |
276 | 280 | ||
277 | /** | 281 | /** |
282 | * clocksource_enable: - enable clocksource | ||
283 | * @cs: pointer to clocksource | ||
284 | * | ||
285 | * Enables the specified clocksource. The clocksource callback | ||
286 | * function should start up the hardware and setup mult and field | ||
287 | * members of struct clocksource to reflect hardware capabilities. | ||
288 | */ | ||
289 | static inline int clocksource_enable(struct clocksource *cs) | ||
290 | { | ||
291 | return cs->enable ? cs->enable(cs) : 0; | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * clocksource_disable: - disable clocksource | ||
296 | * @cs: pointer to clocksource | ||
297 | * | ||
298 | * Disables the specified clocksource. The clocksource callback | ||
299 | * function should power down the now unused hardware block to | ||
300 | * save power. | ||
301 | */ | ||
302 | static inline void clocksource_disable(struct clocksource *cs) | ||
303 | { | ||
304 | if (cs->disable) | ||
305 | cs->disable(cs); | ||
306 | } | ||
307 | |||
308 | /** | ||
278 | * cyc2ns - converts clocksource cycles to nanoseconds | 309 | * cyc2ns - converts clocksource cycles to nanoseconds |
279 | * @cs: Pointer to clocksource | 310 | * @cs: Pointer to clocksource |
280 | * @cycles: Cycles | 311 | * @cycles: Cycles |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 900f1b6598d1..687dff49f6e7 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -182,7 +182,7 @@ EXPORT_SYMBOL(do_settimeofday); | |||
182 | */ | 182 | */ |
183 | static void change_clocksource(void) | 183 | static void change_clocksource(void) |
184 | { | 184 | { |
185 | struct clocksource *new; | 185 | struct clocksource *new, *old; |
186 | 186 | ||
187 | new = clocksource_get_next(); | 187 | new = clocksource_get_next(); |
188 | 188 | ||
@@ -191,11 +191,16 @@ static void change_clocksource(void) | |||
191 | 191 | ||
192 | clocksource_forward_now(); | 192 | clocksource_forward_now(); |
193 | 193 | ||
194 | new->raw_time = clock->raw_time; | 194 | if (clocksource_enable(new)) |
195 | return; | ||
195 | 196 | ||
197 | new->raw_time = clock->raw_time; | ||
198 | old = clock; | ||
196 | clock = new; | 199 | clock = new; |
200 | clocksource_disable(old); | ||
201 | |||
197 | clock->cycle_last = 0; | 202 | clock->cycle_last = 0; |
198 | clock->cycle_last = clocksource_read(new); | 203 | clock->cycle_last = clocksource_read(clock); |
199 | clock->error = 0; | 204 | clock->error = 0; |
200 | clock->xtime_nsec = 0; | 205 | clock->xtime_nsec = 0; |
201 | clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); | 206 | clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); |
@@ -292,6 +297,7 @@ void __init timekeeping_init(void) | |||
292 | ntp_init(); | 297 | ntp_init(); |
293 | 298 | ||
294 | clock = clocksource_get_next(); | 299 | clock = clocksource_get_next(); |
300 | clocksource_enable(clock); | ||
295 | clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); | 301 | clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); |
296 | clock->cycle_last = clocksource_read(clock); | 302 | clock->cycle_last = clocksource_read(clock); |
297 | 303 | ||