asmlinkage and __sched are just macro definitions which use gcc function attributes to supply further instructions to the compiler. asmlinkage is architecture specific. __sched is not. On a 32 bit x86 system, asmlinkage void __sched schedule(void) expands to CPP_ASMLINKAGE __attribute__((regparm(0))) void __attribute__((__section__(".sched.text"))) schedule(void).
CPP_ASMLINKAGE is either null (if __cplusplus is not defined) or it's "extern C" (if it is).
THE LONG VERSION
__sched is a macro which uses a gcc function attribute extension to tell the compiler in which section (of the binary) to place the generated code (instead of the usual text section).
include/linux/sched.h:
What's the purpose of this? It's used to mark scheduler-related kernel functions. When walking the stack looking for a wchan (wait channel, i.e. the kernel function which caused a process to sleep/block), this makes it easy to skip the scheduler stuff. This is done using in_sched_functions(), which tests a function's address to see if it lies within the .sched.text section.
include/linux/sched.h:
kernel/sched.c:
In case you're interested, here's an implementation of get_wchan(). It's architecture specific code, so what follows is the 32bit x86 version. It returns 0 if the process is running or if it fails some basic sanity checks (pointer out of stack bounds, for example), and returns non-zero when it finds the first non-scheduler function.
arch/x86/kernel/process_32.c:
asmlinkage is an architecture specific macro which also uses a gcc function attribute extension, in this case to insure that the compiler passes all arguments on the stack, without using any registers. This is the 32 bit x86 definition (along with related macros and comments which should help shed light on its purpose).
arch/x86/include/asm/linkage.h:
All linux code quoted above was taken from the lastest tree at git.kernel.org.
---------- Post updated at 09:13 AM ---------- Previous update was at 08:55 AM ----------
Quote:
Originally Posted by ygemici
asmlinkage tells the compiler to pass parameters will be get from stack(it is local) area therefore does not looked in registers.(its good optimization for more fast).
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
Last edited by alister; 06-27-2011 at 10:43 AM..
These 2 Users Gave Thanks to alister For This Post:
In the below awk syntax, what does the value '1' signify?
awk '{....}1' file
some eg:
awk '{gsub(/]/,"")}1'
awk 'BEGIN{ORS=""}1'
awk '{ORS=(!(NR%5)?"":"\n")}1' (4 Replies)
Can anyone explain me the usage of momentary press, press and hold, Reset.. I usually use cold boot option which is used to boot the system.
Any help on the other options is really helpful
thanks in advance (5 Replies)
Hi All,
I recently downloaded the Linux kernel source code, added them all to a project in MS VC++ and plan to read through it so that I can improve the way I code, read/understand a large code database and hopefully contribute something to the development of the Linux OS.
I have taken a... (3 Replies)
I was going through the Linux code, i stuck with few inline assembly language code,
I have tried online but in vain. Any help is much appreciated. Thanks.
/* how to get the thread information struct from C */
static inline struct thread_info *current_thread_info(void)
{
struct... (3 Replies)