This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] powerpc: Support auxilliary vector components for cache geometries


Use getauxval() to get L1, L2, L3 cache sizes, cache line sizes, and
cache associativities.  The new types for getauxval() were added in
the stream for Linux kernel v4.11 in commit
98a5f361b8625c6f4841d6ba013bbf0e80d08147.

Add test case which retrieves above values using getauxval().

	* elf/elf.h: Add auxvec identifiers from kernel
	arch/powerpc/include/uapi/asm/auxvec.h.
	* glibc/sysdeps/powerpc/tst-getauxval.c: New test to
	retrieve new auxvec values.
	* glibc/sysdeps/powerpc/Makefile (tests): Add tst-getauxval.
---
 elf/elf.h                       | 12 ++++++
 sysdeps/powerpc/Makefile        |  1 +
 sysdeps/powerpc/tst-getauxval.c | 86 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+)
 create mode 100644 sysdeps/powerpc/tst-getauxval.c

diff --git a/elf/elf.h b/elf/elf.h
index 6d3b356..fff893d 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -1170,6 +1170,18 @@ typedef struct
 #define AT_L2_CACHESHAPE	36
 #define AT_L3_CACHESHAPE	37
+/* Shapes of the caches, with more room to describe them.
+   *GEOMETRY are comprised of cache line size in bytes in the bottom 16 bits
+   and the cache associativity in the next 16 bits.  */
+#define AT_L1I_CACHESIZE	40
+#define AT_L1I_CACHEGEOMETRY	41
+#define AT_L1D_CACHESIZE	42
+#define AT_L1D_CACHEGEOMETRY	43
+#define AT_L2_CACHESIZE		44
+#define AT_L2_CACHEGEOMETRY	45
+#define AT_L3_CACHESIZE		46
+#define AT_L3_CACHEGEOMETRY	47
+
 /* Note section contents.  Each entry in the note section begins with
    a header of a fixed form.  */
diff --git a/sysdeps/powerpc/Makefile b/sysdeps/powerpc/Makefile
index 933810f..5f10f68 100644
--- a/sysdeps/powerpc/Makefile
+++ b/sysdeps/powerpc/Makefile
@@ -35,6 +35,7 @@ ifeq ($(subdir),misc)
 sysdep_headers += sys/platform/ppc.h
 tests += test-gettimebase
 tests += tst-set_ppr
+tests += tst-getauxval
 endif
ifneq (,$(filter %le,$(config-machine)))
diff --git a/sysdeps/powerpc/tst-getauxval.c b/sysdeps/powerpc/tst-getauxval.c
new file mode 100644
index 0000000..1f5e9f0
--- /dev/null
+++ b/sysdeps/powerpc/tst-getauxval.c
@@ -0,0 +1,86 @@
+/* Test the implementation of getauxval functions for
+   cache size, cache line size, and associativity for L1, L2, L3 caches.
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <sys/auxv.h>
+
+#include <support/test-driver.h>
+
+static int
+do_test (void)
+{
+  int rc = 0;
+  unsigned long val;
+  val = getauxval (AT_L1I_CACHESIZE);
+  if (val)
+    printf("AT_L1I_CACHESIZE: %ld (0x%lx)\n",val,val);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L1I_CACHEGEOMETRY);
+  if (val)
+    printf("AT_L1I_CACHEGEOMETRY: associativity %ld; line size %ld\n",
+	   (val & 0xffff0000) >> 16, val & 0x0000ffff);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L1D_CACHESIZE);
+  if (val)
+      printf("AT_L1D_CACHESIZE: %ld (0x%lx)\n",val,val);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L1D_CACHEGEOMETRY);
+  if (val)
+    printf("AT_L1D_CACHEGEOMETRY: associativity %ld; line size %ld\n",
+	   (val & 0xffff0000) >> 16, val & 0x0000ffff);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L2_CACHESIZE);
+  if (val)
+    printf("AT_L2_CACHESIZE: %ld (0x%lx)\n",val,val);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L2_CACHEGEOMETRY);
+  if (val)
+    printf("AT_L2_CACHEGEOMETRY: associativity %ld; line size %ld\n",
+	   (val & 0xffff0000) >> 16, val & 0x0000ffff);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L3_CACHESIZE);
+  if (val)
+      printf("AT_L3_CACHESIZE: %ld (0x%lx)\n",val,val);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  val = getauxval (AT_L3_CACHEGEOMETRY);
+  if (val)
+    printf("AT_L3_CACHEGEOMETRY: associativity %ld; line size %ld\n",
+	   (val & 0xffff0000) >> 16, val & 0x0000ffff);
+  else
+    rc = EXIT_UNSUPPORTED;
+
+  return rc;
+}
+
+#include <support/test-driver.c>
--
2.1.4

Regards,
PC


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]