From 7e2fbdaeabb31251f42e38bed0ae0b660408f8e6 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 Bug: 205906618 Signed-off-by: Liujie Xie Change-Id: I8eba66fd0c6d36393ca39045cf228b659834e0ae Signed-off-by: xieliujie --- 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 d5fbbfd703fc..952053d4f5fa 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -136,6 +136,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_show_max_freq); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_freq_table_limits); +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_sched_newidle_balance); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_sched_nohz_balancer_kick); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_sched_rebalance_domains); diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index f0ec98dbfc96..5ea258839bcc 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -543,7 +543,10 @@ EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch); unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, unsigned int target_freq) { + 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); policy->cached_target_freq = target_freq; if (cpufreq_driver->target_index) { @@ -2094,9 +2097,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) @@ -2213,6 +2218,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, /* Make sure that target_freq is within supported range */ target_freq = clamp_val(target_freq, policy->min, policy->max); + 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 500c96ac7776..5e20f7d00d3d 100644 --- a/include/trace/hooks/cpufreq.h +++ b/include/trace/hooks/cpufreq.h @@ -31,6 +31,21 @@ DECLARE_HOOK(android_vh_cpufreq_acct_update_power, DECLARE_RESTRICTED_HOOK(android_rvh_cpufreq_transition, TP_PROTO(struct cpufreq_policy *policy), TP_ARGS(policy), 1); + +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)); /* macro versions of hooks are no longer required */ #endif /* _TRACE_HOOK_CPUFREQ_H */