手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux 2.6如何使用时间中断来完成进程调度

[日期:2012-01-10] 来源:Linux社区  作者:raintungli [字体:大 中 小]

在__do_IRQ()的处理函数中,handle_IRQ_event (irq/handle.c)主要负责调用不同的中断信号所注册的函数。

  1. /** 
  2.  * handle_IRQ_event - irq action chain handler 
  3.  * @irq:    the interrupt number 
  4.  * @regs:   pointer to a register structure 
  5.  * @action: the interrupt action chain for this irq 
  6.  * 
  7.  * Handles the action chain of an irq event 
  8.  */  
  9. irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,  
  10.                  struct irqaction *action)  
  11. {  
  12.     irqreturn_t ret, retval = IRQ_NONE;  
  13.     unsigned int status = 0;  
  14.   
  15.     handle_dynamic_tick(action);  
  16.   
  17.     if (!(action->flags & IRQF_DISABLED))  
  18.         local_irq_enable_in_hardirq();  
  19.   
  20.     do {  
  21.         ret = action->handler(irq, action->dev_id, regs);  
  22.         if (ret == IRQ_HANDLED)  
  23.             status |= action->flags;  
  24.         retval |= ret;  
  25.         action = action->next;  
  26.     } while (action);  
  27.   
  28.     if (status & IRQF_SAMPLE_RANDOM)  
  29.         add_interrupt_randomness(irq);  
  30.     local_irq_disable();  
  31.   
  32.     return retval;  
  33. }  
其中struct irqaction 是就是每个不同的硬件中断所注册的处理函数

我们在来看看时间中断里所注册的处理函数,x86_64/kernel/time.c

  1. static struct irqaction irq0 = {  
  2.     timer_interrupt, IRQF_DISABLED, CPU_MASK_NONE, "timer", NULL, NULL  
  3. };  

timer_interrupt 函数

  1. static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)  
  2. {  
  3.     if (apic_runs_main_timer > 1)  
  4.         return IRQ_HANDLED;  
  5.     main_timer_handler(regs);  
  6. #ifdef CONFIG_X86_LOCAL_APIC   
  7.     if (using_apic_timer)  
  8.         smp_send_timer_broadcast_ipi();  
  9. #endif   
  10.     return IRQ_HANDLED;  
  11. }  
在 main_timer_handler 函数里,我们可以清楚的看到
  1. #ifndef CONFIG_SMP   
  2.     update_process_times(user_mode(regs));  
  3. #endif  
函数update_process_times 里显示的调用了 scheduler_tick
  1. /* 
  2.  * Called from the timer interrupt handler to charge one tick to the current  
  3.  * process.  user_tick is 1 if the tick is user time, 0 for system. 
  4.  */  
  5. void update_process_times(int user_tick)  
  6. {  
  7.     struct task_struct *p = current;  
  8.     int cpu = smp_processor_id();  
  9.   
  10.     /* Note: this timer irq context must be accounted for as well. */  
  11.     if (user_tick)  
  12.         account_user_time(p, jiffies_to_cputime(1));  
  13.     else  
  14.         account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1));  
  15.     run_local_timers();  
  16.     if (rcu_pending(cpu))  
  17.         rcu_check_callbacks(cpu, user_tick);  
  18.     scheduler_tick();  
  19.     run_posix_cpu_timers(p);  
  20. }  
我们可以看到在时间中断里会调用进程调度,并且在中断的上半部分,也就是不可被打断。linux
相关资讯       Linux基础教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款