All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Work with hartid equal to or greater than SBI_HARTMASK_MAX_BITS.
@ 2025-01-09 23:08 Chao-ying Fu
  2025-01-10  0:42 ` Inochi Amaoto
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Chao-ying Fu @ 2025-01-09 23:08 UTC (permalink / raw)
  To: opensbi

Some platforms use hartid that is equal to greater than SBI_HARTMASK_MAX_BITS,
so we should remove the check.
---
 lib/utils/fdt/fdt_domain.c  | 3 ---
 lib/utils/fdt/fdt_helper.c  | 9 ---------
 platform/generic/platform.c | 3 ---
 3 files changed, 15 deletions(-)

diff --git a/lib/utils/fdt/fdt_domain.c b/lib/utils/fdt/fdt_domain.c
index 4bc7ed8..6bc63c2 100644
--- a/lib/utils/fdt/fdt_domain.c
+++ b/lib/utils/fdt/fdt_domain.c
@@ -471,9 +471,6 @@ static int __fdt_parse_domain(const void *fdt, int domain_offset, void *opaque)
 		if (err)
 			continue;
 
-		if (SBI_HARTMASK_MAX_BITS <= val32)
-			continue;
-
 		if (!fdt_node_is_enabled(fdt, cpu_offset))
 			continue;
 
diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c
index cb350e5..aec08fa 100644
--- a/lib/utils/fdt/fdt_helper.c
+++ b/lib/utils/fdt/fdt_helper.c
@@ -1032,9 +1032,6 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,
 		if (rc)
 			continue;
 
-		if (SBI_HARTMASK_MAX_BITS <= hartid)
-			continue;
-
 		if (match_hwirq == hwirq) {
 			if (hartid < first_hartid)
 				first_hartid = hartid;
@@ -1097,9 +1094,6 @@ int fdt_parse_plmt_node(const void *fdt, int nodeoffset, unsigned long *plmt_bas
 		if (rc)
 			continue;
 
-		if (SBI_HARTMASK_MAX_BITS <= hartid)
-			continue;
-
 		if (hwirq == IRQ_M_TIMER)
 			hcount++;
 	}
@@ -1153,9 +1147,6 @@ int fdt_parse_plicsw_node(const void *fdt, int nodeoffset, unsigned long *plicsw
 		if (rc)
 			continue;
 
-		if (SBI_HARTMASK_MAX_BITS <= hartid)
-			continue;
-
 		if (hwirq == IRQ_M_SOFT)
 			hcount++;
 	}
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index c03ed88..331ff8e 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -200,9 +200,6 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
 		if (rc)
 			continue;
 
-		if (SBI_HARTMASK_MAX_BITS <= hartid)
-			continue;
-
 		if (!fdt_node_is_enabled(fdt, cpu_offset))
 			continue;
 
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 28+ messages in thread
* [PATCH v2] We add a new configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT as an int
@ 2025-01-19 20:04 Raj Vishwanathan
  2025-01-21  1:46 ` [PATCH v3] New configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT Raj Vishwanathan
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Raj Vishwanathan @ 2025-01-19 20:04 UTC (permalink / raw)
  To: opensbi

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
chacheline size of 64.
We have the option of increasing the scratch allocation alignment to 64 bytes
as the cache line size, to avoid two atomic variables from
the same cache line that may cause livelock on some platforms.
---
 lib/sbi/Kconfig       |  8 ++++++++
 lib/sbi/sbi_scratch.c | 18 ++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig
index c6cc04b..1ffa170 100644
--- a/lib/sbi/Kconfig
+++ b/lib/sbi/Kconfig
@@ -69,4 +69,12 @@ 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 for allocation alignment to 64 bytes to avoid 
+	  livelock on certain platforms due to atomic variables from the same 
+	  cache line.  Leave it 0 for default behaviour.
+
 endmenu
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index ccbbc68..88ea3c7 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -14,6 +14,13 @@
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 
+#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 +77,15 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size)
 	if (!size)
 		return 0;
 
-	size += __SIZEOF_POINTER__ - 1;
-	size &= ~((unsigned long)__SIZEOF_POINTER__ - 1);
+	/*
+	 * We let the allocation align to the cache line size, so
+	 * certain platforms due to atomic variables from the same cache line.
+	 * This ensures that the LR/SC variables are in a separate cache line 
+	 * to avoid live lock.
+	 */
+
+	size += SCRATCH_ALLOC_ALIGNMENT- 1;
+	size &= ~((unsigned long)SCRATCH_ALLOC_ALIGNMENT - 1);
 
 	spin_lock(&extra_lock);
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2025-03-14  1:31 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` [PATCH v3] New configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT Raj Vishwanathan
2025-01-28  4:36     ` 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

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.