Re: [PATCH 4/5] irqtime: Move irqtime entry accounting after irq offset incrementation

From: Thomas Gleixner
Date: Tue Dec 01 2020 - 08:35:47 EST


On Tue, Dec 01 2020 at 12:40, Frederic Weisbecker wrote:
> On Tue, Dec 01, 2020 at 12:33:26PM +0100, Thomas Gleixner wrote:
>> > /*
>> > * We do not account for softirq time from ksoftirqd here.
>> > * We want to continue accounting softirq time to ksoftirqd thread
>> > * in that case, so as not to confuse scheduler with a special task
>> > * that do not consume any time, but still wants to run.
>> > */
>> > if (pc & HARDIRQ_MASK)
>> > irqtime_account_delta(irqtime, delta, CPUTIME_IRQ);
>> > else if ((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd())
>> > irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ);
>> > }
>>
>> Why not making all of this explicit instead of these conditionals?
>
> Hmm, I'm not sure I get what you suggest?

Instead of playing games with preeempt count and offsets and checking
for ksoftirqd, can't you just have:

account_hardirqtime()
account_softirqtime()

and call them from the right spots. See the below for illustration (it's
obviously incomplete).

Thanks,

tglx
---
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -377,6 +377,7 @@ static inline void invoke_softirq(void)
return;

if (!force_irqthreads) {
+ account_softirq_enter_time(current);
#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
/*
* We can safely execute softirq on the current stack if
@@ -391,6 +392,7 @@ static inline void invoke_softirq(void)
* to prevent from any overrun.
*/
do_softirq_own_stack();
+ account_softirq_exit_time(current);
#endif
} else {
wakeup_softirqd();
@@ -417,7 +419,7 @@ static inline void __irq_exit_rcu(void)
#else
lockdep_assert_irqs_disabled();
#endif
- account_irq_exit_time(current);
+ account_hardirq_exit_time(current);
preempt_count_sub(HARDIRQ_OFFSET);
if (!in_interrupt() && local_softirq_pending())
invoke_softirq();