sched-pelt.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <math.h>
  10. #include <stdio.h>
  11. #define HALFLIFE 32
  12. #define SHIFT 32
  13. double y;
  14. void calc_runnable_avg_yN_inv(void)
  15. {
  16. int i;
  17. unsigned int x;
  18. /* To silence -Wunused-but-set-variable warnings. */
  19. printf("static const u32 runnable_avg_yN_inv[] __maybe_unused = {");
  20. for (i = 0; i < HALFLIFE; i++) {
  21. x = ((1UL<<32)-1)*pow(y, i);
  22. if (i % 6 == 0) printf("\n\t");
  23. printf("0x%8x, ", x);
  24. }
  25. printf("\n};\n\n");
  26. }
  27. int sum = 1024;
  28. void calc_runnable_avg_yN_sum(void)
  29. {
  30. int i;
  31. printf("static const u32 runnable_avg_yN_sum[] = {\n\t 0,");
  32. for (i = 1; i <= HALFLIFE; i++) {
  33. if (i == 1)
  34. sum *= y;
  35. else
  36. sum = sum*y + 1024*y;
  37. if (i % 11 == 0)
  38. printf("\n\t");
  39. printf("%5d,", sum);
  40. }
  41. printf("\n};\n\n");
  42. }
  43. int n = -1;
  44. /* first period */
  45. long max = 1024;
  46. void calc_converged_max(void)
  47. {
  48. long last = 0, y_inv = ((1UL<<32)-1)*y;
  49. for (; ; n++) {
  50. if (n > -1)
  51. max = ((max*y_inv)>>SHIFT) + 1024;
  52. /*
  53. * This is the same as:
  54. * max = max*y + 1024;
  55. */
  56. if (last == max)
  57. break;
  58. last = max;
  59. }
  60. n--;
  61. printf("#define LOAD_AVG_PERIOD %d\n", HALFLIFE);
  62. printf("#define LOAD_AVG_MAX %ld\n", max);
  63. // printf("#define LOAD_AVG_MAX_N %d\n\n", n);
  64. }
  65. void calc_accumulated_sum_32(void)
  66. {
  67. int i, x = sum;
  68. printf("static const u32 __accumulated_sum_N32[] = {\n\t 0,");
  69. for (i = 1; i <= n/HALFLIFE+1; i++) {
  70. if (i > 1)
  71. x = x/2 + sum;
  72. if (i % 6 == 0)
  73. printf("\n\t");
  74. printf("%6d,", x);
  75. }
  76. printf("\n};\n\n");
  77. }
  78. void main(void)
  79. {
  80. printf("/* Generated by Documentation/scheduler/sched-pelt; do not modify. */\n\n");
  81. y = pow(0.5, 1/(double)HALFLIFE);
  82. calc_runnable_avg_yN_inv();
  83. // calc_runnable_avg_yN_sum();
  84. calc_converged_max();
  85. // calc_accumulated_sum_32();
  86. }