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