Skip to content

Commit b049340

Browse files
committed
vtime: Optimize full dynticks accounting off case with static keys
If no CPU is in the full dynticks range, we can avoid the full dynticks cputime accounting through generic vtime along with its overhead and use the traditional tick based accounting instead. Let's do this and nope the off case with static keys. 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 a5725ac commit b049340

3 files changed

Lines changed: 67 additions & 31 deletions

File tree

‎include/linux/context_tracking.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,15 @@ static inline void context_tracking_init(void) { }
7474
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
7575
static inline void guest_enter(void)
7676
{
77-
if (static_key_false(&context_tracking_enabled) &&
78-
vtime_accounting_enabled())
77+
if (vtime_accounting_enabled())
7978
vtime_guest_enter(current);
8079
else
8180
current->flags |= PF_VCPU;
8281
}
8382

8483
static inline void guest_exit(void)
8584
{
86-
if (static_key_false(&context_tracking_enabled) &&
87-
vtime_accounting_enabled())
85+
if (vtime_accounting_enabled())
8886
vtime_guest_exit(current);
8987
else
9088
current->flags &= ~PF_VCPU;

‎include/linux/vtime.h‎

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,97 @@
11
#ifndef _LINUX_KERNEL_VTIME_H
22
#define _LINUX_KERNEL_VTIME_H
33

4+
#include <linux/context_tracking_state.h>
45
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
56
#include <asm/vtime.h>
67
#endif
78

9+
810
struct task_struct;
911

12+
/*
13+
* vtime_accounting_enabled() definitions/declarations
14+
*/
15+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
16+
static inline bool vtime_accounting_enabled(void) { return true; }
17+
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
18+
19+
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
20+
static inline bool vtime_accounting_enabled(void)
21+
{
22+
if (static_key_false(&context_tracking_enabled)) {
23+
if (context_tracking_active())
24+
return true;
25+
}
26+
27+
return false;
28+
}
29+
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
30+
31+
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
32+
static inline bool vtime_accounting_enabled(void) { return false; }
33+
#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
34+
35+
36+
/*
37+
* Common vtime APIs
38+
*/
1039
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
40+
41+
#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
1142
extern void vtime_task_switch(struct task_struct *prev);
43+
#else
44+
extern void vtime_common_task_switch(struct task_struct *prev);
45+
static inline void vtime_task_switch(struct task_struct *prev)
46+
{
47+
if (vtime_accounting_enabled())
48+
vtime_common_task_switch(prev);
49+
}
50+
#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
51+
1252
extern void vtime_account_system(struct task_struct *tsk);
1353
extern void vtime_account_idle(struct task_struct *tsk);
1454
extern void vtime_account_user(struct task_struct *tsk);
15-
extern void vtime_account_irq_enter(struct task_struct *tsk);
1655

17-
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
18-
static inline bool vtime_accounting_enabled(void) { return true; }
19-
#endif
56+
#ifdef __ARCH_HAS_VTIME_ACCOUNT
57+
extern void vtime_account_irq_enter(struct task_struct *tsk);
58+
#else
59+
extern void vtime_common_account_irq_enter(struct task_struct *tsk);
60+
static inline void vtime_account_irq_enter(struct task_struct *tsk)
61+
{
62+
if (vtime_accounting_enabled())
63+
vtime_common_account_irq_enter(tsk);
64+
}
65+
#endif /* __ARCH_HAS_VTIME_ACCOUNT */
2066

2167
#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
2268

2369
static inline void vtime_task_switch(struct task_struct *prev) { }
2470
static inline void vtime_account_system(struct task_struct *tsk) { }
2571
static inline void vtime_account_user(struct task_struct *tsk) { }
2672
static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
27-
static inline bool vtime_accounting_enabled(void) { return false; }
28-
#endif
73+
#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
2974

3075
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
3176
extern void arch_vtime_task_switch(struct task_struct *tsk);
32-
extern void vtime_account_irq_exit(struct task_struct *tsk);
33-
extern bool vtime_accounting_enabled(void);
77+
extern void vtime_gen_account_irq_exit(struct task_struct *tsk);
78+
79+
static inline void vtime_account_irq_exit(struct task_struct *tsk)
80+
{
81+
if (vtime_accounting_enabled())
82+
vtime_gen_account_irq_exit(tsk);
83+
}
84+
3485
extern void vtime_user_enter(struct task_struct *tsk);
86+
3587
static inline void vtime_user_exit(struct task_struct *tsk)
3688
{
3789
vtime_account_user(tsk);
3890
}
3991
extern void vtime_guest_enter(struct task_struct *tsk);
4092
extern void vtime_guest_exit(struct task_struct *tsk);
4193
extern void vtime_init_idle(struct task_struct *tsk, int cpu);
42-
#else
94+
#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
4395
static inline void vtime_account_irq_exit(struct task_struct *tsk)
4496
{
4597
/* On hard|softirq exit we always account to hard|softirq cputime */

‎kernel/sched/cputime.c‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,8 @@ static inline void irqtime_account_process_tick(struct task_struct *p, int user_
378378
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
379379

380380
#ifndef __ARCH_HAS_VTIME_TASK_SWITCH
381-
void vtime_task_switch(struct task_struct *prev)
381+
void vtime_common_task_switch(struct task_struct *prev)
382382
{
383-
if (!vtime_accounting_enabled())
384-
return;
385-
386383
if (is_idle_task(prev))
387384
vtime_account_idle(prev);
388385
else
@@ -404,11 +401,8 @@ void vtime_task_switch(struct task_struct *prev)
404401
* vtime_account().
405402
*/
406403
#ifndef __ARCH_HAS_VTIME_ACCOUNT
407-
void vtime_account_irq_enter(struct task_struct *tsk)
404+
void vtime_common_account_irq_enter(struct task_struct *tsk)
408405
{
409-
if (!vtime_accounting_enabled())
410-
return;
411-
412406
if (!in_interrupt()) {
413407
/*
414408
* If we interrupted user, context_tracking_in_user()
@@ -428,7 +422,7 @@ void vtime_account_irq_enter(struct task_struct *tsk)
428422
}
429423
vtime_account_system(tsk);
430424
}
431-
EXPORT_SYMBOL_GPL(vtime_account_irq_enter);
425+
EXPORT_SYMBOL_GPL(vtime_common_account_irq_enter);
432426
#endif /* __ARCH_HAS_VTIME_ACCOUNT */
433427
#endif /* CONFIG_VIRT_CPU_ACCOUNTING */
434428

@@ -669,11 +663,8 @@ void vtime_account_system(struct task_struct *tsk)
669663
write_sequnlock(&tsk->vtime_seqlock);
670664
}
671665

672-
void vtime_account_irq_exit(struct task_struct *tsk)
666+
void vtime_gen_account_irq_exit(struct task_struct *tsk)
673667
{
674-
if (!vtime_accounting_enabled())
675-
return;
676-
677668
write_seqlock(&tsk->vtime_seqlock);
678669
if (context_tracking_in_user())
679670
tsk->vtime_snap_whence = VTIME_USER;
@@ -732,11 +723,6 @@ void vtime_account_idle(struct task_struct *tsk)
732723
account_idle_time(delta_cpu);
733724
}
734725

735-
bool vtime_accounting_enabled(void)
736-
{
737-
return context_tracking_active();
738-
}
739-
740726
void arch_vtime_task_switch(struct task_struct *prev)
741727
{
742728
write_seqlock(&prev->vtime_seqlock);

0 commit comments

Comments
 (0)