Skip to contentSkip to conversation

sched/fair: Fix the wrong throttled clock time for cfs_rq_clock_task()

PATCH In review Xunlei Pang 5 participants 6 messages May 10, 2016 – Jun 3, 2016 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/fair: Fix the wrong throttled clock time for cfs_rq_clock_task()

Two minor fixes for cfs_rq_clock_task().
1) If cfs_rq is currently being throttled, we need to subtract the cfs throttled clock time.

2) Make "throttled_clock_task_time" update SMP unrelated. Now UP cases need it as well.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index 1708729e..fb80a12 100644
@@ -3655,7 +3655,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
 static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
 {
 	if (unlikely(cfs_rq->throttle_count))
-		return cfs_rq->throttled_clock_task;
+		return cfs_rq->throttled_clock_task - cfs_rq->throttled_clock_task_time;
 
 	return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
 }
@@ -3793,13 +3793,11 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
 
 	cfs_rq->throttle_count--;
-#ifdef CONFIG_SMP
 	if (!cfs_rq->throttle_count) {
 		/* adjust cfs_rq_clock_task() */
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 	}
-#endif
 
 	return 0;
 }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 29 lines · Xunlei Pang

Two minor fixes for cfs_rq_clock_task().
1) If cfs_rq is currently being throttled, we need to subtract the cfs throttled clock time.

2) Make "throttled_clock_task_time" update SMP unrelated. Now UP cases need it as well.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -1
index 1708729e..fb80a12 100644
@@ -3655,7 +3655,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
 static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
 {
 	if (unlikely(cfs_rq->throttle_count))
-		return cfs_rq->throttled_clock_task;
+		return cfs_rq->throttled_clock_task - cfs_rq->throttled_clock_task_time;
 
 	return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
 }
@@ -3793,13 +3793,11 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
 
 	cfs_rq->throttle_count--;

kernel/sched/fair.c static int tg_unthrottle_up(struct task_group *tg, void *data) · line 3803

Quoted 10 lines
kernel/sched/fair.c +0 -2
-#ifdef CONFIG_SMP
 	if (!cfs_rq->throttle_count) {
 		/* adjust cfs_rq_clock_task() */
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 	}
-#endif
 
 	return 0;
 }

[Cc: [email protected]]

This looks reasonable to me (at least the first part; I'm not certain why the CONFIG_SMP ifdef was put in place).

maintainer
#2 lore raw
Quoted 25 lines · On Tue, May 10, 2016 at 11:19:44AM -0700, [email protected] wrote:
Quoted 23 lines · Xunlei Pang

Two minor fixes for cfs_rq_clock_task().
1) If cfs_rq is currently being throttled, we need to subtract the cfs throttled clock time.

2) Make "throttled_clock_task_time" update SMP unrelated. Now UP cases need it as well.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -1
index 1708729e..fb80a12 100644
@@ -3655,7 +3655,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
 static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
 {
 	if (unlikely(cfs_rq->throttle_count))
-		return cfs_rq->throttled_clock_task;
+		return cfs_rq->throttled_clock_task - cfs_rq->throttled_clock_task_time;
 
Quoted 2 lines

kernel/sched/fair.c static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg) · line 3661

Quoted 2 lines
kernel/sched/fair.c +0 -0
 	return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
 }

The alternative is obviously to do the subtraction in tg_throttle_down(), were we set ->throttled_clock_task.

Quoted 12 lines
Quoted 12 lines
kernel/sched/fair.c +0 -2
@@ -3793,13 +3793,11 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
 
 	cfs_rq->throttle_count--;
-#ifdef CONFIG_SMP
 	if (!cfs_rq->throttle_count) {
 		/* adjust cfs_rq_clock_task() */
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 	}
-#endif
 
Quoted 7 lines

kernel/sched/fair.c static int tg_unthrottle_up(struct task_group *tg, void *data) · line 3803

Quoted 2 lines
kernel/sched/fair.c +0 -0
 	return 0;
 }

[Cc: [email protected]]

This looks reasonable to me (at least the first part; I'm not certain why the CONFIG_SMP ifdef was put in place).

64660c864f46 ("sched: Prevent interactions with throttled entities")

Introduced it, because at that time it was about updating shares, which is only present on SMP. Then:

f1b17280efbd ("sched: Maintain runnable averages across throttled periods")

Added the clock thing inside it, and:

82958366cfea ("sched: Replace update_shares weight distribution with per-entity computation")

took out the shares update and left the clock update, resulting in the current code.

#3 lore raw
Quoted 26 lines · Peter Zijlstra
Quoted 25 lines · On Tue, May 10, 2016 at 11:19:44AM -0700, [email protected] wrote:
Quoted 23 lines · Xunlei Pang

Two minor fixes for cfs_rq_clock_task().
1) If cfs_rq is currently being throttled, we need to subtract the cfs throttled clock time.

2) Make "throttled_clock_task_time" update SMP unrelated. Now UP cases need it as well.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -1
index 1708729e..fb80a12 100644
@@ -3655,7 +3655,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
 static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
 {
 	if (unlikely(cfs_rq->throttle_count))
-		return cfs_rq->throttled_clock_task;
+		return cfs_rq->throttled_clock_task - cfs_rq->throttled_clock_task_time;
 
Quoted 4 lines
Quoted 2 lines

kernel/sched/fair.c static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg) · line 3661

Quoted 2 lines
kernel/sched/fair.c +0 -0
 	return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
 }

The alternative is obviously to do the subtraction in tg_throttle_down(), were we set ->throttled_clock_task.

It is possible, but throttled_clock_task is a timestamp, I think doing it here is semantically better.

Quoted 24 lines
Quoted 13 lines
Quoted 13 lines
kernel/sched/fair.c +0 -2
@@ -3793,13 +3793,11 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
 
 	cfs_rq->throttle_count--;
-#ifdef CONFIG_SMP
 	if (!cfs_rq->throttle_count) {
 		/* adjust cfs_rq_clock_task() */
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 	}
-#endif
 
Quoted 6 lines

kernel/sched/fair.c static int tg_unthrottle_up(struct task_group *tg, void *data) · line 3803

Quoted 2 lines
kernel/sched/fair.c +0 -0
 	return 0;
 }

[Cc: [email protected]]

This looks reasonable to me (at least the first part; I'm not certain why the CONFIG_SMP ifdef was put in place).

64660c864f46 ("sched: Prevent interactions with throttled entities")

Introduced it, because at that time it was about updating shares, which is only present on SMP. Then:

Quoted 10 lines

f1b17280efbd ("sched: Maintain runnable averages across throttled periods")

Added the clock thing inside it, and:

82958366cfea ("sched: Replace update_shares weight distribution with per-entity computation")

took out the shares update and left the clock update, resulting in the current code.

Thanks,
Xunlei

#4 lore raw

Ping

Quoted 69 lines · Xunlei Pang
Quoted 26 lines · Peter Zijlstra
Quoted 25 lines · On Tue, May 10, 2016 at 11:19:44AM -0700, [email protected] wrote:
Quoted 23 lines · Xunlei Pang

Two minor fixes for cfs_rq_clock_task().
1) If cfs_rq is currently being throttled, we need to subtract the cfs throttled clock time.

2) Make "throttled_clock_task_time" update SMP unrelated. Now UP cases need it as well.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -1
index 1708729e..fb80a12 100644
@@ -3655,7 +3655,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
 static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
 {
 	if (unlikely(cfs_rq->throttle_count))
-		return cfs_rq->throttled_clock_task;
+		return cfs_rq->throttled_clock_task - cfs_rq->throttled_clock_task_time;
 
Quoted 4 lines
Quoted 2 lines

kernel/sched/fair.c static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg) · line 3661

Quoted 2 lines
kernel/sched/fair.c +0 -0
 	return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
 }

The alternative is obviously to do the subtraction in tg_throttle_down(), were we set ->throttled_clock_task.

It is possible, but throttled_clock_task is a timestamp, I think doing it here is semantically better.

Quoted 23 lines
Quoted 12 lines
Quoted 12 lines
kernel/sched/fair.c +0 -2
@@ -3793,13 +3793,11 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
 
 	cfs_rq->throttle_count--;
-#ifdef CONFIG_SMP
 	if (!cfs_rq->throttle_count) {
 		/* adjust cfs_rq_clock_task() */
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 	}
-#endif
 
Quoted 6 lines

kernel/sched/fair.c static int tg_unthrottle_up(struct task_group *tg, void *data) · line 3803

Quoted 2 lines
kernel/sched/fair.c +0 -0
 	return 0;
 }

[Cc: [email protected]]

This looks reasonable to me (at least the first part; I'm not certain why the CONFIG_SMP ifdef was put in place).

64660c864f46 ("sched: Prevent interactions with throttled entities")

Introduced it, because at that time it was about updating shares, which is only present on SMP. Then:

Quoted 10 lines

f1b17280efbd ("sched: Maintain runnable averages across throttled periods")

Added the clock thing inside it, and:

82958366cfea ("sched: Replace update_shares weight distribution with per-entity computation")

took out the shares update and left the clock update, resulting in the current code.

Thanks,
Xunlei

#5 lore raw
In reply to Xunlei Pang
sched/fair: Fix the wrong throttled clock time for cfs_rq_clock_task()
Commit-ID:  1a99ae3f00d3c7c7885ee529ac9a874b19caa0cf
Gitweb:     http://git.kernel.org/tip/1a99ae3f00d3c7c7885ee529ac9a874b19caa0cf
Author:     Xunlei Pang <[email protected]>
AuthorDate: Tue, 10 May 2016 21:03:18 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Jun 2016 09:18:56 +0200

sched/fair: Fix the wrong throttled clock time for cfs_rq_clock_task()

Two minor fixes for cfs_rq_clock_task():

1) If cfs_rq is currently being throttled, we need to subtract the cfs throttled clock time.

2) Make "throttled_clock_task_time" update SMP unrelated. Now UP cases need it as well.

---
 kernel/sched/fair.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/fair.c +1 -3
index 218f8e8..1e87bb6 100644
@@ -3688,7 +3688,7 @@ static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
 static inline u64 cfs_rq_clock_task(struct cfs_rq *cfs_rq)
 {
 	if (unlikely(cfs_rq->throttle_count))
-		return cfs_rq->throttled_clock_task;
+		return cfs_rq->throttled_clock_task - cfs_rq->throttled_clock_task_time;
 
 	return rq_clock_task(rq_of(cfs_rq)) - cfs_rq->throttled_clock_task_time;
 }
@@ -3826,13 +3826,11 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
 
 	cfs_rq->throttle_count--;
-#ifdef CONFIG_SMP
 	if (!cfs_rq->throttle_count) {
 		/* adjust cfs_rq_clock_task() */
 		cfs_rq->throttled_clock_task_time += rq_clock_task(rq) -
 					     cfs_rq->throttled_clock_task;
 	}
-#endif
 
 	return 0;
 }