dl-diagnostics-cpu.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Print CPU diagnostics data in ld.so. AArch64 version.
  2. Copyright (C) 2021-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <dl-diagnostics.h>
  16. #include <cpu-features.h>
  17. #include <dl-iterate_cpu.h>
  18. #include <ldsodefs.h>
  19. #include <sys/auxv.h>
  20. static void
  21. print_cpu_features_value (const char *label, uint64_t value)
  22. {
  23. _dl_printf ("aarch64.cpu_features.");
  24. _dl_diagnostics_print_labeled_value (label, value);
  25. }
  26. static void
  27. print_per_cpu_value (const struct dl_iterate_cpu *dic,
  28. const char *label, uint64_t value)
  29. {
  30. _dl_printf ("aarch64.processor[0x%x].", dic->processor_index);
  31. _dl_diagnostics_print_labeled_value (label, value);
  32. }
  33. void
  34. _dl_diagnostics_cpu (void)
  35. {
  36. print_cpu_features_value ("bti", GLRO (dl_aarch64_cpu_features).bti);
  37. print_cpu_features_value ("midr_el1",
  38. GLRO (dl_aarch64_cpu_features).midr_el1);
  39. print_cpu_features_value ("mops", GLRO (dl_aarch64_cpu_features).mops);
  40. print_cpu_features_value ("mte_state",
  41. GLRO (dl_aarch64_cpu_features).mte_state);
  42. print_cpu_features_value ("prefer_sve_ifuncs",
  43. GLRO (dl_aarch64_cpu_features).prefer_sve_ifuncs);
  44. print_cpu_features_value ("sve", GLRO (dl_aarch64_cpu_features).sve);
  45. print_cpu_features_value ("zva_size",
  46. GLRO (dl_aarch64_cpu_features).zva_size);
  47. struct dl_iterate_cpu dic;
  48. _dl_iterate_cpu_init (&dic);
  49. while (_dl_iterate_cpu_next (&dic))
  50. {
  51. if (dic.requested_cpu >= 0)
  52. _dl_printf ("aarch64.processor[0x%x].requested=0x%x\n",
  53. dic.processor_index, dic.requested_cpu);
  54. if (dic.actual_cpu >= 0)
  55. _dl_printf ("aarch64.processor[0x%x].observed=0x%x\n",
  56. dic.processor_index, dic.actual_cpu);
  57. if (dic.actual_node >= 0)
  58. _dl_printf ("aarch64.processor[0x%x].observed_node=0x%x\n",
  59. dic.processor_index, dic.actual_node);
  60. if (GLRO (dl_hwcap) & HWCAP_CPUID)
  61. {
  62. uint64_t midr_el1;
  63. asm ("mrs %0, midr_el1" : "=r" (midr_el1));
  64. print_per_cpu_value (&dic, "midr_el1", midr_el1);
  65. }
  66. {
  67. uint64_t dczid_el0;
  68. asm ("mrs %0, dczid_el0" : "=r" (dczid_el0));
  69. print_per_cpu_value (&dic, "dczid_el0", dczid_el0);
  70. }
  71. }
  72. }