diff --git a/kernel/driver/timers/timer.c b/kernel/driver/timers/timer.c index 84f3e014..108decb8 100644 --- a/kernel/driver/timers/timer.c +++ b/kernel/driver/timers/timer.c @@ -7,6 +7,9 @@ struct timer_func_list_t timer_func_head; +// 定时器循环阈值,每次最大执行10个定时器任务 +#define TIMER_RUN_CYCLE_THRESHOLD 10 + void test_timer() { printk_color(ORANGE, BLACK, "(test_timer)"); @@ -29,17 +32,20 @@ void do_timer_softirq(void *data) { struct timer_func_list_t *tmp = container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list); - + int cycle_count = 0; while ((!list_empty(&timer_func_head.list)) && (tmp->expire_jiffies <= timer_jiffies)) { timer_func_del(tmp); tmp->func(tmp->data); kfree(tmp); - tmp = container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list); - } - + ++cycle_count; + // 当前定时器达到阈值 + if(cycle_count == TIMER_RUN_CYCLE_THRESHOLD) + break; + tmp = container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list); + } } /** diff --git a/kernel/driver/timers/timer.h b/kernel/driver/timers/timer.h index a13d47b2..07e0a422 100644 --- a/kernel/driver/timers/timer.h +++ b/kernel/driver/timers/timer.h @@ -7,7 +7,7 @@ uint64_t volatile timer_jiffies = 0; // 系统时钟计数 // 计算接下来n毫秒对应的系统时间片 -#define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + expire_ms / 5 + (expire_ms % HPET0_INTERVAL ? 1 : 0)) +#define cal_next_n_ms_jiffies(expire_ms) (timer_jiffies + expire_ms / 5 + ((expire_ms % HPET0_INTERVAL) ? 1 : 0)) void timer_init();