Skip to contentSkip to conversation

sched/fair: simplfy the work when reweighting entity

RFC PATCH Superseded Jiang Biao 3 participants 4 messages Aug 4, 2020 – Aug 6, 2020 Scheduler

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiang Biao

author
#0 lore raw

RFC PATCH 1/1 sched/fair: simplfy the work when reweighting entity

If a se is on_rq when reweighting entity, all we need should be updating the load of cfs_rq, other dequeue/enqueue works could be redundant, such as,
* account_numa_dequeue/account_numa_enqueue
* list_del/list_add from/into cfs_tasks
* nr_running--/nr_running++

Just simplfy the work. Could be helpful for the hot path.

---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 04fa8dbcfa4d..18a8fc7bd0de 100644
@@ -3086,7 +3086,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 		/* commit outstanding execution time */
 		if (cfs_rq->curr == se)
 			update_curr(cfs_rq);
-		account_entity_dequeue(cfs_rq, se);
+		update_load_sub(&cfs_rq->load, se->load.weight);
 	}
 	dequeue_load_avg(cfs_rq, se);
 
@@ -3102,7 +3102,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 
 	enqueue_load_avg(cfs_rq, se);
 	if (se->on_rq)
-		account_entity_enqueue(cfs_rq, se);
+		update_load_add(&cfs_rq->load, se->load.weight);
 
 }
 
Signature · 1 line
2.21.0
#1 lore raw
Quoted 6 lines · Jiang Biao

If a se is on_rq when reweighting entity, all we need should be updating the load of cfs_rq, other dequeue/enqueue works could be redundant, such as,
* account_numa_dequeue/account_numa_enqueue
* list_del/list_add from/into cfs_tasks
* nr_running--/nr_running++

I think this could make sense. Have you spotted a code path where this gives you a change?

I guess only for a task on the rq, so: entity_is_task(se) && se->on_rq

Quoted 1 line

Just simplfy the work. Could be helpful for the hot path.

IMHO hotpath is update_cfs_group() -> reweight_entity() but this is only called for '!entity_is_task(se)'.

See

3290 if (!gcfs_rq)
3291 return;

in update_cfs_group().

The 'entity_is_task(se)' case is

set_load_weight(struct task_struct *p, ...) -> reweight_task(p, ...) -> reweight_entity(..., &p->se, ...)

but here !se->on_rq.

Quoted 26 lines
---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 04fa8dbcfa4d..18a8fc7bd0de 100644
@@ -3086,7 +3086,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 		/* commit outstanding execution time */
 		if (cfs_rq->curr == se)
 			update_curr(cfs_rq);
-		account_entity_dequeue(cfs_rq, se);
+		update_load_sub(&cfs_rq->load, se->load.weight);
 	}
 	dequeue_load_avg(cfs_rq, se);
 
@@ -3102,7 +3102,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 
 	enqueue_load_avg(cfs_rq, se);
 	if (se->on_rq)
-		account_entity_enqueue(cfs_rq, se);
+		update_load_add(&cfs_rq->load, se->load.weight);
 
 }
#2 lore raw
Quoted 12 lines · Dietmar Eggemann
Quoted 6 lines · Jiang Biao

If a se is on_rq when reweighting entity, all we need should be updating the load of cfs_rq, other dequeue/enqueue works could be redundant, such as,
* account_numa_dequeue/account_numa_enqueue
* list_del/list_add from/into cfs_tasks
* nr_running--/nr_running++

Quoted 4 lines

I think this could make sense. Have you spotted a code path where this gives you a change?

I guess only for a task on the rq, so: entity_is_task(se) && se->on_rq

Yes, you're right. No other code path I spotted except what you list below.

Quoted 6 lines
Quoted 2 lines

Just simplfy the work. Could be helpful for the hot path.

IMHO hotpath is update_cfs_group() -> reweight_entity() but this is only called for '!entity_is_task(se)'.

Quoted 6 lines

See

3290 if (!gcfs_rq)
3291 return;

in update_cfs_group().

Yes, It is.
But *nr_running--/nr_running++* works are still redundant for ‘!entity_is_task(se)' hot path. :)
Besides, I guess we could simplify the logic and make it cleaner and more readable with this patch.
If it could make sense to you, would you mind if I resend the patch with the commit log amended?

Quoted 7 lines

The 'entity_is_task(se)' case is

set_load_weight(struct task_struct *p, ...) -> reweight_task(p, ...) -> reweight_entity(..., &p->se, ...)

but here !se->on_rq.

Yes, indeed.

Thanks a lot for your comments.
Regards,
Jiang

Quoted 28 lines
Quoted 27 lines

---
kernel/sched/fair.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 04fa8dbcfa4d..18a8fc7bd0de 100644
@@ -3086,7 +3086,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 		/* commit outstanding execution time */
 		if (cfs_rq->curr == se)
 			update_curr(cfs_rq);
-		account_entity_dequeue(cfs_rq, se);
+		update_load_sub(&cfs_rq->load, se->load.weight);
 	}
 	dequeue_load_avg(cfs_rq, se);
 
@@ -3102,7 +3102,7 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
 
 	enqueue_load_avg(cfs_rq, se);
 	if (se->on_rq)
-		account_entity_enqueue(cfs_rq, se);
+		update_load_add(&cfs_rq->load, se->load.weight);
 
 }
#3 lore raw
Quoted 26 lines · benbjiang(蒋彪)
Quoted 12 lines · Dietmar Eggemann
Quoted 6 lines · Jiang Biao

If a se is on_rq when reweighting entity, all we need should be updating the load of cfs_rq, other dequeue/enqueue works could be redundant, such as,
* account_numa_dequeue/account_numa_enqueue
* list_del/list_add from/into cfs_tasks
* nr_running--/nr_running++

Quoted 4 lines

I think this could make sense. Have you spotted a code path where this gives you a change?

I guess only for a task on the rq, so: entity_is_task(se) && se->on_rq

Yes, you're right. No other code path I spotted except what you list below.

Quoted 8 lines
Quoted 2 lines

Just simplfy the work. Could be helpful for the hot path.

IMHO hotpath is update_cfs_group() -> reweight_entity() but this is only called for '!entity_is_task(se)'.

See

Quoted 7 lines
Quoted 4 lines

3290 if (!gcfs_rq)
3291 return;

in update_cfs_group().

Yes, It is.
But *nr_running--/nr_running++* works are still redundant for ‘!entity_is_task(se)' hot path. :)

True.

Quoted 2 lines

Besides, I guess we could simplify the logic and make it cleaner and more readable with this patch.

Yes.

Quoted 2 lines

If it could make sense to you, would you mind if I resend the patch with the commit log amended?

LGTM so why not?

Quoted 7 lines
Quoted 6 lines

The 'entity_is_task(se)' case is

set_load_weight(struct task_struct *p, ...) -> reweight_task(p, ...) -> reweight_entity(..., &p->se, ...)

but here !se->on_rq.

Yes, indeed.

[...]