]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/inc/libbenchmark/libbenchmark_porting_abstraction_layer_operating_system.h
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libbenchmark / inc / libbenchmark / libbenchmark_porting_abstraction_layer_operating_system.h
1 /****************************************************************************/
2 #if( defined _WIN32 && !defined KERNEL_MODE && NTDDI_VERSION >= NTDDI_WINXP )
3
4   #ifdef LIBBENCHMARK_PAL_OPERATING_SYSTEM
5     #error More than one porting abstraction layer matches current platform. in "libbenchmark_porting_abstraction_layer_operating_system.h".
6   #endif
7
8   #define LIBBENCHMARK_PAL_OPERATING_SYSTEM
9
10   #define LIBBENCHMARK_PAL_OS_STRING  "Windows"
11
12   #include <windows.h>
13
14   #define LIBBENCHMARK_PAL_TIME_UNITS_PER_SECOND( pointer_to_time_units_per_second )  QueryPerformanceFrequency( (LARGE_INTEGER *)(pointer_to_time_units_per_second) )
15
16   #define LIBBENCHMARK_PAL_GET_HIGHRES_TIME( pointer_to_time )                        QueryPerformanceCounter( (LARGE_INTEGER *)(pointer_to_time) );
17
18 #endif
19
20
21
22
23
24 /****************************************************************************/
25 #if( defined _WIN32 && defined KERNEL_MODE && NTDDI_VERSION >= NTDDI_WINXP )
26
27   #ifdef LIBBENCHMARK_PAL_OPERATING_SYSTEM
28     #error More than one porting abstraction layer matches current platform. in "libbenchmark_porting_abstraction_layer_operating_system.h".
29   #endif
30
31   #define LIBBENCHMARK_PAL_OPERATING_SYSTEM
32
33   #define LIBBENCHMARK_PAL_OS_STRING  "Windows"
34
35   #include <wdm.h>
36
37   #define LIBBENCHMARK_PAL_TIME_UNITS_PER_SECOND( pointer_to_time_units_per_second )  KeQueryPerformanceCounter( (LARGE_INTEGER *)(pointer_to_time_units_per_second) )
38
39   #define LIBBENCHMARK_PAL_GET_HIGHRES_TIME( pointer_to_time )                        *( (LARGE_INTEGER *) pointer_to_time ) = KeQueryPerformanceCounter( NULL );
40
41 #endif
42
43
44
45
46
47 /****************************************************************************/
48 #if( defined __linux__ && !defined KERNEL_MODE )
49
50   #ifdef LIBBENCHMARK_PAL_OPERATING_SYSTEM
51     #error More than one porting abstraction layer matches current platform. in "libbenchmark_porting_abstraction_layer_operating_system.h".
52   #endif
53
54   #define LIBBENCHMARK_PAL_OPERATING_SYSTEM
55
56   #define LIBBENCHMARK_PAL_OS_STRING  "Linux"
57
58   #define _GNU_SOURCE
59
60   #include <unistd.h>
61   #include <stdarg.h>
62   #include <stdio.h>
63
64   #if( defined _POSIX_THREADS && _POSIX_TIMERS >= 0 && _POSIX_MONOTONIC_CLOCK >= 0 )
65     #define LIBBENCHMARK_PAL_TIME_UNITS_PER_SECOND( pointer_to_time_units_per_second )  *(pointer_to_time_units_per_second) = NUMBER_OF_NANOSECONDS_IN_ONE_SECOND
66
67     #define LIBBENCHMARK_PAL_GET_HIGHRES_TIME( pointer_to_time )                          \
68     {                                                                                     \
69       struct timespec tp;                                                                 \
70       clock_gettime( CLOCK_MONOTONIC_RAW, &tp );                                          \
71       *(pointer_to_time) = tp.tv_sec * NUMBER_OF_NANOSECONDS_IN_ONE_SECOND + tp.tv_nsec;  \
72     }
73   #else
74     #error Linux without high resolution timers.
75   #endif
76
77 #endif
78
79
80
81
82
83 /****************************************************************************/
84 #if( defined __linux__ && defined KERNEL_MODE )
85
86   #ifdef LIBBENCHMARK_PAL_OPERATING_SYSTEM
87     #error More than one porting abstraction layer matches current platform. in "libbenchmark_porting_abstraction_layer_operating_system.h".
88   #endif
89
90   #define LIBBENCHMARK_PAL_OPERATING_SYSTEM
91
92   #define LIBBENCHMARK_PAL_OS_STRING  "Linux"
93
94   #define _GNU_SOURCE
95
96   #include <linux/module.h>
97
98   /* TRD : not clear to me how to obtain high res freq and current count, in Linux kernel
99            it doesn't matter right now because it becamse clear earlier there's no wait-for-thread-to-complete
100            function either, which breaks the lfds thread abstraction, and until I sort that out, benchmark
101            can't run anyway
102   */
103
104   #error No high resolution time abstraction for the Linux kernel.
105
106 #endif
107
108
109
110
111
112 /****************************************************************************/
113 #if( !defined LIBBENCHMARK_PAL_OPERATING_SYSTEM )
114
115   #error No matching porting abstraction layer in "libbenchmark_porting_abstraction_layer_operating_system.h".
116
117 #endif
118