From patchwork Fri Jun 24 16:00:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nikita Shubin X-Patchwork-Id: 12894846 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 9B95AC43334 for ; Fri, 24 Jun 2022 16:03:41 +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=lcoTD3T6hX1EnZCGFO2pb8x9U8vpQU9ZH3VKXUVURjU=; b=eetgX6hGk2CISV HHpaPd64Mi9EPXErJaPn0/kiQLxepZ48Om9/hItvYojtjSN1XnUh0pqEQc/kCHFfGDyR94ooJ9o4a 6l1ZHYLKyExEsPFLe2nKZ+GuMKI//jPFWIBXsrSklNTFmuJ8w+QTuz40nhYUg7gWwUlIUSyIaUuLP THx/Y38a90WamaGXiYP/97H3ChmhqMF5j96YTdOIBrFWKnoT9jbanH5NeKsz0sgwzBm29ELdNkqiX LezY5QPXNdsN0eYhYkEDInjMLfnX0RNQsTCUJq3JO7/gIIMBHiqvYukpwP3ma8Ailii7jRtlPfxXu gLDg1qAzvfHX0GDHqkjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4lla-002woo-An; Fri, 24 Jun 2022 16:02:42 +0000 Received: from forward500p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b7:110]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4llV-002wmH-Pa; Fri, 24 Jun 2022 16:02:39 +0000 Received: from myt6-e228e91c65dd.qloud-c.yandex.net (myt6-e228e91c65dd.qloud-c.yandex.net [IPv6:2a02:6b8:c12:42a5:0:640:e228:e91c]) by forward500p.mail.yandex.net (Yandex) with ESMTP id AD567F04F2E; Fri, 24 Jun 2022 19:01:26 +0300 (MSK) Received: from myt5-ca5ec8faf378.qloud-c.yandex.net (myt5-ca5ec8faf378.qloud-c.yandex.net [2a02:6b8:c12:2514:0:640:ca5e:c8fa]) by myt6-e228e91c65dd.qloud-c.yandex.net (mxback/Yandex) with ESMTP id Cpu7h3Tut9-1PgmlxSt; Fri, 24 Jun 2022 19:01:26 +0300 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1656086486; bh=Od97yBVEB4xl89bfu7RN4gha8Ggf6tred2IKE8Y/ikg=; h=In-Reply-To:References:Date:Subject:Cc:To:From:Message-Id; b=d974ooxfFUysBu9E+rf/JT1jxMMbkAAQqTLxQpILPVr9Qa6L16K+LVoLCZhdEkGq3 Sgww9ZUHNRO1wBhf6vDXPQl3LynbA+blqByd1VF43/AMSL3z24qbA91j5DHb6GezGx ZA3EHvYAYCNujbvd9CCfdBQXnVkJWN86e9+5FoaQ= Authentication-Results: myt6-e228e91c65dd.qloud-c.yandex.net; dkim=pass header.i=@maquefel.me Received: by myt5-ca5ec8faf378.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id iVUkuL8Azf-1PMKOJDi; Fri, 24 Jun 2022 19:01:25 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Nikita Shubin To: Atish Patra , Anup Patel Cc: =?utf-8?b?Sm/Do28gTcOhcmlvIERvbWluZ29z?= , linux@yadro.com, Nikita Shubin , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/5] drivers/perf: riscv_pmu_sbi: perf format Date: Fri, 24 Jun 2022 19:00:51 +0300 Message-Id: <20220624160117.3206-2-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220624160117.3206-1-nikita.shubin@maquefel.me> References: <20220624160117.3206-1-nikita.shubin@maquefel.me> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220624_090238_249619_94E108E3 X-CRM114-Status: GOOD ( 12.30 ) 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 From: Nikita Shubin Update driver to export formatting and event information to sysfs so it can be used by the perf user space tools with the syntaxes: perf stat -e cpu/event=0x05 perf stat -e cpu/event=0x05,firmware=0x1/ 63-bit is used to distinguish hardware events from firmware. Firmware events are defined by "RISC-V Supervisor Binary Interface Specification". perf stat -e cpu/event=0x05,firmware=0x1/ is equivalent to perf stat -e r8000000000000005 Inspired-by: João Mário Domingos Signed-off-by: Nikita Shubin Link: https://github.com/riscv-non-isa/riscv-sbi-doc/blob/master/riscv-sbi.adoc --- drivers/perf/riscv_pmu_sbi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index dca3537a8dcc..2b5861a10d8e 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -21,6 +21,25 @@ #include #include +PMU_FORMAT_ATTR(event, "config:0-62"); +PMU_FORMAT_ATTR(firmware, "config:63-63"); + +static struct attribute *riscv_arch_formats_attr[] = { + &format_attr_event.attr, + &format_attr_firmware.attr, + NULL, +}; + +static struct attribute_group riscv_pmu_format_group = { + .name = "format", + .attrs = riscv_arch_formats_attr, +}; + +static const struct attribute_group *riscv_pmu_attr_groups[] = { + &riscv_pmu_format_group, + NULL, +}; + union sbi_pmu_ctr_info { unsigned long value; struct { @@ -720,6 +739,7 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT; pmu->pmu.capabilities |= PERF_PMU_CAP_NO_EXCLUDE; } + pmu->pmu.attr_groups = riscv_pmu_attr_groups; pmu->num_counters = num_counters; pmu->ctr_start = pmu_sbi_ctr_start; pmu->ctr_stop = pmu_sbi_ctr_stop;