-
Notifications
You must be signed in to change notification settings - Fork 8
/
plasma_sysconf.c
106 lines (94 loc) · 3.41 KB
/
plasma_sysconf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* plasma_sysconf - system configuration info
*
* Copyright (c) 2013, Glue Logic LLC. All rights reserved. code()gluelogic.com
*
* This file is part of plasma.
*
* plasma is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* plasma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with plasma. If not, see <http://www.gnu.org/licenses/>.
*/
/* _AIX requires minimum standards level for _SC_PAGESIZE define */
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 500
#endif
#define PLASMA_FEATURE_DISABLE_WIN32_FULLHDRS
#include "plasma_sysconf.h"
#include "plasma_feature.h"
#ifdef PLASMA_FEATURE_POSIX
#include <unistd.h>
/* FUTURE: might make interfaces into macros which simply call sysconf() */
#elif defined(_WIN32)
#include <windows.h>
/* SYSTEM_INFO structure
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958%28v=vs.85%29.aspx
* GetLogicalProcessorInformation (contains more complex code example)
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms683194%28v=vs.85%29.aspx */
#endif
/* plasma_sysconf_nprocessors_onln()
* sysconf _SC_NPROCESSORS_ONLN and _SC_NPROCESSORS_CONF are not required by
* standards, but are provided on numerous unix platforms and documented as
* optional by Open Group.
* http://www.opengroup.org/austin/docs/austin_512.txt
* http://austingroupbugs.net/view.php?id=339
* http://www.mail-archive.com/[email protected]/msg01435.html
* Implemented by AIX/Tru64/Solaris/Linux/FreeBSD/NetBSD/OpenBSD/Darwin.
* https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/sysconf.3.html
* http://stackoverflow.com/questions/4586405/get-number-of-cpus-in-linux-using-c
*/
#ifdef _AIX /*(AIX requires _ALL_SOURCE defined for this definition)*/
#define _SC_NPROCESSORS_ONLN 72
#endif
/*(Mac OSX requires _DARWIN_C_SOURCE defined for this definition)*/
#if defined(__APPLE__) && defined(__MACH__)
#define _SC_NPROCESSORS_ONLN 58
#endif
long
plasma_sysconf_nprocessors_onln (void)
{
long nprocs_onln;
#ifdef _SC_NPROCESSORS_ONLN
nprocs_onln = sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(_WIN32)
SYSTEM_INFO info;
GetSystemInfo(&info);
nprocs_onln = info.dwNumberOfProcessors;
#else
#error "sysconf(_SC_NPROCESSORS_ONLN) not implemented"
#endif
return nprocs_onln;
}
long
plasma_sysconf_pagesize (void)
{
long pagesize;
#ifdef _SC_PAGESIZE
pagesize = sysconf(_SC_PAGESIZE);
#elif defined(_WIN32)
/* http://msdn.microsoft.com/en-us/library/windows/desktop/cc644950%28v=vs.85%29.aspx
* Page size is 4,096 bytes on x64 and x86 or 8,192 bytes for Itanium-based systems.
*/
#if defined(_M_AMD64) || defined(_M_IX86)
pagesize = 4096;
#elif defined(_M_IA64)
pagesize = 8192;
#else
SYSTEM_INFO info;
GetSystemInfo(&info);
pagesize = info.dwPageSize;
#endif
#else
#error "sysconf(_SC_PAGESIZE) not implemented"
#endif
return pagesize;
}