diff options
Diffstat (limited to 'kernel/time/timekeeping.c')
-rw-r--r-- | kernel/time/timekeeping.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index e8c77d9c633a..7a248135c6f2 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -125,6 +125,75 @@ void getnstimeofday(struct timespec *ts) | |||
125 | 125 | ||
126 | EXPORT_SYMBOL(getnstimeofday); | 126 | EXPORT_SYMBOL(getnstimeofday); |
127 | 127 | ||
128 | ktime_t ktime_get(void) | ||
129 | { | ||
130 | cycle_t cycle_now, cycle_delta; | ||
131 | unsigned int seq; | ||
132 | s64 secs, nsecs; | ||
133 | |||
134 | WARN_ON(timekeeping_suspended); | ||
135 | |||
136 | do { | ||
137 | seq = read_seqbegin(&xtime_lock); | ||
138 | secs = xtime.tv_sec + wall_to_monotonic.tv_sec; | ||
139 | nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec; | ||
140 | |||
141 | /* read clocksource: */ | ||
142 | cycle_now = clocksource_read(clock); | ||
143 | |||
144 | /* calculate the delta since the last update_wall_time: */ | ||
145 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | ||
146 | |||
147 | /* convert to nanoseconds: */ | ||
148 | nsecs += cyc2ns(clock, cycle_delta); | ||
149 | |||
150 | } while (read_seqretry(&xtime_lock, seq)); | ||
151 | /* | ||
152 | * Use ktime_set/ktime_add_ns to create a proper ktime on | ||
153 | * 32-bit architectures without CONFIG_KTIME_SCALAR. | ||
154 | */ | ||
155 | return ktime_add_ns(ktime_set(secs, 0), nsecs); | ||
156 | } | ||
157 | EXPORT_SYMBOL_GPL(ktime_get); | ||
158 | |||
159 | /** | ||
160 | * ktime_get_ts - get the monotonic clock in timespec format | ||
161 | * @ts: pointer to timespec variable | ||
162 | * | ||
163 | * The function calculates the monotonic clock from the realtime | ||
164 | * clock and the wall_to_monotonic offset and stores the result | ||
165 | * in normalized timespec format in the variable pointed to by @ts. | ||
166 | */ | ||
167 | void ktime_get_ts(struct timespec *ts) | ||
168 | { | ||
169 | cycle_t cycle_now, cycle_delta; | ||
170 | struct timespec tomono; | ||
171 | unsigned int seq; | ||
172 | s64 nsecs; | ||
173 | |||
174 | WARN_ON(timekeeping_suspended); | ||
175 | |||
176 | do { | ||
177 | seq = read_seqbegin(&xtime_lock); | ||
178 | *ts = xtime; | ||
179 | tomono = wall_to_monotonic; | ||
180 | |||
181 | /* read clocksource: */ | ||
182 | cycle_now = clocksource_read(clock); | ||
183 | |||
184 | /* calculate the delta since the last update_wall_time: */ | ||
185 | cycle_delta = (cycle_now - clock->cycle_last) & clock->mask; | ||
186 | |||
187 | /* convert to nanoseconds: */ | ||
188 | nsecs = cyc2ns(clock, cycle_delta); | ||
189 | |||
190 | } while (read_seqretry(&xtime_lock, seq)); | ||
191 | |||
192 | set_normalized_timespec(ts, ts->tv_sec + tomono.tv_sec, | ||
193 | ts->tv_nsec + tomono.tv_nsec + nsecs); | ||
194 | } | ||
195 | EXPORT_SYMBOL_GPL(ktime_get_ts); | ||
196 | |||
128 | /** | 197 | /** |
129 | * do_gettimeofday - Returns the time of day in a timeval | 198 | * do_gettimeofday - Returns the time of day in a timeval |
130 | * @tv: pointer to the timeval to be set | 199 | * @tv: pointer to the timeval to be set |