Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / x86 / dl-diagnostics-cpu.c
bloba1578e466545a9f12d5369f82e8af222fd3802c2
1 /* Print CPU diagnostics data in ld.so. x86 version.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #include <dl-diagnostics.h>
20 #include <ldsodefs.h>
22 static void
23 print_cpu_features_value (const char *label, uint64_t value)
25 _dl_printf ("x86.cpu_features.");
26 _dl_diagnostics_print_labeled_value (label, value);
29 static void
30 print_cpu_feature_internal (unsigned int index, const char *kind,
31 unsigned int reg, uint32_t value)
33 _dl_printf ("x86.cpu_features.features[0x%x].%s[0x%x]=0x%x\n",
34 index, kind, reg, value);
37 static void
38 print_cpu_feature_preferred (const char *label, unsigned int flag)
40 _dl_printf("x86.cpu_features.preferred.%s=0x%x\n", label, flag);
43 void
44 _dl_diagnostics_cpu (void)
46 const struct cpu_features *cpu_features = __get_cpu_features ();
48 print_cpu_features_value ("basic.kind", cpu_features->basic.kind);
49 print_cpu_features_value ("basic.max_cpuid", cpu_features->basic.max_cpuid);
50 print_cpu_features_value ("basic.family", cpu_features->basic.family);
51 print_cpu_features_value ("basic.model", cpu_features->basic.model);
52 print_cpu_features_value ("basic.stepping", cpu_features->basic.stepping);
54 for (unsigned int index = 0; index < CPUID_INDEX_MAX; ++index)
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, "cpuid", reg,
62 cpu_features->features[index].cpuid_array[reg]);
63 for (unsigned int reg = 0; reg < 4; ++reg)
64 print_cpu_feature_internal
65 (index, "active", reg,
66 cpu_features->features[index].active_array[reg]);
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
76 print_cpu_features_value ("isa_1", cpu_features->isa_1);
77 print_cpu_features_value ("xsave_state_size",
78 cpu_features->xsave_state_size);
79 print_cpu_features_value ("xsave_state_full_size",
80 cpu_features->xsave_state_full_size);
81 print_cpu_features_value ("data_cache_size", cpu_features->data_cache_size);
82 print_cpu_features_value ("shared_cache_size",
83 cpu_features->shared_cache_size);
84 print_cpu_features_value ("non_temporal_threshold",
85 cpu_features->non_temporal_threshold);
86 print_cpu_features_value ("rep_movsb_threshold",
87 cpu_features->rep_movsb_threshold);
88 print_cpu_features_value ("rep_movsb_stop_threshold",
89 cpu_features->rep_movsb_stop_threshold);
90 print_cpu_features_value ("rep_stosb_threshold",
91 cpu_features->rep_stosb_threshold);
92 print_cpu_features_value ("level1_icache_size",
93 cpu_features->level1_icache_size);
94 print_cpu_features_value ("level1_icache_linesize",
95 cpu_features->level1_icache_linesize);
96 print_cpu_features_value ("level1_dcache_size",
97 cpu_features->level1_dcache_size);
98 print_cpu_features_value ("level1_dcache_assoc",
99 cpu_features->level1_dcache_assoc);
100 print_cpu_features_value ("level1_dcache_linesize",
101 cpu_features->level1_dcache_linesize);
102 print_cpu_features_value ("level2_cache_size",
103 cpu_features->level2_cache_size);
104 print_cpu_features_value ("level2_cache_assoc",
105 cpu_features->level2_cache_assoc);
106 print_cpu_features_value ("level2_cache_linesize",
107 cpu_features->level2_cache_linesize);
108 print_cpu_features_value ("level3_cache_size",
109 cpu_features->level3_cache_size);
110 print_cpu_features_value ("level3_cache_assoc",
111 cpu_features->level3_cache_assoc);
112 print_cpu_features_value ("level3_cache_linesize",
113 cpu_features->level3_cache_linesize);
114 print_cpu_features_value ("level4_cache_size",
115 cpu_features->level4_cache_size);
116 _Static_assert (offsetof (struct cpu_features, level4_cache_size)
117 + sizeof (cpu_features->level4_cache_size)
118 == sizeof (*cpu_features),
119 "last cpu_features field has been printed");