Received: by 2002:a05:7412:bb8d:b0:d7:7d3a:4fe2 with SMTP id js13csp1062408rdb; Tue, 15 Aug 2023 23:47:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVqVIbM0Uw9ZiahntyCAm8V7OAeWDSkwr7NO+Umba5LSM5YUkJ0eqgEmRTeEfc8a0WUD07 X-Received: by 2002:a05:6512:3c87:b0:4fb:8a0a:31f2 with SMTP id h7-20020a0565123c8700b004fb8a0a31f2mr970675lfv.69.1692168419848; Tue, 15 Aug 2023 23:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692168419; cv=none; d=google.com; s=arc-20160816; b=lm9rCfiznjHZDYZ6rfc2UhKUuwpZ7kRN5U5uJS4mKJqDUauWSNXIT4RfHLJE9Rtfrh QUh6g10NxmdB2MIzzM6K13Quzk3cSdl25DPo3GieUi1prTaNXiLcSsAYC0Wt1Ir5cDOf tPrsfailc+Y7Xf3V+xdW9w45TFpirxPEZBDnyUwCETCeMVNsaWgciP7Yl3EwCEm1KWcH 5HO3WY5iFoEwuELJbxLeCLVaMOP6uu5nKKoUJJFeoiNph6xb8LhaMdve5RFoTZBy5xOb OysDSS/wKIw7G95EmiUv9lsTiGlTDgG2W7LataIrTyVEivsHFsF90gQZarkdraE73W5Q JIyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vT/NXGTS2ks/1JGDMD/3lsy5RkFYlYyTOccrgk6+woM=; fh=PLqKwzzhs16LkIzlrulORyed5gJfrt1mS0J5uT6/ZzA=; b=Vs3UtaLW1mW5NQLL/M3+CinutvSFoUZlKM9sqmKYMTTSD9A+3wvku8S/Lm94FMHc1y 4+l7mkGLi5M/4S+fgWfPzrzm5L9oVnQnwbOSexs7EuH3ZP+s4SvAo3Qk2hO5dAJC93ja 8zCl0YjA7eMfvRvUoTDIbdpviiCrWM6pdLLskzEuZGj97JQuXqLbEfnvJQlYTnEPWVrj 5Bq4gGRAZnQDhSyCAuyxpSSuiOmhwq4NqY/idL3U9v7yuT2GXMlPbVcnhQcbgj7/PpgS OZiZ0OhQMKhpMVVqS8ALdh+MVylxXCZFNCfrYfOxUTgi5k6D4Hxfz4ai5/v83pqM+J8X a3Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RkdpQIw4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jp12-20020a170906f74c00b00991dcfb1b07si10433810ejb.962.2023.08.15.23.46.33; Tue, 15 Aug 2023 23:46:59 -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=@kernel.org header.s=k20201202 header.b=RkdpQIw4; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239105AbjHOS2w (ORCPT + 99 others); Tue, 15 Aug 2023 14:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239103AbjHOS2W (ORCPT ); Tue, 15 Aug 2023 14:28:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0E1C1BC1; Tue, 15 Aug 2023 11:28:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D435E636E1; Tue, 15 Aug 2023 18:28:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13927C433C8; Tue, 15 Aug 2023 18:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692124088; bh=K+26otvjFP17cj7wEWOr2nFfsRJWCmK3+NoKvksgHS0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RkdpQIw4DeWACFcizOeb+JqOBZSS+g1ZMqs3iIXgoXSa2nCvbbeW8sXmAg+TFraqQ 6Qw3rv5ntIRC2COrrk4eFL09IzgWeHrNqW8Xn1GsQfl4x0wLiSpsiuQx6/wqPA7Y4d qG9qI54XfEmGTUk0YnVp7YQJ07bd++V/yHtpSFkCeBh9eHafjULLXBnI9FilEdvPiw JjtqGE7Y8MFIrpG3UCeOlNxQWhWslwMWyDd7wLqAm6GWWZ/QSVSAbwxB0efsTbvpQu UGaYpwSw2JakyBp7brO2aGob4ivUmK6r2HWMBIXxIAc7MqW2LwRJeKN98jnengdH5A HVZXW6d+LKiZA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id AFE01404DF; Tue, 15 Aug 2023 15:28:05 -0300 (-03) Date: Tue, 15 Aug 2023 15:28:05 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Alexandre Ghiti , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , Will Deacon , Rob Herring , Andrew Jones , =?iso-8859-1?Q?R=E9mi?= Denis-Courmont , 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, Atish Patra Subject: Re: [PATCH v6 09/10] tools: lib: perf: Implement riscv mmap support Message-ID: References: <20230802080328.1213905-1-alexghiti@rivosinc.com> <20230802080328.1213905-10-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Em Mon, Aug 14, 2023 at 09:44:29AM -0700, Ian Rogers escreveu: > On Wed, Aug 2, 2023 at 1:13 AM 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 > > Reviewed-by: Atish Patra > > Reviewed-by: Ian Rogers Thanks, applied. - Arnaldo > Thanks, > Ian > > > --- > > tools/lib/perf/mmap.c | 66 +++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 66 insertions(+) > > > > diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c > > index 0d1634cedf44..2184814b37dd 100644 > > --- a/tools/lib/perf/mmap.c > > +++ b/tools/lib/perf/mmap.c > > @@ -392,6 +392,72 @@ static u64 read_perf_counter(unsigned int counter) > > > > static u64 read_timestamp(void) { return read_sysreg(cntvct_el0); } > > > > +/* __riscv_xlen contains the witdh of the native base integer, here 64-bit */ > > +#elif defined(__riscv) && __riscv_xlen == 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, %1" \ > > + : "=r" (__v) \ > > + : "i" (csr) : ); \ > > + __v; \ > > +}) > > + > > +static unsigned long csr_read_num(int csr_num) > > +{ > > +#define switchcase_csr_read(__csr_num, __val) {\ > > + case __csr_num: \ > > + __val = 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 = 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) { return 0; } > > static u64 read_timestamp(void) { return 0; } > > -- > > 2.39.2 > > -- - Arnaldo