From patchwork Tue Jan 28 04:59:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 13952043 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 37EACC0218D for ; Tue, 28 Jan 2025 05:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QcgV78ON7bQjbj8rz+m5AxTl8xJOToNes7SYHJXciAs=; b=byfaNfNZyy2OANqC7uAaONe40M MZzCibUN7sSmSripfP/ANF+YEq2U4wqKhcdIil/X9yXAJHBk/xcadkpGfGRndtmpR1rvrv/ECaTar 7VscvwZfLmSMv5m+R8TcexFXY/KGcy+zBgl++Jflj+IhTzAZB97WUED7CP86p0vquW+gxFq+CfYL0 0CvfroEQwd1ayyml/R72wtbZWcCb7RTi/ImdzbVK7BbY0GBfyKD7+vS8VeD5sBgDJXHRbXbsBGHBX doj68T0vcn8AnwLYzVoOEpyDiyLXHo+xzsM4SdxEmhKShf2CNjQovGOAKpmJXCqjMstBjOdCHP8kR e6z41IXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tce2X-000000049Da-1Elf; Tue, 28 Jan 2025 05:21:33 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tcdhx-000000044lY-1jGM for linux-arm-kernel@lists.infradead.org; Tue, 28 Jan 2025 05:00:19 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2ee51f8c47dso7192405a91.1 for ; Mon, 27 Jan 2025 21:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1738040417; x=1738645217; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QcgV78ON7bQjbj8rz+m5AxTl8xJOToNes7SYHJXciAs=; b=P3tQzYDsLZ3oEzhEc3dopSglHdtx3Lmzw4Zk/eOuPx4CY20kD58oIRbrK3c4tVkVBQ a+qRifkjv1vNKQ06dGq2yESptaKtcwgiwa5C49W9U4dV5fhSl/Q68EnqF2fPTTr9nrqW 7mc43NY1faDezQ4Oj1BYzffWU2XSMWefHD1oDDgqIDCheyD0j/RtE3NSPFttMZJ4LzKr k9Pc2ST36k/AdO1fspxuNDVXmyvM7OQrD2jRsbdPyxErM3buq9rk1p3XPuOGB2NNt4JX qUXPFSOVzclXzQ5tQxBOJUSbrMFB5dLkgimljRlDlUVPKDIJdcvwDwLnbmiXt/aT9nkK 7mmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738040417; x=1738645217; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QcgV78ON7bQjbj8rz+m5AxTl8xJOToNes7SYHJXciAs=; b=JfapUkdCMgU1a63SRIJ8b5xKaZNGoTDJ914gmHJ1K0/1s+rb5wbgtsFYCXaNhnySvo p7T+micCSSTXMeE0kSAbHvYUccMjApdBETu/+EFp8piYwBHO3zJgPauOfjuoV+Js47cJ b7Dbjro4ZgaDs+xjuXrdKd3azL/XCYW/QJNyx1mzFAkKmc8UY/+PxxQ6jjPnfcgvaGcc PaifVG9vDBtJ59BK58m63YoGnbBbyT++GUIIXDe3qt15UTHu0AFgbvFV9jpmb0ar5/iO De40ZmjOWkfdqf5s7J5eIMGfVU1qdRKUOtkG+JGAbZUbT8Ls+CzOMYj9O9EP++yW/4iL fWRg== X-Forwarded-Encrypted: i=1; AJvYcCWKWpFXq/GjXGLqoMZTs+GSfSe8j0NBTuE79n4qic0dBu+YiRK7Lghxz+x2g+nm/thwmf/MZiicBGv1fuMDRm+/@lists.infradead.org X-Gm-Message-State: AOJu0YycFy7Dbz5MX38DX1KtgN/Fk9OlFOq1o3J4T/sG1Yy0i+ID43Ys D28iFcteI2WaHK62BLAYn9ebDUfHqrcWR6pTroSLdIc5Il1ygoJYMHOz85hm6oM= X-Gm-Gg: ASbGncvlBosz0qNty8kYczZOlfxMjBZL569SlWVo0c8YnKN4txFAeztICYoRAU2m6GR QhxBYAh8IrAbJTLwpje/sagqfFJdEILlIJZi4DP8XbU51HZZM1JKDucJe3YDi/5lgUHHdroXK5A WoKC9dV1iiikNhWixQKgMyA8+hlc2dfohc74vEjVpmU6gfkj2yGBl/fDYqa3RKNKeN2hNbTqZ+F gMC28vIz5EaIH6tpB08/d7E7IoiYU648tK82r67q8WXWyztfbM/jfwyEwXnZwiERzRumK5Szsr2 3YeCijwo7MwWNVXvEPgyAeoTsB/I X-Google-Smtp-Source: AGHT+IGCm7GMS3VNtxEaZyWfkLMPbe+hI7KXpym5HHPhVJQX2ASsOYeeTikT15JA57Prj6Ttz9V96w== X-Received: by 2002:a17:90b:524b:b0:2ee:a583:e616 with SMTP id 98e67ed59e1d1-2f782c8fd41mr65998400a91.9.1738040416850; Mon, 27 Jan 2025 21:00:16 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7ffa5a7f7sm8212776a91.11.2025.01.27.21.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 21:00:16 -0800 (PST) From: Atish Patra Date: Mon, 27 Jan 2025 20:59:58 -0800 Subject: [PATCH v3 17/21] RISC-V: perf: Add legacy event encodings via sysfs MIME-Version: 1.0 Message-Id: <20250127-counter_delegation-v3-17-64894d7e16d5@rivosinc.com> References: <20250127-counter_delegation-v3-0-64894d7e16d5@rivosinc.com> In-Reply-To: <20250127-counter_delegation-v3-0-64894d7e16d5@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Anup Patel , Atish Patra , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , weilin.wang@intel.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Conor Dooley , devicetree@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, Atish Patra X-Mailer: b4 0.15-dev-13183 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250127_210017_540690_E344B40A X-CRM114-Status: GOOD ( 16.89 ) 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 Define sysfs details for the legacy events so that any tool can parse these to understand the minimum set of legacy events supported by the platform. The sysfs entry will describe both event encoding and corresponding counter map so that an perf event can be programmed accordingly. Signed-off-by: Atish Patra --- drivers/perf/riscv_pmu_dev.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/perf/riscv_pmu_dev.c b/drivers/perf/riscv_pmu_dev.c index ab84f83df5e1..055011f07759 100644 --- a/drivers/perf/riscv_pmu_dev.c +++ b/drivers/perf/riscv_pmu_dev.c @@ -122,7 +122,20 @@ static struct attribute_group riscv_cdeleg_pmu_format_group = { .attrs = riscv_cdeleg_pmu_formats_attr, }; +#define RVPMU_EVENT_ATTR_RESOLVE(m) #m +#define RVPMU_EVENT_CMASK_ATTR(_name, _var, config, mask) \ + PMU_EVENT_ATTR_STRING(_name, rvpmu_event_attr_##_var, \ + "event=" RVPMU_EVENT_ATTR_RESOLVE(config) \ + ",counterid_mask=" RVPMU_EVENT_ATTR_RESOLVE(mask) "\n") + +#define RVPMU_EVENT_ATTR_PTR(name) (&rvpmu_event_attr_##name.attr.attr) + +static struct attribute_group riscv_cdeleg_pmu_event_group __ro_after_init = { + .name = "events", +}; + static const struct attribute_group *riscv_cdeleg_pmu_attr_groups[] = { + &riscv_cdeleg_pmu_event_group, &riscv_cdeleg_pmu_format_group, NULL, }; @@ -362,11 +375,14 @@ struct riscv_vendor_pmu_events { const struct riscv_pmu_event *hw_event_map; const struct riscv_pmu_event (*cache_event_map)[PERF_COUNT_HW_CACHE_OP_MAX] [PERF_COUNT_HW_CACHE_RESULT_MAX]; + struct attribute **attrs_events; }; -#define RISCV_VENDOR_PMU_EVENTS(_vendorid, _archid, _implid, _hw_event_map, _cache_event_map) \ +#define RISCV_VENDOR_PMU_EVENTS(_vendorid, _archid, _implid, _hw_event_map, \ + _cache_event_map, _attrs) \ { .vendorid = _vendorid, .archid = _archid, .implid = _implid, \ - .hw_event_map = _hw_event_map, .cache_event_map = _cache_event_map }, + .hw_event_map = _hw_event_map, .cache_event_map = _cache_event_map, \ + .attrs_events = _attrs }, static struct riscv_vendor_pmu_events pmu_vendor_events_table[] = { }; @@ -388,6 +404,8 @@ static void rvpmu_vendor_register_events(void) pmu_vendor_events_table[i].archid == arch_id) { current_pmu_hw_event_map = pmu_vendor_events_table[i].hw_event_map; current_pmu_cache_event_map = pmu_vendor_events_table[i].cache_event_map; + riscv_cdeleg_pmu_event_group.attrs = + pmu_vendor_events_table[i].attrs_events; break; } }