energy_plus.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (C) 2017 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. #ifdef CONFIG_MTK_UNIFY_POWER
  14. #include "../../drivers/misc/mediatek/base/power/include/mtk_upower.h"
  15. /*
  16. * MTK static specific energy cost model data. There are no unit requirements
  17. * for the data. Data can be normalized to any reference point, but the
  18. * normalization must be consistent. That is, one bogo-joule/watt must be the
  19. * same quantity for all data, but we don't care what it is.
  20. */
  21. static struct idle_state default_idle_states[] = {
  22. { .power = 0 }, /* 0: active idle = WFI, [P8].leak */
  23. { .power = 0 }, /* 1: disabled */
  24. { .power = 0 }, /* 2: disabled */
  25. { .power = 0 }, /* 3: disabled */
  26. { .power = 0 }, /* 4: MCDI */
  27. { .power = 0 }, /* 5: disabled */
  28. { .power = 0 }, /* 6: WFI/SPARK */
  29. };
  30. static void update_cpu_capacity(unsigned int cpu)
  31. {
  32. unsigned long capacity = SCHED_CAPACITY_SCALE;
  33. if (cpu_core_energy(cpu)) {
  34. int max_cap_idx = cpu_core_energy(cpu)->nr_cap_states - 1;
  35. capacity = cpu_core_energy(cpu)->cap_states[max_cap_idx].cap;
  36. }
  37. topology_set_cpu_scale(cpu, capacity);
  38. pr_info("CPU%d: update cpu_capacity %lu\n",
  39. cpu, arch_scale_cpu_capacity(NULL, cpu));
  40. }
  41. void init_sched_energy_costs(void)
  42. {
  43. struct sched_group_energy *sge;
  44. int sd_level, cpu;
  45. for_each_possible_cpu(cpu) {
  46. for_each_possible_sd_level(sd_level) {
  47. sge = kcalloc(1, sizeof(struct sched_group_energy),
  48. GFP_NOWAIT);
  49. sge->nr_idle_states = ARRAY_SIZE(default_idle_states);
  50. #ifdef CONFIG_MTK_SCHED_EAS_POWER_SUPPORT
  51. sge->idle_power = mtk_idle_power;
  52. sge->busy_power = mtk_busy_power;
  53. #endif
  54. sge->idle_states = default_idle_states;
  55. sge_array[cpu][sd_level] = sge;
  56. }
  57. update_cpu_capacity(cpu);
  58. }
  59. return;
  60. }
  61. #endif