Skip to contentSkip to conversation

KVM: x86: Simplify kvm timer handler

PATCH Applied Jan Kiszka 3 participants 4 messages Sep 14, 2011 – Oct 19, 2011

Subsystems (3)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 KVM: x86: Simplify kvm timer handler

The vcpu reference of a kvm_timer can't become NULL while the timer is valid, so drop this redundant test. This also makes it pointless to carry a separate __kvm_timer_fn, fold it into kvm_timer_fn.

---
 arch/x86/kvm/timer.c |   26 ++++----------------------
 1 files changed, 4 insertions(+), 22 deletions(-)
arch/x86/kvm/timer.c +4 -22
index ae432ea..6b85cc6 100644
@@ -18,9 +18,10 @@
 #include <linux/atomic.h>
 #include "kvm_timer.h"
 
-static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
+enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
 {
-	int restart_timer = 0;
+	struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
+	struct kvm_vcpu *vcpu = ktimer->vcpu;
 	wait_queue_head_t *q = &vcpu->wq;
 
 	/*
@@ -40,26 +41,7 @@ static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
 
 	if (ktimer->t_ops->is_periodic(ktimer)) {
 		hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
-		restart_timer = 1;
-	}
-
-	return restart_timer;
-}
-
-enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
-{
-	int restart_timer;
-	struct kvm_vcpu *vcpu;
-	struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
-
-	vcpu = ktimer->vcpu;
-	if (!vcpu)
-		return HRTIMER_NORESTART;
-
-	restart_timer = __kvm_timer_fn(vcpu, ktimer);
-	if (restart_timer)
 		return HRTIMER_RESTART;
-	else
+	} else
 		return HRTIMER_NORESTART;
 }
-
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 44 lines · Jan Kiszka

The vcpu reference of a kvm_timer can't become NULL while the timer is valid, so drop this redundant test. This also makes it pointless to carry a separate __kvm_timer_fn, fold it into kvm_timer_fn.

---
 arch/x86/kvm/timer.c |   26 ++++----------------------
 1 files changed, 4 insertions(+), 22 deletions(-)
arch/x86/kvm/timer.c +3 -16
index ae432ea..6b85cc6 100644
@@ -18,9 +18,10 @@
 #include <linux/atomic.h>
 #include "kvm_timer.h"
 
-static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
+enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
 {
-	int restart_timer = 0;
+	struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
+	struct kvm_vcpu *vcpu = ktimer->vcpu;
 	wait_queue_head_t *q = &vcpu->wq;
 
 	/*
@@ -40,26 +41,7 @@ static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
 
 	if (ktimer->t_ops->is_periodic(ktimer)) {
 		hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
-		restart_timer = 1;
-	}
-
-	return restart_timer;
-}
-
-enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
-{
-	int restart_timer;
-	struct kvm_vcpu *vcpu;
-	struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
-
-	vcpu = ktimer->vcpu;
-	if (!vcpu)

arch/x86/kvm/timer.c static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer) · line 65

Quoted 10 lines
arch/x86/kvm/timer.c +1 -6
-		return HRTIMER_NORESTART;
-
-	restart_timer = __kvm_timer_fn(vcpu, ktimer);
-	if (restart_timer)
 		return HRTIMER_RESTART;
-	else
+	} else
 		return HRTIMER_NORESTART;
 }
-

Ping.

author
#2 lore raw
Quoted 24 lines · Jan Kiszka
Quoted 23 lines · Jan Kiszka

The vcpu reference of a kvm_timer can't become NULL while the timer is valid, so drop this redundant test. This also makes it pointless to carry a separate __kvm_timer_fn, fold it into kvm_timer_fn.

arch/x86/kvm/timer.c | 26 ++++---------------------- 1 files
changed, 4 insertions(+), 22 deletions(-)

arch/x86/kvm/timer.c index renamed from arch/x86/kvm/timer.c +0 -0

ae432ea..6b85cc6 100644 --- a/arch/x86/kvm/timer.c +++ b/arch/x86/kvm/timer.c @@ -18,9 +18,10 @@ #include <linux/atomic.h> #include "kvm_timer.h"

-static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer) +enum hrtimer_restart kvm_timer_fn(struct
hrtimer *data) { - int restart_timer = 0; + struct kvm_timer
*ktimer = container_of(data, struct kvm_timer, timer); + struct
kvm_vcpu *vcpu = ktimer->vcpu; wait_queue_head_t *q = &vcpu->wq;

/* @@ -40,26 +41,7 @@ static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)

Quoted 13 lines
Quoted 10 lines

if (ktimer->t_ops->is_periodic(ktimer)) { hrtimer_add_expires_ns(&ktimer->timer, ktimer->period); -
restart_timer = 1; - } - - return restart_timer; -} - -enum
hrtimer_restart kvm_timer_fn(struct hrtimer *data) -{ - int
restart_timer; - struct kvm_vcpu *vcpu; - struct kvm_timer
*ktimer = container_of(data, struct kvm_timer, timer); - - vcpu =
ktimer->vcpu; - if (!vcpu) - return HRTIMER_NORESTART; - -
restart_timer = __kvm_timer_fn(vcpu, ktimer); - if
(restart_timer) return HRTIMER_RESTART; - else + } else return
HRTIMER_NORESTART; } -

Ping.

Ping II.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#3 lore raw
In reply to Jan Kiszka
Quoted 8 lines · Jan Kiszka

The vcpu reference of a kvm_timer can't become NULL while the timer is valid, so drop this redundant test. This also makes it pointless to carry a separate __kvm_timer_fn, fold it into kvm_timer_fn.

---
 arch/x86/kvm/timer.c |   26 ++++----------------------
 1 files changed, 4 insertions(+), 22 deletions(-)

Applied, thanks.