Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp9979349rwr; Fri, 12 May 2023 01:56:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XgMa/GXg0f2CwOzKEYMQ2Y6qGqI/FV7MYBkgOptFB89w5FMt40zz72+zr6hmFziJ+FaoN X-Received: by 2002:a17:902:e74c:b0:1aa:cddd:57f2 with SMTP id p12-20020a170902e74c00b001aacddd57f2mr31102320plf.25.1683881795271; Fri, 12 May 2023 01:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683881795; cv=none; d=google.com; s=arc-20160816; b=G2qVvgB4szIpDQ7SWYRq/3K4kKd2pW6sX1c9nYX963h5EJ2aEkt0kuanXFc3OY5Oi4 x1UGKyVzI4xokCgWKYVmoHZWDfqh0NBfW7eH62fOUx6KXMXBHTkOH7UQLtnUrLkJrKGy EiKtWOkxGMUIoZgBpxYED2n1PWD4doD/PeqIFn6sd8xEOv98lZrEEyhHBtXuRwRPkIpl s1/bHSbzikeLi5H76wdxl7cNwE2uB93RGZk4ll5wA6KbUWWgJqCSXx9rgK2M5vKzK5dX aloZnh2rdAbCqTz0u+2+pWCvxJuQk3m8l+/kW2iAPoI5KCmyy2/s7A+zkYL4iBYZEXXv PWLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aUKnEzldAU5lVuG/jDXiwAN3hvqenQj1jlly6nl0Ii8=; b=FeLv7i7ujMSA2+sHg+FkO6QV13pTlVGVRlo6PdEhedSMIgPygx6nnZNlrh/FOCv+hw AI46wNr/Q0+BmlCEifwBUiL04vtCNZ2uEuS11GkfaJaZdYKpXoBzD6hiaixB4xkNcckN E6IzeM96NTJDzKtNDWL8ASHQPorkl5o2ZjHxvN7pYeOQUFnP1Q1e72JlQhZU1gdYjL+T NYWudZlD9dR8G2rpMLlpo7aTSjuNcq109IQoTfbQ00M6AXwvXjd2gl/sLiQx8qEgzZFJ Zf18mtftR/+SBq9y4gL+vgFxy62fl8slwhkCyZV00qBqQOVUYDRor4o5KbvIDtuENA48 feOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=MSFrF7b5; 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 iz11-20020a170902ef8b00b001aadb0b0359si8524261plb.290.2023.05.12.01.56.20; Fri, 12 May 2023 01:56:35 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=MSFrF7b5; 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 S240013AbjELIx6 (ORCPT + 99 others); Fri, 12 May 2023 04:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239907AbjELIx4 (ORCPT ); Fri, 12 May 2023 04:53:56 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 360BF8A4D for ; Fri, 12 May 2023 01:53:54 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f315735514so312533045e9.1 for ; Fri, 12 May 2023 01:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1683881632; x=1686473632; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aUKnEzldAU5lVuG/jDXiwAN3hvqenQj1jlly6nl0Ii8=; b=MSFrF7b5hiO1ul3GJrXQGuAvBJZJjaxiZFm1B1nXYPy8Es1boj6Hg/UQTy0zngEWOf Hb6LMVmocFr2ebzFjeyGNAcGUgjlX/5LylebVGWKHj7CQcp6H32YRmIgUls62+6VFvdj 0u/qcXaZ4FxgdRpeFM9PDSawxPeUenA5ZbKsI5axxJdnK4G023jROUWI6yJPz5r66sVd uUVQBgdQTf7bQHZRM1233MUCbAqwD8tnKjFwWiYXwEXLXTaIkPMARsPAOkXrBxWv29U9 lBW8XXEZBgeJEMZFp341SW2ij8IB5Ln5tZwk1SsXjMSALbX1Ie4lPdLt5RX4d6UD9/84 d9rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683881632; x=1686473632; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aUKnEzldAU5lVuG/jDXiwAN3hvqenQj1jlly6nl0Ii8=; b=gf6a1V+rAD5RzmuH6AwUrZ/6tI/9NaQvimGrh4pQ4Qx29snjsHVn+5uQTK3uL7Vjoi 0AR1sIDZPsKKD0FFDOJggiF03QsQBlACfSpQY0FpJZPs01RZDzcLWrfFx20u99VvLeng ym4khSAb8HOr9AovMh9AZHOsHCvP6HKUjINDlBpNNSrPXT6nD7TX1w8Umjw20oNCOqBM ynePjt2Ya8GAoPpHtk/+gv/OhDKbVRmzHH8xlzCX/Bb2lH+d4Cna9b7lQ8zmTFw6nJGF 8ThkvlIK1fI6VNhFU3t3ZI41G28ROKB8IWukAGBi8r3FLExLaK3L4IYimauU1lXwmGeS 51gA== X-Gm-Message-State: AC+VfDyAM0rYY9OvwgzQUoSvITZceowhrTuH+NKnNH1COj3NTPy7GGYV xxM3fh8GpCHVioENkiHCJ0TXMA== X-Received: by 2002:adf:e904:0:b0:306:2d81:341d with SMTP id f4-20020adfe904000000b003062d81341dmr21035750wrm.24.1683881632684; Fri, 12 May 2023 01:53:52 -0700 (PDT) Received: from alex-rivos.home (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c214d00b003f42461ac75sm15015618wml.12.2023.05.12.01.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 01:53:52 -0700 (PDT) From: Alexandre Ghiti To: 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 , Atish Patra , 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 Cc: Alexandre Ghiti Subject: [PATCH v2 00/10] riscv: Allow userspace to directly access perf counters Date: Fri, 12 May 2023 10:53:11 +0200 Message-Id: <20230512085321.13259-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 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. *Note* that there are still ongoing discussions around which mode should be the default mode with distro people. base-commit-tag: v6.3 Changes in v2: - Split into smaller patches, way better! - Add RB from Conor - Simplify the way we checked riscv architecture - Fix race mmap and other thread running on other cpus - Use hwc when available - Set all userspace access flags in event_init, too cumbersome to handle sysctl changes - Fix arch_perf_update_userpage for pmu other than riscv-pmu by renaming pmu driver - Fixed kernel test robot build error - Fixed documentation (Andrew and Bagas) - perf testsuite passes mmap tests in all 3 modes Alexandre Ghiti (10): 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 drivers: perf: Rename riscv pmu driver riscv: Prepare for user-space perf event mmap support drivers: perf: Implement perf event mmap support in the legacy backend drivers: perf: Implement perf event mmap support in the SBI backend Documentation: admin-guide: Add riscv sysctl_perf_user_access tools: lib: perf: Implement riscv mmap support perf: tests: Adapt mmap-basic.c for riscv Documentation/admin-guide/sysctl/kernel.rst | 24 ++- arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/perf_event.c | 74 ++++++++ drivers/perf/riscv_pmu.c | 41 ++++ drivers/perf/riscv_pmu_legacy.c | 37 +++- drivers/perf/riscv_pmu_sbi.c | 196 +++++++++++++++++++- include/linux/perf/riscv_pmu.h | 10 +- include/linux/perf_event.h | 3 +- tools/lib/perf/mmap.c | 65 +++++++ tools/perf/tests/mmap-basic.c | 4 +- 10 files changed, 435 insertions(+), 21 deletions(-) create mode 100644 arch/riscv/kernel/perf_event.c -- 2.37.2