mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aboorva Devarajan <aboorvad@linux.ibm.com>
To: Shrikanth Hegde <sshegde@linux.ibm.com>
Cc: Christophe Leroy <chleroy@kernel.org>,
	linux-kernel@vger.kernel.org,
	Ritesh Harjani <ritesh.list@gmail.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	linuxppc-dev@lists.ozlabs.org,
	Mukesh Kumar Chaurasiya <mchauras@linux.ibm.com>
Subject: Re: [PATCH] powerpc/entry: Fix double accounting of user time on interrupt entry
Date: Thu, 03 Sep 2026 01:44:03 +0530	[thread overview]
Message-ID: <032f834f0f6147649d9a29ec17ac62551dbf5142.camel@linux.ibm.com> (raw)
In-Reply-To: <95913fca-5631-40ff-abed-4afad99722e6@linux.ibm.com>

On Wed, 2026-09-02 at 12:37 +0530, Shrikanth Hegde wrote:

Hi Shrikanth,

> Hi Aboorva.
> 
> On 9/2/26 10:36 AM, Aboorva Devarajan wrote:
> > Since the switch to generic entry, an interrupt taken from user mode
> > accounts user time twice: once in arch_interrupt_enter_prepare() and
> > again in arch_enter_from_user_mode(), which irqentry_enter() invokes
> > for the same interrupt:
> > 
> >    arch_interrupt_enter_prepare()
> >        account_cpu_user_entry()
> >    irqentry_enter()
> >      arch_enter_from_user_mode()
> >        account_cpu_user_entry()
> > 
> > account_cpu_user_entry() accumulates the time spent in user mode
> > since the last return to user space, so the second call charges the
> > same interval again.
> > 
> > With CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y this roughly doubles the
> > reported user time of any workload that takes interrupts. On a
> > pseries LPAR, ps/top show ~200% CPU for a single-threaded CPU-bound
> > loop, and time(1) reports user time about twice the elapsed time.
> > 
> 
> Could you please run mpstat with 50% or less loading workload like stress-ng
> and document the difference in changelog.

Sure, will add it in v2.

1. On the same pseries LPAR, taskset -c 6 stress-ng --cpu 1 --cpu-load 50:

Without the patch, the reported %usr is inflated, while with the patch
it is close to the expected 50%.

Without Patch:
06:43:09 AM  CPU    %usr**   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
06:43:10 AM    6   69.74     0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   30.26

With Patch:
06:29:33 AM  CPU    %usr**   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
06:29:34 AM    6   48.51     0.00    0.00    0.00    0.99    0.00    0.00    0.00    0.00   50.50

2. Single-threaded CPU-bound workload:

taskset -c 100 python3 -c 'while True: pass' (executed for ~3 seconds)

Without patch:
TIME         ELAPSED %CPU
00:00:06       00:02  209

With patch:
TIME         ELAPSED %CPU
00:00:03       00:03  104

> 
> > Remove the accounting from arch_interrupt_enter_prepare() and rely on
> > arch_enter_from_user_mode(), which runs for both syscalls and
> > interrupts. The duplicate account_stolen_time() call is removed the
> > same way.
> > 
> > Fixes: bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")
> > Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com>
> > ---
> > Verified on a pseries LPAR (CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y),
> 
> Usual default is VIRT_CPU_ACCOUNTING_GEN, selected by NO_HZ_FULL.
> Most distros usually enable NO_HZ_FULL=y.
> 
> At hindsight, I don't see the issue dependency on it. But better to be sure.

It is only observed with CONFIG_VIRT_CPU_ACCOUNTING_NATIVE.

account_cpu_user_entry() updates utime only with NATIVE accounting.
With CONFIG_VIRT_CPU_ACCOUNTING_GEN or tick-based accounting, it is
an empty stub and therefore a no-op.

So kernels using CONFIG_VIRT_CPU_ACCOUNTING_GEN or tick-based accounting
are not affected.

> > 7.3.0-rc1, single-threaded CPU-bound loop:
> > 
> > Before:
> > 
> >    $ python3 -c 'while True: pass' &
> >    $ sleep 3; ps -p $! -o pid,etime,time,pcpu
> >        PID     ELAPSED     TIME %CPU
> >       4980       00:03 00:00:06  210
> > 
> > After:
> > 
> >    $ python3 -c 'while True: pass' &
> >    $ sleep 3; ps -p $! -o pid,etime,time,pcpu
> >        PID     ELAPSED     TIME %CPU
> >       4951       00:03 00:00:03  105
> > 
> >   arch/powerpc/include/asm/entry-common.h | 6 ++++--
> >   1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h
> > index c5adb5006361..984294e62568 100644
> > --- a/arch/powerpc/include/asm/entry-common.h
> > +++ b/arch/powerpc/include/asm/entry-common.h
> > @@ -222,8 +222,6 @@ static inline void arch_interrupt_enter_prepare(struct pt_regs *regs)
> >   
> >   	if (user_mode(regs)) {
> >   		kuap_lock();
> > -		account_cpu_user_entry();
> > -		account_stolen_time();
> >   	} else {
> >   		kuap_save_and_lock(regs);
> >   		/*
> > @@ -426,6 +424,10 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
> >   #endif
> >   	kuap_assert_locked();
> >   	booke_restore_dbcr0();
> > +	/*
> > +	 * User and stolen time is accounted here for every entry from
> > +	 * user mode. The interrupt prepare hooks must not account again.
> > +	 */
> >   	account_cpu_user_entry();
> >   	account_stolen_time();
> >   
> > 
> > base-commit: fb442a6673ff1046bf67754957d95880fdb394b5

Thanks,
Aboorva

      reply	other threads:[~2026-09-02 20:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02  5:06 Aboorva Devarajan
2026-09-02  5:31 ` Mukesh Kumar Chaurasiya
2026-09-02 17:45   ` Aboorva Devarajan
2026-09-02  5:36 ` Christophe Leroy (CS GROUP)
2026-09-02 19:44   ` Aboorva Devarajan
2026-09-03  4:51     ` Christophe Leroy (CS GROUP)
2026-09-02  7:07 ` Shrikanth Hegde
2026-09-02 20:14   ` Aboorva Devarajan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=032f834f0f6147649d9a29ec17ac62551dbf5142.camel@linux.ibm.com \
    --to=aboorvad@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mchauras@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=sshegde@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®