Commit | Line | Data |
---|---|---|
76d034ed YD |
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 | printf("static const u32 runnable_avg_yN_inv[] = {"); | |
24 | for (i = 0; i < HALFLIFE; i++) { | |
25 | x = ((1UL<<32)-1)*pow(y, i); | |
26 | ||
27 | if (i % 6 == 0) printf("\n\t"); | |
28 | printf("0x%8x, ", x); | |
29 | } | |
30 | printf("\n};\n\n"); | |
31 | } | |
32 | ||
33 | int sum = 1024; | |
34 | ||
35 | void calc_runnable_avg_yN_sum(void) | |
36 | { | |
37 | int i; | |
38 | ||
39 | printf("static const u32 runnable_avg_yN_sum[] = {\n\t 0,"); | |
40 | for (i = 1; i <= HALFLIFE; i++) { | |
41 | if (i == 1) | |
42 | sum *= y; | |
43 | else | |
44 | sum = sum*y + 1024*y; | |
45 | ||
46 | if (i % 11 == 0) | |
47 | printf("\n\t"); | |
48 | ||
49 | printf("%5d,", sum); | |
50 | } | |
51 | printf("\n};\n\n"); | |
52 | } | |
53 | ||
54 | int n = -1; | |
55 | /* first period */ | |
56 | long max = 1024; | |
57 | ||
58 | void calc_converged_max(void) | |
59 | { | |
60 | long last = 0, y_inv = ((1UL<<32)-1)*y; | |
61 | ||
62 | for (; ; n++) { | |
63 | if (n > -1) | |
64 | max = ((max*y_inv)>>SHIFT) + 1024; | |
65 | /* | |
66 | * This is the same as: | |
67 | * max = max*y + 1024; | |
68 | */ | |
69 | ||
70 | if (last == max) | |
71 | break; | |
72 | ||
73 | last = max; | |
74 | } | |
75 | n--; | |
76 | printf("#define LOAD_AVG_PERIOD %d\n", HALFLIFE); | |
77 | printf("#define LOAD_AVG_MAX %ld\n", max); | |
78 | // printf("#define LOAD_AVG_MAX_N %d\n\n", n); | |
79 | } | |
80 | ||
81 | void calc_accumulated_sum_32(void) | |
82 | { | |
83 | int i, x = sum; | |
84 | ||
85 | printf("static const u32 __accumulated_sum_N32[] = {\n\t 0,"); | |
86 | for (i = 1; i <= n/HALFLIFE+1; i++) { | |
87 | if (i > 1) | |
88 | x = x/2 + sum; | |
89 | ||
90 | if (i % 6 == 0) | |
91 | printf("\n\t"); | |
92 | ||
93 | printf("%6d,", x); | |
94 | } | |
95 | printf("\n};\n\n"); | |
96 | } | |
97 | ||
98 | void main(void) | |
99 | { | |
100 | printf("/* Generated by Documentation/scheduler/sched-pelt; do not modify. */\n\n"); | |
101 | ||
102 | y = pow(0.5, 1/(double)HALFLIFE); | |
103 | ||
104 | calc_runnable_avg_yN_inv(); | |
105 | // calc_runnable_avg_yN_sum(); | |
106 | calc_converged_max(); | |
107 | // calc_accumulated_sum_32(); | |
108 | } |