1/* Print CPU diagnostics data in ld.so. x86 version.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <dl-diagnostics.h>
20#include <ldsodefs.h>
21
22static void
23print_cpu_features_value (const char *label, uint64_t value)
24{
25 _dl_printf (fmt: "x86.cpu_features.");
26 _dl_diagnostics_print_labeled_value (label, value);
27}
28
29static void
30print_cpu_feature_internal (unsigned int index, const char *kind,
31 unsigned int reg, uint32_t value)
32{
33 _dl_printf (fmt: "x86.cpu_features.features[0x%x].%s[0x%x]=0x%x\n",
34 index, kind, reg, value);
35}
36
37static void
38print_cpu_feature_preferred (const char *label, unsigned int flag)
39{
40 _dl_printf(fmt: "x86.cpu_features.preferred.%s=0x%x\n", label, flag);
41}
42
43void
44_dl_diagnostics_cpu (void)
45{
46 const struct cpu_features *cpu_features = __get_cpu_features ();
47
48 print_cpu_features_value (label: "basic.kind", value: cpu_features->basic.kind);
49 print_cpu_features_value (label: "basic.max_cpuid", value: cpu_features->basic.max_cpuid);
50 print_cpu_features_value (label: "basic.family", value: cpu_features->basic.family);
51 print_cpu_features_value (label: "basic.model", value: cpu_features->basic.model);
52 print_cpu_features_value (label: "basic.stepping", value: cpu_features->basic.stepping);
53
54 for (unsigned int index = 0; index < CPUID_INDEX_MAX; ++index)
55 {
56 /* The index values are part of the ABI via
57 <sys/platform/x86.h>, so translating them to strings is not
58 necessary. */
59 for (unsigned int reg = 0; reg < 4; ++reg)
60 print_cpu_feature_internal
61 (index, kind: "cpuid", reg,
62 value: cpu_features->features[index].cpuid_array[reg]);
63 for (unsigned int reg = 0; reg < 4; ++reg)
64 print_cpu_feature_internal
65 (index, kind: "active", reg,
66 value: cpu_features->features[index].active_array[reg]);
67 }
68
69 /* The preferred indicators are not part of the ABI and need to be
70 translated. */
71#define BIT(x) \
72 print_cpu_feature_preferred (#x, CPU_FEATURE_PREFERRED_P (cpu_features, x));
73#include "cpu-features-preferred_feature_index_1.def"
74#undef BIT
75
76 print_cpu_features_value (label: "isa_1", value: cpu_features->isa_1);
77 print_cpu_features_value (label: "xsave_state_size",
78 value: cpu_features->xsave_state_size);
79 print_cpu_features_value (label: "xsave_state_full_size",
80 value: cpu_features->xsave_state_full_size);
81 print_cpu_features_value (label: "data_cache_size", value: cpu_features->data_cache_size);
82 print_cpu_features_value (label: "shared_cache_size",
83 value: cpu_features->shared_cache_size);
84 print_cpu_features_value (label: "non_temporal_threshold",
85 value: cpu_features->non_temporal_threshold);
86 print_cpu_features_value (label: "rep_movsb_threshold",
87 value: cpu_features->rep_movsb_threshold);
88 print_cpu_features_value (label: "rep_movsb_stop_threshold",
89 value: cpu_features->rep_movsb_stop_threshold);
90 print_cpu_features_value (label: "rep_stosb_threshold",
91 value: cpu_features->rep_stosb_threshold);
92 print_cpu_features_value (label: "level1_icache_size",
93 value: cpu_features->level1_icache_size);
94 print_cpu_features_value (label: "level1_icache_linesize",
95 value: cpu_features->level1_icache_linesize);
96 print_cpu_features_value (label: "level1_dcache_size",
97 value: cpu_features->level1_dcache_size);
98 print_cpu_features_value (label: "level1_dcache_assoc",
99 value: cpu_features->level1_dcache_assoc);
100 print_cpu_features_value (label: "level1_dcache_linesize",
101 value: cpu_features->level1_dcache_linesize);
102 print_cpu_features_value (label: "level2_cache_size",
103 value: cpu_features->level2_cache_size);
104 print_cpu_features_value (label: "level2_cache_assoc",
105 value: cpu_features->level2_cache_assoc);
106 print_cpu_features_value (label: "level2_cache_linesize",
107 value: cpu_features->level2_cache_linesize);
108 print_cpu_features_value (label: "level3_cache_size",
109 value: cpu_features->level3_cache_size);
110 print_cpu_features_value (label: "level3_cache_assoc",
111 value: cpu_features->level3_cache_assoc);
112 print_cpu_features_value (label: "level3_cache_linesize",
113 value: cpu_features->level3_cache_linesize);
114 print_cpu_features_value (label: "level4_cache_size",
115 value: cpu_features->level4_cache_size);
116 print_cpu_features_value (label: "cachesize_non_temporal_divisor",
117 value: cpu_features->cachesize_non_temporal_divisor);
118 _Static_assert (
119 offsetof (struct cpu_features, cachesize_non_temporal_divisor)
120 + sizeof (cpu_features->cachesize_non_temporal_divisor)
121 == sizeof (*cpu_features),
122 "last cpu_features field has been printed");
123}
124

source code of glibc/sysdeps/x86/dl-diagnostics-cpu.c