eas_plus.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2018 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  12. */
  13. /*
  14. * Add a system-wide over-utilization indicator which
  15. * is updated in load-balance.
  16. */
  17. #include "../../drivers/misc/mediatek/base/power/include/mtk_upower.h"
  18. #include "energy_plus.h"
  19. extern int cpu_eff_tp;
  20. inline bool system_overutilized(int cpu);
  21. static inline unsigned long task_util(struct task_struct *p);
  22. bool is_intra_domain(int prev, int target);
  23. static int select_max_spare_capacity(struct task_struct *p, int target);
  24. static int init_cpu_info(void);
  25. static unsigned int aggressive_idle_pull(int this_cpu);
  26. bool idle_lb_enhance(struct task_struct *p, int cpu);
  27. static int
  28. ___select_idle_sibling(struct task_struct *p, int prev_cpu, int new_cpu);
  29. static int __find_energy_efficient_cpu(struct sched_domain *sd,
  30. struct task_struct *p, int cpu, int prev_cpu, int sync);
  31. extern int find_best_idle_cpu(struct task_struct *p, bool prefer_idle);
  32. static int start_cpu(struct task_struct *p, bool prefer_idle,
  33. bool boosted);
  34. static int
  35. migrate_running_task(int this_cpu, struct task_struct *p, struct rq *target);
  36. #ifdef CONFIG_UCLAMP_TASK
  37. static __always_inline
  38. unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util,
  39. struct task_struct *p);
  40. #else
  41. inline unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util,
  42. struct task_struct *p)
  43. {
  44. return util;
  45. }
  46. #endif
  47. #ifdef CONFIG_MTK_UNIFY_POWER
  48. extern int
  49. mtk_idle_power(int cpu_idx, int idle_state, int cpu, void *argu, int sd_level);
  50. extern
  51. int mtk_busy_power(int cpu_idx, int cpu, void *argu, int sd_level);
  52. extern
  53. const struct sched_group_energy * const cci_energy(void);
  54. #endif
  55. /*#define DEBUG_EENV_DECISIONS*/
  56. #ifdef DEBUG_EENV_DECISIONS
  57. /* max of 8 levels of sched groups traversed */
  58. #define EAS_EENV_DEBUG_LEVELS 16
  59. struct _eenv_debug {
  60. unsigned long cap;
  61. unsigned long norm_util;
  62. unsigned long cap_energy;
  63. unsigned long idle_energy;
  64. unsigned long this_energy;
  65. unsigned long this_busy_energy;
  66. unsigned long this_idle_energy;
  67. cpumask_t group_cpumask;
  68. unsigned long cpu_util[1];
  69. };
  70. #endif
  71. struct eenv_cpu {
  72. /* CPU ID, must be in cpus_mask */
  73. int cpu_id;
  74. /*
  75. * Index (into sched_group_energy::cap_states) of the OPP the
  76. * CPU needs to run at if the task is placed on it.
  77. * This includes the both active and blocked load, due to
  78. * other tasks on this CPU, as well as the task's own
  79. * utilization.
  80. */
  81. #ifndef CONFIG_MTK_SCHED_EAS_POWER_SUPPORT
  82. int cap_idx;
  83. int cap;
  84. #else
  85. int cap_idx[3]; /* [FIXME] cluster may > 3 */
  86. int cap[3];
  87. #endif
  88. /* Estimated system energy */
  89. unsigned long energy;
  90. /* Estimated energy variation wrt EAS_CPU_PRV */
  91. long nrg_delta;
  92. #ifdef DEBUG_EENV_DECISIONS
  93. struct _eenv_debug *debug;
  94. int debug_idx;
  95. #endif /* DEBUG_EENV_DECISIONS */
  96. };
  97. struct energy_env {
  98. /* Utilization to move */
  99. struct task_struct *p;
  100. unsigned long util_delta;
  101. unsigned long util_delta_boosted;
  102. /* Mask of CPUs candidates to evaluate */
  103. cpumask_t cpus_mask;
  104. /* CPU candidates to evaluate */
  105. struct eenv_cpu *cpu;
  106. int eenv_cpu_count;
  107. #ifdef DEBUG_EENV_DECISIONS
  108. /* pointer to the memory block reserved
  109. * for debug on this CPU - there will be
  110. * sizeof(struct _eenv_debug) *
  111. * (EAS_CPU_CNT * EAS_EENV_DEBUG_LEVELS)
  112. * bytes allocated here.
  113. */
  114. struct _eenv_debug *debug;
  115. #endif
  116. /*
  117. * Index (into energy_env::cpu) of the morst energy efficient CPU for
  118. * the specified energy_env::task
  119. */
  120. int next_idx;
  121. int max_cpu_count;
  122. /* Support data */
  123. struct sched_group *sg_top;
  124. struct sched_group *sg_cap;
  125. struct sched_group *sg;
  126. };
  127. void mtk_update_new_capacity(struct energy_env *eenv);
  128. static void select_task_prefer_cpu_fair(struct task_struct *p, int *result);
  129. inline int valid_cpu_prefer(int task_prefer);
  130. inline int hinted_cpu_prefer(int task_prefer);
  131. int cpu_prefer(struct task_struct *p);
  132. extern unsigned int hmp_cpu_is_fastest(int cpu);
  133. static int check_freq_turning(void);
  134. struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf,
  135. struct task_struct *p, int dest_cpu);