public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Paul Turner <pjt@google.com>
Cc: Benjamin Segall <bsegall@google.com>,
	linux-kernel@vger.kernel.org, Venki Pallipadi <venki@google.com>,
	Srivatsa Vaddagiri <vatsa@in.ibm.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>,
	Mike Galbraith <efault@gmx.de>,
	Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>,
	Ingo Molnar <mingo@elte.hu>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Morten Rasmussen <Morten.Rasmussen@arm.com>,
	Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Subject: Re: [PATCH 14/16] sched: make __update_entity_runnable_avg() fast
Date: Thu, 12 Jul 2012 16:30:50 +0200	[thread overview]
Message-ID: <1342103450.28010.10.camel@twins> (raw)
In-Reply-To: <CAPM31R+RYvLLN0mK8VBOe7QTxCxEEuLEZ1OokeLAB=D0cxqJxQ@mail.gmail.com>

On Wed, 2012-07-11 at 17:15 -0700, Paul Turner wrote:
> convergence
> 345> 47765

Ah, 345 is much saner indeed!

> And for posterity, a simple generator so that I don't lose it again:
> #include <math.h>
> #include <stdio.h>
> 
> #define SRR(x, y) (((x) + (1UL << ((y) - 1))) >> (y))
> #define N 32
> #define WMULT_SHIFT 32
> 
> const long WMULT_CONST = ((1UL << N) - 1);
> const double y = .97857206208770013451;

I used pow(0.5, 1.0/N), no point in loosing precision and mis-typing a
digit or somesuch nonsense ;-)

