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);