From patchwork Mon Oct 26 07:24:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 40871 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 768823857C7E; Mon, 26 Oct 2020 07:24:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by sourceware.org (Postfix) with ESMTPS id E1C9E3857C73 for ; Mon, 26 Oct 2020 07:24:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E1C9E3857C73 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zong.li@sifive.com Received: by mail-pf1-x442.google.com with SMTP id e7so5690249pfn.12 for ; Mon, 26 Oct 2020 00:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hQdcidD413w9dbB/Z41PWwqc0Qt3JhAD3PwpKwkzTUA=; b=SCJ85gcPIoJqMGtCvtrfKCMnjU491/UTwBZrabqOLQxo+WGX9/QmXnNHf+NapXqRWL lg1C0FgyqWIKZ2Af/1+/q81BDL5m7QukENTccsUAEbnQfNsSBDvdAuyFcGt6uzK67hsl /Ra5ZoQgRswbNc2jhEbRjPg0G7oFCFPSXwtuk/6KXTdxLgl/ltCK0w9FMLr06fev9mQo h3+nvW0Bp4AQ3Lf3RhH+5YCzIRrskfpwdt9W2uTT2KEvgBUgz1bwVfVMjSfvWBJnJCT0 4iRUo9WqIWcTjVD7OD3KfvxOcJcsUXnIRUDE4GrsHaFTNy8Q8I7w+fyoOyrtItowQ5H6 yPnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hQdcidD413w9dbB/Z41PWwqc0Qt3JhAD3PwpKwkzTUA=; b=eH84HMgrttkr5SFHYOxtGjsBKYTKy42B2JFUjMtqHU/VDy0BzWlB+sjsPn25MmopoZ M9mUqigvqBCTIyi0gTRiOqX6umJkr2rdFXi/UjCuCE5djDqPUoRU+ElFvS/ZrKHZp10Z 8aWhNy8uzDMlYPOlQuf2nXSCx9wBOSRVQAFlG9STWf6ajuHUBpsDn0u/BWQSz4jAJuYn MvSl2mZMbF9SIS7LdFtHgRN9/uQDjcz04pbFWZixzG+QfgAv5VX090iQJRy2HAcBDbYt zQVJVBiJPIWQSX0wQUZSFISZjQvFjTAnGeaP+bIHDI9gcUBNAcYv/xtQUOgdsKvTKz2Z AR9g== X-Gm-Message-State: AOAM531zSAVd5a+unFqxyhEXluRDp680Fo7JU99Cg4EkXmeiAdymvBYJ f2Ez8IeMC1nLmNOPcJYIeHqV8ooskdqz1N7A X-Google-Smtp-Source: ABdhPJy5RNr2o5/tBqEsl3hcohPcZlJfAppJzLDkRedKZAMmCuBiKS9pYkElHZeqO0sjWcvIWVFwdg== X-Received: by 2002:a63:d252:: with SMTP id t18mr11494189pgi.300.1603697092674; Mon, 26 Oct 2020 00:24:52 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id c12sm10519670pgi.14.2020.10.26.00.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 00:24:52 -0700 (PDT) From: Zong Li To: libc-alpha@sourceware.org, joseph@codesourcery.com Subject: [PATCH 1/1] riscv: Get cache information through sysconf Date: Mon, 26 Oct 2020 15:24:47 +0800 Message-Id: <2df8703a77c3bce4fbdcf523a9b5c3ddf7491b9b.1603693614.git.zong.li@sifive.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zong Li , andrew@sifive.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Add support to query cache information on RISC-V through sysconf() function. The cache information had been added in AUX vector of RISC-V architecture in Linux kernel v.5.10-rc1. Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt --- sysdeps/unix/sysv/linux/riscv/sysconf.c | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/riscv/sysconf.c diff --git a/sysdeps/unix/sysv/linux/riscv/sysconf.c b/sysdeps/unix/sysv/linux/riscv/sysconf.c new file mode 100644 index 0000000000..e73095528c --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/sysconf.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2020 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 int linux_sysconf (int name); + +static inline long int +sysconf_get_cache_associativity (unsigned long type) +{ + return (__getauxval (type) & 0xffff0000) >> 16; +} + +static inline long int +sysconf_get_cache_linesize (unsigned long type) +{ + return __getauxval (type) & 0xffff; +} + +static inline long int +sysconf_get_cache_size (unsigned long type) +{ + return __getauxval (type); +} + +/* Get the value of the system variable NAME. */ +long int +__sysconf (int name) +{ + switch (name) + { + case _SC_LEVEL1_ICACHE_SIZE: + return sysconf_get_cache_size (AT_L1I_CACHESIZE); + case _SC_LEVEL1_ICACHE_ASSOC: + return sysconf_get_cache_associativity (AT_L1I_CACHEGEOMETRY); + case _SC_LEVEL1_ICACHE_LINESIZE: + return sysconf_get_cache_linesize (AT_L1I_CACHEGEOMETRY); + case _SC_LEVEL1_DCACHE_SIZE: + return sysconf_get_cache_size (AT_L1D_CACHESIZE); + case _SC_LEVEL1_DCACHE_ASSOC: + return sysconf_get_cache_associativity (AT_L1D_CACHEGEOMETRY); + case _SC_LEVEL1_DCACHE_LINESIZE: + return sysconf_get_cache_linesize (AT_L1D_CACHEGEOMETRY); + case _SC_LEVEL2_CACHE_SIZE: + return sysconf_get_cache_size (AT_L2_CACHESIZE); + case _SC_LEVEL2_CACHE_ASSOC: + return sysconf_get_cache_associativity (AT_L2_CACHEGEOMETRY); + case _SC_LEVEL2_CACHE_LINESIZE: + return sysconf_get_cache_linesize (AT_L2_CACHEGEOMETRY); + default: + return linux_sysconf (name); + } +} + +/* Now the generic Linux version. */ +#undef __sysconf +#define __sysconf static linux_sysconf +#include