public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/fair: cleanup, clamp values with macros clamp() and max().
@ 2014-05-16  3:12 Dongsheng Yang
  2014-05-16 10:20 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Dongsheng Yang @ 2014-05-16  3:12 UTC (permalink / raw)
  To: mingo, peterz; +Cc: linux-kernel, Dongsheng Yang

Rather than use "if" to check and clamp values to allowed minmum or maxmum,
this patch use macros clamp() and max() to clean it up.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
---
 kernel/sched/fair.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 7570dd9..939a7ab 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2041,10 +2041,7 @@ static long calc_cfs_shares(struct cfs_rq *cfs_rq, struct task_group *tg)
 	if (tg_weight)
 		shares /= tg_weight;
 
-	if (shares < MIN_SHARES)
-		shares = MIN_SHARES;
-	if (shares > tg->shares)
-		shares = tg->shares;
+	shares = clamp(shares, MIN_SHARES, tg->shares);
 
 	return shares;
 }
@@ -4133,8 +4130,7 @@ static long effective_load(struct task_group *tg, int cpu, long wl, long wg)
 		 * those are clipped to [MIN_SHARES, ...) do so now. See
 		 * calc_cfs_shares().
 		 */
-		if (wl < MIN_SHARES)
-			wl = MIN_SHARES;
+		wl = max(wl, MIN_SHARES);
 
 		/*
 		 * wl = dw_i = S * (s'_i - s_i); see (3)
-- 
1.8.2.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sched/fair: cleanup, clamp values with macros clamp() and max().
  2014-05-16  3:12 [PATCH] sched/fair: cleanup, clamp values with macros clamp() and max() Dongsheng Yang
@ 2014-05-16 10:20 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2014-05-16 10:20 UTC (permalink / raw)
  To: Dongsheng Yang; +Cc: mingo, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1721 bytes --]

On Fri, May 16, 2014 at 12:12:34PM +0900, Dongsheng Yang wrote:
> Rather than use "if" to check and clamp values to allowed minmum or maxmum,
> this patch use macros clamp() and max() to clean it up.
> 
> Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
> ---
>  kernel/sched/fair.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 7570dd9..939a7ab 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -2041,10 +2041,7 @@ static long calc_cfs_shares(struct cfs_rq *cfs_rq, struct task_group *tg)
>  	if (tg_weight)
>  		shares /= tg_weight;
>  
> -	if (shares < MIN_SHARES)
> -		shares = MIN_SHARES;
> -	if (shares > tg->shares)
> -		shares = tg->shares;
> +	shares = clamp(shares, MIN_SHARES, tg->shares);
>  
>  	return shares;
>  }
> @@ -4133,8 +4130,7 @@ static long effective_load(struct task_group *tg, int cpu, long wl, long wg)
>  		 * those are clipped to [MIN_SHARES, ...) do so now. See
>  		 * calc_cfs_shares().
>  		 */
> -		if (wl < MIN_SHARES)
> -			wl = MIN_SHARES;
> +		wl = max(wl, MIN_SHARES);
>  
>  		/*
>  		 * wl = dw_i = S * (s'_i - s_i); see (3)

kernel/sched/fair.c: In function ‘calc_cfs_shares’:
kernel/sched/fair.c:2068:11: warning: comparison of distinct pointer types lacks a cast [enabled by default]
kernel/sched/fair.c:2068:11: warning: comparison of distinct pointer types lacks a cast [enabled by default]
kernel/sched/fair.c: In function ‘effective_load’:
kernel/sched/fair.c:4157:8: warning: comparison of distinct pointer types lacks a cast [enabled by default]
kernel/sched/fair.c: In function ‘migrate_task_rq_fair’:

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-16 10:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-16  3:12 [PATCH] sched/fair: cleanup, clamp values with macros clamp() and max() Dongsheng Yang
2014-05-16 10:20 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox