1 /* 2 * File: common_timers.h 3 * 4 * Keep all the common defines/checks for the timer tests here 5 */ 6 7 #ifndef LAPI_COMMON_TIMERS_H__ 8 #define LAPI_COMMON_TIMERS_H__ 9 10 #include "config.h" 11 #include "lapi/syscalls.h" 12 #include "lapi/posix_clocks.h" 13 14 #ifndef NSEC_PER_SEC 15 #define NSEC_PER_SEC (1000000000LL) 16 #endif 17 18 static const clock_t clock_list[] = { 19 CLOCK_REALTIME, 20 CLOCK_MONOTONIC, 21 CLOCK_PROCESS_CPUTIME_ID, 22 CLOCK_THREAD_CPUTIME_ID, 23 CLOCK_BOOTTIME, 24 CLOCK_BOOTTIME_ALARM, 25 CLOCK_REALTIME_ALARM, 26 CLOCK_TAI, 27 }; 28 /* CLOCKS_DEFINED is the number of clock sources defined for sure */ 29 #define CLOCKS_DEFINED (sizeof(clock_list) / sizeof(*clock_list)) 30 /* MAX_CLOCKS is the maximum number of clock sources supported by kernel */ 31 #define MAX_CLOCKS 16 32 33 #define CLOCK_TO_STR(def_name) \ 34 case def_name: \ 35 return #def_name; 36 get_clock_str(const int clock_id)37static inline const char *get_clock_str(const int clock_id) 38 { 39 switch (clock_id) { 40 CLOCK_TO_STR(CLOCK_REALTIME); 41 CLOCK_TO_STR(CLOCK_MONOTONIC); 42 CLOCK_TO_STR(CLOCK_PROCESS_CPUTIME_ID); 43 CLOCK_TO_STR(CLOCK_THREAD_CPUTIME_ID); 44 CLOCK_TO_STR(CLOCK_BOOTTIME); 45 CLOCK_TO_STR(CLOCK_BOOTTIME_ALARM); 46 CLOCK_TO_STR(CLOCK_REALTIME_ALARM); 47 CLOCK_TO_STR(CLOCK_TAI); 48 default: 49 return "CLOCK_!?!?!?"; 50 } 51 } 52 possibly_unsupported(clock_t clock)53static inline int possibly_unsupported(clock_t clock) 54 { 55 switch (clock) { 56 case CLOCK_BOOTTIME: 57 case CLOCK_BOOTTIME_ALARM: 58 case CLOCK_REALTIME_ALARM: 59 case CLOCK_TAI: 60 return 1; 61 default: 62 return 0; 63 } 64 } 65 66 #include "lapi/syscalls.h" 67 68 #include <time.h> 69 #include <unistd.h> 70 71 /* timer_t in kernel(int) is different from Glibc definition(void*). 72 * Use the kernel definition for syscall tests 73 */ 74 typedef int kernel_timer_t; 75 76 #endif /* LAPI_COMMON_TIMERS_H__ */ 77