xen/riscv: add vtimer context switch helpers

Introduce vtimer_ctxt_switch_from() and vtimer_ctxt_switch_to() to handle
virtual timer state across vCPU context switches.

At present, vtimer_ctxt_switch_from() is a no-op because the RISC-V SSTC
extension, which provides a virtualization-aware timer, is not yet
supported. Xen therefore relies the virtual (SBI-based) timer.

The virtual timer uses Xen's internal timer infrastructure and must be
associated with the pCPU on which the vCPU is currently running so that
timer events can be delivered efficiently. As a result, vtimer_ctxt_switch_to()
migrates the timer to the target pCPU when a vCPU is scheduled in.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Oleksii Kurochko authored and Jan Beulich committed 2026-03-10 09:26:24 +01:00
1 parent d81a91b0e4
commit 4313feae90
2 files changed
+18

No files matched your search

+3
View File
@@ -14,4 +14,7 @@ void vcpu_timer_destroy(struct vcpu *v);
void vtimer_set_timer(struct vtimer *t, uint64_t ticks);
void vtimer_ctxt_switch_from(struct vcpu *p);
void vtimer_ctxt_switch_to(struct vcpu *n);
#endif /* ASM__RISCV__VTIMER_H */
+15
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <xen/bug.h>
#include <xen/sched.h>
#include <xen/timer.h>
@@ -69,3 +70,17 @@ void vtimer_set_timer(struct vtimer *t, const uint64_t ticks)
migrate_timer(&t->timer, smp_processor_id());
set_timer(&t->timer, expires);
}
void vtimer_ctxt_switch_from(struct vcpu *p)
{
ASSERT(!is_idle_vcpu(p));
/* Nothing to do at the moment as SSTC isn't supported now. */
}
void vtimer_ctxt_switch_to(struct vcpu *n)
{
ASSERT(!is_idle_vcpu(n));
migrate_timer(&n->arch.vtimer.timer, n->processor);
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.