From 84d818b0a6f30692b048bbb491670fd3d69a05c6 Mon Sep 17 00:00:00 2001 From: Yun Hsiang Date: Thu, 13 Aug 2020 14:41:46 +0800 Subject: [PATCH] ANDROID: sched: add vendor hook for correcting cpu capacity Current CPU capacity is scaled by frequency but it will sometime overestimate. Add vendor hook to adjust cpu capacity. android_vh_arch_set_freq_scale Adjust cpu freq scale for each opp. Bug: 163935827 Bug: 265389443 Signed-off-by: Yun Hsiang Change-Id: I054740a7f60301d5a3b085bfa540d52853f5eec5 (cherry picked from commit e209b3b88d9772ecd782d71c1ae7c5425dd20289) --- drivers/android/vendor_hooks.c | 2 ++ drivers/base/arch_topology.c | 3 +++ include/trace/hooks/topology.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 include/trace/hooks/topology.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 97e9414bb44e..7dc7311c9896 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -44,11 +44,13 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event * associated with them) to allow external modules to probe them. */ +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_arch_set_freq_scale); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_is_fpsimd_save); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_transaction_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_set_priority); diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 1ef327b402a9..2cdade8aa933 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -25,6 +25,7 @@ #undef CREATE_TRACE_POINTS #include +#include static DEFINE_PER_CPU(struct scale_freq_data __rcu *, sft_data); static struct cpumask scale_freq_counters_mask; @@ -149,6 +150,8 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq, scale = (cur_freq << SCHED_CAPACITY_SHIFT) / max_freq; + trace_android_vh_arch_set_freq_scale(cpus, cur_freq, max_freq, &scale); + for_each_cpu(i, cpus) per_cpu(arch_freq_scale, i) = scale; } diff --git a/include/trace/hooks/topology.h b/include/trace/hooks/topology.h new file mode 100644 index 000000000000..d2673d4379c1 --- /dev/null +++ b/include/trace/hooks/topology.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM topology + +#define TRACE_INCLUDE_PATH trace/hooks + +#if !defined(_TRACE_HOOK_TOPOLOGY_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_TOPOLOGY_H + +#include + +struct cpumask; + +#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_ANDROID_VENDOR_HOOKS) + +DECLARE_HOOK(android_vh_arch_set_freq_scale, + TP_PROTO(const struct cpumask *cpus, unsigned long freq, unsigned long max, + unsigned long *scale), + TP_ARGS(cpus, freq, max, scale)); + +#else + +#define trace_android_vh_arch_set_freq_scale(cpus, freq, max, scale) + +#endif + +#endif /* _TRACE_HOOK_TOPOLOGY_H */ +/* This part must be outside protection */ +#include