From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Andi Kleen <ak@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] 80386 and 80486 cmpxchg64 and cmpxchg64_local fallback
Date: Fri, 20 Jul 2007 12:49:47 -0400 [thread overview]
Message-ID: <20070720164947.GA2793@Krystal> (raw)
In-Reply-To: <200707201714.16811.ak@suse.de>
Fall back on interrupt disable in cmpxchg8b on 80386 and 80486
Actually, on 386, cmpxchg and cmpxchg_local fall back on
cmpxchg_386_u8/16/32: it disables interruptions around non atomic
updates to mimic the cmpxchg behavior.
The comment:
/* Poor man's cmpxchg for 386. Unsuitable for SMP */
in the implementation tells much about how this cmpxchg implementation
should not be used in a SMP context. However, the cmpxchg_local can
perfectly use this fallback, since it only needs to be atomic wrt the
local cpu.
This patch adds a cmpxchg_386_u64 and uses it as a fallback for cmpxchg64
and cmpxchg64_local on 80386 and 80486.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
arch/i386/kernel/cpu/intel.c | 17 +++++++
include/asm-i386/cmpxchg.h | 99 ++++++++++++++++++++++++++++---------------
2 files changed, 82 insertions(+), 34 deletions(-)
Index: linux-2.6-lttng/arch/i386/kernel/cpu/intel.c
===================================================================
--- linux-2.6-lttng.orig/arch/i386/kernel/cpu/intel.c 2007-07-20 12:41:24.000000000 -0400
+++ linux-2.6-lttng/arch/i386/kernel/cpu/intel.c 2007-07-20 12:43:56.000000000 -0400
@@ -329,5 +329,22 @@ unsigned long cmpxchg_386_u32(volatile v
EXPORT_SYMBOL(cmpxchg_386_u32);
#endif
+#ifndef CONFIG_X86_CMPXCHG64
+unsigned long long cmpxchg_486_u64(volatile void *ptr, u64 old, u64 new)
+{
+ u64 prev;
+ unsigned long flags;
+
+ /* Poor man's cmpxchg8b for 386 and 486. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u64 *)ptr;
+ if (prev == old)
+ *(u64 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+EXPORT_SYMBOL(cmpxchg_486_u64);
+#endif
+
// arch_initcall(intel_cpu_init);
Index: linux-2.6-lttng/include/asm-i386/cmpxchg.h
===================================================================
--- linux-2.6-lttng.orig/include/asm-i386/cmpxchg.h 2007-07-20 12:41:24.000000000 -0400
+++ linux-2.6-lttng/include/asm-i386/cmpxchg.h 2007-07-20 12:42:12.000000000 -0400
@@ -116,6 +116,15 @@ static inline unsigned long __xchg(unsig
(unsigned long)(n),sizeof(*(ptr))))
#endif
+#ifdef CONFIG_X86_CMPXCHG64
+#define cmpxchg64(ptr,o,n)\
+ ((__typeof__(*(ptr)))__cmpxchg64((ptr),(unsigned long long)(o),\
+ (unsigned long long)(n)))
+#define cmpxchg64_local(ptr,o,n)\
+ ((__typeof__(*(ptr)))__cmpxchg64_local((ptr),(unsigned long long)(o),\
+ (unsigned long long)(n)))
+#endif
+
static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
unsigned long new, int size)
{
@@ -203,6 +212,34 @@ static inline unsigned long __cmpxchg_lo
return old;
}
+static inline unsigned long long __cmpxchg64(volatile void *ptr,
+ unsigned long long old, unsigned long long new)
+{
+ unsigned long long prev;
+ __asm__ __volatile__(LOCK_PREFIX "cmpxchg8b %3"
+ : "=A"(prev)
+ : "b"((unsigned long)new),
+ "c"((unsigned long)(new >> 32)),
+ "m"(*__xg(ptr)),
+ "0"(old)
+ : "memory");
+ return prev;
+}
+
+static inline unsigned long long __cmpxchg64_local(volatile void *ptr,
+ unsigned long long old, unsigned long long new)
+{
+ unsigned long long prev;
+ __asm__ __volatile__("cmpxchg8b %3"
+ : "=A"(prev)
+ : "b"((unsigned long)new),
+ "c"((unsigned long)(new >> 32)),
+ "m"(*__xg(ptr)),
+ "0"(old)
+ : "memory");
+ return prev;
+}
+
#ifndef CONFIG_X86_CMPXCHG
/*
* Building a kernel capable running on 80386. It may be necessary to
@@ -252,42 +289,36 @@ static inline unsigned long cmpxchg_386(
})
#endif
-#ifdef CONFIG_X86_CMPXCHG64
-
-static inline unsigned long long __cmpxchg64(volatile void *ptr, unsigned long long old,
- unsigned long long new)
-{
- unsigned long long prev;
- __asm__ __volatile__(LOCK_PREFIX "cmpxchg8b %3"
- : "=A"(prev)
- : "b"((unsigned long)new),
- "c"((unsigned long)(new >> 32)),
- "m"(*__xg(ptr)),
- "0"(old)
- : "memory");
- return prev;
-}
+#ifndef CONFIG_X86_CMPXCHG64
+/*
+ * Building a kernel capable running on 80386 and 80486. It may be necessary
+ * to simulate the cmpxchg8b on the 80386 and 80486 CPU.
+ */
-static inline unsigned long long __cmpxchg64_local(volatile void *ptr,
- unsigned long long old, unsigned long long new)
-{
- unsigned long long prev;
- __asm__ __volatile__("cmpxchg8b %3"
- : "=A"(prev)
- : "b"((unsigned long)new),
- "c"((unsigned long)(new >> 32)),
- "m"(*__xg(ptr)),
- "0"(old)
- : "memory");
- return prev;
-}
+extern unsigned long long cmpxchg_486_u64(volatile void *, u64, u64);
-#define cmpxchg64(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg64((ptr),(unsigned long long)(o),\
- (unsigned long long)(n)))
-#define cmpxchg64_local(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg64_local((ptr),(unsigned long long)(o),\
- (unsigned long long)(n)))
+#define cmpxchg64(ptr,o,n) \
+({ \
+ __typeof__(*(ptr)) __ret; \
+ if (likely(boot_cpu_data.x86 > 4)) \
+ __ret = __cmpxchg64((ptr), (unsigned long long)(o), \
+ (unsigned long long)(n)); \
+ else \
+ __ret = cmpxchg_486_u64((ptr), (unsigned long long)(o), \
+ (unsigned long long)(n)); \
+ __ret; \
+})
+#define cmpxchg64_local(ptr,o,n) \
+({ \
+ __typeof__(*(ptr)) __ret; \
+ if (likely(boot_cpu_data.x86 > 4)) \
+ __ret = __cmpxchg64_local((ptr), (unsigned long long)(o), \
+ (unsigned long long)(n)); \
+ else \
+ __ret = cmpxchg_486_u64((ptr), (unsigned long long)(o), \
+ (unsigned long long)(n)); \
+ __ret; \
+})
#endif
#endif
--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
next prev parent reply other threads:[~2007-07-20 16:56 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-19 9:54 [PATCH] [0/58] First batch of x86 patches for .23 Andi Kleen
2007-07-19 9:54 ` [PATCH] [1/58] x86: Always flush pages in change_page_attr Andi Kleen
2007-08-06 10:15 ` [patches] " Jan Beulich
2007-08-06 10:36 ` Andi Kleen
2007-08-06 10:49 ` Jan Beulich
2007-07-19 9:54 ` [PATCH] [2/58] x86_64: Tell gcc to only align stack to 8 bytes Andi Kleen
2007-07-19 11:50 ` Serge Belyshev
2007-07-19 12:06 ` Andi Kleen
2007-07-19 14:42 ` Chuck Ebbert
2007-07-19 9:54 ` [PATCH] [3/58] x86_64: asm/ptrace.h needs linux/compiler.h Andi Kleen
2007-07-19 9:54 ` [PATCH] [4/58] x86_64: Don't rely on a unique IO-APIC ID Andi Kleen
2007-07-19 9:54 ` [PATCH] [5/58] x86_64: Report the pending irq if available in smp_affinity Andi Kleen
2007-07-19 10:23 ` Ingo Molnar
2007-07-19 9:54 ` [PATCH] [6/58] x86_64: Use LOCAL_DISTANCE and REMOTE_DISTANCE in x86_64 ACPI code Andi Kleen
2007-07-19 9:54 ` [PATCH] [7/58] x86_64: various cleanups in NUMA scan node Andi Kleen
2007-07-19 17:15 ` Yinghai Lu
2007-07-19 17:21 ` Andi Kleen
2007-07-19 17:38 ` Yinghai Lu
2007-07-19 20:00 ` Andi Kleen
2007-07-19 21:01 ` David Rientjes
2007-07-19 9:54 ` [PATCH] [8/58] x86_64: Use string instruction memcpy/memset on AMD Fam10 Andi Kleen
2007-07-19 16:43 ` Jan Engelhardt
2007-07-19 17:00 ` Yinghai Lu
2007-07-19 9:54 ` [PATCH] [9/58] x86_64: Always use builtin memcpy on gcc 4.3 Andi Kleen
2007-07-21 23:16 ` Oleg Verych
2007-07-21 23:27 ` Andi Kleen
2007-07-22 0:29 ` Denis Vlasenko
2007-07-19 9:54 ` [PATCH] [10/58] i386: Move all simple string operations out of line Andi Kleen
2007-07-19 9:54 ` [PATCH] [11/58] x86: Support __attribute__((__cold__)) in gcc 4.3 Andi Kleen
2007-07-19 9:54 ` [PATCH] [12/58] x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu Andi Kleen
2007-08-21 16:25 ` Daniel Walker
2007-08-21 18:45 ` Andi Kleen
2007-08-21 18:40 ` Andrew Morton
2007-07-19 9:54 ` [PATCH] [13/58] x86: Separate checking of unsynchronized and unstable TSC Andi Kleen
2007-07-19 9:54 ` [PATCH] [14/58] x86_64: Add on_cpu_single Andi Kleen
2007-07-19 11:09 ` Satyam Sharma
2007-07-19 12:07 ` Andi Kleen
2007-07-19 9:54 ` [PATCH] [15/58] i386: Rewrite sched_clock Andi Kleen
2007-07-19 16:51 ` Daniel Walker
2007-07-19 17:13 ` Andi Kleen
2007-07-19 17:15 ` Daniel Walker
2007-07-19 17:22 ` Andi Kleen
2007-07-19 17:31 ` Daniel Walker
2007-07-19 17:38 ` Andi Kleen
2007-07-19 17:43 ` Daniel Walker
2007-07-19 18:00 ` Andi Kleen
2007-07-19 18:00 ` Daniel Walker
2007-07-20 3:11 ` Mathieu Desnoyers
2007-07-20 3:47 ` Mathieu Desnoyers
2007-07-20 4:18 ` [PATCH] [15/58] i386: Rewrite sched_clock (cmpxchg8b) Mathieu Desnoyers
2007-07-20 5:07 ` Nick Piggin
2007-07-20 5:47 ` Mathieu Desnoyers
2007-07-20 8:27 ` [PATCH] [15/58] i386: Rewrite sched_clock Andi Kleen
2007-07-20 14:12 ` Mathieu Desnoyers
2007-07-20 14:39 ` Mathieu Desnoyers
2007-07-20 15:14 ` Andi Kleen
2007-07-20 15:22 ` Mathieu Desnoyers
2007-07-20 16:49 ` Mathieu Desnoyers [this message]
2007-07-19 9:55 ` [PATCH] [16/58] x86_64: Use new shared sched_clock in x86-64 too Andi Kleen
2007-07-19 9:55 ` [PATCH] [17/58] i386: Add L3 cache support to AMD CPUID4 emulation Andi Kleen
2007-07-20 17:00 ` [patches] " Andreas Herrmann
2007-07-20 17:15 ` Andreas Herrmann
2007-07-19 9:55 ` [PATCH] [18/58] x86_64: remove extra extern declaring about dmi_ioremap Andi Kleen
2007-07-19 9:55 ` [PATCH] [19/58] x86_64: Don't use softirq save locks in smp_call_function Andi Kleen
2007-07-19 12:16 ` Satyam Sharma
2007-07-19 12:19 ` Andi Kleen
2007-07-19 9:55 ` [PATCH] [20/58] x86: Always probe the NMI watchdog Andi Kleen
2007-07-19 10:24 ` Björn Steinbrink
2007-07-19 10:42 ` Andi Kleen
2007-07-19 9:55 ` [PATCH] [21/58] i386: Reserve the right performance counter for the Intel PerfMon " Andi Kleen
2007-07-19 10:21 ` Björn Steinbrink
2007-07-19 10:45 ` Andi Kleen
2007-07-19 9:55 ` [PATCH] [22/58] x86_64: hpet tsc calibration fix broken smi detection logic Andi Kleen
2007-07-19 9:55 ` [PATCH] [23/58] i386: remove pit_interrupt_hook Andi Kleen
2007-07-19 9:55 ` [PATCH] [24/58] x86_64: Untangle asm/hpet.h from asm/timex.h Andi Kleen
2007-07-19 9:55 ` [PATCH] [25/58] x86_64: use generic cmos update Andi Kleen
2007-07-19 9:55 ` [PATCH] [26/58] x86_64: Use generic xtime init Andi Kleen
2007-07-19 9:55 ` [PATCH] [27/58] x86_64: Remove dead code and other janitor work in tsc.c Andi Kleen
2007-07-19 9:55 ` [PATCH] [28/58] x86_64: Fix APIC typo Andi Kleen
2007-07-19 9:55 ` [PATCH] [29/58] x86_64: fiuxp pt_reqs leftovers Andi Kleen
2007-07-19 9:55 ` [PATCH] [30/58] x86: share hpet.h with i386 Andi Kleen
2007-07-19 9:55 ` [PATCH] [31/58] x86_64: apic.c coding style janitor work Andi Kleen
2007-07-19 9:55 ` [PATCH] [32/58] x86_64: time.c white space wreckage cleanup Andi Kleen
2007-07-19 9:55 ` [PATCH] [33/58] x86_64: Avoid too many remote cpu references due to /proc/stat Andi Kleen
2007-07-19 10:21 ` Christoph Hellwig
2007-07-19 10:41 ` Andi Kleen
2007-07-19 10:55 ` Adrian Bunk
2007-07-19 9:55 ` [PATCH] [34/58] x86_64: ia32entry adjustments Andi Kleen
2007-07-19 14:46 ` Jeff Garzik
2007-08-06 10:43 ` Jan Beulich
2007-07-19 9:55 ` [PATCH] [35/58] i386: allow debuggers to access the vsyscall page with compat vDSO Andi Kleen
2007-07-19 9:55 ` [PATCH] [36/58] x86_64: minor exception trace variables cleanup Andi Kleen
2007-07-19 9:55 ` [PATCH] [37/58] x86_64: remove unused variable maxcpus Andi Kleen
2007-07-19 9:55 ` [PATCH] [38/58] i386: smp-alt-once option is only useful with HOTPLUG_CPU Andi Kleen
2007-07-19 9:55 ` [PATCH] [39/58] i386: minor nx handling adjustment Andi Kleen
2007-07-19 9:55 ` [PATCH] [40/58] i386: remapped_pgdat_init() static Andi Kleen
2007-07-19 9:55 ` [PATCH] [41/58] i386: arch/i386/kernel/i8253.c should #include <asm/timer.h> Andi Kleen
2007-07-19 9:55 ` [PATCH] [42/58] i386: timer_irq_works() static again Andi Kleen
2007-07-19 9:55 ` [PATCH] [43/58] x86_64: Quicklist support for x86_64 Andi Kleen
2007-07-19 9:55 ` [PATCH] [44/58] x86_64: extract helper function from e820_register_active_regions Andi Kleen
2007-07-19 9:55 ` [PATCH] [45/58] x86_64: fake pxm-to-node mapping for fake numa Andi Kleen
2007-07-19 9:55 ` [PATCH] [46/58] x86_64: fake apicid_to_node " Andi Kleen
2007-07-19 9:55 ` [PATCH] [47/58] i386: insert unclaimed MMCONFIG resources Andi Kleen
2007-07-19 9:55 ` [PATCH] [48/58] x86_64: O_EXCL on /dev/mcelog Andi Kleen
2007-07-19 9:55 ` [PATCH] [49/58] x86_64: support poll() " Andi Kleen
2007-07-19 9:55 ` [PATCH] [50/58] x86_64: mcelog tolerant level cleanup Andi Kleen
2007-07-19 9:55 ` [PATCH] [51/58] i386: fix machine rebooting Andi Kleen
2007-07-19 9:55 ` [PATCH] [52/58] i386: fix section mismatch warnings in mtrr Andi Kleen
2007-07-19 9:55 ` [PATCH] [53/58] x86: PM_TRACE support Andi Kleen
2007-07-19 9:55 ` [PATCH] [54/58] x86: Make Alt-SysRq-p display the debug register contents Andi Kleen
2007-07-19 9:55 ` [PATCH] [55/58] i386: add reference to the arguments Andi Kleen
2007-07-19 9:55 ` [PATCH] [56/58] x86: round_jiffies() for i386 and x86-64 non-critical/corrected MCE polling Andi Kleen
2007-07-19 9:55 ` [PATCH] [57/58] x86_64: check remote IRR bit before migrating level triggered irq Andi Kleen
2007-07-19 9:55 ` [PATCH] [58/58] x86: remove support for the Rise CPU Andi Kleen
2007-07-19 10:45 ` Alan Cox
2007-07-19 10:48 ` Adrian Bunk
2007-07-19 11:13 ` Alan Cox
2007-07-19 12:03 ` Andi Kleen
2007-07-19 14:56 ` Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070720164947.GA2793@Krystal \
--to=mathieu.desnoyers@polymtl.ca \
--cc=ak@suse.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.