qcom-lpm.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __QCOM_LPM_H__
  7. #define __QCOM_LPM_H__
  8. #define MAX_LPM_CPUS 8
  9. #define MAXSAMPLES 5
  10. #define PRED_TIMER_ADD 100
  11. #define PRED_PREMATURE_CNT 3
  12. #define PRED_REF_STDDEV 500
  13. #define CLUST_SMPL_INVLD_TIME 40000
  14. #define MAX_CLUSTER_STATES 4
  15. extern bool sleep_disabled;
  16. extern bool prediction_disabled;
  17. struct qcom_cluster_node {
  18. struct lpm_cluster *cluster;
  19. struct kobject *kobj;
  20. int state_idx;
  21. struct kobj_attribute disable_attr;
  22. struct attribute_group *attr_group;
  23. struct attribute **attrs;
  24. };
  25. struct history_lpm {
  26. int mode[MAXSAMPLES];
  27. uint32_t resi[MAXSAMPLES];
  28. int nsamp;
  29. uint32_t samples_idx;
  30. };
  31. struct history_ipi {
  32. uint32_t interval[MAXSAMPLES];
  33. uint32_t current_ptr;
  34. ktime_t cpu_idle_resched_ts;
  35. };
  36. struct lpm_cpu {
  37. int cpu;
  38. int enable;
  39. int last_idx;
  40. struct notifier_block nb;
  41. struct cpuidle_driver *drv;
  42. struct cpuidle_device *dev;
  43. ktime_t next_wakeup;
  44. uint64_t predicted;
  45. uint32_t history_invalid;
  46. bool predict_started;
  47. bool htmr_wkup;
  48. struct hrtimer histtimer;
  49. struct hrtimer biastimer;
  50. struct history_lpm lpm_history;
  51. struct history_ipi ipi_history;
  52. ktime_t now;
  53. uint64_t bias;
  54. int64_t next_pred_time;
  55. uint32_t pred_type;
  56. bool ipi_pending;
  57. spinlock_t lock;
  58. };
  59. struct cluster_history {
  60. uint64_t residency;
  61. int mode;
  62. uint64_t entry_time;
  63. };
  64. struct lpm_cluster {
  65. struct device *dev;
  66. uint32_t samples_idx;
  67. bool history_invalid;
  68. bool htmr_wkup;
  69. int entry_idx;
  70. int nsamp;
  71. struct cluster_history history[MAXSAMPLES];
  72. struct generic_pm_domain *genpd;
  73. struct qcom_cluster_node *dev_node[MAX_CLUSTER_STATES];
  74. struct kobject *dev_kobj;
  75. struct notifier_block genpd_nb;
  76. struct work_struct work;
  77. struct hrtimer histtimer;
  78. ktime_t entry_time;
  79. ktime_t next_wakeup;
  80. ktime_t pred_wakeup;
  81. ktime_t now;
  82. ktime_t cpu_next_wakeup[MAX_LPM_CPUS];
  83. bool state_allowed[MAX_CLUSTER_STATES];
  84. struct list_head list;
  85. spinlock_t lock;
  86. bool predicted;
  87. bool initialized;
  88. };
  89. struct cluster_governor {
  90. void (*select)(struct lpm_cpu *cpu_gov);
  91. void (*enable)(void);
  92. void (*disable)(void);
  93. void (*reflect)(void);
  94. };
  95. DECLARE_PER_CPU(struct lpm_cpu, lpm_cpu_data);
  96. int qcom_cluster_lpm_governor_init(void);
  97. void qcom_cluster_lpm_governor_deinit(void);
  98. void update_cluster_select(struct lpm_cpu *cpu_gov);
  99. void clear_cpu_predict_history(void);
  100. int create_global_sysfs_nodes(void);
  101. int create_cluster_sysfs_nodes(struct lpm_cluster *cluster_gov);
  102. void register_cluster_governor_ops(struct cluster_governor *ops);
  103. void remove_global_sysfs_nodes(void);
  104. void remove_cluster_sysfs_nodes(struct lpm_cluster *cluster_gov);
  105. #endif /* __QCOM_LPM_H__ */