ANDROID: DEBUG: sched,cpufreq: add cpu_capacity change tracepoint
This is useful when we want to compare cpu utilization and
cpu curr capacity side by side.
Signed-off-by: Juri Lelli <juri.lelli@arm.com>
Signed-off-by: Andres Oportus <andresoportus@google.com>
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 19ea8f5..6a3d078 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -29,6 +29,7 @@
#include <linux/suspend.h>
#include <linux/syscore_ops.h>
#include <linux/tick.h>
+#include <linux/sched.h>
#include <trace/events/power.h>
static LIST_HEAD(cpufreq_policy_list);
@@ -428,6 +429,7 @@
void cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
struct cpufreq_freqs *freqs)
{
+ int cpu;
/*
* Catch double invocations of _begin() which lead to self-deadlock.
@@ -456,6 +458,8 @@
spin_unlock(&policy->transition_lock);
scale_freq_capacity(policy, freqs);
+ for_each_cpu(cpu, policy->cpus)
+ trace_cpu_capacity(capacity_curr_of(cpu), cpu);
cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
}
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 074a7c06..d1ab918 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1092,6 +1092,8 @@
struct capacity_state *cap_states; /* ptr to capacity state array */
};
+unsigned long capacity_curr_of(int cpu);
+
struct sched_group;
struct sched_domain_shared {
diff --git a/include/trace/events/power.h b/include/trace/events/power.h
index 070be71..ec6f815 100644
--- a/include/trace/events/power.h
+++ b/include/trace/events/power.h
@@ -172,6 +172,13 @@
(unsigned long)__entry->cpu_id)
);
+DEFINE_EVENT(cpu, cpu_capacity,
+
+ TP_PROTO(unsigned int capacity, unsigned int cpu_id),
+
+ TP_ARGS(capacity, cpu_id)
+);
+
TRACE_EVENT(device_pm_callback_start,
TP_PROTO(struct device *dev, const char *pm_ops, int event),
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 71f9a53..766c693 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5153,6 +5153,17 @@
}
}
+/*
+ * Returns the current capacity of cpu after applying both
+ * cpu and freq scaling.
+ */
+unsigned long capacity_curr_of(int cpu)
+{
+ return cpu_rq(cpu)->cpu_capacity_orig *
+ arch_scale_freq_capacity(NULL, cpu)
+ >> SCHED_CAPACITY_SHIFT;
+}
+
static inline bool energy_aware(void)
{
return sched_feat(ENERGY_AWARE);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 7de37eb..1f5fb36d 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1575,17 +1575,6 @@
return __cpu_util(cpu, 0);
}
-/*
- * Returns the current capacity of cpu after applying both
- * cpu and freq scaling.
- */
-static inline unsigned long capacity_curr_of(int cpu)
-{
- return cpu_rq(cpu)->cpu_capacity_orig *
- arch_scale_freq_capacity(NULL, cpu)
- >> SCHED_CAPACITY_SHIFT;
-}
-
#endif
#ifdef CONFIG_CPU_FREQ_GOV_SCHED