Blame SOURCES/0002-Backport-of-Print-cache-size-and-geometry-auxv-types.patch

3c8a07
From 1616d034b61622836d3a36af53dcfca7624c844e Mon Sep 17 00:00:00 2001
3c8a07
From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
3c8a07
Date: Wed, 19 Dec 2018 19:03:12 -0200
3c8a07
Subject: [PATCH] Print cache size and geometry auxv types on LD_SHOW_AUXV=1
3c8a07
3c8a07
Add support for AT_L1I_CACHESIZE, AT_L1I_CACHEGEOMETRY,
3c8a07
AT_L1D_CACHESIZE, AT_L1D_CACHEGEOMETRY, AT_L2_CACHESIZE,
3c8a07
AT_L2_CACHEGEOMETRY, AT_L3_CACHESIZE and AT_L3_CACHEGEOMETRY when
3c8a07
LD_SHOW_AUXV=1.
3c8a07
3c8a07
AT_L*_CACHESIZE is printed as decimal and represent the number of
3c8a07
bytes of the cache.
3c8a07
3c8a07
AT_L*_CACHEGEOMETRY is treated in order to specify the cache line size
3c8a07
and its associativity.
3c8a07
3c8a07
Example output from a POWER8:
3c8a07
3c8a07
AT_L1I_CACHESIZE:     32768
3c8a07
AT_L1I_CACHEGEOMETRY: 128B line size, 8-way set associative
3c8a07
AT_L1D_CACHESIZE:     65536
3c8a07
AT_L1D_CACHEGEOMETRY: 128B line size, 8-way set associative
3c8a07
AT_L2_CACHESIZE:      524288
3c8a07
AT_L2_CACHEGEOMETRY:  128B line size, 8-way set associative
3c8a07
AT_L3_CACHESIZE:      8388608
3c8a07
AT_L3_CACHEGEOMETRY:  128B line size, 8-way set associative
3c8a07
3c8a07
Some of the new types are longer than the previous ones, requiring to
3c8a07
increase the indentation in order to keep the values aligned.
3c8a07
3c8a07
    * elf/dl-sysdep.c (auxvars): Add AT_L1I_CACHESIZE,
3c8a07
    AT_L1I_CACHEGEOMETRY, AT_L1D_CACHESIZE, AT_L1D_CACHEGEOMETRY,
3c8a07
    AT_L2_CACHESIZE, AT_L2_CACHEGEOMETRY, AT_L3_CACHESIZE and
3c8a07
    AT_L3_CACHEGEOMETRY.  Fix indentation when printing the other
3c8a07
    fields.
3c8a07
    (_dl_show_auxv): Give a special treatment to
3c8a07
    AT_L1I_CACHEGEOMETRY, AT_L1D_CACHEGEOMETRY, AT_L2_CACHEGEOMETRY
3c8a07
    and AT_L3_CACHEGEOMETRY.
3c8a07
    * sysdeps/powerpc/dl-procinfo.h (cache_geometry): New function.
3c8a07
    (_dl_procinfo): Fix indentation when printing AT_HWCAP and
3c8a07
    AT_HWCAP2.  Add support for AT_L1I_CACHEGEOMETRY,
3c8a07
    AT_L1D_CACHEGEOMETRY, AT_L2_CACHEGEOMETRY and AT_L3_CACHEGEOMETRY.
3c8a07
3c8a07
Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
3c8a07
3c8a07
UPDATE:
3c8a07
3c8a07
Backported to glibc 2.28
3c8a07
3c8a07
Signed-off-by: Jair Gonzalez <jair.de.jesus.gonzalez.plascencia@intel.com>
3c8a07
---
3c8a07
 ChangeLog                     | 15 ++++++++
3c8a07
 elf/dl-sysdep.c               | 68 ++++++++++++++++++++---------------
3c8a07
 sysdeps/powerpc/dl-procinfo.h | 55 ++++++++++++++++++++++++++--
3c8a07
 3 files changed, 107 insertions(+), 31 deletions(-)
