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 #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 public:
127 
129  static void* alignedMemoryAlloc16(size_t size) {
130 #ifdef OGDF_SYSTEM_WINDOWS
131 # ifdef __MINGW64__
132  return __mingw_aligned_malloc(size, 16);
133 # else
134  return _aligned_malloc(size, 16);
135 # endif
136 #elif defined(OGDF_SYSTEM_OSX)
137  // malloc returns 16 byte aligned memory on OS X.
138  return malloc(size);
139 #else
140  return memalign(16, size);
141 #endif
142  }
143 
144  static void alignedMemoryFree(void* p) {
145 #ifdef OGDF_SYSTEM_WINDOWS
146 # ifdef __MINGW64__
147  __mingw_aligned_free(p);
148 # else
149  _aligned_free(p);
150 # endif
151 #else
152  free(p);
153 #endif
154  }
155 
157  static int pageSize() { return s_pageSize; }
158 
160  static long long physicalMemory();
161 
163  static long long availablePhysicalMemory();
164 
166  static size_t memoryUsedByProcess();
167 
168 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
169  static size_t peakMemoryUsedByProcess();
171 #endif
172 
174 
184  static size_t memoryAllocatedByMemoryManager();
185 
187  static size_t memoryInGlobalFreeListOfMemoryManager();
188 
190  static size_t memoryInThreadFreeListOfMemoryManager();
191 
193 
197  static size_t memoryAllocatedByMalloc();
198 
200 
204  static size_t memoryInFreelistOfMalloc();
205 
206 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
207 
214 
217  static void getHPCounter(int64_t& counter);
218 
220  static double elapsedSeconds(const int64_t& startCounter, const int64_t& endCounter);
221 #endif
222 
224 
230  static int64_t usedRealTime(int64_t& t);
231 
233 
237  static int64_t realTime();
238 
239 
241 
244 
247  static int getProcessID();
248 
250 
256 
259  static int cpuFeatures() { return s_cpuFeatures; }
260 
262  static bool cpuSupports(CPUFeature feature) {
263  return (s_cpuFeatures & (1 << static_cast<int>(feature))) != 0;
264  }
265 
267  static int cacheSizeKBytes() { return s_cacheSize; }
268 
270  static int cacheLineBytes() { return s_cacheLine; }
271 
273  static int numberOfProcessors() { return s_numberOfProcessors; }
274 
276 
277 private:
278  static unsigned int s_cpuFeatures;
279  static int s_cacheSize;
280  static int s_cacheLine;
281  static int s_numberOfProcessors;
282  static int s_pageSize;
283 
284 #if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
285  static int64_t s_HPCounterFrequency;
286 #endif
287 
288 public:
290  static void init();
291 };
292 
293 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::System::s_numberOfProcessors
static int s_numberOfProcessors
Number of processors (cores) available.
Definition: System.h:281
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:94
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:144
ogdf::System::s_cpuFeatures
static unsigned int s_cpuFeatures
Supported CPU features.
Definition: System.h:278
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:76
ogdf::System::cacheSizeKBytes
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition: System.h:267
ogdf::System::pageSize
static int pageSize()
Returns the page size of virtual memory (in bytes).
Definition: System.h:157
ogdf::System::alignedMemoryAlloc16
static void * alignedMemoryAlloc16(size_t size)
Definition: System.h:129
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:285
ogdf::System::cacheLineBytes
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition: System.h:270
ogdf::CPUFeatureMask::VMX
@ VMX
Virtual Machine Extensions.
ogdf::graphics::init
void init()
Definition: graphics.h:446
ogdf::System::s_pageSize
static int s_pageSize
The page size of virtual memory.
Definition: System.h:282
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:121
ogdf::System::cpuSupports
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition: System.h:262
ogdf::System::s_cacheSize
static int s_cacheSize
Cache size in KBytes.
Definition: System.h:279
ogdf::System::s_cacheLine
static int s_cacheLine
Bytes in a cache line.
Definition: System.h:280
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:259
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:273
ogdf::CPUFeatureMask::MONITOR
@ MONITOR
Processor supports MONITOR/MWAIT instructions.