Chinaunix首页 | 论坛 | 博客
  • 博客访问: 766683
  • 博文数量: 247
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 501
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-12 21:53
个人简介

系统未建立

文章分类

全部博文(247)

文章存档

2021年(1)

2020年(3)

2019年(5)

2018年(3)

2017年(44)

2016年(75)

2015年(52)

2014年(63)

2013年(1)

我的朋友

分类: LINUX

2016-02-14 14:29:41

原文地址:preempt_count详解 作者:gtkchen

当从内核态返回到用户态的时候,要检查是否进行调度,而调度要看两个条件:
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.总开关,第一位。
阅读(1125) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~