]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/lscpu.h
11 #include "pathnames.h"
15 #define LSCPU_DEBUG_INIT (1 << 1)
16 #define LSCPU_DEBUG_MISC (1 << 2)
17 #define LSCPU_DEBUG_GATHER (1 << 3)
18 #define LSCPU_DEBUG_TYPE (1 << 4)
19 #define LSCPU_DEBUG_CPU (1 << 5)
20 #define LSCPU_DEBUG_VIRT (1 << 6)
21 #define LSBLK_DEBUG_ALL 0xFFFF
23 UL_DEBUG_DECLARE_MASK(lscpu
);
24 #define DBG(m, x) __UL_DBG(lscpu, LSCPU_DEBUG_, m, x)
25 #define ON_DBG(m, x) __UL_DBG_CALL(lscpu, LSCPU_DEBUG_, m, x)
27 #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lscpu)
30 #define _PATH_SYS_SYSTEM "/sys/devices/system"
31 #define _PATH_SYS_HYP_FEATURES "/sys/hypervisor/properties/features"
32 #define _PATH_SYS_CPU _PATH_SYS_SYSTEM "/cpu"
33 #define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
34 #define _PATH_SYS_DMI "/sys/firmware/dmi/tables/DMI"
35 #define _PATH_ACPI_PPTT "/sys/firmware/acpi/tables/PPTT"
38 int id
; /* unique identifier */
39 int nth
; /* cache<number> from cpuinfo */
42 char *allocation_policy
;
48 unsigned int ways_of_associativity
;
49 unsigned int physical_line_partition
;
50 unsigned int number_of_sets
;
51 unsigned int coherency_line_size
;
56 struct lscpu_cputype
{
60 int vendor_id
; /* created by lscpu_decode_arm() */
61 char *bios_vendor
; /* aarch64 */
62 char *machinetype
; /* s390 */
66 char *bios_modelname
; /* aarch64 */
67 char *bios_family
; /* aarch64 */
68 char *revision
; /* alternative for model (ppc) */
72 char *mtid
; /* maximum thread id (s390) */
73 char *addrsz
; /* address sizes */
74 int dispatching
; /* -1 if not evailable, DIST_* */
75 int freqboost
; /* -1 if not evailable */
77 size_t physsockets
; /* Physical sockets (modules) */
78 size_t physchips
; /* Physical chips */
79 size_t physcoresperchip
; /* Physical cores per chip */
81 size_t nthreads_per_core
;
82 size_t ncores_per_socket
;
83 size_t nsockets_per_book
;
84 size_t nbooks_per_drawer
;
85 size_t ndrawers_per_system
;
87 char *dynamic_mhz
; /* s390; copy from the first CPU */
88 char *static_mhz
; /* s390; copy from the first CPU */
94 cpu_set_t
**socketmaps
;
98 cpu_set_t
**drawermaps
;
100 unsigned int has_freq
: 1,
102 has_polarization
: 1,
105 size_t nr_socket_on_cluster
; /* the number of sockets if the is_cluster is 1 */
107 char *isa
; /* loongarch */
110 /* dispatching modes */
116 /* cpu polarization */
127 struct lscpu_cputype
*type
;
131 char *bogomips
; /* per-CPU bogomips */
132 char *mhz
; /* freq from cpuinfo */
133 char *dynamic_mhz
; /* from cpuinf for s390 */
134 char *static_mhz
; /* from cpuinf for s390 */
135 float mhz_max_freq
; /* realtime freq from /sys/.../cpuinfo_max_freq */
136 float mhz_min_freq
; /* realtime freq from /sys/.../cpuinfo_min_freq */
144 int polarization
; /* POLAR_* */
145 int address
; /* physical cpu address */
146 int configured
; /* cpu configured */
150 char *name
; /* uname() .machine */
152 unsigned int bit32
:1,
156 struct lscpu_vulnerability
{
161 /* virtualization types */
169 /* hypervisor vendors */
171 VIRT_VENDOR_NONE
= 0,
176 VIRT_VENDOR_IBM
, /* sys-z powervm */
179 VIRT_VENDOR_INNOTEK
, /* VBOX */
181 VIRT_VENDOR_PARALLELS
, /* OpenVZ/VIrtuozzo */
190 char *cpuflag
; /* virtualization flag (vmx, svm) */
191 char *hypervisor
; /* hypervisor software */
192 int vendor
; /* VIRT_VENDOR_* */
193 int type
; /* VIRT_TYPE_* ? */
198 LSCPU_OUTPUT_SUMMARY
= 0, /* default */
200 LSCPU_OUTPUT_PARSABLE
,
201 LSCPU_OUTPUT_READABLE
205 int maxcpus
; /* size in bits of kernel cpu mask */
207 const char *prefix
; /* path to /sys and /proc snapshot or NULL */
209 struct path_cxt
*syscpu
; /* _PATH_SYS_CPU path handler */
210 struct path_cxt
*procfs
; /* /proc path handler */
211 struct path_cxt
*rootfs
; /* / path handler */
214 struct lscpu_cputype
**cputypes
;
216 size_t npossibles
; /* number of possible CPUs */
217 struct lscpu_cpu
**cpus
; /* possible CPUs, contains gaps (cups[n]=NULL) */
220 cpu_set_t
*present
; /* mask with present CPUs */
222 size_t nonlines
; /* aka number of trhreads */
223 cpu_set_t
*online
; /* mask with online CPUs */
225 struct lscpu_arch
*arch
;
226 struct lscpu_virt
*virt
;
228 struct lscpu_vulnerability
*vuls
; /* array of CPU vulnerabilities */
229 size_t nvuls
; /* number of CPU vulnerabilities */
231 struct lscpu_cache
*caches
; /* all instances of the all caches from /sys */
234 struct lscpu_cache
*ecaches
;
235 size_t necaches
; /* extra caches (s390) from /proc/cpuinfo */
237 size_t nnodes
; /* number of NUMA modes */
238 int *idx2nodenum
; /* Support for discontinuous nodes */
239 cpu_set_t
**nodemaps
; /* array with NUMA nodes */
241 int mode
; /* LSCPU_OUTPUT_* */
243 unsigned int noalive
: 1,
252 int is_cluster
; /* For aarch64 if the machine doesn't have ACPI PPTT */
255 #define is_cpu_online(_cxt, _cpu) \
256 ((_cxt) && (_cpu) && (_cxt)->online && \
257 CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->online))
259 #define is_cpu_present(_cxt, _cpu) \
260 ((_cxt) && (_cpu) && (_cxt)->present && \
261 CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->present))
263 struct lscpu_cputype
*lscpu_new_cputype(void);
264 void lscpu_ref_cputype(struct lscpu_cputype
*ct
);
265 void lscpu_unref_cputype(struct lscpu_cputype
*ct
);
266 struct lscpu_cputype
*lscpu_add_cputype(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
267 struct lscpu_cputype
*lscpu_cputype_get_default(struct lscpu_cxt
*cxt
);
269 int lscpu_read_cpuinfo(struct lscpu_cxt
*cxt
);
270 int lscpu_read_cpulists(struct lscpu_cxt
*cxt
);
271 int lscpu_read_archext(struct lscpu_cxt
*cxt
);
272 int lscpu_read_vulnerabilities(struct lscpu_cxt
*cxt
);
273 int lscpu_read_numas(struct lscpu_cxt
*cxt
);
275 void lscpu_free_caches(struct lscpu_cache
*caches
, size_t n
);
276 void lscpu_sort_caches(struct lscpu_cache
*caches
, size_t n
);
278 size_t lscpu_get_cache_full_size(struct lscpu_cxt
*cxt
, const char *name
, int *instances
);
279 struct lscpu_cache
*lscpu_cpu_get_cache(struct lscpu_cxt
*cxt
,
280 struct lscpu_cpu
*cpu
, const char *name
);
282 int lscpu_read_topology(struct lscpu_cxt
*cxt
);
283 void lscpu_cputype_free_topology(struct lscpu_cputype
*ct
);
285 float lsblk_cputype_get_maxmhz(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
286 float lsblk_cputype_get_minmhz(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
287 float lsblk_cputype_get_scalmhz(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
289 struct lscpu_arch
*lscpu_read_architecture(struct lscpu_cxt
*cxt
);
290 void lscpu_free_architecture(struct lscpu_arch
*ar
);
292 struct lscpu_virt
*lscpu_read_virtualization(struct lscpu_cxt
*cxt
);
293 void lscpu_free_virtualization(struct lscpu_virt
*virt
);
295 struct lscpu_cpu
*lscpu_new_cpu(int id
);
296 void lscpu_ref_cpu(struct lscpu_cpu
*cpu
);
297 void lscpu_unref_cpu(struct lscpu_cpu
*cpu
);
298 struct lscpu_cpu
*lscpu_get_cpu(struct lscpu_cxt
*cxt
, int logical_id
);
299 int lscpu_cpu_set_type(struct lscpu_cpu
*cpu
, struct lscpu_cputype
*type
);
300 int lscpu_create_cpus(struct lscpu_cxt
*cxt
, cpu_set_t
*cpuset
, size_t setsize
);
301 struct lscpu_cpu
*lscpu_cpus_loopup_by_type(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
303 void lscpu_decode_arm(struct lscpu_cxt
*cxt
);
305 int lookup(char *line
, char *pattern
, char **value
);
307 void *get_mem_chunk(size_t base
, size_t len
, const char *devmem
);
309 struct lscpu_dmi_header
323 /* Processor Information */
324 uint16_t processor_family
;
325 char *processor_manufacturer
;
326 char *processor_version
;
327 uint16_t current_speed
;
332 void to_dmi_header(struct lscpu_dmi_header
*h
, uint8_t *data
);
333 char *dmi_string(const struct lscpu_dmi_header
*dm
, uint8_t s
);
334 int parse_dmi_table(uint16_t len
, uint16_t num
, uint8_t *data
, struct dmi_info
*di
);
335 size_t get_number_of_physical_sockets_from_dmi(void);
336 int dmi_decode_cputype(struct lscpu_cputype
*);