Skip to content

Commit af8c5e2

Browse files
committed
Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull scheduler updates from Ingo Molnar: "The main changes in this cycle were: - Implement frequency/CPU invariance and OPP selection for SCHED_DEADLINE (Juri Lelli) - Tweak the task migration logic for better multi-tasking workload scalability (Mel Gorman) - Misc cleanups, fixes and improvements" * 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/deadline: Make bandwidth enforcement scale-invariant sched/cpufreq: Move arch_scale_{freq,cpu}_capacity() outside of #ifdef CONFIG_SMP sched/cpufreq: Remove arch_scale_freq_capacity()'s 'sd' parameter sched/cpufreq: Always consider all CPUs when deciding next freq sched/cpufreq: Split utilization signals sched/cpufreq: Change the worker kthread to SCHED_DEADLINE sched/deadline: Move CPU frequency selection triggering points sched/cpufreq: Use the DEADLINE utilization signal sched/deadline: Implement "runtime overrun signal" support sched/fair: Only immediately migrate tasks due to interrupts if prev and target CPUs share cache sched/fair: Correct obsolete comment about cpufreq_update_util() sched/fair: Remove impossible condition from find_idlest_group_cpu() sched/cpufreq: Don't pass flags to sugov_set_iowait_boost() sched/cpufreq: Initialize sg_cpu->flags to 0 sched/fair: Consider RT/IRQ pressure in capacity_spare_wake() sched/fair: Use 'unsigned long' for utilization, consistently sched/core: Rework and clarify prepare_lock_switch() sched/fair: Remove unused 'curr' parameter from wakeup_gran sched/headers: Constify object_is_on_stack()
2 parents a1c75e1 + 0788116 commit af8c5e2

File tree

12 files changed

+339
-161
lines changed

12 files changed

+339
-161
lines changed

include/linux/arch_topology.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
2727
DECLARE_PER_CPU(unsigned long, freq_scale);
2828

2929
static inline
30-
unsigned long topology_get_freq_scale(struct sched_domain *sd, int cpu)
30+
unsigned long topology_get_freq_scale(int cpu)
3131
{
3232
return per_cpu(freq_scale, cpu);
3333
}

