Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp703887rwo; Wed, 2 Aug 2023 02:52:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGPV8NxDg0QwoSoJRfebuotzj/b21h1AeJYYYXErN5kM8xK0xennJG2jZFqGVoaij6Rthuf X-Received: by 2002:a17:902:7009:b0:1bc:2bd:852a with SMTP id y9-20020a170902700900b001bc02bd852amr10475903plk.42.1690969956130; Wed, 02 Aug 2023 02:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690969956; cv=none; d=google.com; s=arc-20160816; b=sftOtYhcnw3W+A489PiRb3uuvIDWDQTGkgL742hM0/anaGCuyjUr98iW9bedR+a8lI xqNQEZ8CxGlxCaAlbClFuXDgo/WPPyGyrlfTdPT59tslanDcNEP4BvqmwZNNtN8Yfdyf sacZhU30Wbr0ZSq2dETC95hz2AN/a7CDE3TFqW6WGjnYtOeUoSYZ8EnoqLpg0a9z89Vc WTjsEzhAB0M+dmLR/mhC7ppR0fZMvi9BD+Yibks5q1uvjK8/81NUsK+1Rbcyb8X4HlOP F06mdDc6tOGW6OegnWu+XuM50ca1+VtLVT2UZKssl8Ktg9JAzhA5wEJnC/0JNPDuvKK6 ejaA== 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=7afbVzdz7i3XV0LSy+5KsI/iNIynDErY3gG58bPEFNo=; fh=JaxZGKf0NGxFruMBNweFeRrHWrRBBIwkQ5sLyfk9jAY=; b=W3CTZQ/vWc0MwpXwQHdQDusTtaKLo62YhdYmAClA6C3wcrQldm7Em40nfDvPndqtTR SJHanxGOT9mkY/Bu5za+r2Am0mQ5f3yVxN1K6bAZLb8xKr57QKyrab+oTrSQ1Gem/vAg E/Vsvq4mvTdxX8Dm2L0bFEmL/ZWWQgUDAYPlhzk98+bLaqzIjzoWse2DVo8VL/bI/iOI kDee3klhflG+FRNHcQ8t151VwHjZ4mSUS7/h4TMFLQN0hDm0LDkP/5Rl25n3A5FgKKxo b2JgvFJ0Pp+DIhVdcJCqJqDqPmOtUb5+X84FXPHVDyJaqrj+FgoDVZ6hwAeDEthxbTOU le6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=qifnnd1m; 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 o5-20020a170902d4c500b001b8a998c2ebsi10955209plg.363.2023.08.02.02.52.24; Wed, 02 Aug 2023 02:52:36 -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=qifnnd1m; 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 S233747AbjHBIKN (ORCPT + 99 others); Wed, 2 Aug 2023 04:10:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233730AbjHBIKM (ORCPT ); Wed, 2 Aug 2023 04:10:12 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC178E5F for ; Wed, 2 Aug 2023 01:10:10 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fc0aecf15bso69873505e9.1 for ; Wed, 02 Aug 2023 01:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690963809; x=1691568609; 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=7afbVzdz7i3XV0LSy+5KsI/iNIynDErY3gG58bPEFNo=; b=qifnnd1mKlQIbmFMQtnxa9WqcewBxOF1/ulkKZ0PlwvTFCAGuQxSgo1kcwBebXtHjM rpmSpxRKelVFPrBiLJFe6TQ/HsCgwCo4mpuiYtYIYNnDyIOebL6tMHLAyw9pigfIdHHi xWN6KuEvcE6ua4CybzZrL4imUKgHHO9F7J6YzHT1QIOUgi1nqmPKRxp2h0G8Sofwog8U gU3grY1tQXjUv6WVst3cwIliB/fUUp/K0iLvsma3syDq4RkO9KvWY5Ve6RUBV0YkrSuf 7rRQGfdNGtkkGsEX0dcr4Wp00mu9hOiOsCxFOWmXWX6hTlpNnA8n4hoeTtME5dj7noaR p8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690963809; x=1691568609; 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=7afbVzdz7i3XV0LSy+5KsI/iNIynDErY3gG58bPEFNo=; b=M9R2kwlTbWtla30MuPRyFKIUdEQcto2yNCpObhOOFOT+KHZGCZUN8wWrTOFymEOm0e 60SYHrvEk1GZjAn3s493gpZ84lvGCQmMvPfjneLHvdI20Iw132EfwZUNk1VDoKifjCXV ghNFdPtai5NjEvCGy5D/nMbvpYs9WxJv6HTykS9kohSPiQRRJopGc51phXYRgsMqiMwy sA3Ct0sp8AmIx8qXqBpInRRJDjsUdWX0wKMXwd7KN+in3YtuhMBaFT7Db7Ub/bBYvr+E Bs+rlu8kdt6nuQUIbWmuEJoJdZybOQRLhISVXPTKLOSEVET+l2ds8HLVaxXnZsxRJ8GM sjOw== X-Gm-Message-State: ABy/qLZcV+ZLdLVoimtxqs9BeG/diToLo7GerlUVyEqSrwYb5IfOUsct jzna16MaXBbN51dl8eZ0K3fZng== X-Received: by 2002:a7b:c855:0:b0:3fc:616:b0db with SMTP id c21-20020a7bc855000000b003fc0616b0dbmr4218529wml.9.1690963809354; Wed, 02 Aug 2023 01:10:09 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id w12-20020a5d404c000000b0031411b7087dsm18316163wrp.20.2023.08.02.01.10.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 01:10:09 -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 , =?UTF-8?q?R=C3=A9mi=20Denis-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 Cc: Alexandre Ghiti , Atish Patra Subject: [PATCH v6 06/10] drivers: perf: Implement perf event mmap support in the legacy backend Date: Wed, 2 Aug 2023 10:03:24 +0200 Message-Id: <20230802080328.1213905-7-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230802080328.1213905-1-alexghiti@rivosinc.com> References: <20230802080328.1213905-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_BLOCKED,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 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); } -- 2.39.2