Skip to content

Commit 48d6a81

Browse files
committed
context_tracking: Optimize guest APIs off case with static key
Optimize guest entry/exit APIs with static keys. This minimize the overhead for those who enable CONFIG_NO_HZ_FULL without always using it. Having no range passed to nohz_full= should result in the probes overhead to be minimized. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Kevin Hilman <khilman@linaro.org>
1 parent ad65782 commit 48d6a81

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

include/linux/context_tracking.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,23 @@ static inline void context_tracking_init(void) { }
9595

9696

9797
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
98-
extern void guest_enter(void);
99-
extern void guest_exit(void);
98+
static inline void guest_enter(void)
99+
{
100+
if (static_key_false(&context_tracking_enabled) &&
101+
vtime_accounting_enabled())
102+
vtime_guest_enter(current);
103+
else
104+
current->flags |= PF_VCPU;
105+
}
106+
107+
static inline void guest_exit(void)
108+
{
109+
if (static_key_false(&context_tracking_enabled) &&
110+
vtime_accounting_enabled())
111+
vtime_guest_exit(current);
112+
else
113+
current->flags &= ~PF_VCPU;
114+
}
100115
#else
101116
static inline void guest_enter(void)
102117
{

kernel/context_tracking.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#include <linux/export.h>
2222

2323
struct static_key context_tracking_enabled = STATIC_KEY_INIT_FALSE;
24+
EXPORT_SYMBOL_GPL(context_tracking_enabled);
2425

2526
DEFINE_PER_CPU(struct context_tracking, context_tracking);
27+
EXPORT_SYMBOL_GPL(context_tracking);
2628

2729
void context_tracking_cpu_set(int cpu)
2830
{
@@ -163,27 +165,6 @@ void context_tracking_user_exit(void)
163165
local_irq_restore(flags);
164166
}
165167

166-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
167-
void guest_enter(void)
168-
{
169-
if (vtime_accounting_enabled())
170-
vtime_guest_enter(current);
171-
else
172-
current->flags |= PF_VCPU;
173-
}
174-
EXPORT_SYMBOL_GPL(guest_enter);
175-
176-
void guest_exit(void)
177-
{
178-
if (vtime_accounting_enabled())
179-
vtime_guest_exit(current);
180-
else
181-
current->flags &= ~PF_VCPU;
182-
}
183-
EXPORT_SYMBOL_GPL(guest_exit);
184-
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
185-
186-
187168
/**
188169
* context_tracking_task_switch - context switch the syscall callbacks
189170
* @prev: the task that is being switched out

kernel/sched/cputime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ void vtime_guest_enter(struct task_struct *tsk)
724724
current->flags |= PF_VCPU;
725725
write_sequnlock(&tsk->vtime_seqlock);
726726
}
727+
EXPORT_SYMBOL_GPL(vtime_guest_enter);
727728

728729
void vtime_guest_exit(struct task_struct *tsk)
729730
{
@@ -732,6 +733,7 @@ void vtime_guest_exit(struct task_struct *tsk)
732733
current->flags &= ~PF_VCPU;
733734
write_sequnlock(&tsk->vtime_seqlock);
734735
}
736+
EXPORT_SYMBOL_GPL(vtime_guest_exit);
735737

736738
void vtime_account_idle(struct task_struct *tsk)
737739
{

0 commit comments

Comments
 (0)