From: Nick Piggin <nickpiggin@yahoo.com.au>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [patch 1/5] i386 generic cmpxchg
Date: Sun, 30 Oct 2005 11:43:08 +1100 [thread overview]
Message-ID: <4364171C.7020103@yahoo.com.au> (raw)
In-Reply-To: <436416AD.3050709@yahoo.com.au>
[-- Attachment #1: Type: text/plain, Size: 33 bytes --]
1/5
--
SUSE Labs, Novell Inc.
[-- Attachment #2: i386-generic-cmpxchg.patch --]
[-- Type: text/plain, Size: 4052 bytes --]
Changelog
* Make cmpxchg generally available on the i386 platform.
* Provide emulation of cmpxchg suitable for uniprocessor if
built and run on 386.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
* Cut down patch and small style changes.
Signed-off-by: Nick Piggin <npiggin@suse.de>
Index: linux-2.6/arch/i386/kernel/cpu/intel.c
===================================================================
--- linux-2.6.orig/arch/i386/kernel/cpu/intel.c
+++ linux-2.6/arch/i386/kernel/cpu/intel.c
@@ -6,6 +6,7 @@
#include <linux/bitops.h>
#include <linux/smp.h>
#include <linux/thread_info.h>
+#include <linux/module.h>
#include <asm/processor.h>
#include <asm/msr.h>
@@ -264,5 +265,55 @@ __init int intel_cpu_init(void)
return 0;
}
+#ifndef CONFIG_X86_CMPXCHG
+unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new)
+{
+ u8 prev;
+ unsigned long flags;
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u8 *)ptr;
+ if (prev == old)
+ *(u8 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u8);
+
+unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new)
+{
+ u16 prev;
+ unsigned long flags;
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u16 *)ptr;
+ if (prev == old)
+ *(u16 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u16);
+
+unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new)
+{
+ u32 prev;
+ unsigned long flags;
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u32 *)ptr;
+ if (prev == old)
+ *(u32 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u32);
+#endif
+
// arch_initcall(intel_cpu_init);
Index: linux-2.6/include/asm-i386/system.h
===================================================================
--- linux-2.6.orig/include/asm-i386/system.h
+++ linux-2.6/include/asm-i386/system.h
@@ -256,11 +256,6 @@ static inline unsigned long __xchg(unsig
* store NEW in MEM. Return the initial value in MEM. Success is
* indicated by comparing RETURN with OLD.
*/
-
-#ifdef CONFIG_X86_CMPXCHG
-#define __HAVE_ARCH_CMPXCHG 1
-#endif
-
static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
unsigned long new, int size)
{
@@ -288,12 +283,53 @@ static inline unsigned long __cmpxchg(vo
return old;
}
+#ifdef CONFIG_X86_CMPXCHG
+#define __HAVE_ARCH_CMPXCHG 1
#define cmpxchg(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
- (unsigned long)(n),sizeof(*(ptr))))
-
+ ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))))
+
+#else
+
+/*
+ * Building a kernel capable running on 80386. It may be necessary to
+ * simulate the cmpxchg on the 80386 CPU. For that purpose we define
+ * a function for each of the sizes we support.
+ */
+
+extern unsigned long cmpxchg_386_u8(volatile void *, u8, u8);
+extern unsigned long cmpxchg_386_u16(volatile void *, u16, u16);
+extern unsigned long cmpxchg_386_u32(volatile void *, u32, u32);
+
+static inline unsigned long cmpxchg_386(volatile void *ptr, unsigned long old,
+ unsigned long new, int size)
+{
+ switch (size) {
+ case 1:
+ return cmpxchg_386_u8(ptr, old, new);
+ case 2:
+ return cmpxchg_386_u16(ptr, old, new);
+ case 4:
+ return cmpxchg_386_u32(ptr, old, new);
+ }
+ return old;
+}
+
+#define cmpxchg(ptr,o,n) \
+({ \
+ __typeof__(*(ptr)) __ret; \
+ if (likely(boot_cpu_data.x86 > 3)) \
+ __ret = __cmpxchg((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))); \
+ else \
+ __ret = cmpxchg_386((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))); \
+ __ret; \
+})
+#endif
+
#ifdef __KERNEL__
-struct alt_instr {
+struct alt_instr {
__u8 *instr; /* original instruction */
__u8 *replacement;
__u8 cpuid; /* cpuid bit set for replacement */
next prev parent reply other threads:[~2005-10-30 0:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-30 0:41 [patches] lockless pagecache prep round 1 Nick Piggin
2005-10-30 0:43 ` Nick Piggin [this message]
2005-10-30 0:44 ` [patch 2/5] atomic: atomic_cmpxchg Nick Piggin
2005-10-30 0:45 ` [patch 3/5] atomic: atomic_inc_not_zero Nick Piggin
2005-10-30 0:45 ` [patch 4/5] rcu file: use atomic primitives Nick Piggin
2005-10-30 0:47 ` [patch 5/5] atomic: dec_and_lock " Nick Piggin
2005-10-31 19:05 ` [patch 3/5] atomic: atomic_inc_not_zero Christoph Lameter
2005-11-01 4:34 ` Nick Piggin
2005-11-14 16:29 ` Paul Jackson
2005-11-14 21:48 ` Andrew Morton
2005-11-14 22:02 ` Paul Jackson
2005-11-14 23:09 ` Andrew Morton
2005-11-15 8:57 ` Nick Piggin
2005-10-30 20:12 ` [patch 1/5] i386 generic cmpxchg Zwane Mwaikambo
2005-10-31 1:29 ` Nick Piggin
2005-10-31 6:06 ` Zwane Mwaikambo
2005-10-31 19:09 ` Christoph Lameter
2005-10-30 0:48 ` [patche 1/5] radix tree: lookup_slot Nick Piggin
2005-10-30 0:49 ` [patch 2/5] radix tree: use prealloc Nick Piggin
2005-10-30 0:50 ` [patch 3/5] radix tree: cleanup Nick Piggin
2005-10-30 0:51 ` [patch 4/5] radix tree: clear_tags bail Nick Piggin
2005-10-30 0:57 ` [patch 5/5] radix tree: shrink Nick Piggin
2005-10-30 1:04 ` [patch 1/5] radix tree: lookup_slot Nick Piggin
-- strict thread matches above, loose matches on Subject: below --
2005-11-05 7:55 [patch 0/4] atomic primitives again Nick Piggin
2005-11-05 7:56 ` [patch 1/5] i386: generic cmpxchg Nick Piggin
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=4364171C.7020103@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--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.