Skip to content

Commit 763a744

Browse files
laoarPeter Zijlstra
authored andcommitted
sched: Don't account irq time if sched_clock_irqtime is disabled
sched_clock_irqtime may be disabled due to the clock source, in which case IRQ time should not be accounted. Let's add a conditional check to avoid unnecessary logic. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Michal Koutný <mkoutny@suse.com> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lore.kernel.org/r/20250103022409.2544-3-laoar.shao@gmail.com
1 parent 8722903 commit 763a744

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

kernel/sched/core.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -740,29 +740,31 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
740740
s64 __maybe_unused steal = 0, irq_delta = 0;
741741

742742
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
743-
irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time;
743+
if (irqtime_enabled()) {
744+
irq_delta = irq_time_read(cpu_of(rq)) - rq->prev_irq_time;
744745

745-
/*
746-
* Since irq_time is only updated on {soft,}irq_exit, we might run into
747-
* this case when a previous update_rq_clock() happened inside a
748-
* {soft,}IRQ region.
749-
*
750-
* When this happens, we stop ->clock_task and only update the
751-
* prev_irq_time stamp to account for the part that fit, so that a next
752-
* update will consume the rest. This ensures ->clock_task is
753-
* monotonic.
754-
*
755-
* It does however cause some slight miss-attribution of {soft,}IRQ
756-
* time, a more accurate solution would be to update the irq_time using
757-
* the current rq->clock timestamp, except that would require using
758-
* atomic ops.
759-
*/
760-
if (irq_delta > delta)
761-
irq_delta = delta;
746+
/*
747+
* Since irq_time is only updated on {soft,}irq_exit, we might run into
748+
* this case when a previous update_rq_clock() happened inside a
749+
* {soft,}IRQ region.
750+
*
751+
* When this happens, we stop ->clock_task and only update the
752+
* prev_irq_time stamp to account for the part that fit, so that a next
753+
* update will consume the rest. This ensures ->clock_task is
754+
* monotonic.
755+
*
756+
* It does however cause some slight miss-attribution of {soft,}IRQ
757+
* time, a more accurate solution would be to update the irq_time using
758+
* the current rq->clock timestamp, except that would require using
759+
* atomic ops.
760+
*/
761+
if (irq_delta > delta)
762+
irq_delta = delta;
762763

763-
rq->prev_irq_time += irq_delta;
764-
delta -= irq_delta;
765-
delayacct_irq(rq->curr, irq_delta);
764+
rq->prev_irq_time += irq_delta;
765+
delta -= irq_delta;
766+
delayacct_irq(rq->curr, irq_delta);
767+
}
766768
#endif
767769
#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
768770
if (static_key_false((&paravirt_steal_rq_enabled))) {

0 commit comments

Comments
 (0)