diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/posix-timers.c | 35 | ||||
-rw-r--r-- | kernel/time/timekeeping.c | 21 |
2 files changed, 56 insertions, 0 deletions
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index d089d052c4a9..495440779ce3 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c | |||
@@ -242,6 +242,25 @@ static int posix_get_monotonic_raw(clockid_t which_clock, struct timespec *tp) | |||
242 | return 0; | 242 | return 0; |
243 | } | 243 | } |
244 | 244 | ||
245 | |||
246 | static int posix_get_realtime_coarse(clockid_t which_clock, struct timespec *tp) | ||
247 | { | ||
248 | *tp = current_kernel_time(); | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | static int posix_get_monotonic_coarse(clockid_t which_clock, | ||
253 | struct timespec *tp) | ||
254 | { | ||
255 | *tp = get_monotonic_coarse(); | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp) | ||
260 | { | ||
261 | *tp = ktime_to_timespec(KTIME_LOW_RES); | ||
262 | return 0; | ||
263 | } | ||
245 | /* | 264 | /* |
246 | * Initialize everything, well, just everything in Posix clocks/timers ;) | 265 | * Initialize everything, well, just everything in Posix clocks/timers ;) |
247 | */ | 266 | */ |
@@ -262,10 +281,26 @@ static __init int init_posix_timers(void) | |||
262 | .timer_create = no_timer_create, | 281 | .timer_create = no_timer_create, |
263 | .nsleep = no_nsleep, | 282 | .nsleep = no_nsleep, |
264 | }; | 283 | }; |
284 | struct k_clock clock_realtime_coarse = { | ||
285 | .clock_getres = posix_get_coarse_res, | ||
286 | .clock_get = posix_get_realtime_coarse, | ||
287 | .clock_set = do_posix_clock_nosettime, | ||
288 | .timer_create = no_timer_create, | ||
289 | .nsleep = no_nsleep, | ||
290 | }; | ||
291 | struct k_clock clock_monotonic_coarse = { | ||
292 | .clock_getres = posix_get_coarse_res, | ||
293 | .clock_get = posix_get_monotonic_coarse, | ||
294 | .clock_set = do_posix_clock_nosettime, | ||
295 | .timer_create = no_timer_create, | ||
296 | .nsleep = no_nsleep, | ||
297 | }; | ||
265 | 298 | ||
266 | register_posix_clock(CLOCK_REALTIME, &clock_realtime); | 299 | register_posix_clock(CLOCK_REALTIME, &clock_realtime); |
267 | register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); | 300 | register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); |
268 | register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw); | 301 | register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw); |
302 | register_posix_clock(CLOCK_REALTIME_COARSE, &clock_realtime_coarse); | ||
303 | register_posix_clock(CLOCK_MONOTONIC_COARSE, &clock_monotonic_coarse); | ||
269 | 304 | ||
270 | posix_timers_cache = kmem_cache_create("posix_timers_cache", | 305 | posix_timers_cache = kmem_cache_create("posix_timers_cache", |
271 | sizeof (struct k_itimer), 0, SLAB_PANIC, | 306 | sizeof (struct k_itimer), 0, SLAB_PANIC, |
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 15e06defca55..03cbeb34d141 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c | |||
@@ -847,6 +847,10 @@ unsigned long get_seconds(void) | |||
847 | } | 847 | } |
848 | EXPORT_SYMBOL(get_seconds); | 848 | EXPORT_SYMBOL(get_seconds); |
849 | 849 | ||
850 | struct timespec __current_kernel_time(void) | ||
851 | { | ||
852 | return xtime_cache; | ||
853 | } | ||
850 | 854 | ||
851 | struct timespec current_kernel_time(void) | 855 | struct timespec current_kernel_time(void) |
852 | { | 856 | { |
@@ -862,3 +866,20 @@ struct timespec current_kernel_time(void) | |||
862 | return now; | 866 | return now; |
863 | } | 867 | } |
864 | EXPORT_SYMBOL(current_kernel_time); | 868 | EXPORT_SYMBOL(current_kernel_time); |
869 | |||
870 | struct timespec get_monotonic_coarse(void) | ||
871 | { | ||
872 | struct timespec now, mono; | ||
873 | unsigned long seq; | ||
874 | |||
875 | do { | ||
876 | seq = read_seqbegin(&xtime_lock); | ||
877 | |||
878 | now = xtime_cache; | ||
879 | mono = wall_to_monotonic; | ||
880 | } while (read_seqretry(&xtime_lock, seq)); | ||
881 | |||
882 | set_normalized_timespec(&now, now.tv_sec + mono.tv_sec, | ||
883 | now.tv_nsec + mono.tv_nsec); | ||
884 | return now; | ||
885 | } | ||