For testing: export sched_clock() in clock_gettime() Signed-off-by: Andi Kleen --- include/linux/time.h | 1 + kernel/posix-timers.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) Index: linux/include/linux/time.h =================================================================== --- linux.orig/include/linux/time.h +++ linux/include/linux/time.h @@ -219,6 +219,7 @@ struct itimerval { * The IDs of various hardware clocks: */ #define CLOCK_SGI_CYCLE 10 +#define CLOCK_SCHED_CLOCK 11 #define MAX_CLOCKS 16 #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) #define CLOCKS_MONO CLOCK_MONOTONIC Index: linux/kernel/posix-timers.c =================================================================== --- linux.orig/kernel/posix-timers.c +++ linux/kernel/posix-timers.c @@ -223,6 +223,14 @@ static int posix_ktime_get_ts(clockid_t return 0; } +static int posix_sched_clock(clockid_t clock, struct timespec *tp) +{ + unsigned long long ns = sched_clock(); + tp->tv_nsec = do_div(ns, 1000000000); + tp->tv_sec = ns; + return 0; +} + /* * Initialize everything, well, just everything in Posix clocks/timers ;) */ @@ -236,9 +244,14 @@ static __init int init_posix_timers(void .clock_get = posix_ktime_get_ts, .clock_set = do_posix_clock_nosettime, }; + struct k_clock clock_sched = { + .clock_get = posix_sched_clock, + .clock_getres = hrtimer_get_res, + }; register_posix_clock(CLOCK_REALTIME, &clock_realtime); register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); + register_posix_clock(CLOCK_SCHED_CLOCK, &clock_sched); posix_timers_cache = kmem_cache_create("posix_timers_cache", sizeof (struct k_itimer), 0, 0, NULL);