2 * lscpu - CPU architecture information helper
4 * Copyright (C) 2008 Cai Qian <qcai@redhat.com>
5 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it would be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <sys/utsname.h>
34 #include <sys/types.h>
37 #if (defined(__x86_64__) || defined(__i386__))
38 # if !defined( __SANITIZE_ADDRESS__)
39 # define INCLUDE_VMWARE_BDOOR
41 # warning VMWARE detection disabled by __SANITIZE_ADDRESS__
45 #ifdef INCLUDE_VMWARE_BDOOR
55 #if defined(HAVE_LIBRTAS)
59 #include <libsmartcols.h>
68 #include "closestream.h"
75 #define _PATH_SYS_SYSTEM "/sys/devices/system"
76 #define _PATH_SYS_HYP_FEATURES "/sys/hypervisor/properties/features"
77 #define _PATH_SYS_CPU _PATH_SYS_SYSTEM "/cpu"
78 #define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
79 #define _PATH_PROC_XEN "/proc/xen"
80 #define _PATH_PROC_XENCAP _PATH_PROC_XEN "/capabilities"
81 #define _PATH_PROC_CPUINFO "/proc/cpuinfo"
82 #define _PATH_PROC_PCIDEVS "/proc/bus/pci/devices"
83 #define _PATH_PROC_SYSINFO "/proc/sysinfo"
84 #define _PATH_PROC_STATUS "/proc/self/status"
85 #define _PATH_PROC_VZ "/proc/vz"
86 #define _PATH_PROC_BC "/proc/bc"
87 #define _PATH_PROC_DEVICETREE "/proc/device-tree"
88 #define _PATH_DEV_MEM "/dev/mem"
89 #define _PATH_PROC_OSRELEASE "/proc/sys/kernel/osrelease"
91 /* Xen Domain feature flag used for /sys/hypervisor/properties/features */
92 #define XENFEAT_supervisor_mode_kernel 3
93 #define XENFEAT_mmu_pt_update_preserve_ad 5
94 #define XENFEAT_hvm_callback_vector 8
96 #define XEN_FEATURES_PV_MASK (1U << XENFEAT_mmu_pt_update_preserve_ad)
97 #define XEN_FEATURES_PVH_MASK ( (1U << XENFEAT_supervisor_mode_kernel) \
98 | (1U << XENFEAT_hvm_callback_vector) )
100 /* virtualization types */
107 static const char *virt_types
[] = {
108 [VIRT_NONE
] = N_("none"),
109 [VIRT_PARA
] = N_("para"),
110 [VIRT_FULL
] = N_("full"),
111 [VIRT_CONT
] = N_("container"),
114 static const char *hv_vendors
[] = {
118 [HYPER_MSHV
] = "Microsoft",
119 [HYPER_VMWARE
] = "VMware",
121 [HYPER_VSERVER
] = "Linux-VServer",
122 [HYPER_UML
] = "User-mode Linux",
123 [HYPER_INNOTEK
] = "Innotek GmbH",
124 [HYPER_HITACHI
] = "Hitachi",
125 [HYPER_PARALLELS
] = "Parallels",
126 [HYPER_VBOX
] = "Oracle",
127 [HYPER_OS400
] = "OS/400",
128 [HYPER_PHYP
] = "pHyp",
129 [HYPER_SPAR
] = "Unisys s-Par",
130 [HYPER_WSL
] = "Windows Subsystem for Linux"
133 static const int hv_vendor_pci
[] = {
134 [HYPER_NONE
] = 0x0000,
135 [HYPER_XEN
] = 0x5853,
136 [HYPER_KVM
] = 0x0000,
137 [HYPER_MSHV
] = 0x1414,
138 [HYPER_VMWARE
] = 0x15ad,
139 [HYPER_VBOX
] = 0x80ee,
142 static const int hv_graphics_pci
[] = {
143 [HYPER_NONE
] = 0x0000,
144 [HYPER_XEN
] = 0x0001,
145 [HYPER_KVM
] = 0x0000,
146 [HYPER_MSHV
] = 0x5353,
147 [HYPER_VMWARE
] = 0x0710,
148 [HYPER_VBOX
] = 0xbeef,
153 MODE_32BIT
= (1 << 1),
154 MODE_64BIT
= (1 << 2)
157 /* cache(s) description */
163 cpu_set_t
**sharedmaps
;
166 /* dispatching modes */
172 static const char *disp_modes
[] = {
173 [DISP_HORIZONTAL
] = N_("horizontal"),
174 [DISP_VERTICAL
] = N_("vertical")
177 /* cpu polarization */
186 struct polarization_modes
{
191 static struct polarization_modes polar_modes
[] = {
192 [POLAR_UNKNOWN
] = {"U", "-"},
193 [POLAR_VLOW
] = {"VL", "vert-low"},
194 [POLAR_VMEDIUM
] = {"VM", "vert-medium"},
195 [POLAR_VHIGH
] = {"VH", "vert-high"},
196 [POLAR_HORIZONTAL
] = {"H", "horizontal"},
199 /* global description */
203 char *machinetype
; /* s390 */
207 char *revision
; /* alternative for model (ppc) */
208 char *cpu
; /* alternative for modelname (ppc, sparc) */
209 char *virtflag
; /* virtualization flag (vmx, svm) */
210 char *hypervisor
; /* hypervisor software */
211 int hyper
; /* hypervisor vendor ID */
212 int virtype
; /* VIRT_PARA|FULL|NONE ? */
214 char *dynamic_mhz
; /* dynamic mega hertz (s390) */
215 char *static_mhz
; /* static mega hertz (s390) */
216 char **maxmhz
; /* maximum mega hertz */
217 char **minmhz
; /* minimum mega hertz */
221 char *mtid
; /* maximum thread id (s390) */
222 int dispatching
; /* none, horizontal or vertical */
223 int mode
; /* rm, lm or/and tm */
225 int ncpuspos
; /* maximal possible CPUs */
226 int ncpus
; /* number of present CPUs */
227 cpu_set_t
*present
; /* mask with present CPUs */
228 cpu_set_t
*online
; /* mask with online CPUs */
230 int nthreads
; /* number of online threads */
233 struct cpu_cache
*caches
;
235 int necaches
; /* extra caches (s390) */
236 struct cpu_cache
*ecaches
;
239 * All maps are sequentially indexed (0..ncpuspos), the array index
240 * does not have match with cpuX number as presented by kernel. You
241 * have to use real_cpu_num() to get the real cpuX number.
243 * For example, the possible system CPUs are: 1,3,5, it means that
244 * ncpuspos=3, so all arrays are in range 0..3.
246 int *idx2cpunum
; /* mapping index to CPU num */
248 int nnodes
; /* number of NUMA modes */
249 int *idx2nodenum
; /* Support for discontinuous nodes */
250 cpu_set_t
**nodemaps
; /* array with NUMA nodes */
252 /* drawers -- based on drawer_siblings (internal kernel map of cpuX's
253 * hardware threads within the same drawer */
254 int ndrawers
; /* number of all online drawers */
255 cpu_set_t
**drawermaps
; /* unique drawer_siblings */
256 int *drawerids
; /* physical drawer ids */
258 /* books -- based on book_siblings (internal kernel map of cpuX's
259 * hardware threads within the same book */
260 int nbooks
; /* number of all online books */
261 cpu_set_t
**bookmaps
; /* unique book_siblings */
262 int *bookids
; /* physical book ids */
264 /* sockets -- based on core_siblings (internal kernel map of cpuX's
265 * hardware threads within the same physical_package_id (socket)) */
266 int nsockets
; /* number of all online sockets */
267 cpu_set_t
**socketmaps
; /* unique core_siblings */
268 int *socketids
; /* physical socket ids */
270 /* cores -- based on thread_siblings (internal kernel map of cpuX's
271 * hardware threads within the same core as cpuX) */
272 int ncores
; /* number of all online cores */
273 cpu_set_t
**coremaps
; /* unique thread_siblings */
274 int *coreids
; /* physical core ids */
276 int *polarization
; /* cpu polarization */
277 int *addresses
; /* physical cpu addresses */
278 int *configured
; /* cpu configured */
279 int physsockets
; /* Physical sockets (modules) */
280 int physchips
; /* Physical chips */
281 int physcoresperchip
; /* Physical cores per chip */
285 OUTPUT_SUMMARY
= 0, /* default */
286 OUTPUT_PARSABLE
, /* -p */
287 OUTPUT_READABLE
, /* -e */
291 SYSTEM_LIVE
= 0, /* analyzing a live system */
292 SYSTEM_SNAPSHOT
, /* analyzing a snapshot of a different system */
295 struct lscpu_modifier
{
296 int mode
; /* OUTPUT_* */
297 int system
; /* SYSTEM_* */
298 unsigned int hex
:1, /* print CPU masks rather than CPU lists */
299 compat
:1, /* use backwardly compatible format */
300 online
:1, /* print online CPUs */
301 offline
:1, /* print offline CPUs */
302 json
:1, /* JSON output format */
303 physical
:1; /* use physical numbers */
306 static int maxcpus
; /* size in bits of kernel cpu mask */
308 #define is_cpu_online(_d, _cpu) \
309 ((_d) && (_d)->online ? \
310 CPU_ISSET_S((_cpu), CPU_ALLOC_SIZE(maxcpus), (_d)->online) : 0)
311 #define is_cpu_present(_d, _cpu) \
312 ((_d) && (_d)->present ? \
313 CPU_ISSET_S((_cpu), CPU_ALLOC_SIZE(maxcpus), (_d)->present) : 0)
315 #define real_cpu_num(_d, _i) ((_d)->idx2cpunum[(_i)])
336 /* column description
338 struct lscpu_coldesc
{
342 unsigned int is_abbr
:1; /* name is abbreviation */
345 static struct lscpu_coldesc coldescs
[] =
347 [COL_CPU
] = { "CPU", N_("logical CPU number"), 1 },
348 [COL_CORE
] = { "CORE", N_("logical core number") },
349 [COL_SOCKET
] = { "SOCKET", N_("logical socket number") },
350 [COL_NODE
] = { "NODE", N_("logical NUMA node number") },
351 [COL_BOOK
] = { "BOOK", N_("logical book number") },
352 [COL_DRAWER
] = { "DRAWER", N_("logical drawer number") },
353 [COL_CACHE
] = { "CACHE", N_("shows how caches are shared between CPUs") },
354 [COL_POLARIZATION
] = { "POLARIZATION", N_("CPU dispatching mode on virtual hardware") },
355 [COL_ADDRESS
] = { "ADDRESS", N_("physical address of a CPU") },
356 [COL_CONFIGURED
] = { "CONFIGURED", N_("shows if the hypervisor has allocated the CPU") },
357 [COL_ONLINE
] = { "ONLINE", N_("shows if Linux currently makes use of the CPU") },
358 [COL_MAXMHZ
] = { "MAXMHZ", N_("shows the maximum MHz of the CPU") },
359 [COL_MINMHZ
] = { "MINMHZ", N_("shows the minimum MHz of the CPU") }
363 column_name_to_id(const char *name
, size_t namesz
)
367 for (i
= 0; i
< ARRAY_SIZE(coldescs
); i
++) {
368 const char *cn
= coldescs
[i
].name
;
370 if (!strncasecmp(name
, cn
, namesz
) && !*(cn
+ namesz
))
373 warnx(_("unknown column: %s"), name
);
377 /* Lookup a pattern and get the value from cpuinfo.
380 * "<pattern> : <key>"
383 lookup(char *line
, char *pattern
, char **value
)
386 int len
= strlen(pattern
);
388 /* don't re-fill already found tags, first one wins */
389 if (!*line
|| *value
)
393 if (strncmp(line
, pattern
, len
))
397 for (p
= line
+ len
; isspace(*p
); p
++);
404 for (++p
; isspace(*p
); p
++);
412 len
= strlen(line
) - 1;
413 for (p
= line
+ len
; isspace(*(p
-1)); p
--);
420 /* Parse extra cache lines contained within /proc/cpuinfo but which are not
421 * part of the cache topology information within the sysfs filesystem.
422 * This is true for all shared caches on e.g. s390. When there are layers of
423 * hypervisors in between it is not knows which CPUs share which caches.
424 * Therefore information about shared caches is only available in
427 * "cache<nr> : level=<lvl> type=<type> scope=<scope> size=<size> line_size=<lsz> associativity=<as>"
430 lookup_cache(char *line
, struct lscpu_desc
*desc
)
432 struct cpu_cache
*cache
;
437 /* Make sure line starts with "cache<nr> :" */
438 if (strncmp(line
, "cache", 5))
440 for (p
= line
+ 5; isdigit(*p
); p
++);
441 for (; isspace(*p
); p
++);
445 p
= strstr(line
, "scope=") + 6;
446 /* Skip private caches, also present in sysfs */
447 if (!p
|| strncmp(p
, "Private", 7) == 0)
449 p
= strstr(line
, "level=");
450 if (!p
|| sscanf(p
, "level=%d", &level
) != 1)
452 p
= strstr(line
, "type=") + 5;
456 if (strncmp(p
, "Data", 4) == 0)
458 if (strncmp(p
, "Instruction", 11) == 0)
460 p
= strstr(line
, "size=");
461 if (!p
|| sscanf(p
, "size=%lld", &size
) != 1)
465 desc
->ecaches
= xrealloc(desc
->ecaches
,
466 desc
->necaches
* sizeof(struct cpu_cache
));
467 cache
= &desc
->ecaches
[desc
->necaches
- 1];
468 memset(cache
, 0 , sizeof(*cache
));
470 xasprintf(&cache
->name
, "L%d%c", level
, type
);
472 xasprintf(&cache
->name
, "L%d", level
);
473 xasprintf(&cache
->size
, "%lldK", size
);
477 /* Don't init the mode for platforms where we are not able to
478 * detect that CPU supports 64-bit mode.
481 init_mode(struct lscpu_modifier
*mod
)
485 if (mod
->system
== SYSTEM_SNAPSHOT
)
486 /* reading info from any /{sys,proc} dump, don't mix it with
487 * information about our real CPU */
490 #if defined(__alpha__) || defined(__ia64__)
491 m
|= MODE_64BIT
; /* 64bit platforms only */
493 /* platforms with 64bit flag in /proc/cpuinfo, define
494 * 32bit default here */
495 #if defined(__i386__) || defined(__x86_64__) || \
496 defined(__s390x__) || defined(__s390__) || defined(__sparc_v9__)
502 #if defined(HAVE_LIBRTAS)
503 #define PROCESSOR_MODULE_INFO 43
504 static int strbe16toh(const char *buf
, int offset
)
506 return (buf
[offset
] << 8) + buf
[offset
+1];
509 static void read_physical_info_powerpc(struct lscpu_desc
*desc
)
514 desc
->physsockets
= desc
->physchips
= desc
->physcoresperchip
= 0;
516 rc
= rtas_get_sysparm(PROCESSOR_MODULE_INFO
, sizeof(buf
), buf
);
520 len
= strbe16toh(buf
, 0);
524 ntypes
= strbe16toh(buf
, 2);
530 desc
->physsockets
= strbe16toh(buf
, 4);
531 desc
->physchips
= strbe16toh(buf
, 6);
532 desc
->physcoresperchip
= strbe16toh(buf
, 8);
535 static void read_physical_info_powerpc(
536 struct lscpu_desc
*desc
__attribute__((__unused__
)))
542 read_basicinfo(struct lscpu_desc
*desc
, struct lscpu_modifier
*mod
)
544 FILE *fp
= path_fopen("r", 1, _PATH_PROC_CPUINFO
);
546 struct utsname utsbuf
;
550 if (uname(&utsbuf
) == -1)
551 err(EXIT_FAILURE
, _("error: uname failed"));
552 desc
->arch
= xstrdup(utsbuf
.machine
);
555 while (fgets(buf
, sizeof(buf
), fp
) != NULL
) {
556 if (lookup(buf
, "vendor", &desc
->vendor
)) ;
557 else if (lookup(buf
, "vendor_id", &desc
->vendor
)) ;
558 else if (lookup(buf
, "family", &desc
->family
)) ;
559 else if (lookup(buf
, "cpu family", &desc
->family
)) ;
560 else if (lookup(buf
, "model", &desc
->model
)) ;
561 else if (lookup(buf
, "model name", &desc
->modelname
)) ;
562 else if (lookup(buf
, "stepping", &desc
->stepping
)) ;
563 else if (lookup(buf
, "cpu MHz", &desc
->mhz
)) ;
564 else if (lookup(buf
, "cpu MHz dynamic", &desc
->dynamic_mhz
)) ; /* s390 */
565 else if (lookup(buf
, "cpu MHz static", &desc
->static_mhz
)) ; /* s390 */
566 else if (lookup(buf
, "flags", &desc
->flags
)) ; /* x86 */
567 else if (lookup(buf
, "features", &desc
->flags
)) ; /* s390 */
568 else if (lookup(buf
, "Features", &desc
->flags
)) ; /* aarch64 */
569 else if (lookup(buf
, "type", &desc
->flags
)) ; /* sparc64 */
570 else if (lookup(buf
, "bogomips", &desc
->bogomips
)) ;
571 else if (lookup(buf
, "BogoMIPS", &desc
->bogomips
)) ; /* aarch64 */
572 else if (lookup(buf
, "bogomips per cpu", &desc
->bogomips
)) ; /* s390 */
573 else if (lookup(buf
, "cpu", &desc
->cpu
)) ;
574 else if (lookup(buf
, "revision", &desc
->revision
)) ;
575 else if (lookup(buf
, "CPU revision", &desc
->revision
)) ; /* aarch64 */
576 else if (lookup(buf
, "max thread id", &desc
->mtid
)) ; /* s390 */
577 else if (lookup_cache(buf
, desc
)) ;
582 desc
->mode
= init_mode(mod
);
585 snprintf(buf
, sizeof(buf
), " %s ", desc
->flags
);
586 if (strstr(buf
, " svm "))
587 desc
->virtflag
= xstrdup("svm");
588 else if (strstr(buf
, " vmx "))
589 desc
->virtflag
= xstrdup("vmx");
590 if (strstr(buf
, " lm "))
591 desc
->mode
|= MODE_32BIT
| MODE_64BIT
; /* x86_64 */
592 if (strstr(buf
, " zarch "))
593 desc
->mode
|= MODE_32BIT
| MODE_64BIT
; /* s390x */
594 if (strstr(buf
, " sun4v ") || strstr(buf
, " sun4u "))
595 desc
->mode
|= MODE_32BIT
| MODE_64BIT
; /* sparc64 */
598 if (desc
->arch
&& mod
->system
!= SYSTEM_SNAPSHOT
) {
599 if (strcmp(desc
->arch
, "ppc64") == 0)
600 desc
->mode
|= MODE_32BIT
| MODE_64BIT
;
601 else if (strcmp(desc
->arch
, "ppc") == 0)
602 desc
->mode
|= MODE_32BIT
;
607 if (path_exist(_PATH_SYS_CPU
"/kernel_max"))
608 /* note that kernel_max is maximum index [NR_CPUS-1] */
609 maxcpus
= path_read_s32(_PATH_SYS_CPU
"/kernel_max") + 1;
611 else if (mod
->system
== SYSTEM_LIVE
)
612 /* the root is '/' so we are working with data from the current kernel */
613 maxcpus
= get_max_number_of_cpus();
616 /* error or we are reading some /sys snapshot instead of the
617 * real /sys, let's use any crazy number... */
620 setsize
= CPU_ALLOC_SIZE(maxcpus
);
622 if (path_exist(_PATH_SYS_CPU
"/possible")) {
623 cpu_set_t
*tmp
= path_read_cpulist(maxcpus
, _PATH_SYS_CPU
"/possible");
626 desc
->ncpuspos
= CPU_COUNT_S(setsize
, tmp
);
627 desc
->idx2cpunum
= xcalloc(desc
->ncpuspos
, sizeof(int));
629 for (num
= 0, idx
= 0; num
< maxcpus
; num
++) {
630 if (CPU_ISSET(num
, tmp
))
631 desc
->idx2cpunum
[idx
++] = num
;
635 err(EXIT_FAILURE
, _("failed to determine number of CPUs: %s"),
636 _PATH_SYS_CPU
"/possible");
639 /* get mask for present CPUs */
640 if (path_exist(_PATH_SYS_CPU
"/present")) {
641 desc
->present
= path_read_cpulist(maxcpus
, _PATH_SYS_CPU
"/present");
642 desc
->ncpus
= CPU_COUNT_S(setsize
, desc
->present
);
645 /* get mask for online CPUs */
646 if (path_exist(_PATH_SYS_CPU
"/online")) {
647 desc
->online
= path_read_cpulist(maxcpus
, _PATH_SYS_CPU
"/online");
648 desc
->nthreads
= CPU_COUNT_S(setsize
, desc
->online
);
651 /* get dispatching mode */
652 if (path_exist(_PATH_SYS_CPU
"/dispatching"))
653 desc
->dispatching
= path_read_s32(_PATH_SYS_CPU
"/dispatching");
655 desc
->dispatching
= -1;
657 if (mod
->system
== SYSTEM_LIVE
)
658 read_physical_info_powerpc(desc
);
660 if ((fp
= path_fopen("r", 0, _PATH_PROC_SYSINFO
))) {
661 while (fgets(buf
, sizeof(buf
), fp
) != NULL
&& !desc
->machinetype
)
662 lookup(buf
, "Type", &desc
->machinetype
);
668 has_pci_device(unsigned int vendor
, unsigned int device
)
671 unsigned int num
, fn
, ven
, dev
;
674 f
= path_fopen("r", 0, _PATH_PROC_PCIDEVS
);
678 /* for more details about bus/pci/devices format see
679 * drivers/pci/proc.c in linux kernel
681 while(fscanf(f
, "%02x%02x\t%04x%04x\t%*[^\n]",
682 &num
, &fn
, &ven
, &dev
) == 4) {
684 if (ven
== vendor
&& dev
== device
)
694 #if defined(__x86_64__) || defined(__i386__)
697 * This CPUID leaf returns the information about the hypervisor.
698 * EAX : maximum input value for CPUID supported by the hypervisor.
699 * EBX, ECX, EDX : Hypervisor vendor ID signature. E.g. VMwareVMware.
701 #define HYPERVISOR_INFO_LEAF 0x40000000
704 cpuid(unsigned int op
, unsigned int *eax
, unsigned int *ebx
,
705 unsigned int *ecx
, unsigned int *edx
)
708 #if defined(__PIC__) && defined(__i386__)
709 /* x86 PIC cannot clobber ebx -- gcc bitches */
725 read_hypervisor_cpuid(struct lscpu_desc
*desc
)
727 unsigned int eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
728 char hyper_vendor_id
[13];
730 memset(hyper_vendor_id
, 0, sizeof(hyper_vendor_id
));
732 cpuid(HYPERVISOR_INFO_LEAF
, &eax
, &ebx
, &ecx
, &edx
);
733 memcpy(hyper_vendor_id
+ 0, &ebx
, 4);
734 memcpy(hyper_vendor_id
+ 4, &ecx
, 4);
735 memcpy(hyper_vendor_id
+ 8, &edx
, 4);
736 hyper_vendor_id
[12] = '\0';
738 if (!hyper_vendor_id
[0])
741 if (!strncmp("XenVMMXenVMM", hyper_vendor_id
, 12))
742 desc
->hyper
= HYPER_XEN
;
743 else if (!strncmp("KVMKVMKVM", hyper_vendor_id
, 9))
744 desc
->hyper
= HYPER_KVM
;
745 else if (!strncmp("Microsoft Hv", hyper_vendor_id
, 12))
746 desc
->hyper
= HYPER_MSHV
;
747 else if (!strncmp("VMwareVMware", hyper_vendor_id
, 12))
748 desc
->hyper
= HYPER_VMWARE
;
749 else if (!strncmp("UnisysSpar64", hyper_vendor_id
, 12))
750 desc
->hyper
= HYPER_SPAR
;
753 #else /* ! (__x86_64__ || __i386__) */
755 read_hypervisor_cpuid(struct lscpu_desc
*desc
__attribute__((__unused__
)))
760 static int is_compatible(const char *path
, const char *str
)
762 FILE *fd
= path_fopen("r", 0, "%s", path
);
768 memset(buf
, 0, sizeof(buf
));
769 len
= fread(buf
, 1, sizeof(buf
) - 1, fd
);
772 for (i
= 0; i
< len
;) {
773 if (!strcmp(&buf
[i
], str
))
775 i
+= strlen(&buf
[i
]);
784 read_hypervisor_powerpc(struct lscpu_desc
*desc
)
786 assert(!desc
->hyper
);
788 /* IBM iSeries: legacy, para-virtualized on top of OS/400 */
789 if (path_exist("/proc/iSeries")) {
790 desc
->hyper
= HYPER_OS400
;
791 desc
->virtype
= VIRT_PARA
;
793 /* PowerNV (POWER Non-Virtualized, bare-metal) */
794 } else if (is_compatible(_PATH_PROC_DEVICETREE
"/compatible", "ibm,powernv")) {
795 desc
->hyper
= HYPER_NONE
;
796 desc
->virtype
= VIRT_NONE
;
798 /* PowerVM (IBM's proprietary hypervisor, aka pHyp) */
799 } else if (path_exist(_PATH_PROC_DEVICETREE
"/ibm,partition-name")
800 && path_exist(_PATH_PROC_DEVICETREE
"/hmc-managed?")
801 && !path_exist(_PATH_PROC_DEVICETREE
"/chosen/qemu,graphic-width")) {
803 desc
->hyper
= HYPER_PHYP
;
804 desc
->virtype
= VIRT_PARA
;
805 fd
= path_fopen("r", 0, _PATH_PROC_DEVICETREE
"/ibm,partition-name");
808 if (fscanf(fd
, "%255s", buf
) == 1 && !strcmp(buf
, "full"))
809 desc
->virtype
= VIRT_NONE
;
814 } else if (is_compatible(_PATH_PROC_DEVICETREE
"/compatible", "qemu,pseries")) {
815 desc
->hyper
= HYPER_KVM
;
816 desc
->virtype
= VIRT_PARA
;
821 #ifdef INCLUDE_VMWARE_BDOOR
823 #define VMWARE_BDOOR_MAGIC 0x564D5868
824 #define VMWARE_BDOOR_PORT 0x5658
825 #define VMWARE_BDOOR_CMD_GETVERSION 10
827 static UL_ASAN_BLACKLIST
828 void vmware_bdoor(uint32_t *eax
, uint32_t *ebx
, uint32_t *ecx
, uint32_t *edx
)
831 #if defined(__PIC__) && defined(__i386__)
832 /* x86 PIC cannot clobber ebx -- gcc bitches */
844 : "0" (VMWARE_BDOOR_MAGIC
),
845 "1" (VMWARE_BDOOR_CMD_GETVERSION
),
846 "2" (VMWARE_BDOOR_PORT
),
851 static jmp_buf segv_handler_env
;
854 segv_handler(__attribute__((__unused__
)) int sig
,
855 __attribute__((__unused__
)) siginfo_t
*info
,
856 __attribute__((__unused__
)) void *ignored
)
858 siglongjmp(segv_handler_env
, 1);
862 is_vmware_platform(void)
864 uint32_t eax
, ebx
, ecx
, edx
;
865 struct sigaction act
, oact
;
868 * FIXME: Not reliable for non-root users. Note it works as expected if
869 * vmware_bdoor() is not optimized for PIE, but then it fails to build
870 * on 32bit x86 systems. See lscpu git log for more details (commit
871 * 7845b91dbc7690064a2be6df690e4aaba728fb04). kzak [3-Nov-2016]
877 * The assembly routine for vmware detection works
878 * fine under vmware, even if ran as regular user. But
879 * on real HW or under other hypervisors, it segfaults (which is
880 * expected). So we temporarily install SIGSEGV handler to catch
881 * the signal. All this magic is needed because lscpu
882 * isn't supposed to require root privileges.
884 if (sigsetjmp(segv_handler_env
, 1))
887 memset(&act
, 0, sizeof(act
));
888 act
.sa_sigaction
= segv_handler
;
889 act
.sa_flags
= SA_SIGINFO
;
891 if (sigaction(SIGSEGV
, &act
, &oact
))
892 err(EXIT_FAILURE
, _("cannot set signal handler"));
894 vmware_bdoor(&eax
, &ebx
, &ecx
, &edx
);
896 if (sigaction(SIGSEGV
, &oact
, NULL
))
897 err(EXIT_FAILURE
, _("cannot restore signal handler"));
899 return eax
!= (uint32_t)-1 && ebx
== VMWARE_BDOOR_MAGIC
;
902 #else /* ! INCLUDE_VMWARE_BDOOR */
905 is_vmware_platform(void)
910 #endif /* INCLUDE_VMWARE_BDOOR */
913 read_hypervisor(struct lscpu_desc
*desc
, struct lscpu_modifier
*mod
)
917 /* We have to detect WSL first. is_vmware_platform() crashes on Windows 10. */
919 if ((fd
= path_fopen("r", 0, _PATH_PROC_OSRELEASE
))) {
922 if (fgets(buf
, sizeof(buf
), fd
) != NULL
) {
923 if (strstr(buf
, "Microsoft")) {
924 desc
->hyper
= HYPER_WSL
;
925 desc
->virtype
= VIRT_CONT
;
933 if (mod
->system
!= SYSTEM_SNAPSHOT
) {
934 read_hypervisor_cpuid(desc
);
936 desc
->hyper
= read_hypervisor_dmi();
937 if (!desc
->hyper
&& is_vmware_platform())
938 desc
->hyper
= HYPER_VMWARE
;
942 desc
->virtype
= VIRT_FULL
;
944 if (desc
->hyper
== HYPER_XEN
) {
947 fd
= path_fopen("r", 0, _PATH_SYS_HYP_FEATURES
);
948 if (fd
&& fscanf(fd
, "%x", &features
) == 1) {
950 if (features
& XEN_FEATURES_PV_MASK
)
951 desc
->virtype
= VIRT_PARA
;
953 else if ((features
& XEN_FEATURES_PVH_MASK
)
954 == XEN_FEATURES_PVH_MASK
)
955 desc
->virtype
= VIRT_PARA
;
958 err(EXIT_FAILURE
, _("failed to read from: %s"),
959 _PATH_SYS_HYP_FEATURES
);
962 } else if (read_hypervisor_powerpc(desc
) > 0) {}
964 /* Xen para-virt or dom0 */
965 else if (path_exist(_PATH_PROC_XEN
)) {
967 fd
= path_fopen("r", 0, _PATH_PROC_XENCAP
);
972 if (fscanf(fd
, "%255s", buf
) == 1 &&
973 !strcmp(buf
, "control_d"))
977 desc
->virtype
= dom0
? VIRT_NONE
: VIRT_PARA
;
978 desc
->hyper
= HYPER_XEN
;
980 /* Xen full-virt on non-x86_64 */
981 } else if (has_pci_device( hv_vendor_pci
[HYPER_XEN
], hv_graphics_pci
[HYPER_XEN
])) {
982 desc
->hyper
= HYPER_XEN
;
983 desc
->virtype
= VIRT_FULL
;
984 } else if (has_pci_device( hv_vendor_pci
[HYPER_VMWARE
], hv_graphics_pci
[HYPER_VMWARE
])) {
985 desc
->hyper
= HYPER_VMWARE
;
986 desc
->virtype
= VIRT_FULL
;
987 } else if (has_pci_device( hv_vendor_pci
[HYPER_VBOX
], hv_graphics_pci
[HYPER_VBOX
])) {
988 desc
->hyper
= HYPER_VBOX
;
989 desc
->virtype
= VIRT_FULL
;
992 } else if ((fd
= path_fopen("r", 0, _PATH_PROC_SYSINFO
))) {
995 desc
->hyper
= HYPER_IBM
;
996 desc
->hypervisor
= "PR/SM";
997 desc
->virtype
= VIRT_FULL
;
998 while (fgets(buf
, sizeof(buf
), fd
) != NULL
) {
1001 if (!strstr(buf
, "Control Program:"))
1003 if (!strstr(buf
, "KVM"))
1004 desc
->hyper
= HYPER_IBM
;
1006 desc
->hyper
= HYPER_KVM
;
1007 str
= strchr(buf
, ':');
1010 xasprintf(&str
, "%s", str
+ 1);
1012 /* remove leading, trailing and repeating whitespace */
1015 desc
->hypervisor
= str
;
1016 str
+= strlen(str
) - 1;
1017 while ((*str
== '\n') || (*str
== ' '))
1019 while ((str
= strstr(desc
->hypervisor
, " ")))
1020 memmove(str
, str
+ 1, strlen(str
));
1025 /* OpenVZ/Virtuozzo - /proc/vz dir should exist
1026 * /proc/bc should not */
1027 else if (path_exist(_PATH_PROC_VZ
) && !path_exist(_PATH_PROC_BC
)) {
1028 desc
->hyper
= HYPER_PARALLELS
;
1029 desc
->virtype
= VIRT_CONT
;
1032 } else if (desc
->vendor
&&
1033 (strcmp(desc
->vendor
, "PowerVM Lx86") == 0 ||
1034 strcmp(desc
->vendor
, "IBM/S390") == 0)) {
1035 desc
->hyper
= HYPER_IBM
;
1036 desc
->virtype
= VIRT_FULL
;
1038 /* User-mode-linux */
1039 } else if (desc
->modelname
&& strstr(desc
->modelname
, "UML")) {
1040 desc
->hyper
= HYPER_UML
;
1041 desc
->virtype
= VIRT_PARA
;
1044 } else if ((fd
= path_fopen("r", 0, _PATH_PROC_STATUS
))) {
1048 while (fgets(buf
, sizeof(buf
), fd
) != NULL
) {
1049 if (lookup(buf
, "VxID", &val
))
1057 while (isdigit(*val
))
1060 desc
->hyper
= HYPER_VSERVER
;
1061 desc
->virtype
= VIRT_CONT
;
1068 /* add @set to the @ary, unnecessary set is deallocated. */
1069 static int add_cpuset_to_array(cpu_set_t
**ary
, int *items
, cpu_set_t
*set
)
1072 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1077 for (i
= 0; i
< *items
; i
++) {
1078 if (CPU_EQUAL_S(setsize
, set
, ary
[i
]))
1091 read_topology(struct lscpu_desc
*desc
, int idx
)
1093 cpu_set_t
*thread_siblings
, *core_siblings
;
1094 cpu_set_t
*book_siblings
, *drawer_siblings
;
1095 int coreid
, socketid
, bookid
, drawerid
;
1096 int i
, num
= real_cpu_num(desc
, idx
);
1098 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/topology/thread_siblings", num
))
1101 thread_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
1102 "/cpu%d/topology/thread_siblings", num
);
1103 core_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
1104 "/cpu%d/topology/core_siblings", num
);
1105 book_siblings
= NULL
;
1106 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/book_siblings", num
))
1107 book_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
1108 "/cpu%d/topology/book_siblings", num
);
1109 drawer_siblings
= NULL
;
1110 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/drawer_siblings", num
))
1111 drawer_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
1112 "/cpu%d/topology/drawer_siblings", num
);
1114 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/core_id", num
))
1115 coreid
= path_read_s32(_PATH_SYS_CPU
1116 "/cpu%d/topology/core_id", num
);
1118 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/physical_package_id", num
))
1119 socketid
= path_read_s32(_PATH_SYS_CPU
1120 "/cpu%d/topology/physical_package_id", num
);
1122 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/book_id", num
))
1123 bookid
= path_read_s32(_PATH_SYS_CPU
1124 "/cpu%d/topology/book_id", num
);
1126 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/drawer_id", num
))
1127 drawerid
= path_read_s32(_PATH_SYS_CPU
1128 "/cpu%d/topology/drawer_id", num
);
1130 if (!desc
->coremaps
) {
1131 int ndrawers
, nbooks
, nsockets
, ncores
, nthreads
;
1132 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1134 /* threads within one core */
1135 nthreads
= CPU_COUNT_S(setsize
, thread_siblings
);
1139 /* cores within one socket */
1140 ncores
= CPU_COUNT_S(setsize
, core_siblings
) / nthreads
;
1144 /* number of sockets within one book. Because of odd /
1145 * non-present cpu maps and to keep calculation easy we make
1146 * sure that nsockets and nbooks is at least 1.
1148 nsockets
= desc
->ncpus
/ nthreads
/ ncores
;
1152 /* number of books */
1153 nbooks
= desc
->ncpus
/ nthreads
/ ncores
/ nsockets
;
1157 /* number of drawers */
1158 ndrawers
= desc
->ncpus
/ nbooks
/ nthreads
/ ncores
/ nsockets
;
1162 /* all threads, see also read_basicinfo()
1163 * -- fallback for kernels without
1164 * /sys/devices/system/cpu/online.
1166 if (!desc
->nthreads
)
1167 desc
->nthreads
= ndrawers
* nbooks
* nsockets
* ncores
* nthreads
;
1169 /* For each map we make sure that it can have up to ncpuspos
1170 * entries. This is because we cannot reliably calculate the
1171 * number of cores, sockets and books on all architectures.
1172 * E.g. completely virtualized architectures like s390 may
1173 * have multiple sockets of different sizes.
1175 desc
->coremaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
1176 desc
->socketmaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
1177 desc
->coreids
= xcalloc(desc
->ncpuspos
, sizeof(*desc
->drawerids
));
1178 desc
->socketids
= xcalloc(desc
->ncpuspos
, sizeof(*desc
->drawerids
));
1179 for (i
= 0; i
< desc
->ncpuspos
; i
++)
1180 desc
->coreids
[i
] = desc
->socketids
[i
] = -1;
1181 if (book_siblings
) {
1182 desc
->bookmaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
1183 desc
->bookids
= xcalloc(desc
->ncpuspos
, sizeof(*desc
->drawerids
));
1184 for (i
= 0; i
< desc
->ncpuspos
; i
++)
1185 desc
->bookids
[i
] = -1;
1187 if (drawer_siblings
) {
1188 desc
->drawermaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
1189 desc
->drawerids
= xcalloc(desc
->ncpuspos
, sizeof(*desc
->drawerids
));
1190 for (i
= 0; i
< desc
->ncpuspos
; i
++)
1191 desc
->drawerids
[i
] = -1;
1195 add_cpuset_to_array(desc
->socketmaps
, &desc
->nsockets
, core_siblings
);
1196 desc
->coreids
[idx
] = coreid
;
1197 add_cpuset_to_array(desc
->coremaps
, &desc
->ncores
, thread_siblings
);
1198 desc
->socketids
[idx
] = socketid
;
1199 if (book_siblings
) {
1200 add_cpuset_to_array(desc
->bookmaps
, &desc
->nbooks
, book_siblings
);
1201 desc
->bookids
[idx
] = bookid
;
1203 if (drawer_siblings
) {
1204 add_cpuset_to_array(desc
->drawermaps
, &desc
->ndrawers
, drawer_siblings
);
1205 desc
->drawerids
[idx
] = drawerid
;
1210 read_polarization(struct lscpu_desc
*desc
, int idx
)
1213 int num
= real_cpu_num(desc
, idx
);
1215 if (desc
->dispatching
< 0)
1217 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/polarization", num
))
1219 if (!desc
->polarization
)
1220 desc
->polarization
= xcalloc(desc
->ncpuspos
, sizeof(int));
1221 path_read_str(mode
, sizeof(mode
), _PATH_SYS_CPU
"/cpu%d/polarization", num
);
1222 if (strncmp(mode
, "vertical:low", sizeof(mode
)) == 0)
1223 desc
->polarization
[idx
] = POLAR_VLOW
;
1224 else if (strncmp(mode
, "vertical:medium", sizeof(mode
)) == 0)
1225 desc
->polarization
[idx
] = POLAR_VMEDIUM
;
1226 else if (strncmp(mode
, "vertical:high", sizeof(mode
)) == 0)
1227 desc
->polarization
[idx
] = POLAR_VHIGH
;
1228 else if (strncmp(mode
, "horizontal", sizeof(mode
)) == 0)
1229 desc
->polarization
[idx
] = POLAR_HORIZONTAL
;
1231 desc
->polarization
[idx
] = POLAR_UNKNOWN
;
1235 read_address(struct lscpu_desc
*desc
, int idx
)
1237 int num
= real_cpu_num(desc
, idx
);
1239 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/address", num
))
1241 if (!desc
->addresses
)
1242 desc
->addresses
= xcalloc(desc
->ncpuspos
, sizeof(int));
1243 desc
->addresses
[idx
] = path_read_s32(_PATH_SYS_CPU
"/cpu%d/address", num
);
1247 read_configured(struct lscpu_desc
*desc
, int idx
)
1249 int num
= real_cpu_num(desc
, idx
);
1251 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/configure", num
))
1253 if (!desc
->configured
)
1254 desc
->configured
= xcalloc(desc
->ncpuspos
, sizeof(int));
1255 desc
->configured
[idx
] = path_read_s32(_PATH_SYS_CPU
"/cpu%d/configure", num
);
1259 read_max_mhz(struct lscpu_desc
*desc
, int idx
)
1261 int num
= real_cpu_num(desc
, idx
);
1263 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/cpufreq/cpuinfo_max_freq", num
))
1266 desc
->maxmhz
= xcalloc(desc
->ncpuspos
, sizeof(char *));
1267 xasprintf(&(desc
->maxmhz
[idx
]), "%.4f",
1268 (float)path_read_s32(_PATH_SYS_CPU
1269 "/cpu%d/cpufreq/cpuinfo_max_freq", num
) / 1000);
1273 read_min_mhz(struct lscpu_desc
*desc
, int idx
)
1275 int num
= real_cpu_num(desc
, idx
);
1277 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/cpufreq/cpuinfo_min_freq", num
))
1280 desc
->minmhz
= xcalloc(desc
->ncpuspos
, sizeof(char *));
1281 xasprintf(&(desc
->minmhz
[idx
]), "%.4f",
1282 (float)path_read_s32(_PATH_SYS_CPU
1283 "/cpu%d/cpufreq/cpuinfo_min_freq", num
) / 1000);
1287 cachecmp(const void *a
, const void *b
)
1289 struct cpu_cache
*c1
= (struct cpu_cache
*) a
;
1290 struct cpu_cache
*c2
= (struct cpu_cache
*) b
;
1292 return strcmp(c2
->name
, c1
->name
);
1296 read_cache(struct lscpu_desc
*desc
, int idx
)
1300 int num
= real_cpu_num(desc
, idx
);
1302 if (!desc
->ncaches
) {
1303 while(path_exist(_PATH_SYS_CPU
"/cpu%d/cache/index%d",
1304 num
, desc
->ncaches
))
1310 desc
->caches
= xcalloc(desc
->ncaches
, sizeof(*desc
->caches
));
1312 for (i
= 0; i
< desc
->ncaches
; i
++) {
1313 struct cpu_cache
*ca
= &desc
->caches
[i
];
1316 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/cache/index%d",
1323 path_read_str(buf
, sizeof(buf
),
1324 _PATH_SYS_CPU
"/cpu%d/cache/index%d/type",
1326 if (!strcmp(buf
, "Data"))
1328 else if (!strcmp(buf
, "Instruction"))
1334 level
= path_read_s32(_PATH_SYS_CPU
"/cpu%d/cache/index%d/level",
1337 snprintf(buf
, sizeof(buf
), "L%d%c", level
, type
);
1339 snprintf(buf
, sizeof(buf
), "L%d", level
);
1341 ca
->name
= xstrdup(buf
);
1344 if (path_exist(_PATH_SYS_CPU
"/cpu%d/cache/index%d/size",num
, i
)) {
1345 path_read_str(buf
, sizeof(buf
),
1346 _PATH_SYS_CPU
"/cpu%d/cache/index%d/size", num
, i
);
1347 ca
->size
= xstrdup(buf
);
1349 ca
->size
= xstrdup("unknown size");
1353 /* information about how CPUs share different caches */
1354 map
= path_read_cpuset(maxcpus
,
1355 _PATH_SYS_CPU
"/cpu%d/cache/index%d/shared_cpu_map",
1358 if (!ca
->sharedmaps
)
1359 ca
->sharedmaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
1360 add_cpuset_to_array(ca
->sharedmaps
, &ca
->nsharedmaps
, map
);
1364 static inline int is_node_dirent(struct dirent
*d
)
1368 #ifdef _DIRENT_HAVE_D_TYPE
1369 (d
->d_type
== DT_DIR
|| d
->d_type
== DT_UNKNOWN
) &&
1371 strncmp(d
->d_name
, "node", 4) == 0 &&
1372 isdigit_string(d
->d_name
+ 4);
1376 nodecmp(const void *ap
, const void *bp
)
1378 int *a
= (int *) ap
, *b
= (int *) bp
;
1383 read_nodes(struct lscpu_desc
*desc
)
1390 /* number of NUMA node */
1391 path
= path_strdup(_PATH_SYS_NODE
);
1392 dir
= opendir(path
);
1395 while (dir
&& (d
= readdir(dir
))) {
1396 if (is_node_dirent(d
))
1400 if (!desc
->nnodes
) {
1406 desc
->nodemaps
= xcalloc(desc
->nnodes
, sizeof(cpu_set_t
*));
1407 desc
->idx2nodenum
= xmalloc(desc
->nnodes
* sizeof(int));
1411 while ((d
= readdir(dir
)) && i
< desc
->nnodes
) {
1412 if (is_node_dirent(d
))
1413 desc
->idx2nodenum
[i
++] = strtol_or_err(((d
->d_name
) + 4),
1414 _("Failed to extract the node number"));
1417 qsort(desc
->idx2nodenum
, desc
->nnodes
, sizeof(int), nodecmp
);
1420 /* information about how nodes share different CPUs */
1421 for (i
= 0; i
< desc
->nnodes
; i
++)
1422 desc
->nodemaps
[i
] = path_read_cpuset(maxcpus
,
1423 _PATH_SYS_NODE
"/node%d/cpumap",
1424 desc
->idx2nodenum
[i
]);
1428 get_cell_data(struct lscpu_desc
*desc
, int idx
, int col
,
1429 struct lscpu_modifier
*mod
,
1430 char *buf
, size_t bufsz
)
1432 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1434 int cpu
= real_cpu_num(desc
, idx
);
1440 snprintf(buf
, bufsz
, "%d", cpu
);
1443 if (mod
->physical
) {
1444 if (desc
->coreids
[idx
] == -1)
1445 snprintf(buf
, bufsz
, "-");
1447 snprintf(buf
, bufsz
, "%d", desc
->coreids
[idx
]);
1449 if (cpuset_ary_isset(cpu
, desc
->coremaps
,
1450 desc
->ncores
, setsize
, &i
) == 0)
1451 snprintf(buf
, bufsz
, "%zu", i
);
1455 if (mod
->physical
) {
1456 if (desc
->socketids
[idx
] == -1)
1457 snprintf(buf
, bufsz
, "-");
1459 snprintf(buf
, bufsz
, "%d", desc
->socketids
[idx
]);
1461 if (cpuset_ary_isset(cpu
, desc
->socketmaps
,
1462 desc
->nsockets
, setsize
, &i
) == 0)
1463 snprintf(buf
, bufsz
, "%zu", i
);
1467 if (cpuset_ary_isset(cpu
, desc
->nodemaps
,
1468 desc
->nnodes
, setsize
, &i
) == 0)
1469 snprintf(buf
, bufsz
, "%d", desc
->idx2nodenum
[i
]);
1472 if (mod
->physical
) {
1473 if (desc
->drawerids
[idx
] == -1)
1474 snprintf(buf
, bufsz
, "-");
1476 snprintf(buf
, bufsz
, "%d", desc
->drawerids
[idx
]);
1478 if (cpuset_ary_isset(cpu
, desc
->drawermaps
,
1479 desc
->ndrawers
, setsize
, &i
) == 0)
1480 snprintf(buf
, bufsz
, "%zu", i
);
1484 if (mod
->physical
) {
1485 if (desc
->bookids
[idx
] == -1)
1486 snprintf(buf
, bufsz
, "-");
1488 snprintf(buf
, bufsz
, "%d", desc
->bookids
[idx
]);
1490 if (cpuset_ary_isset(cpu
, desc
->bookmaps
,
1491 desc
->nbooks
, setsize
, &i
) == 0)
1492 snprintf(buf
, bufsz
, "%zu", i
);
1501 for (j
= desc
->ncaches
- 1; j
>= 0; j
--) {
1502 struct cpu_cache
*ca
= &desc
->caches
[j
];
1504 if (cpuset_ary_isset(cpu
, ca
->sharedmaps
,
1505 ca
->nsharedmaps
, setsize
, &i
) == 0) {
1506 int x
= snprintf(p
, sz
, "%zu", i
);
1507 if (x
< 0 || (size_t) x
>= sz
)
1515 *p
++ = mod
->compat
? ',' : ':';
1522 case COL_POLARIZATION
:
1523 if (desc
->polarization
) {
1524 int x
= desc
->polarization
[idx
];
1526 snprintf(buf
, bufsz
, "%s",
1527 mod
->mode
== OUTPUT_PARSABLE
?
1528 polar_modes
[x
].parsable
:
1529 polar_modes
[x
].readable
);
1533 if (desc
->addresses
)
1534 snprintf(buf
, bufsz
, "%d", desc
->addresses
[idx
]);
1536 case COL_CONFIGURED
:
1537 if (!desc
->configured
)
1539 if (mod
->mode
== OUTPUT_PARSABLE
)
1540 snprintf(buf
, bufsz
, "%s",
1541 desc
->configured
[idx
] ? _("Y") : _("N"));
1543 snprintf(buf
, bufsz
, "%s",
1544 desc
->configured
[idx
] ? _("yes") : _("no"));
1549 if (mod
->mode
== OUTPUT_PARSABLE
)
1550 snprintf(buf
, bufsz
, "%s",
1551 is_cpu_online(desc
, cpu
) ? _("Y") : _("N"));
1553 snprintf(buf
, bufsz
, "%s",
1554 is_cpu_online(desc
, cpu
) ? _("yes") : _("no"));
1558 xstrncpy(buf
, desc
->maxmhz
[idx
], bufsz
);
1562 xstrncpy(buf
, desc
->minmhz
[idx
], bufsz
);
1569 get_cell_header(struct lscpu_desc
*desc
, int col
,
1570 struct lscpu_modifier
*mod
,
1571 char *buf
, size_t bufsz
)
1575 if (col
== COL_CACHE
) {
1580 for (i
= desc
->ncaches
- 1; i
>= 0; i
--) {
1581 int x
= snprintf(p
, sz
, "%s", desc
->caches
[i
].name
);
1582 if (x
< 0 || (size_t) x
>= sz
)
1589 *p
++ = mod
->compat
? ',' : ':';
1597 snprintf(buf
, bufsz
, "%s", coldescs
[col
].name
);
1602 * [-p] backend, we support two parsable formats:
1604 * 1) "compatible" -- this format is compatible with the original lscpu(1)
1605 * output and it contains fixed set of the columns. The CACHE columns are at
1606 * the end of the line and the CACHE is not printed if the number of the caches
1607 * is zero. The CACHE columns are separated by two commas, for example:
1610 * # CPU,Core,Socket,Node,,L1d,L1i,L2
1614 * 2) "user defined output" -- this format prints always all columns without
1615 * special prefix for CACHE column. If there are not CACHEs then the column is
1616 * empty and the header "Cache" is printed rather than a real name of the cache.
1617 * The CACHE columns are separated by ':'.
1619 * $ lscpu --parse=CPU,CORE,SOCKET,NODE,CACHE
1620 * # CPU,Core,Socket,Node,L1d:L1i:L2
1625 print_parsable(struct lscpu_desc
*desc
, int cols
[], int ncols
,
1626 struct lscpu_modifier
*mod
)
1628 char buf
[BUFSIZ
], *data
;
1635 "# The following is the parsable format, which can be fed to other\n"
1636 "# programs. Each different item in every column has an unique ID\n"
1637 "# starting from zero.\n"));
1639 fputs("# ", stdout
);
1640 for (i
= 0; i
< ncols
; i
++) {
1643 if (col
== COL_CACHE
) {
1644 if (mod
->compat
&& !desc
->ncaches
)
1646 if (mod
->compat
&& i
!= 0)
1652 data
= get_cell_header(desc
, col
, mod
, buf
, sizeof(buf
));
1654 if (data
&& * data
&& col
!= COL_CACHE
&&
1655 !coldescs
[col
].is_abbr
) {
1657 * For normal column names use mixed case (e.g. "Socket")
1661 while (p
&& *p
!= '\0') {
1662 *p
= tolower((unsigned int) *p
);
1666 fputs(data
&& *data
? data
: "", stdout
);
1673 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1675 int cpu
= real_cpu_num(desc
, i
);
1677 if (!mod
->offline
&& desc
->online
&& !is_cpu_online(desc
, cpu
))
1679 if (!mod
->online
&& desc
->online
&& is_cpu_online(desc
, cpu
))
1681 if (desc
->present
&& !is_cpu_present(desc
, cpu
))
1683 for (c
= 0; c
< ncols
; c
++) {
1684 if (mod
->compat
&& cols
[c
] == COL_CACHE
) {
1693 data
= get_cell_data(desc
, i
, cols
[c
], mod
,
1695 fputs(data
&& *data
? data
: "", stdout
);
1705 print_readable(struct lscpu_desc
*desc
, int cols
[], int ncols
,
1706 struct lscpu_modifier
*mod
)
1711 struct libscols_table
*table
;
1713 scols_init_debug(0);
1715 table
= scols_new_table();
1717 err(EXIT_FAILURE
, _("failed to initialize output table"));
1719 scols_table_enable_json(table
, 1);
1720 scols_table_set_name(table
, "cpus");
1723 for (i
= 0; i
< ncols
; i
++) {
1724 data
= get_cell_header(desc
, cols
[i
], mod
, buf
, sizeof(buf
));
1725 if (!scols_table_new_column(table
, data
, 0, 0))
1726 err(EXIT_FAILURE
, _("failed to initialize output column"));
1729 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1731 struct libscols_line
*line
;
1732 int cpu
= real_cpu_num(desc
, i
);
1734 if (!mod
->offline
&& desc
->online
&& !is_cpu_online(desc
, cpu
))
1736 if (!mod
->online
&& desc
->online
&& is_cpu_online(desc
, cpu
))
1738 if (desc
->present
&& !is_cpu_present(desc
, cpu
))
1741 line
= scols_table_new_line(table
, NULL
);
1743 err(EXIT_FAILURE
, _("failed to initialize output line"));
1745 for (c
= 0; c
< ncols
; c
++) {
1746 data
= get_cell_data(desc
, i
, cols
[c
], mod
,
1748 if (!data
|| !*data
)
1750 if (scols_line_set_data(line
, c
, data
))
1755 scols_print_table(table
);
1756 scols_unref_table(table
);
1760 static void __attribute__ ((__format__(printf
, 3, 4)))
1761 add_summary_sprint(struct libscols_table
*tb
,
1766 struct libscols_line
*ln
= scols_table_new_line(tb
, NULL
);
1771 err(EXIT_FAILURE
, _("failed to initialize output line"));
1773 /* description column */
1774 scols_line_set_data(ln
, 0, txt
);
1777 va_start(args
, fmt
);
1778 xvasprintf(&data
, fmt
, args
);
1782 scols_line_refer_data(ln
, 1, data
);
1785 #define add_summary_n(tb, txt, num) add_summary_sprint(tb, txt, "%d", num)
1786 #define add_summary_s(tb, txt, str) add_summary_sprint(tb, txt, "%s", str)
1789 print_cpuset(struct libscols_table
*tb
,
1790 const char *key
, cpu_set_t
*set
, int hex
)
1792 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1793 size_t setbuflen
= 7 * maxcpus
;
1794 char setbuf
[setbuflen
], *p
;
1797 p
= cpumask_create(setbuf
, setbuflen
, set
, setsize
);
1798 add_summary_s(tb
, key
, p
);
1800 p
= cpulist_create(setbuf
, setbuflen
, set
, setsize
);
1801 add_summary_s(tb
, key
, p
);
1809 print_summary(struct lscpu_desc
*desc
, struct lscpu_modifier
*mod
)
1813 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1814 struct libscols_table
*tb
;
1816 scols_init_debug(0);
1818 tb
= scols_new_table();
1820 err(EXIT_FAILURE
, _("failed to initialize output table"));
1822 scols_table_enable_noheadings(tb
, 1);
1824 scols_table_enable_json(tb
, 1);
1825 scols_table_set_name(tb
, "lscpu");
1828 if (scols_table_new_column(tb
, "field", 0, 0) == NULL
||
1829 scols_table_new_column(tb
, "data", 0, SCOLS_FL_NOEXTREMES
) == NULL
)
1830 err(EXIT_FAILURE
, _("failed to initialize output column"));
1832 add_summary_s(tb
, _("Architecture:"), desc
->arch
);
1834 char mbuf
[64], *p
= mbuf
;
1836 if (desc
->mode
& MODE_32BIT
) {
1837 strcpy(p
, "32-bit, ");
1840 if (desc
->mode
& MODE_64BIT
) {
1841 strcpy(p
, "64-bit, ");
1845 add_summary_s(tb
, _("CPU op-mode(s):"), mbuf
);
1847 #if !defined(WORDS_BIGENDIAN)
1848 add_summary_s(tb
, _("Byte Order:"), "Little Endian");
1850 add_summary_s(tb
, _("Byte Order:"), "Big Endian");
1852 add_summary_n(tb
, _("CPU(s):"), desc
->ncpus
);
1855 print_cpuset(tb
, mod
->hex
? _("On-line CPU(s) mask:") :
1856 _("On-line CPU(s) list:"),
1857 desc
->online
, mod
->hex
);
1859 if (desc
->online
&& CPU_COUNT_S(setsize
, desc
->online
) != desc
->ncpus
) {
1862 /* Linux kernel provides cpuset of off-line CPUs that contains
1863 * all configured CPUs (see /sys/devices/system/cpu/offline),
1864 * but want to print real (present in system) off-line CPUs only.
1866 set
= cpuset_alloc(maxcpus
, NULL
, NULL
);
1868 err(EXIT_FAILURE
, _("failed to callocate cpu set"));
1869 CPU_ZERO_S(setsize
, set
);
1870 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1871 int cpu
= real_cpu_num(desc
, i
);
1872 if (!is_cpu_online(desc
, cpu
) && is_cpu_present(desc
, cpu
))
1873 CPU_SET_S(cpu
, setsize
, set
);
1875 print_cpuset(tb
, mod
->hex
? _("Off-line CPU(s) mask:") :
1876 _("Off-line CPU(s) list:"),
1881 if (desc
->nsockets
) {
1882 int threads_per_core
, cores_per_socket
, sockets_per_book
;
1883 int books_per_drawer
, drawers
;
1886 threads_per_core
= cores_per_socket
= sockets_per_book
= 0;
1887 books_per_drawer
= drawers
= 0;
1888 /* s390 detects its cpu topology via /proc/sysinfo, if present.
1889 * Using simply the cpu topology masks in sysfs will not give
1890 * usable results since everything is virtualized. E.g.
1891 * virtual core 0 may have only 1 cpu, but virtual core 2 may
1893 * If the cpu topology is not exported (e.g. 2nd level guest)
1894 * fall back to old calculation scheme.
1896 if ((fd
= path_fopen("r", 0, _PATH_PROC_SYSINFO
))) {
1900 while (fd
&& fgets(pbuf
, sizeof(pbuf
), fd
) != NULL
) {
1901 if (sscanf(pbuf
, "CPU Topology SW:%d%d%d%d%d%d",
1902 &t0
, &t1
, &drawers
, &books_per_drawer
,
1904 &cores_per_socket
) == 6)
1911 threads_per_core
= atoi(desc
->mtid
) + 1;
1912 add_summary_n(tb
, _("Thread(s) per core:"),
1913 threads_per_core
?: desc
->nthreads
/ desc
->ncores
);
1914 add_summary_n(tb
, _("Core(s) per socket:"),
1915 cores_per_socket
?: desc
->ncores
/ desc
->nsockets
);
1917 add_summary_n(tb
, _("Socket(s) per book:"),
1918 sockets_per_book
?: desc
->nsockets
/ desc
->nbooks
);
1919 if (desc
->ndrawers
) {
1920 add_summary_n(tb
, _("Book(s) per drawer:"),
1921 books_per_drawer
?: desc
->nbooks
/ desc
->ndrawers
);
1922 add_summary_n(tb
, _("Drawer(s):"), drawers
?: desc
->ndrawers
);
1924 add_summary_n(tb
, _("Book(s):"), books_per_drawer
?: desc
->nbooks
);
1927 add_summary_n(tb
, _("Socket(s):"), sockets_per_book
?: desc
->nsockets
);
1931 add_summary_n(tb
, _("NUMA node(s):"), desc
->nnodes
);
1933 add_summary_s(tb
, _("Vendor ID:"), desc
->vendor
);
1934 if (desc
->machinetype
)
1935 add_summary_s(tb
, _("Machine type:"), desc
->machinetype
);
1937 add_summary_s(tb
, _("CPU family:"), desc
->family
);
1938 if (desc
->model
|| desc
->revision
)
1939 add_summary_s(tb
, _("Model:"), desc
->revision
? desc
->revision
: desc
->model
);
1940 if (desc
->modelname
|| desc
->cpu
)
1941 add_summary_s(tb
, _("Model name:"), desc
->cpu
? desc
->cpu
: desc
->modelname
);
1943 add_summary_s(tb
, _("Stepping:"), desc
->stepping
);
1945 add_summary_s(tb
, _("CPU MHz:"), desc
->mhz
);
1946 if (desc
->dynamic_mhz
)
1947 add_summary_s(tb
, _("CPU dynamic MHz:"), desc
->dynamic_mhz
);
1948 if (desc
->static_mhz
)
1949 add_summary_s(tb
, _("CPU static MHz:"), desc
->static_mhz
);
1951 add_summary_s(tb
, _("CPU max MHz:"), desc
->maxmhz
[0]);
1953 add_summary_s(tb
, _("CPU min MHz:"), desc
->minmhz
[0]);
1955 add_summary_s(tb
, _("BogoMIPS:"), desc
->bogomips
);
1956 if (desc
->virtflag
) {
1957 if (!strcmp(desc
->virtflag
, "svm"))
1958 add_summary_s(tb
, _("Virtualization:"), "AMD-V");
1959 else if (!strcmp(desc
->virtflag
, "vmx"))
1960 add_summary_s(tb
, _("Virtualization:"), "VT-x");
1962 if (desc
->hypervisor
)
1963 add_summary_s(tb
, _("Hypervisor:"), desc
->hypervisor
);
1965 add_summary_s(tb
, _("Hypervisor vendor:"), hv_vendors
[desc
->hyper
]);
1966 add_summary_s(tb
, _("Virtualization type:"), _(virt_types
[desc
->virtype
]));
1968 if (desc
->dispatching
>= 0)
1969 add_summary_s(tb
, _("Dispatching mode:"), _(disp_modes
[desc
->dispatching
]));
1970 if (desc
->ncaches
) {
1973 for (i
= desc
->ncaches
- 1; i
>= 0; i
--) {
1974 snprintf(cbuf
, sizeof(cbuf
),
1975 _("%s cache:"), desc
->caches
[i
].name
);
1976 add_summary_s(tb
, cbuf
, desc
->caches
[i
].size
);
1979 if (desc
->necaches
) {
1982 for (i
= desc
->necaches
- 1; i
>= 0; i
--) {
1983 snprintf(cbuf
, sizeof(cbuf
),
1984 _("%s cache:"), desc
->ecaches
[i
].name
);
1985 add_summary_s(tb
, cbuf
, desc
->ecaches
[i
].size
);
1989 for (i
= 0; i
< desc
->nnodes
; i
++) {
1990 snprintf(buf
, sizeof(buf
), _("NUMA node%d CPU(s):"), desc
->idx2nodenum
[i
]);
1991 print_cpuset(tb
, buf
, desc
->nodemaps
[i
], mod
->hex
);
1994 if (desc
->physsockets
) {
1995 add_summary_n(tb
, _("Physical sockets:"), desc
->physsockets
);
1996 add_summary_n(tb
, _("Physical chips:"), desc
->physchips
);
1997 add_summary_n(tb
, _("Physical cores/chip:"), desc
->physcoresperchip
);
2001 add_summary_s(tb
, _("Flags:"), desc
->flags
);
2003 scols_print_table(tb
);
2004 scols_unref_table(tb
);
2007 static void __attribute__((__noreturn__
)) usage(FILE *out
)
2011 fputs(USAGE_HEADER
, out
);
2012 fprintf(out
, _(" %s [options]\n"), program_invocation_short_name
);
2014 fputs(USAGE_SEPARATOR
, out
);
2015 fputs(_("Display information about the CPU architecture.\n"), out
);
2017 fputs(USAGE_OPTIONS
, out
);
2018 fputs(_(" -a, --all print both online and offline CPUs (default for -e)\n"), out
);
2019 fputs(_(" -b, --online print online CPUs only (default for -p)\n"), out
);
2020 fputs(_(" -c, --offline print offline CPUs only\n"), out
);
2021 fputs(_(" -J, --json use JSON for default or extended format\n"), out
);
2022 fputs(_(" -e, --extended[=<list>] print out an extended readable format\n"), out
);
2023 fputs(_(" -p, --parse[=<list>] print out a parsable format\n"), out
);
2024 fputs(_(" -s, --sysroot <dir> use specified directory as system root\n"), out
);
2025 fputs(_(" -x, --hex print hexadecimal masks rather than lists of CPUs\n"), out
);
2026 fputs(_(" -y, --physical print physical instead of logical IDs\n"), out
);
2027 fputs(USAGE_SEPARATOR
, out
);
2028 fputs(USAGE_HELP
, out
);
2029 fputs(USAGE_VERSION
, out
);
2031 fprintf(out
, _("\nAvailable columns:\n"));
2033 for (i
= 0; i
< ARRAY_SIZE(coldescs
); i
++)
2034 fprintf(out
, " %13s %s\n", coldescs
[i
].name
, _(coldescs
[i
].help
));
2036 fprintf(out
, USAGE_MAN_TAIL("lscpu(1)"));
2038 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
2041 int main(int argc
, char *argv
[])
2043 struct lscpu_modifier _mod
= { .mode
= OUTPUT_SUMMARY
}, *mod
= &_mod
;
2044 struct lscpu_desc _desc
= { .flags
= NULL
}, *desc
= &_desc
;
2046 int columns
[ARRAY_SIZE(coldescs
)], ncolumns
= 0;
2047 int cpu_modifier_specified
= 0;
2049 static const struct option longopts
[] = {
2050 { "all", no_argument
, NULL
, 'a' },
2051 { "online", no_argument
, NULL
, 'b' },
2052 { "offline", no_argument
, NULL
, 'c' },
2053 { "help", no_argument
, NULL
, 'h' },
2054 { "extended", optional_argument
, NULL
, 'e' },
2055 { "json", no_argument
, NULL
, 'J' },
2056 { "parse", optional_argument
, NULL
, 'p' },
2057 { "sysroot", required_argument
, NULL
, 's' },
2058 { "physical", no_argument
, NULL
, 'y' },
2059 { "hex", no_argument
, NULL
, 'x' },
2060 { "version", no_argument
, NULL
, 'V' },
2061 { NULL
, 0, NULL
, 0 }
2064 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
2069 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
2071 setlocale(LC_ALL
, "");
2072 bindtextdomain(PACKAGE
, LOCALEDIR
);
2073 textdomain(PACKAGE
);
2074 atexit(close_stdout
);
2076 while ((c
= getopt_long(argc
, argv
, "abce::hJp::s:xyV", longopts
, NULL
)) != -1) {
2078 err_exclusive_options(c
, longopts
, excl
, excl_st
);
2082 mod
->online
= mod
->offline
= 1;
2083 cpu_modifier_specified
= 1;
2087 cpu_modifier_specified
= 1;
2091 cpu_modifier_specified
= 1;
2103 ncolumns
= string_to_idarray(optarg
,
2104 columns
, ARRAY_SIZE(columns
),
2107 return EXIT_FAILURE
;
2109 mod
->mode
= c
== 'p' ? OUTPUT_PARSABLE
: OUTPUT_READABLE
;
2112 path_set_prefix(optarg
);
2113 mod
->system
= SYSTEM_SNAPSHOT
;
2122 printf(UTIL_LINUX_VERSION
);
2123 return EXIT_SUCCESS
;
2125 errtryhelp(EXIT_FAILURE
);
2129 if (cpu_modifier_specified
&& mod
->mode
== OUTPUT_SUMMARY
) {
2131 _("%s: options --all, --online and --offline may only "
2132 "be used with options --extended or --parse.\n"),
2133 program_invocation_short_name
);
2134 return EXIT_FAILURE
;
2140 /* set default cpu display mode if none was specified */
2141 if (!mod
->online
&& !mod
->offline
) {
2143 mod
->offline
= mod
->mode
== OUTPUT_READABLE
? 1 : 0;
2146 read_basicinfo(desc
, mod
);
2148 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
2149 /* only consider present CPUs */
2150 if (desc
->present
&&
2151 !CPU_ISSET(real_cpu_num(desc
, i
), desc
->present
))
2153 read_topology(desc
, i
);
2154 read_cache(desc
, i
);
2155 read_polarization(desc
, i
);
2156 read_address(desc
, i
);
2157 read_configured(desc
, i
);
2158 read_max_mhz(desc
, i
);
2159 read_min_mhz(desc
, i
);
2163 qsort(desc
->caches
, desc
->ncaches
,
2164 sizeof(struct cpu_cache
), cachecmp
);
2167 qsort(desc
->ecaches
, desc
->necaches
,
2168 sizeof(struct cpu_cache
), cachecmp
);
2171 read_hypervisor(desc
, mod
);
2174 case OUTPUT_SUMMARY
:
2175 print_summary(desc
, mod
);
2177 case OUTPUT_PARSABLE
:
2179 columns
[ncolumns
++] = COL_CPU
;
2180 columns
[ncolumns
++] = COL_CORE
;
2181 columns
[ncolumns
++] = COL_SOCKET
;
2182 columns
[ncolumns
++] = COL_NODE
;
2183 columns
[ncolumns
++] = COL_CACHE
;
2186 print_parsable(desc
, columns
, ncolumns
, mod
);
2188 case OUTPUT_READABLE
:
2190 /* No list was given. Just print whatever is there. */
2191 columns
[ncolumns
++] = COL_CPU
;
2193 columns
[ncolumns
++] = COL_NODE
;
2194 if (desc
->drawermaps
)
2195 columns
[ncolumns
++] = COL_DRAWER
;
2197 columns
[ncolumns
++] = COL_BOOK
;
2198 if (desc
->socketmaps
)
2199 columns
[ncolumns
++] = COL_SOCKET
;
2201 columns
[ncolumns
++] = COL_CORE
;
2203 columns
[ncolumns
++] = COL_CACHE
;
2205 columns
[ncolumns
++] = COL_ONLINE
;
2206 if (desc
->configured
)
2207 columns
[ncolumns
++] = COL_CONFIGURED
;
2208 if (desc
->polarization
)
2209 columns
[ncolumns
++] = COL_POLARIZATION
;
2210 if (desc
->addresses
)
2211 columns
[ncolumns
++] = COL_ADDRESS
;
2213 columns
[ncolumns
++] = COL_MAXMHZ
;
2215 columns
[ncolumns
++] = COL_MINMHZ
;
2217 print_readable(desc
, columns
, ncolumns
, mod
);
2221 return EXIT_SUCCESS
;