Discussion:
[PATCH] KVM: pvclock_clocksource_read while-loop optimization
Arjan Koers
2011-01-01 20:51:03 UTC
Permalink
Reduce the number of while-loop iterations (from two to one in the most
common situation)

Signed-off-by: Arjan Koers <***@xutrox.com>

diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index 42eb330..8f52acb 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -93,7 +93,7 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
struct pvclock_shadow_time shadow;
unsigned version;
cycle_t ret, offset;
- u64 last;
+ u64 last, save;

do {
version = pvclock_get_time_values(&shadow, src);
@@ -125,8 +125,9 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
do {
if (ret < last)
return last;
+ save = last;
last = atomic64_cmpxchg(&last_value, last, ret);
- } while (unlikely(last != ret));
+ } while (unlikely(last != save));

return ret;
}


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Glauber Costa
2011-01-03 16:50:33 UTC
Permalink
Post by Arjan Koers
Reduce the number of while-loop iterations (from two to one in the most
common situation)
diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index 42eb330..8f52acb 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -93,7 +93,7 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
struct pvclock_shadow_time shadow;
unsigned version;
cycle_t ret, offset;
- u64 last;
+ u64 last, save;
do {
version = pvclock_get_time_values(&shadow, src);
@@ -125,8 +125,9 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
do {
if (ret < last)
return last;
+ save = last;
last = atomic64_cmpxchg(&last_value, last, ret);
- } while (unlikely(last != ret));
+ } while (unlikely(last != save));
return ret;
}
Hey, good catch.



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...