Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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 
122 
123 public:
129 
130  static void *alignedMemoryAlloc16(size_t size) {
131 #ifdef OGDF_SYSTEM_WINDOWS
132 # ifdef __MINGW64__
133  return __mingw_aligned_malloc(size, 16);
134 # else
135  return _aligned_malloc(size, 16);
136 # endif
137 #elif defined(OGDF_SYSTEM_OSX)
138  // malloc returns 16 byte aligned memory on OS X.
139  return malloc(size);
140 #else
141  return memalign(16, size);
142 #endif
143  }
144 
145  static void alignedMemoryFree(void *p) {
146 #ifdef OGDF_SYSTEM_WINDOWS
147 # ifdef __MINGW64__
148  __mingw_aligned_free(p);
149 # else
150  _aligned_free(p);
151 # endif
152 #else
153  free(p);
154 #endif
155  }
156 
158  static int pageSize() { return s_pageSize; }
159 
161  static long long physicalMemory();
162 
164  static long long availablePhysicalMemory();
165 
167  static size_t memoryUsedByProcess();
168 
169 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
170  static size_t peakMemoryUsedByProcess();
172 #endif
173 
175 
185  static size_t memoryAllocatedByMemoryManager();
186 
188  static size_t memoryInGlobalFreeListOfMemoryManager();
189 
191  static size_t memoryInThreadFreeListOfMemoryManager();
192 
194 
198  static size_t memoryAllocatedByMalloc();
199 
201 
205  static size_t memoryInFreelistOfMalloc();
206 
207 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
208 
209 
216 
218  static void getHPCounter(int64_t &counter);
219 
221  static double elapsedSeconds(
222  const int64_t &startCounter,
223  const int64_t &endCounter);
224 #endif
225 
227 
233  static int64_t usedRealTime(int64_t &t);
234 
236 
240  static int64_t realTime();
241 
242 
244 
248 
250  static int getProcessID();
251 
253 
260 
262  static int cpuFeatures() { return s_cpuFeatures; }
263 
265  static bool cpuSupports(CPUFeature feature) {
266  return (s_cpuFeatures & (1 << static_cast<int>(feature))) != 0;
267  }
268 
270  static int cacheSizeKBytes() { return s_cacheSize; }
271 
273  static int cacheLineBytes() { return s_cacheLine; }
274 
276  static int numberOfProcessors() { return s_numberOfProcessors; }
277 
279 
280 private:
281  static unsigned int s_cpuFeatures;
282  static int s_cacheSize;
283  static int s_cacheLine;
284  static int s_numberOfProcessors;
285  static int s_pageSize;
286 
287 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
288  static int64_t s_HPCounterFrequency;
289 #endif
290 
291 public:
293  static void init();
294 };
295 
296 }
unsigned int operator|=(unsigned int &i, CPUFeatureMask fm)
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition: System.h:273
Streaming SIMD Extensions 3 (SSE3)
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition: System.h:270
static int pageSize()
Returns the page size of virtual memory (in bytes).
Definition: System.h:158
#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:288
Safer Mode Extensions.
void init()
Definition: graphics.h:472
Virtual Machine Extensions.
System specific functionality.
Definition: System.h:121
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:283
static unsigned int s_cpuFeatures
Supported CPU features.
Definition: System.h:281
static int cpuFeatures()
Returns the bit vector describing the CPU features supported on current system.
Definition: System.h:262
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:284
Enhanced Intel SpeedStep Technology.
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition: System.h:276
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:282
static void alignedMemoryFree(void *p)
Definition: System.h:145
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition: System.h:265
Streaming SIMD Extensions 4.1 (SSE4.1)
Intel MMX Technology.
static int s_pageSize
The page size of virtual memory.
Definition: System.h:285
The namespace for all OGDF objects.
static void * alignedMemoryAlloc16(size_t size)
Definition: System.h:130
Streaming SIMD Extensions (SSE)
Processor supports MONITOR/MWAIT instructions.