summaryrefslogtreecommitdiffstats
path: root/kernel/power
diff options
context:
space:
mode:
authorQuentin Perret <quentin.perret@arm.com>2019-01-22 11:42:47 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2019-01-23 17:07:57 -0500
commit9cac42d0645ceb2ca8b815cee04810ec9b0d13b3 (patch)
treee5b9b629aee849fc0d914d477d0cee24152f1c82 /kernel/power
parent49a57857aeea06ca831043acbb0fa5e0f50602fd (diff)
PM / EM: Expose the Energy Model in debugfs
The recently introduced Energy Model (EM) framework manages power cost tables of CPUs. These tables are currently only visible from kernel space. However, in order to debug the behaviour of subsystems that use the EM (EAS for example), it is often required to know what the power costs are from userspace. For this reason, introduce under /sys/kernel/debug/energy_model a set of directories representing the performance domains of the system. Each performance domain contains a set of sub-directories representing the different capacity states (cs) and their attributes, as well as a file exposing the related CPUs. The resulting hierarchy is as follows on Arm juno r0 for example: /sys/kernel/debug/energy_model ├── pd0 │   ├── cpus │   ├── cs:450000 │   │   ├── cost │   │   ├── frequency │   │   └── power │   ├── cs:575000 │   │   ├── cost │   │   ├── frequency │   │   └── power │   ├── cs:700000 │   │   ├── cost │   │   ├── frequency │   │   └── power │   ├── cs:775000 │   │   ├── cost │   │   ├── frequency │   │   └── power │   └── cs:850000 │   ├── cost │   ├── frequency │   └── power └── pd1 ├── cpus ├── cs:1100000 │   ├── cost │   ├── frequency │   └── power ├── cs:450000 │   ├── cost │   ├── frequency │   └── power ├── cs:625000 │   ├── cost │   ├── frequency │   └── power ├── cs:800000 │   ├── cost │   ├── frequency │   └── power └── cs:950000 ├── cost ├── frequency └── power Signed-off-by: Quentin Perret <quentin.perret@arm.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'kernel/power')
-rw-r--r--kernel/power/energy_model.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c
index d9dc2c38764a..7d66ee68aaaf 100644
--- a/kernel/power/energy_model.c
+++ b/kernel/power/energy_model.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/cpu.h> 11#include <linux/cpu.h>
12#include <linux/cpumask.h> 12#include <linux/cpumask.h>
13#include <linux/debugfs.h>
13#include <linux/energy_model.h> 14#include <linux/energy_model.h>
14#include <linux/sched/topology.h> 15#include <linux/sched/topology.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
@@ -23,6 +24,60 @@ static DEFINE_PER_CPU(struct em_perf_domain *, em_data);
23 */ 24 */
24static DEFINE_MUTEX(em_pd_mutex); 25static DEFINE_MUTEX(em_pd_mutex);
25 26
27#ifdef CONFIG_DEBUG_FS
28static struct dentry *rootdir;
29
30static void em_debug_create_cs(struct em_cap_state *cs, struct dentry *pd)
31{
32 struct dentry *d;
33 char name[24];
34
35 snprintf(name, sizeof(name), "cs:%lu", cs->frequency);
36
37 /* Create per-cs directory */
38 d = debugfs_create_dir(name, pd);
39 debugfs_create_ulong("frequency", 0444, d, &cs->frequency);
40 debugfs_create_ulong("power", 0444, d, &cs->power);
41 debugfs_create_ulong("cost", 0444, d, &cs->cost);
42}
43
44static int em_debug_cpus_show(struct seq_file *s, void *unused)
45{
46 seq_printf(s, "%*pbl\n", cpumask_pr_args(to_cpumask(s->private)));
47
48 return 0;
49}
50DEFINE_SHOW_ATTRIBUTE(em_debug_cpus);
51
52static void em_debug_create_pd(struct em_perf_domain *pd, int cpu)
53{
54 struct dentry *d;
55 char name[8];
56 int i;
57
58 snprintf(name, sizeof(name), "pd%d", cpu);
59
60 /* Create the directory of the performance domain */
61 d = debugfs_create_dir(name, rootdir);
62
63 debugfs_create_file("cpus", 0444, d, pd->cpus, &em_debug_cpus_fops);
64
65 /* Create a sub-directory for each capacity state */
66 for (i = 0; i < pd->nr_cap_states; i++)
67 em_debug_create_cs(&pd->table[i], d);
68}
69
70static int __init em_debug_init(void)
71{
72 /* Create /sys/kernel/debug/energy_model directory */
73 rootdir = debugfs_create_dir("energy_model", NULL);
74
75 return 0;
76}
77core_initcall(em_debug_init);
78#else /* CONFIG_DEBUG_FS */
79static void em_debug_create_pd(struct em_perf_domain *pd, int cpu) {}
80#endif
26static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states, 81static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
27 struct em_data_callback *cb) 82 struct em_data_callback *cb)
28{ 83{
@@ -102,6 +157,8 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
102 pd->nr_cap_states = nr_states; 157 pd->nr_cap_states = nr_states;
103 cpumask_copy(to_cpumask(pd->cpus), span); 158 cpumask_copy(to_cpumask(pd->cpus), span);
104 159
160 em_debug_create_pd(pd, cpu);
161
105 return pd; 162 return pd;
106 163
107free_cs_table: 164free_cs_table: