diff options
author | rsc <rsc> | 2007-09-30 14:30:04 +0000 |
---|---|---|
committer | rsc <rsc> | 2007-09-30 14:30:04 +0000 |
commit | 9fd9f80431ad85552c0969831a3ccc3e800ac464 (patch) | |
tree | e9190c3029d9b3eda767ae9d2cb93e0e54344e7b /main.c | |
parent | c840f3ecdc718c4a6eb6fbd9e0cbb0a012c3adf4 (diff) | |
download | xv6-labs-9fd9f80431ad85552c0969831a3ccc3e800ac464.tar.gz xv6-labs-9fd9f80431ad85552c0969831a3ccc3e800ac464.tar.bz2 xv6-labs-9fd9f80431ad85552c0969831a3ccc3e800ac464.zip |
Re: why cpuid() in locking code?
rtm wrote:
> Why does acquire() call cpuid()? Why does release() call cpuid()?
The cpuid in acquire is redundant with the cmpxchg, as you said.
I have removed the cpuid from acquire.
The cpuid in release is actually doing something important,
but not on the hardware. It keeps gcc from reordering the
lock->locked assignment above the other two during optimization.
(Not that current gcc -O2 would choose to do that, but it is allowed to.)
I have replaced the cpuid in release with a "gcc barrier" that
keeps gcc from moving things around but has no hardware effect.
On a related note, I don't think the cpuid in mpmain is necessary,
for the same reason that the cpuid wasn't needed in release.
As to the question of whether
acquire();
x = protected;
release();
might read protected after release(), I still haven't convinced
myself whether it can. I'll put the cpuid back into release if
we determine that it can.
Russ
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 1 |
1 files changed, 0 insertions, 1 deletions
@@ -50,7 +50,6 @@ mpmain(void) if(cpu() != mp_bcpu()) lapic_init(cpu()); setupsegs(0); - cpuid(0, 0, 0, 0, 0); // memory barrier cpus[cpu()].booted = 1; scheduler(); |