From patchwork Fri Jul 5 07:15:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1957138 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=hNp6HzpU; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=ele+Rt0r; 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 4WFlCh34cRz1xpP for ; Fri, 5 Jul 2024 17:15:28 +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=zQIblk/OPjdAtvr3P3ha7An/DiRNxGRAUzYgj/czcfo=; b=hNp6HzpU8kgeqp JzD2bO+hFnLUDoYEWTIU3zr8WIigVjaqT/41zQVJlmLpwB2fHNdoy7j8bjneFU+p/Fyj3wAJGPmrJ EDxXF2a06+rgV1dRWcg85Y/49LC3BMoeZR75Hu71EvWSTYzKh6z6fK18xCG57RB7mWKSKaacZE+cb Yk8sAah//M9JCA7d6RaK8IQkUf8cHB8qyDuxAqPk8fV5Y9AHk3jTKGqT5PdaGQGTjhg4x72/kLLFl E5/6siVppKGqIXg6haG5EUOYBHRvw3ZIn5o6sKW0df/wlRyCrnLZEIoyqkuNlj5c7jP9nQsF0zmUy KfYqRdNkvofIsvgdfBdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdAA-0000000F81R-0EYv; Fri, 05 Jul 2024 07:15:22 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sPdA7-0000000F7zo-2EVL for opensbi@lists.infradead.org; Fri, 05 Jul 2024 07:15:20 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-70b07bdbfbcso537798b3a.0 for ; Fri, 05 Jul 2024 00:15:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1720163718; x=1720768518; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n0qXM7rcZ0FLoMAZcHAoGZKUEAWaxYXTxtvoo7TbKwE=; b=ele+Rt0rVTTbqArBTbrCEmIEgbg9lOggozeFQQ5iXm6EmR/5FNr+B8gzWM2Xa0/yUR tLi6tRfAWPzUeWulJ2I90BKA981HpbxO7Wh1KyFHISr6ZCEwAP6YlqDIROditJgRedAn ZC6UagIgGbryx24NSyjCGduHwSHcr3KAKT87wzPefvqCUMVY0z7/c2b4X2P3mknptRt5 yRSzhcM24VSR5llTNGgz66U7JXy2a7tgIkS0gl0yZd9W61iHVGN6sn42aq3TPPAqZKmF NMkVsGhdH0hJtDYPp44gpju9pZ0c1XHty1shtZmmawGTd8vBXOrQRdFdGsOZ2aZQ7DQb 5IWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720163718; x=1720768518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n0qXM7rcZ0FLoMAZcHAoGZKUEAWaxYXTxtvoo7TbKwE=; b=WQ+Wl8g1aGACe8veUyPKtdiDotZMkAbGW/n2Dr0i4MLb88IhZez9pjXd9sNyKI8e9R x9qygiU0oy2QWTDSJTuxyrKyd5vbOXwxfHYD5NPfTlUnHQotLJQ59Q9wp1Ot9GRediC9 nEIKeLt08dKdNaB2SaYT2OAc2vZxHx1TTm5z6ZmKP1q9UTxJmpCM95Oql/iklODWqCjI ATbYsIGaZJS5jZ9W8LD83to0uSG8tHT4WxeiWRQ0dri4+aRq47SWN9KfiIitLrusAsi0 fpkW5ujpikzLNnF3l/1HNSEZUF6u0csW/wqc0k3m4yOD+iSwYKrcz2xihcTP/uXNO9oi 6sJA== X-Forwarded-Encrypted: i=1; AJvYcCXDW7YFyyeQGTPS6wr6PY1R+lTG1LdE1PS4vx2N6YWCyBLycAtwrxCcJmXcHhJxbYBX50uQfXaWo2+b+Igi9UghI+xvf8I2IahWEEM= X-Gm-Message-State: AOJu0YzB1LBp1Jq3VRbQObAsHFEyqBuIRoc4w4HgeX58PqO3naQ1egsI vzBzKEqshYdXz/xfR3QnzOkq6SBbmX6EoyvWoliZMYquL4Ebu1A1oa14dN+fLOc51ysGZJdckOU l X-Google-Smtp-Source: AGHT+IHHBbpT30iQ08OR56MfGPC/8jxwnnJVhEw0ErnkoaKYf51wW29WWgbxICRyROPEhZzSUdrwsQ== X-Received: by 2002:a05:6a20:9718:b0:1af:f50f:cbe5 with SMTP id adf61e73a8af0-1c0cd194c0bmr4153053637.8.1720163718284; Fri, 05 Jul 2024 00:15:18 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([223.185.133.57]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-75e51aaf3f2sm2262658a12.15.2024.07.05.00.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:15:17 -0700 (PDT) From: Anup Patel To: Atish Patra Cc: Andrew Jones , Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 3/6] lib: sbi: Optimize fifo enqueue/dequeue for basic data types Date: Fri, 5 Jul 2024 12:45:01 +0530 Message-Id: <20240705071504.50988-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240705071504.50988-1-apatel@ventanamicro.com> References: <20240705071504.50988-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240705_001519_601244_C3EEEFAE X-CRM114-Status: UNSURE ( 8.96 ) 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: Don't use sbi_memcpy() for basic data types in fifo enqueue/dequeue instead use direct type-cast and assignment. Signed-off-by: Anup Patel --- lib/sbi/sbi_fifo.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:434 listed in] [list.dnswl.org] 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_EF Message has a valid DKIM or DK signature from envelope-from 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 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 Don't use sbi_memcpy() for basic data types in fifo enqueue/dequeue instead use direct type-cast and assignment. Signed-off-by: Anup Patel Reviewed-By: Himanshu Chauhan --- lib/sbi/sbi_fifo.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c index 72c6d39..9199a30 100644 --- a/lib/sbi/sbi_fifo.c +++ b/lib/sbi/sbi_fifo.c @@ -66,7 +66,26 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) if (head >= fifo->num_entries) head = head - fifo->num_entries; - sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size); + switch (fifo->entry_size) { + case 1: + *(char *)(fifo->queue + head * fifo->entry_size) = *(char *)data; + break; + case 2: + *(u16 *)(fifo->queue + head * fifo->entry_size) = *(u16 *)data; + break; + case 4: + *(u32 *)(fifo->queue + head * fifo->entry_size) = *(u32 *)data; + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)(fifo->queue + head * fifo->entry_size) = *(u64 *)data; + break; +#endif + default: + sbi_memcpy(fifo->queue + head * fifo->entry_size, + data, fifo->entry_size); + break; + } fifo->avail++; } @@ -184,8 +203,26 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data) return SBI_ENOENT; } - sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size, - fifo->entry_size); + switch (fifo->entry_size) { + case 1: + *(char *)data = *(char *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 2: + *(u16 *)data = *(u16 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 4: + *(u32 *)data = *(u32 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)data = *(u64 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#endif + default: + sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size, + fifo->entry_size); + break; + } fifo->avail--; fifo->tail++;