Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'pm-cpufreq' into pm-opp

+638 -404
+12
arch/powerpc/include/asm/opal-api.h
··· 361 361 OPAL_MSG_HMI_EVT, 362 362 OPAL_MSG_DPO, 363 363 OPAL_MSG_PRD, 364 + OPAL_MSG_OCC, 364 365 OPAL_MSG_TYPE_MAX, 365 366 }; 366 367 ··· 700 699 }; 701 700 702 701 struct opal_prd_msg; 702 + 703 + #define OCC_RESET 0 704 + #define OCC_LOAD 1 705 + #define OCC_THROTTLE 2 706 + #define OCC_MAX_THROTTLE_STATUS 5 707 + 708 + struct opal_occ_msg { 709 + __be64 type; 710 + __be64 chip; 711 + __be64 throttle_status; 712 + }; 703 713 704 714 /* 705 715 * SG entries
+1 -3
drivers/acpi/processor_perflib.c
··· 784 784 785 785 EXPORT_SYMBOL(acpi_processor_register_performance); 786 786 787 - void 788 - acpi_processor_unregister_performance(struct acpi_processor_performance 789 - *performance, unsigned int cpu) 787 + void acpi_processor_unregister_performance(unsigned int cpu) 790 788 { 791 789 struct acpi_processor *pr; 792 790
+51 -42
drivers/cpufreq/acpi-cpufreq.c
··· 65 65 #define MSR_K7_HWCR_CPB_DIS (1ULL << 25) 66 66 67 67 struct acpi_cpufreq_data { 68 - struct acpi_processor_performance *acpi_data; 69 68 struct cpufreq_frequency_table *freq_table; 70 69 unsigned int resume; 71 70 unsigned int cpu_feature; 71 + unsigned int acpi_perf_cpu; 72 72 cpumask_var_t freqdomain_cpus; 73 73 }; 74 74 75 - static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); 76 - 77 75 /* acpi_perf_data is a pointer to percpu data. */ 78 76 static struct acpi_processor_performance __percpu *acpi_perf_data; 77 + 78 + static inline struct acpi_processor_performance *to_perf_data(struct acpi_cpufreq_data *data) 79 + { 80 + return per_cpu_ptr(acpi_perf_data, data->acpi_perf_cpu); 81 + } 79 82 80 83 static struct cpufreq_driver acpi_cpufreq_driver; 81 84 ··· 147 144 148 145 static ssize_t show_freqdomain_cpus(struct cpufreq_policy *policy, char *buf) 149 146 { 150 - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); 147 + struct acpi_cpufreq_data *data = policy->driver_data; 151 148 152 149 return cpufreq_show_cpus(data->freqdomain_cpus, buf); 153 150 } ··· 205 202 struct acpi_processor_performance *perf; 206 203 int i; 207 204 208 - perf = data->acpi_data; 205 + perf = to_perf_data(data); 209 206 210 207 for (i = 0; i < perf->state_count; i++) { 211 208 if (value == perf->states[i].status) ··· 224 221 else 225 222 msr &= INTEL_MSR_RANGE; 226 223 227 - perf = data->acpi_data; 224 + perf = to_perf_data(data); 228 225 229 226 cpufreq_for_each_entry(pos, data->freq_table) 230 227 if (msr == perf->states[pos->driver_data].status) ··· 330 327 put_cpu(); 331 328 } 332 329 333 - static u32 get_cur_val(const struct cpumask *mask) 330 + static u32 331 + get_cur_val(const struct cpumask *mask, struct acpi_cpufreq_data *data) 334 332 { 335 333 struct acpi_processor_performance *perf; 336 334 struct drv_cmd cmd; ··· 339 335 if (unlikely(cpumask_empty(mask))) 340 336 return 0; 341 337 342 - switch (per_cpu(acfreq_data, cpumask_first(mask))->cpu_feature) { 338 + switch (data->cpu_feature) { 343 339 case SYSTEM_INTEL_MSR_CAPABLE: 344 340 cmd.type = SYSTEM_INTEL_MSR_CAPABLE; 345 341 cmd.addr.msr.reg = MSR_IA32_PERF_CTL; ··· 350 346 break; 351 347 case SYSTEM_IO_CAPABLE: 352 348 cmd.type = SYSTEM_IO_CAPABLE; 353 - perf = per_cpu(acfreq_data, cpumask_first(mask))->acpi_data; 349 + perf = to_perf_data(data); 354 350 cmd.addr.io.port = perf->control_register.address; 355 351 cmd.addr.io.bit_width = perf->control_register.bit_width; 356 352 break; ··· 368 364 369 365 static unsigned int get_cur_freq_on_cpu(unsigned int cpu) 370 366 { 371 - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu); 367 + struct acpi_cpufreq_data *data; 368 + struct cpufreq_policy *policy; 372 369 unsigned int freq; 373 370 unsigned int cached_freq; 374 371 375 372 pr_debug("get_cur_freq_on_cpu (%d)\n", cpu); 376 373 377 - if (unlikely(data == NULL || 378 - data->acpi_data == NULL || data->freq_table == NULL)) { 374 + policy = cpufreq_cpu_get(cpu); 375 + if (unlikely(!policy)) 379 376 return 0; 380 - } 381 377 382 - cached_freq = data->freq_table[data->acpi_data->state].frequency; 383 - freq = extract_freq(get_cur_val(cpumask_of(cpu)), data); 378 + data = policy->driver_data; 379 + cpufreq_cpu_put(policy); 380 + if (unlikely(!data || !data->freq_table)) 381 + return 0; 382 + 383 + cached_freq = data->freq_table[to_perf_data(data)->state].frequency; 384 + freq = extract_freq(get_cur_val(cpumask_of(cpu), data), data); 384 385 if (freq != cached_freq) { 385 386 /* 386 387 * The dreaded BIOS frequency change behind our back. ··· 406 397 unsigned int i; 407 398 408 399 for (i = 0; i < 100; i++) { 409 - cur_freq = extract_freq(get_cur_val(mask), data); 400 + cur_freq = extract_freq(get_cur_val(mask, data), data); 410 401 if (cur_freq == freq) 411 402 return 1; 412 403 udelay(10); ··· 417 408 static int acpi_cpufreq_target(struct cpufreq_policy *policy, 418 409 unsigned int index) 419 410 { 420 - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); 411 + struct acpi_cpufreq_data *data = policy->driver_data; 421 412 struct acpi_processor_performance *perf; 422 413 struct drv_cmd cmd; 423 414 unsigned int next_perf_state = 0; /* Index into perf table */ 424 415 int result = 0; 425 416 426 - if (unlikely(data == NULL || 427 - data->acpi_data == NULL || data->freq_table == NULL)) { 417 + if (unlikely(data == NULL || data->freq_table == NULL)) { 428 418 return -ENODEV; 429 419 } 430 420 431 - perf = data->acpi_data; 421 + perf = to_perf_data(data); 432 422 next_perf_state = data->freq_table[index].driver_data; 433 423 if (perf->state == next_perf_state) { 434 424 if (unlikely(data->resume)) { ··· 490 482 static unsigned long 491 483 acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) 492 484 { 493 - struct acpi_processor_performance *perf = data->acpi_data; 485 + struct acpi_processor_performance *perf; 494 486 487 + perf = to_perf_data(data); 495 488 if (cpu_khz) { 496 489 /* search the closest match to cpu_khz */ 497 490 unsigned int i; ··· 681 672 goto err_free; 682 673 } 683 674 684 - data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu); 685 - per_cpu(acfreq_data, cpu) = data; 675 + perf = per_cpu_ptr(acpi_perf_data, cpu); 676 + data->acpi_perf_cpu = cpu; 677 + policy->driver_data = data; 686 678 687 679 if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) 688 680 acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS; 689 681 690 - result = acpi_processor_register_performance(data->acpi_data, cpu); 682 + result = acpi_processor_register_performance(perf, cpu); 691 683 if (result) 692 684 goto err_free_mask; 693 685 694 - perf = data->acpi_data; 695 686 policy->shared_type = perf->shared_type; 696 687 697 688 /* ··· 847 838 err_freqfree: 848 839 kfree(data->freq_table); 849 840 err_unreg: 850 - acpi_processor_unregister_performance(perf, cpu); 841 + acpi_processor_unregister_performance(cpu); 851 842 err_free_mask: 852 843 free_cpumask_var(data->freqdomain_cpus); 853 844 err_free: 854 845 kfree(data); 855 - per_cpu(acfreq_data, cpu) = NULL; 846 + policy->driver_data = NULL; 856 847 857 848 return result; 858 849 } 859 850 860 851 static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy) 861 852 { 862 - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); 853 + struct acpi_cpufreq_data *data = policy->driver_data; 863 854 864 855 pr_debug("acpi_cpufreq_cpu_exit\n"); 865 856 866 857 if (data) { 867 - per_cpu(acfreq_data, policy->cpu) = NULL; 868 - acpi_processor_unregister_performance(data->acpi_data, 869 - policy->cpu); 858 + policy->driver_data = NULL; 859 + acpi_processor_unregister_performance(data->acpi_perf_cpu); 870 860 free_cpumask_var(data->freqdomain_cpus); 871 861 kfree(data->freq_table); 872 862 kfree(data); ··· 876 868 877 869 static int acpi_cpufreq_resume(struct cpufreq_policy *policy) 878 870 { 879 - struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); 871 + struct acpi_cpufreq_data *data = policy->driver_data; 880 872 881 873 pr_debug("acpi_cpufreq_resume\n"); 882 874 ··· 888 880 static struct freq_attr *acpi_cpufreq_attr[] = { 889 881 &cpufreq_freq_attr_scaling_available_freqs, 890 882 &freqdomain_cpus, 891 - NULL, /* this is a placeholder for cpb, do not remove */ 883 + #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB 884 + &cpb, 885 + #endif 892 886 NULL, 893 887 }; 894 888 ··· 963 953 * only if configured. This is considered legacy code, which 964 954 * will probably be removed at some point in the future. 965 955 */ 966 - if (check_amd_hwpstate_cpu(0)) { 967 - struct freq_attr **iter; 956 + if (!check_amd_hwpstate_cpu(0)) { 957 + struct freq_attr **attr; 968 958 969 - pr_debug("adding sysfs entry for cpb\n"); 959 + pr_debug("CPB unsupported, do not expose it\n"); 970 960 971 - for (iter = acpi_cpufreq_attr; *iter != NULL; iter++) 972 - ; 973 - 974 - /* make sure there is a terminator behind it */ 975 - if (iter[1] == NULL) 976 - *iter = &cpb; 961 + for (attr = acpi_cpufreq_attr; *attr; attr++) 962 + if (*attr == &cpb) { 963 + *attr = NULL; 964 + break; 965 + } 977 966 } 978 967 #endif 979 968 acpi_cpufreq_boost_init();
+145 -177
drivers/cpufreq/cpufreq.c
··· 112 112 return cpufreq_driver->target_index || cpufreq_driver->target; 113 113 } 114 114 115 - /* 116 - * rwsem to guarantee that cpufreq driver module doesn't unload during critical 117 - * sections 118 - */ 119 - static DECLARE_RWSEM(cpufreq_rwsem); 120 - 121 115 /* internal prototypes */ 122 116 static int __cpufreq_governor(struct cpufreq_policy *policy, 123 117 unsigned int event); ··· 271 277 * If corresponding call cpufreq_cpu_put() isn't made, the policy wouldn't be 272 278 * freed as that depends on the kobj count. 273 279 * 274 - * It also takes a read-lock of 'cpufreq_rwsem' and doesn't put it back if a 275 - * valid policy is found. This is done to make sure the driver doesn't get 276 - * unregistered while the policy is being used. 277 - * 278 280 * Return: A valid policy on success, otherwise NULL on failure. 279 281 */ 280 282 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) ··· 279 289 unsigned long flags; 280 290 281 291 if (WARN_ON(cpu >= nr_cpu_ids)) 282 - return NULL; 283 - 284 - if (!down_read_trylock(&cpufreq_rwsem)) 285 292 return NULL; 286 293 287 294 /* get the cpufreq driver */ ··· 293 306 294 307 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 295 308 296 - if (!policy) 297 - up_read(&cpufreq_rwsem); 298 - 299 309 return policy; 300 310 } 301 311 EXPORT_SYMBOL_GPL(cpufreq_cpu_get); ··· 304 320 * 305 321 * This decrements the kobject reference count incremented earlier by calling 306 322 * cpufreq_cpu_get(). 307 - * 308 - * It also drops the read-lock of 'cpufreq_rwsem' taken at cpufreq_cpu_get(). 309 323 */ 310 324 void cpufreq_cpu_put(struct cpufreq_policy *policy) 311 325 { 312 326 kobject_put(&policy->kobj); 313 - up_read(&cpufreq_rwsem); 314 327 } 315 328 EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 316 329 ··· 832 851 struct freq_attr *fattr = to_attr(attr); 833 852 ssize_t ret; 834 853 835 - if (!down_read_trylock(&cpufreq_rwsem)) 836 - return -EINVAL; 837 - 838 854 down_read(&policy->rwsem); 839 855 840 856 if (fattr->show) ··· 840 862 ret = -EIO; 841 863 842 864 up_read(&policy->rwsem); 843 - up_read(&cpufreq_rwsem); 844 865 845 866 return ret; 846 867 } ··· 854 877 get_online_cpus(); 855 878 856 879 if (!cpu_online(policy->cpu)) 857 - goto unlock; 858 - 859 - if (!down_read_trylock(&cpufreq_rwsem)) 860 880 goto unlock; 861 881 862 882 down_write(&policy->rwsem); ··· 871 897 872 898 unlock_policy_rwsem: 873 899 up_write(&policy->rwsem); 874 - 875 - up_read(&cpufreq_rwsem); 876 900 unlock: 877 901 put_online_cpus(); 878 902 ··· 999 1027 } 1000 1028 } 1001 1029 1002 - static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, 1003 - struct device *dev) 1030 + static int cpufreq_add_dev_interface(struct cpufreq_policy *policy) 1004 1031 { 1005 1032 struct freq_attr **drv_attr; 1006 1033 int ret = 0; ··· 1031 1060 return cpufreq_add_dev_symlink(policy); 1032 1061 } 1033 1062 1034 - static void cpufreq_init_policy(struct cpufreq_policy *policy) 1063 + static int cpufreq_init_policy(struct cpufreq_policy *policy) 1035 1064 { 1036 1065 struct cpufreq_governor *gov = NULL; 1037 1066 struct cpufreq_policy new_policy; 1038 - int ret = 0; 1039 1067 1040 1068 memcpy(&new_policy, policy, sizeof(*policy)); 1041 1069 ··· 1053 1083 cpufreq_parse_governor(gov->name, &new_policy.policy, NULL); 1054 1084 1055 1085 /* set default policy */ 1056 - ret = cpufreq_set_policy(policy, &new_policy); 1057 - if (ret) { 1058 - pr_debug("setting policy failed\n"); 1059 - if (cpufreq_driver->exit) 1060 - cpufreq_driver->exit(policy); 1061 - } 1086 + return cpufreq_set_policy(policy, &new_policy); 1062 1087 } 1063 1088 1064 - static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, 1065 - unsigned int cpu, struct device *dev) 1089 + static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) 1066 1090 { 1067 1091 int ret = 0; 1068 1092 ··· 1090 1126 return 0; 1091 1127 } 1092 1128 1093 - static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu) 1129 + static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) 1094 1130 { 1095 - struct cpufreq_policy *policy; 1096 - unsigned long flags; 1097 - 1098 - read_lock_irqsave(&cpufreq_driver_lock, flags); 1099 - policy = per_cpu(cpufreq_cpu_data, cpu); 1100 - read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1101 - 1102 - if (likely(policy)) { 1103 - /* Policy should be inactive here */ 1104 - WARN_ON(!policy_is_inactive(policy)); 1105 - 1106 - down_write(&policy->rwsem); 1107 - policy->cpu = cpu; 1108 - policy->governor = NULL; 1109 - up_write(&policy->rwsem); 1110 - } 1111 - 1112 - return policy; 1113 - } 1114 - 1115 - static struct cpufreq_policy *cpufreq_policy_alloc(struct device *dev) 1116 - { 1131 + struct device *dev = get_cpu_device(cpu); 1117 1132 struct cpufreq_policy *policy; 1118 1133 int ret; 1134 + 1135 + if (WARN_ON(!dev)) 1136 + return NULL; 1119 1137 1120 1138 policy = kzalloc(sizeof(*policy), GFP_KERNEL); 1121 1139 if (!policy) ··· 1126 1180 init_completion(&policy->kobj_unregister); 1127 1181 INIT_WORK(&policy->update, handle_update); 1128 1182 1129 - policy->cpu = dev->id; 1183 + policy->cpu = cpu; 1130 1184 1131 1185 /* Set this once on allocation */ 1132 - policy->kobj_cpu = dev->id; 1186 + policy->kobj_cpu = cpu; 1133 1187 1134 1188 return policy; 1135 1189 ··· 1191 1245 kfree(policy); 1192 1246 } 1193 1247 1194 - /** 1195 - * cpufreq_add_dev - add a CPU device 1196 - * 1197 - * Adds the cpufreq interface for a CPU device. 1198 - * 1199 - * The Oracle says: try running cpufreq registration/unregistration concurrently 1200 - * with with cpu hotplugging and all hell will break loose. Tried to clean this 1201 - * mess up, but more thorough testing is needed. - Mathieu 1202 - */ 1203 - static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1248 + static int cpufreq_online(unsigned int cpu) 1204 1249 { 1205 - unsigned int j, cpu = dev->id; 1206 - int ret = -ENOMEM; 1207 1250 struct cpufreq_policy *policy; 1251 + bool new_policy; 1208 1252 unsigned long flags; 1209 - bool recover_policy = !sif; 1253 + unsigned int j; 1254 + int ret; 1210 1255 1211 - pr_debug("adding CPU %u\n", cpu); 1212 - 1213 - if (cpu_is_offline(cpu)) { 1214 - /* 1215 - * Only possible if we are here from the subsys_interface add 1216 - * callback. A hotplug notifier will follow and we will handle 1217 - * it as CPU online then. For now, just create the sysfs link, 1218 - * unless there is no policy or the link is already present. 1219 - */ 1220 - policy = per_cpu(cpufreq_cpu_data, cpu); 1221 - return policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus) 1222 - ? add_cpu_dev_symlink(policy, cpu) : 0; 1223 - } 1224 - 1225 - if (!down_read_trylock(&cpufreq_rwsem)) 1226 - return 0; 1256 + pr_debug("%s: bringing CPU%u online\n", __func__, cpu); 1227 1257 1228 1258 /* Check if this CPU already has a policy to manage it */ 1229 1259 policy = per_cpu(cpufreq_cpu_data, cpu); 1230 - if (policy && !policy_is_inactive(policy)) { 1260 + if (policy) { 1231 1261 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); 1232 - ret = cpufreq_add_policy_cpu(policy, cpu, dev); 1233 - up_read(&cpufreq_rwsem); 1234 - return ret; 1235 - } 1262 + if (!policy_is_inactive(policy)) 1263 + return cpufreq_add_policy_cpu(policy, cpu); 1236 1264 1237 - /* 1238 - * Restore the saved policy when doing light-weight init and fall back 1239 - * to the full init if that fails. 1240 - */ 1241 - policy = recover_policy ? cpufreq_policy_restore(cpu) : NULL; 1242 - if (!policy) { 1243 - recover_policy = false; 1244 - policy = cpufreq_policy_alloc(dev); 1265 + /* This is the only online CPU for the policy. Start over. */ 1266 + new_policy = false; 1267 + down_write(&policy->rwsem); 1268 + policy->cpu = cpu; 1269 + policy->governor = NULL; 1270 + up_write(&policy->rwsem); 1271 + } else { 1272 + new_policy = true; 1273 + policy = cpufreq_policy_alloc(cpu); 1245 1274 if (!policy) 1246 - goto nomem_out; 1275 + return -ENOMEM; 1247 1276 } 1248 1277 1249 1278 cpumask_copy(policy->cpus, cpumask_of(cpu)); ··· 1229 1308 ret = cpufreq_driver->init(policy); 1230 1309 if (ret) { 1231 1310 pr_debug("initialization failed\n"); 1232 - goto err_set_policy_cpu; 1311 + goto out_free_policy; 1233 1312 } 1234 1313 1235 1314 down_write(&policy->rwsem); 1236 1315 1237 - /* related cpus should atleast have policy->cpus */ 1238 - cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); 1239 - 1240 - /* Remember which CPUs have been present at the policy creation time. */ 1241 - if (!recover_policy) 1316 + if (new_policy) { 1317 + /* related_cpus should at least include policy->cpus. */ 1318 + cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); 1319 + /* Remember CPUs present at the policy creation time. */ 1242 1320 cpumask_and(policy->real_cpus, policy->cpus, cpu_present_mask); 1321 + } 1243 1322 1244 1323 /* 1245 1324 * affected cpus must always be the one, which are online. We aren't ··· 1247 1326 */ 1248 1327 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); 1249 1328 1250 - if (!recover_policy) { 1329 + if (new_policy) { 1251 1330 policy->user_policy.min = policy->min; 1252 1331 policy->user_policy.max = policy->max; 1253 1332 ··· 1261 1340 policy->cur = cpufreq_driver->get(policy->cpu); 1262 1341 if (!policy->cur) { 1263 1342 pr_err("%s: ->get() failed\n", __func__); 1264 - goto err_get_freq; 1343 + goto out_exit_policy; 1265 1344 } 1266 1345 } 1267 1346 ··· 1308 1387 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1309 1388 CPUFREQ_START, policy); 1310 1389 1311 - if (!recover_policy) { 1312 - ret = cpufreq_add_dev_interface(policy, dev); 1390 + if (new_policy) { 1391 + ret = cpufreq_add_dev_interface(policy); 1313 1392 if (ret) 1314 - goto err_out_unregister; 1393 + goto out_exit_policy; 1315 1394 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1316 1395 CPUFREQ_CREATE_POLICY, policy); 1317 1396 ··· 1320 1399 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1321 1400 } 1322 1401 1323 - cpufreq_init_policy(policy); 1402 + ret = cpufreq_init_policy(policy); 1403 + if (ret) { 1404 + pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n", 1405 + __func__, cpu, ret); 1406 + /* cpufreq_policy_free() will notify based on this */ 1407 + new_policy = false; 1408 + goto out_exit_policy; 1409 + } 1324 1410 1325 - if (!recover_policy) { 1411 + if (new_policy) { 1326 1412 policy->user_policy.policy = policy->policy; 1327 1413 policy->user_policy.governor = policy->governor; 1328 1414 } 1329 1415 up_write(&policy->rwsem); 1330 1416 1331 1417 kobject_uevent(&policy->kobj, KOBJ_ADD); 1332 - 1333 - up_read(&cpufreq_rwsem); 1334 1418 1335 1419 /* Callback for handling stuff after policy is ready */ 1336 1420 if (cpufreq_driver->ready) ··· 1345 1419 1346 1420 return 0; 1347 1421 1348 - err_out_unregister: 1349 - err_get_freq: 1422 + out_exit_policy: 1350 1423 up_write(&policy->rwsem); 1351 1424 1352 1425 if (cpufreq_driver->exit) 1353 1426 cpufreq_driver->exit(policy); 1354 - err_set_policy_cpu: 1355 - cpufreq_policy_free(policy, recover_policy); 1356 - nomem_out: 1357 - up_read(&cpufreq_rwsem); 1427 + out_free_policy: 1428 + cpufreq_policy_free(policy, !new_policy); 1429 + return ret; 1430 + } 1431 + 1432 + /** 1433 + * cpufreq_add_dev - the cpufreq interface for a CPU device. 1434 + * @dev: CPU device. 1435 + * @sif: Subsystem interface structure pointer (not used) 1436 + */ 1437 + static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1438 + { 1439 + unsigned cpu = dev->id; 1440 + int ret; 1441 + 1442 + dev_dbg(dev, "%s: adding CPU%u\n", __func__, cpu); 1443 + 1444 + if (cpu_online(cpu)) { 1445 + ret = cpufreq_online(cpu); 1446 + } else { 1447 + /* 1448 + * A hotplug notifier will follow and we will handle it as CPU 1449 + * online then. For now, just create the sysfs link, unless 1450 + * there is no policy or the link is already present. 1451 + */ 1452 + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1453 + 1454 + ret = policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus) 1455 + ? add_cpu_dev_symlink(policy, cpu) : 0; 1456 + } 1358 1457 1359 1458 return ret; 1360 1459 } 1361 1460 1362 - static int __cpufreq_remove_dev_prepare(struct device *dev) 1461 + static void cpufreq_offline_prepare(unsigned int cpu) 1363 1462 { 1364 - unsigned int cpu = dev->id; 1365 - int ret = 0; 1366 1463 struct cpufreq_policy *policy; 1367 1464 1368 1465 pr_debug("%s: unregistering CPU %u\n", __func__, cpu); ··· 1393 1444 policy = cpufreq_cpu_get_raw(cpu); 1394 1445 if (!policy) { 1395 1446 pr_debug("%s: No cpu_data found\n", __func__); 1396 - return -EINVAL; 1447 + return; 1397 1448 } 1398 1449 1399 1450 if (has_target()) { 1400 - ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 1451 + int ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 1401 1452 if (ret) 1402 1453 pr_err("%s: Failed to stop governor\n", __func__); 1403 1454 } ··· 1418 1469 /* Start governor again for active policy */ 1419 1470 if (!policy_is_inactive(policy)) { 1420 1471 if (has_target()) { 1421 - ret = __cpufreq_governor(policy, CPUFREQ_GOV_START); 1472 + int ret = __cpufreq_governor(policy, CPUFREQ_GOV_START); 1422 1473 if (!ret) 1423 1474 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 1424 1475 ··· 1428 1479 } else if (cpufreq_driver->stop_cpu) { 1429 1480 cpufreq_driver->stop_cpu(policy); 1430 1481 } 1431 - 1432 - return ret; 1433 1482 } 1434 1483 1435 - static int __cpufreq_remove_dev_finish(struct device *dev) 1484 + static void cpufreq_offline_finish(unsigned int cpu) 1436 1485 { 1437 - unsigned int cpu = dev->id; 1438 - int ret; 1439 1486 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1440 1487 1441 1488 if (!policy) { 1442 1489 pr_debug("%s: No cpu_data found\n", __func__); 1443 - return -EINVAL; 1490 + return; 1444 1491 } 1445 1492 1446 1493 /* Only proceed for inactive policies */ 1447 1494 if (!policy_is_inactive(policy)) 1448 - return 0; 1495 + return; 1449 1496 1450 1497 /* If cpu is last user of policy, free policy */ 1451 1498 if (has_target()) { 1452 - ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); 1499 + int ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); 1453 1500 if (ret) 1454 1501 pr_err("%s: Failed to exit governor\n", __func__); 1455 1502 } ··· 1457 1512 */ 1458 1513 if (cpufreq_driver->exit) 1459 1514 cpufreq_driver->exit(policy); 1460 - 1461 - return 0; 1462 1515 } 1463 1516 1464 1517 /** ··· 1473 1530 return 0; 1474 1531 1475 1532 if (cpu_online(cpu)) { 1476 - __cpufreq_remove_dev_prepare(dev); 1477 - __cpufreq_remove_dev_finish(dev); 1533 + cpufreq_offline_prepare(cpu); 1534 + cpufreq_offline_finish(cpu); 1478 1535 } 1479 1536 1480 1537 cpumask_clear_cpu(cpu, policy->real_cpus); ··· 2190 2247 2191 2248 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); 2192 2249 2193 - if (new_policy->min > policy->max || new_policy->max < policy->min) 2250 + /* 2251 + * This check works well when we store new min/max freq attributes, 2252 + * because new_policy is a copy of policy with one field updated. 2253 + */ 2254 + if (new_policy->min > new_policy->max) 2194 2255 return -EINVAL; 2195 2256 2196 2257 /* verify the cpu speed can be set within this limit */ ··· 2243 2296 old_gov = policy->governor; 2244 2297 /* end old governor */ 2245 2298 if (old_gov) { 2246 - __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 2299 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); 2300 + if (ret) { 2301 + /* This can happen due to race with other operations */ 2302 + pr_debug("%s: Failed to Stop Governor: %s (%d)\n", 2303 + __func__, old_gov->name, ret); 2304 + return ret; 2305 + } 2306 + 2247 2307 up_write(&policy->rwsem); 2248 - __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); 2308 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); 2249 2309 down_write(&policy->rwsem); 2310 + 2311 + if (ret) { 2312 + pr_err("%s: Failed to Exit Governor: %s (%d)\n", 2313 + __func__, old_gov->name, ret); 2314 + return ret; 2315 + } 2250 2316 } 2251 2317 2252 2318 /* start new governor */ 2253 2319 policy->governor = new_policy->governor; 2254 - if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) { 2255 - if (!__cpufreq_governor(policy, CPUFREQ_GOV_START)) 2320 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT); 2321 + if (!ret) { 2322 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_START); 2323 + if (!ret) 2256 2324 goto out; 2257 2325 2258 2326 up_write(&policy->rwsem); ··· 2279 2317 pr_debug("starting governor %s failed\n", policy->governor->name); 2280 2318 if (old_gov) { 2281 2319 policy->governor = old_gov; 2282 - __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT); 2283 - __cpufreq_governor(policy, CPUFREQ_GOV_START); 2320 + if (__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) 2321 + policy->governor = NULL; 2322 + else 2323 + __cpufreq_governor(policy, CPUFREQ_GOV_START); 2284 2324 } 2285 2325 2286 - return -EINVAL; 2326 + return ret; 2287 2327 2288 2328 out: 2289 2329 pr_debug("governor: change or update limits\n"); ··· 2351 2387 unsigned long action, void *hcpu) 2352 2388 { 2353 2389 unsigned int cpu = (unsigned long)hcpu; 2354 - struct device *dev; 2355 2390 2356 - dev = get_cpu_device(cpu); 2357 - if (dev) { 2358 - switch (action & ~CPU_TASKS_FROZEN) { 2359 - case CPU_ONLINE: 2360 - cpufreq_add_dev(dev, NULL); 2361 - break; 2391 + switch (action & ~CPU_TASKS_FROZEN) { 2392 + case CPU_ONLINE: 2393 + cpufreq_online(cpu); 2394 + break; 2362 2395 2363 - case CPU_DOWN_PREPARE: 2364 - __cpufreq_remove_dev_prepare(dev); 2365 - break; 2396 + case CPU_DOWN_PREPARE: 2397 + cpufreq_offline_prepare(cpu); 2398 + break; 2366 2399 2367 - case CPU_POST_DEAD: 2368 - __cpufreq_remove_dev_finish(dev); 2369 - break; 2400 + case CPU_POST_DEAD: 2401 + cpufreq_offline_finish(cpu); 2402 + break; 2370 2403 2371 - case CPU_DOWN_FAILED: 2372 - cpufreq_add_dev(dev, NULL); 2373 - break; 2374 - } 2404 + case CPU_DOWN_FAILED: 2405 + cpufreq_online(cpu); 2406 + break; 2375 2407 } 2376 2408 return NOTIFY_OK; 2377 2409 } ··· 2475 2515 2476 2516 pr_debug("trying to register driver %s\n", driver_data->name); 2477 2517 2518 + /* Protect against concurrent CPU online/offline. */ 2519 + get_online_cpus(); 2520 + 2478 2521 write_lock_irqsave(&cpufreq_driver_lock, flags); 2479 2522 if (cpufreq_driver) { 2480 2523 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2481 - return -EEXIST; 2524 + ret = -EEXIST; 2525 + goto out; 2482 2526 } 2483 2527 cpufreq_driver = driver_data; 2484 2528 write_unlock_irqrestore(&cpufreq_driver_lock, flags); ··· 2521 2557 register_hotcpu_notifier(&cpufreq_cpu_notifier); 2522 2558 pr_debug("driver %s up and running\n", driver_data->name); 2523 2559 2524 - return 0; 2560 + out: 2561 + put_online_cpus(); 2562 + return ret; 2563 + 2525 2564 err_if_unreg: 2526 2565 subsys_interface_unregister(&cpufreq_interface); 2527 2566 err_boost_unreg: ··· 2534 2567 write_lock_irqsave(&cpufreq_driver_lock, flags); 2535 2568 cpufreq_driver = NULL; 2536 2569 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2537 - return ret; 2570 + goto out; 2538 2571 } 2539 2572 EXPORT_SYMBOL_GPL(cpufreq_register_driver); 2540 2573 ··· 2555 2588 2556 2589 pr_debug("unregistering driver %s\n", driver->name); 2557 2590 2591 + /* Protect against concurrent cpu hotplug */ 2592 + get_online_cpus(); 2558 2593 subsys_interface_unregister(&cpufreq_interface); 2559 2594 if (cpufreq_boost_supported()) 2560 2595 cpufreq_sysfs_remove_file(&boost.attr); 2561 2596 2562 2597 unregister_hotcpu_notifier(&cpufreq_cpu_notifier); 2563 2598 2564 - down_write(&cpufreq_rwsem); 2565 2599 write_lock_irqsave(&cpufreq_driver_lock, flags); 2566 2600 2567 2601 cpufreq_driver = NULL; 2568 2602 2569 2603 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2570 - up_write(&cpufreq_rwsem); 2604 + put_online_cpus(); 2571 2605 2572 2606 return 0; 2573 2607 }
+7 -18
drivers/cpufreq/cpufreq_conservative.c
··· 47 47 static void cs_check_cpu(int cpu, unsigned int load) 48 48 { 49 49 struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu); 50 - struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy; 50 + struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; 51 51 struct dbs_data *dbs_data = policy->governor_data; 52 52 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; 53 53 ··· 102 102 } 103 103 } 104 104 105 - static void cs_dbs_timer(struct work_struct *work) 105 + static unsigned int cs_dbs_timer(struct cpu_dbs_info *cdbs, 106 + struct dbs_data *dbs_data, bool modify_all) 106 107 { 107 - struct cs_cpu_dbs_info_s *dbs_info = container_of(work, 108 - struct cs_cpu_dbs_info_s, cdbs.work.work); 109 - unsigned int cpu = dbs_info->cdbs.cur_policy->cpu; 110 - struct cs_cpu_dbs_info_s *core_dbs_info = &per_cpu(cs_cpu_dbs_info, 111 - cpu); 112 - struct dbs_data *dbs_data = dbs_info->cdbs.cur_policy->governor_data; 113 108 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; 114 - int delay = delay_for_sampling_rate(cs_tuners->sampling_rate); 115 - bool modify_all = true; 116 109 117 - mutex_lock(&core_dbs_info->cdbs.timer_mutex); 118 - if (!need_load_eval(&core_dbs_info->cdbs, cs_tuners->sampling_rate)) 119 - modify_all = false; 120 - else 121 - dbs_check_cpu(dbs_data, cpu); 110 + if (modify_all) 111 + dbs_check_cpu(dbs_data, cdbs->shared->policy->cpu); 122 112 123 - gov_queue_work(dbs_data, dbs_info->cdbs.cur_policy, delay, modify_all); 124 - mutex_unlock(&core_dbs_info->cdbs.timer_mutex); 113 + return delay_for_sampling_rate(cs_tuners->sampling_rate); 125 114 } 126 115 127 116 static int dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val, ··· 124 135 if (!dbs_info->enable) 125 136 return 0; 126 137 127 - policy = dbs_info->cdbs.cur_policy; 138 + policy = dbs_info->cdbs.shared->policy; 128 139 129 140 /* 130 141 * we only care if our internally tracked freq moves outside the 'valid'
+146 -50
drivers/cpufreq/cpufreq_governor.c
··· 32 32 33 33 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu) 34 34 { 35 - struct cpu_dbs_common_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu); 35 + struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu); 36 36 struct od_dbs_tuners *od_tuners = dbs_data->tuners; 37 37 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; 38 - struct cpufreq_policy *policy; 38 + struct cpufreq_policy *policy = cdbs->shared->policy; 39 39 unsigned int sampling_rate; 40 40 unsigned int max_load = 0; 41 41 unsigned int ignore_nice; ··· 60 60 ignore_nice = cs_tuners->ignore_nice_load; 61 61 } 62 62 63 - policy = cdbs->cur_policy; 64 - 65 63 /* Get Absolute Load */ 66 64 for_each_cpu(j, policy->cpus) { 67 - struct cpu_dbs_common_info *j_cdbs; 65 + struct cpu_dbs_info *j_cdbs; 68 66 u64 cur_wall_time, cur_idle_time; 69 67 unsigned int idle_time, wall_time; 70 68 unsigned int load; ··· 161 163 static inline void __gov_queue_work(int cpu, struct dbs_data *dbs_data, 162 164 unsigned int delay) 163 165 { 164 - struct cpu_dbs_common_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu); 166 + struct cpu_dbs_info *cdbs = dbs_data->cdata->get_cpu_cdbs(cpu); 165 167 166 - mod_delayed_work_on(cpu, system_wq, &cdbs->work, delay); 168 + mod_delayed_work_on(cpu, system_wq, &cdbs->dwork, delay); 167 169 } 168 170 169 171 void gov_queue_work(struct dbs_data *dbs_data, struct cpufreq_policy *policy, ··· 197 199 static inline void gov_cancel_work(struct dbs_data *dbs_data, 198 200 struct cpufreq_policy *policy) 199 201 { 200 - struct cpu_dbs_common_info *cdbs; 202 + struct cpu_dbs_info *cdbs; 201 203 int i; 202 204 203 205 for_each_cpu(i, policy->cpus) { 204 206 cdbs = dbs_data->cdata->get_cpu_cdbs(i); 205 - cancel_delayed_work_sync(&cdbs->work); 207 + cancel_delayed_work_sync(&cdbs->dwork); 206 208 } 207 209 } 208 210 209 211 /* Will return if we need to evaluate cpu load again or not */ 210 - bool need_load_eval(struct cpu_dbs_common_info *cdbs, 211 - unsigned int sampling_rate) 212 + static bool need_load_eval(struct cpu_common_dbs_info *shared, 213 + unsigned int sampling_rate) 212 214 { 213 - if (policy_is_shared(cdbs->cur_policy)) { 215 + if (policy_is_shared(shared->policy)) { 214 216 ktime_t time_now = ktime_get(); 215 - s64 delta_us = ktime_us_delta(time_now, cdbs->time_stamp); 217 + s64 delta_us = ktime_us_delta(time_now, shared->time_stamp); 216 218 217 219 /* Do nothing if we recently have sampled */ 218 220 if (delta_us < (s64)(sampling_rate / 2)) 219 221 return false; 220 222 else 221 - cdbs->time_stamp = time_now; 223 + shared->time_stamp = time_now; 222 224 } 223 225 224 226 return true; 225 227 } 226 - EXPORT_SYMBOL_GPL(need_load_eval); 228 + 229 + static void dbs_timer(struct work_struct *work) 230 + { 231 + struct cpu_dbs_info *cdbs = container_of(work, struct cpu_dbs_info, 232 + dwork.work); 233 + struct cpu_common_dbs_info *shared = cdbs->shared; 234 + struct cpufreq_policy *policy = shared->policy; 235 + struct dbs_data *dbs_data = policy->governor_data; 236 + unsigned int sampling_rate, delay; 237 + bool modify_all = true; 238 + 239 + mutex_lock(&shared->timer_mutex); 240 + 241 + if (dbs_data->cdata->governor == GOV_CONSERVATIVE) { 242 + struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; 243 + 244 + sampling_rate = cs_tuners->sampling_rate; 245 + } else { 246 + struct od_dbs_tuners *od_tuners = dbs_data->tuners; 247 + 248 + sampling_rate = od_tuners->sampling_rate; 249 + } 250 + 251 + if (!need_load_eval(cdbs->shared, sampling_rate)) 252 + modify_all = false; 253 + 254 + delay = dbs_data->cdata->gov_dbs_timer(cdbs, dbs_data, modify_all); 255 + gov_queue_work(dbs_data, policy, delay, modify_all); 256 + 257 + mutex_unlock(&shared->timer_mutex); 258 + } 227 259 228 260 static void set_sampling_rate(struct dbs_data *dbs_data, 229 261 unsigned int sampling_rate) ··· 267 239 } 268 240 } 269 241 242 + static int alloc_common_dbs_info(struct cpufreq_policy *policy, 243 + struct common_dbs_data *cdata) 244 + { 245 + struct cpu_common_dbs_info *shared; 246 + int j; 247 + 248 + /* Allocate memory for the common information for policy->cpus */ 249 + shared = kzalloc(sizeof(*shared), GFP_KERNEL); 250 + if (!shared) 251 + return -ENOMEM; 252 + 253 + /* Set shared for all CPUs, online+offline */ 254 + for_each_cpu(j, policy->related_cpus) 255 + cdata->get_cpu_cdbs(j)->shared = shared; 256 + 257 + return 0; 258 + } 259 + 260 + static void free_common_dbs_info(struct cpufreq_policy *policy, 261 + struct common_dbs_data *cdata) 262 + { 263 + struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu); 264 + struct cpu_common_dbs_info *shared = cdbs->shared; 265 + int j; 266 + 267 + for_each_cpu(j, policy->cpus) 268 + cdata->get_cpu_cdbs(j)->shared = NULL; 269 + 270 + kfree(shared); 271 + } 272 + 270 273 static int cpufreq_governor_init(struct cpufreq_policy *policy, 271 274 struct dbs_data *dbs_data, 272 275 struct common_dbs_data *cdata) ··· 305 246 unsigned int latency; 306 247 int ret; 307 248 249 + /* State should be equivalent to EXIT */ 250 + if (policy->governor_data) 251 + return -EBUSY; 252 + 308 253 if (dbs_data) { 309 254 if (WARN_ON(have_governor_per_policy())) 310 255 return -EINVAL; 256 + 257 + ret = alloc_common_dbs_info(policy, cdata); 258 + if (ret) 259 + return ret; 260 + 311 261 dbs_data->usage_count++; 312 262 policy->governor_data = dbs_data; 313 263 return 0; ··· 326 258 if (!dbs_data) 327 259 return -ENOMEM; 328 260 261 + ret = alloc_common_dbs_info(policy, cdata); 262 + if (ret) 263 + goto free_dbs_data; 264 + 329 265 dbs_data->cdata = cdata; 330 266 dbs_data->usage_count = 1; 331 267 332 268 ret = cdata->init(dbs_data, !policy->governor->initialized); 333 269 if (ret) 334 - goto free_dbs_data; 270 + goto free_common_dbs_info; 335 271 336 272 /* policy latency is in ns. Convert it to us first */ 337 273 latency = policy->cpuinfo.transition_latency / 1000; ··· 372 300 } 373 301 cdata_exit: 374 302 cdata->exit(dbs_data, !policy->governor->initialized); 303 + free_common_dbs_info: 304 + free_common_dbs_info(policy, cdata); 375 305 free_dbs_data: 376 306 kfree(dbs_data); 377 307 return ret; 378 308 } 379 309 380 - static void cpufreq_governor_exit(struct cpufreq_policy *policy, 381 - struct dbs_data *dbs_data) 310 + static int cpufreq_governor_exit(struct cpufreq_policy *policy, 311 + struct dbs_data *dbs_data) 382 312 { 383 313 struct common_dbs_data *cdata = dbs_data->cdata; 314 + struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(policy->cpu); 315 + 316 + /* State should be equivalent to INIT */ 317 + if (!cdbs->shared || cdbs->shared->policy) 318 + return -EBUSY; 384 319 385 320 policy->governor_data = NULL; 386 321 if (!--dbs_data->usage_count) { ··· 402 323 cdata->exit(dbs_data, policy->governor->initialized == 1); 403 324 kfree(dbs_data); 404 325 } 326 + 327 + free_common_dbs_info(policy, cdata); 328 + return 0; 405 329 } 406 330 407 331 static int cpufreq_governor_start(struct cpufreq_policy *policy, ··· 412 330 { 413 331 struct common_dbs_data *cdata = dbs_data->cdata; 414 332 unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu; 415 - struct cpu_dbs_common_info *cpu_cdbs = cdata->get_cpu_cdbs(cpu); 333 + struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu); 334 + struct cpu_common_dbs_info *shared = cdbs->shared; 416 335 int io_busy = 0; 417 336 418 337 if (!policy->cur) 419 338 return -EINVAL; 339 + 340 + /* State should be equivalent to INIT */ 341 + if (!shared || shared->policy) 342 + return -EBUSY; 420 343 421 344 if (cdata->governor == GOV_CONSERVATIVE) { 422 345 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; ··· 436 349 io_busy = od_tuners->io_is_busy; 437 350 } 438 351 352 + shared->policy = policy; 353 + shared->time_stamp = ktime_get(); 354 + mutex_init(&shared->timer_mutex); 355 + 439 356 for_each_cpu(j, policy->cpus) { 440 - struct cpu_dbs_common_info *j_cdbs = cdata->get_cpu_cdbs(j); 357 + struct cpu_dbs_info *j_cdbs = cdata->get_cpu_cdbs(j); 441 358 unsigned int prev_load; 442 359 443 - j_cdbs->cpu = j; 444 - j_cdbs->cur_policy = policy; 445 360 j_cdbs->prev_cpu_idle = 446 361 get_cpu_idle_time(j, &j_cdbs->prev_cpu_wall, io_busy); 447 362 ··· 455 366 if (ignore_nice) 456 367 j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; 457 368 458 - mutex_init(&j_cdbs->timer_mutex); 459 - INIT_DEFERRABLE_WORK(&j_cdbs->work, cdata->gov_dbs_timer); 369 + INIT_DEFERRABLE_WORK(&j_cdbs->dwork, dbs_timer); 460 370 } 461 371 462 372 if (cdata->governor == GOV_CONSERVATIVE) { ··· 474 386 od_ops->powersave_bias_init_cpu(cpu); 475 387 } 476 388 477 - /* Initiate timer time stamp */ 478 - cpu_cdbs->time_stamp = ktime_get(); 479 - 480 389 gov_queue_work(dbs_data, policy, delay_for_sampling_rate(sampling_rate), 481 390 true); 482 391 return 0; 483 392 } 484 393 485 - static void cpufreq_governor_stop(struct cpufreq_policy *policy, 486 - struct dbs_data *dbs_data) 394 + static int cpufreq_governor_stop(struct cpufreq_policy *policy, 395 + struct dbs_data *dbs_data) 487 396 { 488 397 struct common_dbs_data *cdata = dbs_data->cdata; 489 398 unsigned int cpu = policy->cpu; 490 - struct cpu_dbs_common_info *cpu_cdbs = cdata->get_cpu_cdbs(cpu); 399 + struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu); 400 + struct cpu_common_dbs_info *shared = cdbs->shared; 401 + 402 + /* State should be equivalent to START */ 403 + if (!shared || !shared->policy) 404 + return -EBUSY; 405 + 406 + gov_cancel_work(dbs_data, policy); 491 407 492 408 if (cdata->governor == GOV_CONSERVATIVE) { 493 409 struct cs_cpu_dbs_info_s *cs_dbs_info = ··· 500 408 cs_dbs_info->enable = 0; 501 409 } 502 410 503 - gov_cancel_work(dbs_data, policy); 504 - 505 - mutex_destroy(&cpu_cdbs->timer_mutex); 506 - cpu_cdbs->cur_policy = NULL; 411 + shared->policy = NULL; 412 + mutex_destroy(&shared->timer_mutex); 413 + return 0; 507 414 } 508 415 509 - static void cpufreq_governor_limits(struct cpufreq_policy *policy, 510 - struct dbs_data *dbs_data) 416 + static int cpufreq_governor_limits(struct cpufreq_policy *policy, 417 + struct dbs_data *dbs_data) 511 418 { 512 419 struct common_dbs_data *cdata = dbs_data->cdata; 513 420 unsigned int cpu = policy->cpu; 514 - struct cpu_dbs_common_info *cpu_cdbs = cdata->get_cpu_cdbs(cpu); 421 + struct cpu_dbs_info *cdbs = cdata->get_cpu_cdbs(cpu); 515 422 516 - if (!cpu_cdbs->cur_policy) 517 - return; 423 + /* State should be equivalent to START */ 424 + if (!cdbs->shared || !cdbs->shared->policy) 425 + return -EBUSY; 518 426 519 - mutex_lock(&cpu_cdbs->timer_mutex); 520 - if (policy->max < cpu_cdbs->cur_policy->cur) 521 - __cpufreq_driver_target(cpu_cdbs->cur_policy, policy->max, 427 + mutex_lock(&cdbs->shared->timer_mutex); 428 + if (policy->max < cdbs->shared->policy->cur) 429 + __cpufreq_driver_target(cdbs->shared->policy, policy->max, 522 430 CPUFREQ_RELATION_H); 523 - else if (policy->min > cpu_cdbs->cur_policy->cur) 524 - __cpufreq_driver_target(cpu_cdbs->cur_policy, policy->min, 431 + else if (policy->min > cdbs->shared->policy->cur) 432 + __cpufreq_driver_target(cdbs->shared->policy, policy->min, 525 433 CPUFREQ_RELATION_L); 526 434 dbs_check_cpu(dbs_data, cpu); 527 - mutex_unlock(&cpu_cdbs->timer_mutex); 435 + mutex_unlock(&cdbs->shared->timer_mutex); 436 + 437 + return 0; 528 438 } 529 439 530 440 int cpufreq_governor_dbs(struct cpufreq_policy *policy, 531 441 struct common_dbs_data *cdata, unsigned int event) 532 442 { 533 443 struct dbs_data *dbs_data; 534 - int ret = 0; 444 + int ret; 535 445 536 446 /* Lock governor to block concurrent initialization of governor */ 537 447 mutex_lock(&cdata->mutex); ··· 543 449 else 544 450 dbs_data = cdata->gdbs_data; 545 451 546 - if (WARN_ON(!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT))) { 452 + if (!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)) { 547 453 ret = -EINVAL; 548 454 goto unlock; 549 455 } ··· 553 459 ret = cpufreq_governor_init(policy, dbs_data, cdata); 554 460 break; 555 461 case CPUFREQ_GOV_POLICY_EXIT: 556 - cpufreq_governor_exit(policy, dbs_data); 462 + ret = cpufreq_governor_exit(policy, dbs_data); 557 463 break; 558 464 case CPUFREQ_GOV_START: 559 465 ret = cpufreq_governor_start(policy, dbs_data); 560 466 break; 561 467 case CPUFREQ_GOV_STOP: 562 - cpufreq_governor_stop(policy, dbs_data); 468 + ret = cpufreq_governor_stop(policy, dbs_data); 563 469 break; 564 470 case CPUFREQ_GOV_LIMITS: 565 - cpufreq_governor_limits(policy, dbs_data); 471 + ret = cpufreq_governor_limits(policy, dbs_data); 566 472 break; 473 + default: 474 + ret = -EINVAL; 567 475 } 568 476 569 477 unlock:
+22 -18
drivers/cpufreq/cpufreq_governor.h
··· 109 109 110 110 /* create helper routines */ 111 111 #define define_get_cpu_dbs_routines(_dbs_info) \ 112 - static struct cpu_dbs_common_info *get_cpu_cdbs(int cpu) \ 112 + static struct cpu_dbs_info *get_cpu_cdbs(int cpu) \ 113 113 { \ 114 114 return &per_cpu(_dbs_info, cpu).cdbs; \ 115 115 } \ ··· 128 128 * cs_*: Conservative governor 129 129 */ 130 130 131 + /* Common to all CPUs of a policy */ 132 + struct cpu_common_dbs_info { 133 + struct cpufreq_policy *policy; 134 + /* 135 + * percpu mutex that serializes governor limit change with dbs_timer 136 + * invocation. We do not want dbs_timer to run when user is changing 137 + * the governor or limits. 138 + */ 139 + struct mutex timer_mutex; 140 + ktime_t time_stamp; 141 + }; 142 + 131 143 /* Per cpu structures */ 132 - struct cpu_dbs_common_info { 133 - int cpu; 144 + struct cpu_dbs_info { 134 145 u64 prev_cpu_idle; 135 146 u64 prev_cpu_wall; 136 147 u64 prev_cpu_nice; ··· 152 141 * wake-up from idle. 153 142 */ 154 143 unsigned int prev_load; 155 - struct cpufreq_policy *cur_policy; 156 - struct delayed_work work; 157 - /* 158 - * percpu mutex that serializes governor limit change with gov_dbs_timer 159 - * invocation. We do not want gov_dbs_timer to run when user is changing 160 - * the governor or limits. 161 - */ 162 - struct mutex timer_mutex; 163 - ktime_t time_stamp; 144 + struct delayed_work dwork; 145 + struct cpu_common_dbs_info *shared; 164 146 }; 165 147 166 148 struct od_cpu_dbs_info_s { 167 - struct cpu_dbs_common_info cdbs; 149 + struct cpu_dbs_info cdbs; 168 150 struct cpufreq_frequency_table *freq_table; 169 151 unsigned int freq_lo; 170 152 unsigned int freq_lo_jiffies; ··· 167 163 }; 168 164 169 165 struct cs_cpu_dbs_info_s { 170 - struct cpu_dbs_common_info cdbs; 166 + struct cpu_dbs_info cdbs; 171 167 unsigned int down_skip; 172 168 unsigned int requested_freq; 173 169 unsigned int enable:1; ··· 208 204 */ 209 205 struct dbs_data *gdbs_data; 210 206 211 - struct cpu_dbs_common_info *(*get_cpu_cdbs)(int cpu); 207 + struct cpu_dbs_info *(*get_cpu_cdbs)(int cpu); 212 208 void *(*get_cpu_dbs_info_s)(int cpu); 213 - void (*gov_dbs_timer)(struct work_struct *work); 209 + unsigned int (*gov_dbs_timer)(struct cpu_dbs_info *cdbs, 210 + struct dbs_data *dbs_data, 211 + bool modify_all); 214 212 void (*gov_check_cpu)(int cpu, unsigned int load); 215 213 int (*init)(struct dbs_data *dbs_data, bool notify); 216 214 void (*exit)(struct dbs_data *dbs_data, bool notify); ··· 271 265 extern struct mutex cpufreq_governor_lock; 272 266 273 267 void dbs_check_cpu(struct dbs_data *dbs_data, int cpu); 274 - bool need_load_eval(struct cpu_dbs_common_info *cdbs, 275 - unsigned int sampling_rate); 276 268 int cpufreq_governor_dbs(struct cpufreq_policy *policy, 277 269 struct common_dbs_data *cdata, unsigned int event); 278 270 void gov_queue_work(struct dbs_data *dbs_data, struct cpufreq_policy *policy,
+32 -35
drivers/cpufreq/cpufreq_ondemand.c
··· 155 155 static void od_check_cpu(int cpu, unsigned int load) 156 156 { 157 157 struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu); 158 - struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy; 158 + struct cpufreq_policy *policy = dbs_info->cdbs.shared->policy; 159 159 struct dbs_data *dbs_data = policy->governor_data; 160 160 struct od_dbs_tuners *od_tuners = dbs_data->tuners; 161 161 ··· 191 191 } 192 192 } 193 193 194 - static void od_dbs_timer(struct work_struct *work) 194 + static unsigned int od_dbs_timer(struct cpu_dbs_info *cdbs, 195 + struct dbs_data *dbs_data, bool modify_all) 195 196 { 196 - struct od_cpu_dbs_info_s *dbs_info = 197 - container_of(work, struct od_cpu_dbs_info_s, cdbs.work.work); 198 - unsigned int cpu = dbs_info->cdbs.cur_policy->cpu; 199 - struct od_cpu_dbs_info_s *core_dbs_info = &per_cpu(od_cpu_dbs_info, 197 + struct cpufreq_policy *policy = cdbs->shared->policy; 198 + unsigned int cpu = policy->cpu; 199 + struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, 200 200 cpu); 201 - struct dbs_data *dbs_data = dbs_info->cdbs.cur_policy->governor_data; 202 201 struct od_dbs_tuners *od_tuners = dbs_data->tuners; 203 - int delay = 0, sample_type = core_dbs_info->sample_type; 204 - bool modify_all = true; 202 + int delay = 0, sample_type = dbs_info->sample_type; 205 203 206 - mutex_lock(&core_dbs_info->cdbs.timer_mutex); 207 - if (!need_load_eval(&core_dbs_info->cdbs, od_tuners->sampling_rate)) { 208 - modify_all = false; 204 + if (!modify_all) 209 205 goto max_delay; 210 - } 211 206 212 207 /* Common NORMAL_SAMPLE setup */ 213 - core_dbs_info->sample_type = OD_NORMAL_SAMPLE; 208 + dbs_info->sample_type = OD_NORMAL_SAMPLE; 214 209 if (sample_type == OD_SUB_SAMPLE) { 215 - delay = core_dbs_info->freq_lo_jiffies; 216 - __cpufreq_driver_target(core_dbs_info->cdbs.cur_policy, 217 - core_dbs_info->freq_lo, CPUFREQ_RELATION_H); 210 + delay = dbs_info->freq_lo_jiffies; 211 + __cpufreq_driver_target(policy, dbs_info->freq_lo, 212 + CPUFREQ_RELATION_H); 218 213 } else { 219 214 dbs_check_cpu(dbs_data, cpu); 220 - if (core_dbs_info->freq_lo) { 215 + if (dbs_info->freq_lo) { 221 216 /* Setup timer for SUB_SAMPLE */ 222 - core_dbs_info->sample_type = OD_SUB_SAMPLE; 223 - delay = core_dbs_info->freq_hi_jiffies; 217 + dbs_info->sample_type = OD_SUB_SAMPLE; 218 + delay = dbs_info->freq_hi_jiffies; 224 219 } 225 220 } 226 221 227 222 max_delay: 228 223 if (!delay) 229 224 delay = delay_for_sampling_rate(od_tuners->sampling_rate 230 - * core_dbs_info->rate_mult); 225 + * dbs_info->rate_mult); 231 226 232 - gov_queue_work(dbs_data, dbs_info->cdbs.cur_policy, delay, modify_all); 233 - mutex_unlock(&core_dbs_info->cdbs.timer_mutex); 227 + return delay; 234 228 } 235 229 236 230 /************************** sysfs interface ************************/ ··· 267 273 dbs_info = &per_cpu(od_cpu_dbs_info, cpu); 268 274 cpufreq_cpu_put(policy); 269 275 270 - mutex_lock(&dbs_info->cdbs.timer_mutex); 276 + mutex_lock(&dbs_info->cdbs.shared->timer_mutex); 271 277 272 - if (!delayed_work_pending(&dbs_info->cdbs.work)) { 273 - mutex_unlock(&dbs_info->cdbs.timer_mutex); 278 + if (!delayed_work_pending(&dbs_info->cdbs.dwork)) { 279 + mutex_unlock(&dbs_info->cdbs.shared->timer_mutex); 274 280 continue; 275 281 } 276 282 277 283 next_sampling = jiffies + usecs_to_jiffies(new_rate); 278 - appointed_at = dbs_info->cdbs.work.timer.expires; 284 + appointed_at = dbs_info->cdbs.dwork.timer.expires; 279 285 280 286 if (time_before(next_sampling, appointed_at)) { 281 287 282 - mutex_unlock(&dbs_info->cdbs.timer_mutex); 283 - cancel_delayed_work_sync(&dbs_info->cdbs.work); 284 - mutex_lock(&dbs_info->cdbs.timer_mutex); 288 + mutex_unlock(&dbs_info->cdbs.shared->timer_mutex); 289 + cancel_delayed_work_sync(&dbs_info->cdbs.dwork); 290 + mutex_lock(&dbs_info->cdbs.shared->timer_mutex); 285 291 286 - gov_queue_work(dbs_data, dbs_info->cdbs.cur_policy, 287 - usecs_to_jiffies(new_rate), true); 292 + gov_queue_work(dbs_data, policy, 293 + usecs_to_jiffies(new_rate), true); 288 294 289 295 } 290 - mutex_unlock(&dbs_info->cdbs.timer_mutex); 296 + mutex_unlock(&dbs_info->cdbs.shared->timer_mutex); 291 297 } 292 298 } 293 299 ··· 550 556 551 557 get_online_cpus(); 552 558 for_each_online_cpu(cpu) { 559 + struct cpu_common_dbs_info *shared; 560 + 553 561 if (cpumask_test_cpu(cpu, &done)) 554 562 continue; 555 563 556 - policy = per_cpu(od_cpu_dbs_info, cpu).cdbs.cur_policy; 557 - if (!policy) 564 + shared = per_cpu(od_cpu_dbs_info, cpu).cdbs.shared; 565 + if (!shared) 558 566 continue; 559 567 568 + policy = shared->policy; 560 569 cpumask_or(&done, &done, policy->cpus); 561 570 562 571 if (policy->governor != &cpufreq_gov_ondemand)
+1 -1
drivers/cpufreq/e_powersaver.c
··· 78 78 static int eps_acpi_exit(struct cpufreq_policy *policy) 79 79 { 80 80 if (eps_acpi_cpu_perf) { 81 - acpi_processor_unregister_performance(eps_acpi_cpu_perf, 0); 81 + acpi_processor_unregister_performance(0); 82 82 free_cpumask_var(eps_acpi_cpu_perf->shared_cpu_map); 83 83 kfree(eps_acpi_cpu_perf); 84 84 eps_acpi_cpu_perf = NULL;
+10 -10
drivers/cpufreq/ia64-acpi-cpufreq.c
··· 29 29 30 30 struct cpufreq_acpi_io { 31 31 struct acpi_processor_performance acpi_data; 32 - struct cpufreq_frequency_table *freq_table; 33 32 unsigned int resume; 34 33 }; 35 34 ··· 220 221 unsigned int cpu = policy->cpu; 221 222 struct cpufreq_acpi_io *data; 222 223 unsigned int result = 0; 224 + struct cpufreq_frequency_table *freq_table; 223 225 224 226 pr_debug("acpi_cpufreq_cpu_init\n"); 225 227 ··· 254 254 } 255 255 256 256 /* alloc freq_table */ 257 - data->freq_table = kzalloc(sizeof(*data->freq_table) * 257 + freq_table = kzalloc(sizeof(*freq_table) * 258 258 (data->acpi_data.state_count + 1), 259 259 GFP_KERNEL); 260 - if (!data->freq_table) { 260 + if (!freq_table) { 261 261 result = -ENOMEM; 262 262 goto err_unreg; 263 263 } ··· 276 276 for (i = 0; i <= data->acpi_data.state_count; i++) 277 277 { 278 278 if (i < data->acpi_data.state_count) { 279 - data->freq_table[i].frequency = 279 + freq_table[i].frequency = 280 280 data->acpi_data.states[i].core_frequency * 1000; 281 281 } else { 282 - data->freq_table[i].frequency = CPUFREQ_TABLE_END; 282 + freq_table[i].frequency = CPUFREQ_TABLE_END; 283 283 } 284 284 } 285 285 286 - result = cpufreq_table_validate_and_show(policy, data->freq_table); 286 + result = cpufreq_table_validate_and_show(policy, freq_table); 287 287 if (result) { 288 288 goto err_freqfree; 289 289 } ··· 311 311 return (result); 312 312 313 313 err_freqfree: 314 - kfree(data->freq_table); 314 + kfree(freq_table); 315 315 err_unreg: 316 - acpi_processor_unregister_performance(&data->acpi_data, cpu); 316 + acpi_processor_unregister_performance(cpu); 317 317 err_free: 318 318 kfree(data); 319 319 acpi_io_data[cpu] = NULL; ··· 332 332 333 333 if (data) { 334 334 acpi_io_data[policy->cpu] = NULL; 335 - acpi_processor_unregister_performance(&data->acpi_data, 336 - policy->cpu); 335 + acpi_processor_unregister_performance(policy->cpu); 336 + kfree(policy->freq_table); 337 337 kfree(data); 338 338 } 339 339
+8 -10
drivers/cpufreq/integrator-cpufreq.c
··· 98 98 /* get current setting */ 99 99 cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET); 100 100 101 - if (machine_is_integrator()) { 101 + if (machine_is_integrator()) 102 102 vco.s = (cm_osc >> 8) & 7; 103 - } else if (machine_is_cintegrator()) { 103 + else if (machine_is_cintegrator()) 104 104 vco.s = 1; 105 - } 106 105 vco.v = cm_osc & 255; 107 106 vco.r = 22; 108 107 freqs.old = icst_hz(&cclk_params, vco) / 1000; ··· 162 163 /* detect memory etc. */ 163 164 cm_osc = __raw_readl(cm_base + INTEGRATOR_HDR_OSC_OFFSET); 164 165 165 - if (machine_is_integrator()) { 166 + if (machine_is_integrator()) 166 167 vco.s = (cm_osc >> 8) & 7; 167 - } else { 168 + else 168 169 vco.s = 1; 169 - } 170 170 vco.v = cm_osc & 255; 171 171 vco.r = 22; 172 172 ··· 201 203 struct resource *res; 202 204 203 205 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 204 - if (!res) 206 + if (!res) 205 207 return -ENODEV; 206 208 207 209 cm_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); ··· 232 234 module_platform_driver_probe(integrator_cpufreq_driver, 233 235 integrator_cpufreq_probe); 234 236 235 - MODULE_AUTHOR ("Russell M. King"); 236 - MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs"); 237 - MODULE_LICENSE ("GPL"); 237 + MODULE_AUTHOR("Russell M. King"); 238 + MODULE_DESCRIPTION("cpufreq driver for ARM Integrator CPUs"); 239 + MODULE_LICENSE("GPL");
+9 -6
drivers/cpufreq/intel_pstate.c
··· 484 484 } 485 485 /************************** sysfs end ************************/ 486 486 487 - static void intel_pstate_hwp_enable(void) 487 + static void intel_pstate_hwp_enable(struct cpudata *cpudata) 488 488 { 489 - hwp_active++; 490 489 pr_info("intel_pstate: HWP enabled\n"); 491 490 492 - wrmsrl( MSR_PM_ENABLE, 0x1); 491 + wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); 493 492 } 494 493 495 494 static int byt_get_min_pstate(void) ··· 521 522 int32_t vid_fp; 522 523 u32 vid; 523 524 524 - val = pstate << 8; 525 + val = (u64)pstate << 8; 525 526 if (limits.no_turbo && !limits.turbo_disabled) 526 527 val |= (u64)1 << 32; 527 528 ··· 610 611 { 611 612 u64 val; 612 613 613 - val = pstate << 8; 614 + val = (u64)pstate << 8; 614 615 if (limits.no_turbo && !limits.turbo_disabled) 615 616 val |= (u64)1 << 32; 616 617 ··· 932 933 cpu = all_cpu_data[cpunum]; 933 934 934 935 cpu->cpu = cpunum; 936 + 937 + if (hwp_active) 938 + intel_pstate_hwp_enable(cpu); 939 + 935 940 intel_pstate_get_cpu_pstates(cpu); 936 941 937 942 init_timer_deferrable(&cpu->timer); ··· 1249 1246 return -ENOMEM; 1250 1247 1251 1248 if (static_cpu_has_safe(X86_FEATURE_HWP) && !no_hwp) 1252 - intel_pstate_hwp_enable(); 1249 + hwp_active++; 1253 1250 1254 1251 if (!hwp_active && hwp_only) 1255 1252 goto out;
+2 -2
drivers/cpufreq/powernow-k7.c
··· 421 421 return 0; 422 422 423 423 err2: 424 - acpi_processor_unregister_performance(acpi_processor_perf, 0); 424 + acpi_processor_unregister_performance(0); 425 425 err1: 426 426 free_cpumask_var(acpi_processor_perf->shared_cpu_map); 427 427 err05: ··· 661 661 { 662 662 #ifdef CONFIG_X86_POWERNOW_K7_ACPI 663 663 if (acpi_processor_perf) { 664 - acpi_processor_unregister_performance(acpi_processor_perf, 0); 664 + acpi_processor_unregister_performance(0); 665 665 free_cpumask_var(acpi_processor_perf->shared_cpu_map); 666 666 kfree(acpi_processor_perf); 667 667 }
+2 -3
drivers/cpufreq/powernow-k8.c
··· 795 795 kfree(powernow_table); 796 796 797 797 err_out: 798 - acpi_processor_unregister_performance(&data->acpi_data, data->cpu); 798 + acpi_processor_unregister_performance(data->cpu); 799 799 800 800 /* data->acpi_data.state_count informs us at ->exit() 801 801 * whether ACPI was used */ ··· 863 863 static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) 864 864 { 865 865 if (data->acpi_data.state_count) 866 - acpi_processor_unregister_performance(&data->acpi_data, 867 - data->cpu); 866 + acpi_processor_unregister_performance(data->cpu); 868 867 free_cpumask_var(data->acpi_data.shared_cpu_map); 869 868 } 870 869
+183 -15
drivers/cpufreq/powernv-cpufreq.c
··· 27 27 #include <linux/smp.h> 28 28 #include <linux/of.h> 29 29 #include <linux/reboot.h> 30 + #include <linux/slab.h> 30 31 31 32 #include <asm/cputhreads.h> 32 33 #include <asm/firmware.h> 33 34 #include <asm/reg.h> 34 35 #include <asm/smp.h> /* Required for cpu_sibling_mask() in UP configs */ 36 + #include <asm/opal.h> 35 37 36 38 #define POWERNV_MAX_PSTATES 256 37 39 #define PMSR_PSAFE_ENABLE (1UL << 30) 38 40 #define PMSR_SPR_EM_DISABLE (1UL << 31) 39 41 #define PMSR_MAX(x) ((x >> 32) & 0xFF) 40 - #define PMSR_LP(x) ((x >> 48) & 0xFF) 41 42 42 43 static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1]; 43 - static bool rebooting, throttled; 44 + static bool rebooting, throttled, occ_reset; 45 + 46 + static struct chip { 47 + unsigned int id; 48 + bool throttled; 49 + cpumask_t mask; 50 + struct work_struct throttle; 51 + bool restore; 52 + } *chips; 53 + 54 + static int nr_chips; 44 55 45 56 /* 46 57 * Note: The set of pstates consists of contiguous integers, the ··· 309 298 return powernv_pstate_info.max - powernv_pstate_info.nominal; 310 299 } 311 300 312 - static void powernv_cpufreq_throttle_check(unsigned int cpu) 301 + static void powernv_cpufreq_throttle_check(void *data) 313 302 { 303 + unsigned int cpu = smp_processor_id(); 314 304 unsigned long pmsr; 315 - int pmsr_pmax, pmsr_lp; 305 + int pmsr_pmax, i; 316 306 317 307 pmsr = get_pmspr(SPRN_PMSR); 308 + 309 + for (i = 0; i < nr_chips; i++) 310 + if (chips[i].id == cpu_to_chip_id(cpu)) 311 + break; 318 312 319 313 /* Check for Pmax Capping */ 320 314 pmsr_pmax = (s8)PMSR_MAX(pmsr); 321 315 if (pmsr_pmax != powernv_pstate_info.max) { 322 - throttled = true; 323 - pr_info("CPU %d Pmax is reduced to %d\n", cpu, pmsr_pmax); 324 - pr_info("Max allowed Pstate is capped\n"); 316 + if (chips[i].throttled) 317 + goto next; 318 + chips[i].throttled = true; 319 + pr_info("CPU %d on Chip %u has Pmax reduced to %d\n", cpu, 320 + chips[i].id, pmsr_pmax); 321 + } else if (chips[i].throttled) { 322 + chips[i].throttled = false; 323 + pr_info("CPU %d on Chip %u has Pmax restored to %d\n", cpu, 324 + chips[i].id, pmsr_pmax); 325 325 } 326 326 327 - /* 328 - * Check for Psafe by reading LocalPstate 329 - * or check if Psafe_mode_active is set in PMSR. 330 - */ 331 - pmsr_lp = (s8)PMSR_LP(pmsr); 332 - if ((pmsr_lp < powernv_pstate_info.min) || 333 - (pmsr & PMSR_PSAFE_ENABLE)) { 327 + /* Check if Psafe_mode_active is set in PMSR. */ 328 + next: 329 + if (pmsr & PMSR_PSAFE_ENABLE) { 334 330 throttled = true; 335 331 pr_info("Pstate set to safe frequency\n"); 336 332 } ··· 368 350 return 0; 369 351 370 352 if (!throttled) 371 - powernv_cpufreq_throttle_check(smp_processor_id()); 353 + powernv_cpufreq_throttle_check(NULL); 372 354 373 355 freq_data.pstate_id = powernv_freqs[new_index].driver_data; 374 356 ··· 413 395 .notifier_call = powernv_cpufreq_reboot_notifier, 414 396 }; 415 397 398 + void powernv_cpufreq_work_fn(struct work_struct *work) 399 + { 400 + struct chip *chip = container_of(work, struct chip, throttle); 401 + unsigned int cpu; 402 + cpumask_var_t mask; 403 + 404 + smp_call_function_any(&chip->mask, 405 + powernv_cpufreq_throttle_check, NULL, 0); 406 + 407 + if (!chip->restore) 408 + return; 409 + 410 + chip->restore = false; 411 + cpumask_copy(mask, &chip->mask); 412 + for_each_cpu_and(cpu, mask, cpu_online_mask) { 413 + int index, tcpu; 414 + struct cpufreq_policy policy; 415 + 416 + cpufreq_get_policy(&policy, cpu); 417 + cpufreq_frequency_table_target(&policy, policy.freq_table, 418 + policy.cur, 419 + CPUFREQ_RELATION_C, &index); 420 + powernv_cpufreq_target_index(&policy, index); 421 + for_each_cpu(tcpu, policy.cpus) 422 + cpumask_clear_cpu(tcpu, mask); 423 + } 424 + } 425 + 426 + static char throttle_reason[][30] = { 427 + "No throttling", 428 + "Power Cap", 429 + "Processor Over Temperature", 430 + "Power Supply Failure", 431 + "Over Current", 432 + "OCC Reset" 433 + }; 434 + 435 + static int powernv_cpufreq_occ_msg(struct notifier_block *nb, 436 + unsigned long msg_type, void *_msg) 437 + { 438 + struct opal_msg *msg = _msg; 439 + struct opal_occ_msg omsg; 440 + int i; 441 + 442 + if (msg_type != OPAL_MSG_OCC) 443 + return 0; 444 + 445 + omsg.type = be64_to_cpu(msg->params[0]); 446 + 447 + switch (omsg.type) { 448 + case OCC_RESET: 449 + occ_reset = true; 450 + /* 451 + * powernv_cpufreq_throttle_check() is called in 452 + * target() callback which can detect the throttle state 453 + * for governors like ondemand. 454 + * But static governors will not call target() often thus 455 + * report throttling here. 456 + */ 457 + if (!throttled) { 458 + throttled = true; 459 + pr_crit("CPU Frequency is throttled\n"); 460 + } 461 + pr_info("OCC: Reset\n"); 462 + break; 463 + case OCC_LOAD: 464 + pr_info("OCC: Loaded\n"); 465 + break; 466 + case OCC_THROTTLE: 467 + omsg.chip = be64_to_cpu(msg->params[1]); 468 + omsg.throttle_status = be64_to_cpu(msg->params[2]); 469 + 470 + if (occ_reset) { 471 + occ_reset = false; 472 + throttled = false; 473 + pr_info("OCC: Active\n"); 474 + 475 + for (i = 0; i < nr_chips; i++) { 476 + chips[i].restore = true; 477 + schedule_work(&chips[i].throttle); 478 + } 479 + 480 + return 0; 481 + } 482 + 483 + if (omsg.throttle_status && 484 + omsg.throttle_status <= OCC_MAX_THROTTLE_STATUS) 485 + pr_info("OCC: Chip %u Pmax reduced due to %s\n", 486 + (unsigned int)omsg.chip, 487 + throttle_reason[omsg.throttle_status]); 488 + else if (!omsg.throttle_status) 489 + pr_info("OCC: Chip %u %s\n", (unsigned int)omsg.chip, 490 + throttle_reason[omsg.throttle_status]); 491 + else 492 + return 0; 493 + 494 + for (i = 0; i < nr_chips; i++) 495 + if (chips[i].id == omsg.chip) { 496 + if (!omsg.throttle_status) 497 + chips[i].restore = true; 498 + schedule_work(&chips[i].throttle); 499 + } 500 + } 501 + return 0; 502 + } 503 + 504 + static struct notifier_block powernv_cpufreq_opal_nb = { 505 + .notifier_call = powernv_cpufreq_occ_msg, 506 + .next = NULL, 507 + .priority = 0, 508 + }; 509 + 416 510 static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy) 417 511 { 418 512 struct powernv_smp_call_data freq_data; ··· 544 414 .attr = powernv_cpu_freq_attr, 545 415 }; 546 416 417 + static int init_chip_info(void) 418 + { 419 + unsigned int chip[256]; 420 + unsigned int cpu, i; 421 + unsigned int prev_chip_id = UINT_MAX; 422 + 423 + for_each_possible_cpu(cpu) { 424 + unsigned int id = cpu_to_chip_id(cpu); 425 + 426 + if (prev_chip_id != id) { 427 + prev_chip_id = id; 428 + chip[nr_chips++] = id; 429 + } 430 + } 431 + 432 + chips = kmalloc_array(nr_chips, sizeof(struct chip), GFP_KERNEL); 433 + if (!chips) 434 + return -ENOMEM; 435 + 436 + for (i = 0; i < nr_chips; i++) { 437 + chips[i].id = chip[i]; 438 + chips[i].throttled = false; 439 + cpumask_copy(&chips[i].mask, cpumask_of_node(chip[i])); 440 + INIT_WORK(&chips[i].throttle, powernv_cpufreq_work_fn); 441 + chips[i].restore = false; 442 + } 443 + 444 + return 0; 445 + } 446 + 547 447 static int __init powernv_cpufreq_init(void) 548 448 { 549 449 int rc = 0; ··· 589 429 return rc; 590 430 } 591 431 432 + /* Populate chip info */ 433 + rc = init_chip_info(); 434 + if (rc) 435 + return rc; 436 + 592 437 register_reboot_notifier(&powernv_cpufreq_reboot_nb); 438 + opal_message_notifier_register(OPAL_MSG_OCC, &powernv_cpufreq_opal_nb); 593 439 return cpufreq_register_driver(&powernv_cpufreq_driver); 594 440 } 595 441 module_init(powernv_cpufreq_init); ··· 603 437 static void __exit powernv_cpufreq_exit(void) 604 438 { 605 439 unregister_reboot_notifier(&powernv_cpufreq_reboot_nb); 440 + opal_message_notifier_unregister(OPAL_MSG_OCC, 441 + &powernv_cpufreq_opal_nb); 606 442 cpufreq_unregister_driver(&powernv_cpufreq_driver); 607 443 } 608 444 module_exit(powernv_cpufreq_exit);
+6 -10
drivers/xen/xen-acpi-processor.c
··· 560 560 561 561 return 0; 562 562 err_unregister: 563 - for_each_possible_cpu(i) { 564 - struct acpi_processor_performance *perf; 565 - perf = per_cpu_ptr(acpi_perf_data, i); 566 - acpi_processor_unregister_performance(perf, i); 567 - } 563 + for_each_possible_cpu(i) 564 + acpi_processor_unregister_performance(i); 565 + 568 566 err_out: 569 567 /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ 570 568 free_acpi_perf_data(); ··· 577 579 kfree(acpi_ids_done); 578 580 kfree(acpi_id_present); 579 581 kfree(acpi_id_cst_present); 580 - for_each_possible_cpu(i) { 581 - struct acpi_processor_performance *perf; 582 - perf = per_cpu_ptr(acpi_perf_data, i); 583 - acpi_processor_unregister_performance(perf, i); 584 - } 582 + for_each_possible_cpu(i) 583 + acpi_processor_unregister_performance(i); 584 + 585 585 free_acpi_perf_data(); 586 586 } 587 587
+1 -4
include/acpi/processor.h
··· 228 228 229 229 extern int acpi_processor_register_performance(struct acpi_processor_performance 230 230 *performance, unsigned int cpu); 231 - extern void acpi_processor_unregister_performance(struct 232 - acpi_processor_performance 233 - *performance, 234 - unsigned int cpu); 231 + extern void acpi_processor_unregister_performance(unsigned int cpu); 235 232 236 233 /* note: this locks both the calling module and the processor module 237 234 if a _PPC object exists, rmmod is disallowed then */