3c8a07
3c8a07
diff --git a/ChangeLog b/ChangeLog
3c8a07
index e1f1e8ed..305a772b 100644
3c8a07
--- a/ChangeLog
3c8a07
+++ b/ChangeLog
3c8a07
@@ -1,3 +1,18 @@
3c8a07
+2018-12-19  Tulio Magno Quites Machado Filho  <tuliom@linux.ibm.com>
3c8a07
+
3c8a07
+	* elf/dl-sysdep.c (auxvars): Add AT_L1I_CACHESIZE,
3c8a07
+	AT_L1I_CACHEGEOMETRY, AT_L1D_CACHESIZE, AT_L1D_CACHEGEOMETRY,
3c8a07
+	AT_L2_CACHESIZE, AT_L2_CACHEGEOMETRY, AT_L3_CACHESIZE and
3c8a07
+	AT_L3_CACHEGEOMETRY.  Fix indentation when printing the other
3c8a07
+	fields.
3c8a07
+	(_dl_show_auxv): Give a special treatment to
3c8a07
+	AT_L1I_CACHEGEOMETRY, AT_L1D_CACHEGEOMETRY, AT_L2_CACHEGEOMETRY
3c8a07
+	and AT_L3_CACHEGEOMETRY.
3c8a07
+	* sysdeps/powerpc/dl-procinfo.h (cache_geometry): New function.
3c8a07
+	(_dl_procinfo): Fix indentation when printing AT_HWCAP and
3c8a07
+	AT_HWCAP2.  Add support for AT_L1I_CACHEGEOMETRY,
3c8a07
+	AT_L1D_CACHEGEOMETRY, AT_L2_CACHEGEOMETRY and AT_L3_CACHEGEOMETRY.
3c8a07
+
3c8a07
 2018-08-20  Joseph Myers  <joseph@codesourcery.com>
3c8a07
 
3c8a07
 	* elf/elf.c (NT_VMCOREDD): New macro.
