Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6797332rwd; Mon, 19 Jun 2023 12:33:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xQCFpU9qFWPYkgKbHm9RO4oyKoohYxTpQ21Y6hJg2wjKPQZxDRf8Z8/85m/9p5b/QSWDR X-Received: by 2002:a17:902:6bcb:b0:1b1:b50c:e330 with SMTP id m11-20020a1709026bcb00b001b1b50ce330mr5612101plt.2.1687203180698; Mon, 19 Jun 2023 12:33:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687203180; cv=none; d=google.com; s=arc-20160816; b=srL9mSDPVv8RFV/8HLHkvcxB9x7w85PA5HnrbkzZrHv8jgCed09FzX/ctAVGP5Y9gh ZATMHMCt2lgzI6WO5XYWXxzEC+asV6eBavUp9un8TbxK+YpvP6yWrkBuw2acy58Ih18i DY1X9QK7cWymo1mpvfn3Srcaf+MZhHbXoGC70Rm/yOqbq2kudibqWiJZEIEhnz3asBOF HYkIpNC/njnWo3EUfLZt8PKIc16Ai7vjqOtC+TxnnNbkKO8eLMeKZcuoUFfODvlYzA/P XKXmifyN+vnBNWj720P86WV4NeBM2masz6AoMWslEZC7ck18thxIOaYzwPZ8HhNCMeMa 0OTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lzpzSXcJNt2GDsK+43ZK/uSItcMyByB0gXZwcs2zWL8=; b=j8fWpgTE+skGSi/Sh3xcxIgXYoVpMqjdhVhP0mc1rJOSxjpa+PJNYGmy7jdNU3Loyo OlbOENjVtjDAqPX85i7nYw4Manxut674Ca9ia17SYncdHapZmdAH88PEWvunXOFAOVUx FuKLlfK03Z9Uk94O4K4bCGuVdQ6lfVx3XqR94mAl1nJ4SYRGph7KFONUeWUb4gymgBDy 4pLmnRdDYe7s+Vk2SimI2sLpGBhSnmgZZUrsI0J8G6wBry7bPGAzWQYK/Tdu/le9Ju7T GlvruCUF/WLDEByjxlvghYJ2IREtCUb5DGmW4QCf5vbVr9qMCHk6M2tUVMeSknzEagP6 uw7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=J+1cLliv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a170902be0f00b001afe7fcb257si364486pls.64.2023.06.19.12.32.42; Mon, 19 Jun 2023 12:33:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=J+1cLliv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbjFSTE4 (ORCPT + 99 others); Mon, 19 Jun 2023 15:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbjFSTEz (ORCPT ); Mon, 19 Jun 2023 15:04:55 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1741F198 for ; Mon, 19 Jun 2023 12:04:54 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b46f1256bbso23962561fa.0 for ; Mon, 19 Jun 2023 12:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; t=1687201492; x=1689793492; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lzpzSXcJNt2GDsK+43ZK/uSItcMyByB0gXZwcs2zWL8=; b=J+1cLliv98rSFofa+UWME4RIq3zdyYTQID1sx8+kCq375XpPJUIxBmH3CQmHSo5//J AXopCQue+A08F1XKUy2fqH+FNllGbTBqChD63/ZpHSBbldtk/a12adQjMkLqUXJ/Sqtg 4TW9AD4/AZeM6efGebdhSVVz6pM7uYPUwaUnU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687201492; x=1689793492; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lzpzSXcJNt2GDsK+43ZK/uSItcMyByB0gXZwcs2zWL8=; b=DJTL6dlnTCQjUl9759RGbrNeXdztzD0WeX/ZwtogBESSuafqcw2HsJhv93+lW3BynN b72IihkSj1WLMLCaeHuc7Wz/x/GoIe0/gLDRW5DSSkP1c1nLXuLLgnoSpWKGHYsy1I/W caNUqQ54Xn97C7X/KT863IJCk+ZOD5RTXROIWARoIIhLEBBdS8wH4HOLxhJ+Ppg+hzng OVGjs+egkHOqPXPvs/BLAJJAh4sQLdS4Xw3cWFRnmtl62AzuWrheE/3xq54sodZmGD53 TLsndcarMAzKek5ivzsHB11pLicB8YOQv2xV6jwdJg2oWgaE0RgVMJgI5+bMSoTRJw0q x8Lg== X-Gm-Message-State: AC+VfDyR4Y+2iFpcXFjBcmHLU6DuH9e9E+b9b/LthuQB8tcezSuSM23+ JneghD9ITK6CM3hAfu0i0J41iTVSD1OFQs3RFSwE X-Received: by 2002:a2e:8e2b:0:b0:2b4:5d74:d760 with SMTP id r11-20020a2e8e2b000000b002b45d74d760mr2474899ljk.25.1687201492189; Mon, 19 Jun 2023 12:04:52 -0700 (PDT) MIME-Version: 1.0 References: <20230512085321.13259-1-alexghiti@rivosinc.com> <20230512085321.13259-10-alexghiti@rivosinc.com> In-Reply-To: From: Atish Patra Date: Mon, 19 Jun 2023 12:04:40 -0700 Message-ID: Subject: Re: [PATCH v2 09/10] tools: lib: perf: Implement riscv mmap support To: Alexandre Ghiti Cc: Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Will Deacon , Rob Herring , Andrew Jones , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2023 at 2:06=E2=80=AFAM Alexandre Ghiti wrote: > > On Fri, Jun 16, 2023 at 10:43=E2=80=AFAM Atish Patra wrote: > > > > On Fri, May 12, 2023 at 2:03=E2=80=AFAM Alexandre Ghiti wrote: > > > > > > riscv now support mmaping hardware counters so add what's needed to > > > take advantage of that in libperf. > > > > > > Signed-off-by: Alexandre Ghiti > > > --- > > > tools/lib/perf/mmap.c | 65 +++++++++++++++++++++++++++++++++++++++++= ++ > > > 1 file changed, 65 insertions(+) > > > > > > diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c > > > index 0d1634cedf44..65f250e0ef92 100644 > > > --- a/tools/lib/perf/mmap.c > > > +++ b/tools/lib/perf/mmap.c > > > @@ -392,6 +392,71 @@ static u64 read_perf_counter(unsigned int counte= r) > > > > > > static u64 read_timestamp(void) { return read_sysreg(cntvct_el0); } > > > > > > +#elif __riscv_xlen =3D=3D 64 > > > + > > > > This is applicable for RV32 as well. No ? > > otherwise, you won't need CSR_CYCLEH > > Admittedly, I have not checked rv32 at all in this series and the code > below is a copy-paste. I'd say that rv32 support is out of scope for > this series, is that ok with you? > That's fine. Let's just remove the CYCLEH and leave a TODO comment for RV32= . > > > > > +#define CSR_CYCLE 0xc00 > > > +#define CSR_TIME 0xc01 > > > +#define CSR_CYCLEH 0xc80 > > > + > > > +#define csr_read(csr) \ > > > +({ \ > > > + register unsigned long __v; \ > > > + __asm__ __volatile__ ("csrr %0, " #csr \ > > > + : "=3Dr" (__v) : \ > > > + : "memory"); \ > > > + __v; \ > > > +}) > > > + > > > +static unsigned long csr_read_num(int csr_num) > > > +{ > > > +#define switchcase_csr_read(__csr_num, __val) {\ > > > + case __csr_num: \ > > > + __val =3D csr_read(__csr_num); \ > > > + break; } > > > +#define switchcase_csr_read_2(__csr_num, __val) {\ > > > + switchcase_csr_read(__csr_num + 0, __val) \ > > > + switchcase_csr_read(__csr_num + 1, __val)} > > > +#define switchcase_csr_read_4(__csr_num, __val) {\ > > > + switchcase_csr_read_2(__csr_num + 0, __val) \ > > > + switchcase_csr_read_2(__csr_num + 2, __val)} > > > +#define switchcase_csr_read_8(__csr_num, __val) {\ > > > + switchcase_csr_read_4(__csr_num + 0, __val) \ > > > + switchcase_csr_read_4(__csr_num + 4, __val)} > > > +#define switchcase_csr_read_16(__csr_num, __val) {\ > > > + switchcase_csr_read_8(__csr_num + 0, __val) \ > > > + switchcase_csr_read_8(__csr_num + 8, __val)} > > > +#define switchcase_csr_read_32(__csr_num, __val) {\ > > > + switchcase_csr_read_16(__csr_num + 0, __val) \ > > > + switchcase_csr_read_16(__csr_num + 16, __val)} > > > + > > > + unsigned long ret =3D 0; > > > + > > > + switch (csr_num) { > > > + switchcase_csr_read_32(CSR_CYCLE, ret) > > > + switchcase_csr_read_32(CSR_CYCLEH, ret) > > > + default: > > > + break; > > > + } > > > + > > > + return ret; > > > +#undef switchcase_csr_read_32 > > > +#undef switchcase_csr_read_16 > > > +#undef switchcase_csr_read_8 > > > +#undef switchcase_csr_read_4 > > > +#undef switchcase_csr_read_2 > > > +#undef switchcase_csr_read > > > +} > > > + > > > +static u64 read_perf_counter(unsigned int counter) > > > +{ > > > + return csr_read_num(CSR_CYCLE + counter); > > > +} > > > + > > > +static u64 read_timestamp(void) > > > +{ > > > + return csr_read_num(CSR_TIME); > > > +} > > > + > > > #else > > > static u64 read_perf_counter(unsigned int counter __maybe_unused) { = return 0; } > > > static u64 read_timestamp(void) { return 0; } > > > -- > > > 2.37.2 > > > > > > > > > -- > > Regards, > > Atish --=20 Regards, Atish