History

sched/cputime: Spare a seqcount lock/unlock cycle on context switch

On context switch we are locking the vtime seqcount of the scheduling-out task twice: * On vtime_task_switch_common(), when we flush the pending vtime through vtime_account_system() * On arch_vtime_task_switch() to reset the vtime state. This is pointless as these actions can be performed without the need to unlock/lock in the middle. The reason these steps are separated is to consolidate a very small amount of common code between CONFIG_VIRT_CPU_ACCOUNTING_GEN and CONFIG_VIRT_CPU_ACCOUNTING_NATIVE. Performance in this fast path is definitely a priority over artificial code factorization so split the task switch code between GEN and NATIVE and mutualize the parts than can run under a single seqcount locked block. As a side effect, vtime_account_idle() becomes included in the seqcount protection. This happens to be a welcome preparation in order to properly support kcpustat under vtime in the future and fetch CPUTIME_IDLE without race.

Frederic Weisbecker committed 7 years ago

Commit 8d495471 parent f83eeb12 files · +35 −27Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/vtime.h+16−16
@@ -14,8 +14,12 @@ struct task_struct; · 13 unmodified lines
14 * vtime_accounting_cpu_enabled() definitions/declarations14 * vtime_accounting_cpu_enabled() definitions/declarations
15 */15 */
16#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)16#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)
17
17static inline bool vtime_accounting_cpu_enabled(void) { return true; }18static inline bool vtime_accounting_cpu_enabled(void) { return true; }
19extern void vtime_task_switch(struct task_struct *prev);
20
18#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)21#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
22
19/*23/*
20 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful24 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
21 * in that case and compute the tickless cputime.25 * in that case and compute the tickless cputime.
@@ -36,33 +40,29 @@ static inline bool vtime_accounting_cpu_enabled(void) · 14 unmodified lines
36 40
37 return false;41 return false;
38}42}
43
44extern void vtime_task_switch_generic(struct task_struct *prev);
45
46static inline void vtime_task_switch(struct task_struct *prev)
47{
48 if (vtime_accounting_cpu_enabled())
49 vtime_task_switch_generic(prev);
50}
51
39#else /* !CONFIG_VIRT_CPU_ACCOUNTING */52#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
53
40static inline bool vtime_accounting_cpu_enabled(void) { return false; }54static inline bool vtime_accounting_cpu_enabled(void) { return false; }
41#endif55static inline void vtime_task_switch(struct task_struct *prev) { }
42 56
57#endif
43 58
44/*59/*
45 * Common vtime APIs60 * Common vtime APIs
46 */61 */
47#ifdef CONFIG_VIRT_CPU_ACCOUNTING62#ifdef CONFIG_VIRT_CPU_ACCOUNTING
48
49#ifdef __ARCH_HAS_VTIME_TASK_SWITCH
50extern void vtime_task_switch(struct task_struct *prev);
51#else
52extern void vtime_common_task_switch(struct task_struct *prev);
53static inline void vtime_task_switch(struct task_struct *prev)
54{
55 if (vtime_accounting_cpu_enabled())
56 vtime_common_task_switch(prev);
57}
58#endif /* __ARCH_HAS_VTIME_TASK_SWITCH */
59
60extern void vtime_account_kernel(struct task_struct *tsk);63extern void vtime_account_kernel(struct task_struct *tsk);
61extern void vtime_account_idle(struct task_struct *tsk);64extern void vtime_account_idle(struct task_struct *tsk);
62
63#else /* !CONFIG_VIRT_CPU_ACCOUNTING */65#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
64
65static inline void vtime_task_switch(struct task_struct *prev) { }
66static inline void vtime_account_kernel(struct task_struct *tsk) { }66static inline void vtime_account_kernel(struct task_struct *tsk) { }
67#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */67#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
68 68

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t