From patchwork Mon Dec 11 14:07:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1874544 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zWoVtnrH; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=Z5nYettx; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=Mu93V3fY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SpkYc23Tnz20Gc for ; Tue, 12 Dec 2023 01:25:40 +1100 (AEDT) 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: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:In-Reply-To:References: List-Owner; bh=QhcP1FF5ZtRo4X85KM+JXxnDdpwgyaDJeiV4RMAMr58=; b=zWoVtnrHr6CK06 k7RVwiRMfYGDEdr/GcvZKB/9fJ5a4c6FZ9DvxqQTR92lUNbJaiwmwTuHaLmZ5rbpXkazC8orBRixr PdHqPh3q2BQEp2SDv7ajZvMFP6jT8u804Nbua5SmAods8XEsiLHEwHAj09lWCXNe/ts/UDMsgDfIH j2p6cyI+0Xg0kl2/jNv1W0z9YC/fNGX5/ivrrajQDmswOOK3u/sZRO8w7dQMUiSClHWHpeXELOGWx 0hGXW29Fw9UcgPLPqkso8ojurDqaW5KTzUKFD7pF1hO6vSqIPgNUU9DcJkmXVKJk4lb0Z+fav8QNr de6IsHv+/rVVnO6xcLEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rChDl-005Anz-2S; Mon, 11 Dec 2023 14:25:21 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rChDi-005An5-1O for opensbi@bombadil.infradead.org; Mon, 11 Dec 2023 14:25:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=SSg56zSJ6A2t1SHNtq0DwlzoP5xGUgfmjX+uuuPC5M8=; b=Z5nYettxNEXwdqS3FTGw2Rdr9w dhNthmpCJZFScHCYe7DiTC/eNb8mQclxQaldHUhkPgUTVuvmODTWkTmzVdW+18YybHr2WdBENfaup K2GR7Un0zgNbmxX88N7IkT3HivykcD4PbrxW84izX6gB/2Jq6nBxtxohO/52+dQZg1kJh9t6PXMN/ vEgLNPBO4t12k0mL08jriFW93y1GfF8j483ZJp8xMhjd80R8V3UkSf77eMNmRhHmFQGWZV6TAEpK4 j8JVSCzZonDlfuc+IzLtE5FKxjgD8uTnDZXOvVO/sm0KfWgivXeRlnSwf39KbltkRACVq6slhhYGr jBTQMwkg==; Received: from [220.181.12.36] (helo=m126.mail.126.com) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rChDU-0087L6-0L for opensbi@lists.infradead.org; Mon, 11 Dec 2023 14:25:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=SSg56 zSJ6A2t1SHNtq0DwlzoP5xGUgfmjX+uuuPC5M8=; b=Mu93V3fY79dvG6ldhoJsF lqklpvLvyi9hNIih5j3En9V8eztUxBfprphpNkbOFVwD1SDQwvsIMQaiLBdAETWg 0ogcyCCCngPHXkf5tNuiiY+jiAhpaCGYlR5eW9fDHhDzbguzIDKqXwYeDoXZqLnn X/PAkweUbV2OISnkqwNC0g= Received: from T490.lan (unknown [112.83.182.199]) by zwqz-smtp-mta-g3-1 (Coremail) with SMTP id _____wAXuzmlF3dl58oODw--.24229S2; Mon, 11 Dec 2023 22:07:34 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH] lib: sbi: Optimize ipi_send/ipi_clear Date: Mon, 11 Dec 2023 22:07:26 +0800 Message-ID: <20231211140731.1251787-1-wxjstz@126.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CM-TRANSID: _____wAXuzmlF3dl58oODw--.24229S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuFW5AFy3uF4DGF1fXrWrXwb_yoWfJr48pF WUXF4vyr4Ivr18G34qqa17GF43uayvk3s7tw47Xa48Xw1UZ34UGr10gr4jk3ZFgrZ5AFy5 ZF4jyryfKF4j9FJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_fOzdUUUUU= X-Originating-IP: [112.83.182.199] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdQdDOmSdLpcqMgAAsT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231211_142504_893205_9B8AACB1 X-CRM114-Status: GOOD ( 15.02 ) X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add the hartid parameter to ipi_send/ipi_clear to avoid multiple conversions of hartid and hartindex. Signed-off-by: Xiang W --- include/sbi/sbi_ipi.h | 12 ++++++------ lib/sbi/sbi_hsm.c | 2 +- lib/sbi/sbi_init.c | 4 ++-- lib/sbi/sbi_ipi.c | 17 ++++++++++------- lib/utils/ipi/aclint_mswi.c | 14 ++++ [...] Content analysis details: (1.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_L3 RBL: Low reputation (-3) [220.181.12.36 listed in bl.mailspike.net] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS 0.0 RCVD_IN_MSPIKE_BL Mailspike blocklisted X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add the hartid parameter to ipi_send/ipi_clear to avoid multiple conversions of hartid and hartindex. Signed-off-by: Xiang W --- include/sbi/sbi_ipi.h | 12 ++++++------ lib/sbi/sbi_hsm.c | 2 +- lib/sbi/sbi_init.c | 4 ++-- lib/sbi/sbi_ipi.c | 17 ++++++++++------- lib/utils/ipi/aclint_mswi.c | 14 +++++++------- lib/utils/ipi/andes_plicsw.c | 10 +++++----- lib/utils/irqchip/imsic.c | 2 +- platform/generic/andes/ae350.c | 2 +- 8 files changed, 33 insertions(+), 30 deletions(-) diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h index d396233..947fd7f 100644 --- a/include/sbi/sbi_ipi.h +++ b/include/sbi/sbi_ipi.h @@ -23,11 +23,11 @@ struct sbi_ipi_device { /** Name of the IPI device */ char name[32]; - /** Send IPI to a target HART index */ - void (*ipi_send)(u32 hart_index); + /** Send IPI to a target HART */ + void (*ipi_send)(u32 hartid, u32 hart_index); - /** Clear IPI for a target HART index */ - void (*ipi_clear)(u32 hart_index); + /** Clear IPI for a target HART */ + void (*ipi_clear)(u32 hartid, u32 hart_index); }; enum sbi_ipi_update_type { @@ -85,9 +85,9 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase); void sbi_ipi_process(void); -int sbi_ipi_raw_send(u32 hartindex); +int sbi_ipi_raw_send(u32 hartid, u32 hartindex); -void sbi_ipi_raw_clear(u32 hartindex); +void sbi_ipi_raw_clear(u32 hartid, u32 hartindex); const struct sbi_ipi_device *sbi_ipi_get_device(void); diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 3d60ceb..1288bf7 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -355,7 +355,7 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, (hsm_device_has_hart_secondary_boot() && !init_count)) { rc = hsm_device_hart_start(hartid, scratch->warmboot_addr); } else { - rc = sbi_ipi_raw_send(sbi_hartid_to_hartindex(hartid)); + rc = sbi_ipi_raw_send(hartid, sbi_hartid_to_hartindex(hartid)); } if (!rc) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 6a98e13..c111453 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -257,7 +257,7 @@ static void wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid) sbi_hartmask_for_each_hartindex(i, &coldboot_wait_hmask) { if (i == hartindex) continue; - sbi_ipi_raw_send(i); + sbi_ipi_raw_send(sbi_hartindex_to_hartid(i), i); } /* Release coldboot lock */ @@ -504,7 +504,7 @@ static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid) if (hstate == SBI_HSM_STATE_SUSPENDED) { init_warm_resume(scratch, hartid); } else { - sbi_ipi_raw_clear(sbi_hartid_to_hartindex(hartid)); + sbi_ipi_raw_clear(hartid, sbi_hartid_to_hartindex(hartid)); init_warm_startup(scratch, hartid); } } diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index 5c33a78..dbfd1bb 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -72,7 +72,9 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartindex, */ if (!__atomic_fetch_or(&ipi_data->ipi_type, BIT(event), __ATOMIC_RELAXED)) - ret = sbi_ipi_raw_send(remote_hartindex); + ret = sbi_ipi_raw_send( + sbi_hartindex_to_hartid(remote_hartindex), + remote_hartindex); sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT); @@ -221,10 +223,11 @@ void sbi_ipi_process(void) struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); struct sbi_ipi_data *ipi_data = sbi_scratch_offset_ptr(scratch, ipi_data_off); - u32 hartindex = sbi_hartid_to_hartindex(current_hartid()); + u32 hartid = current_hartid(); + u32 hartindex = sbi_hartid_to_hartindex(hartid); sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD); - sbi_ipi_raw_clear(hartindex); + sbi_ipi_raw_clear(hartid, hartindex); ipi_type = atomic_raw_xchg_ulong(&ipi_data->ipi_type, 0); ipi_event = 0; @@ -239,7 +242,7 @@ void sbi_ipi_process(void) } } -int sbi_ipi_raw_send(u32 hartindex) +int sbi_ipi_raw_send(u32 hartid, u32 hartindex) { if (!ipi_dev || !ipi_dev->ipi_send) return SBI_EINVAL; @@ -255,14 +258,14 @@ int sbi_ipi_raw_send(u32 hartindex) */ wmb(); - ipi_dev->ipi_send(hartindex); + ipi_dev->ipi_send(hartid, hartindex); return 0; } -void sbi_ipi_raw_clear(u32 hartindex) +void sbi_ipi_raw_clear(u32 hartid, u32 hartindex) { if (ipi_dev && ipi_dev->ipi_clear) - ipi_dev->ipi_clear(hartindex); + ipi_dev->ipi_clear(hartid, hartindex); /* * Ensure that memory or MMIO writes after this diff --git a/lib/utils/ipi/aclint_mswi.c b/lib/utils/ipi/aclint_mswi.c index 4ae6bb1..b73b5b6 100644 --- a/lib/utils/ipi/aclint_mswi.c +++ b/lib/utils/ipi/aclint_mswi.c @@ -25,7 +25,7 @@ static unsigned long mswi_ptr_offset; #define mswi_set_hart_data_ptr(__scratch, __mswi) \ sbi_scratch_write_type((__scratch), void *, mswi_ptr_offset, (__mswi)) -static void mswi_ipi_send(u32 hart_index) +static void mswi_ipi_send(u32 hartid, u32 hart_index) { u32 *msip; struct sbi_scratch *scratch; @@ -41,11 +41,10 @@ static void mswi_ipi_send(u32 hart_index) /* Set ACLINT IPI */ msip = (void *)mswi->addr; - writel_relaxed(1, &msip[sbi_hartindex_to_hartid(hart_index) - - mswi->first_hartid]); + writel_relaxed(1, &msip[hartid - mswi->first_hartid]); } -static void mswi_ipi_clear(u32 hart_index) +static void mswi_ipi_clear(u32 hartid, u32 hart_index) { u32 *msip; struct sbi_scratch *scratch; @@ -61,8 +60,7 @@ static void mswi_ipi_clear(u32 hart_index) /* Clear ACLINT IPI */ msip = (void *)mswi->addr; - writel_relaxed(0, &msip[sbi_hartindex_to_hartid(hart_index) - - mswi->first_hartid]); + writel_relaxed(0, &msip[hartid - mswi->first_hartid]); } static struct sbi_ipi_device aclint_mswi = { @@ -73,8 +71,10 @@ static struct sbi_ipi_device aclint_mswi = { int aclint_mswi_warm_init(void) { + u32 hartid = current_hartid(); + /* Clear IPI for current HART */ - mswi_ipi_clear(current_hartid()); + mswi_ipi_clear(hartid, sbi_hartid_to_hartindex(hartid)); return 0; } diff --git a/lib/utils/ipi/andes_plicsw.c b/lib/utils/ipi/andes_plicsw.c index 413ac20..981b8c7 100644 --- a/lib/utils/ipi/andes_plicsw.c +++ b/lib/utils/ipi/andes_plicsw.c @@ -18,11 +18,11 @@ struct plicsw_data plicsw; -static void plicsw_ipi_send(u32 hart_index) +static void plicsw_ipi_send(u32 hartid, u32 hart_index) { ulong pending_reg; u32 interrupt_id, word_index, pending_bit; - u32 target_hart = sbi_hartindex_to_hartid(hart_index); + u32 target_hart = hartid; if (plicsw.hart_count <= target_hart) ebreak(); @@ -41,9 +41,9 @@ static void plicsw_ipi_send(u32 hart_index) writel_relaxed(BIT(pending_bit), (void *)pending_reg); } -static void plicsw_ipi_clear(u32 hart_index) +static void plicsw_ipi_clear(u32 hartid, u32 hart_index) { - u32 target_hart = sbi_hartindex_to_hartid(hart_index); + u32 target_hart = hartid; ulong reg = plicsw.addr + PLICSW_CONTEXT_BASE + PLICSW_CONTEXT_CLAIM + PLICSW_CONTEXT_STRIDE * target_hart; @@ -70,7 +70,7 @@ int plicsw_warm_ipi_init(void) u32 hartid = current_hartid(); /* Clear PLICSW IPI */ - plicsw_ipi_clear(hartid); + plicsw_ipi_clear(hartid, sbi_hartid_to_hartindex(hartid)); return 0; } diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c index 36ef66c..ca6f15d 100644 --- a/lib/utils/irqchip/imsic.c +++ b/lib/utils/irqchip/imsic.c @@ -161,7 +161,7 @@ static int imsic_external_irqfn(struct sbi_trap_regs *regs) return 0; } -static void imsic_ipi_send(u32 hart_index) +static void imsic_ipi_send(u32 hartid, u32 hart_index) { unsigned long reloff; struct imsic_regs *regs; diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c index 088ec07..fafbb3e 100644 --- a/platform/generic/andes/ae350.c +++ b/platform/generic/andes/ae350.c @@ -32,7 +32,7 @@ static int ae350_hart_start(u32 hartid, ulong saddr) * 2) the target hart is non-sleepable 25-series hart0 */ if (!sbi_init_count(hartid) || (is_andes(25) && hartid == 0)) - return sbi_ipi_raw_send(sbi_hartid_to_hartindex(hartid)); + return sbi_ipi_raw_send(hartid, sbi_hartid_to_hartindex(hartid)); /* Write wakeup command to the sleep hart */ smu_set_command(&smu, WAKEUP_CMD, hartid);