Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1250669 > unrolled thread

Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active tickless case

Started byPeter Zijlstra <peterz@infradead.org>
First post2015-10-19 15:20 +0200
Last post2015-10-22 13:10 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active  tickless case Peter Zijlstra <peterz@infradead.org> - 2015-10-19 15:20 +0200
    Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active  tickless case Byungchul Park <byungchul.park@lge.com> - 2015-10-20 03:00 +0200
      Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active  tickless case Peter Zijlstra <peterz@infradead.org> - 2015-10-20 11:50 +0200
        Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active  tickless case Byungchul Park <byungchul.park@lge.com> - 2015-10-22 12:30 +0200
          Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active  tickless case Peter Zijlstra <peterz@infradead.org> - 2015-10-22 13:10 +0200

#1250669 — Re: [PATCH v4 1/2] sched: make __update_cpu_load() handle active tickless case

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-19 15:20 +0200
SubjectRe: [PATCH v4 1/2] sched: make __update_cpu_load() handle active tickless case
Message-ID<qliw2-5t5-11@gated-at.bofh.it>
On Wed, Oct 14, 2015 at 06:47:35PM +0900, byungchul.park@lge.com wrote:
> 
> cpu_load(n) = (1 - 1/s) * cpu_load(n-1) + (1/s) * L

So I've been taught to use subscripts, not arguments, for progressive
values of the same thing. However I can see the recursive nature of you
definition so I can well imagine people having different views on it.

>             , where n = the current tick - 1, s = scale
> 
>             = A * cpu_load(n-1) + B
>             , where A = 1 - 1/s, B = (1/s) * L
> 
>             = A * (A * cpu_load(n-2) + B) + B
> 
>             = A * (A * (A * cpu_load(n-3) + B) + B) + B
> 
>             = A^3 * cpu_load(n-3) + A^2 * B + A * B + B
> 
>             = A^i * cpu_load(n-i) + (A^(i-1) + A^(i-2) + ... + 1) * B
>             , where i = pending_updates - 1

You missed an opportunity here, if you take i==n you avoid the need for
i entirely.

>             = A^i * cpu_load(n-i) + B * (A^i - 1) / (A - 1)
>             , by geometric series formula for sum

That's wrong; the limited geometric series expands to:

  a * (1 - r^n) / (1 - r)

Which would give: A^i * cpu_load(n-i) + B * (1 - A^i) / (1 - A)

>             = (1 - 1/s)^i * (cpu_load(n-i) - L) + L
>             , by extending A and B

This appears to be correct however, I think your above mistake must have
been one copying.

I've rewritten the things a little; does this look good to you?

---
Subject: sched: make __update_cpu_load() handle active tickless case
From: Byungchul Park <byungchul.park@lge.com>
Date: Wed, 14 Oct 2015 18:47:35 +0900

XXX write new changelog...

Cc: mingo@kernel.org
Signed-off-by: Byungchul Park <byungchul.park@lge.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1444816056-11886-2-git-send-email-byungchul.park@lge.com
---
 kernel/sched/fair.c |   49 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 8 deletions(-)

--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4298,14 +4298,46 @@ decay_load_missed(unsigned long load, un
 	return load;
 }
 
-/*
+/**
+ * __update_cpu_load - update the rq->cpu_load[] statistics
+ * @this_rq: The rq to update statistics for
+ * @this_load: The current load
+ * @pending_updates: The number of missed updates
+ * @active: !0 for NOHZ_FULL
+ *
  * Update rq->cpu_load[] statistics. This function is usually called every
- * scheduler tick (TICK_NSEC). With tickless idle this will not be called
- * every tick. We fix it up based on jiffies.
+ * scheduler tick (TICK_NSEC).
+ *
+ * This function computes a decaying average:
+ *
+ *   load[i]' = (1 - 1/2^i) * load[i] + (1/2^i) * load
+ *
+ * Because of NOHZ it might not get called on every tick which gives need for
+ * the @pending_updates argument.
+ *
+ *   load[i]_n = (1 - 1/2^i) * load[i]_n-1 + (1/2^i) * load_n-1
+ *             = A * load[i]_n-1 + B ; A := (1 - 1/2^i), B := (1/2^i) * load
+ *             = A * (A * load[i]_n-2 + B) + B
+ *             = A * (A * (A * load[i]_n-3 + B) + B) + B
+ *             = A^3 * load[i]_n-3 + (A^2 + A + 1) * B
+ *             = A^n * load[i]_0 + (A^(n-1) + A^(n-2) + ... + 1) * B
+ *             = A^n * load[i]_0 + ((1 - A^n) / (1 - A)) * B
+ *             = (1 - 1/2^i)^n * (load[i]_0 - load) + load
+ *
+ * In the above we've assumed load_n := load, which is true for NOHZ_FULL as
+ * any change in load would have resulted in the tick being turned back on.
+ *
+ * For regular NOHZ, this reduces to:
+ *
+ *   load[i]_n = (1 - 1/2^i)^n * load[i]_0
+ *
+ * see decay_load_misses(). For NOHZ_FULL we get to subtract and add the extra
+ * term. See the @active paramter.
  */
 static void __update_cpu_load(struct rq *this_rq, unsigned long this_load,
-			      unsigned long pending_updates)
+			      unsigned long pending_updates, int active)
 {
+	unsigned long tickless_load = active ? this_rq->cpu_load[0] : 0;
 	int i, scale;
 
 	this_rq->nr_load_updates++;
@@ -4317,8 +4349,9 @@ static void __update_cpu_load(struct rq
 
 		/* scale is effectively 1 << i now, and >> i divides by scale */
 
-		old_load = this_rq->cpu_load[i];
+		old_load = this_rq->cpu_load[i] - tickless_load;
 		old_load = decay_load_missed(old_load, pending_updates - 1, i);
+		old_load += tickless_load;
 		new_load = this_load;
 		/*
 		 * Round up the averaging division if load is increasing. This
@@ -4373,7 +4406,7 @@ static void update_idle_cpu_load(struct
 	pending_updates = curr_jiffies - this_rq->last_load_update_tick;
 	this_rq->last_load_update_tick = curr_jiffies;
 
-	__update_cpu_load(this_rq, load, pending_updates);
+	__update_cpu_load(this_rq, load, pending_updates, 0);
 }
 
 /*
@@ -4396,7 +4429,7 @@ void update_cpu_load_nohz(void)
 		 * We were idle, this means load 0, the current load might be
 		 * !0 due to remote wakeups and the sort.
 		 */
-		__update_cpu_load(this_rq, 0, pending_updates);
+		__update_cpu_load(this_rq, 0, pending_updates, 0);
 	}
 	raw_spin_unlock(&this_rq->lock);
 }
