Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

System.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/basic.h>
36 
37 #if defined(OGDF_SYSTEM_OSX)
38 #include <stdlib.h>
39 #elif defined(OGDF_SYSTEM_UNIX) || defined(__MINGW32__)
40 #include <malloc.h>
41 #endif
42 
43 // detect processor architecture we're compiling for
44 //
45 // OGDF_ARCH_X86 Intel / AMD x86 32-bit processors
46 // OGDF_ARCH_X64 Intel / AMD x86 64-bit processors
47 // OGDF_ARCH_IA64 Intel Itanium
48 // OGDF_ARCH_PPC PowerPC
49 // OGDF_ARCH_SPARC SUN SPARC
50 // OGDF_ARCH_SPARC_V9 SUN SPARC V9
51 
52 #if defined(_M_X64) || defined(__x86_64__)
53 #define OGDF_ARCH_X64
54 #elif defined(_M_IX86) || defined(__i386__)
55 #define OGDF_ARCH_X86
56 #elif defined(_M_IA64) || defined(__ia64__)
57 #define OGDF_ARCH_IA64
58 #elif defined(_M_MPPC) || defined(_M_PPC) || defined(__powerpc__)
59 #define OGDF_ARCH_PPC
60 #elif defined(__sparc__)
61 #define OGDF_ARCH_SPARC
62 #elif defined(__sparc_v9__)
63 #define OGDF_ARCH_SPARC_V9
64 #endif
65 
66 namespace ogdf {
67 
69 
76 enum class CPUFeature {
77  MMX,
78  SSE,
79  SSE2,
80  SSE3,
81  SSSE3,
82  SSE4_1,
83  SSE4_2,
84  VMX,
85  SMX,
86  EST,
87  MONITOR
88 };
89 
91 
94 enum class CPUFeatureMask : unsigned int {
95  MMX = 1 << static_cast<int>(CPUFeature::MMX),
96  SSE = 1 << static_cast<int>(CPUFeature::SSE),
97  SSE2 = 1 << static_cast<int>(CPUFeature::SSE2),
98  SSE3 = 1 << static_cast<int>(CPUFeature::SSE3),
99  SSSE3 = 1 << static_cast<int>(CPUFeature::SSSE3),
100  SSE4_1 = 1 << static_cast<int>(CPUFeature::SSE4_1),
101  SSE4_2 = 1 << static_cast<int>(CPUFeature::SSE4_2),
102  VMX = 1 << static_cast<int>(CPUFeature::VMX),
103  SMX = 1 << static_cast<int>(CPUFeature::SMX),
104  EST = 1 << static_cast<int>(CPUFeature::EST),
105  MONITOR = 1 << static_cast<int>(CPUFeature::MONITOR)
106 };
107 
108 OGDF_EXPORT unsigned int operator|=(unsigned int &i, CPUFeatureMask fm);
109 
111 
123 
124 public:
130 
131  static void *alignedMemoryAlloc16(size_t size) {
132 #ifdef OGDF_SYSTEM_WINDOWS
133 # ifdef __MINGW64__
134  return __mingw_aligned_malloc(size, 16);
135 # else
136  return _aligned_malloc(size, 16);
137 # endif
138 #elif defined(OGDF_SYSTEM_OSX)
139  // malloc returns 16 byte aligned memory on OS X.
140  return malloc(size);
141 #else
142  return memalign(16, size);
143 #endif
144  }
145 
146  static void alignedMemoryFree(void *p) {
147 #ifdef OGDF_SYSTEM_WINDOWS
148 # ifdef __MINGW64__
149  __mingw_aligned_free(p);
150 # else
151  _aligned_free(p);
152 # endif
153 #else
154  free(p);
155 #endif
156  }
157 
159  static int pageSize() { return s_pageSize; }
160 
162  static long long physicalMemory();
163 
165  static long long availablePhysicalMemory();
166 
168  static size_t memoryUsedByProcess();
169 
170 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
171  static size_t peakMemoryUsedByProcess();
173 #endif
174 
176 
186  static size_t memoryAllocatedByMemoryManager();
187 
189  static size_t memoryInGlobalFreeListOfMemoryManager();
190 
192  static size_t memoryInThreadFreeListOfMemoryManager();
193 
195 
199  static size_t memoryAllocatedByMalloc();
200 
202 
206  static size_t memoryInFreelistOfMalloc();
207 
208 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
209 
210 
217 
219  static void getHPCounter(int64_t &counter);
220 
222  static double elapsedSeconds(
223  const int64_t &startCounter,
224  const int64_t &endCounter);
225 #endif
226 
228 
234  static int64_t usedRealTime(int64_t &t);
235 
237 
241  static int64_t realTime();
242 
243 
245 
249 
251  static int getProcessID();
252 
254 
261 
263  static int cpuFeatures() { return s_cpuFeatures; }
264 
266  static bool cpuSupports(CPUFeature feature) {
267  return (s_cpuFeatures & (1 << static_cast<int>(feature))) != 0;
268  }
269 
271  static int cacheSizeKBytes() { return s_cacheSize; }
272 
274  static int cacheLineBytes() { return s_cacheLine; }
275 
277  static int numberOfProcessors() { return s_numberOfProcessors; }
278 
280 
281 private:
282  static unsigned int s_cpuFeatures;
283  static int s_cacheSize;
284  static int s_cacheLine;
285  static int s_numberOfProcessors;
286  static int s_pageSize;
287 
288 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
289  static int64_t s_HPCounterFrequency;
290 #endif
291 
292 public:
294  static void init();
295 };
296 
297 
298 } // end namespace ogdf
unsigned int operator|=(unsigned int &i, CPUFeatureMask fm)
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition: System.h:274
Streaming SIMD Extensions 3 (SSE3)
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition: System.h:271
static int pageSize()
Returns the page size of virtual memory (in bytes).
Definition: System.h:159
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
static int64_t s_HPCounterFrequency
Frequency of high-performance counter.
Definition: System.h:289
Safer Mode Extensions.
Virtual Machine Extensions.
System specific functionality.
Definition: System.h:122
CPUFeature
Special features supported by a x86/x64 CPU.
Definition: System.h:76
static int s_cacheLine
Bytes in a cache line.
Definition: System.h:284
static unsigned int s_cpuFeatures
Supported CPU features.
Definition: System.h:282
static int cpuFeatures()
Returns the bit vector describing the CPU features supported on current system.
Definition: System.h:263
CPUFeatureMask
Bit mask for CPU features.
Definition: System.h:94
Supplemental Streaming SIMD Extensions 3 (SSSE3)
static int s_numberOfProcessors
Number of processors (cores) available.
Definition: System.h:285
Enhanced Intel SpeedStep Technology.
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition: System.h:277
Streaming SIMD Extensions 2 (SSE2)
Streaming SIMD Extensions 4.2 (SSE4.2)
Basic declarations, included by all source files.
static int s_cacheSize
Cache size in KBytes.
Definition: System.h:283
static void alignedMemoryFree(void *p)
Definition: System.h:146
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition: System.h:266
Streaming SIMD Extensions 4.1 (SSE4.1)
Intel MMX Technology.
static int s_pageSize
The page size of virtual memory.
Definition: System.h:286
The namespace for all OGDF objects.
static void * alignedMemoryAlloc16(size_t size)
Definition: System.h:131
Streaming SIMD Extensions (SSE)
Processor supports MONITOR/MWAIT instructions.