xchg/cmpxchg defined in wrong place?
Hello Linux Kernel Guru's,
After surveying all the arches that define __HAVE_ARCH_CMPXCHG:
./include/asm-alpha/system.h:#define __HAVE_ARCH_CMPXCHG 1 ./include/asm-i386/system.h:#define __HAVE_ARCH_CMPXCHG 1 ./include/asm-ia64/system.h:#define __HAVE_ARCH_CMPXCHG 1 ./include/asm-ppc/system.h:#define __HAVE_ARCH_CMPXCHG 1 ./include/asm-sparc64/system.h:#define __HAVE_ARCH_CMPXCHG 1
I've come to the conclusion xchg/cmpxchg definitions do NOT belong in system.h. AFAICT, all the above use Load Linked semantics (or in the i386 case, operation is atomic). In other words, xchg/cmpxchg are atomic operations. Shouldn't xchg/cmpxchg definitions live with other atomic operations - asm/atomic.h?
Currently, parisc __xchg lives in arch/parisc/kernel/setup.c. There is no way to inline xchg or cmpxchg for parisc at the moment. And given the dependendencies between asm/system.h, asm/spinlock.h, and asm/atomic.h, I'm not trying to inline them. Perhaps when the definitions formally move to atomic.h (or other more appropriate place).
And to add insult to injury, drivers/char/drm/drmP.h (the only visible consumer of __HAVE_ARCH_CMPXCHG) doesn't even explicitly include asm/system.h!
thanks,
grant
Grant Grundler wrote:
...
Quoted 1 line
Currently, parisc
__xchglives inarch/parisc/kernel/setup.c.
Sorry. I got this fact wrong: __xchg lives in arch/parisc/lib/bitops.c
__xchg_called_with_bad_pointer *is* defined in arch/parisc/kernel/setup.c. My understanding is this fuction in fact should NOT be defined. It's a tool to catch problems for architectures which can inline __xchg.
Neither item is material to my arguments for defining them in atomic.h.
grant
Grant Grundler
Unix Systems Enablement Lab
+1.408.447.7253
Quoted 8 lines
way to inline xchg or cmpxchg for parisc at the moment. And given the dependendencies between
asm/system.h,asm/spinlock.h, andasm/atomic.h, I'm not trying to inline them. Perhaps when the definitions formally move toatomic.h(or other more appropriate place).And to add insult to injury,
drivers/char/drm/drmP.h(the only visible consumer of__HAVE_ARCH_CMPXCHG) doesn't even explicitly includeasm/system.h!
Seems a reasonable thing to try and move to atomic.h yes
Quoted 1 line
Quoted 1 line · Alan Cox
Seems a reasonable thing to try and move to
atomic.hyes
ok. I'll take a whack at parisc arch and see what happens. If it's easy, I'll try the i386 arch as well - mostly to build more drivers as a sanity check.
thanks,
grant
Quoted 1 line · Grant Grundler
ok. I'll take a whack at parisc arch and see what happens.
This was easy. Was even able to build/link with DRM and all the related drivers. Code change committed to parisc-linux CVS:
o removes bogus definition of __xchg_called_with_bad_pointer from setup.c
o definitions follow sparc64 model except I didn't try to inline all of this mess.
o added __xchgNN() and __cmpxchg_uNN() functions to bitops.c and declared them in parisc_ksyms.c for CONFIG_MODULES support.
o added "include <asm/atomic.h>" to arch/parisc/kernel/semaphore.c to make sure it gets the xchg() macro definition.
TODO: DRM should explicitly include asm/atomic.h to pick up
#define __HAVE_ARCH_CMPXCHG directly.
Quoted 2 lines
If it's easy, I'll try the i386 arch as well - mostly to build more drivers as a sanity check.
I moved all the xchg/cmpxchg related code from include/asm-i386/system.h to include/asm-i386/atomic.h and built an x86 kernel (natively) but didn't boot it. Booting the kernel shouldn't be necessary since mis-use will result in a linker error (xchg undefined).
I used 2.4.0-test10 since it was handy. Once I get newer Linus tree, I can cut/paste again and submit the patch to l-k. Should be able to do this in the next couple of days unless someone tells me they've done it already.
thanks,
grant
Quoted 4 lines · Grant Grundler
I moved all the xchg/cmpxchg related code from
include/asm-i386/system.htoinclude/asm-i386/atomic.hand built an x86 kernel (natively) but didn't boot it. Booting the kernel shouldn't be necessary since mis-use will result in a linker error (xchg undefined).
I've always liked this one:
Theory and Practice, distinguished: In Theory, there is no difference between Theory and Practice; in Practice, there always is ...
I'm going to try spinning up a G50, and sniffing at a K220 for parisc linux ... 735/125 on the way in ... I'd like to leave HP-UX on the K220 and 'dual boot' -- but it is such a pain to hook a console up -- Any thoughts on an OS/2 style Boot Manager leaving 'next boot' semaphore flags behind ...
-- Russ
Re: Dual Boot
R P Herrold wrote:
...
Quoted 5 lines
I'm going to try spinning up a G50, and sniffing at a K220 for parisc linux ... 735/125 on the way in ... I'd like to leave HP-UX on the K220 and 'dual boot' -- but it is such a pain to hook a console up -- Any thoughts on an OS/2 style Boot Manager leaving 'next boot' semaphore flags behind ...
It's hard to hook up a serial console on K220?!
Under HPUX, "setboot" command can set the primary boot path so it can reboot from any disk/lan you want. You would have to write a similar program for parisc-linux to poke stuff into NVRAM. It might be a PDC call to do it; I don't know. But it's doable.
grant
Grant Grundler
Unix Systems Enablement Lab
+1.408.447.7253