root/Documentation/scheduler/sched-pelt.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. calc_runnable_avg_yN_inv
  2. calc_runnable_avg_yN_sum
  3. calc_converged_max
  4. calc_accumulated_sum_32
  5. main

   1 /*
   2  * The following program is used to generate the constants for
   3  * computing sched averages.
   4  *
   5  * ==============================================================
   6  *              C program (compile with -lm)
   7  * ==============================================================
   8  */
   9 
  10 #include <math.h>
  11 #include <stdio.h>
  12 
  13 #define HALFLIFE 32
  14 #define SHIFT 32
  15 
  16 double y;
  17 
  18 void calc_runnable_avg_yN_inv(void)
  19 {
  20         int i;
  21         unsigned int x;
  22 
  23         /* To silence -Wunused-but-set-variable warnings. */
  24         printf("static const u32 runnable_avg_yN_inv[] __maybe_unused = {");
  25         for (i = 0; i < HALFLIFE; i++) {
  26                 x = ((1UL<<32)-1)*pow(y, i);
  27 
  28                 if (i % 6 == 0) printf("\n\t");
  29                 printf("0x%8x, ", x);
  30         }
  31         printf("\n};\n\n");
  32 }
  33 
  34 int sum = 1024;
  35 
  36 void calc_runnable_avg_yN_sum(void)
  37 {
  38         int i;
  39 
  40         printf("static const u32 runnable_avg_yN_sum[] = {\n\t    0,");
  41         for (i = 1; i <= HALFLIFE; i++) {
  42                 if (i == 1)
  43                         sum *= y;
  44                 else
  45                         sum = sum*y + 1024*y;
  46 
  47                 if (i % 11 == 0)
  48                         printf("\n\t");
  49 
  50                 printf("%5d,", sum);
  51         }
  52         printf("\n};\n\n");
  53 }
  54 
  55 int n = -1;
  56 /* first period */
  57 long max = 1024;
  58 
  59 void calc_converged_max(void)
  60 {
  61         long last = 0, y_inv = ((1UL<<32)-1)*y;
  62 
  63         for (; ; n++) {
  64                 if (n > -1)
  65                         max = ((max*y_inv)>>SHIFT) + 1024;
  66                         /*
  67                          * This is the same as:
  68                          * max = max*y + 1024;
  69                          */
  70 
  71                 if (last == max)
  72                         break;
  73 
  74                 last = max;
  75         }
  76         n--;
  77         printf("#define LOAD_AVG_PERIOD %d\n", HALFLIFE);
  78         printf("#define LOAD_AVG_MAX %ld\n", max);
  79 //      printf("#define LOAD_AVG_MAX_N %d\n\n", n);
  80 }
  81 
  82 void calc_accumulated_sum_32(void)
  83 {
  84         int i, x = sum;
  85 
  86         printf("static const u32 __accumulated_sum_N32[] = {\n\t     0,");
  87         for (i = 1; i <= n/HALFLIFE+1; i++) {
  88                 if (i > 1)
  89                         x = x/2 + sum;
  90 
  91                 if (i % 6 == 0)
  92                         printf("\n\t");
  93 
  94                 printf("%6d,", x);
  95         }
  96         printf("\n};\n\n");
  97 }
  98 
  99 void main(void)
 100 {
 101         printf("/* Generated by Documentation/scheduler/sched-pelt; do not modify. */\n\n");
 102 
 103         y = pow(0.5, 1/(double)HALFLIFE);
 104 
 105         calc_runnable_avg_yN_inv();
 106 //      calc_runnable_avg_yN_sum();
 107         calc_converged_max();
 108 //      calc_accumulated_sum_32();
 109 }

/* [<][>][^][v][top][bottom][index][help] */