Skip to content

Commit

Permalink
cpufreq: stats: create sysfs entries when cpufreq_stats is a module
Browse files Browse the repository at this point in the history
When cpufreq_stats is compiled in as a module, cpufreq driver would
have already been registered. And so the CPUFREQ_CREATE_POLICY
notifiers wouldn't be called for it. Hence no sysfs entries for stats. :(

This patch calls cpufreq_stats_create_table() for each online CPU from
cpufreq_stats_init() and so if policy is already created for CPUx then
we will register sysfs stats for it.

When its not compiled as module, we will return early as policy wouldn't
be found for any of the CPUs.

Acked-by: Nicolas Pitre <nico@linaro.org>
Tested-by: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Viresh Kumar authored and Rafael J. Wysocki committed Jan 17, 2014
1 parent 2d13594 commit b3f9ff8
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions drivers/cpufreq/cpufreq_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static void cpufreq_stats_free_table(unsigned int cpu)
cpufreq_cpu_put(policy);
}

static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
static int __cpufreq_stats_create_table(struct cpufreq_policy *policy,
struct cpufreq_frequency_table *table)
{
unsigned int i, j, count = 0, ret = 0;
Expand Down Expand Up @@ -253,6 +253,26 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
return ret;
}

static void cpufreq_stats_create_table(unsigned int cpu)
{
struct cpufreq_policy *policy;
struct cpufreq_frequency_table *table;

/*
* "likely(!policy)" because normally cpufreq_stats will be registered
* before cpufreq driver
*/
policy = cpufreq_cpu_get(cpu);
if (likely(!policy))
return;

table = cpufreq_frequency_get_table(policy->cpu);
if (likely(table))
__cpufreq_stats_create_table(policy, table);

cpufreq_cpu_put(policy);
}

static void cpufreq_stats_update_policy_cpu(struct cpufreq_policy *policy)
{
struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table,
Expand Down Expand Up @@ -284,7 +304,7 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
return 0;

if (val == CPUFREQ_CREATE_POLICY)
ret = cpufreq_stats_create_table(policy, table);
ret = __cpufreq_stats_create_table(policy, table);
else if (val == CPUFREQ_REMOVE_POLICY)
__cpufreq_stats_free_table(policy);

Expand Down Expand Up @@ -346,6 +366,9 @@ static int __init cpufreq_stats_init(void)
if (ret)
return ret;

for_each_online_cpu(cpu)
cpufreq_stats_create_table(cpu);

ret = cpufreq_register_notifier(&notifier_trans_block,
CPUFREQ_TRANSITION_NOTIFIER);
if (ret) {
Expand Down

0 comments on commit b3f9ff8

Please sign in to comment.