sched/uclamp: Fix overzealous type replacement
PATCH v2 1/1 sched/uclamp: Fix overzealous type replacement
Some uclamp helpers had their return type changed from 'unsigned int' to 'enum uclamp_id' by commit
0413d7f33e60 ("sched/uclamp: Always use 'enum uclamp_id' for clamp_id values")
but it happens that some do return a value in the [0, SCHED_CAPACITY_SCALE] range, which should really be unsigned int. The affected helpers are uclamp_none(), uclamp_rq_max_value() and uclamp_eff_value(). Fix those up.
Note that this doesn't lead to any obj diff using a relatively recent aarch64 compiler (8.3-2019.03). The current code of e.g. uclamp_eff_value() properly returns an 11 bit value (bits_per(1024)) and doesn't seem to do anything funny. I'm still marking this as fixing the above commit to be on the safe side.
---
v2 changes:
o Also fix uclamp_none() (Vincent)
o Collect reviewed-by
o Slightly reword changelog
--- kernel/sched/core.c | 6 +++--- kernel/sched/sched.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/sched/core.c +3 -3
@@ -810,7 +810,7 @@ static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value)return UCLAMP_BUCKET_DELTA *uclamp_bucket_id (clamp_value); } -static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id) {if (clamp_id ==UCLAMP_MIN )return 0 ;
@@ -853,7 +853,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id, }static inline -enum uclamp_id uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id, +unsigned int uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id,unsigned int clamp_value) {struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket;
@@ -918,7 +918,7 @@ uclamp_eff_get(struct task_struct *p, enum uclamp_id clamp_id)return uc_req; } -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) {struct uclamp_se uc_eff;
kernel/sched/sched.h +1 -1
@@ -2300,7 +2300,7 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}#endif /* CONFIG_CPU_FREQ */ #ifdef CONFIG_UCLAMP_TASK -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); static __always_inline unsigned int uclamp_util_with(struct rq *rq, unsigned int util,
Signature · 1 line
2.22.0
Vincent Guittot
maintainerQuoted 34 lines · Valentin Schneider
Some uclamp helpers had their return type changed from 'unsigned int' to 'enum
uclamp_id' by commit
0413d7f33e60("sched/uclamp: Always use 'enumuclamp_id' forclamp_idvalues")but it happens that some do return a value in the [0,
SCHED_CAPACITY_SCALE] range, which should really be unsigned int. The affected helpers areuclamp_none(),uclamp_rq_max_value()anduclamp_eff_value(). Fix those up.Note that this doesn't lead to any obj diff using a relatively recent aarch64 compiler (8.3-2019.03). The current code of e.g.
uclamp_eff_value()properly returns an 11 bit value (bits_per(1024)) and doesn't seem to do anything funny. I'm still marking this as fixing the above commit to be on the safe side.Fixes 0413d7f33e60 ("sched/uclamp: Always use 'enum uclamp_id' for clamp_id values")Reviewed-by Qais Yousef <[email protected]>Signed-off-by Valentin Schneider <[email protected]>---
v2 changes:
o Also fixuclamp_none()(Vincent)
o Collect reviewed-by
o Slightly reword changelog--- kernel/sched/core.c | 6 +++--- kernel/sched/sched.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)kernel/sched/core.c +0
-0
kernel/sched/core.c static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value) · line 813
Quoted 5 lines
kernel/sched/core.c +1
-1@@ -810,7 +810,7 @@ static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value)return UCLAMP_BUCKET_DELTA *uclamp_bucket_id (clamp_value); } -static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id)
Out of curiosity why uclamp decided to use unsigned int to manipulate utilization instead of unsigned long which is the type of util_avg ?
Quoted 37 lines
kernel/sched/core.c +2
-2{if (clamp_id ==UCLAMP_MIN )return 0 ;@@ -853,7 +853,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id, }static inline -enum uclamp_id uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id, +unsigned int uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id,unsigned int clamp_value) {struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket;@@ -918,7 +918,7 @@ uclamp_eff_get(struct task_struct *p, enum uclamp_id clamp_id)return uc_req; } -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) {struct uclamp_se uc_eff;kernel/sched/sched.h +1
-2@@ -2300,7 +2300,7 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}#endif /* CONFIG_CPU_FREQ */ #ifdef CONFIG_UCLAMP_TASK -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); static __always_inline unsigned int uclamp_util_with(struct rq *rq, unsigned int util, --2.22.0
Quoted 6 lines · Vincent Guittot
kernel/sched/core.c static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value) · line 813
Quoted 2 lines
kernel/sched/core.c +1
-1-static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id)Out of curiosity why uclamp decided to use unsigned int to manipulate utilization instead of unsigned long which is the type of
util_avg?
I didn't stare at the discussion much, but I think it stems from the design choices behind struct uclamp_se: everything is crammed in an unsigned int bitfield. Let me see if I can find some relevant mails.
Quoted 8 lines · Valentin Schneider
Quoted 6 lines · Vincent Guittot
kernel/sched/core.c static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value) · line 813
Quoted 2 lines
kernel/sched/core.c +1
-1-static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id)Out of curiosity why uclamp decided to use unsigned int to manipulate utilization instead of unsigned long which is the type of
util_avg?
Quoted 4 lines
I didn't stare at the discussion much, but I think it stems from the design choices behind struct
uclamp_se: everything is crammed in an unsigned int bitfield. Let me see if I can find some relevant mails.
So I think a relevant mail is:
https://lore.kernel.org/lkml/[email protected]/
Other than that, the uclamp_se.value field was 'int' in v1 and has been 'unsigned int' for all following versions. uclamp_bucket.value is a bitfield of an 'unsigned long' just because we want more headroom for the tasks count, AFAICT.
Vincent Guittot
maintainerQuoted 15 lines · Valentin Schneider
Quoted 8 lines · Valentin Schneider
Quoted 6 lines · Vincent Guittot
kernel/sched/core.c static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value) · line 813
Quoted 2 lines
kernel/sched/core.c +1
-1-static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id)Out of curiosity why uclamp decided to use unsigned int to manipulate utilization instead of unsigned long which is the type of
util_avg?Quoted 4 lines
I didn't stare at the discussion much, but I think it stems from the design choices behind struct
uclamp_se: everything is crammed in an unsigned int bitfield. Let me see if I can find some relevant mails.
Quoted 8 lines
So I think a relevant mail is:
https://lore.kernel.org/lkml/[email protected]/
Other than that, the uclamp_se.value field was 'int' in v1 and has been 'unsigned int' for all following versions. uclamp_bucket.value is a bitfield of an 'unsigned long' just because we want more headroom for the tasks count, AFAICT.
Thanks for the pointer and deep diving in the email threads
Peter Zijlstra
maintainerQuoted 19 lines · Vincent Guittot
Quoted 17 lines · Valentin Schneider
Quoted 8 lines · Valentin Schneider
Quoted 6 lines · Vincent Guittot
kernel/sched/core.c static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value) · line 813
Quoted 2 lines
kernel/sched/core.c +1
-1-static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id)Out of curiosity why uclamp decided to use unsigned int to manipulate utilization instead of unsigned long which is the type of
util_avg?Quoted 4 lines
I didn't stare at the discussion much, but I think it stems from the design choices behind struct
uclamp_se: everything is crammed in an unsigned int bitfield. Let me see if I can find some relevant mails.So I think a relevant mail is:
Quoted 8 lines
Quoted 6 lines
https://lore.kernel.org/lkml/[email protected]/
Other than that, the uclamp_se.value field was 'int' in v1 and has been 'unsigned int' for all following versions. uclamp_bucket.value is a bitfield of an 'unsigned long' just because we want more headroom for the tasks count, AFAICT.
Thanks for the pointer and deep diving in the email threads
It was all in an effort to minimize the number of cachelines touched to maintain this data.
Quoted 16 lines · Valentin Schneider
Some uclamp helpers had their return type changed from 'unsigned int' to 'enum
uclamp_id' by commit
0413d7f33e60("sched/uclamp: Always use 'enumuclamp_id' forclamp_idvalues")but it happens that some do return a value in the [0,
SCHED_CAPACITY_SCALE] range, which should really be unsigned int. The affected helpers areuclamp_none(),uclamp_rq_max_value()anduclamp_eff_value(). Fix those up.Note that this doesn't lead to any obj diff using a relatively recent aarch64 compiler (8.3-2019.03). The current code of e.g.
uclamp_eff_value()properly returns an 11 bit value (bits_per(1024)) and doesn't seem to do anything funny. I'm still marking this as fixing the above commit to be on the safe side.
Quoted 3 lines
Fixes 0413d7f33e60 ("sched/uclamp: Always use 'enum uclamp_id' for clamp_id values")Reviewed-by Qais Yousef <[email protected]>Signed-off-by Valentin Schneider <[email protected]>
Quoted 57 lines
---
v2 changes:
o Also fixuclamp_none()(Vincent)
o Collect reviewed-by
o Slightly reword changelog--- kernel/sched/core.c | 6 +++--- kernel/sched/sched.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)kernel/sched/core.c +3
-3@@ -810,7 +810,7 @@ static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value)return UCLAMP_BUCKET_DELTA *uclamp_bucket_id (clamp_value); } -static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id) {if (clamp_id ==UCLAMP_MIN )return 0 ;@@ -853,7 +853,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id, }static inline -enum uclamp_id uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id, +unsigned int uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id,unsigned int clamp_value) {struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket;@@ -918,7 +918,7 @@ uclamp_eff_get(struct task_struct *p, enum uclamp_id clamp_id)return uc_req; } -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) {struct uclamp_se uc_eff;kernel/sched/sched.h +1
-2@@ -2300,7 +2300,7 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}#endif /* CONFIG_CPU_FREQ */ #ifdef CONFIG_UCLAMP_TASK -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); static __always_inline unsigned int uclamp_util_with(struct rq *rq, unsigned int util, --2.22.0
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 7763baace1b738d65efa46d68326c9406311c6bf Gitweb: https://git.kernel.org/tip/7763baace1b738d65efa46d68326c9406311c6bf Author: Valentin Schneider <[email protected]> AuthorDate: Fri, 15 Nov 2019 10:39:08 Committer: Ingo Molnar <[email protected]> CommitterDate: Sun, 17 Nov 2019 10:46:05 +01:00
sched/uclamp: Fix overzealous type replacement
Some uclamp helpers had their return type changed from 'unsigned int' to 'enum uclamp_id' by commit
0413d7f33e60 ("sched/uclamp: Always use 'enum uclamp_id' for clamp_id values")
but it happens that some do return a value in the [0, SCHED_CAPACITY_SCALE] range, which should really be unsigned int. The affected helpers are uclamp_none(), uclamp_rq_max_value() and uclamp_eff_value(). Fix those up.
Note that this doesn't lead to any obj diff using a relatively recent aarch64 compiler (8.3-2019.03). The current code of e.g. uclamp_eff_value() properly returns an 11 bit value (bits_per(1024)) and doesn't seem to do anything funny. I'm still marking this as fixing the above commit to be on the safe side.
--- kernel/sched/core.c | 6 +++--- kernel/sched/sched.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/sched/core.c +3 -3
@@ -810,7 +810,7 @@ static inline unsigned int uclamp_bucket_base_value(unsigned int clamp_value)return UCLAMP_BUCKET_DELTA *uclamp_bucket_id (clamp_value); } -static inline enum uclamp_id uclamp_none (enum uclamp_id clamp_id) +static inline unsigned int uclamp_none (enum uclamp_id clamp_id) {if (clamp_id ==UCLAMP_MIN )return 0 ;
@@ -853,7 +853,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id, }static inline -enum uclamp_id uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id, +unsigned int uclamp_rq_max_value (struct rq *rq,enum uclamp_id clamp_id,unsigned int clamp_value) {struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket;
@@ -918,7 +918,7 @@ uclamp_eff_get(struct task_struct *p, enum uclamp_id clamp_id)return uc_req; } -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id) {struct uclamp_se uc_eff;
kernel/sched/sched.h +1 -1
@@ -2300,7 +2300,7 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}#endif /* CONFIG_CPU_FREQ */ #ifdef CONFIG_UCLAMP_TASK -enum uclamp_id uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); +unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id); static __always_inline unsigned int uclamp_util_with(struct rq *rq, unsigned int util,