179894
commit 01a5746b6c8a44dc29d33e056b63485075a6a3cc
179894
Author: Florian Weimer <fweimer@redhat.com>
179894
Date:   Wed Feb 24 13:12:04 2021 +0100
179894
179894
    x86: Add CPU-specific diagnostics to ld.so --list-diagnostics
179894
179894
Conflicts:
179894
	sysdeps/x86/dl-diagnostics-cpu.c
179894
	  (reworked due to struct differences, different knobs
179894
	  downstream)
179894
179894
diff --git a/sysdeps/x86/dl-diagnostics-cpu.c b/sysdeps/x86/dl-diagnostics-cpu.c
179894
new file mode 100644
179894
index 0000000000000000..0ba286a828b69937
179894
--- /dev/null
179894
+++ b/sysdeps/x86/dl-diagnostics-cpu.c
179894
@@ -0,0 +1,101 @@
179894
+/* Print CPU diagnostics data in ld.so.  x86 version.
179894
+   Copyright (C) 2021 Free Software Foundation, Inc.
179894
+   This file is part of the GNU C Library.
179894
+
179894
+   The GNU C Library is free software; you can redistribute it and/or
179894
+   modify it under the terms of the GNU Lesser General Public
179894
+   License as published by the Free Software Foundation; either
179894
+   version 2.1 of the License, or (at your option) any later version.
179894
+
179894
+   The GNU C Library is distributed in the hope that it will be useful,
179894
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
179894
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
179894
+   Lesser General Public License for more details.
179894
+
179894
+   You should have received a copy of the GNU Lesser General Public
179894
+   License along with the GNU C Library; if not, see
179894
+   <https://www.gnu.org/licenses/>.  */
179894
+
179894
+#include <dl-diagnostics.h>
179894
+#include <ldsodefs.h>
179894
+
179894
+static void
179894
+print_cpu_features_value (const char *label, uint64_t value)
179894
+{
179894
+  _dl_printf ("x86.cpu_features.");
179894
+  _dl_diagnostics_print_labeled_value (label, value);
179894
+}
179894
+
179894
+static void
179894
+print_cpu_feature_internal (unsigned int index, const char *kind,
179894
+                            unsigned int reg, uint32_t value)
179894
+{
179894
+  _dl_printf ("x86.cpu_features.features[0x%x].%s[0x%x]=0x%x\n",
179894
+              index, kind, reg, value);
179894
+}
179894
+
179894
+static void
179894
+print_cpu_feature_preferred (const char *label, unsigned int flag)
179894
+{
179894
+  _dl_printf("x86.cpu_features.preferred.%s=0x%x\n", label, flag);
179894
+}
179894
+
179894
+void
179894
+_dl_diagnostics_cpu (void)
179894
+{
179894
+  const struct cpu_features *cpu_features = __get_cpu_features ();
179894
+
179894
+  print_cpu_features_value ("basic.kind", cpu_features->basic.kind);
179894
+  print_cpu_features_value ("basic.max_cpuid", cpu_features->basic.max_cpuid);
179894
+  print_cpu_features_value ("basic.family", cpu_features->basic.family);
179894
+  print_cpu_features_value ("basic.model", cpu_features->basic.model);
179894
+  print_cpu_features_value ("basic.stepping", cpu_features->basic.stepping);
179894
+
179894
+  for (unsigned int index = 0; index < COMMON_CPUID_INDEX_MAX; ++index)
179894
+    {
179894
+      /* Downstream, these constants are not part of the ABI yet, so
179894
+         analysis needs to take the precise glibc version into
179894
+         account.  */
179894
+      print_cpu_feature_internal
179894
+        (index, "cpuid", 0, cpu_features->features[index].cpuid.eax);
179894
+      print_cpu_feature_internal
179894
+        (index, "cpuid", 1, cpu_features->features[index].cpuid.ebx);
179894
+      print_cpu_feature_internal
179894
+        (index, "cpuid", 2, cpu_features->features[index].cpuid.ecx);
179894
+      print_cpu_feature_internal
179894
+        (index, "cpuid", 3, cpu_features->features[index].cpuid.edx);
179894
+      print_cpu_feature_internal
179894
+        (index, "usable", 0, cpu_features->features[index].usable.eax);
179894
+      print_cpu_feature_internal
179894
+        (index, "usable", 1, cpu_features->features[index].usable.ebx);
179894
+      print_cpu_feature_internal
179894
+        (index, "usable", 2, cpu_features->features[index].usable.ecx);
179894
+      print_cpu_feature_internal
179894
+        (index, "usable", 3, cpu_features->features[index].usable.edx);
179894
+    }
179894
+
179894
+  /* The preferred indicators are not part of the ABI and need to be
179894
+     translated.  */
179894
+#define BIT(x) \
179894
+  print_cpu_feature_preferred (#x, CPU_FEATURE_PREFERRED_P (cpu_features, x));
179894
+#include "cpu-features-preferred_feature_index_1.def"
179894
+#undef BIT
179894
+
179894
+  print_cpu_features_value ("xsave_state_size",
179894
+                            cpu_features->xsave_state_size);
179894
+  print_cpu_features_value ("xsave_state_full_size",
179894
+                            cpu_features->xsave_state_full_size);
179894
+  print_cpu_features_value ("data_cache_size", cpu_features->data_cache_size);
179894
+  print_cpu_features_value ("shared_cache_size",
179894
+                            cpu_features->shared_cache_size);
179894
+  print_cpu_features_value ("non_temporal_threshold",
179894
+                            cpu_features->non_temporal_threshold);
179894
+  print_cpu_features_value ("rep_movsb_threshold",
179894
+                            cpu_features->rep_movsb_threshold);
179894
+  print_cpu_features_value ("rep_stosb_threshold",
179894
+                            cpu_features->rep_stosb_threshold);
179894
+  _Static_assert (offsetof (struct cpu_features, rep_stosb_threshold)
179894
+                  + sizeof (cpu_features->rep_stosb_threshold)
179894
+                  == sizeof (*cpu_features),
179894
+                  "last cpu_features field has been printed");
179894
+}
179894
diff --git a/sysdeps/x86/include/cpu-features.h b/sysdeps/x86/include/cpu-features.h
179894
index f43e22f677b249a9..536643b209425198 100644
179894
--- a/sysdeps/x86/include/cpu-features.h
179894
+++ b/sysdeps/x86/include/cpu-features.h
179894
@@ -107,6 +107,8 @@ enum
179894
 # define bit_XTILECFG_state	(1u << 17)
179894
 # define bit_XTILEDATA_state	(1u << 18)
179894
 
179894
+/* NB: When adding new fields, update sysdeps/x86/dl-diagnostics-cpu.c
179894
+   to print them.  */
179894
 struct cpu_features
179894
 {
179894
   struct cpu_features_basic basic;