From patchwork Thu Oct 26 14:31:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13437616 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 B11B6C25B48 for ; Thu, 26 Oct 2023 14:32:17 +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=tpI97CC93lXN/ioPq/bvs8SP5wEw12Njwf8GZxiYqH4=; b=lvyzHHEdOeD2Rj NDzPDjl6LNb4MrQmrqtv7AkdqctrmK9AyFtHFZd8TuPHjal0I5A4kodydN15TkJNvNzB1lxMAkDLH exCsmvFA6yTSTUyYChObDeD58Nts5qMlCM/+9VS/z2cJxXU8ROll/xDQ73D4TRm9CKoE2ofKrj7VR +9HfwjnF+wdxL4qCC3fJBGd0ujIyoPbJtzhm59Ld2Em/UrsuhaDVmCpTNIFvE/YwZ2jXFbNGFp4DQ VmUv2Ijj1UXTO4DjHwlQdVu903PcSuAm2ZiF2nqmOIrbPc2XPc7p+7WVVbupLO+1b4Aoj4LPbTdq9 INzAJrHHmkO/LIN31TJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qw1Oq-00Egfa-2Z; Thu, 26 Oct 2023 14:31:52 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qw1OX-00EgSs-25 for linux-arm-kernel@lists.infradead.org; Thu, 26 Oct 2023 14:31:39 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-508172acec5so253099e87.0 for ; Thu, 26 Oct 2023 07:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698330689; x=1698935489; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IjJNbk+YzeocIZaMbaGiDwKsD4n3sxNNihAmQTPUtd4=; b=kHW7xlmvLbqZMYdAa1XDobXlTHYPyn99SVK1KGgMrqmnl3Jd02BM8u2rQUbe/+dOT3 Sv+YWgJ/eBkNTGSxjx4It4qT6g2hwEFMxrjaCWRua5Y6Ns6IBXKqWeKTQnu7j4kTQXQf PQxFCNlzGKzHNlsuEIdwep5W4IbMA0MMsN0XEPtZ5PcYJ0GRVRy/hYn2qY0tMbEGYLyU Ge0Y0EZZczKT9guUODY6HWkc/VWFg6LSMhT4rJbTVEJy+mL55NIGMqnlDhPCVLO1IKuI r2d4g598CnwxjyUhc95QC9IkSEieRGYtvuyNlb3Jx6mGoq1HKytv6KC19WhUHm04oUmP yE3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698330689; x=1698935489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IjJNbk+YzeocIZaMbaGiDwKsD4n3sxNNihAmQTPUtd4=; b=voyr2EWXBN4tCK3wt8uHhm8i65Q+UxvM+GfKy59GMMBQdqmEG8EpL66S6K99TLelmH vU7y6/uaZeTngFFkmpZdpxAeaPTY68g3RIdfgwXAOb+6PTt+6+LdNNdXmESIZEgRwaB5 EvxZ3S88GJkzOUNZaHkCX3s9jLzKO7d515Em+JiieiyzLDGBbWi/ZlCHXLe15Z1NRalY SHozrzJkzTCmqJMWLQKu6BuVtNrRK7Ppq+aItr1FzPUcDEU6D57/nwFifNhpEZTwbxAt /M5HhOi+obMd3JEmDSjC00KoLyvqrQRoBX96ApZOpmJM0D9klcbDBftTBQ/IKBnKuoF9 TXUg== X-Gm-Message-State: AOJu0YyGPW69QZjUGQycpBYujL0C3uN5oQp9FhdcB/MgwhkP3eczaLQv Q6otr+OBP5OjPyRMsnui6OZIcA== X-Google-Smtp-Source: AGHT+IFLytGw/7jgeGoJfJWsBD048sUEsQCNLXq5OinxBlnRc9jpp7CR1gsux8sfYWyRCNcKwi3XKw== X-Received: by 2002:a05:6512:2821:b0:505:7144:7c37 with SMTP id cf33-20020a056512282100b0050571447c37mr13666108lfb.6.1698330689555; Thu, 26 Oct 2023 07:31:29 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:b380:32be:257:5381]) by smtp.gmail.com with ESMTPSA id r9-20020a056000014900b003232f167df5sm14316589wrx.108.2023.10.26.07.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 07:31:29 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Himanshu Chauhan , Xu Lu Subject: [RFC PATCH 3/3] perf: RISC-V: add support for SSE event Date: Thu, 26 Oct 2023 16:31:22 +0200 Message-ID: <20231026143122.279437-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231026143122.279437-1-cleger@rivosinc.com> References: <20231026143122.279437-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231026_073133_720629_7ACF4D8C X-CRM114-Status: GOOD ( 23.41 ) 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 In order to use SSE within PMU drivers, register a SSE handler for the local PMU event. There is not a lot of specific code needed to handle the SSE event, just reuse the existing overlflow IRQ handler and pass appropriate pt_regs. Signed-off-by: Clément Léger --- arch/riscv/include/asm/sbi.h | 2 ++ drivers/perf/riscv_pmu_sbi.c | 51 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 2e99cafe7fed..13b01cd3a814 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -121,6 +121,8 @@ enum sbi_ext_pmu_fid { SBI_EXT_PMU_COUNTER_START, SBI_EXT_PMU_COUNTER_STOP, SBI_EXT_PMU_COUNTER_FW_READ, + SBI_EXT_PMU_COUNTER_FW_READ_HI, + SBI_EXT_PMU_COUNTER_IRQ_CLEAR, }; union sbi_pmu_ctr_info { diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 96c7f670c8f0..3fca70b13304 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -625,6 +626,12 @@ static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) cpu_hw_evt->used_hw_ctrs[0], 0, 0, 0, 0); } +static void pmu_sbi_irq_clear(void) +{ + /* No need to check the error here as we can't do anything about the error */ + sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_IRQ_CLEAR, 0, 0, 0, 0, 0, 0); +} + /* * This function starts all the used counters in two step approach. * Any counter that did not overflow can be start in a single step @@ -670,10 +677,10 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, } } -static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) +static irqreturn_t pmu_sbi_ovf_handler(struct cpu_hw_events *cpu_hw_evt, + struct pt_regs *regs, bool from_sse) { struct perf_sample_data data; - struct pt_regs *regs; struct hw_perf_event *hw_evt; union sbi_pmu_ctr_info *info; int lidx, hidx, fidx; @@ -681,7 +688,6 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) struct perf_event *event; unsigned long overflow; unsigned long overflowed_ctrs = 0; - struct cpu_hw_events *cpu_hw_evt = dev; u64 start_clock = sched_clock(); if (WARN_ON_ONCE(!cpu_hw_evt)) @@ -691,7 +697,10 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) fidx = find_first_bit(cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS); event = cpu_hw_evt->events[fidx]; if (!event) { - csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); + if (from_sse) + pmu_sbi_irq_clear(); + else + csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); return IRQ_NONE; } @@ -703,16 +712,16 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) /* * Overflow interrupt pending bit should only be cleared after stopping - * all the counters to avoid any race condition. + * all the counters to avoid any race condition. When using SSE, + * interrupt is cleared when stopping counters. */ - csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); + if (!from_sse) + csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); /* No overflow bit is set */ if (!overflow) return IRQ_NONE; - regs = get_irq_regs(); - for_each_set_bit(lidx, cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS) { struct perf_event *event = cpu_hw_evt->events[lidx]; @@ -758,6 +767,22 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) return IRQ_HANDLED; } +static irqreturn_t pmu_sbi_ovf_irq_handler(int irq, void *dev) +{ + return pmu_sbi_ovf_handler(dev, get_irq_regs(), false); +} + +static int pmu_sbi_ovf_sse_handler(uint32_t evt, void *arg, + struct pt_regs *regs) +{ + struct cpu_hw_events __percpu *hw_events = arg; + struct cpu_hw_events *hw_event = raw_cpu_ptr(hw_events); + + pmu_sbi_ovf_handler(hw_event, regs, true); + + return 0; +} + static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) { struct riscv_pmu *pmu = hlist_entry_safe(node, struct riscv_pmu, node); @@ -801,9 +826,17 @@ static int pmu_sbi_dying_cpu(unsigned int cpu, struct hlist_node *node) static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pdev) { int ret; + struct sse_event *evt; struct cpu_hw_events __percpu *hw_events = pmu->hw_events; struct irq_domain *domain = NULL; + evt = sse_event_register(SBI_SSE_EVENT_LOCAL_PMU, 0, + pmu_sbi_ovf_sse_handler, hw_events); + if (!IS_ERR(evt)) { + sse_event_enable(evt); + return 0; + } + if (riscv_isa_extension_available(NULL, SSCOFPMF)) { riscv_pmu_irq_num = RV_IRQ_PMU; riscv_pmu_use_irq = true; @@ -831,7 +864,7 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde return -ENODEV; } - ret = request_percpu_irq(riscv_pmu_irq, pmu_sbi_ovf_handler, "riscv-pmu", hw_events); + ret = request_percpu_irq(riscv_pmu_irq, pmu_sbi_ovf_irq_handler, "riscv-pmu", hw_events); if (ret) { pr_err("registering percpu irq failed [%d]\n", ret); return ret;