> 
> long approx_decay(int c) {
>         return (c * 4008) >> 12;
> }
> 
> long mult_inv_array[N];
> void calc_mult_inv() {
>         int i;
>         double yn = 0;
> 
>         printf("inverses\n");
>         for (i = 0; i < N; i++) {
>                 yn = (double)WMULT_CONST * pow(y, i);
>                 mult_inv_array[i] = yn;
>                 printf("%d: %8lx\n", i, mult_inv_array[i]);
>         }
> 
>         printf("\n");
> }
> 
> long mult_inv(long c, int n) {
>         return SRR(c * runnable_avg_yN_inv[n], WMULT_SHIFT);

This works much better when you do:

  s/runnable_avg_yN_inv/mult_inv_array/

> }
> 
> void calc_yn_sum(int n)
> {
>         int i;
>         double sum = 0, sum_fl = 0, diff = 0;
>         long approx = 0, approx_fm = 0, approx_fm2 = 0;
> 
>         printf("sum y^n\n");
>         printf("   %8s  %8s  %8s  %8s %8s\n", "exact", "floor", "shift",
>                "fastmul1", "fastmul2");
>         for (i = 1; i < n; i++) {
>                 sum = (y * sum + y * 1024);
>                 sum_fl = floor(y * sum_fl+ y * 1024);
>                 approx = approx_decay(approx) + approx_decay(1024);
>                 approx_fm = mult_inv(approx_fm, 1) + mult_inv(1024, 1);
>                 approx_fm2 += mult_inv(1024, i);
> 
>                 /*diff = sum;*/
>                 printf("%2d: %8.0f  %8.0f  %8ld  %8ld  %8ld\n", i, sum,
>                                 sum_fl - diff,
>                                 approx - (long)diff,
>                                 approx_fm - (long)diff,
>                                 approx_fm2 - (long)diff);
> 
>         }
>         printf("\n");
> }
> 
> void calc_conv(long n) {
>         long old_n;
>         int i = -1;
> 
>         printf("convergence\n");
>         do {
>                 old_n = n;
>                 n = mult_inv(n, 1) + 1024;
>                 i++;
>         } while (n != old_n);
>         printf("%d> %ld\n", i - 1, n);
>         printf("\n");
> }
> 
> void main() {
>         calc_mult_inv();
>         calc_conv(1024);
>         calc_yn_sum(N);
> }
> 
> 

  reply	other threads:[~2012-07-12 14:31 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-28  2:24 [PATCH 00/16] Series short description Paul Turner
2012-06-28  2:24 ` [PATCH 01/16] sched: track the runnable average on a per-task entitiy basis Paul Turner
2012-06-28  6:06   ` Namhyung Kim
2012-07-12  0:14     ` Paul Turner
2012-07-04 15:32   ` Peter Zijlstra
2012-07-12  0:12     ` Paul Turner
2012-06-28  2:24 ` [PATCH 09/16] sched: normalize tg load contributions against runnable time Paul Turner
2012-06-29  7:26   ` Namhyung Kim
2012-07-04 19:48   ` Peter Zijlstra
2012-07-06 11:52     ` Peter Zijlstra
2012-07-12  1:08       ` Andre Noll
2012-07-12  0:02     ` Paul Turner
2012-07-06 12:23   ` Peter Zijlstra
2012-06-28  2:24 ` [PATCH 02/16] sched: maintain per-rq runnable averages Paul Turner
2012-06-28  2:24 ` [PATCH 04/16] sched: maintain the load contribution of blocked entities Paul Turner
2012-06-29  1:27   ` Namhyung Kim
2012-06-28  2:24 ` [PATCH 08/16] sched: compute load contribution by a group entity Paul Turner
2012-06-28  2:24 ` [PATCH 05/16] sched: add an rq migration call-back to sched_class Paul Turner
2012-06-29  1:32   ` Namhyung Kim
2012-06-28  2:24 ` [PATCH 03/16] sched: aggregate load contributed by task entities on parenting cfs_rq Paul Turner
2012-06-28  6:33   ` Namhyung Kim
2012-07-04 15:28   ` Peter Zijlstra
2012-07-06 14:53     ` Peter Zijlstra
2012-07-09  9:15       ` Ingo Molnar
2012-06-28  2:24 ` [PATCH 07/16] sched: aggregate total task_group load Paul Turner
2012-06-28  2:24 ` [PATCH 06/16] sched: account for blocked load waking back up Paul Turner
2012-06-28  2:24 ` [PATCH 13/16] sched: update_cfs_shares at period edge Paul Turner
2012-06-28  2:24 ` [PATCH 14/16] sched: make __update_entity_runnable_avg() fast Paul Turner
2012-07-04 15:41   ` Peter Zijlstra
2012-07-04 17:20     ` Peter Zijlstra
2012-07-09 20:18       ` Benjamin Segall
2012-07-10 10:51         ` Peter Zijlstra
2012-07-12  0:15           ` Paul Turner
2012-07-12 14:30             ` Peter Zijlstra [this message]
2012-07-04 16:51   ` Peter Zijlstra
2012-06-28  2:24 ` [PATCH 16/16] sched: introduce temporary FAIR_GROUP_SCHED dependency for load-tracking Paul Turner
2012-06-28  2:24 ` [PATCH 11/16] sched: replace update_shares weight distribution with per-entity computation Paul Turner
2012-06-28  2:24 ` [PATCH 15/16] sched: implement usage tracking Paul Turner
2012-06-28  2:24 ` [PATCH 12/16] sched: refactor update_shares_cpu() -> update_blocked_avgs() Paul Turner
2012-06-29  7:28   ` Namhyung Kim
2012-07-12  0:03     ` Paul Turner
2012-07-05 11:58   ` Peter Zijlstra
2012-07-12  0:11     ` Paul Turner
2012-07-12 14:40       ` Peter Zijlstra
2012-06-28  2:24 ` [PATCH 10/16] sched: maintain runnable averages across throttled periods Paul Turner
  -- strict thread matches above, loose matches on Subject: below --
2012-08-23 14:14 [patch 00/16] sched: per-entity load-tracking pjt
2012-08-23 14:14 ` [patch 14/16] sched: make __update_entity_runnable_avg() fast pjt
2012-08-24  8:28   ` Namhyung Kim
2012-08-28 22:18     ` Paul Turner

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=1342103450.28010.10.camel@twins \
    --to=peterz@infradead.org \
    --cc=Morten.Rasmussen@arm.com \
    --cc=bsegall@google.com \
    --cc=efault@gmx.de \
    --cc=kamalesh@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nikunj@linux.vnet.ibm.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pjt@google.com \
    --cc=svaidy@linux.vnet.ibm.com \
    --cc=vatsa@in.ibm.com \
    --cc=venki@google.com \
    --cc=vincent.guittot@linaro.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