From patchwork Thu Jun 8 22:57:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 773567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wkLRm4yg9z9s76 for ; Fri, 9 Jun 2017 08:57:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="lLFNOYqO"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=r1ZqXomat8+lqyaes2wvYqR1XyI5aKj GfXp2IfE3T6QJ7pGT26VHD2Ne6vlrvku+7xiQm2E3Xvz50LV49jNq6gjK56tUhjn 0ol0oOTWd46V8VYfpyn2d4F6yrJ0jWL3fRNMf1HWJ9/z/iJ8WTLaE/9Nk3UHNSHA WT+W/qlEDKUU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=cSCfOmyw8H5G0tTvAY3VaueyJQc=; b=lLFNO YqO1OJZPtt+3Hn6JmC/Ik/qIidEvkeHIHvsqtg8YROVB47/rpXsH2dNr5B6G8tba x0bKpwzyuE/MVIpWIKUXeLFO6uAa/CbOld9X+Y9e8yyQ/goOXGc7dOW1y18uwiFa 9AR3JyQoWtSgCS4i+XR+nudf55p5cj14JWszmw= Received: (qmail 107262 invoked by alias); 8 Jun 2017 22:57:34 -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 107198 invoked by uid 89); 8 Jun 2017 22:57:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Marcus, marcus, marcusshawcroftarmcom, marcus.shawcroft@arm.com X-HELO: mail-qt0-f195.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=bgV8C6HNfS1cTNFYgTRlZLf+bs1owFx2BOM4Bi532Hc=; b=ASehlZ/q3nMa9nk8YFZvnQGqHS0LraOnWvvYzUgZx8dDSeo4wfaubLcoTWfX8x0s6a gLZ2NIQZyf1VGSd6Vsdxc+59U8C8aaDvdvPZNJHt3ew9FqPoS3opgHp4eaiAMsxGtey9 ubDyLgciN3q1t9rVZk2bNWA5tml+6oJjaUzZMP8uZfib8lFeM883hIrAz4Ed2hk5Ikll 1PNVfPVIoYa7GYpWNI+CPXqkOFmjrk3W00lv+YrRXaisgH813NRnuE4O3ZuCMaH6Scls S8dZ39MhOqxQsAFA8hcrULcJp26GBgRLM5B1+iBB3ysSZNuTG9ZTujNgf+rQpxAjp4cX WrAg== X-Gm-Message-State: AKS2vOzvv+/2f9dzorQppg8IsnpLMZ4+ANKSF32KjzGcN8xnkZiiOiQp vpox7HlZWle2A5Ek/gw= X-Received: by 10.55.95.5 with SMTP id t5mr47325392qkb.64.1496962654585; Thu, 08 Jun 2017 15:57:34 -0700 (PDT) From: Richard Henderson To: libc-alpha@sourceware.org Cc: Marcus Shawcroft Subject: [PATCH 1/3] Guess L1 cache linesize for aarch64 Date: Thu, 8 Jun 2017 15:57:26 -0700 Message-Id: <20170608225728.26779-2-rth@twiddle.net> In-Reply-To: <20170608225728.26779-1-rth@twiddle.net> References: <20170608225728.26779-1-rth@twiddle.net> Using the cache hierarchy linesize minimum in CTR_EL0. See the comment within the code for rationale. * sysdeps/unix/sysv/linux/aarch64/sysconf.c: New file. Cc: Marcus Shawcroft --- sysdeps/unix/sysv/linux/aarch64/sysconf.c | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/aarch64/sysconf.c diff --git a/sysdeps/unix/sysv/linux/aarch64/sysconf.c b/sysdeps/unix/sysv/linux/aarch64/sysconf.c new file mode 100644 index 0000000..30608dd --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/sysconf.c @@ -0,0 +1,55 @@ +/* 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 +#include + + +static long int linux_sysconf (int name); + +/* Get the value of the system variable NAME. */ +long int +__sysconf (int name) +{ + unsigned ctr; + + /* Unfortunately, the registers that contain the actual cache info + (CCSIDR_EL1, CLIDR_EL1, and CSSELR_EL1) are protected by the Linux + kernel (though they need not have been). However, CTR_EL0 contains + the *minimum* linesize in the entire cache hierarchy, and is + accessible to userland, for use in __aarch64_sync_cache_range, + and it is a reasonable assumption that the L1 cache will have that + minimum line size. */ + switch (name) + { + case _SC_LEVEL1_ICACHE_LINESIZE: + asm("mrs\t%0, ctr_el0" : "=r"(ctr)); + return 4 << (ctr & 0xf); + case _SC_LEVEL1_DCACHE_LINESIZE: + asm("mrs\t%0, ctr_el0" : "=r"(ctr)); + return 4 << ((ctr >> 16) & 0xf); + } + + return linux_sysconf (name); +} + +/* Now the generic Linux version. */ +#undef __sysconf +#define __sysconf static linux_sysconf +#include