Skip to content

Commit 09417e6

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM: EM: Change debugfs configuration to use runtime EM table data
Dump the runtime EM table values which can be modified in time. In order to do that allocate chunk of debug memory which can be later freed automatically thanks to devm_kcalloc(). This design can handle the fact that the EM table memory can change after EM update, so debug code cannot use the pointer from initialization phase. Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Tested-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9f5fb51 commit 09417e6

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

kernel/power/energy_model.c

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,65 @@ static bool _is_cpu_device(struct device *dev)
3737
#ifdef CONFIG_DEBUG_FS
3838
static struct dentry *rootdir;
3939

40-
static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd)
40+
struct em_dbg_info {
41+
struct em_perf_domain *pd;
42+
int ps_id;
43+
};
44+
45+
#define DEFINE_EM_DBG_SHOW(name, fname) \
46+
static int em_debug_##fname##_show(struct seq_file *s, void *unused) \
47+
{ \
48+
struct em_dbg_info *em_dbg = s->private; \
49+
struct em_perf_state *table; \
50+
unsigned long val; \
51+
\
52+
rcu_read_lock(); \
53+
table = em_perf_state_from_pd(em_dbg->pd); \
54+
val = table[em_dbg->ps_id].name; \
55+
rcu_read_unlock(); \
56+
\
57+
seq_printf(s, "%lu\n", val); \
58+
return 0; \
59+
} \
60+
DEFINE_SHOW_ATTRIBUTE(em_debug_##fname)
61+
62+
DEFINE_EM_DBG_SHOW(frequency, frequency);
63+
DEFINE_EM_DBG_SHOW(power, power);
64+
DEFINE_EM_DBG_SHOW(cost, cost);
65+
DEFINE_EM_DBG_SHOW(performance, performance);
66+
DEFINE_EM_DBG_SHOW(flags, inefficiency);
67+
68+
static void em_debug_create_ps(struct em_perf_domain *em_pd,
69+
struct em_dbg_info *em_dbg, int i,
70+
struct dentry *pd)
4171
{
72+
struct em_perf_state *table;
73+
unsigned long freq;
4274
struct dentry *d;
4375
char name[24];
4476

45-
snprintf(name, sizeof(name), "ps:%lu", ps->frequency);
77+
em_dbg[i].pd = em_pd;
78+
em_dbg[i].ps_id = i;
79+
80+
rcu_read_lock();
81+
table = em_perf_state_from_pd(em_pd);
82+
freq = table[i].frequency;
83+
rcu_read_unlock();
84+
85+
snprintf(name, sizeof(name), "ps:%lu", freq);
4686

4787
/* Create per-ps directory */
4888
d = debugfs_create_dir(name, pd);
49-
debugfs_create_ulong("frequency", 0444, d, &ps->frequency);
50-
debugfs_create_ulong("power", 0444, d, &ps->power);
51-
debugfs_create_ulong("cost", 0444, d, &ps->cost);
52-
debugfs_create_ulong("performance", 0444, d, &ps->performance);
53-
debugfs_create_ulong("inefficient", 0444, d, &ps->flags);
89+
debugfs_create_file("frequency", 0444, d, &em_dbg[i],
90+
&em_debug_frequency_fops);
91+
debugfs_create_file("power", 0444, d, &em_dbg[i],
92+
&em_debug_power_fops);
93+
debugfs_create_file("cost", 0444, d, &em_dbg[i],
94+
&em_debug_cost_fops);
95+
debugfs_create_file("performance", 0444, d, &em_dbg[i],
96+
&em_debug_performance_fops);
97+
debugfs_create_file("inefficient", 0444, d, &em_dbg[i],
98+
&em_debug_inefficiency_fops);
5499
}
55100

56101
static int em_debug_cpus_show(struct seq_file *s, void *unused)
@@ -73,6 +118,7 @@ DEFINE_SHOW_ATTRIBUTE(em_debug_flags);
73118

74119
static void em_debug_create_pd(struct device *dev)
75120
{
121+
struct em_dbg_info *em_dbg;
76122
struct dentry *d;
77123
int i;
78124

@@ -86,9 +132,14 @@ static void em_debug_create_pd(struct device *dev)
86132
debugfs_create_file("flags", 0444, d, dev->em_pd,
87133
&em_debug_flags_fops);
88134

135+
em_dbg = devm_kcalloc(dev, dev->em_pd->nr_perf_states,
136+
sizeof(*em_dbg), GFP_KERNEL);
137+
if (!em_dbg)
138+
return;
139+
89140
/* Create a sub-directory for each performance state */
90141
for (i = 0; i < dev->em_pd->nr_perf_states; i++)
91-
em_debug_create_ps(&dev->em_pd->table[i], d);
142+
em_debug_create_ps(dev->em_pd, em_dbg, i, d);
92143

93144
}
94145

0 commit comments

Comments
 (0)