Skip to content

Commit 874cd33

Browse files
committed
Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull scheduler fixes from Thomas Gleixner: - two patches addressing the problem that the scheduler allows under certain conditions user space tasks to be scheduled on CPUs which are not yet fully booted which causes a few subtle and hard to debug issue - add a missing runqueue clock update in the deadline scheduler which triggers a warning under certain circumstances - fix a silly typo in the scheduler header file * 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/headers: Fix typo sched/deadline: Fix missing clock update sched/core: Require cpu_active() in select_task_rq(), for user tasks sched/core: Fix rules for running on online && !active CPUs
2 parents 26bdace + 595058b commit 874cd33

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

kernel/sched/core.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,33 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
881881
}
882882

883883
#ifdef CONFIG_SMP
884+
885+
static inline bool is_per_cpu_kthread(struct task_struct *p)
886+
{
887+
if (!(p->flags & PF_KTHREAD))
888+
return false;
889+
890+
if (p->nr_cpus_allowed != 1)
891+
return false;
892+
893+
return true;
894+
}
895+
896+
/*
897+
* Per-CPU kthreads are allowed to run on !actie && online CPUs, see
898+
* __set_cpus_allowed_ptr() and select_fallback_rq().
899+
*/
900+
static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
901+
{
902+
if (!cpumask_test_cpu(cpu, &p->cpus_allowed))
903+
return false;
904+
905+
if (is_per_cpu_kthread(p))
906+
return cpu_online(cpu);
907+
908+
return cpu_active(cpu);
909+
}
910+
884911
/*
885912
* This is how migration works:
886913
*
@@ -938,16 +965,8 @@ struct migration_arg {
938965
static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
939966
struct task_struct *p, int dest_cpu)
940967
{
941-
if (p->flags & PF_KTHREAD) {
942-
if (unlikely(!cpu_online(dest_cpu)))
943-
return rq;
944-
} else {
945-
if (unlikely(!cpu_active(dest_cpu)))
946-
return rq;
947-
}
948-
949968
/* Affinity changed (again). */
950-
if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
969+
if (!is_cpu_allowed(p, dest_cpu))
951970
return rq;
952971

953972
update_rq_clock(rq);
@@ -1476,10 +1495,9 @@ static int select_fallback_rq(int cpu, struct task_struct *p)
14761495
for (;;) {
14771496
/* Any allowed, online CPU? */
14781497
for_each_cpu(dest_cpu, &p->cpus_allowed) {
1479-
if (!(p->flags & PF_KTHREAD) && !cpu_active(dest_cpu))
1480-
continue;
1481-
if (!cpu_online(dest_cpu))
1498+
if (!is_cpu_allowed(p, dest_cpu))
14821499
continue;
1500+
14831501
goto out;
14841502
}
14851503

@@ -1542,8 +1560,7 @@ int select_task_rq(struct task_struct *p, int cpu, int sd_flags, int wake_flags)
15421560
* [ this allows ->select_task() to simply return task_cpu(p) and
15431561
* not worry about this generic constraint ]
15441562
*/
1545-
if (unlikely(!cpumask_test_cpu(cpu, &p->cpus_allowed) ||
1546-
!cpu_online(cpu)))
1563+
if (unlikely(!is_cpu_allowed(p, cpu)))
15471564
cpu = select_fallback_rq(task_cpu(p), p);
15481565

15491566
return cpu;

kernel/sched/deadline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,9 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer)
12591259

12601260
rq = task_rq_lock(p, &rf);
12611261

1262+
sched_clock_tick();
1263+
update_rq_clock(rq);
1264+
12621265
if (!dl_task(p) || p->state == TASK_DEAD) {
12631266
struct dl_bw *dl_b = dl_bw_of(task_cpu(p));
12641267

@@ -1278,9 +1281,6 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer)
12781281
if (dl_se->dl_non_contending == 0)
12791282
goto unlock;
12801283

1281-
sched_clock_tick();
1282-
update_rq_clock(rq);
1283-
12841284
sub_running_bw(dl_se, &rq->dl);
12851285
dl_se->dl_non_contending = 0;
12861286
unlock:

kernel/sched/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static inline void rq_clock_skip_update(struct rq *rq)
983983
}
984984

985985
/*
986-
* See rt task throttoling, which is the only time a skip
986+
* See rt task throttling, which is the only time a skip
987987
* request is cancelled.
988988
*/
989989
static inline void rq_clock_cancel_skipupdate(struct rq *rq)

0 commit comments

Comments
 (0)