iwlwifi: mvm: support family 8000 B2/C steps
[deliverable/linux.git] / drivers / cpufreq / cpufreq_stats.c
index cdc5233cf0c4dde0f2c1377b68105f70f6e401cc..5e370a30a964f5f30e9944daa9a768507c938af4 100644 (file)
@@ -18,7 +18,6 @@
 static spinlock_t cpufreq_stats_lock;
 
 struct cpufreq_stats {
-       unsigned int cpu;
        unsigned int total_trans;
        unsigned long long last_time;
        unsigned int max_state;
@@ -36,9 +35,7 @@ static int cpufreq_stats_update(struct cpufreq_stats *stats)
        unsigned long long cur_time = get_jiffies_64();
 
        spin_lock(&cpufreq_stats_lock);
-       if (stats->time_in_state)
-               stats->time_in_state[stats->last_index] +=
-                       cur_time - stats->last_time;
+       stats->time_in_state[stats->last_index] += cur_time - stats->last_time;
        stats->last_time = cur_time;
        spin_unlock(&cpufreq_stats_lock);
        return 0;
@@ -71,7 +68,6 @@ static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
        ssize_t len = 0;
        int i, j;
 
-       cpufreq_stats_update(stats);
        len += snprintf(buf + len, PAGE_SIZE - len, "   From  :    To\n");
        len += snprintf(buf + len, PAGE_SIZE - len, "         : ");
        for (i = 0; i < stats->state_num; i++) {
@@ -165,12 +161,13 @@ static void cpufreq_stats_free_table(unsigned int cpu)
 
 static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
 {
-       unsigned int i, count = 0, ret = 0;
+       unsigned int i = 0, count = 0, ret = -ENOMEM;
        struct cpufreq_stats *stats;
        unsigned int alloc_size;
        unsigned int cpu = policy->cpu;
        struct cpufreq_frequency_table *pos, *table;
 
+       /* We need cpufreq table for creating stats table */
        table = cpufreq_frequency_get_table(cpu);
        if (unlikely(!table))
                return 0;
@@ -180,16 +177,10 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
                return -EEXIST;
 
        stats = kzalloc(sizeof(*stats), GFP_KERNEL);
-       if ((stats) == NULL)
+       if (!stats)
                return -ENOMEM;
 
-       ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
-       if (ret)
-               goto error_out;
-
-       stats->cpu = cpu;
-       policy->stats = stats;
-
+       /* Find total allocation size */
        cpufreq_for_each_valid_entry(pos, table)
                count++;
 
@@ -198,32 +189,40 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS
        alloc_size += count * count * sizeof(int);
 #endif
-       stats->max_state = count;
+
+       /* Allocate memory for time_in_state/freq_table/trans_table in one go */
        stats->time_in_state = kzalloc(alloc_size, GFP_KERNEL);
-       if (!stats->time_in_state) {
-               ret = -ENOMEM;
-               goto error_alloc;
-       }
+       if (!stats->time_in_state)
+               goto free_stat;
+
        stats->freq_table = (unsigned int *)(stats->time_in_state + count);
 
 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS
        stats->trans_table = stats->freq_table + count;
 #endif
-       i = 0;
+
+       stats->max_state = count;
+
+       /* Find valid-unique entries */
        cpufreq_for_each_valid_entry(pos, table)
                if (freq_table_get_index(stats, pos->frequency) == -1)
                        stats->freq_table[i++] = pos->frequency;
+
        stats->state_num = i;
-       spin_lock(&cpufreq_stats_lock);
        stats->last_time = get_jiffies_64();
        stats->last_index = freq_table_get_index(stats, policy->cur);
-       spin_unlock(&cpufreq_stats_lock);
-       return 0;
-error_alloc:
-       sysfs_remove_group(&policy->kobj, &stats_attr_group);
-error_out:
-       kfree(stats);
+
+       policy->stats = stats;
+       ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
+       if (!ret)
+               return 0;
+
+       /* We failed, release resources */
        policy->stats = NULL;
+       kfree(stats->time_in_state);
+free_stat:
+       kfree(stats);
+
        return ret;
 }
 
@@ -244,22 +243,12 @@ static void cpufreq_stats_create_table(unsigned int cpu)
        cpufreq_cpu_put(policy);
 }
 
-static void cpufreq_stats_update_policy_cpu(struct cpufreq_policy *policy)
-{
-       policy->stats->cpu = policy->cpu;
-}
-
 static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
                unsigned long val, void *data)
 {
        int ret = 0;
        struct cpufreq_policy *policy = data;
 
-       if (val == CPUFREQ_UPDATE_POLICY_CPU) {
-               cpufreq_stats_update_policy_cpu(policy);
-               return 0;
-       }
-
        if (val == CPUFREQ_CREATE_POLICY)
                ret = __cpufreq_stats_create_table(policy);
        else if (val == CPUFREQ_REMOVE_POLICY)
@@ -298,18 +287,16 @@ static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
        if (old_index == -1 || new_index == -1)
                goto put_policy;
 
-       cpufreq_stats_update(stats);
-
        if (old_index == new_index)
                goto put_policy;
 
-       spin_lock(&cpufreq_stats_lock);
+       cpufreq_stats_update(stats);
+
        stats->last_index = new_index;
 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS
        stats->trans_table[old_index * stats->max_state + new_index]++;
 #endif
        stats->total_trans++;
-       spin_unlock(&cpufreq_stats_lock);
 
 put_policy:
        cpufreq_cpu_put(policy);
This page took 0.026763 seconds and 5 git commands to generate.