All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raj Vishwanathan <raj.vishwanathan@gmail.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v3] New configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT
Date: Mon, 27 Jan 2025 12:20:17 -0800	[thread overview]
Message-ID: <20250127202017.1043240-1-Raj.Vishwanathan@gmail.com> (raw)
In-Reply-To: <20250115234607.410148-1-Raj.Vishwanathan@gmail.com>

We add a new configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT as an int
If it is set to 0 or not defined, we will continue with the previous
defintion of allocating pointer size chunks. Otherwise we will use the
user specified size.
We use the scratch allocation alignment to 64 bytes or cacheline size,
to avoid two atomic variables from the same cache line causing livelock
on some platforms.

Signed-off-by: Raj Vishwanathan <Raj.Vishwanathan@gmail.com>
---

Changes in V2:
	Remove platform specific references to 64 bytes in the configuration

Changes in V3:
	Remove platform specific references in 64 bytes in the comments
---
 lib/sbi/Kconfig       |  7 +++++++
 lib/sbi/sbi_scratch.c | 14 ++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig
index c6cc04b..5f7eb70 100644
--- a/lib/sbi/Kconfig
+++ b/lib/sbi/Kconfig
@@ -69,4 +69,11 @@ config SBI_ECALL_SSE
 config SBI_ECALL_MPXY
 	bool "MPXY extension"
 	default y
+config SBI_SCRATCH_ALLOC_ALIGNMENT
+	int  "Scratch allocation alignment"
+	default 0
+	help
+	  We provide the option to customize the alignment to allocate from
+	  the extra space in sbi_scratch. Leave it 0 for default behaviour.
+
 endmenu
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index ccbbc68..0f1be58 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -14,6 +14,16 @@
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 
+/*
+ * We do the scratch allocation on the basis of a user configuration.
+ */
+#if !defined(CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT) || (CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT==0)
+#define SCRATCH_ALLOC_ALIGNMENT __SIZEOF_POINTER__
+#else
+#define SCRATCH_ALLOC_ALIGNMENT CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT
+#endif
+
+
 u32 last_hartindex_having_scratch = 0;
 u32 hartindex_to_hartid_table[SBI_HARTMASK_MAX_BITS + 1] = { -1U };
 struct sbi_scratch *hartindex_to_scratch_table[SBI_HARTMASK_MAX_BITS + 1] = { 0 };
@@ -70,8 +80,8 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size)
 	if (!size)
 		return 0;
 
-	size += __SIZEOF_POINTER__ - 1;
-	size &= ~((unsigned long)__SIZEOF_POINTER__ - 1);
+	size += SCRATCH_ALLOC_ALIGNMENT- 1;
+	size &= ~((unsigned long)SCRATCH_ALLOC_ALIGNMENT - 1);
 
 	spin_lock(&extra_lock);
 
-- 
2.43.0



  parent reply	other threads:[~2025-01-27 20:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-09 23:08 [PATCH] Work with hartid equal to or greater than SBI_HARTMASK_MAX_BITS Chao-ying Fu
2025-01-10  0:42 ` Inochi Amaoto
2025-01-10  1:20   ` Chao-ying Fu
2025-01-10  0:57 ` Jessica Clarke
2025-01-10  1:36   ` Chao-ying Fu
2025-01-15 23:46 ` [PATCH v2] " Raj Vishwanathan
2025-01-16  1:01   ` Xiang W
2025-01-21  1:12   ` [PATCH v3] " Raj Vishwanathan
2025-01-21  3:29     ` Xiang W
2025-01-22  0:42   ` Raj Vishwanathan
2025-02-11  4:51     ` Anup Patel
2025-01-27 20:20   ` Raj Vishwanathan [this message]
2025-01-28  4:36     ` [PATCH v3] New configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT Xiang W
2025-02-11  4:45     ` Anup Patel
2025-03-05  0:31       ` Raj Vishwanathan
2025-03-05  2:01         ` Samuel Holland
2025-03-09 14:44     ` [PATCH v4] Set the scratch allocation to alignment to cacheline size Raj Vishwanathan
2025-03-10  5:26       ` Xiang W
2025-03-13 17:53         ` Raj Vishwanathan
2025-03-14  1:31       ` Xiang W
2025-01-28 21:33   ` [PATCH v3] Check that hartid is within the SBI_HARTMASK_MAX_BITS Raj Vishwanathan
2025-01-29  9:07     ` Xiang W
2025-02-11 22:00   ` [PATCH v3] lib: utils:Check that hartid is valid Raj Vishwanathan
2025-02-12  4:01     ` Anup Patel
  -- strict thread matches above, loose matches on Subject: below --
2025-01-19 20:04 [PATCH v2] We add a new configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT as an int Raj Vishwanathan
2025-01-21  1:46 ` [PATCH v3] New configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT Raj Vishwanathan
2025-01-21  3:21   ` Xiang W
2025-01-21 22:55 ` Raj Vishwanathan
2025-01-24 23:26 ` Raj Vishwanathan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250127202017.1043240-1-Raj.Vishwanathan@gmail.com \
    --to=raj.vishwanathan@gmail.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.