Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
68namespace ogdf {
69
71
78enum 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
96enum 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
110OGDF_EXPORT unsigned int operator|=(unsigned int& i, CPUFeatureMask fm);
111
113
124public:
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__)
172 static size_t peakMemoryUsedByProcess();
173#endif
174
176
187
190
193
195
199 static size_t memoryAllocatedByMalloc();
200
202
207
208#if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
210
217
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
247
249 static int getProcessID();
250
252
259
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
279private:
280 static unsigned int s_cpuFeatures;
281 static int s_cacheSize;
282 static int s_cacheLine;
284 static int s_pageSize;
285
286#if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
287 static int64_t s_HPCounterFrequency;
288#endif
289
290public:
292 static void init();
293};
294
295}
Basic declarations, included by all source files.
System specific functionality.
Definition System.h:123
static size_t memoryInGlobalFreeListOfMemoryManager()
Returns the amount of memory (in bytes) contained in the global free list of OGDF's memory manager.
static int getProcessID()
Returns the process ID of the current process.
static size_t memoryAllocatedByMalloc()
Returns the amount of memory (in bytes) allocated on the heap (e.g., with malloc).
static size_t peakMemoryUsedByProcess()
Returns the maximal amount of memory (in bytes) used by the process (Windows/Cygwin only).
static size_t memoryUsedByProcess()
Returns the amount of memory (in bytes) allocated by the process.
static void alignedMemoryFree(void *p)
Definition System.h:146
static int s_cacheLine
Bytes in a cache line.
Definition System.h:282
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition System.h:275
static size_t memoryInThreadFreeListOfMemoryManager()
Returns the amount of memory (in bytes) contained in the thread's free list of OGDF's memory manager.
static void init()
Static initilization routine (automatically called).
static int s_numberOfProcessors
Number of processors (cores) available.
Definition System.h:283
static int cpuFeatures()
Returns the bit vector describing the CPU features supported on current system.
Definition System.h:261
static void getHPCounter(int64_t &counter)
Returns the current value of the high-performance counter in counter.
static unsigned int s_cpuFeatures
Supported CPU features.
Definition System.h:280
static int s_pageSize
The page size of virtual memory.
Definition System.h:284
static int64_t usedRealTime(int64_t &t)
Returns the elapsed time (in milliseconds) between t and now.
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition System.h:272
static size_t memoryAllocatedByMemoryManager()
Returns the amount of memory (in bytes) allocated by OGDF's memory manager.
static int64_t realTime()
Returns the current time point of the real time wall clock.
static size_t memoryInFreelistOfMalloc()
Returns the amount of memory (in bytes) contained in free chunks on the heap.
static int64_t s_HPCounterFrequency
Frequency of high-performance counter.
Definition System.h:287
static long long availablePhysicalMemory()
Returns the size of available (free) physical memory (in bytes).
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition System.h:264
static long long physicalMemory()
Returns the total size of physical memory (in bytes).
static void * alignedMemoryAlloc16(size_t size)
Definition System.h:131
static int pageSize()
Returns the page size of virtual memory (in bytes).
Definition System.h:159
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition System.h:269
static double elapsedSeconds(const int64_t &startCounter, const int64_t &endCounter)
Returns the elapsed time (in seconds) between startCounter and endCounter.
static int s_cacheSize
Cache size in KBytes.
Definition System.h:281
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
CPUFeatureMask
Bit mask for CPU features.
Definition System.h:96
CPUFeature
Special features supported by a x86/x64 CPU.
Definition System.h:78
@ SSSE3
Supplemental Streaming SIMD Extensions 3 (SSSE3)
@ EST
Enhanced Intel SpeedStep Technology.
@ SSE4_2
Streaming SIMD Extensions 4.2 (SSE4.2)
@ MMX
Intel MMX Technology.
@ SSE
Streaming SIMD Extensions (SSE)
@ SSE4_1
Streaming SIMD Extensions 4.1 (SSE4.1)
@ VMX
Virtual Machine Extensions.
@ SSE3
Streaming SIMD Extensions 3 (SSE3)
@ SMX
Safer Mode Extensions.
@ SSE2
Streaming SIMD Extensions 2 (SSE2)
@ MONITOR
Processor supports MONITOR/MWAIT instructions.
The namespace for all OGDF objects.
unsigned int operator|=(unsigned int &i, CPUFeatureMask fm)