[haiku-development] Re: killing atomic syscalls?

  • From: Michael Crawford <mdcrawford@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 25 Feb 2015 20:06:55 -0800

I'm not familiar with the code in question, but in general if
something can be done in userspace rather than in a system call, it
would be a huge win.

System calls are in general implemented by executing an instruction
which is illegal in userspace.  An exception is taken, _all_ of the
registers are saved on the stack, a dispatch table is used to
determine what kernel function to call to carry out that system call's
work.  Upon return, all those registers are restored from the
exception stack.
Michael David Crawford, Consulting Software Engineer
mdcrawford@xxxxxxxxx
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.


On Wed, Feb 25, 2015 at 8:00 PM, kallisti5 <kallisti5@xxxxxxxxxxx> wrote:
> It looks like after Paweł's C++11 work, we don't need the atomic syscalls
> anymore?
>
>
> The main reason for asking is I attempted an arm (Raspberry Pi + u-boot)
> bootstrap and ran into:
>
> .
> .
> In file included from
> /home/kallisti5/Code/haiku/src/system/libroot/os/atomic.c:7:0:
> /home/kallisti5/Code/haiku/headers/os/support/SupportDefs.h:290:1: note:
> previous definition of 'atomic_test_and_set64' was here
>  atomic_test_and_set64(int64* value, int64 newValue, int64 testAgainst)
>  ^
> /home/kallisti5/Code/haiku/src/system/libroot/os/atomic.c:82:1: error:
> redefinition of 'atomic_add64'
>  atomic_add64(int64 *value, int64 addValue)
>  ^
> In file included from
> /home/kallisti5/Code/haiku/src/system/libroot/os/atomic.c:7:0:
> /home/kallisti5/Code/haiku/headers/os/support/SupportDefs.h:299:1: note:
> previous definition of 'atomic_add64' was here
>  atomic_add64(int64* value, int64 addValue)
>  ^
> /home/kallisti5/Code/haiku/src/system/libroot/os/atomic.c:89:1: error:
> redefinition of 'atomic_and64'
>  atomic_and64(int64 *value, int64 andValue)
>  ^
> In file included from
> /home/kallisti5/Code/haiku/src/system/libroot/os/atomic.c:7:0:
> /home/kallisti5/Code/haiku/headers/os/support/SupportDefs.h:306:1: note:
> previous definition of 'atomic_and64' was here
>  atomic_and64(int64* value, int64 andValue)
>  ^
> /home/kallisti5/Code/haiku/src/system/libroot/os/atomic.c:96:1: error:
> redefinition of 'atomic_or64'
>  atomic_or64(int64 *value, int64 orValue)
>  ^
> .
> .
>
>
> After a little digging I found:
> http://cgit.haiku-os.org/haiku/log/?qt=range&q=721a07a+%5Eae18461
>
> "No reason not to use GCC atomic support on non-x86 archs."
>
> "If GCC knows what these functions are actually doing the resulting
> code can be optimized better what is especially noticeable in case of
> invocations of atomic_{or,and}() that ignore the result. Obviously,
> everything is inlined what also improves performance."
>
> Usage: (note most are commented out)
>
> kallisti5@eris haiku :) $ grep -R "ATOMIC64_FUNCS_ARE_SYSCALLS" src/
> headers/
> src/system/kernel/arch/arm/arch_atomic64.cpp:#ifdef
> ATOMIC64_FUNCS_ARE_SYSCALLS
> src/system/kernel/arch/arm/arch_atomic64.cpp:#endif /*
> ATOMIC64_FUNCS_ARE_SYSCALLS */
> src/system/libroot/os/atomic.c:#ifdef ATOMIC64_FUNCS_ARE_SYSCALLS
> src/system/libroot/os/atomic.c:#endif   /* ATOMIC64_FUNCS_ARE_SYSCALLS */
> headers/build/private/kernel/syscalls.h:// #ifdef
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/build/private/kernel/syscalls.h:// #endif       //
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/arm/arch_config.h:#define
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/m68k/arch_config.h://#define
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/mipsel/arch_config.h:#define
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/ppc/arch_config.h:#define
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/x86/arch_config.h://#define
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/x86_64/arch_config.h://#define
> ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/syscalls.h:#ifdef ATOMIC64_FUNCS_ARE_SYSCALLS
> headers/private/system/syscalls.h:#endif        //
> ATOMIC64_FUNCS_ARE_SYSCALLS
>
> kallisti5@eris haiku :) $ grep -R "ATOMIC_FUNCS_ARE_SYSCALLS" src/ headers/
> src/system/boot/arch/arm/kernel_stubs.cpp:#ifdef ATOMIC_FUNCS_ARE_SYSCALLS
> src/system/boot/arch/arm/kernel_stubs.cpp:#endif
> /*ATOMIC_FUNCS_ARE_SYSCALLS*/
> src/system/kernel/arch/arm/arch_atomic32.cpp:#ifdef
> ATOMIC_FUNCS_ARE_SYSCALLS
> src/system/kernel/arch/arm/arch_atomic32.cpp:#endif /*
> ATOMIC_FUNCS_ARE_SYSCALLS */
> src/system/libroot/os/atomic.c:#ifdef ATOMIC_FUNCS_ARE_SYSCALLS
> src/system/libroot/os/atomic.c:#endif   /* ATOMIC_FUNCS_ARE_SYSCALLS */
> headers/build/private/kernel/syscalls.h:// #ifdef ATOMIC_FUNCS_ARE_SYSCALLS
> headers/build/private/kernel/syscalls.h:// #endif       //
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/kernel/arch/sh4/arch_cpu.h:#define ATOMIC_FUNCS_ARE_SYSCALLS
> 1
> headers/private/system/arch/arm/arch_config.h:#define
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/m68k/arch_config.h://#define
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/mipsel/arch_config.h://#define
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/ppc/arch_config.h://#define
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/x86/arch_config.h://#define
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/arch/x86_64/arch_config.h://#define
> ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/syscalls.h:#ifdef ATOMIC_FUNCS_ARE_SYSCALLS
> headers/private/system/syscalls.h:#endif        // ATOMIC_FUNCS_ARE_SYSCALLS
>
>
> I've never been great at the kernel syscall stuff, so posting here :-)
>
>  -- Alex
>

Other related posts: