Search code examples
linuxschedulingscheduler

Why passing parameters to `__switch_to` function through registers?


Why is the function __switch_to declared as taking parameters through registers (and not by convention through the stack)?

extern void FASTCALL(__switch_to(struct task_struct *prev, struct task_struct *next));

It might be relevant for the case when we return from it into ret_from_fork and not to label 1? how?

source code: https://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/include/asm-i386/system.h

(yes, I know it's old by I wondering what's the reason)


Solution

  • In short, when you're talking about 'the stack' you're in fact talking about 'the stack of the current process' and in all normal situations you don't need to specify this. But for __switch_to(), there is no such thing as 'the current process' since the purpose of this function is to switch from one process to another. There is a current process on entry and another on exit but (or at least it seems to be so) but between the two it's only the operating executing instructions to save the CPU context of the old process (on its stack) and restore the CPU context of the new process (from its stack).

    Using the stack will just bring complications.

    Now, I don't think it's not possible to do so, it's just useless.