]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sched: Move clock related paravirt code to kernel/sched
authorJuergen Gross <jgross@suse.com>
Mon, 5 Jan 2026 11:05:05 +0000 (12:05 +0100)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 12 Jan 2026 14:39:14 +0000 (15:39 +0100)
Paravirt clock related functions are available in multiple archs.

In order to share the common parts, move the common static keys
to kernel/sched/ and remove them from the arch specific files.

Make a common paravirt_steal_clock() implementation available in
kernel/sched/cputime.c, guarding it with a new config option
CONFIG_HAVE_PV_STEAL_CLOCK_GEN, which can be selected by an arch
in case it wants to use that common variant.

Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260105110520.21356-7-jgross@suse.com
20 files changed:
arch/Kconfig
arch/arm/include/asm/paravirt.h
arch/arm/kernel/paravirt.c
arch/arm64/include/asm/paravirt.h
arch/arm64/kernel/paravirt.c
arch/loongarch/include/asm/paravirt.h
arch/loongarch/kernel/paravirt.c
arch/powerpc/include/asm/paravirt.h
arch/powerpc/platforms/pseries/setup.c
arch/riscv/include/asm/paravirt.h
arch/riscv/kernel/paravirt.c
arch/x86/include/asm/paravirt.h
arch/x86/kernel/cpu/vmware.c
arch/x86/kernel/kvm.c
arch/x86/kernel/paravirt.c
drivers/xen/time.c
include/linux/sched/cputime.h
kernel/sched/core.c
kernel/sched/cputime.c
kernel/sched/sched.h

index 31220f512b16d5cfbc259935c2d3675b60c1e25c..102ddbd4298efa6246b430f8fe23c8884a6b9454 100644 (file)
@@ -1056,6 +1056,9 @@ config HAVE_IRQ_TIME_ACCOUNTING
          Archs need to ensure they use a high enough resolution clock to
          support irq time accounting and then call enable_sched_clock_irqtime().
 
+config HAVE_PV_STEAL_CLOCK_GEN
+       bool
+
 config HAVE_MOVE_PUD
        bool
        help
index 95d5b0d625cd35ecf127180534098bfa6c5e3b40..69da4bdcf8561061879aaf25b788aa999fff5b13 100644 (file)
@@ -5,10 +5,6 @@
 #ifdef CONFIG_PARAVIRT
 #include <linux/static_call_types.h>
 
-struct static_key;
-extern struct static_key paravirt_steal_enabled;
-extern struct static_key paravirt_steal_rq_enabled;
-
 u64 dummy_steal_clock(int cpu);
 
 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
index 7dd9806369fb08217eeb4ef905ec15f134202cbf..3895a5578852431dfa094560fa49e8e41fc6e216 100644 (file)
@@ -12,9 +12,6 @@
 #include <linux/static_call.h>
 #include <asm/paravirt.h>
 
-struct static_key paravirt_steal_enabled;
-struct static_key paravirt_steal_rq_enabled;
-
 static u64 native_steal_clock(int cpu)
 {
        return 0;
index 9aa193e0e8f28d9309bc18013230e714152f4f93..c9f7590baacbbe9869f08d61cae8e0674a33036f 100644 (file)
@@ -5,10 +5,6 @@
 #ifdef CONFIG_PARAVIRT
 #include <linux/static_call_types.h>
 
-struct static_key;
-extern struct static_key paravirt_steal_enabled;
-extern struct static_key paravirt_steal_rq_enabled;
-
 u64 dummy_steal_clock(int cpu);
 
 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
index aa718d6a9274ab06e78b6dc28f08de97a517a3ec..943b60ce12f42d6b1402ea1ee7856dafc312927a 100644 (file)
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/static_call.h>
+#include <linux/sched/cputime.h>
 
 #include <asm/paravirt.h>
 #include <asm/pvclock-abi.h>
 #include <asm/smp_plat.h>
 
-struct static_key paravirt_steal_enabled;
-struct static_key paravirt_steal_rq_enabled;
-
 static u64 native_steal_clock(int cpu)
 {
        return 0;
index 3f4323603e6aa971edbcf70955947889a42339c3..d219ea0d98ac49cc66a23636ba7f981f03352854 100644 (file)
@@ -5,9 +5,6 @@
 #ifdef CONFIG_PARAVIRT
 
 #include <linux/static_call_types.h>
-struct static_key;
-extern struct static_key paravirt_steal_enabled;
-extern struct static_key paravirt_steal_rq_enabled;
 
 u64 dummy_steal_clock(int cpu);
 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
index b1b51f920b2319ba622ab83a7e191e2b51e33ba8..8caaa94fed1abaab8e485a9ce6aeee4f8bcab06b 100644 (file)
@@ -6,11 +6,10 @@
 #include <linux/kvm_para.h>
 #include <linux/reboot.h>
 #include <linux/static_call.h>
+#include <linux/sched/cputime.h>
 #include <asm/paravirt.h>
 
 static int has_steal_clock;
-struct static_key paravirt_steal_enabled;
-struct static_key paravirt_steal_rq_enabled;
 static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64);
 DEFINE_STATIC_KEY_FALSE(virt_spin_lock_key);
 
index b78b82d660577626adc9ce47ffe449d68a36daa7..92343a23ad156a8607731744fcb9b7bac37317a5 100644 (file)
@@ -23,9 +23,6 @@ static inline bool is_shared_processor(void)
 }
 
 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
