From 799be8c1e19be010beddcc4b4db5d939f11005a1 Mon Sep 17 00:00:00 2001 From: Liujie Xie Date: Thu, 11 Nov 2021 17:05:49 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks for frequency optimization These hooks will do the following works: a) Record the number of times when target_freq being clamped b) Record the number of times when target_freq is greater than policy->cur c) Make corresponding optimization strategies in different hooks d) change the value of target_freq for some scenarios Bug: 205906618 Bug: 206896672 Bug: 265246457 Bug: 314452030 Bug: 375411880 Change-Id: I8eba66fd0c6d36393ca39045cf228b659834e0ae Signed-off-by: Liujie Xie Signed-off-by: vincent.wang Signed-off-by: Han Lin Signed-off-by: Wade Wu --- drivers/android/vendor_hooks.c | 3 +++ drivers/cpufreq/cpufreq.c | 6 ++++++ include/trace/hooks/cpufreq.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index b1695d216fdb..70234211137a 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -57,6 +57,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_suspend_epoch_val); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_resume_epoch_val); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_freq_table_limits); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_online); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_resolve_freq); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_fast_switch); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_target); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cpu_cgroup_attach); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cpu_cgroup_online); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ufs_fill_prdt); diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ac04628291c0..4e7a763283fb 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -540,8 +540,10 @@ static unsigned int __resolve_freq(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) { unsigned int idx; + unsigned int old_target_freq = target_freq; target_freq = clamp_val(target_freq, policy->min, policy->max); + trace_android_vh_cpufreq_resolve_freq(policy, &target_freq, old_target_freq); if (!policy->freq_table) return target_freq; @@ -2179,9 +2181,11 @@ unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, unsigned int target_freq) { unsigned int freq; + unsigned int old_target_freq = target_freq; int cpu; target_freq = clamp_val(target_freq, policy->min, policy->max); + trace_android_vh_cpufreq_fast_switch(policy, &target_freq, old_target_freq); freq = cpufreq_driver->fast_switch(policy, target_freq); if (!freq) @@ -2338,6 +2342,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, target_freq = __resolve_freq(policy, target_freq, relation); + trace_android_vh_cpufreq_target(policy, &target_freq, old_target_freq); + pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n", policy->cpu, target_freq, relation, old_target_freq); diff --git a/include/trace/hooks/cpufreq.h b/include/trace/hooks/cpufreq.h index 77443b3bb642..aef236faefa2 100644 --- a/include/trace/hooks/cpufreq.h +++ b/include/trace/hooks/cpufreq.h @@ -24,6 +24,21 @@ DECLARE_HOOK(android_vh_cpufreq_online, TP_PROTO(struct cpufreq_policy *policy), TP_ARGS(policy)); +DECLARE_HOOK(android_vh_cpufreq_resolve_freq, + TP_PROTO(struct cpufreq_policy *policy, unsigned int *target_freq, + unsigned int old_target_freq), + TP_ARGS(policy, target_freq, old_target_freq)); + +DECLARE_HOOK(android_vh_cpufreq_fast_switch, + TP_PROTO(struct cpufreq_policy *policy, unsigned int *target_freq, + unsigned int old_target_freq), + TP_ARGS(policy, target_freq, old_target_freq)); + +DECLARE_HOOK(android_vh_cpufreq_target, + TP_PROTO(struct cpufreq_policy *policy, unsigned int *target_freq, + unsigned int old_target_freq), + TP_ARGS(policy, target_freq, old_target_freq)); + #endif /* _TRACE_HOOK_CPUFREQ_H */ /* This part must be outside protection */ #include