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.
30 #include <sys/utsname.h>
33 #include <sys/types.h>
44 #include "closestream.h"
51 #define _PATH_SYS_SYSTEM "/sys/devices/system"
52 #define _PATH_SYS_CPU _PATH_SYS_SYSTEM "/cpu"
53 #define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
54 #define _PATH_PROC_XEN "/proc/xen"
55 #define _PATH_PROC_XENCAP _PATH_PROC_XEN "/capabilities"
56 #define _PATH_PROC_CPUINFO "/proc/cpuinfo"
57 #define _PATH_PROC_PCIDEVS "/proc/bus/pci/devices"
58 #define _PATH_PROC_SYSINFO "/proc/sysinfo"
59 #define _PATH_PROC_STATUS "/proc/self/status"
60 #define _PATH_PROC_VZ "/proc/vz"
61 #define _PATH_PROC_BC "/proc/bc"
62 #define _PATH_DEV_MEM "/dev/mem"
64 /* virtualization types */
71 const char *virt_types
[] = {
72 [VIRT_NONE
] = N_("none"),
73 [VIRT_PARA
] = N_("para"),
74 [VIRT_FULL
] = N_("full"),
75 [VIRT_CONT
] = N_("container"),
78 const char *hv_vendors
[] = {
82 [HYPER_MSHV
] = "Microsoft",
83 [HYPER_VMWARE
] = "VMware",
85 [HYPER_VSERVER
] = "Linux-VServer",
86 [HYPER_UML
] = "User-mode Linux",
87 [HYPER_INNOTEK
] = "Innotek GmbH",
88 [HYPER_HITACHI
] = "Hitachi",
89 [HYPER_PARALLELS
] = "Parallels"
94 MODE_32BIT
= (1 << 1),
98 /* cache(s) description */
104 cpu_set_t
**sharedmaps
;
107 /* dispatching modes */
113 const char *disp_modes
[] = {
114 [DISP_HORIZONTAL
] = N_("horizontal"),
115 [DISP_VERTICAL
] = N_("vertical")
118 /* cpu polarization */
127 struct polarization_modes
{
132 struct polarization_modes polar_modes
[] = {
133 [POLAR_UNKNOWN
] = {"U", "-"},
134 [POLAR_VLOW
] = {"VL", "vert-low"},
135 [POLAR_VMEDIUM
] = {"VM", "vert-medium"},
136 [POLAR_VHIGH
] = {"VH", "vert-high"},
137 [POLAR_HORIZONTAL
] = {"H", "horizontal"},
140 /* global description */
147 char *virtflag
; /* virtualization flag (vmx, svm) */
148 char *hypervisor
; /* hypervisor software */
149 int hyper
; /* hypervisor vendor ID */
150 int virtype
; /* VIRT_PARA|FULL|NONE ? */
152 char **maxmhz
; /* maximum mega hertz */
153 char **minmhz
; /* minimum mega hertz */
157 int dispatching
; /* none, horizontal or vertical */
158 int mode
; /* rm, lm or/and tm */
160 int ncpuspos
; /* maximal possible CPUs */
161 int ncpus
; /* number of present CPUs */
162 cpu_set_t
*present
; /* mask with present CPUs */
163 cpu_set_t
*online
; /* mask with online CPUs */
165 int nthreads
; /* number of online threads */
168 struct cpu_cache
*caches
;
171 * All maps are sequentially indexed (0..ncpuspos), the array index
172 * does not have match with cpuX number as presented by kernel. You
173 * have to use real_cpu_num() to get the real cpuX number.
175 * For example, the possible system CPUs are: 1,3,5, it means that
176 * ncpuspos=3, so all arrays are in range 0..3.
178 int *idx2cpunum
; /* mapping index to CPU num */
180 int nnodes
; /* number of NUMA modes */
181 int *idx2nodenum
; /* Support for discontinuous nodes */
182 cpu_set_t
**nodemaps
; /* array with NUMA nodes */
184 /* books -- based on book_siblings (internal kernel map of cpuX's
185 * hardware threads within the same book */
186 int nbooks
; /* number of all online books */
187 cpu_set_t
**bookmaps
; /* unique book_siblings */
189 /* sockets -- based on core_siblings (internal kernel map of cpuX's
190 * hardware threads within the same physical_package_id (socket)) */
191 int nsockets
; /* number of all online sockets */
192 cpu_set_t
**socketmaps
; /* unique core_siblings */
194 /* cores -- based on thread_siblings (internel kernel map of cpuX's
195 * hardware threads within the same core as cpuX) */
196 int ncores
; /* number of all online cores */
197 cpu_set_t
**coremaps
; /* unique thread_siblings */
199 int *polarization
; /* cpu polarization */
200 int *addresses
; /* physical cpu addresses */
201 int *configured
; /* cpu configured */
205 OUTPUT_SUMMARY
= 0, /* default */
206 OUTPUT_PARSABLE
, /* -p */
207 OUTPUT_READABLE
, /* -e */
211 SYSTEM_LIVE
= 0, /* analyzing a live system */
212 SYSTEM_SNAPSHOT
, /* analyzing a snapshot of a different system */
215 struct lscpu_modifier
{
216 int mode
; /* OUTPUT_* */
217 int system
; /* SYSTEM_* */
218 unsigned int hex
:1, /* print CPU masks rather than CPU lists */
219 compat
:1, /* use backwardly compatible format */
220 online
:1, /* print online CPUs */
221 offline
:1; /* print offline CPUs */
224 static int maxcpus
; /* size in bits of kernel cpu mask */
226 #define is_cpu_online(_d, _cpu) \
227 ((_d) && (_d)->online ? \
228 CPU_ISSET_S((_cpu), CPU_ALLOC_SIZE(maxcpus), (_d)->online) : 0)
229 #define is_cpu_present(_d, _cpu) \
230 ((_d) && (_d)->present ? \
231 CPU_ISSET_S((_cpu), CPU_ALLOC_SIZE(maxcpus), (_d)->present) : 0)
233 #define real_cpu_num(_d, _i) ((_d)->idx2cpunum[(_i)])
253 /* column description
255 struct lscpu_coldesc
{
259 unsigned int is_abbr
:1; /* name is abbreviation */
262 static struct lscpu_coldesc coldescs
[] =
264 [COL_CPU
] = { "CPU", N_("logical CPU number"), 1 },
265 [COL_CORE
] = { "CORE", N_("logical core number") },
266 [COL_SOCKET
] = { "SOCKET", N_("logical socket number") },
267 [COL_NODE
] = { "NODE", N_("logical NUMA node number") },
268 [COL_BOOK
] = { "BOOK", N_("logical book number") },
269 [COL_CACHE
] = { "CACHE", N_("shows how caches are shared between CPUs") },
270 [COL_POLARIZATION
] = { "POLARIZATION", N_("CPU dispatching mode on virtual hardware") },
271 [COL_ADDRESS
] = { "ADDRESS", N_("physical address of a CPU") },
272 [COL_CONFIGURED
] = { "CONFIGURED", N_("shows if the hypervisor has allocated the CPU") },
273 [COL_ONLINE
] = { "ONLINE", N_("shows if Linux currently makes use of the CPU") },
274 [COL_MAXMHZ
] = { "MAXMHZ", N_("shows the maximum MHz of the CPU") },
275 [COL_MINMHZ
] = { "MINMHZ", N_("shows the minimum MHz of the CPU") }
279 column_name_to_id(const char *name
, size_t namesz
)
283 for (i
= 0; i
< ARRAY_SIZE(coldescs
); i
++) {
284 const char *cn
= coldescs
[i
].name
;
286 if (!strncasecmp(name
, cn
, namesz
) && !*(cn
+ namesz
))
289 warnx(_("unknown column: %s"), name
);
293 /* Lookup a pattern and get the value from cpuinfo.
296 * "<pattern> : <key>"
299 lookup(char *line
, char *pattern
, char **value
)
302 int len
= strlen(pattern
);
308 if (strncmp(line
, pattern
, len
))
312 for (p
= line
+ len
; isspace(*p
); p
++);
319 for (++p
; isspace(*p
); p
++);
327 len
= strlen(line
) - 1;
328 for (p
= line
+ len
; isspace(*(p
-1)); p
--);
335 /* Don't init the mode for platforms where we are not able to
336 * detect that CPU supports 64-bit mode.
339 init_mode(struct lscpu_modifier
*mod
)
343 if (mod
->system
== SYSTEM_SNAPSHOT
)
344 /* reading info from any /{sys,proc} dump, don't mix it with
345 * information about our real CPU */
348 #if defined(__alpha__) || defined(__ia64__)
349 m
|= MODE_64BIT
; /* 64bit platforms only */
351 /* platforms with 64bit flag in /proc/cpuinfo, define
352 * 32bit default here */
353 #if defined(__i386__) || defined(__x86_64__) || \
354 defined(__s390x__) || defined(__s390__) || defined(__sparc_v9__)
361 read_basicinfo(struct lscpu_desc
*desc
, struct lscpu_modifier
*mod
)
363 FILE *fp
= path_fopen("r", 1, _PATH_PROC_CPUINFO
);
365 struct utsname utsbuf
;
369 if (uname(&utsbuf
) == -1)
370 err(EXIT_FAILURE
, _("error: uname failed"));
371 desc
->arch
= xstrdup(utsbuf
.machine
);
374 while (fgets(buf
, sizeof(buf
), fp
) != NULL
) {
375 if (lookup(buf
, "vendor", &desc
->vendor
)) ;
376 else if (lookup(buf
, "vendor_id", &desc
->vendor
)) ;
377 else if (lookup(buf
, "family", &desc
->family
)) ;
378 else if (lookup(buf
, "cpu family", &desc
->family
)) ;
379 else if (lookup(buf
, "model", &desc
->model
)) ;
380 else if (lookup(buf
, "model name", &desc
->modelname
)) ;
381 else if (lookup(buf
, "stepping", &desc
->stepping
)) ;
382 else if (lookup(buf
, "cpu MHz", &desc
->mhz
)) ;
383 else if (lookup(buf
, "flags", &desc
->flags
)) ; /* x86 */
384 else if (lookup(buf
, "features", &desc
->flags
)) ; /* s390 */
385 else if (lookup(buf
, "type", &desc
->flags
)) ; /* sparc64 */
386 else if (lookup(buf
, "bogomips", &desc
->bogomips
)) ;
387 else if (lookup(buf
, "bogomips per cpu", &desc
->bogomips
)) ; /* s390 */
392 desc
->mode
= init_mode(mod
);
395 snprintf(buf
, sizeof(buf
), " %s ", desc
->flags
);
396 if (strstr(buf
, " svm "))
397 desc
->virtflag
= xstrdup("svm");
398 else if (strstr(buf
, " vmx "))
399 desc
->virtflag
= xstrdup("vmx");
400 if (strstr(buf
, " lm "))
401 desc
->mode
|= MODE_32BIT
| MODE_64BIT
; /* x86_64 */
402 if (strstr(buf
, " zarch "))
403 desc
->mode
|= MODE_32BIT
| MODE_64BIT
; /* s390x */
404 if (strstr(buf
, " sun4v ") || strstr(buf
, " sun4u "))
405 desc
->mode
|= MODE_32BIT
| MODE_64BIT
; /* sparc64 */
408 if (desc
->arch
&& mod
->system
!= SYSTEM_SNAPSHOT
) {
409 if (strcmp(desc
->arch
, "ppc64") == 0)
410 desc
->mode
|= MODE_32BIT
| MODE_64BIT
;
411 else if (strcmp(desc
->arch
, "ppc") == 0)
412 desc
->mode
|= MODE_32BIT
;
417 if (path_exist(_PATH_SYS_CPU
"/kernel_max"))
418 /* note that kernel_max is maximum index [NR_CPUS-1] */
419 maxcpus
= path_read_s32(_PATH_SYS_CPU
"/kernel_max") + 1;
421 else if (mod
->system
== SYSTEM_LIVE
)
422 /* the root is '/' so we are working with data from the current kernel */
423 maxcpus
= get_max_number_of_cpus();
426 /* error or we are reading some /sys snapshot instead of the
427 * real /sys, let's use any crazy number... */
430 setsize
= CPU_ALLOC_SIZE(maxcpus
);
432 if (path_exist(_PATH_SYS_CPU
"/possible")) {
433 cpu_set_t
*tmp
= path_read_cpulist(maxcpus
, _PATH_SYS_CPU
"/possible");
436 desc
->ncpuspos
= CPU_COUNT_S(setsize
, tmp
);
437 desc
->idx2cpunum
= xcalloc(desc
->ncpuspos
, sizeof(int));
439 for (num
= 0, idx
= 0; num
< maxcpus
; num
++) {
440 if (CPU_ISSET(num
, tmp
))
441 desc
->idx2cpunum
[idx
++] = num
;
445 err(EXIT_FAILURE
, _("failed to determine number of CPUs: %s"),
446 _PATH_SYS_CPU
"/possible");
449 /* get mask for present CPUs */
450 if (path_exist(_PATH_SYS_CPU
"/present")) {
451 desc
->present
= path_read_cpulist(maxcpus
, _PATH_SYS_CPU
"/present");
452 desc
->ncpus
= CPU_COUNT_S(setsize
, desc
->present
);
455 /* get mask for online CPUs */
456 if (path_exist(_PATH_SYS_CPU
"/online")) {
457 desc
->online
= path_read_cpulist(maxcpus
, _PATH_SYS_CPU
"/online");
458 desc
->nthreads
= CPU_COUNT_S(setsize
, desc
->online
);
461 /* get dispatching mode */
462 if (path_exist(_PATH_SYS_CPU
"/dispatching"))
463 desc
->dispatching
= path_read_s32(_PATH_SYS_CPU
"/dispatching");
465 desc
->dispatching
= -1;
469 has_pci_device(unsigned int vendor
, unsigned int device
)
472 unsigned int num
, fn
, ven
, dev
;
475 f
= path_fopen("r", 0, _PATH_PROC_PCIDEVS
);
479 /* for more details about bus/pci/devices format see
480 * drivers/pci/proc.c in linux kernel
482 while(fscanf(f
, "%02x%02x\t%04x%04x\t%*[^\n]",
483 &num
, &fn
, &ven
, &dev
) == 4) {
485 if (ven
== vendor
&& dev
== device
)
495 #if defined(__x86_64__) || defined(__i386__)
498 * This CPUID leaf returns the information about the hypervisor.
499 * EAX : maximum input value for CPUID supported by the hypervisor.
500 * EBX, ECX, EDX : Hypervisor vendor ID signature. E.g. VMwareVMware.
502 #define HYPERVISOR_INFO_LEAF 0x40000000
505 cpuid(unsigned int op
, unsigned int *eax
, unsigned int *ebx
,
506 unsigned int *ecx
, unsigned int *edx
)
509 #if defined(__PIC__) && defined(__i386__)
510 /* x86 PIC cannot clobber ebx -- gcc bitches */
527 read_hypervisor_cpuid(struct lscpu_desc
*desc
)
529 unsigned int eax
= 0, ebx
= 0, ecx
= 0, edx
= 0;
530 char hyper_vendor_id
[13];
532 memset(hyper_vendor_id
, 0, sizeof(hyper_vendor_id
));
534 cpuid(HYPERVISOR_INFO_LEAF
, &eax
, &ebx
, &ecx
, &edx
);
535 memcpy(hyper_vendor_id
+ 0, &ebx
, 4);
536 memcpy(hyper_vendor_id
+ 4, &ecx
, 4);
537 memcpy(hyper_vendor_id
+ 8, &edx
, 4);
538 hyper_vendor_id
[12] = '\0';
540 if (!hyper_vendor_id
[0])
543 if (!strncmp("XenVMMXenVMM", hyper_vendor_id
, 12))
544 desc
->hyper
= HYPER_XEN
;
545 else if (!strncmp("KVMKVMKVM", hyper_vendor_id
, 9))
546 desc
->hyper
= HYPER_KVM
;
547 else if (!strncmp("Microsoft Hv", hyper_vendor_id
, 12))
548 desc
->hyper
= HYPER_MSHV
;
549 else if (!strncmp("VMwareVMware", hyper_vendor_id
, 12))
550 desc
->hyper
= HYPER_VMWARE
;
553 #else /* ! __x86_64__ */
555 read_hypervisor_cpuid(struct lscpu_desc
*desc
__attribute__((__unused__
)))
561 read_hypervisor(struct lscpu_desc
*desc
, struct lscpu_modifier
*mod
)
565 if (mod
->system
!= SYSTEM_SNAPSHOT
) {
566 read_hypervisor_cpuid(desc
);
568 desc
->hyper
= read_hypervisor_dmi();
572 desc
->virtype
= VIRT_FULL
;
574 /* Xen para-virt or dom0 */
575 else if (path_exist(_PATH_PROC_XEN
)) {
577 fd
= path_fopen("r", 0, _PATH_PROC_XENCAP
);
582 if (fscanf(fd
, "%s", buf
) == 1 &&
583 !strcmp(buf
, "control_d"))
587 desc
->virtype
= dom0
? VIRT_NONE
: VIRT_PARA
;
588 desc
->hyper
= HYPER_XEN
;
590 /* Xen full-virt on non-x86_64 */
591 } else if (has_pci_device(0x5853, 0x0001)) {
592 desc
->hyper
= HYPER_XEN
;
593 desc
->virtype
= VIRT_FULL
;
596 } else if (path_exist(_PATH_PROC_SYSINFO
)) {
597 FILE *sysinfo_fd
= path_fopen("r", 0, _PATH_PROC_SYSINFO
);
602 desc
->hyper
= HYPER_IBM
;
603 desc
->hypervisor
= "PR/SM";
604 desc
->virtype
= VIRT_FULL
;
605 while (fgets(buf
, sizeof(buf
), sysinfo_fd
) != NULL
) {
608 if (!strstr(buf
, "Control Program:"))
610 if (!strstr(buf
, "KVM"))
611 desc
->hyper
= HYPER_IBM
;
613 desc
->hyper
= HYPER_KVM
;
614 str
= strchr(buf
, ':');
617 xasprintf(&str
, "%s", str
+ 1);
619 /* remove leading, trailing and repeating whitespace */
622 desc
->hypervisor
= str
;
623 str
+= strlen(str
) - 1;
624 while ((*str
== '\n') || (*str
== ' '))
626 while ((str
= strstr(desc
->hypervisor
, " ")))
627 memmove(str
, str
+ 1, strlen(str
));
632 /* OpenVZ/Virtuozzo - /proc/vz dir should exist
633 * /proc/bc should not */
634 else if (path_exist(_PATH_PROC_VZ
) && !path_exist(_PATH_PROC_BC
)) {
635 desc
->hyper
= HYPER_PARALLELS
;
636 desc
->virtype
= VIRT_CONT
;
639 } else if (desc
->vendor
&&
640 (strcmp(desc
->vendor
, "PowerVM Lx86") == 0 ||
641 strcmp(desc
->vendor
, "IBM/S390") == 0)) {
642 desc
->hyper
= HYPER_IBM
;
643 desc
->virtype
= VIRT_FULL
;
645 /* User-mode-linux */
646 } else if (desc
->modelname
&& strstr(desc
->modelname
, "UML")) {
647 desc
->hyper
= HYPER_UML
;
648 desc
->virtype
= VIRT_PARA
;
651 } else if (path_exist(_PATH_PROC_STATUS
)) {
655 fd
= path_fopen("r", 1, _PATH_PROC_STATUS
);
656 while (fgets(buf
, sizeof(buf
), fd
) != NULL
) {
657 if (lookup(buf
, "VxID", &val
))
663 while (isdigit(*val
))
666 desc
->hyper
= HYPER_VSERVER
;
667 desc
->virtype
= VIRT_CONT
;
673 /* add @set to the @ary, unnecessary set is deallocated. */
674 static int add_cpuset_to_array(cpu_set_t
**ary
, int *items
, cpu_set_t
*set
)
677 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
682 for (i
= 0; i
< *items
; i
++) {
683 if (CPU_EQUAL_S(setsize
, set
, ary
[i
]))
696 read_topology(struct lscpu_desc
*desc
, int idx
)
698 cpu_set_t
*thread_siblings
, *core_siblings
, *book_siblings
;
699 int num
= real_cpu_num(desc
, idx
);
701 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/topology/thread_siblings", num
))
704 thread_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
705 "/cpu%d/topology/thread_siblings", num
);
706 core_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
707 "/cpu%d/topology/core_siblings", num
);
708 book_siblings
= NULL
;
709 if (path_exist(_PATH_SYS_CPU
"/cpu%d/topology/book_siblings", num
))
710 book_siblings
= path_read_cpuset(maxcpus
, _PATH_SYS_CPU
711 "/cpu%d/topology/book_siblings", num
);
713 if (!desc
->coremaps
) {
714 int nbooks
, nsockets
, ncores
, nthreads
;
715 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
717 /* threads within one core */
718 nthreads
= CPU_COUNT_S(setsize
, thread_siblings
);
722 /* cores within one socket */
723 ncores
= CPU_COUNT_S(setsize
, core_siblings
) / nthreads
;
727 /* number of sockets within one book. Because of odd /
728 * non-present cpu maps and to keep calculation easy we make
729 * sure that nsockets and nbooks is at least 1.
731 nsockets
= desc
->ncpus
/ nthreads
/ ncores
;
735 /* number of books */
736 nbooks
= desc
->ncpus
/ nthreads
/ ncores
/ nsockets
;
740 /* all threads, see also read_basicinfo()
741 * -- fallback for kernels without
742 * /sys/devices/system/cpu/online.
745 desc
->nthreads
= nbooks
* nsockets
* ncores
* nthreads
;
747 /* For each map we make sure that it can have up to ncpuspos
748 * entries. This is because we cannot reliably calculate the
749 * number of cores, sockets and books on all architectures.
750 * E.g. completely virtualized architectures like s390 may
751 * have multiple sockets of different sizes.
753 desc
->coremaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
754 desc
->socketmaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
756 desc
->bookmaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
759 add_cpuset_to_array(desc
->socketmaps
, &desc
->nsockets
, core_siblings
);
760 add_cpuset_to_array(desc
->coremaps
, &desc
->ncores
, thread_siblings
);
762 add_cpuset_to_array(desc
->bookmaps
, &desc
->nbooks
, book_siblings
);
766 read_polarization(struct lscpu_desc
*desc
, int idx
)
769 int num
= real_cpu_num(desc
, idx
);
771 if (desc
->dispatching
< 0)
773 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/polarization", num
))
775 if (!desc
->polarization
)
776 desc
->polarization
= xcalloc(desc
->ncpuspos
, sizeof(int));
777 path_read_str(mode
, sizeof(mode
), _PATH_SYS_CPU
"/cpu%d/polarization", num
);
778 if (strncmp(mode
, "vertical:low", sizeof(mode
)) == 0)
779 desc
->polarization
[idx
] = POLAR_VLOW
;
780 else if (strncmp(mode
, "vertical:medium", sizeof(mode
)) == 0)
781 desc
->polarization
[idx
] = POLAR_VMEDIUM
;
782 else if (strncmp(mode
, "vertical:high", sizeof(mode
)) == 0)
783 desc
->polarization
[idx
] = POLAR_VHIGH
;
784 else if (strncmp(mode
, "horizontal", sizeof(mode
)) == 0)
785 desc
->polarization
[idx
] = POLAR_HORIZONTAL
;
787 desc
->polarization
[idx
] = POLAR_UNKNOWN
;
791 read_address(struct lscpu_desc
*desc
, int idx
)
793 int num
= real_cpu_num(desc
, idx
);
795 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/address", num
))
797 if (!desc
->addresses
)
798 desc
->addresses
= xcalloc(desc
->ncpuspos
, sizeof(int));
799 desc
->addresses
[idx
] = path_read_s32(_PATH_SYS_CPU
"/cpu%d/address", num
);
803 read_configured(struct lscpu_desc
*desc
, int idx
)
805 int num
= real_cpu_num(desc
, idx
);
807 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/configure", num
))
809 if (!desc
->configured
)
810 desc
->configured
= xcalloc(desc
->ncpuspos
, sizeof(int));
811 desc
->configured
[idx
] = path_read_s32(_PATH_SYS_CPU
"/cpu%d/configure", num
);
815 read_max_mhz(struct lscpu_desc
*desc
, int idx
)
817 int num
= real_cpu_num(desc
, idx
);
819 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/cpufreq/cpuinfo_max_freq", num
))
822 desc
->maxmhz
= xcalloc(desc
->ncpuspos
, sizeof(char *));
823 xasprintf(&(desc
->maxmhz
[idx
]), "%.4f",
824 (float)path_read_s32(_PATH_SYS_CPU
825 "/cpu%d/cpufreq/cpuinfo_max_freq", num
) / 1000);
829 read_min_mhz(struct lscpu_desc
*desc
, int idx
)
831 int num
= real_cpu_num(desc
, idx
);
833 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/cpufreq/cpuinfo_min_freq", num
))
836 desc
->minmhz
= xcalloc(desc
->ncpuspos
, sizeof(char *));
837 xasprintf(&(desc
->minmhz
[idx
]), "%.4f",
838 (float)path_read_s32(_PATH_SYS_CPU
839 "/cpu%d/cpufreq/cpuinfo_min_freq", num
) / 1000);
843 cachecmp(const void *a
, const void *b
)
845 struct cpu_cache
*c1
= (struct cpu_cache
*) a
;
846 struct cpu_cache
*c2
= (struct cpu_cache
*) b
;
848 return strcmp(c2
->name
, c1
->name
);
852 read_cache(struct lscpu_desc
*desc
, int idx
)
856 int num
= real_cpu_num(desc
, idx
);
858 if (!desc
->ncaches
) {
859 while(path_exist(_PATH_SYS_CPU
"/cpu%d/cache/index%d",
866 desc
->caches
= xcalloc(desc
->ncaches
, sizeof(*desc
->caches
));
868 for (i
= 0; i
< desc
->ncaches
; i
++) {
869 struct cpu_cache
*ca
= &desc
->caches
[i
];
872 if (!path_exist(_PATH_SYS_CPU
"/cpu%d/cache/index%d",
879 path_read_str(buf
, sizeof(buf
),
880 _PATH_SYS_CPU
"/cpu%d/cache/index%d/type",
882 if (!strcmp(buf
, "Data"))
884 else if (!strcmp(buf
, "Instruction"))
890 level
= path_read_s32(_PATH_SYS_CPU
"/cpu%d/cache/index%d/level",
893 snprintf(buf
, sizeof(buf
), "L%d%c", level
, type
);
895 snprintf(buf
, sizeof(buf
), "L%d", level
);
897 ca
->name
= xstrdup(buf
);
900 if (path_exist(_PATH_SYS_CPU
"/cpu%d/cache/index%d/size",num
, i
)) {
901 path_read_str(buf
, sizeof(buf
),
902 _PATH_SYS_CPU
"/cpu%d/cache/index%d/size", num
, i
);
903 ca
->size
= xstrdup(buf
);
905 ca
->size
= xstrdup("unknown size");
909 /* information about how CPUs share different caches */
910 map
= path_read_cpuset(maxcpus
,
911 _PATH_SYS_CPU
"/cpu%d/cache/index%d/shared_cpu_map",
915 ca
->sharedmaps
= xcalloc(desc
->ncpuspos
, sizeof(cpu_set_t
*));
916 add_cpuset_to_array(ca
->sharedmaps
, &ca
->nsharedmaps
, map
);
920 static inline int is_node_dirent(struct dirent
*d
)
924 #ifdef _DIRENT_HAVE_D_TYPE
925 (d
->d_type
== DT_DIR
|| d
->d_type
== DT_UNKNOWN
) &&
927 strncmp(d
->d_name
, "node", 4) == 0 &&
928 isdigit_string(d
->d_name
+ 4);
932 nodecmp(const void *ap
, const void *bp
)
934 int *a
= (int *) ap
, *b
= (int *) bp
;
939 read_nodes(struct lscpu_desc
*desc
)
946 /* number of NUMA node */
947 path
= path_strdup(_PATH_SYS_NODE
);
951 while (dir
&& (d
= readdir(dir
))) {
952 if (is_node_dirent(d
))
962 desc
->nodemaps
= xcalloc(desc
->nnodes
, sizeof(cpu_set_t
*));
963 desc
->idx2nodenum
= xmalloc(desc
->nnodes
* sizeof(int));
967 while ((d
= readdir(dir
)) && i
< desc
->nnodes
) {
968 if (is_node_dirent(d
))
969 desc
->idx2nodenum
[i
++] = strtol_or_err(((d
->d_name
) + 4),
970 _("Failed to extract the node number"));
973 qsort(desc
->idx2nodenum
, desc
->nnodes
, sizeof(int), nodecmp
);
976 /* information about how nodes share different CPUs */
977 for (i
= 0; i
< desc
->nnodes
; i
++)
978 desc
->nodemaps
[i
] = path_read_cpuset(maxcpus
,
979 _PATH_SYS_NODE
"/node%d/cpumap",
980 desc
->idx2nodenum
[i
]);
984 get_cell_data(struct lscpu_desc
*desc
, int idx
, int col
,
985 struct lscpu_modifier
*mod
,
986 char *buf
, size_t bufsz
)
988 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
990 int cpu
= real_cpu_num(desc
, idx
);
996 snprintf(buf
, bufsz
, "%d", cpu
);
999 if (cpuset_ary_isset(cpu
, desc
->coremaps
,
1000 desc
->ncores
, setsize
, &i
) == 0)
1001 snprintf(buf
, bufsz
, "%zd", i
);
1004 if (cpuset_ary_isset(cpu
, desc
->socketmaps
,
1005 desc
->nsockets
, setsize
, &i
) == 0)
1006 snprintf(buf
, bufsz
, "%zd", i
);
1009 if (cpuset_ary_isset(cpu
, desc
->nodemaps
,
1010 desc
->nnodes
, setsize
, &i
) == 0)
1011 snprintf(buf
, bufsz
, "%d", desc
->idx2nodenum
[i
]);
1014 if (cpuset_ary_isset(cpu
, desc
->bookmaps
,
1015 desc
->nbooks
, setsize
, &i
) == 0)
1016 snprintf(buf
, bufsz
, "%zd", i
);
1024 for (j
= desc
->ncaches
- 1; j
>= 0; j
--) {
1025 struct cpu_cache
*ca
= &desc
->caches
[j
];
1027 if (cpuset_ary_isset(cpu
, ca
->sharedmaps
,
1028 ca
->nsharedmaps
, setsize
, &i
) == 0) {
1029 int x
= snprintf(p
, sz
, "%zd", i
);
1030 if (x
<= 0 || (size_t) x
+ 2 >= sz
)
1036 *p
++ = mod
->compat
? ',' : ':';
1043 case COL_POLARIZATION
:
1044 if (desc
->polarization
) {
1045 int x
= desc
->polarization
[idx
];
1047 snprintf(buf
, bufsz
, "%s",
1048 mod
->mode
== OUTPUT_PARSABLE
?
1049 polar_modes
[x
].parsable
:
1050 polar_modes
[x
].readable
);
1054 if (desc
->addresses
)
1055 snprintf(buf
, bufsz
, "%d", desc
->addresses
[idx
]);
1057 case COL_CONFIGURED
:
1058 if (!desc
->configured
)
1060 if (mod
->mode
== OUTPUT_PARSABLE
)
1061 snprintf(buf
, bufsz
,
1062 desc
->configured
[idx
] ? _("Y") : _("N"));
1064 snprintf(buf
, bufsz
,
1065 desc
->configured
[idx
] ? _("yes") : _("no"));
1070 if (mod
->mode
== OUTPUT_PARSABLE
)
1071 snprintf(buf
, bufsz
,
1072 is_cpu_online(desc
, cpu
) ? _("Y") : _("N"));
1074 snprintf(buf
, bufsz
,
1075 is_cpu_online(desc
, cpu
) ? _("yes") : _("no"));
1079 xstrncpy(buf
, desc
->maxmhz
[idx
], bufsz
);
1083 xstrncpy(buf
, desc
->minmhz
[idx
], bufsz
);
1090 get_cell_header(struct lscpu_desc
*desc
, int col
,
1091 struct lscpu_modifier
*mod
,
1092 char *buf
, size_t bufsz
)
1096 if (col
== COL_CACHE
) {
1101 for (i
= desc
->ncaches
- 1; i
>= 0; i
--) {
1102 int x
= snprintf(p
, sz
, "%s", desc
->caches
[i
].name
);
1103 if (x
<= 0 || (size_t) x
+ 2 > sz
)
1108 *p
++ = mod
->compat
? ',' : ':';
1116 snprintf(buf
, bufsz
, "%s", coldescs
[col
].name
);
1121 * [-p] backend, we support two parsable formats:
1123 * 1) "compatible" -- this format is compatible with the original lscpu(1)
1124 * output and it contains fixed set of the columns. The CACHE columns are at
1125 * the end of the line and the CACHE is not printed if the number of the caches
1126 * is zero. The CACHE columns are separated by two commas, for example:
1129 * # CPU,Core,Socket,Node,,L1d,L1i,L2
1133 * 2) "user defined output" -- this format prints always all columns without
1134 * special prefix for CACHE column. If there are not CACHEs then the column is
1135 * empty and the header "Cache" is printed rather than a real name of the cache.
1136 * The CACHE columns are separated by ':'.
1138 * $ lscpu --parse=CPU,CORE,SOCKET,NODE,CACHE
1139 * # CPU,Core,Socket,Node,L1d:L1i:L2
1144 print_parsable(struct lscpu_desc
*desc
, int cols
[], int ncols
,
1145 struct lscpu_modifier
*mod
)
1147 char buf
[BUFSIZ
], *data
;
1154 "# The following is the parsable format, which can be fed to other\n"
1155 "# programs. Each different item in every column has an unique ID\n"
1156 "# starting from zero.\n"));
1158 fputs("# ", stdout
);
1159 for (i
= 0; i
< ncols
; i
++) {
1162 if (col
== COL_CACHE
) {
1163 if (mod
->compat
&& !desc
->ncaches
)
1165 if (mod
->compat
&& i
!= 0)
1171 data
= get_cell_header(desc
, col
, mod
, buf
, sizeof(buf
));
1173 if (data
&& * data
&& col
!= COL_CACHE
&&
1174 !coldescs
[col
].is_abbr
) {
1176 * For normal column names use mixed case (e.g. "Socket")
1180 while (p
&& *p
!= '\0') {
1181 *p
= tolower((unsigned int) *p
);
1185 fputs(data
&& *data
? data
: "", stdout
);
1192 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1194 int cpu
= real_cpu_num(desc
, i
);
1196 if (!mod
->offline
&& desc
->online
&& !is_cpu_online(desc
, cpu
))
1198 if (!mod
->online
&& desc
->online
&& is_cpu_online(desc
, cpu
))
1200 if (desc
->present
&& !is_cpu_present(desc
, cpu
))
1202 for (c
= 0; c
< ncols
; c
++) {
1203 if (mod
->compat
&& cols
[c
] == COL_CACHE
) {
1212 data
= get_cell_data(desc
, i
, cols
[c
], mod
,
1214 fputs(data
&& *data
? data
: "", stdout
);
1224 print_readable(struct lscpu_desc
*desc
, int cols
[], int ncols
,
1225 struct lscpu_modifier
*mod
)
1228 char buf
[BUFSIZ
], *data
;
1229 struct tt
*tt
= tt_new_table(TT_FL_FREEDATA
);
1232 err(EXIT_FAILURE
, _("failed to initialize output table"));
1234 for (i
= 0; i
< ncols
; i
++) {
1235 data
= get_cell_header(desc
, cols
[i
], mod
, buf
, sizeof(buf
));
1236 tt_define_column(tt
, xstrdup(data
), 0, 0);
1239 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1241 struct tt_line
*line
;
1242 int cpu
= real_cpu_num(desc
, i
);
1244 if (!mod
->offline
&& desc
->online
&& !is_cpu_online(desc
, cpu
))
1246 if (!mod
->online
&& desc
->online
&& is_cpu_online(desc
, cpu
))
1248 if (desc
->present
&& !is_cpu_present(desc
, cpu
))
1251 line
= tt_add_line(tt
, NULL
);
1253 for (c
= 0; c
< ncols
; c
++) {
1254 data
= get_cell_data(desc
, i
, cols
[c
], mod
,
1256 tt_line_set_data(line
, c
,
1257 xstrdup(data
&& *data
? data
: "-"));
1265 /* output formats "<key> <value>"*/
1266 #define print_s(_key, _val) printf("%-23s%s\n", _key, _val)
1267 #define print_n(_key, _val) printf("%-23s%d\n", _key, _val)
1270 print_cpuset(const char *key
, cpu_set_t
*set
, int hex
)
1272 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1273 size_t setbuflen
= 7 * maxcpus
;
1274 char setbuf
[setbuflen
], *p
;
1277 p
= cpumask_create(setbuf
, setbuflen
, set
, setsize
);
1278 printf("%-23s0x%s\n", key
, p
);
1280 p
= cpulist_create(setbuf
, setbuflen
, set
, setsize
);
1290 print_summary(struct lscpu_desc
*desc
, struct lscpu_modifier
*mod
)
1294 size_t setsize
= CPU_ALLOC_SIZE(maxcpus
);
1296 print_s(_("Architecture:"), desc
->arch
);
1299 char mbuf
[64], *p
= mbuf
;
1301 if (desc
->mode
& MODE_32BIT
) {
1302 strcpy(p
, "32-bit, ");
1305 if (desc
->mode
& MODE_64BIT
) {
1306 strcpy(p
, "64-bit, ");
1310 print_s(_("CPU op-mode(s):"), mbuf
);
1312 #if !defined(WORDS_BIGENDIAN)
1313 print_s(_("Byte Order:"), "Little Endian");
1315 print_s(_("Byte Order:"), "Big Endian");
1317 print_n(_("CPU(s):"), desc
->ncpus
);
1320 print_cpuset(mod
->hex
? _("On-line CPU(s) mask:") :
1321 _("On-line CPU(s) list:"),
1322 desc
->online
, mod
->hex
);
1324 if (desc
->online
&& CPU_COUNT_S(setsize
, desc
->online
) != desc
->ncpus
) {
1327 /* Linux kernel provides cpuset of off-line CPUs that contains
1328 * all configured CPUs (see /sys/devices/system/cpu/offline),
1329 * but want to print real (present in system) off-line CPUs only.
1331 set
= cpuset_alloc(maxcpus
, NULL
, NULL
);
1333 err(EXIT_FAILURE
, _("failed to callocate cpu set"));
1334 CPU_ZERO_S(setsize
, set
);
1335 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1336 int cpu
= real_cpu_num(desc
, i
);
1337 if (!is_cpu_online(desc
, cpu
) && is_cpu_present(desc
, cpu
))
1338 CPU_SET_S(cpu
, setsize
, set
);
1340 print_cpuset(mod
->hex
? _("Off-line CPU(s) mask:") :
1341 _("Off-line CPU(s) list:"),
1346 if (desc
->nsockets
) {
1347 int cores_per_socket
, sockets_per_book
, books
;
1349 cores_per_socket
= sockets_per_book
= books
= 0;
1350 /* s390 detects its cpu topology via /proc/sysinfo, if present.
1351 * Using simply the cpu topology masks in sysfs will not give
1352 * usable results since everything is virtualized. E.g.
1353 * virtual core 0 may have only 1 cpu, but virtual core 2 may
1355 * If the cpu topology is not exported (e.g. 2nd level guest)
1356 * fall back to old calculation scheme.
1358 if (path_exist(_PATH_PROC_SYSINFO
)) {
1359 FILE *fd
= path_fopen("r", 0, _PATH_PROC_SYSINFO
);
1363 while (fd
&& fgets(pbuf
, sizeof(pbuf
), fd
) != NULL
) {
1364 if (sscanf(pbuf
, "CPU Topology SW:%d%d%d%d%d%d",
1365 &t0
, &t1
, &t2
, &books
, &sockets_per_book
,
1366 &cores_per_socket
) == 6)
1372 print_n(_("Thread(s) per core:"), desc
->nthreads
/ desc
->ncores
);
1373 print_n(_("Core(s) per socket:"),
1374 cores_per_socket
?: desc
->ncores
/ desc
->nsockets
);
1376 print_n(_("Socket(s) per book:"),
1377 sockets_per_book
?: desc
->nsockets
/ desc
->nbooks
);
1378 print_n(_("Book(s):"), books
?: desc
->nbooks
);
1380 print_n(_("Socket(s):"), sockets_per_book
?: desc
->nsockets
);
1384 print_n(_("NUMA node(s):"), desc
->nnodes
);
1386 print_s(_("Vendor ID:"), desc
->vendor
);
1388 print_s(_("CPU family:"), desc
->family
);
1390 print_s(_("Model:"), desc
->model
);
1391 if (desc
->modelname
)
1392 print_s(_("Model name:"), desc
->modelname
);
1394 print_s(_("Stepping:"), desc
->stepping
);
1396 print_s(_("CPU MHz:"), desc
->mhz
);
1398 print_s(_("CPU max MHz:"), desc
->maxmhz
[0]);
1400 print_s(_("CPU min MHz:"), desc
->minmhz
[0]);
1402 print_s(_("BogoMIPS:"), desc
->bogomips
);
1403 if (desc
->virtflag
) {
1404 if (!strcmp(desc
->virtflag
, "svm"))
1405 print_s(_("Virtualization:"), "AMD-V");
1406 else if (!strcmp(desc
->virtflag
, "vmx"))
1407 print_s(_("Virtualization:"), "VT-x");
1409 if (desc
->hypervisor
)
1410 print_s(_("Hypervisor:"), desc
->hypervisor
);
1412 print_s(_("Hypervisor vendor:"), hv_vendors
[desc
->hyper
]);
1413 print_s(_("Virtualization type:"), _(virt_types
[desc
->virtype
]));
1415 if (desc
->dispatching
>= 0)
1416 print_s(_("Dispatching mode:"), _(disp_modes
[desc
->dispatching
]));
1417 if (desc
->ncaches
) {
1420 for (i
= desc
->ncaches
- 1; i
>= 0; i
--) {
1421 snprintf(cbuf
, sizeof(cbuf
),
1422 _("%s cache:"), desc
->caches
[i
].name
);
1423 print_s(cbuf
, desc
->caches
[i
].size
);
1427 for (i
= 0; i
< desc
->nnodes
; i
++) {
1428 snprintf(buf
, sizeof(buf
), _("NUMA node%d CPU(s):"), desc
->idx2nodenum
[i
]);
1429 print_cpuset(buf
, desc
->nodemaps
[i
], mod
->hex
);
1433 static void __attribute__((__noreturn__
)) usage(FILE *out
)
1437 fputs(USAGE_HEADER
, out
);
1438 fprintf(out
, _(" %s [options]\n"), program_invocation_short_name
);
1440 fputs(USAGE_OPTIONS
, out
);
1441 fputs(_(" -a, --all print both online and offline CPUs (default for -e)\n"), out
);
1442 fputs(_(" -b, --online print online CPUs only (default for -p)\n"), out
);
1443 fputs(_(" -c, --offline print offline CPUs only\n"), out
);
1444 fputs(_(" -e, --extended[=<list>] print out an extended readable format\n"), out
);
1445 fputs(_(" -p, --parse[=<list>] print out a parsable format\n"), out
);
1446 fputs(_(" -s, --sysroot <dir> use specified directory as system root\n"), out
);
1447 fputs(_(" -x, --hex print hexadecimal masks rather than lists of CPUs\n"), out
);
1448 fputs(USAGE_SEPARATOR
, out
);
1449 fputs(USAGE_HELP
, out
);
1450 fputs(USAGE_VERSION
, out
);
1452 fprintf(out
, _("\nAvailable columns:\n"));
1454 for (i
= 0; i
< ARRAY_SIZE(coldescs
); i
++)
1455 fprintf(out
, " %13s %s\n", coldescs
[i
].name
, _(coldescs
[i
].help
));
1457 fprintf(out
, _("\nFor more details see lscpu(1).\n"));
1459 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
1462 int main(int argc
, char *argv
[])
1464 struct lscpu_modifier _mod
= { .mode
= OUTPUT_SUMMARY
}, *mod
= &_mod
;
1465 struct lscpu_desc _desc
= { .flags
= 0 }, *desc
= &_desc
;
1467 int columns
[ARRAY_SIZE(coldescs
)], ncolumns
= 0;
1468 int cpu_modifier_specified
= 0;
1470 static const struct option longopts
[] = {
1471 { "all", no_argument
, 0, 'a' },
1472 { "online", no_argument
, 0, 'b' },
1473 { "offline", no_argument
, 0, 'c' },
1474 { "help", no_argument
, 0, 'h' },
1475 { "extended", optional_argument
, 0, 'e' },
1476 { "parse", optional_argument
, 0, 'p' },
1477 { "sysroot", required_argument
, 0, 's' },
1478 { "hex", no_argument
, 0, 'x' },
1479 { "version", no_argument
, 0, 'V' },
1483 static const ul_excl_t excl
[] = { /* rows and cols in ASCII order */
1488 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
1490 setlocale(LC_ALL
, "");
1491 bindtextdomain(PACKAGE
, LOCALEDIR
);
1492 textdomain(PACKAGE
);
1493 atexit(close_stdout
);
1495 while ((c
= getopt_long(argc
, argv
, "abce::hp::s:xV", longopts
, NULL
)) != -1) {
1497 err_exclusive_options(c
, longopts
, excl
, excl_st
);
1501 mod
->online
= mod
->offline
= 1;
1502 cpu_modifier_specified
= 1;
1506 cpu_modifier_specified
= 1;
1510 cpu_modifier_specified
= 1;
1519 ncolumns
= string_to_idarray(optarg
,
1520 columns
, ARRAY_SIZE(columns
),
1523 return EXIT_FAILURE
;
1525 mod
->mode
= c
== 'p' ? OUTPUT_PARSABLE
: OUTPUT_READABLE
;
1528 path_set_prefix(optarg
);
1529 mod
->system
= SYSTEM_SNAPSHOT
;
1535 printf(_("%s from %s\n"), program_invocation_short_name
,
1537 return EXIT_SUCCESS
;
1543 if (cpu_modifier_specified
&& mod
->mode
== OUTPUT_SUMMARY
) {
1545 _("%s: options --all, --online and --offline may only "
1546 "be used with options --extended or --parse.\n"),
1547 program_invocation_short_name
);
1548 return EXIT_FAILURE
;
1554 /* set default cpu display mode if none was specified */
1555 if (!mod
->online
&& !mod
->offline
) {
1557 mod
->offline
= mod
->mode
== OUTPUT_READABLE
? 1 : 0;
1560 read_basicinfo(desc
, mod
);
1562 for (i
= 0; i
< desc
->ncpuspos
; i
++) {
1563 read_topology(desc
, i
);
1564 read_cache(desc
, i
);
1565 read_polarization(desc
, i
);
1566 read_address(desc
, i
);
1567 read_configured(desc
, i
);
1568 read_max_mhz(desc
, i
);
1569 read_min_mhz(desc
, i
);
1573 qsort(desc
->caches
, desc
->ncaches
,
1574 sizeof(struct cpu_cache
), cachecmp
);
1577 read_hypervisor(desc
, mod
);
1580 case OUTPUT_SUMMARY
:
1581 print_summary(desc
, mod
);
1583 case OUTPUT_PARSABLE
:
1585 columns
[ncolumns
++] = COL_CPU
;
1586 columns
[ncolumns
++] = COL_CORE
;
1587 columns
[ncolumns
++] = COL_SOCKET
;
1588 columns
[ncolumns
++] = COL_NODE
;
1589 columns
[ncolumns
++] = COL_CACHE
;
1592 print_parsable(desc
, columns
, ncolumns
, mod
);
1594 case OUTPUT_READABLE
:
1596 /* No list was given. Just print whatever is there. */
1597 columns
[ncolumns
++] = COL_CPU
;
1599 columns
[ncolumns
++] = COL_NODE
;
1601 columns
[ncolumns
++] = COL_BOOK
;
1602 if (desc
->socketmaps
)
1603 columns
[ncolumns
++] = COL_SOCKET
;
1605 columns
[ncolumns
++] = COL_CORE
;
1607 columns
[ncolumns
++] = COL_CACHE
;
1609 columns
[ncolumns
++] = COL_ONLINE
;
1610 if (desc
->configured
)
1611 columns
[ncolumns
++] = COL_CONFIGURED
;
1612 if (desc
->polarization
)
1613 columns
[ncolumns
++] = COL_POLARIZATION
;
1614 if (desc
->addresses
)
1615 columns
[ncolumns
++] = COL_ADDRESS
;
1617 columns
[ncolumns
++] = COL_MAXMHZ
;
1619 columns
[ncolumns
++] = COL_MINMHZ
;
1621 print_readable(desc
, columns
, ncolumns
, mod
);
1625 return EXIT_SUCCESS
;