From patchwork Fri Jan 12 11:17:15 2024 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: 13518329 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 6B308C4706C for ; Fri, 12 Jan 2024 11:18:29 +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=0mbfmYQ192GkNMsUhki2M74TQ7NGoDgbGKaMSM2WktY=; b=FWELXO0KWbE9ep z5DNih8CLVownubU8CkCahoSakZMIgQfjg8kcLhyQlA/Py/9nkcB9rxnorp77HUMYsEnmV08HWqm9 zZ5N/c7lZtJ1QJa/cquif0lk+Sa+54qodtGKcEMGt7n0l3CO2G7F5sXodkxuqNLyeVC5ZeX1LkQvH fi2+vcdjD4JnE7gr/TI6Ywteee8c1w7pLqh7Lx+KiFcnPQG2vtmHdDI+sunSyH7a2nfsZJQOA5nDz pT9ekDoA/0RLSR+E1uupeLjDwd8uLCKlT7gae8aPc94KxpkVGKQbRV14mVrX0dFeIffzO3A0A8M0q FMIcxJkL79SPCiZjwsPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rOFY2-002ZXl-0S; Fri, 12 Jan 2024 11:18:02 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rOFXy-002ZV2-1p for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2024 11:18:00 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1d54c7ef801so10843995ad.0 for ; Fri, 12 Jan 2024 03:17:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705058277; x=1705663077; 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=8w/9bskBXsRWHhui8ZaSBSUqNBD3kcRzwMs9bhf0U2U=; b=FSnvwrGWHxmXaUf9md5ait2UW94x+jJbUrG+Onr/BL4CusZ0aMBK45ze7FE+ocxHfN C52ohoMm+3AIHXebZazXRsbt0qhpt32A52FmCd+yMN295SN9yrWLV5qSESy8VIjLEon3 Xk8U27caU1x2FGldv6EeywCkDtAS23OVHubHD3NNUEvuVikxaFn28L1qfocYUSKMWyFd Vq17oh1zW+e6DBdkVN3kP4kklfYYvcI4dn/cKJjrCsaxCoXaClAOb6BQUjVvpGf7W9+0 nteOYyqQzUiVWYmtlV679ixt3XlL8C6VQpUqQe7PfLJuMfBQ8K7Gyq11EOt04ynMpRIW adBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705058277; x=1705663077; 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=8w/9bskBXsRWHhui8ZaSBSUqNBD3kcRzwMs9bhf0U2U=; b=NoPvcz95BvKUjrQlXMck8rgXCEV7o9R4jIjWiWPV33pQYpV1vbG4pQ/wLjxR5FlWVF Uspc05IH1GlBz8zva/ghOXJgcxWTwEf2pW4aAzqfh8+wCTzssphglJeYI4ihnzkLV7mM 8eZNymvb/pLQXo2VwVcnKWuG+B+1N0Jg1j73pv7WDTkhwmMaJtU6zfi1wY0s+X8oCxAR XSia2eAlz+qZaaguw/6ySlUnRNTmYy6XAUahyoHjInle1An2DU0g9jdf86ZYnlmygCPx UFJqonHXPDV4F1ZiqZxVg98D8+4359L0bvjKmumUo7S32OrxeTosHRGe0puSm4D61U9C oSgg== X-Gm-Message-State: AOJu0YyEdF9v2HKVNxM8xQ3l5SbUKPm71rx2AcqPgVOMXiUJwIu7Pve/ kvirxI6aF5AM1q0sNsh1unYH5Eyp2V0oCA== X-Google-Smtp-Source: AGHT+IE7/kN9i+GiQIVlZVdE2Vic4gF/Ie1ElYGWcAfLnQxdjsUZVPiwKOEkVwRXM2sM2j4JicpVGQ== X-Received: by 2002:a17:90b:4c43:b0:28d:e5e7:fe43 with SMTP id np3-20020a17090b4c4300b0028de5e7fe43mr1344177pjb.1.1705058277475; Fri, 12 Jan 2024 03:17:57 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:a276:8a4e:2aa1:5f09]) by smtp.gmail.com with ESMTPSA id sd12-20020a17090b514c00b0028cef021d45sm3794179pjb.17.2024.01.12.03.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 03:17:57 -0800 (PST) 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 v2 3/3] perf: RISC-V: add support for SSE event Date: Fri, 12 Jan 2024 12:17:15 +0100 Message-ID: <20240112111720.2975069-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240112111720.2975069-1-cleger@rivosinc.com> References: <20240112111720.2975069-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_031758_606786_351814FF X-CRM114-Status: GOOD ( 18.79 ) 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. Reuse the existing overlflow IRQ handler and pass appropriate pt_regs. Signed-off-by: Clément Léger --- drivers/perf/riscv_pmu_sbi.c | 46 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 16acd4dcdb96..c82d7fe004c8 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 @@ -668,10 +669,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; @@ -679,7 +680,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)) @@ -688,13 +688,15 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) /* Firmware counter don't support overflow yet */ fidx = find_first_bit(cpu_hw_evt->used_hw_ctrs, RISCV_MAX_COUNTERS); if (fidx == RISCV_MAX_COUNTERS) { - csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); + if (!from_sse) + csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); return IRQ_NONE; } event = cpu_hw_evt->events[fidx]; if (!event) { - csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); + if (!from_sse) + csr_clear(CSR_SIP, BIT(riscv_pmu_irq_num)); return IRQ_NONE; } @@ -706,16 +708,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]; @@ -761,6 +763,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); @@ -804,9 +822,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; @@ -834,7 +860,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;