XEN-ARM定时器管理算法简要总结
/* XEN-ARM的定时器优先队列管理算法采用的是最小堆。关于最小堆的知识,请参考 《算法导论》第二版第6章堆。 下面是简要流程。欢迎讨论 */ /*初始化定时器*/ void __init timer_init(void) { static struct timer *dummy_heap; int i; open_softirq(TIMER_SOFTIRQ, timer_softirq_action); /* * All CPUs initially share an empty dummy heap. Only those CPUs that * are brought online will be dynamically allocated their own heap. */ SET_HEAP_SIZE(&dummy_heap, 0); SET_HEAP_LIMIT(&dummy_heap, 0); for ( i = 0; i < NR_CPUS; i++ ) { spin_lock_init(&timers[i].lock); timers[i].heap = &dummy_heap; } } /* 当软中断发生时,函数执行 在定时器优先队列中查找满足expires的定时器,从队列中摘除,然后执行之 */ static void timer_softirq_action(void) { int cpu = smp_processor_id(); struct timer *t, **heap; s_time_t now; void (*fn)(void *); void *data; DPRINTK(5, "%s:%d\n", __FUNCTION__, __LINE__); spin_lock_irq(&timers[cpu].lock); do { heap = timers[cpu].heap; now = NOW(); //以此取定时器优先队列中最优先定时器 //然后执行其过程 while ( (GET_HEAP_SIZE(heap) != 0) && ( (t = heap[1])->expi...