* [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* Re: [PATCH] only irq-safe atomic ops
2002-02-23 6:13 [PATCH] only irq-safe atomic ops Robert Love
@ 2002-02-23 6:51 ` Andrew Morton
2002-02-23 7:29 ` Robert Love
0 siblings, 1 reply; 36+ messages in thread
From: Andrew Morton @ 2002-02-23 6:51 UTC (permalink / raw)
To: Robert Love; +Cc: linux-kernel
Robert Love wrote:
>
> 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.
>
Thanks, Robert.
Some background here - for the delayed allocation code which I'm
cooking up I need to globally count the number of dirty pages in the
machine. Currently that's done with atomic_inc(&nr_dirty_pages)
in SetPageDirty().
But this counter (which is used for when-to-start-writeback decisions)
is unavoidably approximate. It would be nice to make it a per-CPU
array. So on the rare occasions when the dirty-page count is needed,
I can just whizz across the per-cpu counters adding them all up.
But how to increment or decrement a per-cpu counter? The options
are:
- per_cpu_integer++;
This is *probably* OK on all architectures. But there are no
guarantees that the compiler won't play games, and that this
operation is preempt-safe.
- preempt_disable(); per_cpu_counter++; preempt_enable();
A bit heavyweight for add-one-to-i.
- atomic_inc
A buslocked operation where it is not needed - we only need
a preempt-locked operation here. But it's per-cpu data, and
the buslocked rmw won't be too costly.
I can't believe how piddling this issue is :)
But if there's a general need for such a micro-optimisation
then we need to:
1: Create <linux/atomic.h> (for heavens sake!)
2: In <linux/atomic.h>,
#ifndef ARCH_HAS_ATOMIC_INQ_THINGIES
#define atomic_inc_irq atomic_inc
...
#endif
But for now, I suggest we not bother. I'll just use atomic_inc().
-
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 6:51 ` Andrew Morton
@ 2002-02-23 7:29 ` Robert Love
2002-02-23 7:54 ` Andrew Morton
2002-02-23 9:38 ` Russell King
0 siblings, 2 replies; 36+ messages in thread
From: Robert Love @ 2002-02-23 7:29 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
On Sat, 2002-02-23 at 01:51, Andrew Morton wrote:
> Thanks, Robert.
You are welcome.
> Some background here - for the delayed allocation code which I'm
> cooking up I need to globally count the number of dirty pages in the
> machine. Currently that's done with atomic_inc(&nr_dirty_pages)
> in SetPageDirty().
>
> But this counter (which is used for when-to-start-writeback decisions)
> is unavoidably approximate. It would be nice to make it a per-CPU
> array. So on the rare occasions when the dirty-page count is needed,
> I can just whizz across the per-cpu counters adding them all up.
Question: if (from below) you are going to use atomic operations, why
make it per-CPU at all? Just have one counter and atomic_inc and
atomic_read it. You won't need a spin lock.
> But how to increment or decrement a per-cpu counter? The options
> are:
>
> - per_cpu_integer++;
>
> This is *probably* OK on all architectures. But there are no
> guarantees that the compiler won't play games, and that this
> operation is preempt-safe.
This would be atomic and thus preempt-safe on any sane arch I know, as
long as we are dealing with a normal type int. Admittedly, however, we
can't be sure what the compiler would do.
Thinking about it, you are probably going to be doing this:
++counter[smp_processor_id()];
and that is not preempt-safe since the whole operation certainly is not
atomic. The current CPU could change between calculating it and
referencing the array. But, that wouldn't matter as long as you only
cared about the sum of the counters.
> - preempt_disable(); per_cpu_counter++; preempt_enable();
>
> A bit heavyweight for add-one-to-i.
Agreed, although I bet its not noticeable.
> - atomic_inc
>
> A buslocked operation where it is not needed - we only need
> a preempt-locked operation here. But it's per-cpu data, and
> the buslocked rmw won't be too costly.
>
> I can't believe how piddling this issue is :)
>
> But if there's a general need for such a micro-optimisation
> then we need to:
>
> 1: Create <linux/atomic.h> (for heavens sake!)
>
> 2: In <linux/atomic.h>,
>
> #ifndef ARCH_HAS_ATOMIC_INQ_THINGIES
> #define atomic_inc_irq atomic_inc
> ...
> #endif
I can think up a few more uses of the irq/memory-safe atomic ops, so I
bet this isn't that bad of an idea. But no point doing it without a
corresponding use.
> But for now, I suggest we not bother. I'll just use atomic_inc().
Robert Love
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 7:29 ` Robert Love
@ 2002-02-23 7:54 ` Andrew Morton
2002-02-23 11:38 ` yodaiken
2002-02-23 20:01 ` Stephen Lord
2002-02-23 9:38 ` Russell King
1 sibling, 2 replies; 36+ messages in thread
From: Andrew Morton @ 2002-02-23 7:54 UTC (permalink / raw)
To: Robert Love; +Cc: linux-kernel
Robert Love wrote:
>
> ...
>
> Question: if (from below) you are going to use atomic operations, why
> make it per-CPU at all? Just have one counter and atomic_inc and
> atomic_read it. You won't need a spin lock.
Oh that works fine. But then it's a global counter, so each time
a CPU marks a page dirty, the counter needs to be pulled out of
another CPU's cache. Which is not a thing I *need* to do.
As I said, it's a micro-issue. But it's a requirement which
may pop up elsewhere.
> This would be atomic and thus preempt-safe on any sane arch I know, as
> long as we are dealing with a normal type int. Admittedly, however, we
> can't be sure what the compiler would do.
>
> Thinking about it, you are probably going to be doing this:
>
> ++counter[smp_processor_id()];
>
> and that is not preempt-safe since the whole operation certainly is not
> atomic. The current CPU could change between calculating it and
> referencing the array.
yup. It'd probably work - the compiler should calculate the address and
do a non-buslocked but IRQ-atomic increment on it. But no way can we
rely on that happening.
> But, that wouldn't matter as long as you only
> cared about the sum of the counters.
If the compiler produced code equivalent to
counter[smp_processor_id()] = counter[smp_processor_id()] + 1;
then the counter would get trashed - a context switch could cause CPUB
to write CPUA's counter (+1) onto CPUB's counter. It's quite possibly
illegal for the compiler to evaluate the array subscript twice in this
manner. Dunno.
If the compiler produced code equivalent to:
const int cpu = smp_processor_id();
counter[cpu] = counter[cpu] + 1;
(which is much more likely) then a context switch would result
in CPUB writing CPUA's updated counter onto CPUA's counter. Which
will work a lot more often, until CPUA happens to be updating its
counter at the same time.
> ...
> > 2: In <linux/atomic.h>,
> >
> > #ifndef ARCH_HAS_ATOMIC_INQ_THINGIES
> > #define atomic_inc_irq atomic_inc
> > ...
> > #endif
>
> I can think up a few more uses of the irq/memory-safe atomic ops, so I
> bet this isn't that bad of an idea. But no point doing it without a
> corresponding use.
Sure.
-
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 7:54 ` Andrew Morton
@ 2002-02-23 11:38 ` yodaiken
2002-02-23 18:20 ` Robert Love
2002-02-23 20:01 ` Stephen Lord
1 sibling, 1 reply; 36+ messages in thread
From: yodaiken @ 2002-02-23 11:38 UTC (permalink / raw)
To: Andrew Morton; +Cc: Robert Love, linux-kernel
On Fri, Feb 22, 2002 at 11:54:48PM -0800, Andrew Morton wrote:
> Robert Love wrote:
> > Thinking about it, you are probably going to be doing this:
> >
> > ++counter[smp_processor_id()];
> >
> > and that is not preempt-safe since the whole operation certainly is not
> > atomic. The current CPU could change between calculating it and
> > referencing the array.
>
> yup. It'd probably work - the compiler should calculate the address and
> do a non-buslocked but IRQ-atomic increment on it. But no way can we
> rely on that happening.
>
> > But, that wouldn't matter as long as you only
> > cared about the sum of the counters.
>
> If the compiler produced code equivalent to
>
> counter[smp_processor_id()] = counter[smp_processor_id()] + 1;
>
> then the counter would get trashed - a context switch could cause CPUB
> to write CPUA's counter (+1) onto CPUB's counter. It's quite possibly
> illegal for the compiler to evaluate the array subscript twice in this
> manner. Dunno.
>
> If the compiler produced code equivalent to:
>
> const int cpu = smp_processor_id();
> counter[cpu] = counter[cpu] + 1;
>
> (which is much more likely) then a context switch would result
> in CPUB writing CPUA's updated counter onto CPUA's counter. Which
> will work a lot more often, until CPUA happens to be updating its
> counter at the same time.
So without preemption in the kernel
maybe 4 instructions: calculate cpuid, inc; all local no cache ping
code is easy to read and understand.
with preemption in the kernel
a design problem. a slippery synchronization issue that
involves the characteristic preemption error - code that works
most of the time.
--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
www.fsmlabs.com www.rtlinux.com
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 11:38 ` yodaiken
@ 2002-02-23 18:20 ` Robert Love
2002-02-23 19:06 ` yodaiken
0 siblings, 1 reply; 36+ messages in thread
From: Robert Love @ 2002-02-23 18:20 UTC (permalink / raw)
To: yodaiken; +Cc: Andrew Morton, linux-kernel
On Sat, 2002-02-23 at 06:38, yodaiken@fsmlabs.com wrote:
> So without preemption in the kernel
> maybe 4 instructions: calculate cpuid, inc; all local no cache ping
> code is easy to read and understand.
>
> with preemption in the kernel
> a design problem. a slippery synchronization issue that
> involves the characteristic preemption error - code that works
> most of the time.
Or not. The topic of this thread was a micro-optimization. If we treat
the variable as anything normal requiring synchronization under SMP, any
of the standard solutions (atomic ops, etc.) work. If we want to get
fancy, we can disable preemption, use my atomic_irq ops, or just not
care.
Robert Love
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 18:20 ` Robert Love
@ 2002-02-23 19:06 ` yodaiken
2002-02-23 21:57 ` Roman Zippel
2002-02-23 22:00 ` John Levon
0 siblings, 2 replies; 36+ messages in thread
From: yodaiken @ 2002-02-23 19:06 UTC (permalink / raw)
To: Robert Love; +Cc: yodaiken, Andrew Morton, linux-kernel
On Sat, Feb 23, 2002 at 01:20:06PM -0500, Robert Love wrote:
> On Sat, 2002-02-23 at 06:38, yodaiken@fsmlabs.com wrote:
>
> > So without preemption in the kernel
> > maybe 4 instructions: calculate cpuid, inc; all local no cache ping
> > code is easy to read and understand.
> >
> > with preemption in the kernel
> > a design problem. a slippery synchronization issue that
> > involves the characteristic preemption error - code that works
> > most of the time.
>
> Or not. The topic of this thread was a micro-optimization. If we treat
> the variable as anything normal requiring synchronization under SMP, any
> of the standard solutions (atomic ops, etc.) work. If we want to get
And cause cache ping, possible contention, ...
> fancy, we can disable preemption, use my atomic_irq ops, or just not
> care.
Right. Without preemption it is safe to do
c = smp_get_cpuid();
...
x = ++local_cache[c]
..
y = ++different_local_cache[c];
..
With preemption this turns into a problem that is easier to solve
with a lock or by not having per-cpu caches in the first place --
eg by writing worse code. After all, those are just micro-optimizations
and a few percent here, a few percent there, nobody will notice it. -(
--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
www.fsmlabs.com www.rtlinux.com
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH] only irq-safe atomic ops
2002-02-23 19:06 ` yodaiken
@ 2002-02-23 21:57 ` Roman Zippel
2002-02-23 22:10 ` Andrew Morton
2002-02-23 22:00 ` John Levon
1 sibling, 1 reply; 36+ messages in thread
From: Roman Zippel @ 2002-02-23 21:57 UTC (permalink / raw)
To: yodaiken; +Cc: Robert Love, Andrew Morton, linux-kernel
Hi,
yodaiken@fsmlabs.com wrote:
> Right. Without preemption it is safe to do
> c = smp_get_cpuid();
> ...
> x = ++local_cache[c]
> ..
>
> y = ++different_local_cache[c];
> ..
Just add:
smp_put_cpuid();
Is that so much worse?
bye, Roman
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 21:57 ` Roman Zippel
@ 2002-02-23 22:10 ` Andrew Morton
2002-02-23 22:23 ` yodaiken
2002-02-23 23:13 ` Robert Love
0 siblings, 2 replies; 36+ messages in thread
From: Andrew Morton @ 2002-02-23 22:10 UTC (permalink / raw)
To: Roman Zippel; +Cc: yodaiken, Robert Love, linux-kernel
Roman Zippel wrote:
>
> Hi,
>
> yodaiken@fsmlabs.com wrote:
>
> > Right. Without preemption it is safe to do
> > c = smp_get_cpuid();
> > ...
> > x = ++local_cache[c]
> > ..
> >
> > y = ++different_local_cache[c];
> > ..
>
> Just add:
> smp_put_cpuid();
>
> Is that so much worse?
>
ooh. me likee.
#define smp_get_cpuid() ({ preempt_disable(); smp_processor_id(); })
#define smp_put_cpuid() preempt_enable()
Does rml likee?
-
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH] only irq-safe atomic ops
2002-02-23 22:10 ` Andrew Morton
@ 2002-02-23 22:23 ` yodaiken
2002-02-23 22:40 ` Andrew Morton
2002-02-23 23:13 ` Robert Love
1 sibling, 1 reply; 36+ messages in thread
From: yodaiken @ 2002-02-23 22:23 UTC (permalink / raw)
To: Andrew Morton; +Cc: Roman Zippel, yodaiken, Robert Love, linux-kernel
On Sat, Feb 23, 2002 at 02:10:25PM -0800, Andrew Morton wrote:
> Roman Zippel wrote:
> >
> > Hi,
> >
> > yodaiken@fsmlabs.com wrote:
> >
> > > Right. Without preemption it is safe to do
> > > c = smp_get_cpuid();
> > > ...
> > > x = ++local_cache[c]
> > > ..
> > >
> > > y = ++different_local_cache[c];
> > > ..
> >
> > Just add:
> > smp_put_cpuid();
> >
> > Is that so much worse?
> >
>
> ooh. me likee.
Cool.
Me likee code with unmatched smp_get_cpuid/smp_put_cpuid.
Much nicer to write
x = ++local_cache[smp_getcpuid()];
smp_put_cuid();
than boring old
x = ++ local_cache[c];
Is this part of some scheme to make the GPL support model actually
pay?
c = smp_get_cpuid(); // disables preemption
...
f(); // oops, me forgotee, this function also references cpuid
..
x = ++local_cache[c]; // live dangerously
smp_put_cpuid(); // G_d knows what that does now.
Oh, wait, I know - reference counts for get_cpuid! How hard can that
be? See how simple it is? One simple step at a time.
--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
www.fsmlabs.com www.rtlinux.com
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 22:23 ` yodaiken
@ 2002-02-23 22:40 ` Andrew Morton
2002-02-23 22:48 ` yodaiken
0 siblings, 1 reply; 36+ messages in thread
From: Andrew Morton @ 2002-02-23 22:40 UTC (permalink / raw)
To: yodaiken; +Cc: Roman Zippel, Robert Love, linux-kernel
yodaiken@fsmlabs.com wrote:
>
> Is this part of some scheme to make the GPL support model actually
> pay?
No, no, no. It's all the uncommented code which brings in the dollars.
> c = smp_get_cpuid(); // disables preemption
>
> ...
> f(); // oops, me forgotee, this function also references cpuid
> ..
> x = ++local_cache[c]; // live dangerously
> smp_put_cpuid(); // G_d knows what that does now.
>
preempt_disable() nests. It's not a problem.
-
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 22:40 ` Andrew Morton
@ 2002-02-23 22:48 ` yodaiken
0 siblings, 0 replies; 36+ messages in thread
From: yodaiken @ 2002-02-23 22:48 UTC (permalink / raw)
To: Andrew Morton; +Cc: yodaiken, Roman Zippel, Robert Love, linux-kernel
On Sat, Feb 23, 2002 at 02:40:58PM -0800, Andrew Morton wrote:
> yodaiken@fsmlabs.com wrote:
> >
> > Is this part of some scheme to make the GPL support model actually
> > pay?
>
> No, no, no. It's all the uncommented code which brings in the dollars.
>
> > c = smp_get_cpuid(); // disables preemption
> >
> > ...
> > f(); // oops, me forgotee, this function also references cpuid
> > ..
> > x = ++local_cache[c]; // live dangerously
> > smp_put_cpuid(); // G_d knows what that does now.
> >
>
> preempt_disable() nests. It's not a problem.
Ah, got the reference count already! Good progress.
Is it irq safe yet?
BTW: Robert, whats a good kernel version that you recommend with
preemption patch? I want to rerun some tests.
--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
www.fsmlabs.com www.rtlinux.com
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 22:10 ` Andrew Morton
2002-02-23 22:23 ` yodaiken
@ 2002-02-23 23:13 ` Robert Love
2002-02-23 23:45 ` Robert Love
1 sibling, 1 reply; 36+ messages in thread
From: Robert Love @ 2002-02-23 23:13 UTC (permalink / raw)
To: Andrew Morton; +Cc: Roman Zippel, linux-kernel
On Sat, 2002-02-23 at 17:10, Andrew Morton wrote:
> ooh. me likee.
>
> #define smp_get_cpuid() ({ preempt_disable(); smp_processor_id(); })
> #define smp_put_cpuid() preempt_enable()
>
> Does rml likee?
Yah, that works.
All we need to do is wrap the smp_processor_id references (however many
- it does not matter) in preempt_disable ... preempt_enable. This does
that cleanly.
Robert Love
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH] only irq-safe atomic ops
2002-02-23 23:13 ` Robert Love
@ 2002-02-23 23:45 ` Robert Love
2002-02-23 23:56 ` Andrew Morton
0 siblings, 1 reply; 36+ messages in thread
From: Robert Love @ 2002-02-23 23:45 UTC (permalink / raw)
To: Andrew Morton; +Cc: Roman Zippel, linux-kernel
On Sat, 2002-02-23 at 18:13, Robert Love wrote:
> On Sat, 2002-02-23 at 17:10, Andrew Morton wrote:
>
> > ooh. me likee.
> >
> > #define smp_get_cpuid() ({ preempt_disable(); smp_processor_id(); })
> > #define smp_put_cpuid() preempt_enable()
> >
> > Does rml likee?
>
> Yah, that works.
OK, I still likee, but I was just thinking, if we are going to add have
to add something why not consider the irq-safe atomic ops? It is
certainly the most optimal.
Robert Love
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH] only irq-safe atomic ops
2002-02-23 23:45 ` Robert Love
@ 2002-02-23 23:56 ` Andrew Morton
2002-02-24 1:05 ` yodaiken
0 siblings, 1 reply; 36+ messages in thread
From: Andrew Morton @ 2002-02-23 23:56 UTC (permalink / raw)
To: Robert Love; +Cc: Roman Zippel, linux-kernel
Robert Love wrote:
>
> On Sat, 2002-02-23 at 18:13, Robert Love wrote:
> > On Sat, 2002-02-23 at 17:10, Andrew Morton wrote:
> >
> > > ooh. me likee.
> > >
> > > #define smp_get_cpuid() ({ preempt_disable(); smp_processor_id(); })
> > > #define smp_put_cpuid() preempt_enable()
> > >
> > > Does rml likee?
> >
> > Yah, that works.
>
> OK, I still likee, but I was just thinking, if we are going to add have
> to add something why not consider the irq-safe atomic ops? It is
> certainly the most optimal.
>
For the situation Victor described:
const int cpu = smp_get_cpuid();
per_cpu_array_foo[cpu] = per_cpu_array_bar[cpu] +
per_cpu_array_zot[cpu];
smp_put_cpuid();
It's a nice interface - it says "pin down and return the current
CPU ID".
-
^ permalink raw reply [flat|nested] 36+ messages in thread* Re: [PATCH] only irq-safe atomic ops
2002-02-23 23:56 ` Andrew Morton
@ 2002-02-24 1:05 ` yodaiken
2002-02-24 1:08 ` Robert Love
0 siblings, 1 reply; 36+ messages in thread
From: yodaiken @ 2002-02-24 1:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: Robert Love, Roman Zippel, linux-kernel
On Sat, Feb 23, 2002 at 03:56:36PM -0800, Andrew Morton wrote:
> Robert Love wrote:
> >
> For the situation Victor described:
>
> const int cpu = smp_get_cpuid();
>
> per_cpu_array_foo[cpu] = per_cpu_array_bar[cpu] +
> per_cpu_array_zot[cpu];
>
> smp_put_cpuid();
>
> It's a nice interface - it says "pin down and return the current
> CPU ID".
Go for it! Only 900 odd calls to smp_processor_id in the kernel
source last time I checked.
--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
www.fsmlabs.com www.rtlinux.com
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 19:06 ` yodaiken
2002-02-23 21:57 ` Roman Zippel
@ 2002-02-23 22:00 ` John Levon
2002-02-23 22:43 ` yodaiken
1 sibling, 1 reply; 36+ messages in thread
From: John Levon @ 2002-02-23 22:00 UTC (permalink / raw)
To: linux-kernel
On Sat, Feb 23, 2002 at 12:06:48PM -0700, yodaiken@fsmlabs.com wrote:
> With preemption this turns into a problem that is easier to solve
> with a lock or by not having per-cpu caches in the first place --
whilst you're correct (pre-emption has made everything harder), there's
not much point moaning about it, since it's in linus' kernel now. So
why bother ?
regards
john
--
"Oh dear, more knobs."
- David Chase
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 22:00 ` John Levon
@ 2002-02-23 22:43 ` yodaiken
0 siblings, 0 replies; 36+ messages in thread
From: yodaiken @ 2002-02-23 22:43 UTC (permalink / raw)
To: John Levon; +Cc: linux-kernel
On Sat, Feb 23, 2002 at 10:00:04PM +0000, John Levon wrote:
> On Sat, Feb 23, 2002 at 12:06:48PM -0700, yodaiken@fsmlabs.com wrote:
>
> > With preemption this turns into a problem that is easier to solve
> > with a lock or by not having per-cpu caches in the first place --
>
> whilst you're correct (pre-emption has made everything harder), there's
> not much point moaning about it, since it's in linus' kernel now. So
> why bother ?
>
everyone needs a hobby.
--
---------------------------------------------------------
Victor Yodaiken
Finite State Machine Labs: The RTLinux Company.
www.fsmlabs.com www.rtlinux.com
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 7:54 ` Andrew Morton
2002-02-23 11:38 ` yodaiken
@ 2002-02-23 20:01 ` Stephen Lord
2002-02-23 20:27 ` Andrew Morton
1 sibling, 1 reply; 36+ messages in thread
From: Stephen Lord @ 2002-02-23 20:01 UTC (permalink / raw)
To: Andrew Morton; +Cc: Robert Love, linux-kernel
Andrew Morton wrote:
>Robert Love wrote:
>
>>...
>>
>>Question: if (from below) you are going to use atomic operations, why
>>make it per-CPU at all? Just have one counter and atomic_inc and
>>atomic_read it. You won't need a spin lock.
>>
>
>Oh that works fine. But then it's a global counter, so each time
>a CPU marks a page dirty, the counter needs to be pulled out of
>another CPU's cache. Which is not a thing I *need* to do.
>
>As I said, it's a micro-issue. But it's a requirement which
>may pop up elsewhere.
>
>
I can tell you that Irix has just such a global counter for the amount of
delayed allocate pages - and it gets to be a major point of cache contention
once you get to larger cpu counts. So avoiding that from the start would
be good.
Steve
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 20:01 ` Stephen Lord
@ 2002-02-23 20:27 ` Andrew Morton
0 siblings, 0 replies; 36+ messages in thread
From: Andrew Morton @ 2002-02-23 20:27 UTC (permalink / raw)
To: Stephen Lord; +Cc: Robert Love, linux-kernel
Stephen Lord wrote:
>
> Andrew Morton wrote:
>
> >Robert Love wrote:
> >
> >>...
> >>
> >>Question: if (from below) you are going to use atomic operations, why
> >>make it per-CPU at all? Just have one counter and atomic_inc and
> >>atomic_read it. You won't need a spin lock.
> >>
> >
> >Oh that works fine. But then it's a global counter, so each time
> >a CPU marks a page dirty, the counter needs to be pulled out of
> >another CPU's cache. Which is not a thing I *need* to do.
> >
> >As I said, it's a micro-issue. But it's a requirement which
> >may pop up elsewhere.
> >
> >
> I can tell you that Irix has just such a global counter for the amount of
> delayed allocate pages - and it gets to be a major point of cache contention
> once you get to larger cpu counts. So avoiding that from the start would
> be good.
Ah, good info. Thanks. I'll fix it with a big "FIXME" comment for now,
fix it for real when Rusty's per-CPU infrastructure appears.
-
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH] only irq-safe atomic ops
2002-02-23 7:29 ` Robert Love
2002-02-23 7:54 ` Andrew Morton
@ 2002-02-23 9:38 ` Russell King
1 sibling, 0 replies; 36+ messages in thread
From: Russell King @ 2002-02-23 9:38 UTC (permalink / raw)
To: Robert Love; +Cc: Andrew Morton, linux-kernel
On Sat, Feb 23, 2002 at 02:29:48AM -0500, Robert Love wrote:
> This would be atomic and thus preempt-safe on any sane arch I know, as
> long as we are dealing with a normal type int. Admittedly, however, we
> can't be sure what the compiler would do.
Any sane RISC architecture probably doesn't have a single "increment this
memory location" instruction.
--
Russell King (rmk@arm.linux.org.uk) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
^ permalink raw reply [flat|nested] 36+ messages in thread
[parent not found: <1014444810.1003.53.camel@phantasy.suse.lists.linux.kernel>]
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 --
2002-02-23 6:13 [PATCH] only irq-safe atomic ops 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
[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 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox