@@ -5379,19 +5379,38 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
5379
5379
5380
5380
static __always_inline void return_cfs_rq_runtime (struct cfs_rq * cfs_rq );
5381
5381
5382
- static void
5382
+ static bool
5383
5383
dequeue_entity (struct cfs_rq * cfs_rq , struct sched_entity * se , int flags )
5384
5384
{
5385
- int action = UPDATE_TG ;
5385
+ update_curr (cfs_rq );
5386
+
5387
+ if (flags & DEQUEUE_DELAYED ) {
5388
+ SCHED_WARN_ON (!se -> sched_delayed );
5389
+ } else {
5390
+ bool sleep = flags & DEQUEUE_SLEEP ;
5386
5391
5392
+ /*
5393
+ * DELAY_DEQUEUE relies on spurious wakeups, special task
5394
+ * states must not suffer spurious wakeups, excempt them.
5395
+ */
5396
+ if (flags & DEQUEUE_SPECIAL )
5397
+ sleep = false;
5398
+
5399
+ SCHED_WARN_ON (sleep && se -> sched_delayed );
5400
+
5401
+ if (sched_feat (DELAY_DEQUEUE ) && sleep &&
5402
+ !entity_eligible (cfs_rq , se )) {
5403
+ if (cfs_rq -> next == se )
5404
+ cfs_rq -> next = NULL ;
5405
+ se -> sched_delayed = 1 ;
5406
+ return false;
5407
+ }
5408
+ }
5409
+
5410
+ int action = UPDATE_TG ;
5387
5411
if (entity_is_task (se ) && task_on_rq_migrating (task_of (se )))
5388
5412
action |= DO_DETACH ;
5389
5413
5390
- /*
5391
- * Update run-time statistics of the 'current'.
5392
- */
5393
- update_curr (cfs_rq );
5394
-
5395
5414
/*
5396
5415
* When dequeuing a sched_entity, we must:
5397
5416
* - Update loads to have both entity and cfs_rq synced with now.
@@ -5428,8 +5447,13 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
5428
5447
if ((flags & (DEQUEUE_SAVE | DEQUEUE_MOVE )) != DEQUEUE_SAVE )
5429
5448
update_min_vruntime (cfs_rq );
5430
5449
5450
+ if (flags & DEQUEUE_DELAYED )
5451
+ se -> sched_delayed = 0 ;
5452
+
5431
5453
if (cfs_rq -> nr_running == 0 )
5432
5454
update_idle_cfs_rq_clock_pelt (cfs_rq );
5455
+
5456
+ return true;
5433
5457
}
5434
5458
5435
5459
static void
@@ -5828,11 +5852,21 @@ static bool throttle_cfs_rq(struct cfs_rq *cfs_rq)
5828
5852
idle_task_delta = cfs_rq -> idle_h_nr_running ;
5829
5853
for_each_sched_entity (se ) {
5830
5854
struct cfs_rq * qcfs_rq = cfs_rq_of (se );
5855
+ int flags ;
5856
+
5831
5857
/* throttled entity or throttle-on-deactivate */
5832
5858
if (!se -> on_rq )
5833
5859
goto done ;
5834
5860
5835
- dequeue_entity (qcfs_rq , se , DEQUEUE_SLEEP );
5861
+ /*
5862
+ * Abuse SPECIAL to avoid delayed dequeue in this instance.
5863
+ * This avoids teaching dequeue_entities() about throttled
5864
+ * entities and keeps things relatively simple.
5865
+ */
5866
+ flags = DEQUEUE_SLEEP | DEQUEUE_SPECIAL ;
5867
+ if (se -> sched_delayed )
5868
+ flags |= DEQUEUE_DELAYED ;
5869
+ dequeue_entity (qcfs_rq , se , flags );
5836
5870
5837
5871
if (cfs_rq_is_idle (group_cfs_rq (se )))
5838
5872
idle_task_delta = cfs_rq -> h_nr_running ;
@@ -6918,6 +6952,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
6918
6952
bool was_sched_idle = sched_idle_rq (rq );
6919
6953
int rq_h_nr_running = rq -> cfs .h_nr_running ;
6920
6954
bool task_sleep = flags & DEQUEUE_SLEEP ;
6955
+ bool task_delayed = flags & DEQUEUE_DELAYED ;
6921
6956
struct task_struct * p = NULL ;
6922
6957
int idle_h_nr_running = 0 ;
6923
6958
int h_nr_running = 0 ;
@@ -6931,7 +6966,13 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
6931
6966
6932
6967
for_each_sched_entity (se ) {
6933
6968
cfs_rq = cfs_rq_of (se );
6934
- dequeue_entity (cfs_rq , se , flags );
6969
+
6970
+ if (!dequeue_entity (cfs_rq , se , flags )) {
6971
+ if (p && & p -> se == se )
6972
+ return -1 ;
6973
+
6974
+ break ;
6975
+ }
6935
6976
6936
6977
cfs_rq -> h_nr_running -= h_nr_running ;
6937
6978
cfs_rq -> idle_h_nr_running -= idle_h_nr_running ;
@@ -6956,6 +6997,7 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
6956
6997
break ;
6957
6998
}
6958
6999
flags |= DEQUEUE_SLEEP ;
7000
+ flags &= ~(DEQUEUE_DELAYED | DEQUEUE_SPECIAL );
6959
7001
}
6960
7002
6961
7003
for_each_sched_entity (se ) {
@@ -6985,6 +7027,17 @@ static int dequeue_entities(struct rq *rq, struct sched_entity *se, int flags)
6985
7027
if (unlikely (!was_sched_idle && sched_idle_rq (rq )))
6986
7028
rq -> next_balance = jiffies ;
6987
7029
7030
+ if (p && task_delayed ) {
7031
+ SCHED_WARN_ON (!task_sleep );
7032
+ SCHED_WARN_ON (p -> on_rq != 1 );
7033
+
7034
+ /* Fix-up what dequeue_task_fair() skipped */
7035
+ hrtick_update (rq );
7036
+
7037
+ /* Fix-up what block_task() skipped. */
7038
+ __block_task (rq , p );
7039
+ }
7040
+
6988
7041
return 1 ;
6989
7042
}
6990
7043
@@ -6997,8 +7050,10 @@ static bool dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
6997
7050
{
6998
7051
util_est_dequeue (& rq -> cfs , p );
6999
7052
7000
- if (dequeue_entities (rq , & p -> se , flags ) < 0 )
7053
+ if (dequeue_entities (rq , & p -> se , flags ) < 0 ) {
7054
+ util_est_update (& rq -> cfs , p , DEQUEUE_SLEEP );
7001
7055
return false;
7056
+ }
7002
7057
7003
7058
util_est_update (& rq -> cfs , p , flags & DEQUEUE_SLEEP );
7004
7059
hrtick_update (rq );
@@ -12971,6 +13026,11 @@ static void set_next_task_fair(struct rq *rq, struct task_struct *p, bool first)
12971
13026
/* ensure bandwidth has been allocated on our new cfs_rq */
12972
13027
account_cfs_rq_runtime (cfs_rq , 0 );
12973
13028
}
13029
+
13030
+ if (!first )
13031
+ return ;
13032
+
13033
+ SCHED_WARN_ON (se -> sched_delayed );
12974
13034
}
12975
13035
12976
13036
void init_cfs_rq (struct cfs_rq * cfs_rq )
0 commit comments