Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp984373rwd; Wed, 31 May 2023 08:02:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NWjgRz7QgNuo05t7XmrThpOAEODleaE7D9kJ3EeUYgOmMMpd0wi5KWV6AaKxPtywh3UmM X-Received: by 2002:a17:903:1205:b0:1ac:921c:87fc with SMTP id l5-20020a170903120500b001ac921c87fcmr5056009plh.32.1685545343641; Wed, 31 May 2023 08:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545343; cv=none; d=google.com; s=arc-20160816; b=JsLSolH5JilS3xL3VOvK+YBCI8etxjuJRfBVlehBiQuu3NXfU+SwFkS0NDYcy7QGT2 zXi8YSxRXC0wLL32UHwJk5a4ZxiHqi0RHq+rGFAOyecjy9RFEZSNAH1nZga3o4ibVTaH Y0NC2JgE7oryclkPh1hYcP87XHbTkHlV1eM+3GBTUmfomlJCY1CKHjQ/BCB7XUH1b13Q GV8JvTQUawWIkqu4ZJsqKXITfsMQMSsnCVn+pH4/7wtMpgxt2zp/CpkJSY0ygdqkRfr5 qQny7X7BxEpKiOVp6GZNdZRrzCXR64kDAdQiXof3VVlw968CaAnreI4/rArJvgUyCp3l +g1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RZQfdwTjxzu5eTOjhFaQdoWnR4tOyHUVZ5eFRh/PK/c=; b=EYBh4PQ3etclBINeI1ST2zYfj+5tnr7PQPP4sn1u8Czr7wJMokszxP3o3da6sa6nkv X3htuu8tp/by2rObaSFPWQP1629tSpwwApV5rZS01yhIa0TONcFsJhZQ3cWw4PSTzWqg VbN2yDSqaHGtOgKUtOss3HF6BAhpp53X55VKQRBPCCSrMfYT3B0tvH2diOs1qFDs+kwr qLckTzqT52kI7k1lCzFECa0wjI+9a2J7gFKRsZzq706seIGnYZiSaws2qLUIdTpYTQGD Tq7SmfY4c6B8HWTdOb9x3Q37msHK2sCtzc1jiKS3DTrAvShJr08IaVA/q16tA8Kn6wXf bZAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=i9po3clb; 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 j10-20020a17090276ca00b001aaebc66877si1009623plt.147.2023.05.31.08.02.10; Wed, 31 May 2023 08:02:23 -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=@ventanamicro.com header.s=google header.b=i9po3clb; 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 S236674AbjEaO1z (ORCPT + 99 others); Wed, 31 May 2023 10:27:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236786AbjEaO1s (ORCPT ); Wed, 31 May 2023 10:27:48 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56523125 for ; Wed, 31 May 2023 07:27:41 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-30ae61354fbso3257522f8f.3 for ; Wed, 31 May 2023 07:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1685543259; x=1688135259; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=RZQfdwTjxzu5eTOjhFaQdoWnR4tOyHUVZ5eFRh/PK/c=; b=i9po3clbzEzJ5aZJXp7NVJtbYUD67qaN17suS1XLMBFHgOJIzR9JhzXZI9ZJYqcXzB kq/YSfSHb/X2mueCDVBd/l5QWcvxxlsWUUy88nrWZhX1ilWRtOOHcfJJ/0RS0jGhkCzU 6X+sfKFKK8FPnIqVwRUZZgmv8K9q2bbO9TfEFrndYZKJKeK3GOqAsVNNVqmSiDNc0YfN XGf26cv2lKDNNG9JBv3HmW19c1DlT4oYqocIY9T/iywirimClxbKK+MiFqEKFT4zgJI+ Fxa3nzHXP1JUOKnsWrX1F7xw2VqyGsPWm1LrAxNcnujbuy78IrhQ6p5qAn14yj5SvUqb wjmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685543259; x=1688135259; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RZQfdwTjxzu5eTOjhFaQdoWnR4tOyHUVZ5eFRh/PK/c=; b=AOIk1sT8+mUFM6KE0/6ILlgOyFYQco9gNj7Z8mD4aLisSu2sl510QbaM651XTHwtLO M/ZArCY/KRKZY++0TfKzak9gGozJylzjrwargWn4OlpYf9x1YltvuYRIsNwR7uZ3j0W1 7oj2mas+v1NPItxxJMJlxqhOl8/31R6W+bkuV1uLhR2kZHBEYBk+1SsgnoxEEIm4pYPH uGFKs7g4anlPG9MadcMcwERKK8DD4qDe4ZT7F8oCymrXXaGxTmLYLB+Vtcb7PVqx1Vu4 /Tfht5xdDcZLPNQbH2wtgPWjDYKjPSMuQ6hPE3LukoiHWmgg5ekzEklFcqgyV5hJOv3w B1vQ== X-Gm-Message-State: AC+VfDwmSwXnJ4E4PRic84AOPmXII79+woPSgyqdu/+b7DHqOTqX/gUA qcVdvuP39kM5rYqrwww5T9UQ/g== X-Received: by 2002:adf:cd07:0:b0:30a:bf2b:e03c with SMTP id w7-20020adfcd07000000b0030abf2be03cmr4218382wrm.23.1685543259663; Wed, 31 May 2023 07:27:39 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id l4-20020a05600012c400b003047dc162f7sm7057593wrx.67.2023.05.31.07.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 07:27:39 -0700 (PDT) Date: Wed, 31 May 2023 16:27:38 +0200 From: Andrew Jones To: Alexandre Ghiti Cc: 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 , 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 Subject: Re: [PATCH v2 06/10] drivers: perf: Implement perf event mmap support in the legacy backend Message-ID: <20230531-705f2911e8d66938ece04905@orel> References: <20230512085321.13259-1-alexghiti@rivosinc.com> <20230512085321.13259-7-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230512085321.13259-7-alexghiti@rivosinc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Fri, May 12, 2023 at 10:53:17AM +0200, Alexandre Ghiti wrote: > 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 > --- > drivers/perf/riscv_pmu_legacy.c | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/drivers/perf/riscv_pmu_legacy.c b/drivers/perf/riscv_pmu_legacy.c > index ffe09d857366..f0f5bd856f66 100644 > --- a/drivers/perf/riscv_pmu_legacy.c > +++ b/drivers/perf/riscv_pmu_legacy.c > @@ -74,6 +74,31 @@ 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) > +{ > + /* In legacy mode, the first 3 CSRs are available. */ Shouldn't this be /* In legacy mode, the first and third CSR are available. */ ? > + 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) > +{ > + /* In legacy mode, the first 3 CSRs are available. */ same comment > + 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. > @@ -94,6 +119,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, RISCV_PMU_LEGACY_PDEV_NAME, PERF_TYPE_RAW); > } > -- > 2.37.2 > Otherwise, Reviewed-by: Andrew Jones