Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched: Move clock related paravirt code to kernel/sched

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

authored by

Juergen Gross and committed by
Borislav Petkov (AMD)
e6b2aa6d 68b10fd4

+47 -40
+3
arch/Kconfig
··· 1056 1056 Archs need to ensure they use a high enough resolution clock to 1057 1057 support irq time accounting and then call enable_sched_clock_irqtime(). 1058 1058 1059 + config HAVE_PV_STEAL_CLOCK_GEN 1060 + bool 1061 + 1059 1062 config HAVE_MOVE_PUD 1060 1063 bool 1061 1064 help
-4
arch/arm/include/asm/paravirt.h
··· 5 5 #ifdef CONFIG_PARAVIRT 6 6 #include <linux/static_call_types.h> 7 7 8 - struct static_key; 9 - extern struct static_key paravirt_steal_enabled; 10 - extern struct static_key paravirt_steal_rq_enabled; 11 - 12 8 u64 dummy_steal_clock(int cpu); 13 9 14 10 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
-3
arch/arm/kernel/paravirt.c
··· 12 12 #include <linux/static_call.h> 13 13 #include <asm/paravirt.h> 14 14 15 - struct static_key paravirt_steal_enabled; 16 - struct static_key paravirt_steal_rq_enabled; 17 - 18 15 static u64 native_steal_clock(int cpu) 19 16 { 20 17 return 0;
-4
arch/arm64/include/asm/paravirt.h
··· 5 5 #ifdef CONFIG_PARAVIRT 6 6 #include <linux/static_call_types.h> 7 7 8 - struct static_key; 9 - extern struct static_key paravirt_steal_enabled; 10 - extern struct static_key paravirt_steal_rq_enabled; 11 - 12 8 u64 dummy_steal_clock(int cpu); 13 9 14 10 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
+1 -3
arch/arm64/kernel/paravirt.c
··· 19 19 #include <linux/slab.h> 20 20 #include <linux/types.h> 21 21 #include <linux/static_call.h> 22 + #include <linux/sched/cputime.h> 22 23 23 24 #include <asm/paravirt.h> 24 25 #include <asm/pvclock-abi.h> 25 26 #include <asm/smp_plat.h> 26 - 27 - struct static_key paravirt_steal_enabled; 28 - struct static_key paravirt_steal_rq_enabled; 29 27 30 28 static u64 native_steal_clock(int cpu) 31 29 {
-3
arch/loongarch/include/asm/paravirt.h
··· 5 5 #ifdef CONFIG_PARAVIRT 6 6 7 7 #include <linux/static_call_types.h> 8 - struct static_key; 9 - extern struct static_key paravirt_steal_enabled; 10 - extern struct static_key paravirt_steal_rq_enabled; 11 8 12 9 u64 dummy_steal_clock(int cpu); 13 10 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
+1 -2
arch/loongarch/kernel/paravirt.c
··· 6 6 #include <linux/kvm_para.h> 7 7 #include <linux/reboot.h> 8 8 #include <linux/static_call.h> 9 + #include <linux/sched/cputime.h> 9 10 #include <asm/paravirt.h> 10 11 11 12 static int has_steal_clock; 12 - struct static_key paravirt_steal_enabled; 13 - struct static_key paravirt_steal_rq_enabled; 14 13 static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64); 15 14 DEFINE_STATIC_KEY_FALSE(virt_spin_lock_key); 16 15
-3
arch/powerpc/include/asm/paravirt.h
··· 23 23 } 24 24 25 25 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING 26 - extern struct static_key paravirt_steal_enabled; 27 - extern struct static_key paravirt_steal_rq_enabled; 28 - 29 26 u64 pseries_paravirt_steal_clock(int cpu); 30 27 31 28 static inline u64 paravirt_steal_clock(int cpu)
+1 -3
arch/powerpc/platforms/pseries/setup.c
··· 42 42 #include <linux/memblock.h> 43 43 #include <linux/swiotlb.h> 44 44 #include <linux/seq_buf.h> 45 + #include <linux/sched/cputime.h> 45 46 46 47 #include <asm/mmu.h> 47 48 #include <asm/processor.h> ··· 84 83 EXPORT_SYMBOL(shared_processor); 85 84 86 85 #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING 87 - struct static_key paravirt_steal_enabled; 88 - struct static_key paravirt_steal_rq_enabled; 89 - 90 86 static bool steal_acc = true; 91 87 static int __init parse_no_stealacc(char *arg) 92 88 {
-4
arch/riscv/include/asm/paravirt.h
··· 5 5 #ifdef CONFIG_PARAVIRT 6 6 #include <linux/static_call_types.h> 7 7 8 - struct static_key; 9 - extern struct static_key paravirt_steal_enabled; 10 - extern struct static_key paravirt_steal_rq_enabled; 11 - 12 8 u64 dummy_steal_clock(int cpu); 13 9 14 10 DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock);
+1 -3
arch/riscv/kernel/paravirt.c
··· 16 16 #include <linux/printk.h> 17 17 #include <linux/static_call.h> 18 18 #include <linux/types.h> 19 + #include <linux/sched/cputime.h> 19 20 20 21 #include <asm/barrier.h> 21 22 #include <asm/page.h> 22 23 #include <asm/paravirt.h> 23 24 #include <asm/sbi.h> 24 - 25 - struct static_key paravirt_steal_enabled; 26 - struct static_key paravirt_steal_rq_enabled; 27 25 28 26 static u64 native_steal_clock(int cpu) 29 27 {
-4
arch/x86/include/asm/paravirt.h
··· 30 30 return static_call(pv_sched_clock)(); 31 31 } 32 32 33 - struct static_key; 34 - extern struct static_key paravirt_steal_enabled; 35 - extern struct static_key paravirt_steal_rq_enabled; 36 - 37 33 __visible void __native_queued_spin_unlock(struct qspinlock *lock); 38 34 bool pv_is_native_spin_unlock(void); 39 35 __visible bool __native_vcpu_is_preempted(long cpu);
+1
arch/x86/kernel/cpu/vmware.c
··· 29 29 #include <linux/efi.h> 30 30 #include <linux/reboot.h> 31 31 #include <linux/static_call.h> 32 + #include <linux/sched/cputime.h> 32 33 #include <asm/div64.h> 33 34 #include <asm/x86_init.h> 34 35 #include <asm/hypervisor.h>
+1
arch/x86/kernel/kvm.c
··· 30 30 #include <linux/cc_platform.h> 31 31 #include <linux/efi.h> 32 32 #include <linux/kvm_types.h> 33 + #include <linux/sched/cputime.h> 33 34 #include <asm/timer.h> 34 35 #include <asm/cpu.h> 35 36 #include <asm/traps.h>
-3
arch/x86/kernel/paravirt.c
··· 60 60 static_branch_enable(&virt_spin_lock_key); 61 61 } 62 62 63 - struct static_key paravirt_steal_enabled; 64 - struct static_key paravirt_steal_rq_enabled; 65 - 66 63 static u64 native_steal_clock(int cpu) 67 64 { 68 65 return 0;
+1
drivers/xen/time.c
··· 8 8 #include <linux/gfp.h> 9 9 #include <linux/slab.h> 10 10 #include <linux/static_call.h> 11 + #include <linux/sched/cputime.h> 11 12 12 13 #include <asm/paravirt.h> 13 14 #include <asm/xen/hypervisor.h>
+18
include/linux/sched/cputime.h
··· 2 2 #ifndef _LINUX_SCHED_CPUTIME_H 3 3 #define _LINUX_SCHED_CPUTIME_H 4 4 5 + #include <linux/static_call_types.h> 5 6 #include <linux/sched/signal.h> 6 7 7 8 /* ··· 180 179 181 180 extern unsigned long long 182 181 task_sched_runtime(struct task_struct *task); 182 + 183 + #ifdef CONFIG_PARAVIRT 184 + struct static_key; 185 + extern struct static_key paravirt_steal_enabled; 186 + extern struct static_key paravirt_steal_rq_enabled; 187 + 188 + #ifdef CONFIG_HAVE_PV_STEAL_CLOCK_GEN 189 + u64 dummy_steal_clock(int cpu); 190 + 191 + DECLARE_STATIC_CALL(pv_steal_clock, dummy_steal_clock); 192 + 193 + static inline u64 paravirt_steal_clock(int cpu) 194 + { 195 + return static_call(pv_steal_clock)(cpu); 196 + } 197 + #endif 198 + #endif 183 199 184 200 #endif /* _LINUX_SCHED_CPUTIME_H */
+5
kernel/sched/core.c
··· 770 770 * RQ-clock updating methods: 771 771 */ 772 772 773 + /* Use CONFIG_PARAVIRT as this will avoid more #ifdef in arch code. */ 774 + #ifdef CONFIG_PARAVIRT 775 + struct static_key paravirt_steal_rq_enabled; 776 + #endif 777 + 773 778 static void update_rq_clock_task(struct rq *rq, s64 delta) 774 779 { 775 780 /*
+13
kernel/sched/cputime.c
··· 251 251 * ticks are not redelivered later. Due to that, this function may on 252 252 * occasion account more time than the calling functions think elapsed. 253 253 */ 254 + #ifdef CONFIG_PARAVIRT 255 + struct static_key paravirt_steal_enabled; 256 + 257 + #ifdef CONFIG_HAVE_PV_STEAL_CLOCK_GEN 258 + static u64 native_steal_clock(int cpu) 259 + { 260 + return 0; 261 + } 262 + 263 + DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock); 264 + #endif 265 + #endif 266 + 254 267 static __always_inline u64 steal_account_process_time(u64 maxtime) 255 268 { 256 269 #ifdef CONFIG_PARAVIRT
+1 -1
kernel/sched/sched.h
··· 82 82 struct sched_group; 83 83 struct cpuidle_state; 84 84 85 - #ifdef CONFIG_PARAVIRT 85 + #if defined(CONFIG_PARAVIRT) && !defined(CONFIG_HAVE_PV_STEAL_CLOCK_GEN) 86 86 # include <asm/paravirt.h> 87 87 #endif 88 88