diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2013-08-20 02:38:25 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-08-20 09:43:50 -0400 |
commit | 474deff744c4012f07cfa994947d7c6260c9ab89 (patch) | |
tree | cd848f28a6b476080364cd6c808644a652e8b77e /drivers/cpufreq/cpufreq.c | |
parent | 9e9fd801676a946b759a8669baa24ba327c8c903 (diff) |
cpufreq: remove cpufreq_policy_cpu per-cpu variable
cpufreq_policy_cpu per-cpu variables are used for storing the ID of
the CPU that manages the given CPU's policy. However, we also store
a policy pointer for each cpu in cpufreq_cpu_data, so the
cpufreq_policy_cpu information is simply redundant.
It is better to use cpufreq_cpu_data to retrieve a policy and get
policy->cpu from there, so make that happen everywhere and drop the
cpufreq_policy_cpu per-cpu variables which aren't necessary any more.
[rjw: Changelog]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b03a8514b574..0586bd20a474 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -64,15 +64,14 @@ static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); | |||
64 | * - Lock should not be held across | 64 | * - Lock should not be held across |
65 | * __cpufreq_governor(data, CPUFREQ_GOV_STOP); | 65 | * __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
66 | */ | 66 | */ |
67 | static DEFINE_PER_CPU(int, cpufreq_policy_cpu); | ||
68 | static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem); | 67 | static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem); |
69 | 68 | ||
70 | #define lock_policy_rwsem(mode, cpu) \ | 69 | #define lock_policy_rwsem(mode, cpu) \ |
71 | static int lock_policy_rwsem_##mode(int cpu) \ | 70 | static int lock_policy_rwsem_##mode(int cpu) \ |
72 | { \ | 71 | { \ |
73 | int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \ | 72 | struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); \ |
74 | BUG_ON(policy_cpu == -1); \ | 73 | BUG_ON(!policy); \ |
75 | down_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \ | 74 | down_##mode(&per_cpu(cpu_policy_rwsem, policy->cpu)); \ |
76 | \ | 75 | \ |
77 | return 0; \ | 76 | return 0; \ |
78 | } | 77 | } |
@@ -83,9 +82,9 @@ lock_policy_rwsem(write, cpu); | |||
83 | #define unlock_policy_rwsem(mode, cpu) \ | 82 | #define unlock_policy_rwsem(mode, cpu) \ |
84 | static void unlock_policy_rwsem_##mode(int cpu) \ | 83 | static void unlock_policy_rwsem_##mode(int cpu) \ |
85 | { \ | 84 | { \ |
86 | int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \ | 85 | struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); \ |
87 | BUG_ON(policy_cpu == -1); \ | 86 | BUG_ON(!policy); \ |
88 | up_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \ | 87 | up_##mode(&per_cpu(cpu_policy_rwsem, policy->cpu)); \ |
89 | } | 88 | } |
90 | 89 | ||
91 | unlock_policy_rwsem(read, cpu); | 90 | unlock_policy_rwsem(read, cpu); |
@@ -887,7 +886,6 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, | |||
887 | write_lock_irqsave(&cpufreq_driver_lock, flags); | 886 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
888 | 887 | ||
889 | cpumask_set_cpu(cpu, policy->cpus); | 888 | cpumask_set_cpu(cpu, policy->cpus); |
890 | per_cpu(cpufreq_policy_cpu, cpu) = policy->cpu; | ||
891 | per_cpu(cpufreq_cpu_data, cpu) = policy; | 889 | per_cpu(cpufreq_cpu_data, cpu) = policy; |
892 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); | 890 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
893 | 891 | ||
@@ -1013,9 +1011,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, | |||
1013 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; | 1011 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; |
1014 | cpumask_copy(policy->cpus, cpumask_of(cpu)); | 1012 | cpumask_copy(policy->cpus, cpumask_of(cpu)); |
1015 | 1013 | ||
1016 | /* Initially set CPU itself as the policy_cpu */ | ||
1017 | per_cpu(cpufreq_policy_cpu, cpu) = cpu; | ||
1018 | |||
1019 | init_completion(&policy->kobj_unregister); | 1014 | init_completion(&policy->kobj_unregister); |
1020 | INIT_WORK(&policy->update, handle_update); | 1015 | INIT_WORK(&policy->update, handle_update); |
1021 | 1016 | ||
@@ -1053,10 +1048,8 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, | |||
1053 | #endif | 1048 | #endif |
1054 | 1049 | ||
1055 | write_lock_irqsave(&cpufreq_driver_lock, flags); | 1050 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
1056 | for_each_cpu(j, policy->cpus) { | 1051 | for_each_cpu(j, policy->cpus) |
1057 | per_cpu(cpufreq_cpu_data, j) = policy; | 1052 | per_cpu(cpufreq_cpu_data, j) = policy; |
1058 | per_cpu(cpufreq_policy_cpu, j) = policy->cpu; | ||
1059 | } | ||
1060 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1053 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1061 | 1054 | ||
1062 | if (!frozen) { | 1055 | if (!frozen) { |
@@ -1080,15 +1073,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, | |||
1080 | 1073 | ||
1081 | err_out_unregister: | 1074 | err_out_unregister: |
1082 | write_lock_irqsave(&cpufreq_driver_lock, flags); | 1075 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
1083 | for_each_cpu(j, policy->cpus) { | 1076 | for_each_cpu(j, policy->cpus) |
1084 | per_cpu(cpufreq_cpu_data, j) = NULL; | 1077 | per_cpu(cpufreq_cpu_data, j) = NULL; |
1085 | if (j != cpu) | ||
1086 | per_cpu(cpufreq_policy_cpu, j) = -1; | ||
1087 | } | ||
1088 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1078 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1089 | 1079 | ||
1090 | err_set_policy_cpu: | 1080 | err_set_policy_cpu: |
1091 | per_cpu(cpufreq_policy_cpu, cpu) = -1; | ||
1092 | cpufreq_policy_free(policy); | 1081 | cpufreq_policy_free(policy); |
1093 | nomem_out: | 1082 | nomem_out: |
1094 | up_read(&cpufreq_rwsem); | 1083 | up_read(&cpufreq_rwsem); |
@@ -1112,14 +1101,9 @@ static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) | |||
1112 | 1101 | ||
1113 | static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) | 1102 | static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) |
1114 | { | 1103 | { |
1115 | int j; | ||
1116 | |||
1117 | policy->last_cpu = policy->cpu; | 1104 | policy->last_cpu = policy->cpu; |
1118 | policy->cpu = cpu; | 1105 | policy->cpu = cpu; |
1119 | 1106 | ||
1120 | for_each_cpu(j, policy->cpus) | ||
1121 | per_cpu(cpufreq_policy_cpu, j) = cpu; | ||
1122 | |||
1123 | #ifdef CONFIG_CPU_FREQ_TABLE | 1107 | #ifdef CONFIG_CPU_FREQ_TABLE |
1124 | cpufreq_frequency_table_update_policy_cpu(policy); | 1108 | cpufreq_frequency_table_update_policy_cpu(policy); |
1125 | #endif | 1109 | #endif |
@@ -1131,7 +1115,6 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, | |||
1131 | unsigned int old_cpu, bool frozen) | 1115 | unsigned int old_cpu, bool frozen) |
1132 | { | 1116 | { |
1133 | struct device *cpu_dev; | 1117 | struct device *cpu_dev; |
1134 | unsigned long flags; | ||
1135 | int ret; | 1118 | int ret; |
1136 | 1119 | ||
1137 | /* first sibling now owns the new sysfs dir */ | 1120 | /* first sibling now owns the new sysfs dir */ |
@@ -1148,11 +1131,6 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, | |||
1148 | 1131 | ||
1149 | WARN_ON(lock_policy_rwsem_write(old_cpu)); | 1132 | WARN_ON(lock_policy_rwsem_write(old_cpu)); |
1150 | cpumask_set_cpu(old_cpu, policy->cpus); | 1133 | cpumask_set_cpu(old_cpu, policy->cpus); |
1151 | |||
1152 | write_lock_irqsave(&cpufreq_driver_lock, flags); | ||
1153 | per_cpu(cpufreq_cpu_data, old_cpu) = policy; | ||
1154 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); | ||
1155 | |||
1156 | unlock_policy_rwsem_write(old_cpu); | 1134 | unlock_policy_rwsem_write(old_cpu); |
1157 | 1135 | ||
1158 | ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj, | 1136 | ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj, |
@@ -1186,7 +1164,6 @@ static int __cpufreq_remove_dev(struct device *dev, | |||
1186 | write_lock_irqsave(&cpufreq_driver_lock, flags); | 1164 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
1187 | 1165 | ||
1188 | policy = per_cpu(cpufreq_cpu_data, cpu); | 1166 | policy = per_cpu(cpufreq_cpu_data, cpu); |
1189 | per_cpu(cpufreq_cpu_data, cpu) = NULL; | ||
1190 | 1167 | ||
1191 | /* Save the policy somewhere when doing a light-weight tear-down */ | 1168 | /* Save the policy somewhere when doing a light-weight tear-down */ |
1192 | if (frozen) | 1169 | if (frozen) |
@@ -1292,7 +1269,7 @@ static int __cpufreq_remove_dev(struct device *dev, | |||
1292 | } | 1269 | } |
1293 | } | 1270 | } |
1294 | 1271 | ||
1295 | per_cpu(cpufreq_policy_cpu, cpu) = -1; | 1272 | per_cpu(cpufreq_cpu_data, cpu) = NULL; |
1296 | return 0; | 1273 | return 0; |
1297 | } | 1274 | } |
1298 | 1275 | ||
@@ -2148,10 +2125,8 @@ static int __init cpufreq_core_init(void) | |||
2148 | if (cpufreq_disabled()) | 2125 | if (cpufreq_disabled()) |
2149 | return -ENODEV; | 2126 | return -ENODEV; |
2150 | 2127 | ||
2151 | for_each_possible_cpu(cpu) { | 2128 | for_each_possible_cpu(cpu) |
2152 | per_cpu(cpufreq_policy_cpu, cpu) = -1; | ||
2153 | init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); | 2129 | init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); |
2154 | } | ||
2155 | 2130 | ||
2156 | cpufreq_global_kobject = kobject_create(); | 2131 | cpufreq_global_kobject = kobject_create(); |
2157 | BUG_ON(!cpufreq_global_kobject); | 2132 | BUG_ON(!cpufreq_global_kobject); |