about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c
diff options
context:
space:
mode:
authorPaul Clarke <pc@us.ibm.com>2017-06-09 14:36:22 -0300
committerTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>2017-06-09 14:36:22 -0300
commitcdfbe5037f2f67bf5f560b73732b69d0fabe2314 (patch)
tree67f2fd18a8718ef1e19b134e218c4a90fdffd067 /sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c
parentd6bd839b9acfe619afa1db67a2882c0ce839861f (diff)
downloadglibc-cdfbe5037f2f67bf5f560b73732b69d0fabe2314.tar.gz
glibc-cdfbe5037f2f67bf5f560b73732b69d0fabe2314.tar.xz
glibc-cdfbe5037f2f67bf5f560b73732b69d0fabe2314.zip
powerpc: add sysconf support for cache geometries
There is currently no "cross-platform" (x86 and POWER) support for
determining the cacheline size.

This patch adds support to sysconf() to correctly report cacheline sizes
based on the information in the auxilliary vector.

Thus, using sysconf() is a cross-platform (x86 and POWER) solution for
determining cacheline sizes.

Support is added (on powerpc) for:
_SC_LEVEL1_ICACHE_SIZE _SC_LEVEL1_ICACHE_ASSOC _SC_LEVEL1_ICACHE_LINESIZE
_SC_LEVEL1_DCACHE_SIZE _SC_LEVEL1_DCACHE_ASSOC _SC_LEVEL1_DCACHE_LINESIZE
_SC_LEVEL2_CACHE_SIZE  _SC_LEVEL2_CACHE_ASSOC  _SC_LEVEL2_CACHE_LINESIZE
_SC_LEVEL3_CACHE_SIZE  _SC_LEVEL3_CACHE_ASSOC  _SC_LEVEL3_CACHE_LINESIZE

	* sysdeps/unix/sysv/linux/powerpc/sysconf.c: New file.
	Add powerpc-specific overrides for L1, L2, L3 CACHE_SIZEs,
	CACHE_ASSOCs, and CACHE_LINESIZEs, retrieving from auxv.
	* sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c:
	New file.  Invoke newly supported sysconf values for powerpc,
	and report results.  If none are supported, report so.
	* sysdeps/unix/sysv/linux/powerpc/Makefile (tests):  Add new test,
	tst-sysconf.
Diffstat (limited to 'sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c')
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c b/sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c
new file mode 100644
index 0000000000..94e9f4104e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/test-powerpc-linux-sysconf.c
@@ -0,0 +1,73 @@
+/* Check use of sysconf() for cache geometries.
+   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/>.  */
+
+/* Test use of sysconf() to get cache sizes, cache set associativity
+   and cache line sizes.  */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <support/test-driver.h>
+
+#define call_str(f, name) f(name, #name)
+
+long
+do_sysconf (int name, const char * str)
+{
+  int rc = 0;
+  long val;
+  errno = 0;
+  val = sysconf (name);
+  if (val == -1) {
+    if (errno != EINVAL) {
+      printf("error: sysconf(%s): unexpected errno(%d)\n", str, errno);
+      exit (1);
+    }
+    printf ("info: sysconf(%s): unsupported\n", str);
+    rc = 1;
+  } else
+    printf ("sysconf(%s) = 0x%lx (%ld)\n", str, val, val);
+  return rc;
+}
+
+static int
+do_test (void)
+{
+  int rc = 0;
+
+  rc += call_str (do_sysconf, _SC_LEVEL1_ICACHE_SIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL1_ICACHE_ASSOC);
+  rc += call_str (do_sysconf, _SC_LEVEL1_ICACHE_LINESIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL1_DCACHE_SIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL1_DCACHE_ASSOC);
+  rc += call_str (do_sysconf, _SC_LEVEL1_DCACHE_LINESIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL2_CACHE_SIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL2_CACHE_ASSOC);
+  rc += call_str (do_sysconf, _SC_LEVEL2_CACHE_LINESIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL3_CACHE_SIZE);
+  rc += call_str (do_sysconf, _SC_LEVEL3_CACHE_ASSOC);
+  rc += call_str (do_sysconf, _SC_LEVEL3_CACHE_LINESIZE);
+
+  if (rc)
+    return EXIT_UNSUPPORTED;
+  return 0;
+}
+
+#include <support/test-driver.c>