Merge tag 'usb-serial-4.20-rc7' of https://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / Documentation / scheduler / sched-pelt.c
blobe4219139386ae805575a7c1cae5dc83f5b3e52ca
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 printf("static const u32 runnable_avg_yN_inv[] = {");
24 for (i = 0; i < HALFLIFE; i++) {
25 x = ((1UL<<32)-1)*pow(y, i);
27 if (i % 6 == 0) printf("\n\t");
28 printf("0x%8x, ", x);
30 printf("\n};\n\n");
33 int sum = 1024;
35 void calc_runnable_avg_yN_sum(void)
37 int i;
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;
46 if (i % 11 == 0)
47 printf("\n\t");
49 printf("%5d,", sum);
51 printf("\n};\n\n");
54 int n = -1;
55 /* first period */
56 long max = 1024;
58 void calc_converged_max(void)
60 long last = 0, y_inv = ((1UL<<32)-1)*y;
62 for (; ; n++) {
63 if (n > -1)
64 max = ((max*y_inv)>>SHIFT) + 1024;
66 * This is the same as:
67 * max = max*y + 1024;
70 if (last == max)
71 break;
73 last = max;
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);
81 void calc_accumulated_sum_32(void)
83 int i, x = sum;
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;
90 if (i % 6 == 0)
91 printf("\n\t");
93 printf("%6d,", x);
95 printf("\n};\n\n");
98 void main(void)
100 printf("/* Generated by Documentation/scheduler/sched-pelt; do not modify. */\n\n");
102 y = pow(0.5, 1/(double)HALFLIFE);
104 calc_runnable_avg_yN_inv();
105 // calc_runnable_avg_yN_sum();
106 calc_converged_max();
107 // calc_accumulated_sum_32();