Merge tag 'linux-kselftest-kunit-fixes-5.11-rc3' of git://git.kernel.org/pub/scm...
[linux/fpc-iii.git] / Documentation / scheduler / sched-pelt.c
blob7238b355919c757cc7b8bc38b905470b1a69a805
1 /*
2 * The following program is used to generate the constants for
3 * computing sched averages.
5 * ==============================================================
6 * C program (compile with -lm)
7 * ==============================================================
8 */
10 #include <math.h>
11 #include <stdio.h>
13 #define HALFLIFE 32
14 #define SHIFT 32
16 double y;
18 void calc_runnable_avg_yN_inv(void)
20 int i;
21 unsigned int x;
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);
28 if (i % 6 == 0) printf("\n\t");
29 printf("0x%8x, ", x);
31 printf("\n};\n\n");
34 int sum = 1024;
36 void calc_runnable_avg_yN_sum(void)
38 int i;
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;
47 if (i % 11 == 0)
48 printf("\n\t");
50 printf("%5d,", sum);
52 printf("\n};\n\n");
55 int n = -1;
56 /* first period */
57 long max = 1024;
59 void calc_converged_max(void)
61 long last = 0, y_inv = ((1UL<<32)-1)*y;
63 for (; ; n++) {
64 if (n > -1)
65 max = ((max*y_inv)>>SHIFT) + 1024;
67 * This is the same as:
68 * max = max*y + 1024;
71 if (last == max)
72 break;
74 last = max;
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);
82 void calc_accumulated_sum_32(void)
84 int i, x = sum;
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;
91 if (i % 6 == 0)
92 printf("\n\t");
94 printf("%6d,", x);
96 printf("\n};\n\n");
99 void main(void)
101 printf("/* Generated by Documentation/scheduler/sched-pelt; do not modify. */\n\n");
103 y = pow(0.5, 1/(double)HALFLIFE);
105 calc_runnable_avg_yN_inv();
106 // calc_runnable_avg_yN_sum();
107 calc_converged_max();
108 // calc_accumulated_sum_32();