]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - sys-utils/lscpu.h
2 * SPDX-License-Identifier: GPL-2.0-or-later
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 2 of the License, or
7 * (at your option) any later version.
9 * Copyright (C) 2013 Ondrej Oprala <ooprala@redhat.com>
10 * Copyright (C) 2013-2023 Karel Zak <kzak@redhat.com>
22 #include "pathnames.h"
26 #define LSCPU_DEBUG_INIT (1 << 1)
27 #define LSCPU_DEBUG_MISC (1 << 2)
28 #define LSCPU_DEBUG_GATHER (1 << 3)
29 #define LSCPU_DEBUG_TYPE (1 << 4)
30 #define LSCPU_DEBUG_CPU (1 << 5)
31 #define LSCPU_DEBUG_VIRT (1 << 6)
32 #define LSBLK_DEBUG_ALL 0xFFFF
34 UL_DEBUG_DECLARE_MASK(lscpu
);
35 #define DBG(m, x) __UL_DBG(lscpu, LSCPU_DEBUG_, m, x)
36 #define ON_DBG(m, x) __UL_DBG_CALL(lscpu, LSCPU_DEBUG_, m, x)
38 #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lscpu)
41 #define _PATH_SYS_SYSTEM "/sys/devices/system"
42 #define _PATH_SYS_HYP_FEATURES "/sys/hypervisor/properties/features"
43 #define _PATH_SYS_CPU _PATH_SYS_SYSTEM "/cpu"
44 #define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
45 #define _PATH_SYS_DMI "/sys/firmware/dmi/tables/DMI"
46 #define _PATH_ACPI_PPTT "/sys/firmware/acpi/tables/PPTT"
49 int id
; /* unique identifier */
50 int nth
; /* cache<number> from cpuinfo */
53 char *allocation_policy
;
59 unsigned int ways_of_associativity
;
60 unsigned int physical_line_partition
;
61 unsigned int number_of_sets
;
62 unsigned int coherency_line_size
;
67 struct lscpu_cputype
{
71 int vendor_id
; /* created by lscpu_decode_arm() */
72 char *bios_vendor
; /* aarch64 */
73 char *machinetype
; /* s390 */
77 char *bios_modelname
; /* aarch64 */
78 char *bios_family
; /* aarch64 */
79 char *revision
; /* alternative for model (ppc) */
83 char *mtid
; /* maximum thread id (s390) */
84 char *addrsz
; /* address sizes */
85 int dispatching
; /* -1 if not evailable, DIST_* */
86 int freqboost
; /* -1 if not evailable */
88 size_t physsockets
; /* Physical sockets (modules) */
89 size_t physchips
; /* Physical chips */
90 size_t physcoresperchip
; /* Physical cores per chip */
92 size_t nthreads_per_core
;
93 size_t ncores_per_socket
;
94 size_t nsockets_per_book
;
95 size_t nbooks_per_drawer
;
96 size_t ndrawers_per_system
;
98 char *dynamic_mhz
; /* s390; copy from the first CPU */
99 char *static_mhz
; /* s390; copy from the first CPU */
103 cpu_set_t
**coremaps
;
105 cpu_set_t
**socketmaps
;
107 cpu_set_t
**bookmaps
;
109 cpu_set_t
**drawermaps
;
111 unsigned int has_freq
: 1,
113 has_polarization
: 1,
116 size_t nr_socket_on_cluster
; /* the number of sockets if the is_cluster is 1 */
118 char *isa
; /* loongarch */
121 /* dispatching modes */
127 /* cpu polarization */
138 struct lscpu_cputype
*type
;
142 char *bogomips
; /* per-CPU bogomips */
143 char *mhz
; /* freq from cpuinfo */
144 char *dynamic_mhz
; /* from cpuinf for s390 */
145 char *static_mhz
; /* from cpuinf for s390 */
146 float mhz_max_freq
; /* realtime freq from /sys/.../cpuinfo_max_freq */
147 float mhz_min_freq
; /* realtime freq from /sys/.../cpuinfo_min_freq */
155 int polarization
; /* POLAR_* */
156 int address
; /* physical cpu address */
157 int configured
; /* cpu configured */
161 char *name
; /* uname() .machine */
163 unsigned int bit32
:1,
167 struct lscpu_vulnerability
{
172 /* virtualization types */
180 /* hypervisor vendors */
182 VIRT_VENDOR_NONE
= 0,
187 VIRT_VENDOR_IBM
, /* sys-z powervm */
190 VIRT_VENDOR_INNOTEK
, /* VBOX */
192 VIRT_VENDOR_PARALLELS
, /* OpenVZ/VIrtuozzo */
201 char *cpuflag
; /* virtualization flag (vmx, svm) */
202 char *hypervisor
; /* hypervisor software */
203 int vendor
; /* VIRT_VENDOR_* */
204 int type
; /* VIRT_TYPE_* ? */
209 LSCPU_OUTPUT_SUMMARY
= 0, /* default */
211 LSCPU_OUTPUT_PARSABLE
,
212 LSCPU_OUTPUT_READABLE
216 int maxcpus
; /* size in bits of kernel cpu mask */
218 const char *prefix
; /* path to /sys and /proc snapshot or NULL */
220 struct path_cxt
*syscpu
; /* _PATH_SYS_CPU path handler */
221 struct path_cxt
*procfs
; /* /proc path handler */
222 struct path_cxt
*rootfs
; /* / path handler */
225 struct lscpu_cputype
**cputypes
;
227 size_t npossibles
; /* number of possible CPUs */
228 struct lscpu_cpu
**cpus
; /* possible CPUs, contains gaps (cups[n]=NULL) */
231 cpu_set_t
*present
; /* mask with present CPUs */
233 size_t nonlines
; /* aka number of trhreads */
234 cpu_set_t
*online
; /* mask with online CPUs */
236 struct lscpu_arch
*arch
;
237 struct lscpu_virt
*virt
;
239 struct lscpu_vulnerability
*vuls
; /* array of CPU vulnerabilities */
240 size_t nvuls
; /* number of CPU vulnerabilities */
242 struct lscpu_cache
*caches
; /* all instances of the all caches from /sys */
245 struct lscpu_cache
*ecaches
;
246 size_t necaches
; /* extra caches (s390) from /proc/cpuinfo */
248 size_t nnodes
; /* number of NUMA modes */
249 int *idx2nodenum
; /* Support for discontinuous nodes */
250 cpu_set_t
**nodemaps
; /* array with NUMA nodes */
252 int mode
; /* LSCPU_OUTPUT_* */
254 unsigned int noalive
: 1,
263 int is_cluster
; /* For aarch64 if the machine doesn't have ACPI PPTT */
266 #define is_cpu_online(_cxt, _cpu) \
267 ((_cxt) && (_cpu) && (_cxt)->online && \
268 CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->online))
270 #define is_cpu_present(_cxt, _cpu) \
271 ((_cxt) && (_cpu) && (_cxt)->present && \
272 CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->present))
274 struct lscpu_cputype
*lscpu_new_cputype(void);
275 void lscpu_ref_cputype(struct lscpu_cputype
*ct
);
276 void lscpu_unref_cputype(struct lscpu_cputype
*ct
);
277 struct lscpu_cputype
*lscpu_add_cputype(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
278 struct lscpu_cputype
*lscpu_cputype_get_default(struct lscpu_cxt
*cxt
);
280 int lscpu_read_cpuinfo(struct lscpu_cxt
*cxt
);
281 int lscpu_read_cpulists(struct lscpu_cxt
*cxt
);
282 int lscpu_read_archext(struct lscpu_cxt
*cxt
);
283 int lscpu_read_vulnerabilities(struct lscpu_cxt
*cxt
);
284 int lscpu_read_numas(struct lscpu_cxt
*cxt
);
286 void lscpu_free_caches(struct lscpu_cache
*caches
, size_t n
);
287 void lscpu_sort_caches(struct lscpu_cache
*caches
, size_t n
);
289 size_t lscpu_get_cache_full_size(struct lscpu_cxt
*cxt
, const char *name
, int *instances
);
290 struct lscpu_cache
*lscpu_cpu_get_cache(struct lscpu_cxt
*cxt
,
291 struct lscpu_cpu
*cpu
, const char *name
);
293 int lscpu_read_topology(struct lscpu_cxt
*cxt
);
294 void lscpu_cputype_free_topology(struct lscpu_cputype
*ct
);
296 float lsblk_cputype_get_maxmhz(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
297 float lsblk_cputype_get_minmhz(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
298 float lsblk_cputype_get_scalmhz(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
300 struct lscpu_arch
*lscpu_read_architecture(struct lscpu_cxt
*cxt
);
301 void lscpu_free_architecture(struct lscpu_arch
*ar
);
303 struct lscpu_virt
*lscpu_read_virtualization(struct lscpu_cxt
*cxt
);
304 void lscpu_free_virtualization(struct lscpu_virt
*virt
);
306 struct lscpu_cpu
*lscpu_new_cpu(int id
);
307 void lscpu_ref_cpu(struct lscpu_cpu
*cpu
);
308 void lscpu_unref_cpu(struct lscpu_cpu
*cpu
);
309 struct lscpu_cpu
*lscpu_get_cpu(struct lscpu_cxt
*cxt
, int logical_id
);
310 int lscpu_cpu_set_type(struct lscpu_cpu
*cpu
, struct lscpu_cputype
*type
);
311 int lscpu_create_cpus(struct lscpu_cxt
*cxt
, cpu_set_t
*cpuset
, size_t setsize
);
312 struct lscpu_cpu
*lscpu_cpus_loopup_by_type(struct lscpu_cxt
*cxt
, struct lscpu_cputype
*ct
);
314 void lscpu_decode_arm(struct lscpu_cxt
*cxt
);
316 int lookup(char *line
, char *pattern
, char **value
);
318 void *get_mem_chunk(size_t base
, size_t len
, const char *devmem
);
320 struct lscpu_dmi_header
334 /* Processor Information */
335 uint16_t processor_family
;
336 char *processor_manufacturer
;
337 char *processor_version
;
338 uint16_t current_speed
;
343 void to_dmi_header(struct lscpu_dmi_header
*h
, uint8_t *data
);
344 char *dmi_string(const struct lscpu_dmi_header
*dm
, uint8_t s
);
345 int parse_dmi_table(uint16_t len
, uint16_t num
, uint8_t *data
, struct dmi_info
*di
);
346 size_t get_number_of_physical_sockets_from_dmi(void);
347 int dmi_decode_cputype(struct lscpu_cputype
*);