Skip to content

Commit 2b05a0b

Browse files
cobrien7Peter Zijlstra
authored andcommitted
sched: Add move_queued_task_locked helper
Switch logic that deactivates, sets the task cpu, and reactivates a task on a different rq to use a helper that will be later extended to push entire blocked task chains. This patch was broken out from a larger chain migration patch originally by Connor O'Brien. [jstultz: split out from larger chain migration patch] Signed-off-by: Connor O'Brien <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Metin Kaya <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Reviewed-by: Qais Yousef <[email protected]> Tested-by: K Prateek Nayak <[email protected]> Tested-by: Metin Kaya <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3a9320e commit 2b05a0b

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

kernel/sched/core.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,9 +2620,7 @@ int push_cpu_stop(void *arg)
26202620

26212621
// XXX validate p is still the highest prio task
26222622
if (task_rq(p) == rq) {
2623-
deactivate_task(rq, p, 0);
2624-
set_task_cpu(p, lowest_rq->cpu);
2625-
activate_task(lowest_rq, p, 0);
2623+
move_queued_task_locked(rq, lowest_rq, p);
26262624
resched_curr(lowest_rq);
26272625
}
26282626

@@ -3309,9 +3307,7 @@ static void __migrate_swap_task(struct task_struct *p, int cpu)
33093307
rq_pin_lock(src_rq, &srf);
33103308
rq_pin_lock(dst_rq, &drf);
33113309

3312-
deactivate_task(src_rq, p, 0);
3313-
set_task_cpu(p, cpu);
3314-
activate_task(dst_rq, p, 0);
3310+
move_queued_task_locked(src_rq, dst_rq, p);
33153311
wakeup_preempt(dst_rq, p, 0);
33163312

33173313
rq_unpin_lock(dst_rq, &drf);
@@ -6300,10 +6296,7 @@ static bool try_steal_cookie(int this, int that)
63006296
if (sched_task_is_throttled(p, this))
63016297
goto next;
63026298

6303-
deactivate_task(src, p, 0);
6304-
set_task_cpu(p, this);
6305-
activate_task(dst, p, 0);
6306-
6299+
move_queued_task_locked(src, dst, p);
63076300
resched_curr(dst);
63086301

63096302
success = true;

kernel/sched/deadline.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,9 +2751,7 @@ static int push_dl_task(struct rq *rq)
27512751
goto retry;
27522752
}
27532753

2754-
deactivate_task(rq, next_task, 0);
2755-
set_task_cpu(next_task, later_rq->cpu);
2756-
activate_task(later_rq, next_task, 0);
2754+
move_queued_task_locked(rq, later_rq, next_task);
27572755
ret = 1;
27582756

27592757
resched_curr(later_rq);
@@ -2839,9 +2837,7 @@ static void pull_dl_task(struct rq *this_rq)
28392837
if (is_migration_disabled(p)) {
28402838
push_task = get_push_task(src_rq);
28412839
} else {
2842-
deactivate_task(src_rq, p, 0);
2843-
set_task_cpu(p, this_cpu);
2844-
activate_task(this_rq, p, 0);
2840+
move_queued_task_locked(src_rq, this_rq, p);
28452841
dmin = p->dl.deadline;
28462842
resched = true;
28472843
}

kernel/sched/rt.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,9 +2088,7 @@ static int push_rt_task(struct rq *rq, bool pull)
20882088
goto retry;
20892089
}
20902090

2091-
deactivate_task(rq, next_task, 0);
2092-
set_task_cpu(next_task, lowest_rq->cpu);
2093-
activate_task(lowest_rq, next_task, 0);
2091+
move_queued_task_locked(rq, lowest_rq, next_task);
20942092
resched_curr(lowest_rq);
20952093
ret = 1;
20962094

@@ -2361,9 +2359,7 @@ static void pull_rt_task(struct rq *this_rq)
23612359
if (is_migration_disabled(p)) {
23622360
push_task = get_push_task(src_rq);
23632361
} else {
2364-
deactivate_task(src_rq, p, 0);
2365-
set_task_cpu(p, this_cpu);
2366-
activate_task(this_rq, p, 0);
2362+
move_queued_task_locked(src_rq, this_rq, p);
23672363
resched = true;
23682364
}
23692365
/*

kernel/sched/sched.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,18 @@ static inline void init_sched_mm_cid(struct task_struct *t) { }
37883788

37893789
extern u64 avg_vruntime(struct cfs_rq *cfs_rq);
37903790
extern int entity_eligible(struct cfs_rq *cfs_rq, struct sched_entity *se);
3791+
#ifdef CONFIG_SMP
3792+
static inline
3793+
void move_queued_task_locked(struct rq *src_rq, struct rq *dst_rq, struct task_struct *task)
3794+
{
3795+
lockdep_assert_rq_held(src_rq);
3796+
lockdep_assert_rq_held(dst_rq);
3797+
3798+
deactivate_task(src_rq, task, 0);
3799+
set_task_cpu(task, dst_rq->cpu);
3800+
activate_task(dst_rq, task, 0);
3801+
}
3802+
#endif
37913803

37923804
#ifdef CONFIG_RT_MUTEXES
37933805

0 commit comments

Comments
 (0)