gpt4 book ai didi

linux-kernel - 是否应该只在 SMP 系统中的一个内核上调用 do_timer()?

转载 作者:行者123 更新时间:2023-12-01 00:48:22 25 4
gpt4 key购买 nike

我知道 do_timer 负责更新 jiffies 计数器。因此,我的问题是,它可以在不同的内核上执行还是始终在发生计时器滴答的同一内核上执行?

最佳答案

让我在谷歌搜索和阅读代码后回答我自己的问题。

do_timer() 应该在 ID 保存在 tick_do_timer_cpu 中的 CPU 上调用多变的。
kernel/time/tick-common.c

/*
* tick_do_timer_cpu is a timer core internal variable which holds the CPU NR
* which is responsible for calling do_timer(), i.e. the timekeeping stuff.This
* variable has two functions:
*
* 1) Prevent a thundering herd issue of a gazillion of CPUs trying to grab the
* timekeeping lock all at once. Only the CPU which is assigned to do the
* update is handling it.
*
* 2) Hand off the duty in the NOHZ idle case by setting the value to
* TICK_DO_TIMER_NONE, i.e. a non existing CPU. So the next cpu which looks
* at it will take over and keep the time keeping alive. The handover
* procedure also covers cpu hotplug.
*/


tick_do_timer_cpu根据 tick_periodic() 中的当前 CPU ID 检查或在 tick_sched_do_timer() .如果当前 CPU 相同 do_timer()否则不调用。
static void tick_periodic(int cpu)
{
if (tick_do_timer_cpu == cpu) {
write_seqlock(&jiffies_lock);

/* Keep track of the next tick event */
tick_next_period = ktime_add(tick_next_period, tick_period);

do_timer(1);
write_sequnlock(&jiffies_lock);
update_wall_time();
}

update_process_times(user_mode(get_irq_regs()));
profile_tick(CPU_PROFILING);
}`

这样 jiffies 管理是在 SMP 系统的一个核心上完成的。

关于linux-kernel - 是否应该只在 SMP 系统中的一个内核上调用 do_timer()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32819011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com