|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v3 08/16] xen/riscv: introduce basic vtimer infrastructure for guests
On 09.02.2026 17:52, Oleksii Kurochko wrote:
> @@ -105,11 +106,14 @@ int arch_vcpu_create(struct vcpu *v)
> if ( is_idle_vcpu(v) )
> return rc;
>
> + if ( (rc = vcpu_vtimer_init(v)) )
> + goto fail;
> +
> /*
> - * As the vtimer and interrupt controller (IC) are not yet implemented,
> + * As interrupt controller (IC) is not yet implemented,
> * return an error.
> *
> - * TODO: Drop this once the vtimer and IC are implemented.
> + * TODO: Drop this once IC is implemented.
> */
> rc = -EOPNOTSUPP;
> goto fail;
Shouldn't you then also call vcpu_vtimer_destroy() from arch_vcpu_destroy()?
> --- /dev/null
> +++ b/xen/arch/riscv/vtimer.c
> @@ -0,0 +1,71 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#include <xen/sched.h>
> +#include <xen/timer.h>
> +
> +#include <asm/vtimer.h>
> +
> +static void vtimer_expired(void *data)
> +{
> + struct vtimer *t = data;
> + struct vcpu *v = container_of(t, struct vcpu, arch.vtimer);
> +
> + vcpu_set_interrupt(v, IRQ_VS_TIMER);
> +}
> +
> +int vcpu_vtimer_init(struct vcpu *v)
> +{
> + struct vtimer *t = &v->arch.vtimer;
> +
> + init_timer(&t->timer, vtimer_expired, t, v->processor);
> +
> + return 0;
> +}
> +
> +void vcpu_timer_destroy(struct vcpu *v)
> +{
> + struct vtimer *t = &v->arch.vtimer;
> +
> + if ( t->timer.status == TIMER_STATUS_invalid )
> + return;
> +
> + kill_timer(&v->arch.vtimer.timer);
> +}
> +
> +void vtimer_set_timer(struct vtimer *t, const uint64_t ticks)
> +{
> + struct vcpu *v = container_of(t, struct vcpu, arch.vtimer);
> + s_time_t expires = ticks_to_ns(ticks - boot_clock_cycles);
> +
> + vcpu_unset_interrupt(v, IRQ_VS_TIMER);
> +
> + /*
> + * According to the RISC-V sbi spec:
> + * If the supervisor wishes to clear the timer interrupt without
> + * scheduling the next timer event, it can either request a timer
> + * interrupt infinitely far into the future (i.e., (uint64_t)-1),
> + * or it can instead mask the timer interrupt by clearing sie.STIE CSR
> + * bit.
> + */
> + if ( ticks == ((uint64_t)~0) )
Btw, such a cast doesn't further need parenthesizing.
Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |