Re: [PATCH] powerpc/entry: Fix double accounting of user time on interrupt entry

"Christophe Leroy (CS GROUP)" <[email protected]>
Newsgroups gmane.linux.ports.ppc.embedded
Message-ID <cd25ffa5-5efc-42f1-b145-0c1c6539b4c4__10598.0122739979$1788327399$gmane$org@kernel.org>

Le 02/09/2026 à 07:06, Aboorva Devarajan a écrit :
> 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.

One of them was added by commit 09a9d3a8499d ("powerpc: introduce 
arch_enter_from_user_mode"), the other one by commit 893082ac769b 
("powerpc: Prepare for IRQ entry exit"). Would be good to mention it and 
explain how it went wrong.


> 
> 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.
> 
> 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")

Not sure it is the correct commit. Should probably be one of the ones 
that introduced the wrong call.

> Signed-off-by: Aboorva Devarajan <[email protected]>
> ---
> Verified on a pseries LPAR (CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y),
> 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.
> +	 */

Don't polute the code with such a comment. This is to be explained in 
the commit message. First a comment shall tell what code does, not what 
it doesn't do. And the comment has no added value, when you see 
account_cpu_user_entry() is called you already know that.

Here you feel the need to add such comment, but if you had implemented 
this function yourself and done it right at the first time, would you 
have felt the need for this comment ?

Have a look at https://docs.kernel.org/process/coding-style.html#commenting

>   	account_cpu_user_entry();
>   	account_stolen_time();
>   
> 
> base-commit: fb442a6673ff1046bf67754957d95880fdb394b5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.