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