From patchwork Thu Feb 2 08:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1736182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=r858Jwn6; 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=b0JP18fk; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6tbZ0Rgcz1yhq for ; Thu, 2 Feb 2023 20:22:18 +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: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=za/D83dpdM2TJ+qPwvQ5hwohXGzGnHCZTZ2iLN4XWfk=; b=r858Jwn628LxAW lgmcr/DFMw3dttjAvRgwLjVWD8phl/uf13KOGCl6Nn2TRaBTxAFQV8gnQ7cCziSkfBRdNhZbKlsof Vi17tuR1XUxNlLDTrxSQhSQ2nEG8zNshMyUKwzVUrQkuigfLw+l+v/ns554Jsz33x7A8P0JI6F1ii +FtazWOBlTanxsGlkDgv1Kaye4cvSMcFObrQRocRp7pytz9x1f1xukTYeF4kym1S1QcVzlly3X4aN JTAl+Mu4uIew8wwu+qB1QjZSE4F0U2lNVK2UrGuawAySW+/TooIrT5klDcobjS4RTJKuj89xgYYZS kThFQTgIJMJl+ZfwIukg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVn8-00F8mn-2i; Thu, 02 Feb 2023 09:22:02 +0000 Received: from m126.mail.126.com ([220.181.12.35]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVn4-00F8jh-Vf for opensbi@lists.infradead.org; Thu, 02 Feb 2023 09:22:00 +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=S+eih A8mOrUkkibyr1ABpfbeiBw5nUrOEl74nNiGN+g=; b=b0JP18fkbOHwYBZLvkkj3 xcIlkOghIry7pcqc+UNk5VRSUDtBxbX8m/HDero0aCyI9xExT8wLRZsIfioEraIv N0BDDYq93Q5W+EdQjqYU7EPwJ3k3aY0vmvb4/2TKkYz6HRoV0jks4ddyGi/fI0tl i0UBmbnUUqHmE1YzYgHDfc= Received: from x390.lan (unknown [210.22.74.155]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wB3HlWiedtjeoctAg--.38219S3; Thu, 02 Feb 2023 16:51:47 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v4 1/4] lib: sbi: Optimize sbi_tlb Date: Thu, 2 Feb 2023 16:51:33 +0800 Message-Id: <20230202085136.224745-2-wxjstz@126.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202085136.224745-1-wxjstz@126.com> References: <20230202085136.224745-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3HlWiedtjeoctAg--.38219S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF1xKr1fAr4xuw47Zw4DXFb_yoW5Ar48pr W7tF1qyr4IqrW8K397Aa1DuF1fKrZ2yrW7Wr47t34rXF4DtF1rJr97Gr1jv3Z3Jr9xKw4Y y392yryfCF15Jr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziFAp5UUUUU= X-Originating-IP: [210.22.74.155] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1wYKOl53akfXOAABsL X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_012159_341827_A60A79DA X-CRM114-Status: GOOD ( 10.63 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.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: Originally, the process and sync of sbi_tlb need to wait for each other. Evasion by atomic addition and subtraction. Signed-off-by: Xiang W --- lib/sbi/sbi_tlb.c | 21 +++++++++++ 1 file changed, 11 insertions(+), 10 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [220.181.12.35 listed in wl.mailspike.net] 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 Originally, the process and sync of sbi_tlb need to wait for each other. Evasion by atomic addition and subtraction. Signed-off-by: Xiang W Reviewed-by: Anup Patel Tested-by: Anup Patel --- lib/sbi/sbi_tlb.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 4c142ea..8bab31a 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -215,7 +215,7 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo) { u32 rhartid; struct sbi_scratch *rscratch = NULL; - unsigned long *rtlb_sync = NULL; + atomic_t *rtlb_sync = NULL; tinfo->local_fn(tinfo); @@ -225,7 +225,7 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo) continue; rtlb_sync = sbi_scratch_offset_ptr(rscratch, tlb_sync_off); - while (atomic_raw_xchg_ulong(rtlb_sync, 1)) ; + atomic_sub_return(rtlb_sync, 1); } } @@ -257,10 +257,10 @@ static void tlb_process(struct sbi_scratch *scratch) static void tlb_sync(struct sbi_scratch *scratch) { - unsigned long *tlb_sync = + atomic_t *tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off); - while (!atomic_raw_xchg_ulong(tlb_sync, 0)) { + while (atomic_read(tlb_sync) > 0) { /* * While we are waiting for remote hart to set the sync, * consume fifo requests to avoid deadlock. @@ -343,6 +343,7 @@ static int tlb_update(struct sbi_scratch *scratch, u32 remote_hartid, void *data) { int ret; + atomic_t *tlb_sync; struct sbi_fifo *tlb_fifo_r; struct sbi_tlb_info *tinfo = data; u32 curr_hartid = current_hartid(); @@ -369,11 +370,8 @@ static int tlb_update(struct sbi_scratch *scratch, tlb_fifo_r = sbi_scratch_offset_ptr(remote_scratch, tlb_fifo_off); ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb); - if (ret != SBI_FIFO_UNCHANGED) { - return 1; - } - while (sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { + while (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { /** * For now, Busy loop until there is space in the fifo. * There may be case where target hart is also @@ -387,6 +385,9 @@ static int tlb_update(struct sbi_scratch *scratch, curr_hartid, remote_hartid); } + tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off); + atomic_add_return(tlb_sync, 1); + return 0; } @@ -413,7 +414,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) { int ret; void *tlb_mem; - unsigned long *tlb_sync; + atomic_t *tlb_sync; struct sbi_fifo *tlb_q; const struct sbi_platform *plat = sbi_platform_ptr(scratch); @@ -455,7 +456,7 @@ int sbi_tlb_init(struct sbi_scratch *scratch, bool cold_boot) tlb_q = sbi_scratch_offset_ptr(scratch, tlb_fifo_off); tlb_mem = sbi_scratch_offset_ptr(scratch, tlb_fifo_mem_off); - *tlb_sync = 0; + tlb_sync->counter = 0; sbi_fifo_init(tlb_q, tlb_mem, SBI_TLB_FIFO_NUM_ENTRIES, SBI_TLB_INFO_SIZE); From patchwork Thu Feb 2 08:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1736181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=b4dy4eg0; 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=qQj15U+v; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6tbZ2spyz23kt for ; Thu, 2 Feb 2023 20:22:18 +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: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=kmwspJIdit3dbjhACy0ffTxLZUcnkfts5F5z0e8ndQU=; b=b4dy4eg0cDyy1q fbsL+E+p1/DJJ0JOExL6hj25HwhRZ9uSs7TTJ3RyV/KR1XHEmVYk7O+uD9QsvEE42YMoJmxcvAR96 7nuKnWo7mnDfgoWeQzW+sBy0gZS3McPxNAaqJNOiDnk1CXz+u0irDNJZK6NcHcgBwVgWqUfHrHiJl qsUWWW/O/Ds3EKE8rX8I6EUbwy/6WFIq4Ql6TuXkPGCb9M+kew+OYckFwqKRN0vKYJeDK8HQGSbCl iI9pJ7tVVUlPrfoj60802aruZ1uE5ayOxaAlLt48NI8NkuEgwnC0N492Z0ySuUJ4PctgK+EaYmTkV wCNTdOZPwUODGVbrmI/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVnA-00F8nc-Ft; Thu, 02 Feb 2023 09:22:04 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVn6-00F8le-NA for opensbi@lists.infradead.org; Thu, 02 Feb 2023 09:22:02 +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=bhdtG w8Wie9Dupk0mlkP2hkMsoNoGRcY6Fk6hoXRPUw=; b=qQj15U+vVAutk46DD7lBG Yvlm4kL3mMCti3n4HpP3qc4w4IyYyQeW1QXgkDzPMRLGMyleN1s1woTnFWYwdUAj vTeeUKpNPFYsuCl5X7Mx3tJroqOWJm28CJ5Xhsw4f7WCnlQcLZVQaTXX7Y/DkEnE Ano4y8Yo7fb1rXkv4iTu0Q= Received: from x390.lan (unknown [210.22.74.155]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wB3HlWiedtjeoctAg--.38219S4; Thu, 02 Feb 2023 16:51:47 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v4 2/4] lib: sbi: Optimize sbi_ipi Date: Thu, 2 Feb 2023 16:51:34 +0800 Message-Id: <20230202085136.224745-3-wxjstz@126.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202085136.224745-1-wxjstz@126.com> References: <20230202085136.224745-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3HlWiedtjeoctAg--.38219S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr13GFWfCF4fuFy8Xw4UXFb_yoW5JFyUpF yDWFZ0yw4IqryIqasxta1UZa15G3yvqr17WrW7K34xXr4UWFyrCF1fGr1Ut3W5GF9aqa4Y qw4qyryFkFyUArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRduciUUUUU= X-Originating-IP: [210.22.74.155] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1wgKOl53akfXRQAAs5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_012201_091695_DE4EFF97 X-CRM114-Status: GOOD ( 10.66 ) X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "bombadil.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: the original sbI_ipi will be processed by hart by hart, after optimization, send ipi first and finally wait together. Signed-off-by: Xiang W --- lib/sbi/sbi_ipi.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) Content analysis details: (1.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] 1.3 RCVD_IN_VALIDITY_RPBL RBL: Relay in Validity RPBL, https://senderscore.org/blocklistlookup/ [220.181.12.26 listed in bl.score.senderscore.com] -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 the original sbI_ipi will be processed by hart by hart, after optimization, send ipi first and finally wait together. Signed-off-by: Xiang W --- lib/sbi/sbi_ipi.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index 1bcc2e4..92a33bd 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -31,7 +31,7 @@ static unsigned long ipi_data_off; static const struct sbi_ipi_device *ipi_dev = NULL; static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX]; -static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid, +static int sbi_ipi_update(struct sbi_scratch *scratch, u32 remote_hartid, u32 event, void *data) { int ret; @@ -69,6 +69,18 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid, sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT); + return 0; +} + +static int sbi_ipi_sync(struct sbi_scratch *scratch, u32 event) +{ + const struct sbi_ipi_event_ops *ipi_ops; + + if ((SBI_IPI_EVENT_MAX <= event) || + !ipi_ops_array[event]) + return SBI_EINVAL; + ipi_ops = ipi_ops_array[event]; + if (ipi_ops->sync) ipi_ops->sync(scratch); @@ -83,7 +95,7 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid, int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) { int rc; - ulong i, m; + ulong i, m, n; struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); @@ -92,19 +104,37 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) if (rc) return rc; m &= hmask; + n = m; - /* Send IPIs */ + /* update IPIs */ for (i = hbase; m; i++, m >>= 1) { if (m & 1UL) - sbi_ipi_send(scratch, i, event, data); + sbi_ipi_update(scratch, i, event, data); + } + + /* sync IPIs */ + m = n; + for (i = hbase; m; i++, m >>= 1) { + if (m & 1UL) + sbi_ipi_sync(scratch, event); } } else { + /* update IPIs */ + hbase = 0; + while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) { + for (i = hbase; m; i++, m >>= 1) { + if (m & 1UL) + sbi_ipi_update(scratch, i, event, data); + } + hbase += BITS_PER_LONG; + } + + /* sync IPIs */ hbase = 0; while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) { - /* Send IPIs */ for (i = hbase; m; i++, m >>= 1) { if (m & 1UL) - sbi_ipi_send(scratch, i, event, data); + sbi_ipi_sync(scratch, event); } hbase += BITS_PER_LONG; } From patchwork Thu Feb 2 08:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1736167 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=SdMiRdm1; 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=NEhj7aCY; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6swy6mDcz1yhq for ; Thu, 2 Feb 2023 19:52:18 +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: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=goTUd3iFX9iCgaphQ2NpcNH9XkUy8T+Qet6vPIW1m3k=; b=SdMiRdm1IfMYvP nAfQzvcpeM9EUtfMGmxJjiEoJmcgJ0p1RM3c62ouaoved3tFSXDepXoGMWD+8AeYrkr0xtCOJAl+a q1dqxuJD42yBh8PCtIY6KfeEbyFYQ1LjOxi/wmddW8eH4/qTkBiQdva/ShtvMyPw0DOOlxZirdHCJ z6bEeDwyI1IAjJ5WYbYwoYmMv1JcQYCQNAMwxMPqGVvpkoxtxPFCNwgn9OY2BXyLmxq9RJ5jEHDXW lLvnOU4XVwhuLTFQW+6RfeMC9p2SLty/U4eIuSoyyoqIAlAxX2hTQnLiombr7DCp5RsMZme+tgszi afOar6wqRABuawu81GHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVK4-00F2Qk-39; Thu, 02 Feb 2023 08:52:00 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVK1-00F2P8-7a for opensbi@lists.infradead.org; Thu, 02 Feb 2023 08:51:58 +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=aMvV/ 4Gcy33bpvPRxyeTxL1jRScB66uug634nMPYJPM=; b=NEhj7aCY8kmEQIurxvOud w1J/44tzi4PvPf+vlWfLcTpOCq68Q4Rk6vEgk721aiYr/m1mQXAILS41UsCXPtB/ BralRL48q3/Fbd5N2U84Rj4CoBu4pi9U7QbTvBB1WNBwLjkdvgg3bLvcdgMuKKgV 1W+PmkeVIfOZqGuJrWoqkE= Received: from x390.lan (unknown [210.22.74.155]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wB3HlWiedtjeoctAg--.38219S5; Thu, 02 Feb 2023 16:51:47 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v4 3/4] lib: sbi: rename function of sbi_ipi Date: Thu, 2 Feb 2023 16:51:35 +0800 Message-Id: <20230202085136.224745-4-wxjstz@126.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202085136.224745-1-wxjstz@126.com> References: <20230202085136.224745-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3HlWiedtjeoctAg--.38219S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7tr43Jw17JFyUArWfur43Awb_yoW8trW3pF y3AFnFkr4xtryUK39rAw40gr93Gr4vqFZ7urW7KasYqF4DArn8tF93Jw1jyr95Jr9akw1a vwsFvr48CF12qrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UhZ2fUUUUU= X-Originating-IP: [210.22.74.155] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1wgKOl53akfXRQABs4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_005157_607925_7B8A89B7 X-CRM114-Status: GOOD ( 10.63 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.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: Renamed some functions and reused some code Signed-off-by: Xiang W --- lib/sbi/sbi_tlb.c | 27 ++++++++++ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 8bab31a..741f4bb 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -211,7 +211,7 @@ static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 Renamed some functions and reused some code Signed-off-by: Xiang W --- lib/sbi/sbi_tlb.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 8bab31a..741f4bb 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -211,7 +211,7 @@ static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data) sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT); } -static void tlb_entry_process(struct sbi_tlb_info *tinfo) +static void tlb_process_helper(struct sbi_tlb_info *tinfo) { u32 rhartid; struct sbi_scratch *rscratch = NULL; @@ -229,30 +229,23 @@ static void tlb_entry_process(struct sbi_tlb_info *tinfo) } } -static void tlb_process_count(struct sbi_scratch *scratch, int count) +static int tlb_process_once(struct sbi_scratch *scratch) { struct sbi_tlb_info tinfo; - unsigned int deq_count = 0; struct sbi_fifo *tlb_fifo = sbi_scratch_offset_ptr(scratch, tlb_fifo_off); - while (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) { - tlb_entry_process(&tinfo); - deq_count++; - if (deq_count > count) - break; - + if (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) { + tlb_process_helper(&tinfo); + return 0; } + + return -1; } static void tlb_process(struct sbi_scratch *scratch) { - struct sbi_tlb_info tinfo; - struct sbi_fifo *tlb_fifo = - sbi_scratch_offset_ptr(scratch, tlb_fifo_off); - - while (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) - tlb_entry_process(&tinfo); + while (!tlb_process_once(scratch)); } static void tlb_sync(struct sbi_scratch *scratch) @@ -265,7 +258,7 @@ static void tlb_sync(struct sbi_scratch *scratch) * While we are waiting for remote hart to set the sync, * consume fifo requests to avoid deadlock. */ - tlb_process_count(scratch, 1); + tlb_process_once(scratch); } return; @@ -380,7 +373,7 @@ static int tlb_update(struct sbi_scratch *scratch, * TODO: Introduce a wait/wakeup event mechanism to handle * this properly. */ - tlb_process_count(scratch, 1); + tlb_process_once(scratch); sbi_dprintf("hart%d: hart%d tlb fifo full\n", curr_hartid, remote_hartid); } From patchwork Thu Feb 2 08:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1736184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=ZBWY5XpR; 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=JC8arqI+; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P6tbZ58cDz23pg for ; Thu, 2 Feb 2023 20:22:18 +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: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=YZAXj/OKqzJEntcMWrnY+bnSMe6gT/UZqaj5RjYwdCM=; b=ZBWY5XpRSR/r2u j9d65NjNn8C47e3/dWQDitwxK+nkFqiUldK8BMhoWJZOCOlw2oIAEV/DpCFpub7iPkPhPC1pZCSvl bOAcSgZENfcP9x/wK0yxl7uwJk2G2gpROC97hezNE4xOINM/vJhG92DA1NmDbbs5oqCwXb5NbAoYY 7TzvE/Ordt3q4dg4TRs0vRwX6+WYoxEFpkSBezO/MuC4kJXkuisDAnJuTvfOm5taFYxUidAkBQChs 46XFWqx/su9M9YOrvVSrKF3fxmbNHS81HFsEhxE8qFcfVUntWBdTvP3SNB7rt/GLzXpHBmNiKlJVj Xe1u1qeHrKkmlMBImX8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVn9-00F8nR-QY; Thu, 02 Feb 2023 09:22:03 +0000 Received: from m126.mail.126.com ([220.181.12.29]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNVn6-00F8lX-Ed for opensbi@lists.infradead.org; Thu, 02 Feb 2023 09:22:02 +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=LMBHr 2rF24lHUz1XrIUihXd48Q9fWd+ohm+xYiGnioQ=; b=JC8arqI+62Y6iJhEXWEw2 lvIhh8PhqMlSxUp6nQ0co+8ujfol/IfOc0EZ1UE4ZxVVuAXnXEk/zkcID7Al2tMc IMKyTsJw+wV80P/Ac1nHFN8+KnPHMXdFZyHFW56FLGIBni+XaAtNYLm6G8VH1i5d aI4HyYJoMrnhEIP7IwhUU4= Received: from x390.lan (unknown [210.22.74.155]) by zwqz-smtp-mta-g2-1 (Coremail) with SMTP id _____wB3HlWiedtjeoctAg--.38219S6; Thu, 02 Feb 2023 16:51:47 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v4 4/4] lib: sbi: Optimize sbi_tlb queue waiting Date: Thu, 2 Feb 2023 16:51:36 +0800 Message-Id: <20230202085136.224745-5-wxjstz@126.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202085136.224745-1-wxjstz@126.com> References: <20230202085136.224745-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wB3HlWiedtjeoctAg--.38219S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxGrWDCF47Gw1rurWxur1UAwb_yoWrJF4fpF 9xCFnFyw4IqFyxWr9rGa1UWa1fG39YqrsrWryxGryFqryj93WrXr4xGr10yay5GFZ3tas0 kwsFvr4F9F1UZF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRuBTOUUUUU= X-Originating-IP: [210.22.74.155] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFwYKOlpEFqS-sgABsB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_012200_819116_CE90AC2F X-CRM114-Status: GOOD ( 15.61 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.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: When tlb_fifo is full, it will wait and affect the ipi update to other harts. This patch is optimized. Signed-off-by: Xiang W --- include/sbi/sbi_ipi.h | 3 +++ lib/sbi/sbi_ipi.c | 47 +++++++++++++++++++++ lib/sbi/sbi_tlb.c | 3 ++- 3 files changed, 28 insertions(+), 25 deletions( [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 When tlb_fifo is full, it will wait and affect the ipi update to other harts. This patch is optimized. Signed-off-by: Xiang W --- include/sbi/sbi_ipi.h | 3 +++ lib/sbi/sbi_ipi.c | 47 +++++++++++++++++++++---------------------- lib/sbi/sbi_tlb.c | 3 ++- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h index f6ac807..aad7f77 100644 --- a/include/sbi/sbi_ipi.h +++ b/include/sbi/sbi_ipi.h @@ -41,6 +41,9 @@ struct sbi_ipi_event_ops { * Update callback to save/enqueue data for remote HART * Note: This is an optional callback and it is called just before * triggering IPI to remote HART. + * @return 0 success + * @return -1 break IPI, done on local hart + * @return -2 need retry */ int (* update)(struct sbi_scratch *scratch, struct sbi_scratch *remote_scratch, diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index 92a33bd..3282aaa 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -53,7 +53,7 @@ static int sbi_ipi_update(struct sbi_scratch *scratch, u32 remote_hartid, if (ipi_ops->update) { ret = ipi_ops->update(scratch, remote_scratch, remote_hartid, data); - if (ret < 0) + if (ret != 0) return ret; } @@ -94,51 +94,50 @@ static int sbi_ipi_sync(struct sbi_scratch *scratch, u32 event) */ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) { - int rc; - ulong i, m, n; + int rc, done; + ulong i, m; + struct sbi_hartmask target_mask = {0}; + struct sbi_hartmask retry_mask = {0}; struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + /* find target harts */ if (hbase != -1UL) { rc = sbi_hsm_hart_interruptible_mask(dom, hbase, &m); if (rc) return rc; m &= hmask; - n = m; - /* update IPIs */ for (i = hbase; m; i++, m >>= 1) { if (m & 1UL) - sbi_ipi_update(scratch, i, event, data); - } - - /* sync IPIs */ - m = n; - for (i = hbase; m; i++, m >>= 1) { - if (m & 1UL) - sbi_ipi_sync(scratch, event); + sbi_hartmask_set_hart(i, &target_mask); } } else { - /* update IPIs */ hbase = 0; while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) { for (i = hbase; m; i++, m >>= 1) { if (m & 1UL) - sbi_ipi_update(scratch, i, event, data); + sbi_hartmask_set_hart(i, &target_mask); } hbase += BITS_PER_LONG; } + } - /* sync IPIs */ - hbase = 0; - while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) { - for (i = hbase; m; i++, m >>= 1) { - if (m & 1UL) - sbi_ipi_sync(scratch, event); - } - hbase += BITS_PER_LONG; + /* update IPIs */ + retry_mask = target_mask; + do { + done = true; + sbi_hartmask_for_each_hart(i, &retry_mask) { + rc = sbi_ipi_update(scratch, i, event, data); + if (rc == -2) + done = false; + else + sbi_hartmask_clear_hart(i, &retry_mask); } - } + } while (!done); + + /* sync IPIs */ + sbi_ipi_sync(scratch, event); return 0; } diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 741f4bb..1be2058 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -364,7 +364,7 @@ static int tlb_update(struct sbi_scratch *scratch, ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb); - while (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { + if (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { /** * For now, Busy loop until there is space in the fifo. * There may be case where target hart is also @@ -376,6 +376,7 @@ static int tlb_update(struct sbi_scratch *scratch, tlb_process_once(scratch); sbi_dprintf("hart%d: hart%d tlb fifo full\n", curr_hartid, remote_hartid); + return -2; } tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off);