[RFC PATCH 1/5] lib: sbi: Preserve stimecmp across domain switches
whensun
theodoruswensanfebruanto025 at gmail.com
Thu Oct 22 19:43:41 PDT 2026
From: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
The Sstc extension provides a supervisor timer comparison register.
Without preserving this value, another domain can replace the
previous domain's timer deadline.
Keep a per-domain timer comparison value and initialize new domains
to a future deadline to avoid immediate timer interrupts.
Link: https://github.com/riscv-software-src/opensbi/issues/433
Signed-off-by: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
---
lib/sbi/sbi_domain_context.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 0861d541..26980658 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -50,6 +50,8 @@ struct hart_context {
unsigned long senvcfg;
/** Supervisor resource management configuration register */
unsigned long srmcfg;
+ /** Supervisor timer comparison register */
+ u64 stimecmp;
/** Float context state */
struct sbi_fp_context fp_ctx;
@@ -145,6 +147,8 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
ctx->srmcfg = csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
+ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSTC))
+ ctx->stimecmp = csr_swap64(CSR_STIMECMP, dom_ctx->stimecmp);
/* Eager context switch for float */
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||
@@ -206,6 +210,8 @@ static int hart_context_init(u32 hartindex)
if (!ctx)
return SBI_ENOMEM;
+ ctx->stimecmp = ~0ULL;
+
if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(),
SBI_HART_EXT_V)) {
vec_size = sbi_vector_context_size();
--
2.43.0
More information about the opensbi
mailing list