Re: [PATCH v3] sched/cputime: let ktimers align with ksoftirqd in accounting CPUTIME_SOFTIRQ

From: Sebastian Andrzej Siewior
Date: Tue Dec 05 2023 - 10:31:54 EST


On 2023-12-02 05:28:15 [-0500], Yuanhan Zhang wrote:
> Hi,
Hi,

> Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> 于2023年12月1日周五 11:16写道:
> >
> > On 2023-12-01 16:05:41 [+0800], tiozhang wrote:
> > > In CONFIG_PREEMPT_RT kernel, ktimers also calls __do_softirq,
> > > so when accounting CPUTIME_SOFTIRQ, ktimers need to be accounted the same
> > > as ksoftirqd.
> >
> > I still don't understand why this is a good thing and why want to align
> > it with ksoftirqd and what breaks if we don't.
>
> My motivation of doing this is to keep CPUTIME_SOFTIRQ in /proc/stat
> remaining more accurate in PREEPT_RT kernel.
>
> If we dont align, ktimers' cpu time is added to CPUTIME_SYSTEM when
> CONFIG_IRQ_TIME_ACCOUNTING is enabled, make our stats less accurate..

So it is only SYSTEM? There is no additional SOFTIRQ that is used?

> The main diff between ksoftirqd and force-threaded interrupt is that ksoftirq
> is in SOFTIRQ_OFFSET (serving softirqs) while force-threaded is in
> SOFTIRQ_DISABLE_OFFSET (by using local_disable_bh).

This depends. If you look at a network driver, SOFTIRQ_DISABLE_OFFSET is
used during the driver routine doing almost only schedule a softirq.
Then the main part happens during SOFTIRQ_OFFSET where the driver pulls
the packets and passes them to the network stack.

> CPUTIME_SOFTIRQ serves for time in SOFTIRQ_OFFSET (processing softirqs).
> See
> https://lore.kernel.org/all/1285619753-10892-1-git-send-email-venki@xxxxxxxxxx/

Let me look at this later…

> So this leads to ksoftirqd is counted into CPUTIME_SOFTIRQ but irq-threads
> into CPUTIME_SYSTEM.
>
> Since ktimers is also in SOFTIRQ_OFFSET, align it with ksoftirq will
> put it into CPUTIME_SOFTIRQ, making /proc/stat more accurate.

But this only works if it is observed during the TICK interrupt, right?

Sebastian