1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
3 * vdso_clock_getres.c: Sample code to test clock_getres.
4 * Copyright (c) 2019 Arm Ltd.
7 * gcc -std=gnu99 vdso_clock_getres.c
9 * Tested on ARM, ARM64, MIPS32, x86 (32-bit and 64-bit),
10 * Power (32-bit and 64-bit), S390x (32-bit and 64-bit).
11 * Might work on other architectures.
26 #include <sys/syscall.h>
28 #include "../kselftest.h"
30 static long syscall_clock_getres(clockid_t _clkid
, struct timespec
*_ts
)
34 ret
= syscall(SYS_clock_getres
, _clkid
, _ts
);
39 const char *vdso_clock_name
[12] = {
42 "CLOCK_PROCESS_CPUTIME_ID",
43 "CLOCK_THREAD_CPUTIME_ID",
44 "CLOCK_MONOTONIC_RAW",
45 "CLOCK_REALTIME_COARSE",
46 "CLOCK_MONOTONIC_COARSE",
48 "CLOCK_REALTIME_ALARM",
49 "CLOCK_BOOTTIME_ALARM",
55 * This function calls clock_getres in vdso and by system call
56 * with different values for clock_id.
60 * clock_id: CLOCK_REALTIME [PASS]
61 * clock_id: CLOCK_BOOTTIME [PASS]
62 * clock_id: CLOCK_TAI [PASS]
63 * clock_id: CLOCK_REALTIME_COARSE [PASS]
64 * clock_id: CLOCK_MONOTONIC [PASS]
65 * clock_id: CLOCK_MONOTONIC_RAW [PASS]
66 * clock_id: CLOCK_MONOTONIC_COARSE [PASS]
68 static inline int vdso_test_clock(unsigned int clock_id
)
72 printf("clock_id: %s", vdso_clock_name
[clock_id
]);
73 clock_getres(clock_id
, &x
);
74 syscall_clock_getres(clock_id
, &y
);
76 if ((x
.tv_sec
!= y
.tv_sec
) || (x
.tv_nsec
!= y
.tv_nsec
)) {
85 int main(int argc
, char **argv
)
92 ret
= vdso_test_clock(CLOCK_REALTIME
);
96 ret
+= vdso_test_clock(CLOCK_BOOTTIME
);
100 ret
+= vdso_test_clock(CLOCK_TAI
);
103 #ifdef CLOCK_REALTIME_COARSE
104 ret
+= vdso_test_clock(CLOCK_REALTIME_COARSE
);
107 #ifdef CLOCK_MONOTONIC
108 ret
+= vdso_test_clock(CLOCK_MONOTONIC
);
111 #ifdef CLOCK_MONOTONIC_RAW
112 ret
+= vdso_test_clock(CLOCK_MONOTONIC_RAW
);
115 #ifdef CLOCK_MONOTONIC_COARSE
116 ret
+= vdso_test_clock(CLOCK_MONOTONIC_COARSE
);