Fix locking in input
Quoted 11 lines · Paul
Quoted 3 lines · Pavel Machek
input uses "volatile signed char" as a shared variable between normal and interrupt threads (look at
_sendbyte()). Thats bad idea, this switches it toatomic_t.This change looks unnecessary to me - we aren't trying to increment or decrement the variable, just set it and read it. Reading and writing individual bytes is atomic on any platform we care about.
I think one platform (early ARM?) cannot access bytes directly, and implement the access with read 16-bit, change 8-bit, write back 16 bit. Reading/writing pointers or longs is atomic.
Pavel: Do you know that atomic_set and atomic_read aren't memory barriers? I.e.
- psmouse->ack = 0;
+ atomic_set(&psmouse->ack, 0); psmouse->acking = 1;
It's not guaranteed that all cpus will see psmouse->ack=0 before psmouse->acking=1. And adding the required memory barriers usually makes the code completely unreadable, thus I usually give up and switch to a spinlock.
--
Manfred
Quoted 2 lines · Manfred Spraul
I think one platform (early ARM?) cannot access bytes directly, and implement the access with read 16-bit, change 8-bit, write back 16 bit.
Nope.
Signature · 4 lines
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial coreQuoted 9 lines · Russell King
Quoted 3 lines · Manfred Spraul
I think one platform (early ARM?) cannot access bytes directly, and implement the access with read 16-bit, change 8-bit, write back 16 bit.
Nope.
It seems it's Alpha:
Quoted 9 lines · Linus
FreeBSD doesn't try to be portable any more, but Linux does, and there are architectures where 8- and 16-bit accesses aren't *atomic* but have to be done with read-modify-write cycles.
And even for fields like "age", where we don't care whether the age itself is 100% accurate, we _do_ care that the fields close-by don't get strange effects from updating "age". We used to have exactly this problem on alpha back in the 2.1.x timeframe.
--
Manfred
Quoted 5 lines · Manfred Spraul
Quoted 3 lines · Russell King
On Sun, Nov 23, 2003 at 11:24:02PM +0100, Manfred Spraul wrote:
Quoted 18 lines
Quoted 5 lines
Quoted 1 line
I think one platform (early ARM?) cannot access bytes directly, and implement the access with read 16-bit, change 8-bit, write back 16 bit.
Nope.
It seems it's Alpha:
Quoted 9 lines · Linus
FreeBSD doesn't try to be portable any more, but Linux does, and there are architectures where 8- and 16-bit accesses aren't *atomic* but have to be done with read-modify-write cycles.
And even for fields like "age", where we don't care whether the age itself is 100% accurate, we _do_ care that the fields close-by don't get strange effects from updating "age". We used to have exactly this problem on alpha back in the 2.1.x timeframe.
This is MOSTLY true, but not entirely. As I recall, Alpha has two addressing modes: Sparse and Dense.
The mode you're referring to is dense addressing where 32-bit and 64-bit accesses are atomic, but 16 and 8 bit accesses require RMW.
Sparse mode allows for atomic 8 and 16 bit accesses, but the access size is specified in the address using a rather bizarre binary encoding that doesn't look much like a regular address value. You would probably not want to use this unless you absolutely HAD to use some I/O device that required atomic byte or word accesses.
I'm sure someone else will (or already has) pipe(d) in with a more accurate explanation. :)
Quoted 3 lines · Timothy Miller
This is MOSTLY true, but not entirely. As I recall, Alpha has two addressing modes: Sparse and Dense.
Nope. Alpha only does "dense" addressing on a CPU level.
What the _system_ designers on most PCI systems did was to map the PCI address space twice: once through a "dense" mapping and once through a "sparse" mapping. In the sparse mapping the low address bits give byte enable information, while in the dense mapping you can onyl do 32-bit and 64-bit aligned operations.
But the original alpha CPU couldn't do the sparse mapping - in particular the above only worked with non-cached accesses.
So "real memory" was always dense, and could not atomically be accessed with byte/word writes (you could use the atomic "load-locked" + "store-conditional" to do them, but at a huge performance loss, and obviously the compilers never did that).
Linus
Hi!
Quoted 20 lines
Quoted 9 lines
Quoted 3 lines
input uses "volatile signed char" as a shared variable between normal and interrupt threads (look at
_sendbyte()). Thats bad idea, this switches it toatomic_t.This change looks unnecessary to me - we aren't trying to increment or decrement the variable, just set it and read it. Reading and writing individual bytes is atomic on any platform we care about.
I think one platform (early ARM?) cannot access bytes directly, and implement the access with read 16-bit, change 8-bit, write back 16 bit. Reading/writing pointers or longs is atomic.
Pavel: Do you know that
atomic_setandatomic_readaren't memory barriers? I.e.(quoted diff) +1
-1- psmouse->ack = 0; + atomic_set(&psmouse->ack, 0);psmouse->acking = 1;
Quoted 4 lines
It's not guaranteed that all cpus will see psmouse->ack=0 before psmouse->acking=1. And adding the required memory barriers usually makes the code completely unreadable, thus I usually give up and switch to a spinlock.
Would simply adding mb() there fix it? It is not performance-critical in any way...
Pavel
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]