Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26174718rwd; Mon, 3 Jul 2023 06:26:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRSed9sJNjldJ4NnCRicjCYyqZUUQmOtKAfdNwiW/132Z1asrGs1/KeokRtpsMLPHe9rdX X-Received: by 2002:a17:90a:1bc7:b0:263:34a:cb6f with SMTP id r7-20020a17090a1bc700b00263034acb6fmr11352510pjr.8.1688390798736; Mon, 03 Jul 2023 06:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688390798; cv=none; d=google.com; s=arc-20160816; b=0pTbWgmcYBG9jPl2nXSJnw498nw1jXH0DXD0RWKGV3+4l9xsMEoXRRttVdGdtml3mG 4ZeBETQaT9yEj4lGgtA+YSPJVKnlBMzG+Tt/CBJ4vrgTdgMD+mSLGXnH7yoZ3cyPUeP5 oHIKch/dW4aOYzbEaDrajjHJK74vW2Cq9TxZKrLKIC1EvB0A3JVcc1lbCUKUMTz6d+gh evK3+0iVJ4D4AcK4mRLWj5kCrfY9xEzE9ryg5hzCidTihjK/RQ2XljF/r9nw9ET3dWl6 ZD2Y0MEyTB4nkQhlYQWIuMpfNZHQNW7pRCqlg5YgUub3uHLsnShLNufRVWCKj+l0uDSh Pqkw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rvJvx6RMtbDuAT1323RkBbGas4rmn6vZDZsiVVfiSsE=; fh=hmFTrdz0WFr12osTIIcQLHDbvk92COvsNanUuMWqfoU=; b=BSE7+1lF+/DPxsbx7+8Zss2klIfQeSmCgd3e5WiOsBYT4WODELhP6nmuMtlc9+xCL6 VtyJntx0ymRnyI1zhGwJq3BhvbSxrOjEAEMk0ijVmpPlSTDNL1O6VzAlDCMyI9wdrGi9 OmtzFuJmNOffRGXlwgk+Bti4ehnvMztyFeEBTfPF8qMYQvDfYKBgj+PJS3Er0tqL+/Sx RVzXG/sXnF+JNfe57A6VhBLsJ99duR6Ib51BAITw2hXwgcRsT2NCtK2zsMxnYLHl3/vg iNG4d391i1BH03zVjIv5dLXXRmV78evDDp/rsBvFiclH5hWlql+icSArcH2kahObh6P0 SZHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=PA+jkEZC; 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 d9-20020a17090ad3c900b0025de453ee4csi18371194pjw.168.2023.07.03.06.26.24; Mon, 03 Jul 2023 06:26:38 -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=PA+jkEZC; 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 S229680AbjGCMxD (ORCPT + 99 others); Mon, 3 Jul 2023 08:53:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230500AbjGCMw7 (ORCPT ); Mon, 3 Jul 2023 08:52:59 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED535AF for ; Mon, 3 Jul 2023 05:52:57 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbc244d39dso56788815e9.3 for ; Mon, 03 Jul 2023 05:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1688388776; x=1690980776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rvJvx6RMtbDuAT1323RkBbGas4rmn6vZDZsiVVfiSsE=; b=PA+jkEZCdU8bP2asSDqM7jl8NBccZT3rOEByYZxW/9b3uvGCB0ZWF4YffiSuyw0990 vxeUWOiKn5NZ2SVNEz6EHwjQqlFga+PervFhkiLs/yYBlzOqy6ohMdkmYuOmUOHWHVvL HB7e2yX6KT/y7WWc9ruJqcV7/nvPeWmNNlhHMIkMszBp5a7xVRL0Ge3ALhlhKRHBAXlt ysEOkjQaWciE5gpg3F1VYBVLsMACoeQmBxPbQLjRJOcozzgDv9fmHEy22M+9eX4YIfI+ +7qc3lRX+dQNpdt+ihDhL/UV/JvIGHFO3rAJbfJdR3p2KWrmvV7OC883mPT7uROnN5nY IGnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688388776; x=1690980776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rvJvx6RMtbDuAT1323RkBbGas4rmn6vZDZsiVVfiSsE=; b=PB4DE1XPzkzm+svjE2/FLrVcA+tUhq66PVl3zCg3LBrl4RbbaRU4GrwI740EdMU9mH OvwbgOXSldRJ+uOQmdSgSQCpvDVlq/d08fCy9M1LBgsTru9hpXr8y9FbITMFNq7GekHo WHIgDvNFKI9zzuI9OWz9gM8ARwm+n6scD57b1aOkYSfS2Majx/1kT5Y6kJ4hSkzSgbyF Tf3Pwy3jIGzdRzhCBUeOF2piHZJUJ2ZhLyeApxd2e+25o1yoZJbHnp148Q7XN6U0Ap8u 4sqT5LXai+XXtxCndDihiZXZXkBWOX8Nk7gBH3KKmTtdAJEhIJ8gl9/6BpLj0m0MZmLC PvIQ== X-Gm-Message-State: AC+VfDy11kL9trxhb99tbOfIKpMjr/BtmjlD3/xtGNKE6rZi3xLGh5ab ZRRFEcMolYoCjo1tgRxDDR/m1fve9UghaTyzf/c= X-Received: by 2002:a7b:c445:0:b0:3fb:adc0:c37d with SMTP id l5-20020a7bc445000000b003fbadc0c37dmr13187228wmi.38.1688388776479; Mon, 03 Jul 2023 05:52:56 -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 y17-20020a1c4b11000000b003f90a604885sm26981297wma.34.2023.07.03.05.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 05:52:56 -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 v4 06/10] drivers: perf: Implement perf event mmap support in the legacy backend Date: Mon, 3 Jul 2023 14:46:43 +0200 Message-Id: <20230703124647.215952-7-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230703124647.215952-1-alexghiti@rivosinc.com> References: <20230703124647.215952-1-alexghiti@rivosinc.com> 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=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 Implement the needed callbacks in the legacy driver so that we can directly access the counters through perf in userspace. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones --- drivers/perf/riscv_pmu_legacy.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/perf/riscv_pmu_legacy.c b/drivers/perf/riscv_pmu_legacy.c index 6a000abc28bb..79fdd667922e 100644 --- a/drivers/perf/riscv_pmu_legacy.c +++ b/drivers/perf/riscv_pmu_legacy.c @@ -71,6 +71,29 @@ static void pmu_legacy_ctr_start(struct perf_event *event, u64 ival) local64_set(&hwc->prev_count, initial_val); } +static uint8_t pmu_legacy_csr_index(struct perf_event *event) +{ + return event->hw.idx; +} + +static void pmu_legacy_event_mapped(struct perf_event *event, struct mm_struct *mm) +{ + if (event->attr.config != PERF_COUNT_HW_CPU_CYCLES && + event->attr.config != PERF_COUNT_HW_INSTRUCTIONS) + return; + + event->hw.flags |= PERF_EVENT_FLAG_USER_READ_CNT; +} + +static void pmu_legacy_event_unmapped(struct perf_event *event, struct mm_struct *mm) +{ + if (event->attr.config != PERF_COUNT_HW_CPU_CYCLES && + event->attr.config != PERF_COUNT_HW_INSTRUCTIONS) + return; + + event->hw.flags &= ~PERF_EVENT_FLAG_USER_READ_CNT; +} + /* * This is just a simple implementation to allow legacy implementations * compatible with new RISC-V PMU driver framework. @@ -91,6 +114,9 @@ static void pmu_legacy_init(struct riscv_pmu *pmu) pmu->ctr_get_width = NULL; pmu->ctr_clear_idx = NULL; pmu->ctr_read = pmu_legacy_read_ctr; + pmu->event_mapped = pmu_legacy_event_mapped; + pmu->event_unmapped = pmu_legacy_event_unmapped; + pmu->csr_index = pmu_legacy_csr_index; perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW); } -- 2.39.2