Skip to contentSkip to conversation

Fast 64-bit atomic writes (SSE?)

DISCUSSION Andi Kleen 2 participants 3 messages Mar 20, 2004 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 874qskl5ca.fsf@love-shack.home.digitalvampire.org.suse.lists.linux.kernel

Andi Kleen

author
#1 lore raw
Quoted 3 lines · Roland Dreier

General question:
What's the best way to do this?

Definitely not how you do it ;-) You corrupt the user space FPU context. Also you didn't do a CPUID check, so it would just crash on machines

The RAID code has some examples on how to use SSE2 in the kernel correctly.

Better is probably to use CMPXCHG8, which avoids all of this.

-Andi

#2 lore raw

Andi> Definitely not how you do it ;-) You corrupt the user space Andi> FPU context. Also you didn't do a CPUID check, so it would Andi> just crash on machines

I'm not an asm expert, so could you explain how it corrupts the FPU context? I tried to save off the value of the XMM register I used, and the docs I have say that the movq and movdq instructions don't affect any flags.

As far as the CPUID, you're right... I left that part of the code out but I am definitely planning on using this only if the machine has SSE2.

Andi> The RAID code has some examples on how to use SSE2 in the Andi> kernel correctly.

Hmm, they save cr0 and do a clts, and then restore cr0 when they're done. For my education, can you explain why?

Andi> Better is probably to use CMPXCHG8, which avoids all of Andi> this.

OK, thanks.

- Roland

#3 lore raw
In reply to Andi Kleen

Andi> Better is probably to use CMPXCHG8, which avoids all of Andi> this.

Sorry to follow up again so soon, but I just looked up CMPXCHG8, and I don't see how to use it to write to write-only device memory. Can you elaborate a little?

Thanks,
Roland