3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
11 #include <sys/param.h>
12 #include <sys/sysinfo.h>
25 get_page_size (int in
)
27 return wincap
.allocation_granularity ();
31 __nt_query_system (PSYSTEM_BASIC_INFORMATION psbi
)
35 status
= NtQuerySystemInformation (SystemBasicInformation
, (PVOID
) psbi
,
37 return NT_SUCCESS (status
);
40 #define add_size(p,s) ((p) = ((__typeof__(p))((PBYTE)(p)+(s))))
43 get_nproc_values (int in
)
46 PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX lpi
, plpi
;
47 DWORD lpi_size
= NT_MAX_PATH
;
50 lpi
= (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX
) tp
.c_get ();
51 if (!GetLogicalProcessorInformationEx (RelationGroup
, lpi
, &lpi_size
))
54 for (DWORD size
= lpi_size
; size
> 0;
55 size
-= plpi
->Size
, add_size (plpi
, plpi
->Size
))
56 if (plpi
->Relationship
== RelationGroup
)
58 for (WORD i
= 0; i
< plpi
->Group
.MaximumGroupCount
; ++i
)
61 case _SC_NPROCESSORS_CONF
:
62 cnt
+= plpi
->Group
.GroupInfo
[0].MaximumProcessorCount
;
64 case _SC_NPROCESSORS_ONLN
:
65 cnt
+= plpi
->Group
.GroupInfo
[0].ActiveProcessorCount
;
73 get_phys_pages (int in
)
75 SYSTEM_BASIC_INFORMATION sbi
;
77 if (!__nt_query_system (&sbi
))
79 return sbi
.NumberOfPhysicalPages
80 / (wincap
.allocation_granularity () / wincap
.page_size ());
87 SYSTEM_PERFORMANCE_INFORMATION spi
;
89 status
= NtQuerySystemInformation (SystemPerformanceInformation
,
90 (PVOID
) &spi
, sizeof spi
, NULL
);
91 if (!NT_SUCCESS (status
))
93 __seterrno_from_nt_status (status
);
94 debug_printf ("NtQuerySystemInformation: status %y, %E", status
);
97 return spi
.AvailablePages
98 / (wincap
.allocation_granularity () / wincap
.page_size ());
111 struct cpuid2_cache_desc
120 static const cpuid2_cache_desc cpuid2_cache_descriptor
[] =
122 { 0x06, Level1I
, 8, 4, 32 },
123 { 0x08, Level1I
, 16, 4, 32 },
124 { 0x09, Level1I
, 32, 4, 64 },
125 { 0x0a, Level1D
, 8, 2, 32 },
126 { 0x0c, Level1D
, 16, 4, 32 },
127 { 0x0d, Level1D
, 16, 4, 64 },
128 { 0x0e, Level1D
, 24, 6, 64 },
129 { 0x21, Level2
, 256, 8, 64 },
130 { 0x22, Level3
, 512, 4, 64 },
131 { 0x23, Level3
, 1024, 8, 64 },
132 { 0x25, Level3
, 2048, 8, 64 },
133 { 0x29, Level3
, 4096, 8, 64 },
134 { 0x2c, Level1D
, 32, 8, 64 },
135 { 0x30, Level1I
, 32, 8, 64 },
136 { 0x39, Level2
, 128, 4, 64 },
137 { 0x3a, Level2
, 192, 6, 64 },
138 { 0x3b, Level2
, 128, 2, 64 },
139 { 0x3c, Level2
, 256, 4, 64 },
140 { 0x3d, Level2
, 384, 6, 64 },
141 { 0x3e, Level2
, 512, 4, 64 },
142 { 0x3f, Level2
, 256, 2, 64 },
143 { 0x41, Level2
, 128, 4, 32 },
144 { 0x42, Level2
, 256, 4, 32 },
145 { 0x43, Level2
, 512, 4, 32 },
146 { 0x44, Level2
, 1024, 4, 32 },
147 { 0x45, Level2
, 2048, 4, 32 },
148 { 0x46, Level3
, 4096, 4, 64 },
149 { 0x47, Level3
, 8192, 8, 64 },
150 { 0x48, Level2
, 3072, 12, 64 },
151 { 0x49, Level3
, 4096, 16, 64 },
152 { 0x4a, Level3
, 6144, 12, 64 },
153 { 0x4b, Level3
, 8192, 16, 64 },
154 { 0x4c, Level3
, 12288, 12, 64 },
155 { 0x4d, Level3
, 16384, 16, 64 },
156 { 0x4e, Level2
, 6144, 24, 64 },
157 { 0x60, Level1D
, 16, 8, 64 },
158 { 0x66, Level1D
, 8, 4, 64 },
159 { 0x67, Level1D
, 16, 4, 64 },
160 { 0x68, Level1D
, 32, 4, 64 },
161 { 0x78, Level2
, 1024, 4, 64 },
162 { 0x79, Level2
, 128, 8, 64 },
163 { 0x7a, Level2
, 256, 8, 64 },
164 { 0x7b, Level2
, 512, 8, 64 },
165 { 0x7c, Level2
, 1024, 8, 64 },
166 { 0x7d, Level2
, 2048, 8, 64 },
167 { 0x7f, Level2
, 512, 2, 64 },
168 { 0x80, Level2
, 512, 8, 64 },
169 { 0x82, Level2
, 256, 8, 32 },
170 { 0x83, Level2
, 512, 8, 32 },
171 { 0x84, Level2
, 1024, 8, 32 },
172 { 0x85, Level2
, 2048, 8, 32 },
173 { 0x86, Level2
, 512, 4, 64 },
174 { 0x87, Level2
, 1024, 8, 64 },
175 { 0xd0, Level3
, 512, 4, 64 },
176 { 0xd1, Level3
, 1024, 4, 64 },
177 { 0xd2, Level3
, 2048, 4, 64 },
178 { 0xd6, Level3
, 1024, 8, 64 },
179 { 0xd7, Level3
, 2048, 8, 64 },
180 { 0xd8, Level3
, 4096, 12, 64 },
181 { 0xdc, Level3
, 2048, 12, 64 },
182 { 0xdd, Level3
, 4096, 12, 64 },
183 { 0xde, Level3
, 8192, 12, 64 },
184 { 0xe2, Level3
, 2048, 16, 64 },
185 { 0xe3, Level3
, 4096, 16, 64 },
186 { 0xe4, Level3
, 8192, 16, 64 },
187 { 0xea, Level3
, 12288, 24, 64 },
188 { 0xeb, Level3
, 18432, 24, 64 },
189 { 0xec, Level3
, 24576, 24, 64 },
193 cpuid2_cache_desc_compar (const void *key
, const void *memb
)
195 cpuid2_cache_desc
*ckey
= (cpuid2_cache_desc
*) key
;
196 cpuid2_cache_desc
*cmemb
= (cpuid2_cache_desc
*) memb
;
197 return ckey
->desc
- cmemb
->desc
;
201 get_cpu_cache_intel_cpuid2 (int in
)
207 cpuid (reg
, reg
+ 1, reg
+ 2, reg
+ 3, 0x00000002);
209 for (int i
= 0; i
< num
; ++i
)
211 cpuid (reg
, reg
+ 1, reg
+ 2, reg
+ 3, 0x00000002);
212 for (int r
= 0; r
< 4; ++r
)
214 if (reg
[r
] & 0x80000000)
216 for (int b
= (r
== 0) ? 1 : 0; b
< 4; ++b
)
218 cpuid2_cache_desc key
, *cdp
;
220 key
.desc
= ((uint8_t *) ®
[r
])[b
];
221 cdp
= (cpuid2_cache_desc
*)
222 bsearch (&key
, cpuid2_cache_descriptor
,
223 sizeof cpuid2_cache_descriptor
224 / sizeof *cpuid2_cache_descriptor
,
225 sizeof *cpuid2_cache_descriptor
,
226 cpuid2_cache_desc_compar
);
231 case _SC_LEVEL1_ICACHE_SIZE
:
232 if (cdp
->level
== Level1I
)
233 ret
+= cdp
->size
* 1024;
235 case _SC_LEVEL1_ICACHE_ASSOC
:
236 if (cdp
->level
== Level1I
)
239 case _SC_LEVEL1_ICACHE_LINESIZE
:
240 if (cdp
->level
== Level1I
)
241 return cdp
->linesize
;
243 case _SC_LEVEL1_DCACHE_SIZE
:
244 if (cdp
->level
== Level1D
)
245 ret
+= cdp
->size
* 1024;
247 case _SC_LEVEL1_DCACHE_ASSOC
:
248 if (cdp
->level
== Level1D
)
251 case _SC_LEVEL1_DCACHE_LINESIZE
:
252 if (cdp
->level
== Level1D
)
253 return cdp
->linesize
;
255 case _SC_LEVEL2_CACHE_SIZE
:
256 if (cdp
->level
== Level2
)
257 ret
+= cdp
->size
* 1024;
259 case _SC_LEVEL2_CACHE_ASSOC
:
260 if (cdp
->level
== Level2
)
263 case _SC_LEVEL2_CACHE_LINESIZE
:
264 if (cdp
->level
== Level2
)
265 return cdp
->linesize
;
267 case _SC_LEVEL3_CACHE_SIZE
:
268 if (cdp
->level
== Level3
)
269 ret
+= cdp
->size
* 1024;
271 case _SC_LEVEL3_CACHE_ASSOC
:
272 if (cdp
->level
== Level3
)
275 case _SC_LEVEL3_CACHE_LINESIZE
:
276 if (cdp
->level
== Level3
)
277 return cdp
->linesize
;
287 get_cpu_cache_intel_cpuid4 (int in
)
289 uint32_t eax
, ebx
, ecx
, edx
;
292 for (int idx
= 0; ; ++idx
)
294 uint32_t cache_type
, cur_level
, assoc
, part
, linesize
, sets
;
296 cpuid (&eax
, &ebx
, &ecx
, &edx
, 0x00000004, idx
);
297 if ((cache_type
= (eax
& 0x1f))== 0)
299 cur_level
= ((eax
>> 5) & 0x7);
300 assoc
= ((ebx
>> 22) & 0x3ff) + 1;
301 part
= ((ebx
>> 12) & 0x3ff) + 1;
302 linesize
= (ebx
& 0xfff) + 1;
306 case _SC_LEVEL1_ICACHE_SIZE
:
307 if (cur_level
== 1 && cache_type
== 2)
308 ret
+= assoc
* part
* linesize
* sets
;
310 case _SC_LEVEL1_ICACHE_ASSOC
:
311 if (cur_level
== 1 && cache_type
== 2)
314 case _SC_LEVEL1_ICACHE_LINESIZE
:
315 if (cur_level
== 1 && cache_type
== 2)
318 case _SC_LEVEL1_DCACHE_SIZE
:
319 if (cur_level
== 1 && cache_type
== 1)
320 ret
+= assoc
* part
* linesize
* sets
;
322 case _SC_LEVEL1_DCACHE_ASSOC
:
323 if (cur_level
== 1 && cache_type
== 1)
326 case _SC_LEVEL1_DCACHE_LINESIZE
:
327 if (cur_level
== 1 && cache_type
== 1)
330 case _SC_LEVEL2_CACHE_SIZE
:
332 ret
+= assoc
* part
* linesize
* sets
;
334 case _SC_LEVEL2_CACHE_ASSOC
:
338 case _SC_LEVEL2_CACHE_LINESIZE
:
342 case _SC_LEVEL3_CACHE_SIZE
:
344 ret
+= assoc
* part
* linesize
* sets
;
346 case _SC_LEVEL3_CACHE_ASSOC
:
350 case _SC_LEVEL3_CACHE_LINESIZE
:
359 /* Also called from format_proc_cpuinfo */
361 get_cpu_cache_intel (int in
, uint32_t maxf
)
367 case _SC_LEVEL1_ICACHE_SIZE
:
368 case _SC_LEVEL1_ICACHE_ASSOC
:
369 case _SC_LEVEL1_ICACHE_LINESIZE
:
370 case _SC_LEVEL1_DCACHE_SIZE
:
371 case _SC_LEVEL1_DCACHE_ASSOC
:
372 case _SC_LEVEL1_DCACHE_LINESIZE
:
373 case _SC_LEVEL2_CACHE_SIZE
:
374 case _SC_LEVEL2_CACHE_ASSOC
:
375 case _SC_LEVEL2_CACHE_LINESIZE
:
376 case _SC_LEVEL3_CACHE_SIZE
:
377 case _SC_LEVEL3_CACHE_ASSOC
:
378 case _SC_LEVEL3_CACHE_LINESIZE
:
380 ret
= get_cpu_cache_intel_cpuid4 (in
);
382 ret
= get_cpu_cache_intel_cpuid2 (in
);
390 static const long assoc
[16] = { 0, 1, 2, 2, 4, 4, 8, 8,
391 16, 16, 32, 48, 64, 96, 128, 0x8000 };
393 /* Also called from format_proc_cpuinfo */
395 get_cpu_cache_amd (int in
, uint32_t maxe
)
397 uint32_t eax
, ebx
, ecx
, edx
;
400 if (in
>= _SC_LEVEL1_ICACHE_SIZE
&& in
<= _SC_LEVEL1_DCACHE_LINESIZE
401 && maxe
>= 0x80000005)
402 cpuid (&eax
, &ebx
, &ecx
, &edx
, 0x80000005);
403 else if (in
>= _SC_LEVEL2_CACHE_SIZE
&& in
<= _SC_LEVEL3_CACHE_LINESIZE
404 && maxe
>= 0x80000006)
405 cpuid (&eax
, &ebx
, &ecx
, &edx
, 0x80000006);
411 case _SC_LEVEL1_ICACHE_SIZE
:
412 ret
= (edx
& 0xff000000) >> 14;
414 case _SC_LEVEL1_ICACHE_ASSOC
:
415 ret
= (edx
& 0xff0000) >> 16;
419 case _SC_LEVEL1_ICACHE_LINESIZE
:
422 case _SC_LEVEL1_DCACHE_SIZE
:
423 ret
= (ecx
& 0xff000000) >> 14;
425 case _SC_LEVEL1_DCACHE_ASSOC
:
426 ret
= (ecx
& 0xff0000) >> 16;
430 case _SC_LEVEL1_DCACHE_LINESIZE
:
433 case _SC_LEVEL2_CACHE_SIZE
:
434 ret
= (ecx
& 0xffff0000) >> 6;
436 case _SC_LEVEL2_CACHE_ASSOC
:
437 ret
= assoc
[(ecx
& 0xf000) >> 12];
439 case _SC_LEVEL2_CACHE_LINESIZE
:
442 case _SC_LEVEL3_CACHE_SIZE
:
443 ret
= (long) ((edx
& 0xfffc0000) >> 18) * 512 * 1024;
445 case _SC_LEVEL3_CACHE_ASSOC
:
446 ret
= assoc
[(edx
& 0xf000) >> 12];
448 case _SC_LEVEL3_CACHE_LINESIZE
:
458 get_cpu_cache (int in
)
460 uint32_t maxf
, vendor_id
[4];
461 cpuid (&maxf
, &vendor_id
[0], &vendor_id
[2], &vendor_id
[1], 0x00000000);
464 if (!strcmp ((char*) vendor_id
, "GenuineIntel"))
465 return get_cpu_cache_intel (in
, maxf
& 0xffff);
466 else if (!strcmp ((char*)vendor_id
, "AuthenticAMD")
467 || !strcmp((char*)vendor_id
, "HygonGenuine"))
469 uint32_t maxe
= 0, unused
;
470 cpuid (&maxe
, &unused
, &unused
, &unused
, 0x80000000);
471 return get_cpu_cache_amd (in
, maxe
);
476 enum sc_type
{ cons
, func
};
488 {cons
, {c
:-1L}}, /* 0, _SC_ARG_MAX */
489 {cons
, {c
:CHILD_MAX
}}, /* 1, _SC_CHILD_MAX */
490 {cons
, {c
:CLOCKS_PER_SEC
}}, /* 2, _SC_CLK_TCK */
491 {cons
, {c
:NGROUPS_MAX
}}, /* 3, _SC_NGROUPS_MAX */
492 {cons
, {c
:OPEN_MAX
}}, /* 4, _SC_OPEN_MAX */
493 {cons
, {c
:_POSIX_JOB_CONTROL
}}, /* 5, _SC_JOB_CONTROL */
494 {cons
, {c
:_POSIX_SAVED_IDS
}}, /* 6, _SC_SAVED_IDS */
495 {cons
, {c
:_POSIX_VERSION
}}, /* 7, _SC_VERSION */
496 {func
, {f
:get_page_size
}}, /* 8, _SC_PAGESIZE */
497 {func
, {f
:get_nproc_values
}}, /* 9, _SC_NPROCESSORS_CONF */
498 {func
, {f
:get_nproc_values
}}, /* 10, _SC_NPROCESSORS_ONLN */
499 {func
, {f
:get_phys_pages
}}, /* 11, _SC_PHYS_PAGES */
500 {func
, {f
:get_avphys
}}, /* 12, _SC_AVPHYS_PAGES */
501 {cons
, {c
:MQ_OPEN_MAX
}}, /* 13, _SC_MQ_OPEN_MAX */
502 {cons
, {c
:MQ_PRIO_MAX
}}, /* 14, _SC_MQ_PRIO_MAX */
503 {cons
, {c
:RTSIG_MAX
}}, /* 15, _SC_RTSIG_MAX */
504 {cons
, {c
:-1L}}, /* 16, _SC_SEM_NSEMS_MAX */
505 {cons
, {c
:SEM_VALUE_MAX
}}, /* 17, _SC_SEM_VALUE_MAX */
506 {cons
, {c
:SIGQUEUE_MAX
}}, /* 18, _SC_SIGQUEUE_MAX */
507 {cons
, {c
:TIMER_MAX
}}, /* 19, _SC_TIMER_MAX */
508 {cons
, {c
:-1L}}, /* 20, _SC_TZNAME_MAX */
509 {cons
, {c
:_POSIX_ASYNCHRONOUS_IO
}}, /* 21, _SC_ASYNCHRONOUS_IO */
510 {cons
, {c
:_POSIX_FSYNC
}}, /* 22, _SC_FSYNC */
511 {cons
, {c
:_POSIX_MAPPED_FILES
}}, /* 23, _SC_MAPPED_FILES */
512 {cons
, {c
:-1L}}, /* 24, _SC_MEMLOCK */
513 {cons
, {c
:_POSIX_MEMLOCK_RANGE
}}, /* 25, _SC_MEMLOCK_RANGE */
514 {cons
, {c
:_POSIX_MEMORY_PROTECTION
}}, /* 26, _SC_MEMORY_PROTECTION */
515 {cons
, {c
:_POSIX_MESSAGE_PASSING
}}, /* 27, _SC_MESSAGE_PASSING */
516 {cons
, {c
:-1L}}, /* 28, _SC_PRIORITIZED_IO */
517 {cons
, {c
:_POSIX_REALTIME_SIGNALS
}}, /* 29, _SC_REALTIME_SIGNALS */
518 {cons
, {c
:_POSIX_SEMAPHORES
}}, /* 30, _SC_SEMAPHORES */
519 {cons
, {c
:_POSIX_SHARED_MEMORY_OBJECTS
}}, /* 31, _SC_SHARED_MEMORY_OBJECTS */
520 {cons
, {c
:_POSIX_SYNCHRONIZED_IO
}}, /* 32, _SC_SYNCHRONIZED_IO */
521 {cons
, {c
:_POSIX_TIMERS
}}, /* 33, _SC_TIMERS */
522 {cons
, {c
:AIO_LISTIO_MAX
}}, /* 34, _SC_AIO_LISTIO_MAX */
523 {cons
, {c
:AIO_MAX
}}, /* 35, _SC_AIO_MAX */
524 {cons
, {c
:AIO_PRIO_DELTA_MAX
}}, /* 36, _SC_AIO_PRIO_DELTA_MAX */
525 {cons
, {c
:DELAYTIMER_MAX
}}, /* 37, _SC_DELAYTIMER_MAX */
526 {cons
, {c
:PTHREAD_KEYS_MAX
}}, /* 38, _SC_THREAD_KEYS_MAX */
527 {cons
, {c
:PTHREAD_STACK_MIN
}}, /* 39, _SC_THREAD_STACK_MIN */
528 {cons
, {c
:-1L}}, /* 40, _SC_THREAD_THREADS_MAX */
529 {cons
, {c
:TTY_NAME_MAX
}}, /* 41, _SC_TTY_NAME_MAX */
530 {cons
, {c
:_POSIX_THREADS
}}, /* 42, _SC_THREADS */
531 {cons
, {c
:_POSIX_THREAD_ATTR_STACKADDR
}},/* 43, _SC_THREAD_ATTR_STACKADDR */
532 {cons
, {c
:_POSIX_THREAD_ATTR_STACKSIZE
}},/* 44, _SC_THREAD_ATTR_STACKSIZE */
533 {cons
, {c
:_POSIX_THREAD_PRIORITY_SCHEDULING
}}, /* 45, _SC_THREAD_PRIORITY_SCHEDULING */
534 {cons
, {c
:-1L}}, /* 46, _SC_THREAD_PRIO_INHERIT */
535 {cons
, {c
:-1L}}, /* 47, _SC_THREAD_PRIO_PROTECT */
536 {cons
, {c
:_POSIX_THREAD_PROCESS_SHARED
}}, /* 48, _SC_THREAD_PROCESS_SHARED */
537 {cons
, {c
:_POSIX_THREAD_SAFE_FUNCTIONS
}}, /* 49, _SC_THREAD_SAFE_FUNCTIONS */
538 {cons
, {c
:16384L}}, /* 50, _SC_GETGR_R_SIZE_MAX */
539 {cons
, {c
:16384L}}, /* 51, _SC_GETPW_R_SIZE_MAX */
540 {cons
, {c
:LOGIN_NAME_MAX
}}, /* 52, _SC_LOGIN_NAME_MAX */
541 {cons
, {c
:PTHREAD_DESTRUCTOR_ITERATIONS
}}, /* 53, _SC_THREAD_DESTRUCTOR_ITERATIONS */
542 {cons
, {c
:_POSIX_ADVISORY_INFO
}}, /* 54, _SC_ADVISORY_INFO */
543 {cons
, {c
:ATEXIT_MAX
}}, /* 55, _SC_ATEXIT_MAX */
544 {cons
, {c
:_POSIX_BARRIERS
}}, /* 56, _SC_BARRIERS */
545 {cons
, {c
:BC_BASE_MAX
}}, /* 57, _SC_BC_BASE_MAX */
546 {cons
, {c
:BC_DIM_MAX
}}, /* 58, _SC_BC_DIM_MAX */
547 {cons
, {c
:BC_SCALE_MAX
}}, /* 59, _SC_BC_SCALE_MAX */
548 {cons
, {c
:BC_STRING_MAX
}}, /* 60, _SC_BC_STRING_MAX */
549 {cons
, {c
:_POSIX_CLOCK_SELECTION
}}, /* 61, _SC_CLOCK_SELECTION */
550 {cons
, {c
:-1L}}, /* 62, _SC_COLL_WEIGHTS_MAX */
551 {cons
, {c
:_POSIX_CPUTIME
}}, /* 63, _SC_CPUTIME */
552 {cons
, {c
:EXPR_NEST_MAX
}}, /* 64, _SC_EXPR_NEST_MAX */
553 {cons
, {c
:HOST_NAME_MAX
}}, /* 65, _SC_HOST_NAME_MAX */
554 {cons
, {c
:IOV_MAX
}}, /* 66, _SC_IOV_MAX */
555 {cons
, {c
:_POSIX_IPV6
}}, /* 67, _SC_IPV6 */
556 {cons
, {c
:LINE_MAX
}}, /* 68, _SC_LINE_MAX */
557 {cons
, {c
:_POSIX_MONOTONIC_CLOCK
}}, /* 69, _SC_MONOTONIC_CLOCK */
558 {cons
, {c
:_POSIX_RAW_SOCKETS
}}, /* 70, _SC_RAW_SOCKETS */
559 {cons
, {c
:_POSIX_READER_WRITER_LOCKS
}}, /* 71, _SC_READER_WRITER_LOCKS */
560 {cons
, {c
:_POSIX_REGEXP
}}, /* 72, _SC_REGEXP */
561 {cons
, {c
:RE_DUP_MAX
}}, /* 73, _SC_RE_DUP_MAX */
562 {cons
, {c
:_POSIX_SHELL
}}, /* 74, _SC_SHELL */
563 {cons
, {c
:_POSIX_SPAWN
}}, /* 75, _SC_SPAWN */
564 {cons
, {c
:_POSIX_SPIN_LOCKS
}}, /* 76, _SC_SPIN_LOCKS */
565 {cons
, {c
:-1L}}, /* 77, _SC_SPORADIC_SERVER */
566 {cons
, {c
:-1L}}, /* 78, _SC_SS_REPL_MAX */
567 {cons
, {c
:SYMLOOP_MAX
}}, /* 79, _SC_SYMLOOP_MAX */
568 {cons
, {c
:_POSIX_THREAD_CPUTIME
}}, /* 80, _SC_THREAD_CPUTIME */
569 {cons
, {c
:-1L}}, /* 81, _SC_THREAD_SPORADIC_SERVER */
570 {cons
, {c
:_POSIX_TIMEOUTS
}}, /* 82, _SC_TIMEOUTS */
571 {cons
, {c
:-1L}}, /* 83, _SC_TRACE */
572 {cons
, {c
:-1L}}, /* 84, _SC_TRACE_EVENT_FILTER */
573 {cons
, {c
:-1}}, /* 85, _SC_TRACE_EVENT_NAME_MAX */
574 {cons
, {c
:-1L}}, /* 86, _SC_TRACE_INHERIT */
575 {cons
, {c
:-1L}}, /* 87, _SC_TRACE_LOG */
576 {cons
, {c
:-1L}}, /* 88, _SC_TRACE_NAME_MAX */
577 {cons
, {c
:-1L}}, /* 89, _SC_TRACE_SYS_MAX */
578 {cons
, {c
:-1L}}, /* 90, _SC_TRACE_USER_EVENT_MAX */
579 {cons
, {c
:-1L}}, /* 91, _SC_TYPED_MEMORY_OBJECTS */
580 {cons
, {c
:_POSIX_V6_ILP32_OFF32
}}, /* 92, _SC_V6_ILP32_OFF32 */
581 {cons
, {c
:_POSIX_V6_ILP32_OFFBIG
}}, /* 93, _SC_V6_ILP32_OFFBIG */
582 {cons
, {c
:_POSIX_V6_LP64_OFF64
}}, /* 94, _SC_V6_LP64_OFF64 */
583 {cons
, {c
:_POSIX_V6_LPBIG_OFFBIG
}}, /* 95, _SC_V6_LPBIG_OFFBIG */
584 {cons
, {c
:_XOPEN_CRYPT
}}, /* 96, _SC_XOPEN_CRYPT */
585 {cons
, {c
:_XOPEN_ENH_I18N
}}, /* 97, _SC_XOPEN_ENH_I18N */
586 {cons
, {c
:-1L}}, /* 98, _SC_XOPEN_LEGACY */
587 {cons
, {c
:-1L}}, /* 99, _SC_XOPEN_REALTIME */
588 {cons
, {c
:STREAM_MAX
}}, /* 100, _SC_STREAM_MAX */
589 {cons
, {c
:_POSIX_PRIORITY_SCHEDULING
}}, /* 101, _SC_PRIORITY_SCHEDULING */
590 {cons
, {c
:-1L}}, /* 102, _SC_XOPEN_REALTIME_THREADS */
591 {cons
, {c
:_XOPEN_SHM
}}, /* 103, _SC_XOPEN_SHM */
592 {cons
, {c
:-1L}}, /* 104, _SC_XOPEN_STREAMS */
593 {cons
, {c
:-1L}}, /* 105, _SC_XOPEN_UNIX */
594 {cons
, {c
:_XOPEN_VERSION
}}, /* 106, _SC_XOPEN_VERSION */
595 {cons
, {c
:_POSIX2_CHAR_TERM
}}, /* 107, _SC_2_CHAR_TERM */
596 {cons
, {c
:_POSIX2_C_BIND
}}, /* 108, _SC_2_C_BIND */
597 {cons
, {c
:_POSIX2_C_DEV
}}, /* 109, _SC_2_C_DEV */
598 {cons
, {c
:-1L}}, /* 110, _SC_2_FORT_DEV */
599 {cons
, {c
:-1L}}, /* 111, _SC_2_FORT_RUN */
600 {cons
, {c
:-1L}}, /* 112, _SC_2_LOCALEDEF */
601 {cons
, {c
:-1L}}, /* 113, _SC_2_PBS */
602 {cons
, {c
:-1L}}, /* 114, _SC_2_PBS_ACCOUNTING */
603 {cons
, {c
:-1L}}, /* 115, _SC_2_PBS_CHECKPOINT */
604 {cons
, {c
:-1L}}, /* 116, _SC_2_PBS_LOCATE */
605 {cons
, {c
:-1L}}, /* 117, _SC_2_PBS_MESSAGE */
606 {cons
, {c
:-1L}}, /* 118, _SC_2_PBS_TRACK */
607 {cons
, {c
:_POSIX2_SW_DEV
}}, /* 119, _SC_2_SW_DEV */
608 {cons
, {c
:_POSIX2_UPE
}}, /* 120, _SC_2_UPE */
609 {cons
, {c
:_POSIX2_VERSION
}}, /* 121, _SC_2_VERSION */
610 {cons
, {c
:-1L}}, /* 122, _SC_THREAD_ROBUST_PRIO_INHERIT */
611 {cons
, {c
:-1L}}, /* 123, _SC_THREAD_ROBUST_PRIO_PROTECT */
612 {cons
, {c
:-1L}}, /* 124, _SC_XOPEN_UUCP */
613 {func
, {f
:get_cpu_cache
}}, /* 125, _SC_LEVEL1_ICACHE_SIZE */
614 {func
, {f
:get_cpu_cache
}}, /* 126, _SC_LEVEL1_ICACHE_ASSOC */
615 {func
, {f
:get_cpu_cache
}}, /* 127, _SC_LEVEL1_ICACHE_LINESIZE */
616 {func
, {f
:get_cpu_cache
}}, /* 128, _SC_LEVEL1_DCACHE_SIZE */
617 {func
, {f
:get_cpu_cache
}}, /* 129, _SC_LEVEL1_DCACHE_ASSOC */
618 {func
, {f
:get_cpu_cache
}}, /* 130, _SC_LEVEL1_DCACHE_LINESIZE */
619 {func
, {f
:get_cpu_cache
}}, /* 131, _SC_LEVEL2_CACHE_SIZE */
620 {func
, {f
:get_cpu_cache
}}, /* 132, _SC_LEVEL2_CACHE_ASSOC */
621 {func
, {f
:get_cpu_cache
}}, /* 133, _SC_LEVEL2_CACHE_LINESIZE */
622 {func
, {f
:get_cpu_cache
}}, /* 134, _SC_LEVEL3_CACHE_SIZE */
623 {func
, {f
:get_cpu_cache
}}, /* 135, _SC_LEVEL3_CACHE_ASSOC */
624 {func
, {f
:get_cpu_cache
}}, /* 136, _SC_LEVEL3_CACHE_LINESIZE */
625 {func
, {f
:get_cpu_cache
}}, /* 137, _SC_LEVEL4_CACHE_SIZE */
626 {func
, {f
:get_cpu_cache
}}, /* 138, _SC_LEVEL4_CACHE_ASSOC */
627 {func
, {f
:get_cpu_cache
}}, /* 139, _SC_LEVEL4_CACHE_LINESIZE */
630 #define SC_MIN _SC_ARG_MAX
631 #define SC_MAX _SC_LEVEL4_CACHE_LINESIZE
633 /* sysconf: POSIX 4.8.1.1 */
634 /* Allows a portable app to determine quantities of resources or
635 presence of an option at execution time. */
639 if (in
>= SC_MIN
&& in
<= SC_MAX
)
641 switch (sca
[in
].type
)
646 return sca
[in
].f (in
);
649 /* Unimplemented sysconf name or invalid option value. */
654 #define ls(s) sizeof(s),s
662 {ls ("/bin:/usr/bin")}, /* _CS_PATH */
663 {0, NULL
}, /* _CS_POSIX_V6_ILP32_OFF32_CFLAGS */
664 {0, NULL
}, /* _CS_POSIX_V6_ILP32_OFF32_LDFLAGS */
665 {0, NULL
}, /* _CS_POSIX_V6_ILP32_OFF32_LIBS */
666 {0, NULL
}, /* _CS_XBS5_ILP32_OFF32_LINTFLAGS */
667 {0, NULL
}, /* _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS */
668 {0, NULL
}, /* _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS */
669 {0, NULL
}, /* _CS_POSIX_V6_ILP32_OFFBIG_LIBS */
670 {0, NULL
}, /* _CS_XBS5_ILP32_OFFBIG_LINTFLAGS */
671 {ls ("")}, /* _CS_POSIX_V6_LP64_OFF64_CFLAGS */
672 {ls ("")}, /* _CS_POSIX_V6_LP64_OFF64_LDFLAGS */
673 {ls ("")}, /* _CS_POSIX_V6_LP64_OFF64_LIBS */
674 {ls ("")}, /* _CS_XBS5_LP64_OFF64_LINTFLAGS */
675 {ls ("")}, /* _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS */
676 {ls ("")}, /* _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS */
677 {ls ("")}, /* _CS_POSIX_V6_LPBIG_OFFBIG_LIBS */
678 {ls ("")}, /* _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS */
679 {ls ("POSIX_V6_LP64_OFF64")}, /* _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS */
680 {ls ("")}, /* _CS_POSIX_V7_THREADS_CFLAGS */
681 {ls ("")}, /* _CS_POSIX_V7_THREADS_LDFLAGS */
682 {ls ("POSIXLY_CORRECT=1")}, /* _CS_V7_ENV */
683 {ls ("")}, /* _CS_LFS_CFLAGS */
684 {ls ("")}, /* _CS_LFS_LDFLAGS */
685 {ls ("")}, /* _CS_LFS_LIBS */
686 {ls ("")}, /* _CS_LFS_LINTFLAGS */
689 #define CS_MIN _CS_PATH
690 #define CS_MAX _CS_LFS_LINTFLAGS
693 confstr (int in
, char *buf
, size_t len
)
695 if (in
>= CS_MIN
&& in
<= CS_MAX
)
697 if (csa
[in
].l
&& len
)
700 strncat (buf
, csa
[in
].s
, MIN (len
, csa
[in
].l
) - 1);
704 /* Invalid option value. */
710 get_nprocs_conf (void)
712 return get_nproc_values (_SC_NPROCESSORS_CONF
);
718 return get_nproc_values (_SC_NPROCESSORS_ONLN
);
722 get_phys_pages (void)
724 return get_phys_pages (_SC_PHYS_PAGES
);
728 get_avphys_pages (void)
730 return get_avphys (_SC_AVPHYS_PAGES
);
734 sysinfo (struct sysinfo
*info
)
736 unsigned long long uptime
= 0ULL, totalram
= 0ULL, freeram
= 0ULL,
737 totalswap
= 0ULL, freeswap
= 0ULL;
738 MEMORYSTATUSEX memory_status
;
739 PSYSTEM_PAGEFILE_INFORMATION spi
= NULL
;
740 ULONG sizeof_spi
= 512;
741 PSYSTEM_TIMEOFDAY_INFORMATION stodi
= NULL
;
742 const ULONG sizeof_stodi
= sizeof (SYSTEM_TIMEOFDAY_INFORMATION
);
743 NTSTATUS status
= STATUS_SUCCESS
;
744 winpids
pids ((DWORD
) 0);
752 stodi
= (PSYSTEM_TIMEOFDAY_INFORMATION
) malloc (sizeof_stodi
);
753 status
= NtQuerySystemInformation (SystemTimeOfDayInformation
, (PVOID
) stodi
,
755 if (NT_SUCCESS (status
))
756 uptime
= (stodi
->CurrentTime
.QuadPart
- stodi
->BootTime
.QuadPart
)
759 debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
760 "status %y", status
);
765 memory_status
.dwLength
= sizeof (MEMORYSTATUSEX
);
766 GlobalMemoryStatusEx (&memory_status
);
767 totalram
= memory_status
.ullTotalPhys
/ wincap
.page_size ();
768 freeram
= memory_status
.ullAvailPhys
/ wincap
.page_size ();
770 spi
= (PSYSTEM_PAGEFILE_INFORMATION
) malloc (sizeof_spi
);
773 status
= NtQuerySystemInformation (SystemPagefileInformation
, (PVOID
) spi
,
774 sizeof_spi
, &sizeof_spi
);
775 if (status
== STATUS_INFO_LENGTH_MISMATCH
)
778 spi
= (PSYSTEM_PAGEFILE_INFORMATION
) malloc (sizeof_spi
);
780 status
= NtQuerySystemInformation (SystemPagefileInformation
,
781 (PVOID
) spi
, sizeof_spi
,
785 if (!spi
|| !NT_SUCCESS (status
))
787 debug_printf ("NtQuerySystemInformation(SystemPagefileInformation), "
788 "status %y", status
);
789 totalswap
= (memory_status
.ullTotalPageFile
- memory_status
.ullTotalPhys
)
790 / wincap
.page_size ();
791 freeswap
= (memory_status
.ullAvailPageFile
- memory_status
.ullTotalPhys
)
792 / wincap
.page_size ();
796 PSYSTEM_PAGEFILE_INFORMATION spp
= spi
;
799 totalswap
+= spp
->CurrentSize
;
800 freeswap
+= spp
->CurrentSize
- spp
->TotalUsed
;
802 while (spp
->NextEntryOffset
803 && (spp
= (PSYSTEM_PAGEFILE_INFORMATION
)
804 ((char *) spp
+ spp
->NextEntryOffset
)));
809 info
->uptime
= (long) uptime
;
810 info
->totalram
= (unsigned long) totalram
;
811 info
->freeram
= (unsigned long) freeram
;
812 info
->totalswap
= (unsigned long) totalswap
;
813 info
->freeswap
= (unsigned long) freeswap
;
814 info
->procs
= (unsigned short) pids
.npids
;
815 info
->mem_unit
= (unsigned int) wincap
.page_size ();
817 /* FIXME: unsupported */
818 info
->loads
[0] = 0UL;
819 info
->loads
[1] = 0UL;
820 info
->loads
[2] = 0UL;
821 info
->sharedram
= 0UL;
822 info
->bufferram
= 0UL;
823 info
->totalhigh
= 0UL;
824 info
->freehigh
= 0UL;