Quote:
Originally Posted by alister
I believe you are absolutely mistaken regarding this being a performance optimization. The cpu registers are the fastest, operating system-visible processor-storage locations available, faster than any level of cache and most definitely faster than main memory (RAM). Performance optimizations typically attempt to stuff as many things into registers as possible.
I'm not a big hardware person, but if I'm not mistaken, the x86 32bit architecture has comparitively few registers. asmlinkage is a workaround for this. Note that the stack is not used for this purpose on any other platform. Except for x86 32-bit which includes the gcc function attribute code in the definition of asmlinkage, by default asmlinkage is nothing more than "extern C".
Regards,
Alister
generally you are right.registers are faster therefore are part of the microprocessor.yes stack access is slower than register access.
Additional, CPU often access the stack and therefore stack(return addres of functions,parameters,registers,tmp infos,local variables..) datas usually is
saved in processor's cache.however cpu registers are very fast beceause of registers are very near and wired directly alu.So I meant just optimization not fast my fault.
i want to add some information about this issue.
asmlinkage tells to compiler that the arguments are on the stack(gcc takes it (i386 specific __attribute__((regparm(0))) and related in below asm code)
(actually,is a tag for assembly code convention for compiler (like asm/nasm/..))
# define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) provides like about below..
* userspace application executes
* (c) library routines puts arguments in registers from userspace.
( about register i want to tell something , since Linux 2.3.31 that is supported six system call parameters,but before
linux could handle 4(for some ver..5) system call parametres, if more than four arguments are needed, they are lef on the stack but i mentioned for new
version)
* enter kernel mode (executing trap --> int 0x80/sysenter) and executed kernel syscall handler(system_call() f)
* save current syscall number to eax.
* executed SAVE_ALL macro (%macro SAVE_ALL)
1) save address of kernel data(ds) and extra segment(to es)
2) all arguments(ebx,ecx,edx,esi,edi,ebp actually correct order will be reverse of this for C function call ) saves to stack
3) copy user_data_segment to ds register.
* %endmacro
* call (C) function (arguments are passed on the stack to c function (with asmlinkage))
* RESTORE_ALL(restores ebx, ecx, edx, esi, edi, ebp, eax, ds, es) and then go back to usermode (ret)
And asmlinkage format is like..
On i386
__attribute__((regparm(0)))
On ia64
__attribute__((syscall_linkage))
regards
ygemici