From patchwork Fri Apr 28 15:34:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul A. Clarke" X-Patchwork-Id: 20199 X-Patchwork-Delegate: joseph@codesourcery.com Received: (qmail 7981 invoked by alias); 28 Apr 2017 15:35:09 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 7038 invoked by uid 89); 28 Apr 2017 15:35:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=POWER, H*Ad:U*pc X-HELO: mx0a-001b2d01.pphosted.com Reply-To: pc@us.ibm.com To: libc-alpha@sourceware.org From: Paul Clarke Subject: [PATCH] powerpc: add sysconf support for cache geometries Date: Fri, 28 Apr 2017 10:34:58 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17042815-0024-0000-0000-00001653A6D1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006989; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00853632; UDB=6.00422140; IPR=6.00632573; BA=6.00005316; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015222; XFM=3.00000014; UTC=2017-04-28 15:35:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042815-0025-0000-0000-00004A9C089A Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-28_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704280209 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 2017-04-28 Paul A. Clarke * 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/tst-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. --- sysdeps/unix/sysv/linux/powerpc/Makefile | 1 + sysdeps/unix/sysv/linux/powerpc/sysconf.c | 96 +++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/powerpc/tst-sysconf.c | 75 +++++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/sysconf.c create mode 100644 sysdeps/unix/sysv/linux/powerpc/tst-sysconf.c diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile index 2cfb46e..cfb899a 100644 --- a/sysdeps/unix/sysv/linux/powerpc/Makefile +++ b/sysdeps/unix/sysv/linux/powerpc/Makefile @@ -29,6 +29,7 @@ ifeq ($(subdir),misc) sysdep_headers += bits/ppc.h sysdep_routines += get_timebase_freq tests += test-gettimebasefreq +tests += tst-sysconf endif ifeq ($(subdir),nptl) diff --git a/sysdeps/unix/sysv/linux/powerpc/sysconf.c b/sysdeps/unix/sysv/linux/powerpc/sysconf.c new file mode 100644 index 0000000..bb89933 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/sysconf.c @@ -0,0 +1,96 @@ +/* Get system-specific information at run-time. Linux/powerpc version. + 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 + . */ + +#include +#include +#include + +static long linux_sysconf (int name); + +static long +auxv2sysconf (unsigned long type) +{ + long rc; + rc = getauxval (type); + if (rc == 0) + { + __set_errno (EINVAL); + rc = -1; + } + return rc; +} + +static long +auxv2sysconf_cache_associativity (unsigned long type) +{ + long rc; + rc = auxv2sysconf (type); + if (rc != -1) + rc = (rc & 0xffff0000) >> 16; + return rc; +} + +static long +auxv2sysconf_cache_linesize (unsigned long type) +{ + long rc; + rc = auxv2sysconf (type); + if (rc != -1) + rc = rc & 0xffff; + return rc; +} + +/* Get the value of the system variable NAME. */ +long int +__sysconf (int name) +{ + switch (name) + { + case _SC_LEVEL1_ICACHE_SIZE: + return auxv2sysconf (AT_L1I_CACHESIZE); + case _SC_LEVEL1_ICACHE_ASSOC: + return auxv2sysconf_cache_associativity (AT_L1I_CACHEGEOMETRY); + case _SC_LEVEL1_ICACHE_LINESIZE: + return auxv2sysconf_cache_linesize (AT_L1I_CACHEGEOMETRY); + case _SC_LEVEL1_DCACHE_SIZE: + return auxv2sysconf (AT_L1D_CACHESIZE); + case _SC_LEVEL1_DCACHE_ASSOC: + return auxv2sysconf_cache_associativity (AT_L1D_CACHEGEOMETRY); + case _SC_LEVEL1_DCACHE_LINESIZE: + return auxv2sysconf_cache_linesize (AT_L1D_CACHEGEOMETRY); + case _SC_LEVEL2_CACHE_SIZE: + return auxv2sysconf (AT_L2_CACHESIZE); + case _SC_LEVEL2_CACHE_ASSOC: + return auxv2sysconf_cache_associativity (AT_L2_CACHEGEOMETRY); + case _SC_LEVEL2_CACHE_LINESIZE: + return auxv2sysconf_cache_linesize (AT_L2_CACHEGEOMETRY); + case _SC_LEVEL3_CACHE_SIZE: + return auxv2sysconf (AT_L3_CACHESIZE); + case _SC_LEVEL3_CACHE_ASSOC: + return auxv2sysconf_cache_associativity (AT_L3_CACHEGEOMETRY); + case _SC_LEVEL3_CACHE_LINESIZE: + return auxv2sysconf_cache_linesize (AT_L3_CACHEGEOMETRY); + default: + return linux_sysconf (name); + } +} + +/* Now the generic Linux version. */ +#undef __sysconf +#define __sysconf static linux_sysconf +#include "../sysconf.c" diff --git a/sysdeps/unix/sysv/linux/powerpc/tst-sysconf.c b/sysdeps/unix/sysv/linux/powerpc/tst-sysconf.c new file mode 100644 index 0000000..72b8df9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/tst-sysconf.c @@ -0,0 +1,75 @@ +/* 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 + . */ + +/* Test use of sysconf() to get cache sizes, cache set associativity + and cache line sizes. */ + +#include +#include +#include +#include + +#include + +#define call_str(f, name) f(name, #name) + +long +do_sysconf (int name, const char * str) +{ + int rc = 0; + long val; + printf ("sysconf(%s)", str); + errno = 0; + val = sysconf (name); + if (val == -1) { + if (errno != EINVAL) { + printf(" unexpected errno(%d)\n", errno); + exit (EXIT_FAILURE); + } + printf (" is unsupported\n"); + rc = 1; + } else + printf (" = 0x%lx (%ld)\n", 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; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"