From patchwork Tue Jun 28 11:45:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nikita Shubin X-Patchwork-Id: 12898141 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 88DDFC43334 for ; Tue, 28 Jun 2022 11:47:22 +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=Ak7sMzQgDXl0/UY/UYMm7Spg7SIBabxTAn7JtpWxMWs=; b=ybOlejUCPL2tOR 8Sa/XYz6oatJJXB+4eTvDENFvrySMiVJIC54dnogHCKw1ZM6NpmzT7LFcsMYgJUqSRTzz8JatE8ug EjZILphp/rmlWU/hC3fBA740QrTR+M+tvgUwTpnRuLjmaseYBtt8AyIBCb2EzO1xpY8QJ0qDI4Lnw i9vaHWKD2hwCNDL+BZ98PCVtRwSul9RooJU64vdaiw28ivsQwFygNmz6hvyerX06z0x6APnD1hgRe vnZwujRN3T8O0hqTcQYYG2+SYcAHVAWtcyertWoJqE5fa5ZC9RZrc8vgdeCAS9SYZyElSz5SuAuw3 Dg70RBKHW/Arx90nR1cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o69gV-005zmT-UF; Tue, 28 Jun 2022 11:47:11 +0000 Received: from forward501j.mail.yandex.net ([5.45.198.251]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o69gB-005zdE-3l; Tue, 28 Jun 2022 11:46:53 +0000 Received: from vla1-5c8ce23a551e.qloud-c.yandex.net (vla1-5c8ce23a551e.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:400d:0:640:5c8c:e23a]) by forward501j.mail.yandex.net (Yandex) with ESMTP id B233A6231D1; Tue, 28 Jun 2022 14:46:39 +0300 (MSK) Received: from vla3-178a3f795968.qloud-c.yandex.net (vla3-178a3f795968.qloud-c.yandex.net [2a02:6b8:c15:2584:0:640:178a:3f79]) by vla1-5c8ce23a551e.qloud-c.yandex.net (mxback/Yandex) with ESMTP id Z9x1a00j1O-kbfO9vfl; Tue, 28 Jun 2022 14:46:39 +0300 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1656416799; bh=Fj1CfjmfGHqlANTgIcu8cPsR6XcA+gZqUzEuWcIko50=; h=In-Reply-To:References:Date:Subject:Cc:To:From:Message-Id; b=Iyo0QB+ECzkswea2YaWHcoTNqLb//6FNK9SFNAfsu89FF6hglDxS0NDB3vY6rqhPN Q5ZTt2JRerQs7m2c+7/MzTIRUJE3DM/K/tu844WsXJMBcJvwv8FRwtbegry+9Xd1ke p3Dt/rtXxuct1+9xXwKrxt9lyV48dvMUbqvFuGck= Authentication-Results: vla1-5c8ce23a551e.qloud-c.yandex.net; dkim=pass header.i=@maquefel.me Received: by vla3-178a3f795968.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id s5dKAuvn1y-kZMCIGGq; Tue, 28 Jun 2022 14:46:36 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Nikita Shubin To: Cc: linux@yadro.com, Genevieve Chan , =?utf-8?b?Sm/Do28gTcOhcmlvIERvbWluZ29z?= , Nikita Shubin , Atish Patra , Anup Patel , 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 v5 1/4] drivers/perf: riscv_pmu_sbi: perf format Date: Tue, 28 Jun 2022 14:45:55 +0300 Message-Id: <20220628114625.166665-2-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220628114625.166665-1-nikita.shubin@maquefel.me> References: <20220628114625.166665-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-20220628_044651_556600_E02CF957 X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=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 --- v4->v5: - format config is now 48-bit wide - simply use "config:63" --- 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..a2a22e35d6ed 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-47"); +PMU_FORMAT_ATTR(firmware, "config: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;