[RFC PATCH 1/5] lib: sbi: Preserve stimecmp across domain switches
Anup Patel
anup at brainfault.org
Thu Oct 22 22:52:29 PDT 2026
On Fri, Oct 23, 2026 at 8:14 AM whensun
<theodoruswensanfebruanto025 at gmail.com> wrote:
>
> 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;
When H-extension is available, we also have vstimecmp CSR which
needs to be preserved. Add vstimecmp state and move this PATCH
after the PATCH preserving H-extension state.
Also, better to create separate "struct hart_context_sstc" and use
it in struct hart_context.
>
> /** 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
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
Regards,
Anup
More information about the opensbi
mailing list