其他分享
首页 > 其他分享> > 调度器36—抢占

调度器36—抢占

作者:互联网

一、开关抢占函数

1. preempt_disable/preempt_enable

(1) 关抢占

//include/linux/preempt.h
#define preempt_disable() \
do { \
    preempt_count_inc(); \
    barrier(); \
} while (0)

#define preempt_count_inc() preempt_count_add(1) //include/linux/preempt.h

#define preempt_count_add(val)    __preempt_count_add(val) //include/linux/preempt.h

static inline void __preempt_count_add(int val) //arch/arm64/include/asm/preempt.h
{
    /* 使用的是 current->thread_info.preempt.count */
    u32 pc = READ_ONCE(current_thread_info()->preempt.count);
    pc += val;
    WRITE_ONCE(current_thread_info()->preempt.count, pc);
}

(2) 开抢占

#define preempt_enable() \
do { \
    barrier(); \
    if (unlikely(preempt_count_dec_and_test())) \
        __preempt_schedule(); \
} while (0)

使能 CONFIG_PREEMPTION 的情况下,开抢占后,若抢占计数减为0会触发一次调度

3. 只要对 current->thread_info.preempt.count 进行加减的函数都会起到开关抢占的功能,如关中断、关软中断。

 

二、抢占粒度


三、抢占作用时机


四、开关抢占的区别

 

Linux进程调度与抢占:https://www.cnblogs.com/hellokitty2/p/10741600.html

 

标签:count,info,抢占,val,36,调度,current,preempt
来源: https://www.cnblogs.com/hellokitty2/p/16382905.html