History

clocksource: fix resume logic

We need to make sure that the clocksources are resumed, when timekeeping is resumed. The current resume logic does not guarantee this. Add a resume function pointer to the clocksource struct, so clocksource drivers which need to reinitialize the clocksource can provide a resume function. Add a resume function, which calls the maybe available clocksource resume functions and resets the watchdog function, so a stable TSC can be used accross suspend/resume.

Thomas Gleixner committed 19 years ago

Commit b52f52a1 parent 4037d453 files · +50 −0Browse files

Unified · Split

3 files
  1. include/linux/clocksource.h +3 −0
  2. kernel/time/clocksource.c +45 −0
  3. kernel/timer.c +2 −0
include/linux/clocksource.h+3−0
@@ -49,6 +49,7 @@ struct clocksource; · 48 unmodified lines
4949 * @shift: cycle to nanosecond divisor (power of two)
5050 * @flags: flags describing special properties
5151 * @vread: vsyscall based read
52+ * @resume: resume function for the clocksource, if necessary
5253 * @cycle_interval: Used internally by timekeeping core, please ignore.
5354 * @xtime_interval: Used internally by timekeeping core, please ignore.
5455 */
@@ -65,6 +66,7 @@ struct clocksource { · 10 unmodified lines
6566 u32 shift;
6667 unsigned long flags;
6768 cycle_t (*vread)(void);
69+ void (*resume)(void);
6870
6971 /* timekeeping specific data, ignore */
7072 cycle_t cycle_interval;
@@ -209,6 +211,7 @@ static inline void clocksource_calculate_interval(struct clocksource *c, · 138 unmodified lines
209211 extern int clocksource_register(struct clocksource*);
210212 extern struct clocksource* clocksource_get_next(void);
211213 extern void clocksource_change_rating(struct clocksource *cs, int rating);
214+extern void clocksource_resume(void);
212215
213216 #ifdef CONFIG_GENERIC_TIME_VSYSCALL
214217 extern void update_vsyscall(struct timespec *ts, struct clocksource *c);
kernel/time/clocksource.c+45−0
@@ -74,6 +74,8 @@ static struct clocksource *watchdog; · 73 unmodified lines
7474 static struct timer_list watchdog_timer;
7575 static DEFINE_SPINLOCK(watchdog_lock);
7676 static cycle_t watchdog_last;
77+static int watchdog_resumed;
78+
7779 /*
7880 * Interval: 0.5sec Threshold: 0.0625s
7981 */
@@ -98,15 +100,26 @@ static void clocksource_watchdog(unsigned long data) · 18 unmodified lines
98100 struct clocksource *cs, *tmp;
99101 cycle_t csnow, wdnow;
100102 int64_t wd_nsec, cs_nsec;
103+ int resumed;
101104
102105 spin_lock(&watchdog_lock);
103106
107+ resumed = watchdog_resumed;
108+ if (unlikely(resumed))
109+ watchdog_resumed = 0;
110+
104111 wdnow = watchdog->read();
105112 wd_nsec = cyc2ns(watchdog, (wdnow - watchdog_last) & watchdog->mask);
106113 watchdog_last = wdnow;
107114
108115 list_for_each_entry_safe(cs, tmp, &watchdog_list, wd_list) {
109116 csnow = cs->read();
117+
118+ if (unlikely(resumed)) {
119+ cs->wd_last = csnow;
120+ continue;
121+ }
122+
110123 /* Initialized ? */
111124 if (!(cs->flags & CLOCK_SOURCE_WATCHDOG)) {
112125 if ((cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) &&
@@ -136,6 +149,13 @@ static void clocksource_watchdog(unsigned long data) · 23 unmodified lines
136149 }
137150 spin_unlock(&watchdog_lock);
138151 }
152+static void clocksource_resume_watchdog(void)
153+{
154+ spin_lock(&watchdog_lock);
155+ watchdog_resumed = 1;
156+ spin_unlock(&watchdog_lock);
157+}
158+
139159 static void clocksource_check_watchdog(struct clocksource *cs)
140160 {
141161 struct clocksource *cse;
@@ -182,8 +202,33 @@ static void clocksource_check_watchdog(struct clocksource *cs) · 40 unmodified lines
182202 if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS)
183203 cs->flags |= CLOCK_SOURCE_VALID_FOR_HRES;
184204 }
205+
206+static inline void clocksource_resume_watchdog(void) { }
185207 #endif
186208
209+/**
210+ * clocksource_resume - resume the clocksource(s)
211+ */
212+void clocksource_resume(void)
213+{
214+ struct list_head *tmp;
215+ unsigned long flags;
216+
217+ spin_lock_irqsave(&clocksource_lock, flags);
218+
219+ list_for_each(tmp, &clocksource_list) {
220+ struct clocksource *cs;
221+
222+ cs = list_entry(tmp, struct clocksource, list);
223+ if (cs->resume)
224+ cs->resume();
225+ }
226+
227+ clocksource_resume_watchdog();
228+
229+ spin_unlock_irqrestore(&clocksource_lock, flags);
230+}
231+
187232 /**
188233 * clocksource_get_next - Returns the selected clocksource
189234 *
kernel/timer.c+2−0
@@ -1499,6 +1499,8 @@ unregister_time_interpolator(struct time_interpolator *ti) · 1498 unmodified lines
14991499 prev = &curr->next;
15001500 }
15011501
1502+ clocksource_resume();
1503+
15021504 write_seqlock_irqsave(&xtime_lock, flags);
15031505 if (ti == time_interpolator) {
15041506 /* we lost the best time-interpolator: */