count_inc() preempt_count_add(1) #define preempt_count_dec() preempt_count_sub(1) static __always_inline void __preempt_count_add(int val) { raw_cpu_add_4(__preempt_count, val); } static __always_inline void __preempt_count_sub(int val) { raw_cpu_add_4(__preempt_count, -...
# define preemptible() (preempt_count() == 0 && !irqs_disabled()) static void __sched notrace preempt_schedule_common(void) { do { __preempt_count_add(PREEMPT_ACTIVE); __schedule(); __preempt_count_sub(PREEMPT_ACTIVE); /* * Check again in case we missed a preemption opportunity *...
= PREEMPT_DISABLE_OFFSET)#definepreempt_count_add(val) __preempt_count_add(val)#definepreempt_count_sub(val) __preempt_count_sub(val)#definepreempt_count_dec_and_test() __preempt_count_dec_and_test()#define__preempt_count_inc() __preempt_count_add(1)#define__preempt_count_dec() __p...
dec_preempt_count(); \ } while (0) #define inc_preempt_count() add_preempt_count(1) #define dec_preempt_count() sub_preempt_count(1) #define add_preempt_count(val) do { preempt_count() += (val); } while (0) #define sub_preempt_count(val) do { preempt_count() -= (val); ...
(PREEMPT_ACTIVE);local_irq_enable();/*开启中断*/schedule();/*内核调度,用于内核抢占,即运行优先级较高的任务*/local_irq_disable();/*关闭中断*/sub_preempt_count(PREEMPT_ACTIVE);/*再次检查,避免在调度与现在时刻之间失去抢占机会*/barrier();/*加内存屏障*/}while(unlikely(test_thread_flag(TIF_...
sub_preempt_count_notrace(PREEMPT_ACTIVE);/** Check again in case we missed a preemption opportunity * between schedule and now.*/barrier(); }while(need_resched()); } 可以看到这里进入函数起始,便对当前线程的preempt_count进行了判断,根据上面的介绍,当内核处理任何一个上下文中时,preempt_count均不...
再来看看代码中关于preempt_count的各个字段的定义: ---...: 0x00100000 * PREEMPT_ACTIVE: 0x00200000 */ #define PREEMPT_BITS 8 #define SOFTIRQ_...
sub_preempt_count(PREEMPT_ACTIVE); barrier(); } while (unlikely(test_thread_flag(TIF_NEED_RESCHED))); } 调度函数schedule会检测进程的 preempt_counter 是否很大,避免普通调度时又执行内核抢占调度。 (2)软中断返回执行抢占调度 在打开页出错函数pagefault_enable和软中断底半部开启函数local_bh_enable中,会...
- __preempt_count_sub(PREEMPT_ACTIVE); - barrier(); + preempt_active_exit(); } while (need_resched()); } EXPORT_SYMBOL_GPL(preempt_schedule_context); @@ -2999,17 +2994,11 @@ asmlinkage __visible void __sched preempt_schedule_irq(void) ...
#define sub_preempt_count(val) do { preempt_count() -= (val); } while (0) #define preempt_count() (current_thread_info()->preempt_count) 三、发生抢占的时机 linux进程调度的核心函数是schedule(),进程调度就是在这里做的。 schedule的调用分为主动调用和被动调用。