2024-01-28 20:00:12

by Alexander Gordeev

[permalink] [raw]
Subject: [PATCH 0/5] sched/vtime: vtime.h headers cleanup

Hi all,

Please find a small cleanup to vtime_task_switch() wiring.
I split it into smaller patches to allow separate PowerPC
vs s390 reviews. Otherwise patches 2+3 and 4+5 could have
been merged.

I tested it on s390 and compile-tested it on 32- and 64-bit
PowerPC and few other major architectures only, but it is
only of concern for CONFIG_VIRT_CPU_ACCOUNTING_NATIVE-capable
ones (AFAICT).

Thanks!

Alexander Gordeev (5):
sched/vtime: remove confusing arch_vtime_task_switch() declaration
sched/vtime: get rid of generic vtime_task_switch() implementation
s390/vtime: remove unused __ARCH_HAS_VTIME_TASK_SWITCH leftover
s390/irq,nmi: do not include <linux/vtime.h> header
sched/vtime: do not include <asm/vtime.h> header

arch/powerpc/include/asm/cputime.h | 13 -------------
arch/powerpc/kernel/time.c | 22 ++++++++++++++++++++++
arch/s390/include/asm/vtime.h | 2 --
arch/s390/kernel/irq.c | 1 +
arch/s390/kernel/nmi.c | 1 +
include/asm-generic/vtime.h | 1 -
include/linux/vtime.h | 5 -----
kernel/sched/cputime.c | 13 -------------
8 files changed, 24 insertions(+), 34 deletions(-)
delete mode 100644 include/asm-generic/vtime.h

--
2.40.1



2024-01-28 20:00:14

by Alexander Gordeev

[permalink] [raw]
Subject: [PATCH 4/5] s390/irq,nmi: do not include <linux/vtime.h> header

update_timer_sys() and update_timer_mcck() are inlines used for
CPU time accounting from the interrupt and machine-check handlers.
These routines are specific to s390 architecture, but declared
via <linux/vtime.h> header, which in turn inludes <asm/vtime.h>.
Avoid the extra loop and include <asm/vtime.h> header directly.

Signed-off-by: Alexander Gordeev <[email protected]>
---
arch/s390/kernel/irq.c | 1 +
arch/s390/kernel/nmi.c | 1 +
2 files changed, 2 insertions(+)

diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index 6f71b0ce1068..259496fe0ef9 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -29,6 +29,7 @@
#include <asm/hw_irq.h>
#include <asm/stacktrace.h>
#include <asm/softirq_stack.h>
+#include <asm/vtime.h>
#include "entry.h"

DEFINE_PER_CPU_SHARED_ALIGNED(struct irq_stat, irq_stat);
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index 9ad44c26d1a2..4422a27faace 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -32,6 +32,7 @@
#include <asm/asm-offsets.h>
#include <asm/pai.h>
#include <asm/vx-insn.h>
+#include <asm/vtime.h>
#include <asm/fpu/api.h>

