History

timekeeping: Add persistent_clock_exist flag

In current kernel, there are several places which need to check whether there is a persistent clock for the platform. Current check is done by calling the read_persistent_clock() and validating its return value. So one optimization is to do the check only once in timekeeping_init(), and use a flag persistent_clock_exist to record it. v2: Add a has_persistent_clock() helper function, as suggested by John.

Feng Tang committed 13 years ago

Commit 31ade301 parent f0dbe812 files · +17 −5Browse files

Unified · Split

2 files
  1. include/linux/time.h +6 −0
  2. kernel/time/timekeeping.c +11 −5
include/linux/time.h+6−0
@@ -115,6 +115,12 @@ static inline bool timespec_valid_strict(const struct timespec *ts) · 114 unmodified lines
115115 return true;
116116 }
117117
118+extern bool persistent_clock_exist;
119+static inline bool has_persistent_clock(void)
120+{
121+ return persistent_clock_exist;
122+}
123+
118124 extern void read_persistent_clock(struct timespec *ts);
119125 extern void read_boot_clock(struct timespec *ts);
120126 extern int update_persistent_clock(struct timespec now);
kernel/time/timekeeping.c+11−5
@@ -28,6 +28,9 @@ static struct timekeeper timekeeper; · 27 unmodified lines
2828 /* flag for if timekeeping is suspended */
2929 int __read_mostly timekeeping_suspended;
3030
31+/* Flag for if there is a persistent clock on this platform */
32+bool __read_mostly persistent_clock_exist = false;
33+
3134 static inline void tk_normalize_xtime(struct timekeeper *tk)
3235 {
3336 while (tk->xtime_nsec >= ((u64)NSEC_PER_SEC << tk->shift)) {
@@ -609,12 +612,14 @@ void __init timekeeping_init(void) · 575 unmodified lines
609612 struct timespec now, boot, tmp;
610613
611614 read_persistent_clock(&now);
615+
612616 if (!timespec_valid_strict(&now)) {
613617 pr_warn("WARNING: Persistent clock returned invalid value!\n"
614618 " Check your CMOS/BIOS settings.\n");
615619 now.tv_sec = 0;
616620 now.tv_nsec = 0;
617− }
621+ } else if (now.tv_sec || now.tv_nsec)
622+ persistent_clock_exist = true;
618623
619624 read_boot_clock(&boot);
620625 if (!timespec_valid_strict(&boot)) {
@@ -687,11 +692,12 @@ void timekeeping_inject_sleeptime(struct timespec *delta) · 66 unmodified lines
687692 {
688693 struct timekeeper *tk = &timekeeper;
689694 unsigned long flags;
690− struct timespec ts;
691695
692− /* Make sure we don't set the clock twice */
693− read_persistent_clock(&ts);
694− if (!(ts.tv_sec == 0 && ts.tv_nsec == 0))
696+ /*
697+ * Make sure we don't set the clock twice, as timekeeping_resume()
698+ * already did it
699+ */
700+ if (has_persistent_clock())
695701 return;
696702
697703 write_seqlock_irqsave(&tk->lock, flags);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t