include/linux/sched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,15 @@ struct sched_dl_entity {
472472
* has not been executed yet. This flag is useful to avoid race
473473
* conditions between the inactive timer handler and the wakeup
474474
* code.
475+
*
476+
* @dl_overrun tells if the task asked to be informed about runtime
477+
* overruns.
475478
*/
476479
unsigned int dl_throttled : 1;
477480
unsigned int dl_boosted : 1;
478481
unsigned int dl_yielded : 1;
479482
unsigned int dl_non_contending : 1;
483+
unsigned int dl_overrun : 1;
480484

481485
/*
482486
* Bandwidth enforcement timer. Each -deadline task has its
@@ -1427,6 +1431,7 @@ extern int idle_cpu(int cpu);
14271431
extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *);
14281432
extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *);
14291433
extern int sched_setattr(struct task_struct *, const struct sched_attr *);
1434+
extern int sched_setattr_nocheck(struct task_struct *, const struct sched_attr *);
14301435
extern struct task_struct *idle_task(int cpu);
14311436

14321437
/**

include/linux/sched/cpufreq.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#define SCHED_CPUFREQ_DL (1U << 1)
1313
#define SCHED_CPUFREQ_IOWAIT (1U << 2)
1414

15-
#define SCHED_CPUFREQ_RT_DL (SCHED_CPUFREQ_RT | SCHED_CPUFREQ_DL)
16-
1715
#ifdef CONFIG_CPU_FREQ
1816
struct update_util_data {
1917
void (*func)(struct update_util_data *data, u64 time, unsigned int flags);

include/linux/sched/task_stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static inline void put_task_stack(struct task_struct *tsk) {}
7878
#define task_stack_end_corrupted(task) \
7979
(*(end_of_stack(task)) != STACK_END_MAGIC)
8080

81-
static inline int object_is_on_stack(void *obj)
81+
static inline int object_is_on_stack(const void *obj)
8282
{
8383
void *stack = task_stack_page(current);
8484

include/linux/sched/topology.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
#include <linux/sched/idle.h>
88

9+
/*
10+
* Increase resolution of cpu_capacity calculations
11+
*/
12+
#define SCHED_CAPACITY_SHIFT SCHED_FIXEDPOINT_SHIFT
13+
#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
14+
915
/*
1016
* sched-domains (multiprocessor balancing) declarations:
1117
*/
@@ -27,12 +33,6 @@
2733
#define SD_OVERLAP 0x2000 /* sched_domains of this level overlap */
2834
#define SD_NUMA 0x4000 /* cross-node balancing */
2935

30-
/*
31-
* Increase resolution of cpu_capacity calculations
32-
*/
33-
#define SCHED_CAPACITY_SHIFT SCHED_FIXEDPOINT_SHIFT
34-
#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
35-
3636
#ifdef CONFIG_SCHED_SMT
3737
static inline int cpu_smt_flags(void)
3838
{

include/uapi/linux/sched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@
4949
*/
5050
#define SCHED_FLAG_RESET_ON_FORK 0x01
5151
#define SCHED_FLAG_RECLAIM 0x02
52+
#define SCHED_FLAG_DL_OVERRUN 0x04
53+
54+
#define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \
55+
SCHED_FLAG_RECLAIM | \
56+
SCHED_FLAG_DL_OVERRUN)
5257

5358
#endif /* _UAPI_LINUX_SCHED_H */

kernel/sched/core.c

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
20462046
* If the owning (remote) CPU is still in the middle of schedule() with
20472047
* this task as prev, wait until its done referencing the task.
20482048
*
2049-
* Pairs with the smp_store_release() in finish_lock_switch().
2049+
* Pairs with the smp_store_release() in finish_task().
20502050
*
20512051
* This ensures that tasks getting woken will be fully ordered against
20522052
* their previous state and preserve Program Order.
@@ -2572,6 +2572,50 @@ fire_sched_out_preempt_notifiers(struct task_struct *curr,
25722572

25732573
#endif /* CONFIG_PREEMPT_NOTIFIERS */
25742574

2575+
static inline void prepare_task(struct task_struct *next)
2576+
{
2577+
#ifdef CONFIG_SMP
2578+
/*
2579+
* Claim the task as running, we do this before switching to it
2580+
* such that any running task will have this set.
2581+
*/
2582+
next->on_cpu = 1;
2583+
#endif
2584+
}
2585+
2586+
static inline void finish_task(struct task_struct *prev)
2587+
{
2588+
#ifdef CONFIG_SMP
2589+
/*
2590+
* After ->on_cpu is cleared, the task can be moved to a different CPU.
2591+
* We must ensure this doesn't happen until the switch is completely
2592+
* finished.
2593+
*
2594+
* In particular, the load of prev->state in finish_task_switch() must
2595+
* happen before this.
2596+
*
2597+
* Pairs with the smp_cond_load_acquire() in try_to_wake_up().
2598+
*/
2599+
smp_store_release(&prev->on_cpu, 0);
2600+
#endif
2601+
}
2602+
2603+
static inline void finish_lock_switch(struct rq *rq)
2604+
{
2605+
#ifdef CONFIG_DEBUG_SPINLOCK
2606+
/* this is a valid case when another task releases the spinlock */
2607+
rq->lock.owner = current;
2608+
#endif
2609+
/*
2610+
* If we are tracking spinlock dependencies then we have to
2611+
* fix up the runqueue lock - which gets 'carried over' from
2612+
* prev into current:
2613+
*/
2614+
spin_acquire(&rq->lock.dep_map, 0, 0, _THIS_IP_);
2615+
2616+
raw_spin_unlock_irq(&rq->lock);
2617+
}
2618+
25752619
/**
25762620
* prepare_task_switch - prepare to switch tasks
25772621
* @rq: the runqueue preparing to switch
@@ -2592,7 +2636,7 @@ prepare_task_switch(struct rq *rq, struct task_struct *prev,
25922636
sched_info_switch(rq, prev, next);
25932637
perf_event_task_sched_out(prev, next);
25942638
fire_sched_out_preempt_notifiers(prev, next);
2595-
prepare_lock_switch(rq, next);
2639+
prepare_task(next);
25962640
prepare_arch_switch(next);
25972641
}
25982642

@@ -2647,7 +2691,7 @@ static struct rq *finish_task_switch(struct task_struct *prev)
26472691
* the scheduled task must drop that reference.
26482692
*
26492693
* We must observe prev->state before clearing prev->on_cpu (in
2650-
* finish_lock_switch), otherwise a concurrent wakeup can get prev
2694+
* finish_task), otherwise a concurrent wakeup can get prev
26512695
* running on another CPU and we could rave with its RUNNING -> DEAD
26522696
* transition, resulting in a double drop.
26532697
*/
@@ -2664,7 +2708,8 @@ static struct rq *finish_task_switch(struct task_struct *prev)
26642708
* to use.
26652709
*/
26662710
smp_mb__after_unlock_lock();
2667-
finish_lock_switch(rq, prev);
2711+
finish_task(prev);
2712+
finish_lock_switch(rq);
26682713
finish_arch_post_lock_switch();
26692714

26702715
fire_sched_in_preempt_notifiers(current);
@@ -4041,8 +4086,7 @@ static int __sched_setscheduler(struct task_struct *p,
40414086
return -EINVAL;
40424087
}
40434088

4044-
if (attr->sched_flags &
4045-
~(SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_RECLAIM))
4089+
if (attr->sched_flags & ~(SCHED_FLAG_ALL | SCHED_FLAG_SUGOV))
40464090
return -EINVAL;
40474091

40484092
/*
@@ -4109,6 +4153,9 @@ static int __sched_setscheduler(struct task_struct *p,
41094153
}
41104154

41114155
if (user) {
4156+
if (attr->sched_flags & SCHED_FLAG_SUGOV)
4157+
return -EINVAL;
4158+
41124159
retval = security_task_setscheduler(p);
41134160
if (retval)
41144161
return retval;
@@ -4164,7 +4211,8 @@ static int __sched_setscheduler(struct task_struct *p,
41644211
}
41654212
#endif
41664213
#ifdef CONFIG_SMP
4167-
if (dl_bandwidth_enabled() && dl_policy(policy)) {
4214+
if (dl_bandwidth_enabled() && dl_policy(policy) &&
4215+
!(attr->sched_flags & SCHED_FLAG_SUGOV)) {
41684216
cpumask_t *span = rq->rd->span;
41694217

41704218
/*
@@ -4294,6 +4342,11 @@ int sched_setattr(struct task_struct *p, const struct sched_attr *attr)
42944342
}
42954343
EXPORT_SYMBOL_GPL(sched_setattr);
42964344

4345+
int sched_setattr_nocheck(struct task_struct *p, const struct sched_attr *attr)
4346+
{
4347+
return __sched_setscheduler(p, attr, false, true);
4348+
}
4349+
42974350
/**
42984351
* sched_setscheduler_nocheck - change the scheduling policy and/or RT priority of a thread from kernelspace.
42994352
* @p: the task in question.

0 commit comments

Comments
 (0)