linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Carmody <pc+lkml@asdf.org>
To: alex.shi@intel.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [patch v7 05/21] sched: log the cpu utilization at rq
Date: Mon, 6 May 2013 15:03:18 +0300	[thread overview]
Message-ID: <20130506120318.GM21274@fatphil.org> (raw)
In-Reply-To: <1365040862-8390-6-git-send-email-alex.shi@intel.com>

[Apologies if threading mangled, all headers written by hand]

On 04/04/2013 07:30 AM, Alex Shi wrote:
> The cpu's utilization is to measure how busy is the cpu.
>         util = cpu_rq(cpu)->avg.runnable_avg_sum * SCHED_POEWR_SCALE
>                 / cpu_rq(cpu)->avg.runnable_avg_period;
> 
> Since the util is no more than 1, we scale its value with 1024, same as
> SCHED_POWER_SCALE and set the FULL_UTIL as 1024.
> 
> In later power aware scheduling, we are sensitive for how busy of the
> cpu. Since as to power consuming, it is tight related with cpu busy
> time.
> 
> BTW, rq->util can be used for any purposes if needed, not only power
> scheduling.
> 
> Signed-off-by: Alex Shi <alex.shi@intel.com>
> ---
>  include/linux/sched.h | 2 +-
>  kernel/sched/debug.c  | 1 +
>  kernel/sched/fair.c   | 5 +++++
>  kernel/sched/sched.h  | 4 ++++
>  4 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 5a4cf37..226a515 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -793,7 +793,7 @@ enum cpu_idle_type {
>  #define SCHED_LOAD_SCALE     (1L << SCHED_LOAD_SHIFT)
> 
>  /*
> - * Increase resolution of cpu_power calculations
> + * Increase resolution of cpu_power and rq->util calculations
>   */
>  #define SCHED_POWER_SHIFT    10
>  #define SCHED_POWER_SCALE    (1L << SCHED_POWER_SHIFT)
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 75024a6..f5db759 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -311,6 +311,7 @@ do {                                                                      \
> 
>       P(ttwu_count);
>       P(ttwu_local);
> +     P(util);
> 
>  #undef P
>  #undef P64
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 2e49c3f..7124244 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1495,8 +1495,13 @@ static void update_cfs_rq_blocked_load(struct cfs_rq *cfs_rq, int force_update)
> 
>  static inline void update_rq_runnable_avg(struct rq *rq, int runnable)
>  {
> +     u32 period;
>       __update_entity_runnable_avg(rq->clock_task, &rq->avg, runnable);
>       __update_tg_runnable_avg(&rq->avg, &rq->cfs);
> +
> +     period = rq->avg.runnable_avg_period ? rq->avg.runnable_avg_period : 1;
> +     rq->util = (u64)(rq->avg.runnable_avg_sum << SCHED_POWER_SHIFT)
> +                             / period;

Greetings, Alex.

That cast achieves nothing where it is. If the shift has overflowed,
then you've already lost information; and if it can't overflow, then
it's not needed at all. 

It's itsy-bitsy, but note that there exists a div_u64(u64 dividend,
u32 divisor) helper which may be implemented to be superior to just '/'.
(And also note that the assignment to ``period'' is a good candidate for
gcc's ``?:'' operator.)

If you pull the cast inside the brackets, then you may add my
Reviewed-by: Phil Carmody <pc+lkml@asdf.org>

Cheers,
Phil

>  }
> 
>  /* Add the load generated by se into cfs_rq's child load-average */
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 804ee41..8682110 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -351,6 +351,9 @@ extern struct root_domain def_root_domain;
> 
>  #endif /* CONFIG_SMP */
> 
> +/* full cpu utilization */
> +#define FULL_UTIL    SCHED_POWER_SCALE
> +
>  /*
>   * This is the main, per-CPU runqueue data structure.
>   *
> @@ -482,6 +485,7 @@ struct rq {
>  #endif
> 
>       struct sched_avg avg;
> +     unsigned int util;
>  };
> 
>  static inline int cpu_of(struct rq *rq)
> 
-- 
"In a world of magnets and miracles" 
-- Insane Clown Posse, Miracles, 2009. Much derided.
"Magnets, how do they work"
-- Pink Floyd, High Hopes, 1994. Lauded as lyrical geniuses.

  parent reply	other threads:[~2013-05-06 12:10 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-04  2:00 [patch v7 0/21] sched: power aware scheduling Alex Shi
2013-04-04  2:00 ` [patch v7 01/21] Revert "sched: Introduce temporary FAIR_GROUP_SCHED dependency for load-tracking" Alex Shi
2013-04-04  2:00 ` [patch v7 02/21] sched: set initial value of runnable avg for new forked task Alex Shi
2013-05-06  3:24   ` Preeti U Murthy
2013-04-04  2:00 ` [patch v7 03/21] sched: add sched balance policies in kernel Alex Shi
2013-04-04  2:00 ` [patch v7 04/21] sched: add sysfs interface for sched_balance_policy selection Alex Shi
2013-04-04  2:00 ` [patch v7 05/21] sched: log the cpu utilization at rq Alex Shi
2013-05-06  3:26   ` Preeti U Murthy
2013-05-06  5:22     ` Alex Shi
2013-05-06 12:03   ` Phil Carmody [this message]
2013-05-06 12:35     ` Alex Shi
2013-05-06 21:19   ` Paul Turner
2013-04-04  2:00 ` [patch v7 06/21] sched: add new sg/sd_lb_stats fields for incoming fork/exec/wake balancing Alex Shi
2013-04-04  2:00 ` [patch v7 07/21] sched: move sg/sd_lb_stats struct ahead Alex Shi
2013-04-04  2:00 ` [patch v7 08/21] sched: scale_rt_power rename and meaning change Alex Shi
2013-04-04  2:00 ` [patch v7 09/21] sched: get rq potential maximum utilization Alex Shi
2013-04-04  2:00 ` [patch v7 10/21] sched: add power aware scheduling in fork/exec/wake Alex Shi
2013-04-04  2:00 ` [patch v7 11/21] sched: add sched_burst_threshold_ns as wakeup burst indicator Alex Shi
2013-04-04  2:00 ` [patch v7 12/21] sched: using avg_idle to detect bursty wakeup Alex Shi
2013-04-04  2:00 ` [patch v7 13/21] sched: packing transitory tasks in wakeup power balancing Alex Shi
2013-04-04  2:00 ` [patch v7 14/21] sched: add power/performance balance allow flag Alex Shi
2013-04-04  2:00 ` [patch v7 15/21] sched: pull all tasks from source group Alex Shi
2013-04-04  5:59   ` Namhyung Kim
2013-04-06 11:49     ` Alex Shi
2013-04-04  2:00 ` [patch v7 16/21] sched: no balance for prefer_sibling in power scheduling Alex Shi
2013-05-06  3:26   ` Preeti U Murthy
2013-04-04  2:00 ` [patch v7 17/21] sched: add new members of sd_lb_stats Alex Shi
2013-04-04  2:00 ` [patch v7 18/21] sched: power aware load balance Alex Shi
2013-04-04  2:01 ` [patch v7 19/21] sched: lazy power balance Alex Shi
2013-04-04  2:01 ` [patch v7 20/21] sched: don't do power balance on share cpu power domain Alex Shi
2013-04-08  3:17   ` Preeti U Murthy
2013-04-08  3:25     ` Preeti U Murthy
2013-04-08  4:19       ` Alex Shi
2013-04-04  2:01 ` [patch v7 21/21] sched: make sure select_tas_rq_fair get a cpu Alex Shi
2013-04-11 21:02 ` [patch v7 0/21] sched: power aware scheduling Len Brown
2013-04-12  8:46   ` Alex Shi
2013-04-12 16:23     ` Borislav Petkov
2013-04-12 16:48       ` Mike Galbraith
2013-04-12 17:12         ` Borislav Petkov
2013-04-14  1:36           ` Alex Shi
2013-04-17 21:53         ` Len Brown
2013-04-18  1:51           ` Mike Galbraith
2013-04-26 15:11           ` Mike Galbraith
2013-04-30  5:16             ` Mike Galbraith
2013-04-30  8:30               ` Mike Galbraith
2013-04-30  8:41                 ` Ingo Molnar
2013-04-30  9:35                   ` Mike Galbraith
2013-04-30  9:49                     ` Mike Galbraith
2013-04-30  9:56                       ` Mike Galbraith
2013-05-17  8:06                         ` Preeti U Murthy
2013-05-20  1:01                           ` Alex Shi
2013-05-20  2:30                             ` Preeti U Murthy
2013-04-14  1:28       ` Alex Shi
2013-04-14  5:10         ` Alex Shi
2013-04-14 15:59         ` Borislav Petkov
2013-04-15  6:04           ` Alex Shi
2013-04-15  6:16             ` Alex Shi
2013-04-15  9:52               ` Borislav Petkov
2013-04-15 13:50                 ` Alex Shi
2013-04-15 23:12                   ` Borislav Petkov
2013-04-16  0:22                     ` Alex Shi
2013-04-16 10:24                       ` Borislav Petkov
2013-04-17  1:18                         ` Alex Shi
2013-04-17  7:38                           ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130506120318.GM21274@fatphil.org \
    --to=pc+lkml@asdf.org \
    --cc=alex.shi@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).