From patchwork Mon Jul 3 12:46:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13300035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82324EB64DC for ; Mon, 3 Jul 2023 12:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9wLviCnn04+HcrsL3oR6/66L7ivtKZFeLR/bDWlRqQM=; b=qljcE6QdvNmLy2 YVzTHEwsyPBfW1tR2u6kMd3UIktJq7oZs6cxTWVMFq3hl8JhYsth2o4sprAPAOqW625pJYFpNwB2r kCU5rvjRWNkpbNHDIZrKnMdm9jN0lsQOHFcRMwBzV2qqTtcRGcJUl+GraHZL62GjIdwo4xd6koEKQ uhdL1ZuxWFpTfJXNomwtdXkz5zmIfKq6Rtr/OS/NoJ+DHcl+7gfqtA2mhiOGimjQCI9uR0SvqfxX+ 0xwDTvDez2P5Nv8txNwP66ZLn1LmFOgVmq0yVlXO6z8ab6ZIO85ycz0jRe+3B3aGgS/pOP44B6D40 wf35sk7n0nCkPFzeV0bg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qGJ39-00AXzs-0k; Mon, 03 Jul 2023 12:53:03 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qGJ36-00AXy6-1J for linux-arm-kernel@lists.infradead.org; Mon, 03 Jul 2023 12:53:01 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbc244d39dso56788805e9.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=gvGEpJvuPA9D1lgSER7zSndE+9IVKW5Ys/tikPh44Lcjzy7LPxC50xu/LHDjs+iUTo tKDi87ts3s7yOWLbPLIf8Fuhr84TyrYSc9QNzuOw9Ltj7fiiXUDsnq52oUoGwu4W0Wyi uYJr1v/kZaxhWwHNT2ZjAQIAtI9/M//6pxGQUoLt1w1M5Q210gWLpyzsrSWhCN3NaI3e XgF51P8xNH5ijGQr3ATWINFSx8UfRGeqn8X14+pY7GAPkxy4RTSGMwo7E4dQboi0eyeI 3nYvJ1Mg7WWRzVVUd0Nl8BQWT1Rmn9lbKq6bkrnIBLWx3dS9eF49yiEAh+pk+aCOEhkH OB/g== X-Gm-Message-State: AC+VfDyED9e8k3B++PjeoRMt6Mz7oAQPQP0y7AYjsxFGwdqVHbwfEecy F/8ZL9f2zqwtIiahKiXtkYKT2w== X-Google-Smtp-Source: ACHHUZ5HA8KDH2QJSQViiIkBg1NELVnzyjafnotWcuYa2YPHjr5O+aKLbytRZh1EJVbsoaERYly4pA== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230703_055300_439884_FFB1543F X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Reviewed-by: Atish Patra --- 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); }