Skip to content

Commit 8a411b0

Browse files
christofferdall-armMarc Zyngier
authored andcommitted
KVM: arm/arm64: Remove arch timer workqueue
The use of a work queue in the hrtimer expire function for the bg_timer is a leftover from the time when we would inject interrupts when the bg_timer expired. Since we are no longer doing that, we can instead call kvm_vcpu_wake_up() directly from the hrtimer function and remove all workqueue functionality from the arch timer code. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 71a7e47 commit 8a411b0

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

include/kvm/arm_arch_timer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <linux/clocksource.h>
2323
#include <linux/hrtimer.h>
24-
#include <linux/workqueue.h>
2524

2625
struct arch_timer_context {
2726
/* Registers: control register, timer value */
@@ -52,9 +51,6 @@ struct arch_timer_cpu {
5251
/* Background timer used when the guest is not running */
5352
struct hrtimer bg_timer;
5453

55-
/* Work queued with the above timer expires */
56-
struct work_struct expired;
57-
5854
/* Physical timer emulation */
5955
struct hrtimer phys_timer;
6056

virt/kvm/arm/arch_timer.c

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ static void soft_timer_start(struct hrtimer *hrt, u64 ns)
7070
HRTIMER_MODE_ABS);
7171
}
7272

73-
static void soft_timer_cancel(struct hrtimer *hrt, struct work_struct *work)
73+
static void soft_timer_cancel(struct hrtimer *hrt)
7474
{
7575
hrtimer_cancel(hrt);
76-
if (work)
77-
cancel_work_sync(work);
7876
}
7977

8078
static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
@@ -102,23 +100,6 @@ static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
102100
return IRQ_HANDLED;
103101
}
104102

105-
/*
106-
* Work function for handling the backup timer that we schedule when a vcpu is
107-
* no longer running, but had a timer programmed to fire in the future.
108-
*/
109-
static void kvm_timer_inject_irq_work(struct work_struct *work)
110-
{
111-
struct kvm_vcpu *vcpu;
112-
113-
vcpu = container_of(work, struct kvm_vcpu, arch.timer_cpu.expired);
114-
115-
/*
116-
* If the vcpu is blocked we want to wake it up so that it will see
117-
* the timer has expired when entering the guest.
118-
*/
119-
kvm_vcpu_wake_up(vcpu);
120-
}
121-
122103
static u64 kvm_timer_compute_delta(struct arch_timer_context *timer_ctx)
123104
{
124105
u64 cval, now;
@@ -188,7 +169,7 @@ static enum hrtimer_restart kvm_bg_timer_expire(struct hrtimer *hrt)
188169
return HRTIMER_RESTART;
189170
}
190171

191-
schedule_work(&timer->expired);
172+
kvm_vcpu_wake_up(vcpu);
192173
return HRTIMER_NORESTART;
193174
}
194175

@@ -300,7 +281,7 @@ static void phys_timer_emulate(struct kvm_vcpu *vcpu)
300281
* then we also don't need a soft timer.
301282
*/
302283
if (kvm_timer_should_fire(ptimer) || !kvm_timer_irq_can_fire(ptimer)) {
303-
soft_timer_cancel(&timer->phys_timer, NULL);
284+
soft_timer_cancel(&timer->phys_timer);
304285
return;
305286
}
306287

@@ -426,7 +407,7 @@ void kvm_timer_unschedule(struct kvm_vcpu *vcpu)
426407

427408
vtimer_restore_state(vcpu);
428409

429-
soft_timer_cancel(&timer->bg_timer, &timer->expired);
410+
soft_timer_cancel(&timer->bg_timer);
430411
}
431412

432413
static void set_cntvoff(u64 cntvoff)
@@ -544,7 +525,7 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)
544525
* In any case, we re-schedule the hrtimer for the physical timer when
545526
* coming back to the VCPU thread in kvm_timer_vcpu_load().
546527
*/
547-
soft_timer_cancel(&timer->phys_timer, NULL);
528+
soft_timer_cancel(&timer->phys_timer);
548529

549530
/*
550531
* The kernel may decide to run userspace after calling vcpu_put, so
@@ -637,7 +618,6 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
637618
update_vtimer_cntvoff(vcpu, kvm_phys_timer_read());
638619
vcpu_ptimer(vcpu)->cntvoff = 0;
639620

640-
INIT_WORK(&timer->expired, kvm_timer_inject_irq_work);
641621
hrtimer_init(&timer->bg_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
642622
timer->bg_timer.function = kvm_bg_timer_expire;
643623

@@ -794,8 +774,8 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
794774
struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
795775
struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
796776

797-
soft_timer_cancel(&timer->bg_timer, &timer->expired);
798-
soft_timer_cancel(&timer->phys_timer, NULL);
777+
soft_timer_cancel(&timer->bg_timer);
778+
soft_timer_cancel(&timer->phys_timer);
799779
kvm_vgic_unmap_phys_irq(vcpu, vtimer->irq.irq);
800780
}
801781

0 commit comments

Comments
 (0)