Skip to content

Commit ab83f45

Browse files
posk-iokees
authored andcommitted
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 <[email protected]> Signed-off-by: Andrei Vagin <[email protected]> Acked-by: "Peter Zijlstra (Intel)" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 4943b66 commit ab83f45

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

kernel/sched/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4193,8 +4193,7 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
41934193
* Return: %true if @p->state changes (an actual wakeup was done),
41944194
* %false otherwise.
41954195
*/
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)
41984197
{
41994198
unsigned long flags;
42004199
int cpu, success = 0;

kernel/sched/fair.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7741,6 +7741,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
77417741
if (wake_flags & WF_TTWU) {
77427742
record_wakee(p);
77437743

7744+
if ((wake_flags & WF_CURRENT_CPU) &&
7745+
cpumask_test_cpu(cpu, p->cpus_ptr))
7746+
return cpu;
7747+
77447748
if (sched_energy_enabled()) {
77457749
new_cpu = find_energy_efficient_cpu(p, prev_cpu);
77467750
if (new_cpu >= 0)

kernel/sched/sched.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,12 +2131,13 @@ static inline int task_on_rq_migrating(struct task_struct *p)
21312131
}
21322132

21332133
/* 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 */
21372137

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. */
21402141

21412142
#ifdef CONFIG_SMP
21422143
static_assert(WF_EXEC == SD_BALANCE_EXEC);
@@ -3229,6 +3230,8 @@ static inline bool is_per_cpu_kthread(struct task_struct *p)
32293230
extern void swake_up_all_locked(struct swait_queue_head *q);
32303231
extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
32313232

3233+
extern int try_to_wake_up(struct task_struct *tsk, unsigned int state, int wake_flags);
3234+
32323235
#ifdef CONFIG_PREEMPT_DYNAMIC
32333236
extern int preempt_dynamic_mode;
32343237
extern int sched_dynamic_mode(const char *str);

0 commit comments

Comments
 (0)