41 #ifndef _systemcalls_cpp
42 #define _systemcalls_cpp
54 #ifdef _MEZZ_THREAD_WIN32_
57 #ifdef _MEZZ_THREAD_APPLE_
58 #include <sys/sysctl.h>
69 {
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()).count(); }
71 #ifdef _MEZZ_THREAD_WIN32_
78 LARGE_INTEGER frequency;
81 { QueryPerformanceFrequency(&frequency); }
85 LARGE_INTEGER Current;
86 QueryPerformanceCounter(&Current);
87 return MaxInt(Current.QuadPart * (1000000.0 / frequency.QuadPart));
95 {
return ATimer.GetTimeStamp(); }
98 {
return Whole(ATimer.frequency.QuadPart/1000); }
104 gettimeofday(&Now, NULL);
105 return (Now.tv_sec * 1000000) + Now.tv_usec;
116 #ifdef _MEZZ_THREAD_WIN32_
118 GetSystemInfo( &sysinfo );
120 return sysinfo.dwNumberOfProcessors;
122 return sysconf( _SC_NPROCESSORS_ONLN );
128 #ifdef _MEZZ_THREAD_WIN32_
131 DWORD buffer_size = 0;
133 SYSTEM_LOGICAL_PROCESSOR_INFORMATION * buffer = 0;
135 GetLogicalProcessorInformation(0, &buffer_size);
136 buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION *)malloc(buffer_size);
137 GetLogicalProcessorInformation(&buffer[0], &buffer_size);
139 for (i = 0; i != buffer_size /
sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ++i) {
140 if (buffer[i].Relationship == RelationCache && buffer[i].Cache.Level == 1) {
141 Size = buffer[i].Cache.Size;
154 #ifdef _MEZZ_THREAD_APPLE_
156 Whole CSSize =
sizeof(CacheSize);
157 if(0==sysctlbyname(
"hw.l4icachesize", &CacheSize, &CSSize, NULL, 0))
161 if(0==sysctlbyname(
"hw.l3icachesize", &CacheSize, &CSSize, NULL, 0))
165 if(0==sysctlbyname(
"hw.l2icachesize", &CacheSize, &CSSize, NULL, 0))
169 if(0==sysctlbyname(
"hw.l1icachesize", &CacheSize, &CSSize, NULL, 0))
179 Whole CSSize = sysconf(_SC_LEVEL4_CACHE_SIZE);
182 CSSize = sysconf(_SC_LEVEL3_CACHE_SIZE);
185 CSSize = sysconf(_SC_LEVEL2_CACHE_SIZE);
187 { CSSize = sysconf(_SC_LEVEL1_DCACHE_SIZE); }
197 #ifdef _MEZZ_THREAD_WIN32_
200 DWORD buffer_size = 0;
202 SYSTEM_LOGICAL_PROCESSOR_INFORMATION * buffer = 0;
204 GetLogicalProcessorInformation(0, &buffer_size);
205 buffer = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION *)malloc(buffer_size);
206 GetLogicalProcessorInformation(&buffer[0], &buffer_size);
208 for (i = 0; i != buffer_size /
sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ++i)
210 if (buffer[i].Relationship == RelationCache && buffer[i].Cache.Level == 1)
212 Size = buffer[i].Cache.LineSize;
225 #ifdef _MEZZ_THREAD_APPLE_
226 size_t line_size = 0;
227 size_t sizeof_line_size =
sizeof(line_size);
228 sysctlbyname(
"hw.cachelinesize", &line_size, &sizeof_line_size, 0, 0);
231 Whole Size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
234 Size = sysconf(_SC_LEVEL2_CACHE_LINESIZE);
237 Size = sysconf(_SC_LEVEL3_CACHE_LINESIZE);
239 { Size = sysconf(_SC_LEVEL4_CACHE_LINESIZE); }