Arjan Koers
2011-01-01 20:51:03 UTC
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
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