Debian Codegraph @

madrisan-nagios-plugins-linux/nagios-plugins-linux/include/cputopology.h

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /* cputopology.h -- a library for checking the CPU topology
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef _CPUTOPOLOGY_H
18 #define _CPUTOPOLOGY_H
19
20 #include <sched.h>
21
22 #ifdef __cplusplus
23 extern "C"
24 {
25 #endif
26
27 /*
28 * Fallback for old or obscure libcs without dynamically allocated cpusets
29 *
30 * The following macros are based on code from glibc.
31 *
32 * The GNU C Library is free software; you can redistribute it and/or
33 * modify it under the terms of the GNU Lesser General Public
34 * License as published by the Free Software Foundation; either
35 * version 2.1 of the License, or (at your option) any later version.
36 */
37 #if !HAVE_DECL_CPU_ALLOC
38
39 # define CPU_ZERO_S(setsize, cpusetp) \
40 do { \
41 size_t __i; \
42 size_t __imax = (setsize) / sizeof (__cpu_mask); \
43 __cpu_mask *__bits = (cpusetp)->__bits; \
44 for (__i = 0; __i < __imax; ++__i) \
45 __bits[__i] = 0; \
46 } while (0)
47
48 # define CPU_SET_S(cpu, setsize, cpusetp) \
49 ({ size_t __cpu = (cpu); \
50 __cpu < 8 * (setsize) \
51 ? (((__cpu_mask *) ((cpusetp)->__bits))[__CPUELT (__cpu)] \
52 |= __CPUMASK (__cpu)) \
53 : 0; })
54
55 int __cpuset_count_s(size_t setsize, const cpu_set_t *set);
56 # define CPU_COUNT_S(setsize, cpusetp) __cpuset_count_s(setsize, cpusetp)
57
58 # define CPU_ALLOC_SIZE(count) \
59 ((((count) + __NCPUBITS - 1) / __NCPUBITS) * sizeof (__cpu_mask))
60 # define CPU_ALLOC(count) (malloc(CPU_ALLOC_SIZE(count)))
61 # define CPU_FREE(cpuset) (free(cpuset))
62
63 #endif /* !HAVE_DECL_CPU_ALLOC */
64
65 /* Get the number of total and active cpus. */
66 int get_processor_number_total ();
67 int get_processor_number_online ();
68
69 /* Get the maximum cpu index allowed by the kernel configuration. */
70 int get_processor_number_kernel_max ();
71
72 /* Get the number of sockets, cores, and threads. */
73 int get_cputopology_nthreads ();
74 void get_cputopology_read (unsigned int *nsockets, unsigned int *ncores,
75 unsigned int *nthreads);
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* _CPUTOPOLOGY_H */