中断学习之timer_interrupt x86实现

以2.6.23为例

 

irqreturn_t timer_interrupt(int irq, void *dev_id)
	=>do_timer_interrupt_hook();
		=>global_clock_event->event_handler(global_clock_event);//dev->event_handler = tick_handle_periodic;
			=>tick_handle_periodic
				=>tick_periodic(cpu);
					=>tick_next_period = ktime_add(tick_next_period, tick_period);
					=>do_timer(1);//更新jiffies_64和墙上时间
						=>jiffies_64 += ticks;
						=>update_times(ticks);
							=>update_wall_time();//Uses the current clocksource to increment the wall time
							=>calc_load(ticks);
					=>update_process_times(user_mode(get_irq_regs()));
						=>struct task_struct *p = current;
						int cpu = smp_processor_id();
						=>if (user_tick)
							account_user_time(p, jiffies_to_cputime(1));
						else
							account_system_time(p, HARDIRQ_OFFSET, jiffies_to_cputime(1));
						=>run_local_timers();
							=>raise_softirq(TIMER_SOFTIRQ);
							=>softlockup_tick();
						=>scheduler_tick();
							=>__update_rq_clock(rq);
							=>update_cpu_load(rq);
							=>curr->sched_class->task_tick(rq, curr);
                                =>void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
                                    =>struct sched_entity *se = &curr->se;
                                    =>for_each_sched_entity(se) 
                                        cfs_rq = cfs_rq_of(se);
                                        entity_tick(cfs_rq, se, queued);
                                            =>update_curr(cfs_rq);

				=>next = ktime_add(dev->next_event, tick_period);
				for (;;) {
					if (!clockevents_program_event(dev, next, ktime_get()))
						return;
					tick_periodic(cpu);
					next = ktime_add(next, tick_period);
				}

对于APIC的SMP系统

void apic_timer_interrupt(void)//alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
    apic_timer_interrupt smp_apic_timer_interrupt
    =>void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs)
        ack_APIC_irq();
        irq_enter();
        local_apic_timer_interrupt();
            =>static void local_apic_timer_interrupt(void)
                int cpu = smp_processor_id();
	            struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
                evt->event_handler(evt);
                    =>void hrtimer_interrupt(struct clock_event_device *dev)
        irq_exit();

 

__init ep93xx_timer_init(void)可以作为一个案例

Linux 时钟中断处理(一)
https://blog.csdn.net/bgao86/article/details/51793853

Linux时间管理之hardware
http://blog.chinaunix.net/uid-24774106-id-3902906.html

Linux时间子系统(一) -- 原理    博客不错,包括进程调度
https://blog.csdn.net/flaoter/article/details/77413163

Linux时间子系统之一:clock source(时钟源)
https://blog.csdn.net/DroidPhone/article/details/7975694

Linux时间子系统之(十二):periodic tick
http://www.wowotech.net/timer_subsystem/periodic-tick.html

linux的HZ, Tick, xtime, Jiffies, RTC && mdelay() 与msleep()的区别
https://blog.csdn.net/zhandoushi1982/article/details/5536210

你可能感兴趣的:(linux内核)