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: add WF_CURRENT_CPU and externise ttwu

Add WF_CURRENT_CPU wake flag that advices the scheduler to
move the wakee to the current CPU. This is useful for fast on-CPU
context switching use cases.

In addition, make ttwu external rather than static so that
the flag could be passed to it from outside of sched/core.c.

Signed-off-by: Peter Oskolkov <posk@google.com>
Signed-off-by: Andrei Vagin <avagin@google.com>
Acked-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230308073201.3102738-3-avagin@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>

authored by

Peter Oskolkov and committed by
Kees Cook
ab83f455 4943b66d

+13 -7
+1 -2
kernel/sched/core.c
··· 4193 4193 * Return: %true if @p->state changes (an actual wakeup was done), 4194 4194 * %false otherwise. 4195 4195 */ 4196 - static int 4197 - try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) 4196 + int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) 4198 4197 { 4199 4198 unsigned long flags; 4200 4199 int cpu, success = 0;
+4
kernel/sched/fair.c
··· 7741 7741 if (wake_flags & WF_TTWU) { 7742 7742 record_wakee(p); 7743 7743 7744 + if ((wake_flags & WF_CURRENT_CPU) && 7745 + cpumask_test_cpu(cpu, p->cpus_ptr)) 7746 + return cpu; 7747 + 7744 7748 if (sched_energy_enabled()) { 7745 7749 new_cpu = find_energy_efficient_cpu(p, prev_cpu); 7746 7750 if (new_cpu >= 0)
+8 -5
kernel/sched/sched.h
··· 2131 2131 } 2132 2132 2133 2133 /* Wake flags. The first three directly map to some SD flag value */ 2134 - #define WF_EXEC 0x02 /* Wakeup after exec; maps to SD_BALANCE_EXEC */ 2135 - #define WF_FORK 0x04 /* Wakeup after fork; maps to SD_BALANCE_FORK */ 2136 - #define WF_TTWU 0x08 /* Wakeup; maps to SD_BALANCE_WAKE */ 2134 + #define WF_EXEC 0x02 /* Wakeup after exec; maps to SD_BALANCE_EXEC */ 2135 + #define WF_FORK 0x04 /* Wakeup after fork; maps to SD_BALANCE_FORK */ 2136 + #define WF_TTWU 0x08 /* Wakeup; maps to SD_BALANCE_WAKE */ 2137 2137 2138 - #define WF_SYNC 0x10 /* Waker goes to sleep after wakeup */ 2139 - #define WF_MIGRATED 0x20 /* Internal use, task got migrated */ 2138 + #define WF_SYNC 0x10 /* Waker goes to sleep after wakeup */ 2139 + #define WF_MIGRATED 0x20 /* Internal use, task got migrated */ 2140 + #define WF_CURRENT_CPU 0x40 /* Prefer to move the wakee to the current CPU. */ 2140 2141 2141 2142 #ifdef CONFIG_SMP 2142 2143 static_assert(WF_EXEC == SD_BALANCE_EXEC); ··· 3229 3228 3230 3229 extern void swake_up_all_locked(struct swait_queue_head *q); 3231 3230 extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait); 3231 + 3232 + extern int try_to_wake_up(struct task_struct *tsk, unsigned int state, int wake_flags); 3232 3233 3233 3234 #ifdef CONFIG_PREEMPT_DYNAMIC 3234 3235 extern int preempt_dynamic_mode;