Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2143780rwp; Fri, 14 Jul 2023 01:10:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEHEUoVeA8jIeE5C9cNampEaYKv3NW1kBk72gwMlfrTU9eJmb+CEpnHM2tM9cU6JRj/DjzM X-Received: by 2002:a17:906:208d:b0:983:cb6c:8aa3 with SMTP id 13-20020a170906208d00b00983cb6c8aa3mr3466184ejq.59.1689322218379; Fri, 14 Jul 2023 01:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689322218; cv=none; d=google.com; s=arc-20160816; b=aJ9P4xHLlHoiTC08urKHyhvgjrYNfS27d1DQ7cF8BWWJZ9JKDcCtugd18P2b27QUqP ph6EyIt8JxvnX9ZX/kioZ92qKqkJ4KOx4xqaoc+LVz8mYQoR77zG1iDkzclxezRYoIw0 SDHPVOY24qbYlfM16lViJruAG3AaWuyxtgM5/21v3d9SOTSgYo70pdrwmid3eicP37lu UrXsZa7sTqV4SnFmpgPyGZoQtnnfNrdsCY3Za4FgrtDBaDRdI8Tw8/tDatGIiZujFm6K f9qLS8LNJsrmN2dCoDo0WHWlx4P50k4iPPWS+e8Hgkww2qcR/VtguG4ZHkGtX37ejhQ4 q6mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=KjGLAxee+6Ys9A4CymyGT7r3XR+DwzfZMVxRgHoxE5Q=; fh=y2M5v1gYeu0HYmN0hofCIqVy6M5fV8gJXE/fccYEzwc=; b=aEP0y6FoM54KGL5LU1/V6/ENH24/RC3QdrhVkYFuMHDcfp7mCcyc+ykVT5+7qv2zIc yLs/aHR8phf3sXAbaIZDL7M/pFUg2MqqNgzpxzUBeOt3EPSu/0+T3Ddgd72fi5Ky9+cn SHRxMmV03UAVACqjCPz//rEYT3JcnWX+kIyB/rOcb5uGWkq0wPTBTl7yQF5P7Zt+B/l3 kAEg9DYY101U11E0UBvErWTLp5teqcQj/a66f+XaRmq3LDNZCdPqJd3VZw2MYj/iJ4Rz 9EeKyOweY4J+Et1nN6eBe9zISPsl+VjWGVHEDNUZnb8mBIiRx3xupJLX12ySQnyEPoeu JCwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=CjrJSFwQ; 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 qo5-20020a170907212500b0099331931d5esi9210950ejb.71.2023.07.14.01.09.52; Fri, 14 Jul 2023 01:10:18 -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=@atishpatra.org header.s=google header.b=CjrJSFwQ; 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 S234567AbjGNIGJ (ORCPT + 99 others); Fri, 14 Jul 2023 04:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234925AbjGNIFm (ORCPT ); Fri, 14 Jul 2023 04:05:42 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C483ABD for ; Fri, 14 Jul 2023 01:03:43 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b703d7ed3aso24771711fa.1 for ; Fri, 14 Jul 2023 01:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; t=1689321821; x=1691913821; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KjGLAxee+6Ys9A4CymyGT7r3XR+DwzfZMVxRgHoxE5Q=; b=CjrJSFwQHNriZicyQY+/qEHwW+RTQYr4SNIG047YQMIYg0SDkOYGzcHkruU4HmdQx9 jbtscSpbmpGVYMjHVaxk3IB3OeT8otxO2C8i0F3xLjBHUcMg1WuQW7ENtOZsfYVzNRFI 3BUW0it+1aYPguLEVgD5Sjj70w/JS4oI0XbZs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689321821; x=1691913821; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KjGLAxee+6Ys9A4CymyGT7r3XR+DwzfZMVxRgHoxE5Q=; b=kprllneTo+3jhqu32dLkPBxxjakB7EDo1eYnBMM0m2H/EFim05ckzN9aVFxU7wYmZm SSWeWGN5V4rPU18GFgsX03mD2f0hHZeWW3W/l+bO93DbquHW+wyh0z8+c4xt9PDfBttx qZlUIPykxymfiwViZvoeIulq8J94/d6TpYBky+ZdcXPge82wwqV5lg4+cf3bXn9Z9FSa R7dNQCQkNeZg9Kut7RvBb3MnlmVH4BjAyJQlBEsOsBUfuBC3v+jUsGe2/P3HXyGrLGSl MrnqKLX9Y318owlk7PPmLpUPJWTaacbySx1BCVvZmuHTRU6YNI9OtUTJDxi4l5TXrHgE ocDw== X-Gm-Message-State: ABy/qLa7bYeQIQ+K1POoPaS6ysRY9ZWXa5dS40WSg7xJ2YySAEiCektX Aclw5JVXzeX7/3qm6LdnRkdrF2BwVkAFCCr89Xve X-Received: by 2002:a05:651c:104e:b0:2b6:c790:150a with SMTP id x14-20020a05651c104e00b002b6c790150amr3565106ljm.22.1689321821152; Fri, 14 Jul 2023 01:03:41 -0700 (PDT) MIME-Version: 1.0 References: <20230703124647.215952-1-alexghiti@rivosinc.com> <20230703124647.215952-7-alexghiti@rivosinc.com> In-Reply-To: <20230703124647.215952-7-alexghiti@rivosinc.com> From: Atish Patra Date: Fri, 14 Jul 2023 01:03:29 -0700 Message-ID: Subject: Re: [PATCH v4 06/10] drivers: perf: Implement perf event mmap support in the legacy backend 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 , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Mon, Jul 3, 2023 at 5:52=E2=80=AFAM 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 > 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_leg= acy.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 *ev= ent, 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 !=3D PERF_COUNT_HW_CPU_CYCLES && > + event->attr.config !=3D PERF_COUNT_HW_INSTRUCTIONS) > + return; > + > + event->hw.flags |=3D PERF_EVENT_FLAG_USER_READ_CNT; > +} > + > +static void pmu_legacy_event_unmapped(struct perf_event *event, struct m= m_struct *mm) > +{ > + if (event->attr.config !=3D PERF_COUNT_HW_CPU_CYCLES && > + event->attr.config !=3D PERF_COUNT_HW_INSTRUCTIONS) > + return; > + > + event->hw.flags &=3D ~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 =3D NULL; > pmu->ctr_clear_idx =3D NULL; > pmu->ctr_read =3D pmu_legacy_read_ctr; > + pmu->event_mapped =3D pmu_legacy_event_mapped; > + pmu->event_unmapped =3D pmu_legacy_event_unmapped; > + pmu->csr_index =3D pmu_legacy_csr_index; > > perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW); > } > -- > 2.39.2 > Reviewed-by: Atish Patra --=20 Regards, Atish