提交 7bda799f 编写于 作者: Y Yunfeng Ye 提交者: Zheng Zengkai

tick/sched: Reduce seqcount held scope in tick_do_update_jiffies64()

mainline inclusion
from mainline-5.11-rc1
commit 94ad2e3c
category: feature
feature: Deep isolation
bugzilla: https://gitee.com/openeuler/kernel/issues/I4N00D
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=94ad2e3cedb82af034f6d97c58022f162b669f9b

--------------------------------

If jiffies are up to date already (caller lost the race against another
CPU) there is no point to change the sequence count. Doing that just forces
other CPUs into the seqcount retry loop in tick_nohz_next_event() for
nothing.

Just bail out early.

[ tglx: Rewrote most of it ]
Signed-off-by: NYunfeng Ye <yeyunfeng@huawei.com>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20201117132006.462195901@linutronix.deReviewed-by: NChao Liu <liuchao173@huawei.com>
Reviewed-by: NChen Hui <judy.chenhui@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 aedecd44
...@@ -84,38 +84,35 @@ static void tick_do_update_jiffies64(ktime_t now) ...@@ -84,38 +84,35 @@ static void tick_do_update_jiffies64(ktime_t now)
/* Reevaluate with jiffies_lock held */ /* Reevaluate with jiffies_lock held */
raw_spin_lock(&jiffies_lock); raw_spin_lock(&jiffies_lock);
if (ktime_before(now, tick_next_period)) {
raw_spin_unlock(&jiffies_lock);
return;
}
write_seqcount_begin(&jiffies_seq); write_seqcount_begin(&jiffies_seq);
delta = ktime_sub(now, last_jiffies_update); last_jiffies_update = ktime_add(last_jiffies_update, tick_period);
if (delta >= tick_period) {
delta = ktime_sub(delta, tick_period); delta = ktime_sub(now, tick_next_period);
last_jiffies_update = ktime_add(last_jiffies_update, if (unlikely(delta >= tick_period)) {
tick_period); /* Slow path for long idle sleep times */
s64 incr = ktime_to_ns(tick_period);
/* Slow path for long timeouts */ ticks = ktime_divns(delta, incr);
if (unlikely(delta >= tick_period)) {
s64 incr = ktime_to_ns(tick_period);
ticks = ktime_divns(delta, incr); last_jiffies_update = ktime_add_ns(last_jiffies_update,
incr * ticks);
}
last_jiffies_update = ktime_add_ns(last_jiffies_update, do_timer(++ticks);
incr * ticks);
} /*
do_timer(++ticks); * Keep the tick_next_period variable up to date. WRITE_ONCE()
* pairs with the READ_ONCE() in the lockless quick check above.
*/
WRITE_ONCE(tick_next_period,
ktime_add(last_jiffies_update, tick_period));
/*
* Keep the tick_next_period variable up to date.
* WRITE_ONCE() pairs with the READ_ONCE() in the lockless
* quick check above.
*/
WRITE_ONCE(tick_next_period,
ktime_add(last_jiffies_update, tick_period));
} else {
write_seqcount_end(&jiffies_seq);
raw_spin_unlock(&jiffies_lock);
return;
}
write_seqcount_end(&jiffies_seq); write_seqcount_end(&jiffies_seq);
raw_spin_unlock(&jiffies_lock); raw_spin_unlock(&jiffies_lock);
update_wall_time(); update_wall_time();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册