SW timer is enabled when vcpu thread is scheduled out, and it is to wake up vcpu from blocked queue. If vcpu thread is scheduled out however is not blocked, such as it is preempted by other threads, it is not necessary to enable SW timer. Since vcpu thread is still on running queue and SW timer is only to wake up tasks on blocking queue, so SW timer is not useful in this situation. This patch enables SW timer only when vcpu is scheduled out and is blocking. Also when SW timer is expired, it only wakes up vcpu thread in blocking queue and need not restart SW timer. Bibo Mao (2): LoongArch: KVM: Start SW timer only when vcpu is blocking LoongArch: KVM: Do not restart SW timer when it is expired arch/loongarch/kvm/timer.c | 42 ++++++++------------------------------ 1 file changed, 9 insertions(+), 33 deletions(-) base-commit: 41bccc98fb7931d63d03f326a746ac4d429c1dd3 -- 2.39.3