3c8a07
diff --git a/elf/dl-sysdep.c b/elf/dl-sysdep.c
3c8a07
index 998c5d52..93983251 100644
3c8a07
--- a/elf/dl-sysdep.c
3c8a07
+++ b/elf/dl-sysdep.c
3c8a07
@@ -277,38 +277,46 @@ _dl_show_auxv (void)
3c8a07
     {
3c8a07
       static const struct
3c8a07
       {
3c8a07
-	const char label[17];
3c8a07
+	const char label[22];
3c8a07
 	enum { unknown = 0, dec, hex, str, ignore } form : 8;
3c8a07
       } auxvars[] =
3c8a07
 	{
3c8a07
-	  [AT_EXECFD - 2] =		{ "EXECFD:       ", dec },
3c8a07
-	  [AT_EXECFN - 2] =		{ "EXECFN:       ", str },
3c8a07
-	  [AT_PHDR - 2] =		{ "PHDR:         0x", hex },
3c8a07
-	  [AT_PHENT - 2] =		{ "PHENT:        ", dec },
3c8a07
-	  [AT_PHNUM - 2] =		{ "PHNUM:        ", dec },
3c8a07
-	  [AT_PAGESZ - 2] =		{ "PAGESZ:       ", dec },
3c8a07
-	  [AT_BASE - 2] =		{ "BASE:         0x", hex },
3c8a07
-	  [AT_FLAGS - 2] =		{ "FLAGS:        0x", hex },
3c8a07
-	  [AT_ENTRY - 2] =		{ "ENTRY:        0x", hex },
3c8a07
-	  [AT_NOTELF - 2] =		{ "NOTELF:       ", hex },
3c8a07
-	  [AT_UID - 2] =		{ "UID:          ", dec },
3c8a07
-	  [AT_EUID - 2] =		{ "EUID:         ", dec },
3c8a07
-	  [AT_GID - 2] =		{ "GID:          ", dec },
3c8a07
-	  [AT_EGID - 2] =		{ "EGID:         ", dec },
3c8a07
-	  [AT_PLATFORM - 2] =		{ "PLATFORM:     ", str },
3c8a07
-	  [AT_HWCAP - 2] =		{ "HWCAP:        ", hex },
3c8a07
-	  [AT_CLKTCK - 2] =		{ "CLKTCK:       ", dec },
3c8a07
-	  [AT_FPUCW - 2] =		{ "FPUCW:        ", hex },
3c8a07
-	  [AT_DCACHEBSIZE - 2] =	{ "DCACHEBSIZE:  0x", hex },
3c8a07
-	  [AT_ICACHEBSIZE - 2] =	{ "ICACHEBSIZE:  0x", hex },
3c8a07
-	  [AT_UCACHEBSIZE - 2] =	{ "UCACHEBSIZE:  0x", hex },
3c8a07
+	  [AT_EXECFD - 2] =		{ "EXECFD:            ", dec },
3c8a07
+	  [AT_EXECFN - 2] =		{ "EXECFN:            ", str },
3c8a07
+	  [AT_PHDR - 2] =		{ "PHDR:              0x", hex },
3c8a07
+	  [AT_PHENT - 2] =		{ "PHENT:             ", dec },
3c8a07
+	  [AT_PHNUM - 2] =		{ "PHNUM:             ", dec },
3c8a07
+	  [AT_PAGESZ - 2] =		{ "PAGESZ:            ", dec },
3c8a07
+	  [AT_BASE - 2] =		{ "BASE:              0x", hex },
3c8a07
+	  [AT_FLAGS - 2] =		{ "FLAGS:             0x", hex },
3c8a07
+	  [AT_ENTRY - 2] =		{ "ENTRY:             0x", hex },
3c8a07
+	  [AT_NOTELF - 2] =		{ "NOTELF:            ", hex },
3c8a07
+	  [AT_UID - 2] =		{ "UID:               ", dec },
3c8a07
+	  [AT_EUID - 2] =		{ "EUID:              ", dec },
3c8a07
+	  [AT_GID - 2] =		{ "GID:               ", dec },
3c8a07
+	  [AT_EGID - 2] =		{ "EGID:              ", dec },
3c8a07
+	  [AT_PLATFORM - 2] =		{ "PLATFORM:          ", str },
3c8a07
+	  [AT_HWCAP - 2] =		{ "HWCAP:             ", hex },
3c8a07
+	  [AT_CLKTCK - 2] =		{ "CLKTCK:            ", dec },
3c8a07
+	  [AT_FPUCW - 2] =		{ "FPUCW:             ", hex },
3c8a07
+	  [AT_DCACHEBSIZE - 2] =	{ "DCACHEBSIZE:       0x", hex },
3c8a07
+	  [AT_ICACHEBSIZE - 2] =	{ "ICACHEBSIZE:       0x", hex },
3c8a07
+	  [AT_UCACHEBSIZE - 2] =	{ "UCACHEBSIZE:       0x", hex },
3c8a07
 	  [AT_IGNOREPPC - 2] =		{ "IGNOREPPC", ignore },
3c8a07
-	  [AT_SECURE - 2] =		{ "SECURE:       ", dec },
3c8a07
-	  [AT_BASE_PLATFORM - 2] =	{ "BASE_PLATFORM:", str },
3c8a07
-	  [AT_SYSINFO - 2] =		{ "SYSINFO:      0x", hex },
3c8a07
-	  [AT_SYSINFO_EHDR - 2] =	{ "SYSINFO_EHDR: 0x", hex },
3c8a07
-	  [AT_RANDOM - 2] =		{ "RANDOM:       0x", hex },
3c8a07
-	  [AT_HWCAP2 - 2] =		{ "HWCAP2:       0x", hex },
3c8a07
+	  [AT_SECURE - 2] =		{ "SECURE:            ", dec },
3c8a07
+	  [AT_BASE_PLATFORM - 2] =	{ "BASE_PLATFORM:     ", str },
3c8a07
+	  [AT_SYSINFO - 2] =		{ "SYSINFO:           0x", hex },
3c8a07
+	  [AT_SYSINFO_EHDR - 2] =	{ "SYSINFO_EHDR:      0x", hex },
3c8a07
+	  [AT_RANDOM - 2] =		{ "RANDOM:            0x", hex },
3c8a07
+	  [AT_HWCAP2 - 2] =		{ "HWCAP2:            0x", hex },
3c8a07
+	  [AT_L1I_CACHESIZE - 2] =	{ "L1I_CACHESIZE:     ", dec },
3c8a07
+	  [AT_L1I_CACHEGEOMETRY - 2] =	{ "L1I_CACHEGEOMETRY: 0x", hex },
3c8a07
+	  [AT_L1D_CACHESIZE - 2] =	{ "L1D_CACHESIZE:     ", dec },
3c8a07
+	  [AT_L1D_CACHEGEOMETRY - 2] =	{ "L1D_CACHEGEOMETRY: 0x", hex },
3c8a07
+	  [AT_L2_CACHESIZE - 2] =	{ "L2_CACHESIZE:      ", dec },
3c8a07
+	  [AT_L2_CACHEGEOMETRY - 2] =	{ "L2_CACHEGEOMETRY:  0x", hex },
3c8a07
+	  [AT_L3_CACHESIZE - 2] =	{ "L3_CACHESIZE:      ", dec },
3c8a07
+	  [AT_L3_CACHEGEOMETRY - 2] =	{ "L3_CACHEGEOMETRY:  0x", hex },
3c8a07
 	};
3c8a07
       unsigned int idx = (unsigned int) (av->a_type - 2);
3c8a07
 
3c8a07
@@ -320,7 +328,9 @@ _dl_show_auxv (void)
3c8a07
       assert (AT_NULL == 0);
3c8a07
       assert (AT_IGNORE == 1);
3c8a07
 
3c8a07
-      if (av->a_type == AT_HWCAP || av->a_type == AT_HWCAP2)
3c8a07
+      if (av->a_type == AT_HWCAP || av->a_type == AT_HWCAP2
3c8a07
+	  || AT_L1I_CACHEGEOMETRY || AT_L1D_CACHEGEOMETRY
3c8a07
+	  || AT_L2_CACHEGEOMETRY || AT_L3_CACHEGEOMETRY)
3c8a07
 	{
3c8a07
 	  /* These are handled in a special way per platform.  */
3c8a07
 	  if (_dl_procinfo (av->a_type, av->a_un.a_val) == 0)
3c8a07
diff --git a/sysdeps/powerpc/dl-procinfo.h b/sysdeps/powerpc/dl-procinfo.h
3c8a07
index 3593e966..8d8ffb69 100644
3c8a07
--- a/sysdeps/powerpc/dl-procinfo.h
3c8a07
+++ b/sysdeps/powerpc/dl-procinfo.h
3c8a07
@@ -157,6 +157,37 @@ _dl_string_platform (const char *str)
3c8a07
 }
3c8a07
 
3c8a07
 #if IS_IN (rtld)
3c8a07
+static inline void
3c8a07
+cache_geometry (const char * name, unsigned long int geometry)
3c8a07
+{
3c8a07
+  unsigned long int assocty, line;
3c8a07
+
3c8a07
+  _dl_printf ("%s", name);
3c8a07
+
3c8a07
+  line = geometry & 0xffff;
3c8a07
+  assocty = (geometry >> 16) & 0xffff;
3c8a07
+
3c8a07
+  if (line == 0)
3c8a07
+    _dl_printf ("Unknown line size, ");
3c8a07
+  else
3c8a07
+    _dl_printf ("%luB line size, ", line);
3c8a07
+
3c8a07
+  switch (assocty)
3c8a07
+    {
3c8a07
+    case 0:
3c8a07
+      _dl_printf ("Unknown associativity");
3c8a07
+      break;
3c8a07
+    case 1:
3c8a07
+      _dl_printf ("Directly mapped");
3c8a07
+      break;
3c8a07
+    case 0xffff:
3c8a07
+      _dl_printf ("Fully associative");
3c8a07
+      break;
3c8a07
+    default:
3c8a07
+      _dl_printf ("%lu-way set associative", assocty);
3c8a07
+    }
3c8a07
+}
3c8a07
+
3c8a07
 static inline int
3c8a07
 __attribute__ ((unused))
3c8a07
 _dl_procinfo (unsigned int type, unsigned long int word)
3c8a07
@@ -164,7 +195,7 @@ _dl_procinfo (unsigned int type, unsigned long int word)
3c8a07
   switch(type)
3c8a07
     {
3c8a07
     case AT_HWCAP:
3c8a07
-      _dl_printf ("AT_HWCAP:       ");
3c8a07
+      _dl_printf ("AT_HWCAP:            ");
3c8a07
 
3c8a07
       for (int i = 0; i <= _DL_HWCAP_LAST; ++i)
3c8a07
        if (word & (1 << i))
3c8a07
@@ -174,7 +205,7 @@ _dl_procinfo (unsigned int type, unsigned long int word)
3c8a07
       {
3c8a07
        unsigned int offset = _DL_HWCAP_LAST + 1;
3c8a07
 
3c8a07
-       _dl_printf ("AT_HWCAP2:      ");
3c8a07
+       _dl_printf ("AT_HWCAP2:           ");
3c8a07
 
3c8a07
         /* We have to go through them all because the kernel added the
3c8a07
           AT_HWCAP2 features starting with the high bits.  */
3c8a07
@@ -183,6 +214,26 @@ _dl_procinfo (unsigned int type, unsigned long int word)
3c8a07
            _dl_printf (" %s", _dl_hwcap_string (offset + i));
3c8a07
        break;
3c8a07
       }
3c8a07
+    case AT_L1I_CACHEGEOMETRY:
3c8a07
+      {
3c8a07
+	cache_geometry ("AT_L1I_CACHEGEOMETRY: ", word);
3c8a07
+	break;
3c8a07
+      }
3c8a07
+    case AT_L1D_CACHEGEOMETRY:
3c8a07
+      {
3c8a07
+	cache_geometry ("AT_L1D_CACHEGEOMETRY: ", word);
3c8a07
+	break;
3c8a07
+      }
3c8a07
+    case AT_L2_CACHEGEOMETRY:
3c8a07
+      {
3c8a07
+	cache_geometry ("AT_L2_CACHEGEOMETRY:  ", word);
3c8a07
+	break;
3c8a07
+      }
3c8a07
+    case AT_L3_CACHEGEOMETRY:
3c8a07
+      {
3c8a07
+	cache_geometry ("AT_L3_CACHEGEOMETRY:  ", word);
3c8a07
+	break;
3c8a07
+      }
3c8a07
     default:
3c8a07
       /* This should not happen.  */
3c8a07
       return -1;
3c8a07
-- 
3c8a07
2.27.0
3c8a07