Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp483184rdh; Thu, 26 Oct 2023 07:33:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXhzBJ8fO6BU3i84xTHghhJonqfAAav9xFdSqRt6uFYUZ4gjgREYO33WFGyc3rmAGh93pA X-Received: by 2002:a05:6214:5008:b0:658:c75c:1946 with SMTP id jo8-20020a056214500800b00658c75c1946mr21635515qvb.52.1698330790960; Thu, 26 Oct 2023 07:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698330790; cv=none; d=google.com; s=arc-20160816; b=O+fdYmDvoSAcwj8rjC4EW21V4nNN2K5dFUhbqCrE229FOTlE2IgcXuNzZAomW9KNAt +JAavEmMORXnxt7pCChr2971nK8jnkxV6I7bKelm/kMBnkbVT4MN8yOe9UedX1mMnlON Az+AaXs2MA/UFCcmbe+OaScqWCL26MnL+gooLYHnIye0XXjJhP04NIQ4pzZRQ3qwSjXb uYRLRC3eRUIsFFn9h14UFGiyn3sN5e/3UCdTSPfP8/pdmyWEGGRtBOV2AcOaBNbAZuP4 Kqj5VD/PLgECPhHsuFYKCg1QYEIeYGuyID8BAiCuElH0E91m7CFgWzGW95KTdbKm+d/G Tt9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IjJNbk+YzeocIZaMbaGiDwKsD4n3sxNNihAmQTPUtd4=; fh=AdjJcfMlYbiYDdKKIz6ysPeqNYJJCfTBHWq2VWscBlk=; b=bAjqKkL6bp9o5OhPl8DnMd7Rx9XAZcGI96aOeuPXyrOX83v8d+97Yk+i+ANSssXalO uhQ7KtXW+uWJiuCNC3K3bau4O8tF45pJtjuqDxjmbr1esO/t+vYv5Ld8Ap1h6fpj+Ox0 Ue754fIHbVHP3i51MKmiBHD3Y1v+wE2Otvc/bDXv1Q+Urm5g96GaM0C+3R/LXmnYyQHJ 2OwTiKXHfKiafPBN2VIm0t5WckT3KOlpALdvCpnEoOcpGISPk/pA5v+WMlhLIHnFe2pe nrLkKdyAahTthMjLo6TN72OXP6TCbY1+rzFB2ydlpVZP7o3SaCWuGyEy5YYHf/ChFFb/ L7Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=DQQskNQy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id lr2-20020a0562145bc200b0065652d888b1si411817qvb.14.2023.10.26.07.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 07:33:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=DQQskNQy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 962D380D6A14; Thu, 26 Oct 2023 07:32:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345309AbjJZObp (ORCPT + 99 others); Thu, 26 Oct 2023 10:31:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345287AbjJZObe (ORCPT ); Thu, 26 Oct 2023 10:31:34 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72BC51B8 for ; Thu, 26 Oct 2023 07:31:31 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c506d1798eso3173581fa.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=vger.kernel.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=DQQskNQywQflG/oz+VBvZWAbL+Su2H1Qo1VBiRWdCC/xrUaR4OkBG/NltbM98GWFq6 cUAjW/x59+r4PIdVpAga/SO+PsvStDvH/txzXax28O57piy0ocYvJi6i54kwaOAaS7Ou C3m2ySxPFfVu18eUzh3B/gUCI/Od8nzRS43OsYGeE+IP+v0d3zJkC8v5wVfNnsSDsDri muJDNIBw7MIl6DZWGMmZPONA6Qns6bAwxvxZXjHbHnxAiwUCc00ta9p+CSAVVBImrvVM BE4CCKVkoCJrUvpUdFc8D0xmbNanhSwbg5iOwbgTHyfMI0WKZ+GF1DhTLFjBDpc9F6SM rzYg== 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=gjkB4vW/LT2EmfFJv0Cwf54huvFyP8Kh6S+2Zp1LtT2TwCYUNuvnytgL+ERQvBRidq dF1cu7cG4DTXwWf+s6uM3Sv3ZKo758wlKj5fr6uHHpJBygtCK1ura6HXp0bU0mykcHqT qLUfXBlGV1f+1t7VfEqebc20iBSyjbCyCqJ1ADco7SDdwm0Vh54VLANP5yTCNDeHQrNJ lmYLMW+xYySaSocIA9i7oGh4Ip4EmyXBAJ80+le8pIqSJ6ZhiP2gKD62ZTJiwLfYh1Q7 RgQ6lOu7vEL6786K3eOHsNNYLgUwtevRAt04R2dzd+7co5ZyeykaaPXKCPSWsknyQTBT 28aQ== X-Gm-Message-State: AOJu0YwRxxHUZDBLRjji0pBPHRXGLHcvoUbSfLj1PWLLc2nIM88FYfG4 sy+mnPw6h/k/lAI1ivmltfbvIw== 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?q?Cl=C3=A9ment=20L=C3=A9ger?= 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?q?Cl=C3=A9ment=20L=C3=A9ger?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 26 Oct 2023 07:32:44 -0700 (PDT) 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; -- 2.42.0