Re: [PATCH] sched/cputime: correct account of irqtime

From: Peter Zijlstra
Date: Wed Oct 14 2020 - 09:02:48 EST


On Mon, Oct 12, 2020 at 09:50:44PM +0800, Pingfan Liu wrote:
> __do_softirq() may be interrupted by hardware interrupts. In this case,
> irqtime_account_irq() will account the time slice as CPUTIME_SOFTIRQ by
> mistake.
>
> By passing irqtime_account_irq() an extra param about either hardirq or
> softirq, irqtime_account_irq() can handle the above case.

I'm not sure I see the scenario in which it goes wrong.

irqtime_account_irq() is designed such that we're called with the old
preempt_count on enter and the new preempt_count on exit. This way we'll
accumuate the delta to the previous context.

> @@ -68,7 +68,7 @@ void irqtime_account_irq(struct task_struct *curr)
> */
> if (hardirq_count())
> irqtime_account_delta(irqtime, delta, CPUTIME_IRQ);
> - else if (in_serving_softirq() && curr != this_cpu_ksoftirqd())
> + else if (in_serving_softirq() && curr != this_cpu_ksoftirqd() && !hardirq)
> irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ);
> }