Skip to content

Commit 6f922b8

Browse files
sean-jcKAGA-KOKO
authored andcommitted
sched/vtime: Move guest enter/exit vtime accounting to vtime.h
Provide separate helpers for guest enter vtime accounting (in addition to the existing guest exit helpers), and move all vtime accounting helpers to vtime.h where the existing #ifdef infrastructure can be leveraged to better delineate the different types of accounting. This will also allow future cleanups via deduplication of context tracking code. Opportunstically delete the vtime_account_kernel() stub now that all callers are wrapped with CONFIG_VIRT_CPU_ACCOUNTING_NATIVE=y. No functional change intended. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b41c723 commit 6f922b8

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

include/linux/context_tracking.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ static __always_inline void context_tracking_guest_exit(void)
137137
__context_tracking_exit(CONTEXT_GUEST);
138138
}
139139

140-
static __always_inline void vtime_account_guest_exit(void)
141-
{
142-
if (vtime_accounting_enabled_this_cpu())
143-
vtime_guest_exit(current);
144-
else
145-
current->flags &= ~PF_VCPU;
146-
}
147-
148140
static __always_inline void guest_exit_irqoff(void)
149141
{
150142
context_tracking_guest_exit();
@@ -163,20 +155,13 @@ static __always_inline void guest_enter_irqoff(void)
163155
* to flush.
164156
*/
165157
instrumentation_begin();
166-
vtime_account_kernel(current);
167-
current->flags |= PF_VCPU;
158+
vtime_account_guest_enter();
168159
rcu_virt_note_context_switch(smp_processor_id());
169160
instrumentation_end();
170161
}
171162

172163
static __always_inline void context_tracking_guest_exit(void) { }
173164

174-
static __always_inline void vtime_account_guest_exit(void)
175-
{
176-
vtime_account_kernel(current);
177-
current->flags &= ~PF_VCPU;
178-
}
179-
180165
static __always_inline void guest_exit_irqoff(void)
181166
{
182167
instrumentation_begin();

include/linux/vtime.h

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
#define _LINUX_KERNEL_VTIME_H
44

55
#include <linux/context_tracking_state.h>
6+
#include <linux/sched.h>
7+
68
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
79
#include <asm/vtime.h>
810
#endif
911

10-
11-
struct task_struct;
12-
1312
/*
1413
* Common vtime APIs
1514
*/
1615
#ifdef CONFIG_VIRT_CPU_ACCOUNTING
1716
extern void vtime_account_kernel(struct task_struct *tsk);
1817
extern void vtime_account_idle(struct task_struct *tsk);
19-
#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
20-
static inline void vtime_account_kernel(struct task_struct *tsk) { }
2118
#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
2219

2320
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
@@ -55,6 +52,18 @@ static inline void vtime_flush(struct task_struct *tsk) { }
5552
static inline bool vtime_accounting_enabled_this_cpu(void) { return true; }
5653
extern void vtime_task_switch(struct task_struct *prev);
5754

55+
static __always_inline void vtime_account_guest_enter(void)
56+
{
57+
vtime_account_kernel(current);
58+
current->flags |= PF_VCPU;
59+
}
60+
61+
static __always_inline void vtime_account_guest_exit(void)
62+
{
63+
vtime_account_kernel(current);
64+
current->flags &= ~PF_VCPU;
65+
}
66+
5867
#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
5968

6069
/*
@@ -86,12 +95,37 @@ static inline void vtime_task_switch(struct task_struct *prev)
8695
vtime_task_switch_generic(prev);
8796
}
8897

98+
static __always_inline void vtime_account_guest_enter(void)
99+
{
100+
if (vtime_accounting_enabled_this_cpu())
101+
vtime_guest_enter(current);
102+
else
103+
current->flags |= PF_VCPU;
104+
}
105+
106+
static __always_inline void vtime_account_guest_exit(void)
107+
{
108+
if (vtime_accounting_enabled_this_cpu())
109+
vtime_guest_exit(current);
110+
else
111+
current->flags &= ~PF_VCPU;
112+
}
113+
89114
#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
90115

91-
static inline bool vtime_accounting_enabled_cpu(int cpu) {return false; }
92116
static inline bool vtime_accounting_enabled_this_cpu(void) { return false; }
93117
static inline void vtime_task_switch(struct task_struct *prev) { }
94118

119+
static __always_inline void vtime_account_guest_enter(void)
120+
{
121+
current->flags |= PF_VCPU;
122+
}
123+
124+
static __always_inline void vtime_account_guest_exit(void)
125+
{
126+
current->flags &= ~PF_VCPU;
127+
}
128+
95129
#endif
96130

97131

0 commit comments

Comments
 (0)