From patchwork Wed Feb 1 15:07:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1735673 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=hto29cDJ; 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=Igv4XEsv; 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 4P6QKl2srwz23jG for ; Thu, 2 Feb 2023 02:08:43 +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=0nPdGW8tu2jmNZPSCzhNIuDLD3HCviJXPEBVJJdCD5Y=; b=hto29cDJgbFQOM MQiy0PQUzKmcJyYeyVS0q9vw67BCX/MRQJpiIv5B9RVw9gJsrdZXF+p00cQC52eFPI1cYH7APxdth M3ep+TOEWz9lYBFrWdn6c4yuO9m/WGzmnCnTk/HUG+SRewUWzCa1nf4B3L5GSji5/5Jfnb6gTyrmR n4nQCDR7vY+PDoY4Bib4cqyMGP/vft7vwhdKI9IvQhCc6ZDhsDHK1e3dIn4hnUL03F7BFuM3MUlkg mH36zH0pZOE0VdE+znnOMKfDxA6gnHskeA/Vs0bZapL7QBBlFFBUVdKwIL5j0QVI08hJKXHUfYH1Z a5Qzu4IwXdiXj6djLbAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNEis-00CaKC-HS; Wed, 01 Feb 2023 15:08:30 +0000 Received: from m126.mail.126.com ([123.126.96.242]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNEin-00CaGi-An for opensbi@lists.infradead.org; Wed, 01 Feb 2023 15:08:27 +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=whoyh yBiUDVmpgyEwzch/1uPJWtUSDLEppNEjXE4L90=; b=Igv4XEsvVdz6RYDrbs7Wh 9Sy9D9kMGJsjUicdGH1TzkFQEw7I4gOTVubwz7i1sr0IhwLzLZWrTAcOXxFkiRuG ZRz43YkOKLbDqDGlrHxcmS3UVIUU3HrGjVlzszvUR4C16giHQSC6lMVMX5rmfCtc bT615pMAwh17QYLDInInhs= Received: from x390.lan (unknown [210.22.74.155]) by smtp14 (Coremail) with SMTP id fuRpCgDX3z9lgNpjT6g1Ag--.62276S6; Wed, 01 Feb 2023 23:08:22 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [PATCH v3 4/4] lib: sbi: Optimize sbi_tlb queue waiting Date: Wed, 1 Feb 2023 23:07:56 +0800 Message-Id: <20230201150756.161507-5-wxjstz@126.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201150756.161507-1-wxjstz@126.com> References: <20230201150756.161507-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: fuRpCgDX3z9lgNpjT6g1Ag--.62276S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxGrWDCF47Gw1rurWxur1UAwb_yoW5uF1UpF 9xAF9Fkw4IqFyIqr9rWw4UuF4fG3yvqr4DWryxGr9Yvry8uF1rWr4fGr10yay5XFWrtas0 9wsFvrWF9F1UZF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRAMa5UUUUU= X-Originating-IP: [210.22.74.155] X-CM-SenderInfo: pz0m23b26rjloofrz/1tbiFwcJOlpEFqBv5wAAsD X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_070825_851850_CD769645 X-CRM114-Status: GOOD ( 14.66 ) 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 | 43 ++++++++++++++++++++ lib/sbi/sbi_tlb.c | 3 ++- 3 files changed, 25 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 | 43 ++++++++++++++++++++----------------------- lib/sbi/sbi_tlb.c | 3 ++- 3 files changed, 25 insertions(+), 24 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..89c485e 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -94,8 +94,10 @@ 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(); @@ -104,41 +106,36 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) 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; + 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 c82f53a..673f948 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -367,7 +367,7 @@ static int tlb_update(struct sbi_scratch *scratch, return 1; } - while (sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { + if (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 @@ -379,6 +379,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);