-extern struct static_key paravirt_steal_enabled;
-extern struct static_key paravirt_steal_rq_enabled;
-
 u64 pseries_paravirt_steal_clock(int cpu);
 
 static inline u64 paravirt_steal_clock(int cpu)
index b10a253252387096c954ba6ebb33a72a3b115310..50b26ed8432d554f5b2939464d07cbf0cb9df143 100644 (file)
@@ -42,6 +42,7 @@
 #include <linux/memblock.h>
 #include <linux/swiotlb.h>
 #include <linux/seq_buf.h>
+#include <linux/sched/cputime.h>
 
 #include <asm/mmu.h>
 #include <asm/processor.h>
@@ -83,9 +84,6 @@ DEFINE_STATIC_KEY_FALSE(shared_processor);
 EXPORT_SYMBOL(shared_processor);
 
 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
-struct static_key paravirt_steal_enabled;
-struct static_key paravirt_steal_rq_enabled;
-
 static bool steal_acc = true;
 static int __init parse_no_stealacc(char *arg)
 {
index c0abde70fc2ce983ad2ee81b8a9b7b6c3d37a6f8..17e5e39c72c023af69a8d851346fae3f48253fc7 100644 (file)
@@ -5,10 +5,6 @@
 #ifdef CONFIG_PARAVIRT
 #include <linux/static_call_types.h>
 
-struct static_key;
-extern struct static_key paravirt_steal_enabled;
-extern struct static_key paravirt_steal_rq_enabled;
-
 u64 dummy_steal_clock(int cpu);
 
 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
index fa6b0339a65dea7a173af636aa46cca579e3ee09..d3c334f161725c7d9598079906b750ab934eca50 100644 (file)
 #include <linux/printk.h>
 #include <linux/static_call.h>
 #include <linux/types.h>
+#include <linux/sched/cputime.h>
 
 #include <asm/barrier.h>
 #include <asm/page.h>
 #include <asm/paravirt.h>
 #include <asm/sbi.h>
 
-struct static_key paravirt_steal_enabled;
-struct static_key paravirt_steal_rq_enabled;
-
 static u64 native_steal_clock(int cpu)
 {
        return 0;
index 1344d2fb2b86bf4d8eb9496d063f57241df8445e..0ef797ea84400b53aeaf3e71b2ece3aea46e0e65 100644 (file)
@@ -30,10 +30,6 @@ static __always_inline u64 paravirt_sched_clock(void)
        return static_call(pv_sched_clock)();
 }
 
-struct static_key;
-extern struct static_key paravirt_steal_enabled;
-extern struct static_key paravirt_steal_rq_enabled;
-
 __visible void __native_queued_spin_unlock(struct qspinlock *lock);
 bool pv_is_native_spin_unlock(void);
 __visible bool __native_vcpu_is_preempted(long cpu);
index cb3f900c46fcc1230faa3d03a010a77c10ed7cf8..a3e6936839b11796bf7eecdf7311167abb78f918 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/efi.h>
 #include <linux/reboot.h>
 #include <linux/static_call.h>
+#include <linux/sched/cputime.h>
 #include <asm/div64.h>
 #include <asm/x86_init.h>
 #include <asm/hypervisor.h>
index df78ddee0abbb7d3f9d30ad8ed11266e817dfc6a..21b4de55f823de6f846a3c64dd86569440826c5b 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/cc_platform.h>
 #include <linux/efi.h>
 #include <linux/kvm_types.h>
+#include <linux/sched/cputime.h>
 #include <asm/timer.h>
 #include <asm/cpu.h>
 #include <asm/traps.h>
index ab3e172dcc693120cf05eb530082c22aab0e9e85..a3ba4747be1cfc4f547f95c2d78006ac0d02552d 100644 (file)
@@ -60,9 +60,6 @@ void __init native_pv_lock_init(void)
                static_branch_enable(&virt_spin_lock_key);
 }
 