struct mcck_struct {
--
2.40.1


2024-01-28 20:00:20

by Alexander Gordeev

[permalink] [raw]
Subject: [PATCH 2/5] sched/vtime: get rid of generic vtime_task_switch() implementation

The generic vtime_task_switch() implementation gets built only
if __ARCH_HAS_VTIME_TASK_SWITCH is not defined, but requires an
architecture to implement arch_vtime_task_switch() callback at
the same time, which is confusing.

Further, arch_vtime_task_switch() is implemented for 32-bit PowerPC
architecture only and vtime_task_switch() generic variant is rather
superfluous.

Simplify the whole vtime_task_switch() wiring by moving the existing
generic implementation to PowerPC.

Signed-off-by: Alexander Gordeev <[email protected]>
---
arch/powerpc/include/asm/cputime.h | 13 -------------
arch/powerpc/kernel/time.c | 22 ++++++++++++++++++++++
kernel/sched/cputime.c | 13 -------------
3 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h
index 4961fb38e438..aff858ca99c0 100644
--- a/arch/powerpc/include/asm/cputime.h
+++ b/arch/powerpc/include/asm/cputime.h
@@ -32,23 +32,10 @@
#ifdef CONFIG_PPC64
#define get_accounting(tsk) (&get_paca()->accounting)
#define raw_get_accounting(tsk) (&local_paca->accounting)
-static inline void arch_vtime_task_switch(struct task_struct *tsk) { }

#else
#define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
#define raw_get_accounting(tsk) get_accounting(tsk)
-/*
- * Called from the context switch with interrupts disabled, to charge all
- * accumulated times to the current process, and to prepare accounting on
- * the next process.
- */
-static inline void arch_vtime_task_switch(struct task_struct *prev)
-{
- struct cpu_accounting_data *acct = get_accounting(current);
- struct cpu_accounting_data *acct0 = get_accounting(prev);
-
- acct->starttime = acct0->starttime;
-}
#endif

/*
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index df20cf201f74..c0fdc6d94fee 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -354,6 +354,28 @@ void vtime_flush(struct task_struct *tsk)
acct->hardirq_time = 0;
acct->softirq_time = 0;
}
+
+/*
+ * Called from the context switch with interrupts disabled, to charge all
+ * accumulated times to the current process, and to prepare accounting on
+ * the next process.
+ */
+void vtime_task_switch(struct task_struct *prev)
+{
+ if (is_idle_task(prev))
+ vtime_account_idle(prev);
+ else
+ vtime_account_kernel(prev);
+
+ vtime_flush(prev);
+
+ if (!IS_ENABLED(CONFIG_PPC64)) {
+ struct cpu_accounting_data *acct = get_accounting(current);
+ struct cpu_accounting_data *acct0 = get_accounting(prev);
+
+ acct->starttime = acct0->starttime;
+ }
+}
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */

void __no_kcsan __delay(unsigned long loops)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index af7952f12e6c..aa48b2ec879d 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -424,19 +424,6 @@ static inline void irqtime_account_process_tick(struct task_struct *p, int user_
*/
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE

-# ifndef __ARCH_HAS_VTIME_TASK_SWITCH
-void vtime_task_switch(struct task_struct *prev)
-{
- if (is_idle_task(prev))
- vtime_account_idle(prev);
- else
- vtime_account_kernel(prev);
-
- vtime_flush(prev);
- arch_vtime_task_switch(prev);
-}
-# endif
-
void vtime_account_irq(struct task_struct *tsk, unsigned int offset)
{
unsigned int pc = irq_count() - offset;
--
2.40.1


2024-01-29 09:52:58

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 4/5] s390/irq,nmi: do not include <linux/vtime.h> header

On Sun, Jan 28, 2024 at 08:58:53PM +0100, Alexander Gordeev wrote:
> update_timer_sys() and update_timer_mcck() are inlines used for
> CPU time accounting from the interrupt and machine-check handlers.
> These routines are specific to s390 architecture, but declared
> via <linux/vtime.h> header, which in turn inludes <asm/vtime.h>.
> Avoid the extra loop and include <asm/vtime.h> header directly.
>
> Signed-off-by: Alexander Gordeev <[email protected]>
> ---
> arch/s390/kernel/irq.c | 1 +
> arch/s390/kernel/nmi.c | 1 +
> 2 files changed, 2 insertions(+)
..
> +++ b/arch/s390/kernel/irq.c
> +#include <asm/vtime.h>
..
> +++ b/arch/s390/kernel/nmi.c
> +#include <asm/vtime.h>

It is confusing when the patch subject is "do not include.." and all
what this patch is doing is to add two includes. I see what this is
doing: getting rid of the implicit include of asm/vtime.h most likely
via linux/hardirq.h, but that's not very obvious.

Anyway:
Acked-by: Heiko Carstens <[email protected]>

2024-02-06 23:20:48

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [PATCH 2/5] sched/vtime: get rid of generic vtime_task_switch() implementation

Le Sun, Jan 28, 2024 at 08:58:51PM +0100, Alexander Gordeev a ?crit :
> The generic vtime_task_switch() implementation gets built only
> if __ARCH_HAS_VTIME_TASK_SWITCH is not defined, but requires an
> architecture to implement arch_vtime_task_switch() callback at
> the same time, which is confusing.
>
> Further, arch_vtime_task_switch() is implemented for 32-bit PowerPC
> architecture only and vtime_task_switch() generic variant is rather
> superfluous.
>
> Simplify the whole vtime_task_switch() wiring by moving the existing
> generic implementation to PowerPC.
>
> Signed-off-by: Alexander Gordeev <[email protected]>

Reviewed-by: Frederic Weisbecker <[email protected]>

2024-02-07 14:16:39

by Alexander Gordeev

[permalink] [raw]
Subject: Re: [PATCH 4/5] s390/irq,nmi: do not include <linux/vtime.h> header

On Mon, Jan 29, 2024 at 10:51:44AM +0100, Heiko Carstens wrote:
> It is confusing when the patch subject is "do not include.." and all
> what this patch is doing is to add two includes. I see what this is
> doing: getting rid of the implicit include of asm/vtime.h most likely
> via linux/hardirq.h, but that's not very obvious.
>
> Anyway:
> Acked-by: Heiko Carstens <[email protected]>

Thank you, Heiko!

Whether this wording sounds better?

s390/irq,nmi: include <asm/vtime.h> header directly

update_timer_sys() and update_timer_mcck() are inlines used for
CPU time accounting from the interrupt and machine-check handlers.
These routines are specific to s390 architecture, but included
via <linux/vtime.h> header implicitly. Avoid the extra loop and
include <asm/vtime.h> header directly.