Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

System.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/basic.h>
36 
37 #include <cstdint>
38 #include <cstdlib>
39 #if defined(OGDF_SYSTEM_OSX)
40 # include <stdlib.h>
41 #elif defined(OGDF_SYSTEM_UNIX) || defined(__MINGW32__)
42 # include <malloc.h>
43 #endif
44 
45 // detect processor architecture we're compiling for
46 //
47 // OGDF_ARCH_X86 Intel / AMD x86 32-bit processors
48 // OGDF_ARCH_X64 Intel / AMD x86 64-bit processors
49 // OGDF_ARCH_IA64 Intel Itanium
50 // OGDF_ARCH_PPC PowerPC
51 // OGDF_ARCH_SPARC SUN SPARC
52 // OGDF_ARCH_SPARC_V9 SUN SPARC V9
53 
54 #if defined(_M_X64) || defined(__x86_64__)
55 # define OGDF_ARCH_X64
56 #elif defined(_M_IX86) || defined(__i386__)
57 # define OGDF_ARCH_X86
58 #elif defined(_M_IA64) || defined(__ia64__)
59 # define OGDF_ARCH_IA64
60 #elif defined(_M_MPPC) || defined(_M_PPC) || defined(__powerpc__)
61 # define OGDF_ARCH_PPC
62 #elif defined(__sparc__)
63 # define OGDF_ARCH_SPARC
64 #elif defined(__sparc_v9__)
65 # define OGDF_ARCH_SPARC_V9
66 #endif
67 
68 namespace ogdf {
69 
71 
78 enum class CPUFeature {
79  MMX,
80  SSE,
81  SSE2,
82  SSE3,
83  SSSE3,
84  SSE4_1,
85  SSE4_2,
86  VMX,
87  SMX,
88  EST,
89  MONITOR
90 };
91 
93 
96 enum class CPUFeatureMask : unsigned int {
97  MMX = 1 << static_cast<int>(CPUFeature::MMX),
98  SSE = 1 << static_cast<int>(CPUFeature::SSE),
99  SSE2 = 1 << static_cast<int>(CPUFeature::SSE2),
100  SSE3 = 1 << static_cast<int>(CPUFeature::SSE3),
101  SSSE3 = 1 << static_cast<int>(CPUFeature::SSSE3),
102  SSE4_1 = 1 << static_cast<int>(CPUFeature::SSE4_1),
103  SSE4_2 = 1 << static_cast<int>(CPUFeature::SSE4_2),
104  VMX = 1 << static_cast<int>(CPUFeature::VMX),
105  SMX = 1 << static_cast<int>(CPUFeature::SMX),
106  EST = 1 << static_cast<int>(CPUFeature::EST),
107  MONITOR = 1 << static_cast<int>(CPUFeature::MONITOR)
108 };
109 
110 OGDF_EXPORT unsigned int operator|=(unsigned int& i, CPUFeatureMask fm);
111 
113 
124 public:
129 
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 
216 
219  static void getHPCounter(int64_t& counter);
220 
222  static double elapsedSeconds(const int64_t& startCounter, const int64_t& endCounter);
223 #endif
224 
226 
232  static int64_t usedRealTime(int64_t& t);
233 
235 
239  static int64_t realTime();
240 
241 
243 
246 
249  static int getProcessID();
250 
252 
258 
261  static int cpuFeatures() { return s_cpuFeatures; }
262 
264  static bool cpuSupports(CPUFeature feature) {
265  return (s_cpuFeatures & (1 << static_cast<int>(feature))) != 0;
266  }
267 
269  static int cacheSizeKBytes() { return s_cacheSize; }
270 
272  static int cacheLineBytes() { return s_cacheLine; }
273 
275  static int numberOfProcessors() { return s_numberOfProcessors; }
276 
278 
279 private:
280  static unsigned int s_cpuFeatures;
281  static int s_cacheSize;
282  static int s_cacheLine;
283  static int s_numberOfProcessors;
284  static int s_pageSize;
285 
286 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
287  static int64_t s_HPCounterFrequency;
288 #endif
289 
290 public:
292  static void init();
293 };
294 
295 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::System::s_numberOfProcessors
static int s_numberOfProcessors
Number of processors (cores) available.
Definition: System.h:283
ogdf::CPUFeatureMask::MMX
@ MMX
Intel MMX Technology.
ogdf::CPUFeatureMask::SSE4_2
@ SSE4_2
Streaming SIMD Extensions 4.2 (SSE4.2)
ogdf::CPUFeatureMask
CPUFeatureMask
Bit mask for CPU features.
Definition: System.h:96
ogdf::CPUFeatureMask::SSSE3
@ SSSE3
Supplemental Streaming SIMD Extensions 3 (SSSE3)
ogdf::CPUFeatureMask::SSE4_1
@ SSE4_1
Streaming SIMD Extensions 4.1 (SSE4.1)
ogdf::CPUFeature::SSSE3
@ SSSE3
Supplemental Streaming SIMD Extensions 3 (SSSE3)
ogdf::CPUFeature::EST
@ EST
Enhanced Intel SpeedStep Technology.
ogdf::CPUFeatureMask::SSE3
@ SSE3
Streaming SIMD Extensions 3 (SSE3)
ogdf::CPUFeature::SSE4_2
@ SSE4_2
Streaming SIMD Extensions 4.2 (SSE4.2)
ogdf::CPUFeature::SMX
@ SMX
Safer Mode Extensions.
ogdf::CPUFeature::VMX
@ VMX
Virtual Machine Extensions.
ogdf::CPUFeature::MONITOR
@ MONITOR
Processor supports MONITOR/MWAIT instructions.
ogdf::System::alignedMemoryFree
static void alignedMemoryFree(void *p)
Definition: System.h:146
ogdf::System::s_cpuFeatures
static unsigned int s_cpuFeatures
Supported CPU features.
Definition: System.h:280
ogdf::CPUFeature::SSE4_1
@ SSE4_1
Streaming SIMD Extensions 4.1 (SSE4.1)
ogdf::CPUFeature::SSE3
@ SSE3
Streaming SIMD Extensions 3 (SSE3)
ogdf::operator|=
unsigned int operator|=(unsigned int &i, CPUFeatureMask fm)
ogdf::CPUFeature
CPUFeature
Special features supported by a x86/x64 CPU.
Definition: System.h:78
ogdf::System::cacheSizeKBytes
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition: System.h:269
ogdf::System::pageSize
static int pageSize()
Returns the page size of virtual memory (in bytes).
Definition: System.h:159
ogdf::System::alignedMemoryAlloc16
static void * alignedMemoryAlloc16(size_t size)
Definition: System.h:131
ogdf::CPUFeature::SSE2
@ SSE2
Streaming SIMD Extensions 2 (SSE2)
ogdf::CPUFeatureMask::SMX
@ SMX
Safer Mode Extensions.
ogdf::System::s_HPCounterFrequency
static int64_t s_HPCounterFrequency
Frequency of high-performance counter.
Definition: System.h:287
ogdf::System::cacheLineBytes
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition: System.h:272
ogdf::CPUFeatureMask::VMX
@ VMX
Virtual Machine Extensions.
ogdf::graphics::init
void init()
Definition: graphics.h:450
ogdf::System::s_pageSize
static int s_pageSize
The page size of virtual memory.
Definition: System.h:284
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::CPUFeatureMask::SSE
@ SSE
Streaming SIMD Extensions (SSE)
ogdf::CPUFeatureMask::SSE2
@ SSE2
Streaming SIMD Extensions 2 (SSE2)
ogdf::CPUFeature::MMX
@ MMX
Intel MMX Technology.
ogdf::System
System specific functionality.
Definition: System.h:123
ogdf::System::cpuSupports
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition: System.h:264
ogdf::System::s_cacheSize
static int s_cacheSize
Cache size in KBytes.
Definition: System.h:281
ogdf::System::s_cacheLine
static int s_cacheLine
Bytes in a cache line.
Definition: System.h:282
ogdf::CPUFeature::SSE
@ SSE
Streaming SIMD Extensions (SSE)
ogdf::System::cpuFeatures
static int cpuFeatures()
Returns the bit vector describing the CPU features supported on current system.
Definition: System.h:261
ogdf::CPUFeatureMask::EST
@ EST
Enhanced Intel SpeedStep Technology.
ogdf::System::numberOfProcessors
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition: System.h:275
ogdf::CPUFeatureMask::MONITOR
@ MONITOR
Processor supports MONITOR/MWAIT instructions.