From: Chao-ying Fu <icebergfu@gmail.com>
To: opensbi@lists.infradead.org
Subject: [PATCH] Align the scratch allocation to 64 bytes
Date: Thu, 9 Jan 2025 16:34:50 -0800 [thread overview]
Message-ID: <20250110003451.2800-1-cfu@mips.com> (raw)
We increase 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/sbi_scratch.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_scratch.c b/lib/sbi/sbi_scratch.c
index ccbbc68..6b161bc 100644
--- a/lib/sbi/sbi_scratch.c
+++ b/lib/sbi/sbi_scratch.c
@@ -14,6 +14,9 @@
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_string.h>
+/* Minimum size and alignment of scratch allocations */
+#define SCRATCH_ALLOC_ALIGN 64
+
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 +73,12 @@ 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 64 bytes to avoid livelock on
+ * certain platforms due to atomic variables from the same cache line.
+ */
+ size += SCRATCH_ALLOC_ALIGN - 1;
+ size &= ~((unsigned long)SCRATCH_ALLOC_ALIGN - 1);
spin_lock(&extra_lock);
--
2.47.1
next reply other threads:[~2025-01-10 0:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 0:34 Chao-ying Fu [this message]
2025-01-10 4:15 ` [PATCH] Align the scratch allocation to 64 bytes Xiang W
2025-01-10 2:36 ` Chao-ying Fu
2025-01-19 20:04 ` [PATCH v2] We add a new configuration CONFIG_SBI_SCRATCH_ALLOC_ALIGNMENT as an int Raj Vishwanathan
2025-01-20 3:58 ` Xiang W
2025-01-20 18:56 ` [EXTERNAL]Re: " 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=20250110003451.2800-1-cfu@mips.com \
--to=icebergfu@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox