public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] only irq-safe atomic ops
@ 2002-02-23  6:13 Robert Love
  2002-02-23  6:51 ` Andrew Morton
  0 siblings, 1 reply; 36+ messages in thread
From: Robert Love @ 2002-02-23  6:13 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm

The following patch implements i386 versions of atomic_inc and
atomic_dec that are LOCK-less but provide IRQ-atomicity and act as a
memory-barrier.

An applicable use would be data that needs to be IRQ-safe but not
SMP-safe (or, more likely, is already SMP-safe for some other reason).

Additionally, these variants could prevent having to use
preempt_disable/enable or "full" atomic ops around per-CPU data with a
preemptible kernel.

The patch is against 2.5.5.  Enjoy,

	Robert Love

diff -urN linux-2.5.5/include/asm-i386/atomic.h linux/include/asm-i386/atomic.h
--- linux-2.5.5/include/asm-i386/atomic.h	Tue Feb 19 21:10:58 2002
+++ linux/include/asm-i386/atomic.h	Fri Feb 22 22:42:02 2002
@@ -111,6 +111,21 @@
 }
 
 /**
+ * atomic_inc_irq - increment atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * This is an IRQ-safe and memory-barrier
+ * increment without lock
+ */
+static __inline__ void atomic_inc_irq(atomic_t *v)
+{
+	__asm__ __volatile__(
+		"incl %0"
+		:"=m" (v->counter)
+		:"m" (v->counter));
+}
+
+/**
  * atomic_dec - decrement atomic variable
  * @v: pointer of type atomic_t
  * 
@@ -124,6 +139,21 @@
 		:"=m" (v->counter)
 		:"m" (v->counter));
 }
+
+/**
+ * atomic_dec_irq - decrement atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * This is an IRQ-safe and memory-barrier
+ * decrement without lock
+ */
+static __inline__ void atomic_dec_irq(atomic_t *v)
+{
+	__asm__ __volatile__(
+		"decl %0"
+		:"=m" (v->counter)
+		:"m" (v->counter));
+}
 
 /**
  * atomic_dec_and_test - decrement and test



^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2002-02-25 20:09 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1014444810.1003.53.camel@phantasy.suse.lists.linux.kernel>
     [not found] ` <3C773C02.93C7753E@zip.com.au.suse.lists.linux.kernel>
     [not found]   ` <1014449389.1003.149.camel@phantasy.suse.lists.linux.kernel>
     [not found]     ` <3C774AC8.5E0848A2@zip.com.au.suse.lists.linux.kernel>
     [not found]       ` <3C77F503.1060005@sgi.com.suse.lists.linux.kernel>
     [not found]         ` <3C77FB35.16844FE7@zip.com.au.suse.lists.linux.kernel>
2002-02-23 20:56           ` [PATCH] only irq-safe atomic ops Andi Kleen
2002-02-23 21:06             ` Andrew Morton
2002-02-23 21:17               ` Stephen Lord
2002-02-23 21:42                 ` Andrew Morton
2002-02-23 22:10                   ` Stephen Lord
2002-02-23 22:34                     ` Andrew Morton
2002-02-23 23:07                       ` Mike Fedyk
2002-02-23 23:47                         ` Andrew Morton
2002-02-25 13:02                       ` Stephen Lord
2002-02-25 13:12                         ` Jens Axboe
2002-02-25 13:18                           ` Stephen Lord
2002-02-25 19:42                             ` Andrew Morton
2002-02-25 19:45                               ` Steve Lord
2002-02-25 20:05                                 ` Andrew Morton
2002-02-23  6:13 Robert Love
2002-02-23  6:51 ` Andrew Morton
2002-02-23  7:29   ` Robert Love
2002-02-23  7:54     ` Andrew Morton
2002-02-23 11:38       ` yodaiken
2002-02-23 18:20         ` Robert Love
2002-02-23 19:06           ` yodaiken
2002-02-23 21:57             ` Roman Zippel
2002-02-23 22:10               ` Andrew Morton
2002-02-23 22:23                 ` yodaiken
2002-02-23 22:40                   ` Andrew Morton
2002-02-23 22:48                     ` yodaiken
2002-02-23 23:13                 ` Robert Love
2002-02-23 23:45                   ` Robert Love
2002-02-23 23:56                     ` Andrew Morton
2002-02-24  1:05                       ` yodaiken
2002-02-24  1:08                         ` Robert Love
2002-02-23 22:00             ` John Levon
2002-02-23 22:43               ` yodaiken
2002-02-23 20:01       ` Stephen Lord
2002-02-23 20:27         ` Andrew Morton
2002-02-23  9:38     ` Russell King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox