1 /* SPDX-License-Identifier: GPL-2.0 */ 2 3 #ifndef __CLOCK_HELPERS_H 4 #define __CLOCK_HELPERS_H 5 6 #include <sys/types.h> 7 #include <time.h> 8 9 #define MSEC_PER_SEC 1000LL 10 #define USEC_PER_MSEC 1000LL 11 #define NSEC_PER_USEC 1000LL 12 #define NSEC_PER_MSEC 1000000LL 13 #define USEC_PER_SEC 1000000LL 14 #define NSEC_PER_SEC 1000000000LL 15 #define PSEC_PER_SEC 1000000000000LL 16 #define FSEC_PER_SEC 1000000000000000LL 17 18 #ifndef CLOCK_AUX 19 #define CLOCK_AUX 16 20 #endif 21 22 #ifndef MAX_AUX_CLOCKS 23 #define MAX_AUX_CLOCKS 8 24 #endif 25 26 #ifndef CLOCK_AUX_LAST 27 #define CLOCK_AUX_LAST (CLOCK_AUX + MAX_AUX_CLOCKS - 1) 28 #endif 29 30 __attribute__((unused)) 31 static inline const char *clock_name(clockid_t clockid) 32 { 33 switch (clockid) { 34 case CLOCK_REALTIME: 35 return "CLOCK_REALTIME"; 36 case CLOCK_MONOTONIC: 37 return "CLOCK_MONOTONIC"; 38 case CLOCK_PROCESS_CPUTIME_ID: 39 return "CLOCK_PROCESS_CPUTIME_ID"; 40 case CLOCK_THREAD_CPUTIME_ID: 41 return "CLOCK_THREAD_CPUTIME_ID"; 42 case CLOCK_MONOTONIC_RAW: 43 return "CLOCK_MONOTONIC_RAW"; 44 case CLOCK_REALTIME_COARSE: 45 return "CLOCK_REALTIME_COARSE"; 46 case CLOCK_MONOTONIC_COARSE: 47 return "CLOCK_MONOTONIC_COARSE"; 48 case CLOCK_BOOTTIME: 49 return "CLOCK_BOOTTIME"; 50 case CLOCK_REALTIME_ALARM: 51 return "CLOCK_REALTIME_ALARM"; 52 case CLOCK_BOOTTIME_ALARM: 53 return "CLOCK_BOOTTIME_ALARM"; 54 case CLOCK_TAI: 55 return "CLOCK_TAI"; 56 case CLOCK_AUX + 0: 57 return "CLOCK_AUX0"; 58 case CLOCK_AUX + 1: 59 return "CLOCK_AUX1"; 60 case CLOCK_AUX + 2: 61 return "CLOCK_AUX2"; 62 case CLOCK_AUX + 3: 63 return "CLOCK_AUX3"; 64 case CLOCK_AUX + 4: 65 return "CLOCK_AUX4"; 66 case CLOCK_AUX + 5: 67 return "CLOCK_AUX5"; 68 case CLOCK_AUX + 6: 69 return "CLOCK_AUX6"; 70 case CLOCK_AUX + 7: 71 return "CLOCK_AUX7"; 72 }; 73 return "UNKNOWN_CLOCKID"; 74 } 75 76 #endif /* __CLOCK_HELPERS_H */ 77