Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2220380rwp; Fri, 14 Jul 2023 02:47:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlE/rnJ4adMHqJs1g0ZflPnEZ4h9dGYLQpc/fK1OkE8Nk8xrEeVSlsdf4pnfRST8ucuSTETM X-Received: by 2002:ac2:4d8c:0:b0:4f9:dd30:1123 with SMTP id g12-20020ac24d8c000000b004f9dd301123mr3335361lfe.49.1689328073091; Fri, 14 Jul 2023 02:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689328073; cv=none; d=google.com; s=arc-20160816; b=M46RP/eVmWAEuHStqdip35LaBEq/QhXs+cMpwOPglpbYGbS1Gs3LG3+AyHoVoZ9hFS YI6XhEMTEEj+RS7QQl7NE8y4vtEZMqR4DSMVjgCOhmzVfdwb0KTfiDvqAbwrc4g0Rj6a FZEDviOp/V1EyRxGOV2v9pK/WXjiWF8Oy1pH/MeLxFqAmuNNpFFQ2mmtSZL8Vj7S4W66 n7e/iMWExl5/7+X3P3a2GNO6+FHiGGETqouoMbPIBxd+x/g1XxCWHfeZhHzeQysNOgZE kx5LY9C1Wa09xO6p1bgAm9V6Oc6l5JqFqOJ7V30n06hvvrRKdyaxnkvvjGX4FAIeIEUE Df8A== 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=HPuE+yRzqiEB8varg/w30zSn9gbVAkPIryT0l1Bao0s=; fh=y2M5v1gYeu0HYmN0hofCIqVy6M5fV8gJXE/fccYEzwc=; b=AEls1cnfD+y4oLiSObedmEc/ER9SLHRuUX9TpQWknqu0Fa1BW6Idge+BqNKZ3gU7CF dreswes/SOMlR9CEMCVaepNB7UirvBF9AFQlZjr70VfayP6HCNCFavxP9DY1nxxKhilU AopHnhKLg4bveyEGLQXulk5uJPQ4bHEzc2vA0l73fN0eIHX+/9+v/Pn96qEF+KoWb133 2ezdBVAeQlKBh4AXxzObwyKtKHunmFiDMsQSsTSOhfQpUwKaJNhji5SafhmiA36xbKUx wbtloeUPAFuFamiFNIjTEIIgxlqBTdfKavyHSq71weQ56JqY65b4tedimz38W16/RBSN L2hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=jK5Xtm5j; 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 d12-20020aa7c1cc000000b0051bfc04e1b4si8515240edp.226.2023.07.14.02.47.29; Fri, 14 Jul 2023 02:47:53 -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=jK5Xtm5j; 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 S235609AbjGNJ3q (ORCPT + 99 others); Fri, 14 Jul 2023 05:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235664AbjGNJ3p (ORCPT ); Fri, 14 Jul 2023 05:29:45 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F4162D64 for ; Fri, 14 Jul 2023 02:29:43 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b6f52e1c5cso25274651fa.1 for ; Fri, 14 Jul 2023 02:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; t=1689326981; x=1691918981; 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=HPuE+yRzqiEB8varg/w30zSn9gbVAkPIryT0l1Bao0s=; b=jK5Xtm5jSqA1gQEB1zqIWZrWjhypJYmneNg2c/JPWKd+ea9Kaql368JQ7WEkdFlnDc 3NyBkZhtAZeJEoB0DyaD+4ec+9G/adfezCCfH+VSTTPf95jFkGBE+PWh5KR5MrVQU413 puA97e3k8noBO4WvDAM2xRmZO11oKqI0SGP1Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689326981; x=1691918981; 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=HPuE+yRzqiEB8varg/w30zSn9gbVAkPIryT0l1Bao0s=; b=ADSNgBttnseABqxsgzeZlKopcygW1P3wxaCdocifVNN8Lfa4gKNdDsXqjDThKOI4FK eYfx3sYiGK7Pt/mUyKBMt/WoPDVgTQ7oqRsXOifETEJ/R8B0B+M/93s8ssxlNquYiu8i nefwBSo6LL/1Z+edjYVSVnWToOxCKuRK9WdLuTKDRWxI9fTx53UKaqz3pH1LocXioahw 4CIzOjm5nuRF7/kWHb3FE1AbxFF6glsqUsOZSzOmiw2ksJ1ZUIB8bznJAJt8pqoZ9Qe5 A4VB+z7nGH4+yhKnGagmz6oNhDqaiAkgDWekeVSd/3UIy8gYTOArw1GrGGnsDauoD3EH A1bQ== X-Gm-Message-State: ABy/qLb4ss52zWvKtb33BhVas4+sJyRToEFa8noyz1b/m8rsb14IjNE6 9mza0douRoWdQW/7NInEM/2pCBql0Ar2ITIl4EHR X-Received: by 2002:a2e:b04b:0:b0:2b8:3ff3:cd93 with SMTP id d11-20020a2eb04b000000b002b83ff3cd93mr643024ljl.7.1689326981568; Fri, 14 Jul 2023 02:29:41 -0700 (PDT) MIME-Version: 1.0 References: <20230703124647.215952-1-alexghiti@rivosinc.com> <20230703124647.215952-10-alexghiti@rivosinc.com> In-Reply-To: <20230703124647.215952-10-alexghiti@rivosinc.com> From: Atish Patra Date: Fri, 14 Jul 2023 02:29:30 -0700 Message-ID: Subject: Re: [PATCH v4 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_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Mon, Jul 3, 2023 at 5:56=E2=80=AFAM Alexandre Ghiti wrote: > > riscv now supports mmaping hardware counters so add what's needed to > take advantage of that in libperf. > > Signed-off-by: Alexandre Ghiti > Reviewed-by: Andrew Jones > --- > 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..378a163f0554 100644 > --- a/tools/lib/perf/mmap.c > +++ b/tools/lib/perf/mmap.c > @@ -392,6 +392,71 @@ static u64 read_perf_counter(unsigned int counter) > > static u64 read_timestamp(void) { return read_sysreg(cntvct_el0); } > > +#elif __riscv_xlen =3D=3D 64 > + > +/* TODO: implement rv32 support */ > + > +#define CSR_CYCLE 0xc00 > +#define CSR_TIME 0xc01 > + > +#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) > + 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) { retu= rn 0; } > static u64 read_timestamp(void) { return 0; } > -- > 2.39.2 > Reviewed-by: Atish Patra --=20 Regards, Atish