From 8057048cbc4e0ee60a36cb5c93b2cf58291cfbc3 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 3 Jul 2009 12:39:07 +0200 Subject: [PATCH] --- yaml --- r: 155211 b: refs/heads/master c: 824975ef190e7dcb77718d1cc2cb53769b16d918 h: refs/heads/master i: 155209: 971bdf050b2a65802609c771980fc8556f084923 155207: 937a0037421902186e410e0e9f45562f30489c2c v: v3 --- [refs] | 2 +- trunk/arch/x86/lib/atomic64_32.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index 7b25ffc3982e..d5f9b5c562f4 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 69237f94e65d3d7f539f1adb98ef68685c595004 +refs/heads/master: 824975ef190e7dcb77718d1cc2cb53769b16d918 diff --git a/trunk/arch/x86/lib/atomic64_32.c b/trunk/arch/x86/lib/atomic64_32.c index 5fc1e2caa544..61959627e1e1 100644 --- a/trunk/arch/x86/lib/atomic64_32.c +++ b/trunk/arch/x86/lib/atomic64_32.c @@ -76,13 +76,22 @@ u64 atomic64_read(atomic64_t *ptr) */ u64 atomic64_add_return(u64 delta, atomic64_t *ptr) { - u64 old_val, new_val; + /* + * Try first with a (probably incorrect) assumption about + * what we have there. We'll do two loops most likely, + * but we'll get an ownership MESI transaction straight away + * instead of a read transaction followed by a + * flush-for-ownership transaction: + */ + u64 old_val, new_val, real_val = 1ULL << 32; do { - old_val = atomic_read(ptr); + old_val = real_val; new_val = old_val + delta; - } while (atomic64_cmpxchg(ptr, old_val, new_val) != old_val); + real_val = atomic64_cmpxchg(ptr, old_val, new_val); + + } while (real_val != old_val); return new_val; }