lkml.org 
[lkml]   [1998]   [Dec]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From(Alan Cox)
SubjectRe: m68k softirq.h fix
DateThu, 24 Dec 1998 10:30:33 +0000 (GMT)
> > 	see 'softirq.h' files in it.
> > For the idea WHY your code is wrong, see Alpha's definitions
> > for atomic_inc(), and friends. You must not go setting,
> > or (heaven forbid), blindly ++:ing fields in there!
>
> I'm still confused. Is there any documentation/book/webpage/gopher hole/etc
> that I can read for this? In particular, what exactly is non-atomic about
> ++/--?

On some single processor machines the "++" operation is atomic in all
respects. The atomic_t, atomic_inc etc are primarily there for SMP machines
or systems where it may not be.

On the m68k for example ++ might generate this code if the value is also
referred too later (this is a 'sufficiently contrived example' - gcc's code
generator isnt quite so daft)

MOVE D0, _variable
ADDQ #1, D0
MOVE _variable, D0

With atomic_t it will always generate something like

ADD #1, _variable


On SMP machines it becomes even more 'interesting' because multiple processors
access the bus and same memory. So given the x86 code

inc [_variable]

executed on both processors at once, both may fetch and write the same value
back. So on x86 the atomic_t code generates

lock inc [_variable]

Where lock is an x86 "read-modify-write" instruction - that is one that the
other cpus cannot get at the value while the inc is being done.

Alan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:46    [from the cache]
©2003-2010