调度器47—上下文切换

1. current上下文切换时刻

//调用路径
__schedule //整个切换都是关local irq的
    context_switch //函数最后才调用它
        switch_to
            cpu_switch_to

//cpu_switch_to 实现
//arch/arm64/include/asm/current.h
/*
 * We don't use read_sysreg() as we want the compiler to cache the
 * value where possible.
 */
static __always_inline struct task_struct *get_current(void)
{
    unsigned long sp_el0;

    asm ("mrs %0, sp_el0" : "=r" (sp_el0));

    return (struct task_struct *)sp_el0;
}
#define current get_current()

//arch/arm64/kernel/entry.S
SYM_FUNC_START(cpu_switch_to)
    msr    sp_el0, x1  # current 从 prev task 切为 next task

 

posted on 2023-03-20 11:00  Hello-World3  阅读(111)  评论(0编辑  收藏  举报

导航