From patchwork Tue Apr 11 04:56:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1767504 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=qv2h9Yzu; 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=k3wAqfF4; 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 4PwYWK2c3Bz1yb6 for ; Tue, 11 Apr 2023 14:58:00 +1000 (AEST) 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=T288T6JBQ7ST+0pO4Lm7Anz5CqTNx1WW7ZtD6Xzz7Eo=; b=qv2h9YzuRa6uSl 0yACBej6RoIhvoWdRFx/GEkTEZfOLb/ETata5+8skgW4qHE6mXL58Y1tw0GLaxDXXRIoNmlCvLQSW 2zqBeUxoO4rA+ex9hNsQ09zYA6/zRzARPKwct4laPIaXa/aC2m3p+4unKdFlR04bZn9u7cgD1tL8k 1nhBcdy513/3vy3Gtk5BGIyxuT8yOo90R8ojO8cO11eOJ/teBwEtO8VX6trACguXBCt8SF7Ivkt1D A9KBcg33Cxu+wlVs6GLU6ZNRUNlgB8FZSfpogaH1hkmdXFZ4GogdtCJEH7lce2pMBwVX3LXw8s/Dm b+d6tdGo76DkqoyF0t4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm64c-00GQ5U-0h; Tue, 11 Apr 2023 04:57:42 +0000 Received: from m126.mail.126.com ([220.181.12.37]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm64Y-00GQ3g-31 for opensbi@lists.infradead.org; Tue, 11 Apr 2023 04:57:40 +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=6f7jc 5/QRpAqoU7Q6MmcjwfNK5HMCYqnkm+ucf5ECsY=; b=k3wAqfF4dNvdx0PE+t/2B snBAoJR5RPk/1KEoKLGsSl2KJl7/uCK2lLYI8LLxsLUDvuERUZNEoSkf+3teGnGE dTH/cJ8eks2NrCt8WmkFMoYNTZetcoDeC6UbY/h2a0ISqnt9tuyiZni+5jqL9E2u YrMm1JeXR53SseFwn4skeU= Received: from x390.lan (unknown [58.247.140.64]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDX39uH6DRkw4GXBA--.8700S3; Tue, 11 Apr 2023 12:56:40 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v5 1/4] lib: sbi: Optimize sbi_tlb Date: Tue, 11 Apr 2023 12:56:18 +0800 Message-Id: <20230411045621.60331-2-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411045621.60331-1-wxjstz@126.com> References: <20230411045621.60331-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDX39uH6DRkw4GXBA--.8700S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF1xKr4UCF48GryUtry7Wrg_yoW5Aw4fpF W2yF1qyr4IqrW8K397Aa1DuF1fKrs2yrW7Wr47t34rXF4Dt3Z5Jr97Gr1jv3Z5JrZxKa1Y yws2yryxCF15Jr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEU73QUUUUU= X-Originating-IP: [58.247.140.64] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5AhOOlpEFnQIIQAAsN X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230410_215739_300736_8A4625EC X-CRM114-Status: GOOD ( 10.04 ) 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 Reviewed-by: Anup Patel Tested-by: Anup Patel --- 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 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..d950c45 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; + ATOMIC_INIT(tlb_sync, 0); sbi_fifo_init(tlb_q, tlb_mem, SBI_TLB_FIFO_NUM_ENTRIES, SBI_TLB_INFO_SIZE); From patchwork Tue Apr 11 04:56:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1767503 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=pctMya27; 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=mQAHOci1; 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 4PwYWK1mNCz1yZZ for ; Tue, 11 Apr 2023 14:57:59 +1000 (AEST) 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=r0axTg/RqxbqHoU+iSFn8pMmGr/alv65qTMfvvXsei0=; b=pctMya27/DKe9Q ofmwjKWeqNX9X7xvAs4r8nq8kh+V3yUcox/50bcZt7zBnlI8ZNVSCXMCR5WlUYlaxabbnX9XnUsFb 1ohCcoMMP+aeig8sguKBAtbCIDf+HZO4jwhtNhawThf1UbBzbTcDUXFkxIlsXdJAtYGqZeMJQEbqf ImUYj2FIylkO6pC505w3zOIfvea194CoRIDbAlMUaheIsTIPY4iUohIp83DIVzAe7ryF84bZtAFu7 uy3rkAv7SlakT0mtj8o2/rwtaefS8pSU3/7Ob0LH4K8IczoYWoDFs7gZ1cb2Mhia+24UL3cdHgymZ w4lumpzkTQS0jaK/QzgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm64b-00GQ5C-2Y; Tue, 11 Apr 2023 04:57:41 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm64Y-00GQ45-30 for opensbi@lists.infradead.org; Tue, 11 Apr 2023 04:57:40 +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=VSq37 vy6+RdniruaKD0jj+qpzCalGiEfosoCQ/CU4uw=; b=mQAHOci15EcI/P6gx8DS2 xExmiOUO/1EJpROi729XHzN60UaMNKGdrmqRpZ3kxFTuI+o6aG7awfrZ+r98nSMC BcZ0h43BuAe1KIYhc2ivWWSHSJfLoFaiyiQuk13D0r9drTrRlEKh28iKVKyUGHzE Zb2caW7x+5OTh9rwbAfc/8= Received: from x390.lan (unknown [58.247.140.64]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDX39uH6DRkw4GXBA--.8700S4; Tue, 11 Apr 2023 12:56:40 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v5 2/4] lib: sbi: Optimize sbi_ipi Date: Tue, 11 Apr 2023 12:56:19 +0800 Message-Id: <20230411045621.60331-3-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411045621.60331-1-wxjstz@126.com> References: <20230411045621.60331-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDX39uH6DRkw4GXBA--.8700S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr13Gr48uw4xAr4DZw4UCFg_yoW8ZFy3pF 1DGFZ0yws2qryxXasxJa1UZF45G3y0qr17WrW7G3s2qr45WFyrCF4fGw1Ut3W5GF9aqa4Y qw4vvryFkF1UZ3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziyCJPUUUUU= X-Originating-IP: [58.247.140.64] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi1whOOl53a9h70wAAsZ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230410_215739_300985_77B9E30A X-CRM114-Status: UNSURE ( 8.67 ) X-CRM114-Notice: Please train this message. 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: 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 | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 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.26 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 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 Reviewed-by: Anup Patel Tested-by: Anup Patel --- lib/sbi/sbi_ipi.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index b9f6205..33bff7a 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -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,22 +104,40 @@ 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); } + + /* 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)) { - /* Send IPIs */ for (i = hbase; m; i++, m >>= 1) { if (m & 1UL) sbi_ipi_send(scratch, i, event, data); } 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; + } } return 0; From patchwork Tue Apr 11 04:56:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1767506 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=zUusY4RP; 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=osIE6z0o; 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 4PwYX3146dz1yZZ for ; Tue, 11 Apr 2023 14:58:43 +1000 (AEST) 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=CgdHC1IHwNeiB/3UpZr+O5yIKsupVcW7tYSDithW7S4=; b=zUusY4RP+KKHn6 eLbMJbkAH/1okRsoitQnosLyoWwa+1vLHvhhZ2HcRLsrNJ3rWn4DJE44fBt3ftFMcY8SAFh9AMIFO 9a2B54c327ZLd1Rl1XpbRhuTIZm3TESUsK/gaWDoVKPAUTCCouEAaeZMDSYEE+Ri9xTenaMOOzUwu qbUffUVfcUuT+bPw7x5l5DVsJxro3B6nl0CbEJ4GqKAktwbgEtGuAXhxsWi7L6BWp5wEo2Mz4AP72 t7BUNia9pWR45tUbZMdwpMMVm34VRQYx7WlK9lak4OQGflzYWpbdzaHstHGsN4XpaVcGKL6jeR8gx IqLZGlFkprHeRD5YL08g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm65P-00GQHd-0A; Tue, 11 Apr 2023 04:58:31 +0000 Received: from m126.mail.126.com ([220.181.12.28]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm65M-00GQG7-0p for opensbi@lists.infradead.org; Tue, 11 Apr 2023 04:58:29 +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=eAgcw 5jfLwH2yzjayFVdW4oS+JaAM3O+AAQL7lv3T20=; b=osIE6z0oxy68+pLormUNw B+RSiSnpmFdd9er/oTMylmfghxgXEy+S9xFRc1O3pg5AC4cdfasVIA4LHiRDhBP0 nBcG0FbuhqHnFSld2BYM903mVh7qfX9b8P3UC3zKf+T5iQxhyP77vk2OfUZjMeH+ iElaYWm6hBJAKquZpq+eME= Received: from x390.lan (unknown [58.247.140.64]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDX39uH6DRkw4GXBA--.8700S5; Tue, 11 Apr 2023 12:56:40 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v5 3/4] sbi: tlb: Simplify to tlb_process_count/tlb_process function Date: Tue, 11 Apr 2023 12:56:20 +0800 Message-Id: <20230411045621.60331-4-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411045621.60331-1-wxjstz@126.com> References: <20230411045621.60331-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDX39uH6DRkw4GXBA--.8700S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFWkWFy7Gr47XrWrKryxGrg_yoW8Zr1rpF 9xAFnFyr48K34Ut397Jw4xWryfGr4vyFZ29ry7K3sYqF4DAF15tr93Jw1jyF95Jr9akw4Y qwsFvrWxCF17XrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR9Xo7UUUUU= X-Originating-IP: [58.247.140.64] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFwhOOlpEGDWKbQAAs- X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230410_215828_611458_350C4600 X-CRM114-Status: UNSURE ( 9.70 ) X-CRM114-Notice: Please train this message. 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: tlb_process_count is only used when count=1, so refactor to tlb_process_once and add the return value to be reused in tlb_process Signed-off-by: Xiang W --- lib/sbi/sbi_tlb.c | 23 ++++++++ 1 file changed, 8 insertions(+), 15 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.28 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 tlb_process_count is only used when count=1, so refactor to tlb_process_once and add the return value to be reused in tlb_process Signed-off-by: Xiang W Reviewed-by: Anup Patel Tested-by: Anup Patel --- lib/sbi/sbi_tlb.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index d950c45..60ca8c6 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -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 bool 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)) { + if (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) { tlb_entry_process(&tinfo); - deq_count++; - if (deq_count > count) - break; - + return true; } + + return false; } 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 Tue Apr 11 04:56:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1767502 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=pSfURu0a; 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=VYB4jB81; 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 4PwYWK36qRz1ybF for ; Tue, 11 Apr 2023 14:58:02 +1000 (AEST) 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=dGFNm1CX7FcmRE09U40zlDcjG+iEH7+erJEDpT7yqVo=; b=pSfURu0aOg+2w0 ah2oOaw+4AClqpf9Dqd5ZKxujlIkyjumb/V3Z15qIVjdDPqqtJiRpO6/sGIPYqfa12nRm9J1BKH95 w+13NqatJdDGYGpAK34/+AiM5M9GPL3j6jPgijzSSft+TENUtA/4O7jrgXakPIgwA438IndWIqv9C 28+cV9UJl2ANwGkBCGmKPYQy3Twhi3tVvl2vUtQEbi6eIZibOCsiCN/jD0iiTxWEAobBAo4pWAg9y nvmSc+K5ZqCsJ9LF7hcV19AzxP/WlTfzMmHlbHNSjlyAcPyNpSGkaM7MzzEIuTjixySITDgQqXNIe kFVpgxW/yhSv7/UhCbRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm64d-00GQ5k-2L; Tue, 11 Apr 2023 04:57:43 +0000 Received: from m126.mail.126.com ([220.181.12.37]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pm64Z-00GQ4E-1y for opensbi@lists.infradead.org; Tue, 11 Apr 2023 04:57:41 +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=p8ySc il8HGvHy5t2a7cXGk3e9zDiDoqESVNKEbVH3aU=; b=VYB4jB81dVkq3zxLa5g7m 92AyI1fTdPzxjDbJmPDyjQdoM/0PYfiKgv8M6R8qvuOMOVLj7lrmGwLpvY1JhJEq emCEMrF2TWh/qu/tKERz5Nq/ahabqf3Hv/7pjKliY0TpquICo31IWRHlh0O9Ox3o XFUaUsFem+8Sjr9HnyqmhU= Received: from x390.lan (unknown [58.247.140.64]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDX39uH6DRkw4GXBA--.8700S6; Tue, 11 Apr 2023 12:56:40 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W , anup@brainfault.org Subject: [PATCH v5 4/4] lib: sbi: Optimize sbi_tlb queue waiting Date: Tue, 11 Apr 2023 12:56:21 +0800 Message-Id: <20230411045621.60331-5-wxjstz@126.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411045621.60331-1-wxjstz@126.com> References: <20230411045621.60331-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wDX39uH6DRkw4GXBA--.8700S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFWxJF4fCryxKrW5uryDWrg_yoWrJFWxpF 9xAFnFyw4IvFyxXr9rCa1UWF4fG39Yqr47W34xGryFqrWj9FyrWr1xGr10ya4rJFWftas0 9wsFyr4F9F1UZF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziQJ57UUUUU= X-Originating-IP: [58.247.140.64] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbi5AtOOlpEFnQILwAAsA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230410_215739_968948_F309E552 X-CRM114-Status: GOOD ( 14.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 | 46 +++++++++++++++++++++ lib/sbi/sbi_tlb.c | 3 ++- 3 files changed, 28 insertions(+), 24 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 | 46 +++++++++++++++++++++---------------------- lib/sbi/sbi_tlb.c | 3 ++- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h index f384e74..5511d50 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 33bff7a..11512d1 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -53,7 +53,7 @@ static int sbi_ipi_send(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; } @@ -95,50 +95,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; + bool retry_needed; + 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_send(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_send(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 { + retry_needed = false; + sbi_hartmask_for_each_hart(i, &retry_mask) { + rc = sbi_ipi_send(scratch, i, event, data); + if (rc == -2) + retry_needed = true; + else + sbi_hartmask_clear_hart(i, &retry_mask); } - } + } while (retry_needed); + + /* sync IPIs */ + sbi_ipi_sync(scratch, event); return 0; } diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 60ca8c6..248997e 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);