Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2696686rwl; Thu, 13 Apr 2023 09:37:44 -0700 (PDT) X-Google-Smtp-Source: AKy350YcAR6BJXh9/4es03SHashEKtV6rNT2R9o601GEbwQzAtZRDEPqLecrof6ZgtUUkoyvshiH X-Received: by 2002:a17:903:32ca:b0:1a4:fe85:ab05 with SMTP id i10-20020a17090332ca00b001a4fe85ab05mr4153029plr.48.1681403864368; Thu, 13 Apr 2023 09:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681403864; cv=none; d=google.com; s=arc-20160816; b=co6yf3smmX6/5CHYUaWkWpQg3JE/P82rCrWmkQRWYNxlutjkGgduS4QT5+GJE6E6xx 0uqK3U0sCrGkXev9oDGJV5ljP9r0GwCxQEQ5DbOC3ieboKNMhnNtBkuZg9xTvVRXfU01 gAxHL9if9MuT4dt2zaH70utliQYkpsDRVTSwkn3PTXLQxmYVlAeGYeC9FgLRvO/ZpOyK ZKJAQoPX0T1oivxEwyCuFOlqQs+5kCIkAW56hRehAs3bG4rd+MOt70uaYcA6BsSoSK2T sItpnP5fX4u8C9cCf3UXCLCvmWIvwrJFgp4mqtLIWR8JQ5zlfngZWoVvQos1Py7dzIeP EUtg== 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=Luz0Qw0w9ZqnvhFtzZjcXX6GzM1RqYDZy0O1Aw36Dho=; b=CdtIP9k3d/ckGrdoQsmqlnpEwbdiO+8hkDga7WV+YkVT0G5aq9JjAX1/ojmpgMKcrO fNYTQr1iqanTAx5ovL/sRoUWeS2BlTItTfs81zmlaurxBGP00WZT3nFPfUJB6qnYafsn GaJc4hDammHIuzW+lp71UAoYoxzB/AMZzQ9yY13W205O5da+spDqFbnaLN9lSksMEPiF 1U3X92kSKgyU+LD7OCaMKGSqijzCLts4X512rz3ZTDQgznjOn/WZkbotufzyjYJfjrPL t5mftGwPk1ty3/DJSUAzDNViHsatJEuiZ3eauPDmhfp49OB4L+uDDOzDyoICEqSfOjCP +6fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=KJY7IATI; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jl4-20020a170903134400b001a67798316dsi2266507plb.261.2023.04.13.09.37.28; Thu, 13 Apr 2023 09:37:44 -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=@google.com header.s=20221208 header.b=KJY7IATI; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229479AbjDMQgl (ORCPT + 99 others); Thu, 13 Apr 2023 12:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjDMQgj (ORCPT ); Thu, 13 Apr 2023 12:36:39 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0C014697 for ; Thu, 13 Apr 2023 09:36:36 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f04275b2bdso104305e9.1 for ; Thu, 13 Apr 2023 09:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681403795; x=1683995795; 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=Luz0Qw0w9ZqnvhFtzZjcXX6GzM1RqYDZy0O1Aw36Dho=; b=KJY7IATIbGi514kJ7FRgfvPH9tgEmqo9KPyiQPUGil2KvhdD62ffqRe6SWY/E8f+nR S9h5/DMAAqtdcMbcCeInOxViyL44v/SfjGY6qWFOHzFeQ/KkU+AtC+3VOuya8yMueOK9 xZPJCTNC90XXxwGYH39hDdxdpNWd2Tnj2RPHh0Z6v55AXv5V54kc0pZeC0gRamAwz8EC hPjPXG1ofsaZd7/0LBlKWDFKWTAL0E852Y7mm9gmvneulSccFEuR4lR3/0PAFq7GHqQl 5VdAaFoTnOFCtQ7EOYfeSlNF8bM2FS2qbo7GwRxiK1+KUN2v6u1R1rlEwUaOf38EV0D9 3Edw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681403795; x=1683995795; 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=Luz0Qw0w9ZqnvhFtzZjcXX6GzM1RqYDZy0O1Aw36Dho=; b=AxgvRCFrkM5vNtYKemyB8lJ9DxLfO2AeIzUQPKnTypWBNnVokICSm+uVPvWwLQxhHr lFzi5CwNDkx64moi0XyxB+3yV5CHnpN2/jNBrEYm5xFjyKaOljqaWLlZg2V0DNPmLIml Aq+ZwEFARP3JlLqYsJeP+9ejOpU1RfyzAIr37SqdrB1xTL3ijlCGlsVKO9I4gTetHdU7 lNf5L3OnqjXMYez3Z2f5wKRvbo0jqWYAB65TDFyuAG4UbZF3GtXRMe1x2qfFJS1tynZl RbF+HjNCttd/x9hJHRFYeDcDGgftsqfiz8eNmM9EZ2NFme0GX1AXZef0A3gDgJ38/cvc iu+A== X-Gm-Message-State: AAQBX9dm4z3R3NwJ100BxdtHJx9KiXBme1RV3IKtqYgrdLgwEb7lSJ35 sYMN+CubaX7sZanJMd8ICSD/+Sd0BawVPlJhwz+mwA== X-Received: by 2002:a05:600c:5405:b0:3df:f3cb:e8ce with SMTP id he5-20020a05600c540500b003dff3cbe8cemr709159wmb.7.1681403795029; Thu, 13 Apr 2023 09:36:35 -0700 (PDT) MIME-Version: 1.0 References: <20230413161725.195417-1-alexghiti@rivosinc.com> In-Reply-To: <20230413161725.195417-1-alexghiti@rivosinc.com> From: Ian Rogers Date: Thu, 13 Apr 2023 09:36:23 -0700 Message-ID: Subject: Re: [PATCH 0/4] riscv: Allow userspace to directly access perf counters To: Alexandre Ghiti Cc: Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , Will Deacon , Rob Herring , 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, paranlee Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, Apr 13, 2023 at 9:17=E2=80=AFAM Alexandre Ghiti wrote: > > riscv used to allow direct access to cycle/time/instret counters, > bypassing the perf framework, this patchset intends to allow the user to > mmap any counter when accessed through perf. But we can't break the > existing behaviour so we introduce a sysctl perf_user_access like arm64 > does, which defaults to the legacy mode described above. > > The core of this patchset lies in patch 4, the first 3 patches are > simple fixes. > > base-commit-tag: v6.3-rc1 > > Alexandre Ghiti (4): > perf: Fix wrong comment about default event_idx > include: riscv: Fix wrong include guard in riscv_pmu.h > riscv: Make legacy counter enum match the HW numbering > riscv: Enable perf counters user access only through perf Presumably the test also needs patching: https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/p= erf/tests/mmap-basic.c?h=3Dperf-tools-next#n287 Thanks, Ian > Documentation/admin-guide/sysctl/kernel.rst | 23 +++- > arch/riscv/include/asm/perf_event.h | 3 + > arch/riscv/kernel/Makefile | 2 +- > arch/riscv/kernel/perf_event.c | 65 +++++++++++ > drivers/perf/riscv_pmu.c | 42 ++++++++ > drivers/perf/riscv_pmu_legacy.c | 24 ++++- > drivers/perf/riscv_pmu_sbi.c | 113 ++++++++++++++++++-- > include/linux/perf/riscv_pmu.h | 9 +- > include/linux/perf_event.h | 3 +- > tools/lib/perf/mmap.c | 65 +++++++++++ > 10 files changed, 332 insertions(+), 17 deletions(-) > create mode 100644 arch/riscv/kernel/perf_event.c > > -- > 2.37.2 >