Skip to content

Commit 781773e

Browse files
author
Peter Zijlstra
committed
sched/fair: Implement ENQUEUE_DELAYED
Doing a wakeup on a delayed dequeue task is about as simple as it sounds -- remove the delayed mark and enjoy the fact it was actually still on the runqueue. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Tested-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent f12e148 commit 781773e

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

kernel/sched/fair.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,6 +5289,9 @@ static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
52895289

52905290
static inline bool cfs_bandwidth_used(void);
52915291

5292+
static void
5293+
requeue_delayed_entity(struct sched_entity *se);
5294+
52925295
static void
52935296
enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
52945297
{
@@ -5922,8 +5925,10 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq)
59225925
for_each_sched_entity(se) {
59235926
struct cfs_rq *qcfs_rq = cfs_rq_of(se);
59245927

5925-
if (se->on_rq)
5928+
if (se->on_rq) {
5929+
SCHED_WARN_ON(se->sched_delayed);
59265930
break;
5931+
}
59275932
enqueue_entity(qcfs_rq, se, ENQUEUE_WAKEUP);
59285933

59295934
if (cfs_rq_is_idle(group_cfs_rq(se)))
@@ -6773,6 +6778,22 @@ static int sched_idle_cpu(int cpu)
67736778
}
67746779
#endif
67756780

6781+
static void
6782+
requeue_delayed_entity(struct sched_entity *se)
6783+
{
6784+
struct cfs_rq *cfs_rq = cfs_rq_of(se);
6785+
6786+
/*
6787+
* se->sched_delayed should imply: se->on_rq == 1.
6788+
* Because a delayed entity is one that is still on
6789+
* the runqueue competing until elegibility.
6790+
*/
6791+
SCHED_WARN_ON(!se->sched_delayed);
6792+
SCHED_WARN_ON(!se->on_rq);
6793+
6794+
se->sched_delayed = 0;
6795+
}
6796+
67766797
/*
67776798
* The enqueue_task method is called before nr_running is
67786799
* increased. Here we update the fair scheduling stats and
@@ -6787,6 +6808,11 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
67876808
int task_new = !(flags & ENQUEUE_WAKEUP);
67886809
int rq_h_nr_running = rq->cfs.h_nr_running;
67896810

6811+
if (flags & ENQUEUE_DELAYED) {
6812+
requeue_delayed_entity(se);
6813+
return;
6814+
}
6815+
67906816
/*
67916817
* The code below (indirectly) updates schedutil which looks at
67926818
* the cfs_rq utilization to select a frequency.
@@ -6804,8 +6830,11 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
68046830
cpufreq_update_util(rq, SCHED_CPUFREQ_IOWAIT);
68056831

68066832
for_each_sched_entity(se) {
6807-
if (se->on_rq)
6833+
if (se->on_rq) {
6834+
if (se->sched_delayed)
6835+
requeue_delayed_entity(se);
68086836
break;
6837+
}
68096838
cfs_rq = cfs_rq_of(se);
68106839
enqueue_entity(cfs_rq, se, flags);
68116840

0 commit comments

Comments
 (0)