-struct static_key paravirt_steal_enabled;
-struct static_key paravirt_steal_rq_enabled;
-
 static u64 native_steal_clock(int cpu)
 {
        return 0;
index 5683383d2305292aa857e60902a48ed677e11b98..d360ded2ef39f415efa93c8715ee7f597c8ece44 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/gfp.h>
 #include <linux/slab.h>
 #include <linux/static_call.h>
+#include <linux/sched/cputime.h>
 
 #include <asm/paravirt.h>
 #include <asm/xen/hypervisor.h>
index 5f8fd5b24a2e55556ceed14d1ef2ddb5fa4932e8..e90efaf6d26e90833b3e692ecc607e04464c6f81 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef _LINUX_SCHED_CPUTIME_H
 #define _LINUX_SCHED_CPUTIME_H
 
+#include <linux/static_call_types.h>
 #include <linux/sched/signal.h>
 
 /*
@@ -180,4 +181,21 @@ static inline void prev_cputime_init(struct prev_cputime *prev)
 extern unsigned long long
 task_sched_runtime(struct task_struct *task);
 
+#ifdef CONFIG_PARAVIRT
+struct static_key;
+extern struct static_key paravirt_steal_enabled;
+extern struct static_key paravirt_steal_rq_enabled;
+
+#ifdef CONFIG_HAVE_PV_STEAL_CLOCK_GEN
+u64 dummy_steal_clock(int cpu);
+
+DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
+
+static inline u64 paravirt_steal_clock(int cpu)
+{
+       return static_call(pv_steal_clock)(cpu);
+}
+#endif
+#endif
+
 #endif /* _LINUX_SCHED_CPUTIME_H */
index 60afadb6eedea6521022175effd9d7bf36aab412..efac2fb12b222bc17db9b3058ffe8448e0d8f421 100644 (file)
@@ -770,6 +770,11 @@ struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf)
  * RQ-clock updating methods:
  */
 
+/* Use CONFIG_PARAVIRT as this will avoid more #ifdef in arch code. */
+#ifdef CONFIG_PARAVIRT
+struct static_key paravirt_steal_rq_enabled;
+#endif
+
 static void update_rq_clock_task(struct rq *rq, s64 delta)
 {
 /*
index 4f97896887ecbb9fcd3d26e06f5c775d20e3c996..7ff8dbec7ee3d52b1b24c53702124d5c3ee10520 100644 (file)
@@ -251,6 +251,19 @@ void __account_forceidle_time(struct task_struct *p, u64 delta)
  * ticks are not redelivered later. Due to that, this function may on
  * occasion account more time than the calling functions think elapsed.
  */
+#ifdef CONFIG_PARAVIRT
+struct static_key paravirt_steal_enabled;
+
+#ifdef CONFIG_HAVE_PV_STEAL_CLOCK_GEN
+static u64 native_steal_clock(int cpu)
+{
+       return 0;
+}
+
+DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock);
+#endif
+#endif
+
 static __always_inline u64 steal_account_process_time(u64 maxtime)
 {
 #ifdef CONFIG_PARAVIRT
index 28e7cc4f796425bf41796991ac0002db8c8b547e..fcc2a1c0dcb8b517a0ef24d4814e466487f43d73 100644 (file)
@@ -82,7 +82,7 @@ struct rt_rq;
 struct sched_group;
 struct cpuidle_state;
 
-#ifdef CONFIG_PARAVIRT
+#if defined(CONFIG_PARAVIRT) && !defined(CONFIG_HAVE_PV_STEAL_CLOCK_GEN)
 # include <asm/paravirt.h>
 #endif