From patchwork Thu Oct 29 17:33:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 40923 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 571343987474; Thu, 29 Oct 2020 17:33:48 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by sourceware.org (Postfix) with ESMTPS id 6C39A3858020 for ; Thu, 29 Oct 2020 17:33:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6C39A3858020 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-x444.google.com with SMTP id y14so2908757pfp.13 for ; Thu, 29 Oct 2020 10:33:45 -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=kro7vyqF37AHfyGJVR3+4lgrirU/MZBrYNe02JDeA4I=; b=BzQu5v5VSsyNrNahi7athhU/C8jxgKvPj7Sj7FLJGdZ5IHNSyr/3tG+BTkLmAMMUy6 FbYD3+RyYous5uIUTAhi6EpI8ey36C4CqMF5ibaD6bmWSpvEc3DHzfokj5PZ3jfeO6H1 C9SOqjrn/bhjz/41EEFFoVeAr9x6hzmsYvS43yVIs5VElbNjU4Z9z7JHDGLNFyHuRPn3 k9C6SPafi6VMELq0guIubmNG5ffkaoAcQab3f8qFcXgWRnpGtM0U5zhjG0Zj8nNCzVoh cbYZHe5PL8D/NiiYT7MEOckousRzE5rteiyYRjvNpJAWTjkKIlK4Y+cyJfV7Zow50l2h rwfg== 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=kro7vyqF37AHfyGJVR3+4lgrirU/MZBrYNe02JDeA4I=; b=nfiYmW0QBszLin1UIi5P4XitBDwwxtpSh3WGABUs92dbUGnTreQtaYrPmAJuwEUspZ VjPa0sYuhoFs0myYehrNtmLxXj9zFFM0yTJcCR5twFMuS1kMmEjBV5B8jJzMWU3+CdOO HkzLcxJrBEXbOVWfgje1yefKR+GllGbPHZkGvIxRGrzeREoeAuZa9SQt2QS7gvOfgknR n4mHu3KVffmR63/6ar2DLhaRoh8L+1Y10gNNXem43W7eSsCyMMgUr7rqVySqdqln/JIH 88Iu1cmxdIDrgW3932S7vSeJEDBQj2eoRI/SFpSNizrKg/SKce+PvNrQk31COJQU/oMw txZg== X-Gm-Message-State: AOAM530HAGi3XHV2xQxFyCV69eSuhZu0Rhj2qC0vgZTQDRiiIiXNdnex LQFcMoyUPm0rvDxohv9JXtSKEvkBhQRPpq94 X-Google-Smtp-Source: ABdhPJzo13kSLRh0ND7xlEexZuEXtjLmiOESpusHZxu6o9kan/RsU4TNlSA4SpDSTZQEQK8k7csjYw== X-Received: by 2002:a63:e34a:: with SMTP id o10mr4869885pgj.129.1603992824235; Thu, 29 Oct 2020 10:33:44 -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 f204sm3639598pfa.189.2020.10.29.10.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 10:33:43 -0700 (PDT) From: Zong Li To: libc-alpha@sourceware.org, fweimer@redhat.com, schwab@linux-m68k.org, joseph@codesourcery.com, andrew@sifive.com Subject: [PATCH v2 1/1] riscv: Get cache information through sysconf Date: Fri, 30 Oct 2020 01:33:38 +0800 Message-Id: X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 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 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 | 100 ++++++++++++++++++++++++ 1 file changed, 100 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..02b469cc65 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/sysconf.c @@ -0,0 +1,100 @@ +/* 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 bool +getauxval2_einval (unsigned long int type, unsigned long int *result) +{ + if (__getauxval2 (type, result)) + return true; + + __set_errno (EINVAL); + + return false; +} + +static inline long int +sysconf_get_cache_associativity (unsigned long type) +{ + unsigned long int result; + + if (getauxval2_einval (type, &result)) + return (result & 0xffff0000) >> 16; + + return -1; +} + +static inline long int +sysconf_get_cache_linesize (unsigned long type) +{ + unsigned long int result; + + if (getauxval2_einval (type, &result)) + return result & 0xffff; + + return -1; +} + +static inline long int +sysconf_get_cache_size (unsigned long type) +{ + unsigned long int result; + + if (getauxval2_einval (type, &result)) + return result; + + return -1; +} + +/* 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