@@ -4412,7 +4445,7 @@ void update_cpu_load_active(struct rq *t
 	 * See the mess around update_idle_cpu_load() / update_cpu_load_nohz().
 	 */
 	this_rq->last_load_update_tick = jiffies;
-	__update_cpu_load(this_rq, load, 1);
+	__update_cpu_load(this_rq, load, 1, 1);
 }
 
 /*
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1251220

FromByungchul Park <byungchul.park@lge.com>
Date2015-10-20 03:00 +0200
Message-ID<qltrt-4x1-59@gated-at.bofh.it>
In reply to#1250669
On Mon, Oct 19, 2015 at 03:16:18PM +0200, Peter Zijlstra wrote:
> On Wed, Oct 14, 2015 at 06:47:35PM +0900, byungchul.park@lge.com wrote:
> > 
> > cpu_load(n) = (1 - 1/s) * cpu_load(n-1) + (1/s) * L
> 
> So I've been taught to use subscripts, not arguments, for progressive
> values of the same thing. However I can see the recursive nature of you
> definition so I can well imagine people having different views on it.
> 
> >             , where n = the current tick - 1, s = scale
> > 
> >             = A * cpu_load(n-1) + B
> >             , where A = 1 - 1/s, B = (1/s) * L
> > 
> >             = A * (A * cpu_load(n-2) + B) + B
> > 
> >             = A * (A * (A * cpu_load(n-3) + B) + B) + B
> > 
> >             = A^3 * cpu_load(n-3) + A^2 * B + A * B + B
> > 
> >             = A^i * cpu_load(n-i) + (A^(i-1) + A^(i-2) + ... + 1) * B
> >             , where i = pending_updates - 1
> 
> You missed an opportunity here, if you take i==n you avoid the need for
> i entirely.

i don't think so. as i said, _n_ is the current tick -1 and _i_ is
pending_updates - 1. we cannot take i == n, but should keep (n-i).

> 
> >             = A^i * cpu_load(n-i) + B * (A^i - 1) / (A - 1)
> >             , by geometric series formula for sum
> 
> That's wrong; the limited geometric series expands to:

NO, that's not wrong. it doesn't matter at all.

a * (1 - r^n) / (1 - r)
= a * (-1)(r^n - 1) / (-1)(r - 1)
= a * (r^n - 1) / (r - 1)

i mean these two are exactly same.

> 
>   a * (1 - r^n) / (1 - r)

but i think this is also good one.

> 
> Which would give: A^i * cpu_load(n-i) + B * (1 - A^i) / (1 - A)
> 
> >             = (1 - 1/s)^i * (cpu_load(n-i) - L) + L
> >             , by extending A and B
> 
> This appears to be correct however, I think your above mistake must have
> been one copying.
> 
> I've rewritten the things a little; does this look good to you?

however, your expressions and descriptions below look better than me,
except some logical errors. could you keep my logical flow unchagned?

thanks anyway,
byungchul

> 
> ---
> Subject: sched: make __update_cpu_load() handle active tickless case
> From: Byungchul Park <byungchul.park@lge.com>
> Date: Wed, 14 Oct 2015 18:47:35 +0900
> 
> XXX write new changelog...
> 
> Cc: mingo@kernel.org
> Signed-off-by: Byungchul Park <byungchul.park@lge.com>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: http://lkml.kernel.org/r/1444816056-11886-2-git-send-email-byungchul.park@lge.com
> ---
>  kernel/sched/fair.c |   49 +++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 41 insertions(+), 8 deletions(-)
> 
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -4298,14 +4298,46 @@ decay_load_missed(unsigned long load, un
>  	return load;
>  }
>  
> -/*
> +/**
> + * __update_cpu_load - update the rq->cpu_load[] statistics
> + * @this_rq: The rq to update statistics for
> + * @this_load: The current load
> + * @pending_updates: The number of missed updates
> + * @active: !0 for NOHZ_FULL
> + *
>   * Update rq->cpu_load[] statistics. This function is usually called every
> - * scheduler tick (TICK_NSEC). With tickless idle this will not be called
> - * every tick. We fix it up based on jiffies.
> + * scheduler tick (TICK_NSEC).
> + *
> + * This function computes a decaying average:
> + *
> + *   load[i]' = (1 - 1/2^i) * load[i] + (1/2^i) * load
> + *
> + * Because of NOHZ it might not get called on every tick which gives need for
> + * the @pending_updates argument.
> + *
> + *   load[i]_n = (1 - 1/2^i) * load[i]_n-1 + (1/2^i) * load_n-1
> + *             = A * load[i]_n-1 + B ; A := (1 - 1/2^i), B := (1/2^i) * load
> + *             = A * (A * load[i]_n-2 + B) + B
> + *             = A * (A * (A * load[i]_n-3 + B) + B) + B
> + *             = A^3 * load[i]_n-3 + (A^2 + A + 1) * B
> + *             = A^n * load[i]_0 + (A^(n-1) + A^(n-2) + ... + 1) * B
> + *             = A^n * load[i]_0 + ((1 - A^n) / (1 - A)) * B
> + *             = (1 - 1/2^i)^n * (load[i]_0 - load) + load
> + *
> + * In the above we've assumed load_n := load, which is true for NOHZ_FULL as
> + * any change in load would have resulted in the tick being turned back on.
> + *
> + * For regular NOHZ, this reduces to:
> + *
> + *   load[i]_n = (1 - 1/2^i)^n * load[i]_0
> + *
> + * see decay_load_misses(). For NOHZ_FULL we get to subtract and add the extra
> + * term. See the @active paramter.
>   */
>  static void __update_cpu_load(struct rq *this_rq, unsigned long this_load,
> -			      unsigned long pending_updates)
> +			      unsigned long pending_updates, int active)
>  {
> +	unsigned long tickless_load = active ? this_rq->cpu_load[0] : 0;
>  	int i, scale;
>  
>  	this_rq->nr_load_updates++;
> @@ -4317,8 +4349,9 @@ static void __update_cpu_load(struct rq
>  
>  		/* scale is effectively 1 << i now, and >> i divides by scale */
>  
> -		old_load = this_rq->cpu_load[i];
> +		old_load = this_rq->cpu_load[i] - tickless_load;
>  		old_load = decay_load_missed(old_load, pending_updates - 1, i);
> +		old_load += tickless_load;
>  		new_load = this_load;
>  		/*
>  		 * Round up the averaging division if load is increasing. This
> @@ -4373,7 +4406,7 @@ static void update_idle_cpu_load(struct
>  	pending_updates = curr_jiffies - this_rq->last_load_update_tick;
>  	this_rq->last_load_update_tick = curr_jiffies;
>  
> -	__update_cpu_load(this_rq, load, pending_updates);
> +	__update_cpu_load(this_rq, load, pending_updates, 0);
>  }
>  
>  /*
> @@ -4396,7 +4429,7 @@ void update_cpu_load_nohz(void)
>  		 * We were idle, this means load 0, the current load might be
>  		 * !0 due to remote wakeups and the sort.
>  		 */
> -		__update_cpu_load(this_rq, 0, pending_updates);
> +		__update_cpu_load(this_rq, 0, pending_updates, 0);
>  	}
>  	raw_spin_unlock(&this_rq->lock);
>  }
> @@ -4412,7 +4445,7 @@ void update_cpu_load_active(struct rq *t
>  	 * See the mess around update_idle_cpu_load() / update_cpu_load_nohz().
>  	 */
>  	this_rq->last_load_update_tick = jiffies;
> -	__update_cpu_load(this_rq, load, 1);
> +	__update_cpu_load(this_rq, load, 1, 1);
>  }
>  
>  /*
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1251536

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-20 11:50 +0200
Message-ID<qlBIm-8jI-11@gated-at.bofh.it>
In reply to#1251220
On Tue, Oct 20, 2015 at 09:49:32AM +0900, Byungchul Park wrote:
> > >             = A^i * cpu_load(n-i) + (A^(i-1) + A^(i-2) + ... + 1) * B
> > >             , where i = pending_updates - 1
> > 
> > You missed an opportunity here, if you take i==n you avoid the need for
> > i entirely.
> 
> i don't think so. as i said, _n_ is the current tick -1 and _i_ is
> pending_updates - 1. we cannot take i == n, but should keep (n-i).

Just think relative; it doesn't matter when in time we do this.
So 0 to n is identical to any other interval.

> > >             = A^i * cpu_load(n-i) + B * (A^i - 1) / (A - 1)
> > >             , by geometric series formula for sum
> > 
> > That's wrong; the limited geometric series expands to:
> 
> NO, that's not wrong. it doesn't matter at all.
> 
> a * (1 - r^n) / (1 - r)
> = a * (-1)(r^n - 1) / (-1)(r - 1)
> = a * (r^n - 1) / (r - 1)
> 
> i mean these two are exactly same.

Ah indeed! Sorry for that. I clearly didn't think beyond the series
expansion I found.

> > I've rewritten the things a little; does this look good to you?
> 
> however, your expressions and descriptions below look better than me,
> except some logical errors. could you keep my logical flow unchagned?

> > + *   load[i]_n = (1 - 1/2^i) * load[i]_n-1 + (1/2^i) * load_n-1
> > + *             = A * load[i]_n-1 + B ; A := (1 - 1/2^i), B := (1/2^i) * load
> > + *             = A * (A * load[i]_n-2 + B) + B
> > + *             = A * (A * (A * load[i]_n-3 + B) + B) + B
> > + *             = A^3 * load[i]_n-3 + (A^2 + A + 1) * B
> > + *             = A^n * load[i]_0 + (A^(n-1) + A^(n-2) + ... + 1) * B
> > + *             = A^n * load[i]_0 + ((1 - A^n) / (1 - A)) * B
> > + *             = (1 - 1/2^i)^n * (load[i]_0 - load) + load

That is the same logic, right?

Please be more specific as to what you'd like restored.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1253701

FromByungchul Park <byungchul.park@lge.com>
Date2015-10-22 12:30 +0200
Message-ID<qmlib-7Vb-27@gated-at.bofh.it>
In reply to#1251536
On Tue, Oct 20, 2015 at 11:48:48AM +0200, Peter Zijlstra wrote:
> On Tue, Oct 20, 2015 at 09:49:32AM +0900, Byungchul Park wrote:
> > > >             = A^i * cpu_load(n-i) + (A^(i-1) + A^(i-2) + ... + 1) * B
> > > >             , where i = pending_updates - 1
> > > 
> > > You missed an opportunity here, if you take i==n you avoid the need for
> > > i entirely.
> > 
> > i don't think so. as i said, _n_ is the current tick -1 and _i_ is
> > pending_updates - 1. we cannot take i == n, but should keep (n-i).
> 
> Just think relative; it doesn't matter when in time we do this.
> So 0 to n is identical to any other interval.

You are right. I'm always tired these days. I was confused.
Sorry for that.

> 
> > > >             = A^i * cpu_load(n-i) + B * (A^i - 1) / (A - 1)
> > > >             , by geometric series formula for sum
> > > 
> > > That's wrong; the limited geometric series expands to:
> > 
> > NO, that's not wrong. it doesn't matter at all.
> > 
> > a * (1 - r^n) / (1 - r)
> > = a * (-1)(r^n - 1) / (-1)(r - 1)
> > = a * (r^n - 1) / (r - 1)
> > 
> > i mean these two are exactly same.
> 
> Ah indeed! Sorry for that. I clearly didn't think beyond the series
> expansion I found.
> 
> > > I've rewritten the things a little; does this look good to you?
> > 
> > however, your expressions and descriptions below look better than me,
> > except some logical errors. could you keep my logical flow unchagned?
> 
> > > + *   load[i]_n = (1 - 1/2^i) * load[i]_n-1 + (1/2^i) * load_n-1
> > > + *             = A * load[i]_n-1 + B ; A := (1 - 1/2^i), B := (1/2^i) * load
> > > + *             = A * (A * load[i]_n-2 + B) + B
> > > + *             = A * (A * (A * load[i]_n-3 + B) + B) + B
> > > + *             = A^3 * load[i]_n-3 + (A^2 + A + 1) * B
> > > + *             = A^n * load[i]_0 + (A^(n-1) + A^(n-2) + ... + 1) * B
> > > + *             = A^n * load[i]_0 + ((1 - A^n) / (1 - A)) * B
> > > + *             = (1 - 1/2^i)^n * (load[i]_0 - load) + load
> 
> That is the same logic, right?

Yes, absolutely same logic.

Thanks a lot,
byungchul

> 
> Please be more specific as to what you'd like restored.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1253712

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-22 13:10 +0200
Message-ID<qmlUR-yG-3@gated-at.bofh.it>
In reply to#1253701
On Thu, Oct 22, 2015 at 07:28:52PM +0900, Byungchul Park wrote:

> You are right. I'm always tired these days. I was confused.
> Sorry for that.

No problem, I know the feeling, my second kid is growing teeth :-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web