Kernelspace C11 atomics for MIPS
Ed Schouten
ed at 80386.nl
Mon Jun 3 20:16:00 UTC 2013
Hey Warner,
After playing around a bit I managed to get qemu user mode emulation
for mips64 working on my workstation. Apart from a stupid thinko
(__sync_fetch_and_sub() did B - A instead of A - B), the code managed
to survive the following test, which calls the stdatomic library
functions with random parameters:
http://80386.nl/pub/stdatomic-fuzzer.txt
I'll see if I can push this tool into the tree after polishing it up a
bit. Unfortunately it only tests the logical aspects of the routines
-- not whether the routines are actually atomic.
2013/6/3 Warner Losh <imp at bsdimp.com>:
> The number of necessary syncs varies by processor type. There's also newer synchronization instructions that make this as efficient as possible for all mips32r2 and mips64r2-based machines. Older Caviums, at least and maybe newer ones, also have their own variants. What you have will mostly work for the processors we have to support. mips_sync could therefore be better. Doing it before AND after seems like overkill as well. Since sync is a fairly performance killing assembler instruction, how would you feel about allowing optimizations?
>
> This is my biggest single concern about the patch, but it also my current biggest concern about the MIPS atomic operators in general.
I have to confess, that's exactly the part I know very little about.
The code I wrote is largely based on the code in <machine/atomic.h>.
The mips_sync() function has been copied over almost literally. I
think tuning this could be done separately.
Regarding calling mips_sync() before and after. I think we always have
to call it before we perform the action (for example if the atomic
call is used to implement an unlock). But indeed, afterwards makes
little sense. We would only need to perform a barrier at the compiler
level -- not the memory level. It wouldn't make sense to add this
explicitly, because these are separate functions in a separate
compilation unit anyway.
Thoughts?
> I have some cavium gear I can easily test on, and some other stuff I can less-easily test on.
Awesome! At least testing it on Cavium would be nice. I've updated the
diff. Please refresh.
http://80386.nl/pub/mips-stdatomic.txt
One easy way to test this, would be to link the fuzzer source file
against the stdatomic.c file added by my patch and run that. The
source file should compile both in user+kernel now.
Thanks,
--
Ed Schouten <ed at 80386.nl>
More information about the freebsd-arch
mailing list