preempt_count详解

当从内核态返回到用户态的时候,要检查是否进行调度,而调度要看两个条件:
1.preempt_count是否为0
2.rescheduled是否置位
 
ret_from_exception:
 preempt_stop(CLBR_ANY)
ret_from_intr:
 GET_THREAD_INFO(%ebp)
check_userspace:
 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
 movb PT_CS(%esp), %al
 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
 cmpl $USER_RPL, %eax
 jb resume_kernel  # not returning to v8086 or userspace
ENTRY(resume_userspace)
 LOCKDEP_SYS_EXIT
  DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
     # setting need_resched or sigpending
     # between sampling and the iret
 movl TI_flags(%ebp), %ecx
 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
     # int/exception return?
 jne work_pending
 jmp restore_all
END(ret_from_exception)
#ifdef CONFIG_PREEMPT
ENTRY(resume_kernel)
 DISABLE_INTERRUPTS(CLBR_ANY)
  cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
 jnz restore_nocheck
need_resched:
 movl TI_flags(%ebp), %ecx # need_resched set ?
 testb $_TIF_NEED_RESCHED, %cl
 jz restore_all
 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
 jz restore_all
  call preempt_schedule_irq
 jmp need_resched
END(resume_kernel)
#endif
 CFI_ENDPROC
检查preempt_count的时候,是统一检查是否为0,也就是说, 有4个条件限制,可能不能够进行调度。
1.preempt_disable()
 
#define preempt_disable() \
do { \
 inc_preempt_count(); \
 barrier(); \
} while (0)
 
#define inc_preempt_count() add_preempt_count(1)
 
会在preempt_enable中释放
 
2.add_preempt_count(HARDIRQ_OFFSET)
是在irq_enter()中调用的,记录进入硬件中断处理的次数(计数),
会在irq_exit()中释放
 
3.__local_bh_disable((unsigned long)__builtin_return_address(0));
在do_softirq中调用的,
static inline void __local_bh_disable(unsigned long ip)
{
 add_preempt_count(SOFTIRQ_OFFSET);
 barrier();
}
 
4.总开关,第一位。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值