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

Merge branch 'pm-cpufreq'

* pm-cpufreq: (37 commits)
cpufreq: dt: allow driver to boot automatically
intel_pstate: Fix overflow in busy_scaled due to long delay
cpufreq: qoriq: optimize the CPU frequency switching time
cpufreq: gx-suspmod: Fix two typos in two comments
cpufreq: nforce2: Fix typo in comment to function nforce2_init()
cpufreq: governor: Serialize governor callbacks
cpufreq: governor: split cpufreq_governor_dbs()
cpufreq: governor: register notifier from cs_init()
cpufreq: Remove cpufreq_update_policy()
cpufreq: Restart governor as soon as possible
cpufreq: Call cpufreq_policy_put_kobj() from cpufreq_policy_free()
cpufreq: Initialize policy->kobj while allocating policy
cpufreq: Stop migrating sysfs files on hotplug
cpufreq: Don't allow updating inactive policies from sysfs
intel_pstate: Force setting target pstate when required
intel_pstate: change some inconsistent debug information
cpufreq: Track cpu managing sysfs kobjects separately
cpufreq: Fix for typos in two comments
cpufreq: Mark policy->governor = NULL for inactive policies
cpufreq: Manage governor usage history with 'policy->last_governor'
...

+699 -532
-2
Documentation/cpu-freq/user-guide.txt
··· 196 196 related_cpus : List of Online + Offline CPUs that need software 197 197 coordination of frequency. 198 198 199 - scaling_driver : Hardware driver for cpufreq. 200 - 201 199 scaling_cur_freq : Current frequency of the CPU as determined by 202 200 the governor and cpufreq core, in KHz. This is 203 201 the frequency the kernel thinks the CPU runs
+1 -1
drivers/cpufreq/Kconfig.arm
··· 5 5 # big LITTLE core layer and glue drivers 6 6 config ARM_BIG_LITTLE_CPUFREQ 7 7 tristate "Generic ARM big LITTLE CPUfreq driver" 8 - depends on ARM && BIG_LITTLE && ARM_CPU_TOPOLOGY && HAVE_CLK 8 + depends on (ARM_CPU_TOPOLOGY || ARM64) && HAVE_CLK 9 9 select PM_OPP 10 10 help 11 11 This enables the Generic CPUfreq driver for ARM big.LITTLE platforms.
+32 -8
drivers/cpufreq/arm_big_little.c
··· 31 31 #include <linux/slab.h> 32 32 #include <linux/topology.h> 33 33 #include <linux/types.h> 34 - #include <asm/bL_switcher.h> 35 34 36 35 #include "arm_big_little.h" 37 36 ··· 40 41 #define MAX_CLUSTERS 2 41 42 42 43 #ifdef CONFIG_BL_SWITCHER 44 + #include <asm/bL_switcher.h> 43 45 static bool bL_switching_enabled; 44 46 #define is_bL_switching_enabled() bL_switching_enabled 45 47 #define set_switching_enabled(x) (bL_switching_enabled = (x)) 46 48 #else 47 49 #define is_bL_switching_enabled() false 48 50 #define set_switching_enabled(x) do { } while (0) 51 + #define bL_switch_request(...) do { } while (0) 52 + #define bL_switcher_put_enabled() do { } while (0) 53 + #define bL_switcher_get_enabled() do { } while (0) 49 54 #endif 50 55 51 56 #define ACTUAL_FREQ(cluster, freq) ((cluster == A7_CLUSTER) ? freq << 1 : freq) ··· 189 186 mutex_unlock(&cluster_lock[old_cluster]); 190 187 } 191 188 189 + /* 190 + * FIXME: clk_set_rate has to handle the case where clk_change_rate 191 + * can fail due to hardware or firmware issues. Until the clk core 192 + * layer is fixed, we can check here. In most of the cases we will 193 + * be reading only the cached value anyway. This needs to be removed 194 + * once clk core is fixed. 195 + */ 196 + if (bL_cpufreq_get_rate(cpu) != new_rate) 197 + return -EIO; 192 198 return 0; 193 199 } 194 200 ··· 334 322 static int _get_cluster_clk_and_freq_table(struct device *cpu_dev) 335 323 { 336 324 u32 cluster = raw_cpu_to_cluster(cpu_dev->id); 337 - char name[14] = "cpu-cluster."; 338 325 int ret; 339 326 340 327 if (freq_table[cluster]) ··· 353 342 goto free_opp_table; 354 343 } 355 344 356 - name[12] = cluster + '0'; 357 - clk[cluster] = clk_get(cpu_dev, name); 345 + clk[cluster] = clk_get(cpu_dev, NULL); 358 346 if (!IS_ERR(clk[cluster])) { 359 347 dev_dbg(cpu_dev, "%s: clk: %p & freq table: %p, cluster: %d\n", 360 348 __func__, clk[cluster], freq_table[cluster], ··· 516 506 .attr = cpufreq_generic_attr, 517 507 }; 518 508 509 + #ifdef CONFIG_BL_SWITCHER 519 510 static int bL_cpufreq_switcher_notifier(struct notifier_block *nfb, 520 511 unsigned long action, void *_arg) 521 512 { ··· 549 538 .notifier_call = bL_cpufreq_switcher_notifier, 550 539 }; 551 540 541 + static int __bLs_register_notifier(void) 542 + { 543 + return bL_switcher_register_notifier(&bL_switcher_notifier); 544 + } 545 + 546 + static int __bLs_unregister_notifier(void) 547 + { 548 + return bL_switcher_unregister_notifier(&bL_switcher_notifier); 549 + } 550 + #else 551 + static int __bLs_register_notifier(void) { return 0; } 552 + static int __bLs_unregister_notifier(void) { return 0; } 553 + #endif 554 + 552 555 int bL_cpufreq_register(struct cpufreq_arm_bL_ops *ops) 553 556 { 554 557 int ret, i; ··· 580 555 581 556 arm_bL_ops = ops; 582 557 583 - ret = bL_switcher_get_enabled(); 584 - set_switching_enabled(ret); 558 + set_switching_enabled(bL_switcher_get_enabled()); 585 559 586 560 for (i = 0; i < MAX_CLUSTERS; i++) 587 561 mutex_init(&cluster_lock[i]); ··· 591 567 __func__, ops->name, ret); 592 568 arm_bL_ops = NULL; 593 569 } else { 594 - ret = bL_switcher_register_notifier(&bL_switcher_notifier); 570 + ret = __bLs_register_notifier(); 595 571 if (ret) { 596 572 cpufreq_unregister_driver(&bL_cpufreq_driver); 597 573 arm_bL_ops = NULL; ··· 615 591 } 616 592 617 593 bL_switcher_get_enabled(); 618 - bL_switcher_unregister_notifier(&bL_switcher_notifier); 594 + __bLs_unregister_notifier(); 619 595 cpufreq_unregister_driver(&bL_cpufreq_driver); 620 596 bL_switcher_put_enabled(); 621 597 pr_info("%s: Un-registered platform driver: %s\n", __func__,
+1
drivers/cpufreq/cpufreq-dt.c
··· 416 416 }; 417 417 module_platform_driver(dt_cpufreq_platdrv); 418 418 419 + MODULE_ALIAS("platform:cpufreq-dt"); 419 420 MODULE_AUTHOR("Viresh Kumar <viresh.kumar@linaro.org>"); 420 421 MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>"); 421 422 MODULE_DESCRIPTION("Generic cpufreq driver");
+1 -1
drivers/cpufreq/cpufreq-nforce2.c
··· 414 414 * nforce2_init - initializes the nForce2 CPUFreq driver 415 415 * 416 416 * Initializes the nForce2 FSB support. Returns -ENODEV on unsupported 417 - * devices, -EINVAL on problems during initiatization, and zero on 417 + * devices, -EINVAL on problems during initialization, and zero on 418 418 * success. 419 419 */ 420 420 static int __init nforce2_init(void)
+325 -248
drivers/cpufreq/cpufreq.c
··· 31 31 #include <linux/tick.h> 32 32 #include <trace/events/power.h> 33 33 34 - /* Macros to iterate over lists */ 35 - /* Iterate over online CPUs policies */ 36 34 static LIST_HEAD(cpufreq_policy_list); 37 - #define for_each_policy(__policy) \ 35 + 36 + static inline bool policy_is_inactive(struct cpufreq_policy *policy) 37 + { 38 + return cpumask_empty(policy->cpus); 39 + } 40 + 41 + static bool suitable_policy(struct cpufreq_policy *policy, bool active) 42 + { 43 + return active == !policy_is_inactive(policy); 44 + } 45 + 46 + /* Finds Next Acive/Inactive policy */ 47 + static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy, 48 + bool active) 49 + { 50 + do { 51 + policy = list_next_entry(policy, policy_list); 52 + 53 + /* No more policies in the list */ 54 + if (&policy->policy_list == &cpufreq_policy_list) 55 + return NULL; 56 + } while (!suitable_policy(policy, active)); 57 + 58 + return policy; 59 + } 60 + 61 + static struct cpufreq_policy *first_policy(bool active) 62 + { 63 + struct cpufreq_policy *policy; 64 + 65 + /* No policies in the list */ 66 + if (list_empty(&cpufreq_policy_list)) 67 + return NULL; 68 + 69 + policy = list_first_entry(&cpufreq_policy_list, typeof(*policy), 70 + policy_list); 71 + 72 + if (!suitable_policy(policy, active)) 73 + policy = next_policy(policy, active); 74 + 75 + return policy; 76 + } 77 + 78 + /* Macros to iterate over CPU policies */ 79 + #define for_each_suitable_policy(__policy, __active) \ 80 + for (__policy = first_policy(__active); \ 81 + __policy; \ 82 + __policy = next_policy(__policy, __active)) 83 + 84 + #define for_each_active_policy(__policy) \ 85 + for_each_suitable_policy(__policy, true) 86 + #define for_each_inactive_policy(__policy) \ 87 + for_each_suitable_policy(__policy, false) 88 + 89 + #define for_each_policy(__policy) \ 38 90 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) 39 91 40 92 /* Iterate over governors */ ··· 101 49 */ 102 50 static struct cpufreq_driver *cpufreq_driver; 103 51 static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 104 - static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback); 105 52 static DEFINE_RWLOCK(cpufreq_driver_lock); 106 53 DEFINE_MUTEX(cpufreq_governor_lock); 107 - 108 - /* This one keeps track of the previously set governor of a removed CPU */ 109 - static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); 110 54 111 55 /* Flag to suspend/resume CPUFreq governors */ 112 56 static bool cpufreq_suspended; ··· 226 178 policy->cpuinfo.transition_latency = transition_latency; 227 179 228 180 /* 229 - * The driver only supports the SMP configuartion where all processors 181 + * The driver only supports the SMP configuration where all processors 230 182 * share the clock and voltage and clock. 231 183 */ 232 184 cpumask_setall(policy->cpus); ··· 235 187 } 236 188 EXPORT_SYMBOL_GPL(cpufreq_generic_init); 237 189 238 - unsigned int cpufreq_generic_get(unsigned int cpu) 190 + /* Only for cpufreq core internal use */ 191 + struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) 239 192 { 240 193 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 194 + 195 + return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; 196 + } 197 + 198 + unsigned int cpufreq_generic_get(unsigned int cpu) 199 + { 200 + struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); 241 201 242 202 if (!policy || IS_ERR(policy->clk)) { 243 203 pr_err("%s: No %s associated to cpu: %d\n", ··· 257 201 } 258 202 EXPORT_SYMBOL_GPL(cpufreq_generic_get); 259 203 260 - /* Only for cpufreq core internal use */ 261 - struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu) 262 - { 263 - return per_cpu(cpufreq_cpu_data, cpu); 264 - } 265 - 204 + /** 205 + * cpufreq_cpu_get: returns policy for a cpu and marks it busy. 206 + * 207 + * @cpu: cpu to find policy for. 208 + * 209 + * This returns policy for 'cpu', returns NULL if it doesn't exist. 210 + * It also increments the kobject reference count to mark it busy and so would 211 + * require a corresponding call to cpufreq_cpu_put() to decrement it back. 212 + * If corresponding call cpufreq_cpu_put() isn't made, the policy wouldn't be 213 + * freed as that depends on the kobj count. 214 + * 215 + * It also takes a read-lock of 'cpufreq_rwsem' and doesn't put it back if a 216 + * valid policy is found. This is done to make sure the driver doesn't get 217 + * unregistered while the policy is being used. 218 + * 219 + * Return: A valid policy on success, otherwise NULL on failure. 220 + */ 266 221 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) 267 222 { 268 223 struct cpufreq_policy *policy = NULL; 269 224 unsigned long flags; 270 225 271 - if (cpu >= nr_cpu_ids) 226 + if (WARN_ON(cpu >= nr_cpu_ids)) 272 227 return NULL; 273 228 274 229 if (!down_read_trylock(&cpufreq_rwsem)) ··· 290 223 291 224 if (cpufreq_driver) { 292 225 /* get the CPU */ 293 - policy = per_cpu(cpufreq_cpu_data, cpu); 226 + policy = cpufreq_cpu_get_raw(cpu); 294 227 if (policy) 295 228 kobject_get(&policy->kobj); 296 229 } ··· 304 237 } 305 238 EXPORT_SYMBOL_GPL(cpufreq_cpu_get); 306 239 240 + /** 241 + * cpufreq_cpu_put: Decrements the usage count of a policy 242 + * 243 + * @policy: policy earlier returned by cpufreq_cpu_get(). 244 + * 245 + * This decrements the kobject reference count incremented earlier by calling 246 + * cpufreq_cpu_get(). 247 + * 248 + * It also drops the read-lock of 'cpufreq_rwsem' taken at cpufreq_cpu_get(). 249 + */ 307 250 void cpufreq_cpu_put(struct cpufreq_policy *policy) 308 251 { 309 252 kobject_put(&policy->kobj); ··· 875 798 876 799 down_write(&policy->rwsem); 877 800 801 + /* Updating inactive policies is invalid, so avoid doing that. */ 802 + if (unlikely(policy_is_inactive(policy))) { 803 + ret = -EBUSY; 804 + goto unlock_policy_rwsem; 805 + } 806 + 878 807 if (fattr->store) 879 808 ret = fattr->store(policy, buf, count); 880 809 else 881 810 ret = -EIO; 882 811 812 + unlock_policy_rwsem: 883 813 up_write(&policy->rwsem); 884 814 885 815 up_read(&cpufreq_rwsem); ··· 957 873 } 958 874 EXPORT_SYMBOL(cpufreq_sysfs_remove_file); 959 875 960 - /* symlink affected CPUs */ 876 + static int add_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu) 877 + { 878 + struct device *cpu_dev; 879 + 880 + pr_debug("%s: Adding symlink for CPU: %u\n", __func__, cpu); 881 + 882 + if (!policy) 883 + return 0; 884 + 885 + cpu_dev = get_cpu_device(cpu); 886 + if (WARN_ON(!cpu_dev)) 887 + return 0; 888 + 889 + return sysfs_create_link(&cpu_dev->kobj, &policy->kobj, "cpufreq"); 890 + } 891 + 892 + static void remove_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu) 893 + { 894 + struct device *cpu_dev; 895 + 896 + pr_debug("%s: Removing symlink for CPU: %u\n", __func__, cpu); 897 + 898 + cpu_dev = get_cpu_device(cpu); 899 + if (WARN_ON(!cpu_dev)) 900 + return; 901 + 902 + sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); 903 + } 904 + 905 + /* Add/remove symlinks for all related CPUs */ 961 906 static int cpufreq_add_dev_symlink(struct cpufreq_policy *policy) 962 907 { 963 908 unsigned int j; 964 909 int ret = 0; 965 910 966 - for_each_cpu(j, policy->cpus) { 967 - struct device *cpu_dev; 968 - 969 - if (j == policy->cpu) 911 + /* Some related CPUs might not be present (physically hotplugged) */ 912 + for_each_cpu_and(j, policy->related_cpus, cpu_present_mask) { 913 + if (j == policy->kobj_cpu) 970 914 continue; 971 915 972 - pr_debug("Adding link for CPU: %u\n", j); 973 - cpu_dev = get_cpu_device(j); 974 - ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj, 975 - "cpufreq"); 916 + ret = add_cpu_dev_symlink(policy, j); 976 917 if (ret) 977 918 break; 978 919 } 920 + 979 921 return ret; 922 + } 923 + 924 + static void cpufreq_remove_dev_symlink(struct cpufreq_policy *policy) 925 + { 926 + unsigned int j; 927 + 928 + /* Some related CPUs might not be present (physically hotplugged) */ 929 + for_each_cpu_and(j, policy->related_cpus, cpu_present_mask) { 930 + if (j == policy->kobj_cpu) 931 + continue; 932 + 933 + remove_cpu_dev_symlink(policy, j); 934 + } 980 935 } 981 936 982 937 static int cpufreq_add_dev_interface(struct cpufreq_policy *policy, ··· 1060 937 memcpy(&new_policy, policy, sizeof(*policy)); 1061 938 1062 939 /* Update governor of new_policy to the governor used before hotplug */ 1063 - gov = find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu)); 940 + gov = find_governor(policy->last_governor); 1064 941 if (gov) 1065 942 pr_debug("Restoring governor %s for cpu %d\n", 1066 943 policy->governor->name, policy->cpu); ··· 1086 963 unsigned int cpu, struct device *dev) 1087 964 { 1088 965 int ret = 0; 1089 - unsigned long flags; 966 + 967 + /* Has this CPU been taken care of already? */ 968 + if (cpumask_test_cpu(cpu, policy->cpus)) 969 + return 0; 1090 970 1091 971 if (has_target()) { 1092 972 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP); ··· 1100 974 } 1101 975 1102 976 down_write(&policy->rwsem); 1103 - 1104 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1105 - 1106 977 cpumask_set_cpu(cpu, policy->cpus); 1107 - per_cpu(cpufreq_cpu_data, cpu) = policy; 1108 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1109 - 1110 978 up_write(&policy->rwsem); 1111 979 1112 980 if (has_target()) { ··· 1114 994 } 1115 995 } 1116 996 1117 - return sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); 997 + return 0; 1118 998 } 1119 999 1120 1000 static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu) ··· 1123 1003 unsigned long flags; 1124 1004 1125 1005 read_lock_irqsave(&cpufreq_driver_lock, flags); 1126 - 1127 - policy = per_cpu(cpufreq_cpu_data_fallback, cpu); 1128 - 1006 + policy = per_cpu(cpufreq_cpu_data, cpu); 1129 1007 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1130 1008 1131 - if (policy) 1132 - policy->governor = NULL; 1009 + if (likely(policy)) { 1010 + /* Policy should be inactive here */ 1011 + WARN_ON(!policy_is_inactive(policy)); 1012 + 1013 + down_write(&policy->rwsem); 1014 + policy->cpu = cpu; 1015 + up_write(&policy->rwsem); 1016 + } 1133 1017 1134 1018 return policy; 1135 1019 } 1136 1020 1137 - static struct cpufreq_policy *cpufreq_policy_alloc(void) 1021 + static struct cpufreq_policy *cpufreq_policy_alloc(struct device *dev) 1138 1022 { 1139 1023 struct cpufreq_policy *policy; 1024 + int ret; 1140 1025 1141 1026 policy = kzalloc(sizeof(*policy), GFP_KERNEL); 1142 1027 if (!policy) ··· 1153 1028 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) 1154 1029 goto err_free_cpumask; 1155 1030 1031 + ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &dev->kobj, 1032 + "cpufreq"); 1033 + if (ret) { 1034 + pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret); 1035 + goto err_free_rcpumask; 1036 + } 1037 + 1156 1038 INIT_LIST_HEAD(&policy->policy_list); 1157 1039 init_rwsem(&policy->rwsem); 1158 1040 spin_lock_init(&policy->transition_lock); ··· 1167 1035 init_completion(&policy->kobj_unregister); 1168 1036 INIT_WORK(&policy->update, handle_update); 1169 1037 1038 + policy->cpu = dev->id; 1039 + 1040 + /* Set this once on allocation */ 1041 + policy->kobj_cpu = dev->id; 1042 + 1170 1043 return policy; 1171 1044 1045 + err_free_rcpumask: 1046 + free_cpumask_var(policy->related_cpus); 1172 1047 err_free_cpumask: 1173 1048 free_cpumask_var(policy->cpus); 1174 1049 err_free_policy: ··· 1184 1045 return NULL; 1185 1046 } 1186 1047 1187 - static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) 1048 + static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy, bool notify) 1188 1049 { 1189 1050 struct kobject *kobj; 1190 1051 struct completion *cmp; 1191 1052 1192 - blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1193 - CPUFREQ_REMOVE_POLICY, policy); 1053 + if (notify) 1054 + blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1055 + CPUFREQ_REMOVE_POLICY, policy); 1194 1056 1195 - down_read(&policy->rwsem); 1057 + down_write(&policy->rwsem); 1058 + cpufreq_remove_dev_symlink(policy); 1196 1059 kobj = &policy->kobj; 1197 1060 cmp = &policy->kobj_unregister; 1198 - up_read(&policy->rwsem); 1061 + up_write(&policy->rwsem); 1199 1062 kobject_put(kobj); 1200 1063 1201 1064 /* ··· 1210 1069 pr_debug("wait complete\n"); 1211 1070 } 1212 1071 1213 - static void cpufreq_policy_free(struct cpufreq_policy *policy) 1072 + static void cpufreq_policy_free(struct cpufreq_policy *policy, bool notify) 1214 1073 { 1074 + unsigned long flags; 1075 + int cpu; 1076 + 1077 + /* Remove policy from list */ 1078 + write_lock_irqsave(&cpufreq_driver_lock, flags); 1079 + list_del(&policy->policy_list); 1080 + 1081 + for_each_cpu(cpu, policy->related_cpus) 1082 + per_cpu(cpufreq_cpu_data, cpu) = NULL; 1083 + write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1084 + 1085 + cpufreq_policy_put_kobj(policy, notify); 1215 1086 free_cpumask_var(policy->related_cpus); 1216 1087 free_cpumask_var(policy->cpus); 1217 1088 kfree(policy); 1218 1089 } 1219 1090 1220 - static int update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu, 1221 - struct device *cpu_dev) 1222 - { 1223 - int ret; 1224 - 1225 - if (WARN_ON(cpu == policy->cpu)) 1226 - return 0; 1227 - 1228 - /* Move kobject to the new policy->cpu */ 1229 - ret = kobject_move(&policy->kobj, &cpu_dev->kobj); 1230 - if (ret) { 1231 - pr_err("%s: Failed to move kobj: %d\n", __func__, ret); 1232 - return ret; 1233 - } 1234 - 1235 - down_write(&policy->rwsem); 1236 - policy->cpu = cpu; 1237 - up_write(&policy->rwsem); 1238 - 1239 - return 0; 1240 - } 1241 - 1242 - static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1091 + /** 1092 + * cpufreq_add_dev - add a CPU device 1093 + * 1094 + * Adds the cpufreq interface for a CPU device. 1095 + * 1096 + * The Oracle says: try running cpufreq registration/unregistration concurrently 1097 + * with with cpu hotplugging and all hell will break loose. Tried to clean this 1098 + * mess up, but more thorough testing is needed. - Mathieu 1099 + */ 1100 + static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1243 1101 { 1244 1102 unsigned int j, cpu = dev->id; 1245 1103 int ret = -ENOMEM; 1246 1104 struct cpufreq_policy *policy; 1247 1105 unsigned long flags; 1248 - bool recover_policy = cpufreq_suspended; 1249 - 1250 - if (cpu_is_offline(cpu)) 1251 - return 0; 1106 + bool recover_policy = !sif; 1252 1107 1253 1108 pr_debug("adding CPU %u\n", cpu); 1254 1109 1255 - /* check whether a different CPU already registered this 1256 - * CPU because it is in the same boat. */ 1257 - policy = cpufreq_cpu_get_raw(cpu); 1258 - if (unlikely(policy)) 1259 - return 0; 1110 + /* 1111 + * Only possible if 'cpu' wasn't physically present earlier and we are 1112 + * here from subsys_interface add callback. A hotplug notifier will 1113 + * follow and we will handle it like logical CPU hotplug then. For now, 1114 + * just create the sysfs link. 1115 + */ 1116 + if (cpu_is_offline(cpu)) 1117 + return add_cpu_dev_symlink(per_cpu(cpufreq_cpu_data, cpu), cpu); 1260 1118 1261 1119 if (!down_read_trylock(&cpufreq_rwsem)) 1262 1120 return 0; 1263 1121 1264 - /* Check if this cpu was hot-unplugged earlier and has siblings */ 1265 - read_lock_irqsave(&cpufreq_driver_lock, flags); 1266 - for_each_policy(policy) { 1267 - if (cpumask_test_cpu(cpu, policy->related_cpus)) { 1268 - read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1269 - ret = cpufreq_add_policy_cpu(policy, cpu, dev); 1270 - up_read(&cpufreq_rwsem); 1271 - return ret; 1272 - } 1122 + /* Check if this CPU already has a policy to manage it */ 1123 + policy = per_cpu(cpufreq_cpu_data, cpu); 1124 + if (policy && !policy_is_inactive(policy)) { 1125 + WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); 1126 + ret = cpufreq_add_policy_cpu(policy, cpu, dev); 1127 + up_read(&cpufreq_rwsem); 1128 + return ret; 1273 1129 } 1274 - read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1275 1130 1276 1131 /* 1277 1132 * Restore the saved policy when doing light-weight init and fall back ··· 1276 1139 policy = recover_policy ? cpufreq_policy_restore(cpu) : NULL; 1277 1140 if (!policy) { 1278 1141 recover_policy = false; 1279 - policy = cpufreq_policy_alloc(); 1142 + policy = cpufreq_policy_alloc(dev); 1280 1143 if (!policy) 1281 1144 goto nomem_out; 1282 1145 } 1283 - 1284 - /* 1285 - * In the resume path, since we restore a saved policy, the assignment 1286 - * to policy->cpu is like an update of the existing policy, rather than 1287 - * the creation of a brand new one. So we need to perform this update 1288 - * by invoking update_policy_cpu(). 1289 - */ 1290 - if (recover_policy && cpu != policy->cpu) 1291 - WARN_ON(update_policy_cpu(policy, cpu, dev)); 1292 - else 1293 - policy->cpu = cpu; 1294 1146 1295 1147 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1296 1148 ··· 1307 1181 policy->user_policy.min = policy->min; 1308 1182 policy->user_policy.max = policy->max; 1309 1183 1310 - /* prepare interface data */ 1311 - ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, 1312 - &dev->kobj, "cpufreq"); 1313 - if (ret) { 1314 - pr_err("%s: failed to init policy->kobj: %d\n", 1315 - __func__, ret); 1316 - goto err_init_policy_kobj; 1317 - } 1184 + write_lock_irqsave(&cpufreq_driver_lock, flags); 1185 + for_each_cpu(j, policy->related_cpus) 1186 + per_cpu(cpufreq_cpu_data, j) = policy; 1187 + write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1318 1188 } 1319 - 1320 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1321 - for_each_cpu(j, policy->cpus) 1322 - per_cpu(cpufreq_cpu_data, j) = policy; 1323 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1324 1189 1325 1190 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { 1326 1191 policy->cur = cpufreq_driver->get(policy->cpu); ··· 1370 1253 goto err_out_unregister; 1371 1254 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1372 1255 CPUFREQ_CREATE_POLICY, policy); 1373 - } 1374 1256 1375 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1376 - list_add(&policy->policy_list, &cpufreq_policy_list); 1377 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1257 + write_lock_irqsave(&cpufreq_driver_lock, flags); 1258 + list_add(&policy->policy_list, &cpufreq_policy_list); 1259 + write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1260 + } 1378 1261 1379 1262 cpufreq_init_policy(policy); 1380 1263 ··· 1398 1281 1399 1282 err_out_unregister: 1400 1283 err_get_freq: 1401 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1402 - for_each_cpu(j, policy->cpus) 1403 - per_cpu(cpufreq_cpu_data, j) = NULL; 1404 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1405 - 1406 - if (!recover_policy) { 1407 - kobject_put(&policy->kobj); 1408 - wait_for_completion(&policy->kobj_unregister); 1409 - } 1410 - err_init_policy_kobj: 1411 1284 up_write(&policy->rwsem); 1412 1285 1413 1286 if (cpufreq_driver->exit) 1414 1287 cpufreq_driver->exit(policy); 1415 1288 err_set_policy_cpu: 1416 - if (recover_policy) { 1417 - /* Do not leave stale fallback data behind. */ 1418 - per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL; 1419 - cpufreq_policy_put_kobj(policy); 1420 - } 1421 - cpufreq_policy_free(policy); 1422 - 1289 + cpufreq_policy_free(policy, recover_policy); 1423 1290 nomem_out: 1424 1291 up_read(&cpufreq_rwsem); 1425 1292 1426 1293 return ret; 1427 1294 } 1428 1295 1429 - /** 1430 - * cpufreq_add_dev - add a CPU device 1431 - * 1432 - * Adds the cpufreq interface for a CPU device. 1433 - * 1434 - * The Oracle says: try running cpufreq registration/unregistration concurrently 1435 - * with with cpu hotplugging and all hell will break loose. Tried to clean this 1436 - * mess up, but more thorough testing is needed. - Mathieu 1437 - */ 1438 - static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1439 - { 1440 - return __cpufreq_add_dev(dev, sif); 1441 - } 1442 - 1443 1296 static int __cpufreq_remove_dev_prepare(struct device *dev, 1444 1297 struct subsys_interface *sif) 1445 1298 { 1446 - unsigned int cpu = dev->id, cpus; 1447 - int ret; 1448 - unsigned long flags; 1299 + unsigned int cpu = dev->id; 1300 + int ret = 0; 1449 1301 struct cpufreq_policy *policy; 1450 1302 1451 1303 pr_debug("%s: unregistering CPU %u\n", __func__, cpu); 1452 1304 1453 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1454 - 1455 - policy = per_cpu(cpufreq_cpu_data, cpu); 1456 - 1457 - /* Save the policy somewhere when doing a light-weight tear-down */ 1458 - if (cpufreq_suspended) 1459 - per_cpu(cpufreq_cpu_data_fallback, cpu) = policy; 1460 - 1461 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1462 - 1305 + policy = cpufreq_cpu_get_raw(cpu); 1463 1306 if (!policy) { 1464 1307 pr_debug("%s: No cpu_data found\n", __func__); 1465 1308 return -EINVAL; ··· 1431 1354 pr_err("%s: Failed to stop governor\n", __func__); 1432 1355 return ret; 1433 1356 } 1434 - 1435 - strncpy(per_cpu(cpufreq_cpu_governor, cpu), 1436 - policy->governor->name, CPUFREQ_NAME_LEN); 1437 1357 } 1438 1358 1439 - down_read(&policy->rwsem); 1440 - cpus = cpumask_weight(policy->cpus); 1441 - up_read(&policy->rwsem); 1359 + down_write(&policy->rwsem); 1360 + cpumask_clear_cpu(cpu, policy->cpus); 1442 1361 1443 - if (cpu != policy->cpu) { 1444 - sysfs_remove_link(&dev->kobj, "cpufreq"); 1445 - } else if (cpus > 1) { 1362 + if (policy_is_inactive(policy)) { 1363 + if (has_target()) 1364 + strncpy(policy->last_governor, policy->governor->name, 1365 + CPUFREQ_NAME_LEN); 1366 + } else if (cpu == policy->cpu) { 1446 1367 /* Nominate new CPU */ 1447 - int new_cpu = cpumask_any_but(policy->cpus, cpu); 1448 - struct device *cpu_dev = get_cpu_device(new_cpu); 1368 + policy->cpu = cpumask_any(policy->cpus); 1369 + } 1370 + up_write(&policy->rwsem); 1449 1371 1450 - sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); 1451 - ret = update_policy_cpu(policy, new_cpu, cpu_dev); 1452 - if (ret) { 1453 - if (sysfs_create_link(&cpu_dev->kobj, &policy->kobj, 1454 - "cpufreq")) 1455 - pr_err("%s: Failed to restore kobj link to cpu:%d\n", 1456 - __func__, cpu_dev->id); 1457 - return ret; 1372 + /* Start governor again for active policy */ 1373 + if (!policy_is_inactive(policy)) { 1374 + if (has_target()) { 1375 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_START); 1376 + if (!ret) 1377 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 1378 + 1379 + if (ret) 1380 + pr_err("%s: Failed to start governor\n", __func__); 1458 1381 } 1459 - 1460 - if (!cpufreq_suspended) 1461 - pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", 1462 - __func__, new_cpu, cpu); 1463 1382 } else if (cpufreq_driver->stop_cpu) { 1464 1383 cpufreq_driver->stop_cpu(policy); 1465 1384 } 1466 1385 1467 - return 0; 1386 + return ret; 1468 1387 } 1469 1388 1470 1389 static int __cpufreq_remove_dev_finish(struct device *dev, 1471 1390 struct subsys_interface *sif) 1472 1391 { 1473 - unsigned int cpu = dev->id, cpus; 1392 + unsigned int cpu = dev->id; 1474 1393 int ret; 1475 - unsigned long flags; 1476 - struct cpufreq_policy *policy; 1477 - 1478 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1479 - policy = per_cpu(cpufreq_cpu_data, cpu); 1480 - per_cpu(cpufreq_cpu_data, cpu) = NULL; 1481 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1394 + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1482 1395 1483 1396 if (!policy) { 1484 1397 pr_debug("%s: No cpu_data found\n", __func__); 1485 1398 return -EINVAL; 1486 1399 } 1487 1400 1488 - down_write(&policy->rwsem); 1489 - cpus = cpumask_weight(policy->cpus); 1490 - 1491 - if (cpus > 1) 1492 - cpumask_clear_cpu(cpu, policy->cpus); 1493 - up_write(&policy->rwsem); 1401 + /* Only proceed for inactive policies */ 1402 + if (!policy_is_inactive(policy)) 1403 + return 0; 1494 1404 1495 1405 /* If cpu is last user of policy, free policy */ 1496 - if (cpus == 1) { 1497 - if (has_target()) { 1498 - ret = __cpufreq_governor(policy, 1499 - CPUFREQ_GOV_POLICY_EXIT); 1500 - if (ret) { 1501 - pr_err("%s: Failed to exit governor\n", 1502 - __func__); 1503 - return ret; 1504 - } 1505 - } 1506 - 1507 - if (!cpufreq_suspended) 1508 - cpufreq_policy_put_kobj(policy); 1509 - 1510 - /* 1511 - * Perform the ->exit() even during light-weight tear-down, 1512 - * since this is a core component, and is essential for the 1513 - * subsequent light-weight ->init() to succeed. 1514 - */ 1515 - if (cpufreq_driver->exit) 1516 - cpufreq_driver->exit(policy); 1517 - 1518 - /* Remove policy from list of active policies */ 1519 - write_lock_irqsave(&cpufreq_driver_lock, flags); 1520 - list_del(&policy->policy_list); 1521 - write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1522 - 1523 - if (!cpufreq_suspended) 1524 - cpufreq_policy_free(policy); 1525 - } else if (has_target()) { 1526 - ret = __cpufreq_governor(policy, CPUFREQ_GOV_START); 1527 - if (!ret) 1528 - ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); 1529 - 1406 + if (has_target()) { 1407 + ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT); 1530 1408 if (ret) { 1531 - pr_err("%s: Failed to start governor\n", __func__); 1409 + pr_err("%s: Failed to exit governor\n", __func__); 1532 1410 return ret; 1533 1411 } 1534 1412 } 1413 + 1414 + /* 1415 + * Perform the ->exit() even during light-weight tear-down, 1416 + * since this is a core component, and is essential for the 1417 + * subsequent light-weight ->init() to succeed. 1418 + */ 1419 + if (cpufreq_driver->exit) 1420 + cpufreq_driver->exit(policy); 1421 + 1422 + /* Free the policy only if the driver is getting removed. */ 1423 + if (sif) 1424 + cpufreq_policy_free(policy, true); 1535 1425 1536 1426 return 0; 1537 1427 } ··· 1513 1469 unsigned int cpu = dev->id; 1514 1470 int ret; 1515 1471 1516 - if (cpu_is_offline(cpu)) 1472 + /* 1473 + * Only possible if 'cpu' is getting physically removed now. A hotplug 1474 + * notifier should have already been called and we just need to remove 1475 + * link or free policy here. 1476 + */ 1477 + if (cpu_is_offline(cpu)) { 1478 + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1479 + struct cpumask mask; 1480 + 1481 + if (!policy) 1482 + return 0; 1483 + 1484 + cpumask_copy(&mask, policy->related_cpus); 1485 + cpumask_clear_cpu(cpu, &mask); 1486 + 1487 + /* 1488 + * Free policy only if all policy->related_cpus are removed 1489 + * physically. 1490 + */ 1491 + if (cpumask_intersects(&mask, cpu_present_mask)) { 1492 + remove_cpu_dev_symlink(policy, cpu); 1493 + return 0; 1494 + } 1495 + 1496 + cpufreq_policy_free(policy, true); 1517 1497 return 0; 1498 + } 1518 1499 1519 1500 ret = __cpufreq_remove_dev_prepare(dev, sif); 1520 1501 ··· 1636 1567 1637 1568 ret_freq = cpufreq_driver->get(policy->cpu); 1638 1569 1570 + /* Updating inactive policies is invalid, so avoid doing that. */ 1571 + if (unlikely(policy_is_inactive(policy))) 1572 + return ret_freq; 1573 + 1639 1574 if (ret_freq && policy->cur && 1640 1575 !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { 1641 1576 /* verify no discrepancy between actual and ··· 1729 1656 1730 1657 pr_debug("%s: Suspending Governors\n", __func__); 1731 1658 1732 - for_each_policy(policy) { 1659 + for_each_active_policy(policy) { 1733 1660 if (__cpufreq_governor(policy, CPUFREQ_GOV_STOP)) 1734 1661 pr_err("%s: Failed to stop governor for policy: %p\n", 1735 1662 __func__, policy); ··· 1763 1690 1764 1691 pr_debug("%s: Resuming Governors\n", __func__); 1765 1692 1766 - for_each_policy(policy) { 1693 + for_each_active_policy(policy) { 1767 1694 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) 1768 1695 pr_err("%s: Failed to resume driver: %p\n", __func__, 1769 1696 policy); ··· 1964 1891 * Failed after setting to intermediate freq? Driver should have 1965 1892 * reverted back to initial frequency and so should we. Check 1966 1893 * here for intermediate_freq instead of get_intermediate, in 1967 - * case we have't switched to intermediate freq at all. 1894 + * case we haven't switched to intermediate freq at all. 1968 1895 */ 1969 1896 if (unlikely(retval && intermediate_freq)) { 1970 1897 freqs.old = intermediate_freq; ··· 2165 2092 2166 2093 void cpufreq_unregister_governor(struct cpufreq_governor *governor) 2167 2094 { 2168 - int cpu; 2095 + struct cpufreq_policy *policy; 2096 + unsigned long flags; 2169 2097 2170 2098 if (!governor) 2171 2099 return; ··· 2174 2100 if (cpufreq_disabled()) 2175 2101 return; 2176 2102 2177 - for_each_present_cpu(cpu) { 2178 - if (cpu_online(cpu)) 2179 - continue; 2180 - if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) 2181 - strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); 2103 + /* clear last_governor for all inactive policies */ 2104 + read_lock_irqsave(&cpufreq_driver_lock, flags); 2105 + for_each_inactive_policy(policy) { 2106 + if (!strcmp(policy->last_governor, governor->name)) { 2107 + policy->governor = NULL; 2108 + strcpy(policy->last_governor, "\0"); 2109 + } 2182 2110 } 2111 + read_unlock_irqrestore(&cpufreq_driver_lock, flags); 2183 2112 2184 2113 mutex_lock(&cpufreq_governor_mutex); 2185 2114 list_del(&governor->governor_list); ··· 2381 2304 if (dev) { 2382 2305 switch (action & ~CPU_TASKS_FROZEN) { 2383 2306 case CPU_ONLINE: 2384 - __cpufreq_add_dev(dev, NULL); 2307 + cpufreq_add_dev(dev, NULL); 2385 2308 break; 2386 2309 2387 2310 case CPU_DOWN_PREPARE: ··· 2393 2316 break; 2394 2317 2395 2318 case CPU_DOWN_FAILED: 2396 - __cpufreq_add_dev(dev, NULL); 2319 + cpufreq_add_dev(dev, NULL); 2397 2320 break; 2398 2321 } 2399 2322 } ··· 2413 2336 struct cpufreq_policy *policy; 2414 2337 int ret = -EINVAL; 2415 2338 2416 - for_each_policy(policy) { 2339 + for_each_active_policy(policy) { 2417 2340 freq_table = cpufreq_frequency_get_table(policy->cpu); 2418 2341 if (freq_table) { 2419 2342 ret = cpufreq_frequency_table_cpuinfo(policy,
+16 -12
drivers/cpufreq/cpufreq_conservative.c
··· 148 148 return 0; 149 149 } 150 150 151 + static struct notifier_block cs_cpufreq_notifier_block = { 152 + .notifier_call = dbs_cpufreq_notifier, 153 + }; 154 + 151 155 /************************** sysfs interface ************************/ 152 156 static struct common_dbs_data cs_dbs_cdata; 153 157 ··· 321 317 322 318 /************************** sysfs end ************************/ 323 319 324 - static int cs_init(struct dbs_data *dbs_data) 320 + static int cs_init(struct dbs_data *dbs_data, bool notify) 325 321 { 326 322 struct cs_dbs_tuners *tuners; 327 323 ··· 340 336 dbs_data->tuners = tuners; 341 337 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO * 342 338 jiffies_to_usecs(10); 343 - mutex_init(&dbs_data->mutex); 339 + 340 + if (notify) 341 + cpufreq_register_notifier(&cs_cpufreq_notifier_block, 342 + CPUFREQ_TRANSITION_NOTIFIER); 343 + 344 344 return 0; 345 345 } 346 346 347 - static void cs_exit(struct dbs_data *dbs_data) 347 + static void cs_exit(struct dbs_data *dbs_data, bool notify) 348 348 { 349 + if (notify) 350 + cpufreq_unregister_notifier(&cs_cpufreq_notifier_block, 351 + CPUFREQ_TRANSITION_NOTIFIER); 352 + 349 353 kfree(dbs_data->tuners); 350 354 } 351 355 352 356 define_get_cpu_dbs_routines(cs_cpu_dbs_info); 353 - 354 - static struct notifier_block cs_cpufreq_notifier_block = { 355 - .notifier_call = dbs_cpufreq_notifier, 356 - }; 357 - 358 - static struct cs_ops cs_ops = { 359 - .notifier_block = &cs_cpufreq_notifier_block, 360 - }; 361 357 362 358 static struct common_dbs_data cs_dbs_cdata = { 363 359 .governor = GOV_CONSERVATIVE, ··· 367 363 .get_cpu_dbs_info_s = get_cpu_dbs_info_s, 368 364 .gov_dbs_timer = cs_dbs_timer, 369 365 .gov_check_cpu = cs_check_cpu, 370 - .gov_ops = &cs_ops, 371 366 .init = cs_init, 372 367 .exit = cs_exit, 368 + .mutex = __MUTEX_INITIALIZER(cs_dbs_cdata.mutex), 373 369 }; 374 370 375 371 static int cs_cpufreq_governor_dbs(struct cpufreq_policy *policy,
+217 -186
drivers/cpufreq/cpufreq_governor.c
··· 239 239 } 240 240 } 241 241 242 + static int cpufreq_governor_init(struct cpufreq_policy *policy, 243 + struct dbs_data *dbs_data, 244 + struct common_dbs_data *cdata) 245 + { 246 + unsigned int latency; 247 + int ret; 248 + 249 + if (dbs_data) { 250 + if (WARN_ON(have_governor_per_policy())) 251 + return -EINVAL; 252 + dbs_data->usage_count++; 253 + policy->governor_data = dbs_data; 254 + return 0; 255 + } 256 + 257 + dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL); 258 + if (!dbs_data) 259 + return -ENOMEM; 260 + 261 + dbs_data->cdata = cdata; 262 + dbs_data->usage_count = 1; 263 + 264 + ret = cdata->init(dbs_data, !policy->governor->initialized); 265 + if (ret) 266 + goto free_dbs_data; 267 + 268 + /* policy latency is in ns. Convert it to us first */ 269 + latency = policy->cpuinfo.transition_latency / 1000; 270 + if (latency == 0) 271 + latency = 1; 272 + 273 + /* Bring kernel and HW constraints together */ 274 + dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate, 275 + MIN_LATENCY_MULTIPLIER * latency); 276 + set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate, 277 + latency * LATENCY_MULTIPLIER)); 278 + 279 + if (!have_governor_per_policy()) { 280 + if (WARN_ON(cpufreq_get_global_kobject())) { 281 + ret = -EINVAL; 282 + goto cdata_exit; 283 + } 284 + cdata->gdbs_data = dbs_data; 285 + } 286 + 287 + ret = sysfs_create_group(get_governor_parent_kobj(policy), 288 + get_sysfs_attr(dbs_data)); 289 + if (ret) 290 + goto put_kobj; 291 + 292 + policy->governor_data = dbs_data; 293 + 294 + return 0; 295 + 296 + put_kobj: 297 + if (!have_governor_per_policy()) { 298 + cdata->gdbs_data = NULL; 299 + cpufreq_put_global_kobject(); 300 + } 301 + cdata_exit: 302 + cdata->exit(dbs_data, !policy->governor->initialized); 303 + free_dbs_data: 304 + kfree(dbs_data); 305 + return ret; 306 + } 307 + 308 + static void cpufreq_governor_exit(struct cpufreq_policy *policy, 309 + struct dbs_data *dbs_data) 310 + { 311 + struct common_dbs_data *cdata = dbs_data->cdata; 312 + 313 + policy->governor_data = NULL; 314 + if (!--dbs_data->usage_count) { 315 + sysfs_remove_group(get_governor_parent_kobj(policy), 316 + get_sysfs_attr(dbs_data)); 317 + 318 + if (!have_governor_per_policy()) { 319 + cdata->gdbs_data = NULL; 320 + cpufreq_put_global_kobject(); 321 + } 322 + 323 + cdata->exit(dbs_data, policy->governor->initialized == 1); 324 + kfree(dbs_data); 325 + } 326 + } 327 + 328 + static int cpufreq_governor_start(struct cpufreq_policy *policy, 329 + struct dbs_data *dbs_data) 330 + { 331 + struct common_dbs_data *cdata = dbs_data->cdata; 332 + unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu; 333 + struct cpu_dbs_common_info *cpu_cdbs = cdata->get_cpu_cdbs(cpu); 334 + int io_busy = 0; 335 + 336 + if (!policy->cur) 337 + return -EINVAL; 338 + 339 + if (cdata->governor == GOV_CONSERVATIVE) { 340 + struct cs_dbs_tuners *cs_tuners = dbs_data->tuners; 341 + 342 + sampling_rate = cs_tuners->sampling_rate; 343 + ignore_nice = cs_tuners->ignore_nice_load; 344 + } else { 345 + struct od_dbs_tuners *od_tuners = dbs_data->tuners; 346 + 347 + sampling_rate = od_tuners->sampling_rate; 348 + ignore_nice = od_tuners->ignore_nice_load; 349 + io_busy = od_tuners->io_is_busy; 350 + } 351 + 352 + for_each_cpu(j, policy->cpus) { 353 + struct cpu_dbs_common_info *j_cdbs = cdata->get_cpu_cdbs(j); 354 + unsigned int prev_load; 355 + 356 + j_cdbs->cpu = j; 357 + j_cdbs->cur_policy = policy; 358 + j_cdbs->prev_cpu_idle = 359 + get_cpu_idle_time(j, &j_cdbs->prev_cpu_wall, io_busy); 360 + 361 + prev_load = (unsigned int)(j_cdbs->prev_cpu_wall - 362 + j_cdbs->prev_cpu_idle); 363 + j_cdbs->prev_load = 100 * prev_load / 364 + (unsigned int)j_cdbs->prev_cpu_wall; 365 + 366 + if (ignore_nice) 367 + j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; 368 + 369 + mutex_init(&j_cdbs->timer_mutex); 370 + INIT_DEFERRABLE_WORK(&j_cdbs->work, cdata->gov_dbs_timer); 371 + } 372 + 373 + if (cdata->governor == GOV_CONSERVATIVE) { 374 + struct cs_cpu_dbs_info_s *cs_dbs_info = 375 + cdata->get_cpu_dbs_info_s(cpu); 376 + 377 + cs_dbs_info->down_skip = 0; 378 + cs_dbs_info->enable = 1; 379 + cs_dbs_info->requested_freq = policy->cur; 380 + } else { 381 + struct od_ops *od_ops = cdata->gov_ops; 382 + struct od_cpu_dbs_info_s *od_dbs_info = cdata->get_cpu_dbs_info_s(cpu); 383 + 384 + od_dbs_info->rate_mult = 1; 385 + od_dbs_info->sample_type = OD_NORMAL_SAMPLE; 386 + od_ops->powersave_bias_init_cpu(cpu); 387 + } 388 + 389 + /* Initiate timer time stamp */ 390 + cpu_cdbs->time_stamp = ktime_get(); 391 + 392 + gov_queue_work(dbs_data, policy, delay_for_sampling_rate(sampling_rate), 393 + true); 394 + return 0; 395 + } 396 + 397 + static void cpufreq_governor_stop(struct cpufreq_policy *policy, 398 + struct dbs_data *dbs_data) 399 + { 400 + struct common_dbs_data *cdata = dbs_data->cdata; 401 + unsigned int cpu = policy->cpu; 402 + struct cpu_dbs_common_info *cpu_cdbs = cdata->get_cpu_cdbs(cpu); 403 + 404 + if (cdata->governor == GOV_CONSERVATIVE) { 405 + struct cs_cpu_dbs_info_s *cs_dbs_info = 406 + cdata->get_cpu_dbs_info_s(cpu); 407 + 408 + cs_dbs_info->enable = 0; 409 + } 410 + 411 + gov_cancel_work(dbs_data, policy); 412 + 413 + mutex_destroy(&cpu_cdbs->timer_mutex); 414 + cpu_cdbs->cur_policy = NULL; 415 + } 416 + 417 + static void cpufreq_governor_limits(struct cpufreq_policy *policy, 418 + struct dbs_data *dbs_data) 419 + { 420 + struct common_dbs_data *cdata = dbs_data->cdata; 421 + unsigned int cpu = policy->cpu; 422 + struct cpu_dbs_common_info *cpu_cdbs = cdata->get_cpu_cdbs(cpu); 423 + 424 + if (!cpu_cdbs->cur_policy) 425 + return; 426 + 427 + mutex_lock(&cpu_cdbs->timer_mutex); 428 + if (policy->max < cpu_cdbs->cur_policy->cur) 429 + __cpufreq_driver_target(cpu_cdbs->cur_policy, policy->max, 430 + CPUFREQ_RELATION_H); 431 + else if (policy->min > cpu_cdbs->cur_policy->cur) 432 + __cpufreq_driver_target(cpu_cdbs->cur_policy, policy->min, 433 + CPUFREQ_RELATION_L); 434 + dbs_check_cpu(dbs_data, cpu); 435 + mutex_unlock(&cpu_cdbs->timer_mutex); 436 + } 437 + 242 438 int cpufreq_governor_dbs(struct cpufreq_policy *policy, 243 - struct common_dbs_data *cdata, unsigned int event) 439 + struct common_dbs_data *cdata, unsigned int event) 244 440 { 245 441 struct dbs_data *dbs_data; 246 - struct od_cpu_dbs_info_s *od_dbs_info = NULL; 247 - struct cs_cpu_dbs_info_s *cs_dbs_info = NULL; 248 - struct od_ops *od_ops = NULL; 249 - struct od_dbs_tuners *od_tuners = NULL; 250 - struct cs_dbs_tuners *cs_tuners = NULL; 251 - struct cpu_dbs_common_info *cpu_cdbs; 252 - unsigned int sampling_rate, latency, ignore_nice, j, cpu = policy->cpu; 253 - int io_busy = 0; 254 - int rc; 442 + int ret = 0; 443 + 444 + /* Lock governor to block concurrent initialization of governor */ 445 + mutex_lock(&cdata->mutex); 255 446 256 447 if (have_governor_per_policy()) 257 448 dbs_data = policy->governor_data; 258 449 else 259 450 dbs_data = cdata->gdbs_data; 260 451 261 - WARN_ON(!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT)); 452 + if (WARN_ON(!dbs_data && (event != CPUFREQ_GOV_POLICY_INIT))) { 453 + ret = -EINVAL; 454 + goto unlock; 455 + } 262 456 263 457 switch (event) { 264 458 case CPUFREQ_GOV_POLICY_INIT: 265 - if (have_governor_per_policy()) { 266 - WARN_ON(dbs_data); 267 - } else if (dbs_data) { 268 - dbs_data->usage_count++; 269 - policy->governor_data = dbs_data; 270 - return 0; 271 - } 272 - 273 - dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL); 274 - if (!dbs_data) { 275 - pr_err("%s: POLICY_INIT: kzalloc failed\n", __func__); 276 - return -ENOMEM; 277 - } 278 - 279 - dbs_data->cdata = cdata; 280 - dbs_data->usage_count = 1; 281 - rc = cdata->init(dbs_data); 282 - if (rc) { 283 - pr_err("%s: POLICY_INIT: init() failed\n", __func__); 284 - kfree(dbs_data); 285 - return rc; 286 - } 287 - 288 - if (!have_governor_per_policy()) 289 - WARN_ON(cpufreq_get_global_kobject()); 290 - 291 - rc = sysfs_create_group(get_governor_parent_kobj(policy), 292 - get_sysfs_attr(dbs_data)); 293 - if (rc) { 294 - cdata->exit(dbs_data); 295 - kfree(dbs_data); 296 - return rc; 297 - } 298 - 299 - policy->governor_data = dbs_data; 300 - 301 - /* policy latency is in ns. Convert it to us first */ 302 - latency = policy->cpuinfo.transition_latency / 1000; 303 - if (latency == 0) 304 - latency = 1; 305 - 306 - /* Bring kernel and HW constraints together */ 307 - dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate, 308 - MIN_LATENCY_MULTIPLIER * latency); 309 - set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate, 310 - latency * LATENCY_MULTIPLIER)); 311 - 312 - if ((cdata->governor == GOV_CONSERVATIVE) && 313 - (!policy->governor->initialized)) { 314 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops; 315 - 316 - cpufreq_register_notifier(cs_ops->notifier_block, 317 - CPUFREQ_TRANSITION_NOTIFIER); 318 - } 319 - 320 - if (!have_governor_per_policy()) 321 - cdata->gdbs_data = dbs_data; 322 - 323 - return 0; 459 + ret = cpufreq_governor_init(policy, dbs_data, cdata); 460 + break; 324 461 case CPUFREQ_GOV_POLICY_EXIT: 325 - if (!--dbs_data->usage_count) { 326 - sysfs_remove_group(get_governor_parent_kobj(policy), 327 - get_sysfs_attr(dbs_data)); 328 - 329 - if (!have_governor_per_policy()) 330 - cpufreq_put_global_kobject(); 331 - 332 - if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) && 333 - (policy->governor->initialized == 1)) { 334 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops; 335 - 336 - cpufreq_unregister_notifier(cs_ops->notifier_block, 337 - CPUFREQ_TRANSITION_NOTIFIER); 338 - } 339 - 340 - cdata->exit(dbs_data); 341 - kfree(dbs_data); 342 - cdata->gdbs_data = NULL; 343 - } 344 - 345 - policy->governor_data = NULL; 346 - return 0; 347 - } 348 - 349 - cpu_cdbs = dbs_data->cdata->get_cpu_cdbs(cpu); 350 - 351 - if (dbs_data->cdata->governor == GOV_CONSERVATIVE) { 352 - cs_tuners = dbs_data->tuners; 353 - cs_dbs_info = dbs_data->cdata->get_cpu_dbs_info_s(cpu); 354 - sampling_rate = cs_tuners->sampling_rate; 355 - ignore_nice = cs_tuners->ignore_nice_load; 356 - } else { 357 - od_tuners = dbs_data->tuners; 358 - od_dbs_info = dbs_data->cdata->get_cpu_dbs_info_s(cpu); 359 - sampling_rate = od_tuners->sampling_rate; 360 - ignore_nice = od_tuners->ignore_nice_load; 361 - od_ops = dbs_data->cdata->gov_ops; 362 - io_busy = od_tuners->io_is_busy; 363 - } 364 - 365 - switch (event) { 462 + cpufreq_governor_exit(policy, dbs_data); 463 + break; 366 464 case CPUFREQ_GOV_START: 367 - if (!policy->cur) 368 - return -EINVAL; 369 - 370 - mutex_lock(&dbs_data->mutex); 371 - 372 - for_each_cpu(j, policy->cpus) { 373 - struct cpu_dbs_common_info *j_cdbs = 374 - dbs_data->cdata->get_cpu_cdbs(j); 375 - unsigned int prev_load; 376 - 377 - j_cdbs->cpu = j; 378 - j_cdbs->cur_policy = policy; 379 - j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, 380 - &j_cdbs->prev_cpu_wall, io_busy); 381 - 382 - prev_load = (unsigned int) 383 - (j_cdbs->prev_cpu_wall - j_cdbs->prev_cpu_idle); 384 - j_cdbs->prev_load = 100 * prev_load / 385 - (unsigned int) j_cdbs->prev_cpu_wall; 386 - 387 - if (ignore_nice) 388 - j_cdbs->prev_cpu_nice = 389 - kcpustat_cpu(j).cpustat[CPUTIME_NICE]; 390 - 391 - mutex_init(&j_cdbs->timer_mutex); 392 - INIT_DEFERRABLE_WORK(&j_cdbs->work, 393 - dbs_data->cdata->gov_dbs_timer); 394 - } 395 - 396 - if (dbs_data->cdata->governor == GOV_CONSERVATIVE) { 397 - cs_dbs_info->down_skip = 0; 398 - cs_dbs_info->enable = 1; 399 - cs_dbs_info->requested_freq = policy->cur; 400 - } else { 401 - od_dbs_info->rate_mult = 1; 402 - od_dbs_info->sample_type = OD_NORMAL_SAMPLE; 403 - od_ops->powersave_bias_init_cpu(cpu); 404 - } 405 - 406 - mutex_unlock(&dbs_data->mutex); 407 - 408 - /* Initiate timer time stamp */ 409 - cpu_cdbs->time_stamp = ktime_get(); 410 - 411 - gov_queue_work(dbs_data, policy, 412 - delay_for_sampling_rate(sampling_rate), true); 465 + ret = cpufreq_governor_start(policy, dbs_data); 413 466 break; 414 - 415 467 case CPUFREQ_GOV_STOP: 416 - if (dbs_data->cdata->governor == GOV_CONSERVATIVE) 417 - cs_dbs_info->enable = 0; 418 - 419 - gov_cancel_work(dbs_data, policy); 420 - 421 - mutex_lock(&dbs_data->mutex); 422 - mutex_destroy(&cpu_cdbs->timer_mutex); 423 - cpu_cdbs->cur_policy = NULL; 424 - 425 - mutex_unlock(&dbs_data->mutex); 426 - 468 + cpufreq_governor_stop(policy, dbs_data); 427 469 break; 428 - 429 470 case CPUFREQ_GOV_LIMITS: 430 - mutex_lock(&dbs_data->mutex); 431 - if (!cpu_cdbs->cur_policy) { 432 - mutex_unlock(&dbs_data->mutex); 433 - break; 434 - } 435 - mutex_lock(&cpu_cdbs->timer_mutex); 436 - if (policy->max < cpu_cdbs->cur_policy->cur) 437 - __cpufreq_driver_target(cpu_cdbs->cur_policy, 438 - policy->max, CPUFREQ_RELATION_H); 439 - else if (policy->min > cpu_cdbs->cur_policy->cur) 440 - __cpufreq_driver_target(cpu_cdbs->cur_policy, 441 - policy->min, CPUFREQ_RELATION_L); 442 - dbs_check_cpu(dbs_data, cpu); 443 - mutex_unlock(&cpu_cdbs->timer_mutex); 444 - mutex_unlock(&dbs_data->mutex); 471 + cpufreq_governor_limits(policy, dbs_data); 445 472 break; 446 473 } 447 - return 0; 474 + 475 + unlock: 476 + mutex_unlock(&cdata->mutex); 477 + 478 + return ret; 448 479 } 449 480 EXPORT_SYMBOL_GPL(cpufreq_governor_dbs);
+7 -9
drivers/cpufreq/cpufreq_governor.h
··· 208 208 void *(*get_cpu_dbs_info_s)(int cpu); 209 209 void (*gov_dbs_timer)(struct work_struct *work); 210 210 void (*gov_check_cpu)(int cpu, unsigned int load); 211 - int (*init)(struct dbs_data *dbs_data); 212 - void (*exit)(struct dbs_data *dbs_data); 211 + int (*init)(struct dbs_data *dbs_data, bool notify); 212 + void (*exit)(struct dbs_data *dbs_data, bool notify); 213 213 214 214 /* Governor specific ops, see below */ 215 215 void *gov_ops; 216 + 217 + /* 218 + * Protects governor's data (struct dbs_data and struct common_dbs_data) 219 + */ 220 + struct mutex mutex; 216 221 }; 217 222 218 223 /* Governor Per policy data */ ··· 226 221 unsigned int min_sampling_rate; 227 222 int usage_count; 228 223 void *tuners; 229 - 230 - /* dbs_mutex protects dbs_enable in governor start/stop */ 231 - struct mutex mutex; 232 224 }; 233 225 234 226 /* Governor specific ops, will be passed to dbs_data->gov_ops */ ··· 234 232 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy, 235 233 unsigned int freq_next, unsigned int relation); 236 234 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq); 237 - }; 238 - 239 - struct cs_ops { 240 - struct notifier_block *notifier_block; 241 235 }; 242 236 243 237 static inline int delay_for_sampling_rate(unsigned int sampling_rate)
+3 -3
drivers/cpufreq/cpufreq_ondemand.c
··· 475 475 476 476 /************************** sysfs end ************************/ 477 477 478 - static int od_init(struct dbs_data *dbs_data) 478 + static int od_init(struct dbs_data *dbs_data, bool notify) 479 479 { 480 480 struct od_dbs_tuners *tuners; 481 481 u64 idle_time; ··· 513 513 tuners->io_is_busy = should_io_be_busy(); 514 514 515 515 dbs_data->tuners = tuners; 516 - mutex_init(&dbs_data->mutex); 517 516 return 0; 518 517 } 519 518 520 - static void od_exit(struct dbs_data *dbs_data) 519 + static void od_exit(struct dbs_data *dbs_data, bool notify) 521 520 { 522 521 kfree(dbs_data->tuners); 523 522 } ··· 540 541 .gov_ops = &od_ops, 541 542 .init = od_init, 542 543 .exit = od_exit, 544 + .mutex = __MUTEX_INITIALIZER(od_dbs_cdata.mutex), 543 545 }; 544 546 545 547 static void od_set_powersave_bias(unsigned int powersave_bias)
+2 -2
drivers/cpufreq/gx-suspmod.c
··· 144 144 145 145 146 146 /** 147 - * we can detect a core multipiler from dir0_lsb 147 + * we can detect a core multiplier from dir0_lsb 148 148 * from GX1 datasheet p.56, 149 149 * MULT[3:0]: 150 150 * 0000 = SYSCLK multiplied by 4 (test only) ··· 346 346 347 347 /* it needs to be assured that at least one supported frequency is 348 348 * within policy->min and policy->max. If it is not, policy->max 349 - * needs to be increased until one freuqency is supported. 349 + * needs to be increased until one frequency is supported. 350 350 * policy->min may not be decreased, though. This way we guarantee a 351 351 * specific processing capacity. 352 352 */
+42 -30
drivers/cpufreq/intel_pstate.c
··· 48 48 return ((int64_t)x * (int64_t)y) >> FRAC_BITS; 49 49 } 50 50 51 - static inline int32_t div_fp(int32_t x, int32_t y) 51 + static inline int32_t div_fp(s64 x, s64 y) 52 52 { 53 - return div_s64((int64_t)x << FRAC_BITS, y); 53 + return div64_s64((int64_t)x << FRAC_BITS, y); 54 54 } 55 55 56 56 static inline int ceiling_fp(int32_t x) ··· 68 68 int32_t core_pct_busy; 69 69 u64 aperf; 70 70 u64 mperf; 71 + u64 tsc; 71 72 int freq; 72 73 ktime_t time; 73 74 }; ··· 110 109 ktime_t last_sample_time; 111 110 u64 prev_aperf; 112 111 u64 prev_mperf; 112 + u64 prev_tsc; 113 113 struct sample sample; 114 114 }; 115 115 ··· 398 396 399 397 update_turbo_state(); 400 398 if (limits.turbo_disabled) { 401 - pr_warn("Turbo disabled by BIOS or unavailable on processor\n"); 399 + pr_warn("intel_pstate: Turbo disabled by BIOS or unavailable on processor\n"); 402 400 return -EPERM; 403 401 } 404 402 ··· 486 484 static void intel_pstate_hwp_enable(void) 487 485 { 488 486 hwp_active++; 489 - pr_info("intel_pstate HWP enabled\n"); 487 + pr_info("intel_pstate: HWP enabled\n"); 490 488 491 489 wrmsrl( MSR_PM_ENABLE, 0x1); 492 490 } ··· 537 535 538 536 val |= vid; 539 537 540 - wrmsrl(MSR_IA32_PERF_CTL, val); 538 + wrmsrl_on_cpu(cpudata->cpu, MSR_IA32_PERF_CTL, val); 541 539 } 542 540 543 541 #define BYT_BCLK_FREQS 5 ··· 706 704 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf); 707 705 } 708 706 709 - static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) 707 + static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate, bool force) 710 708 { 711 709 int max_perf, min_perf; 712 710 713 - update_turbo_state(); 711 + if (force) { 712 + update_turbo_state(); 714 713 715 - intel_pstate_get_min_max(cpu, &min_perf, &max_perf); 714 + intel_pstate_get_min_max(cpu, &min_perf, &max_perf); 716 715 717 - pstate = clamp_t(int, pstate, min_perf, max_perf); 716 + pstate = clamp_t(int, pstate, min_perf, max_perf); 718 717 719 - if (pstate == cpu->pstate.current_pstate) 720 - return; 721 - 718 + if (pstate == cpu->pstate.current_pstate) 719 + return; 720 + } 722 721 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); 723 722 724 723 cpu->pstate.current_pstate = pstate; ··· 736 733 737 734 if (pstate_funcs.get_vid) 738 735 pstate_funcs.get_vid(cpu); 739 - intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); 736 + intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate, false); 740 737 } 741 738 742 739 static inline void intel_pstate_calc_busy(struct cpudata *cpu) ··· 759 756 { 760 757 u64 aperf, mperf; 761 758 unsigned long flags; 759 + u64 tsc; 762 760 763 761 local_irq_save(flags); 764 762 rdmsrl(MSR_IA32_APERF, aperf); 765 763 rdmsrl(MSR_IA32_MPERF, mperf); 764 + tsc = native_read_tsc(); 766 765 local_irq_restore(flags); 767 766 768 767 cpu->last_sample_time = cpu->sample.time; 769 768 cpu->sample.time = ktime_get(); 770 769 cpu->sample.aperf = aperf; 771 770 cpu->sample.mperf = mperf; 771 + cpu->sample.tsc = tsc; 772 772 cpu->sample.aperf -= cpu->prev_aperf; 773 773 cpu->sample.mperf -= cpu->prev_mperf; 774 + cpu->sample.tsc -= cpu->prev_tsc; 774 775 775 776 intel_pstate_calc_busy(cpu); 776 777 777 778 cpu->prev_aperf = aperf; 778 779 cpu->prev_mperf = mperf; 780 + cpu->prev_tsc = tsc; 779 781 } 780 782 781 783 static inline void intel_hwp_set_sample_time(struct cpudata *cpu) ··· 802 794 static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu) 803 795 { 804 796 int32_t core_busy, max_pstate, current_pstate, sample_ratio; 805 - u32 duration_us; 797 + s64 duration_us; 806 798 u32 sample_time; 807 799 808 800 /* ··· 829 821 * to adjust our busyness. 830 822 */ 831 823 sample_time = pid_params.sample_rate_ms * USEC_PER_MSEC; 832 - duration_us = (u32) ktime_us_delta(cpu->sample.time, 833 - cpu->last_sample_time); 824 + duration_us = ktime_us_delta(cpu->sample.time, 825 + cpu->last_sample_time); 834 826 if (duration_us > sample_time * 3) { 835 827 sample_ratio = div_fp(int_tofp(sample_time), 836 828 int_tofp(duration_us)); ··· 845 837 int32_t busy_scaled; 846 838 struct _pid *pid; 847 839 signed int ctl; 840 + int from; 841 + struct sample *sample; 842 + 843 + from = cpu->pstate.current_pstate; 848 844 849 845 pid = &cpu->pid; 850 846 busy_scaled = intel_pstate_get_scaled_busy(cpu); ··· 856 844 ctl = pid_calc(pid, busy_scaled); 857 845 858 846 /* Negative values of ctl increase the pstate and vice versa */ 859 - intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl); 847 + intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl, true); 848 + 849 + sample = &cpu->sample; 850 + trace_pstate_sample(fp_toint(sample->core_pct_busy), 851 + fp_toint(busy_scaled), 852 + from, 853 + cpu->pstate.current_pstate, 854 + sample->mperf, 855 + sample->aperf, 856 + sample->tsc, 857 + sample->freq); 860 858 } 861 859 862 860 static void intel_hwp_timer_func(unsigned long __data) ··· 880 858 static void intel_pstate_timer_func(unsigned long __data) 881 859 { 882 860 struct cpudata *cpu = (struct cpudata *) __data; 883 - struct sample *sample; 884 861 885 862 intel_pstate_sample(cpu); 886 863 887 - sample = &cpu->sample; 888 - 889 864 intel_pstate_adjust_busy_pstate(cpu); 890 - 891 - trace_pstate_sample(fp_toint(sample->core_pct_busy), 892 - fp_toint(intel_pstate_get_scaled_busy(cpu)), 893 - cpu->pstate.current_pstate, 894 - sample->mperf, 895 - sample->aperf, 896 - sample->freq); 897 865 898 866 intel_pstate_set_sample_time(cpu); 899 867 } ··· 947 935 948 936 add_timer_on(&cpu->timer, cpunum); 949 937 950 - pr_debug("Intel pstate controlling: cpu %d\n", cpunum); 938 + pr_debug("intel_pstate: controlling: cpu %d\n", cpunum); 951 939 952 940 return 0; 953 941 } ··· 1013 1001 int cpu_num = policy->cpu; 1014 1002 struct cpudata *cpu = all_cpu_data[cpu_num]; 1015 1003 1016 - pr_info("intel_pstate CPU %d exiting\n", cpu_num); 1004 + pr_debug("intel_pstate: CPU %d exiting\n", cpu_num); 1017 1005 1018 1006 del_timer_sync(&all_cpu_data[cpu_num]->timer); 1019 1007 if (hwp_active) 1020 1008 return; 1021 1009 1022 - intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); 1010 + intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate, false); 1023 1011 } 1024 1012 1025 1013 static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
+10 -10
drivers/cpufreq/pxa2xx-cpufreq.c
··· 56 56 MODULE_PARM_DESC(pxa27x_maxfreq, "Set the pxa27x maxfreq in MHz" 57 57 "(typically 624=>pxa270, 416=>pxa271, 520=>pxa272)"); 58 58 59 - typedef struct { 59 + struct pxa_freqs { 60 60 unsigned int khz; 61 61 unsigned int membus; 62 62 unsigned int cccr; ··· 64 64 unsigned int cclkcfg; 65 65 int vmin; 66 66 int vmax; 67 - } pxa_freqs_t; 67 + }; 68 68 69 69 /* Define the refresh period in mSec for the SDRAM and the number of rows */ 70 70 #define SDRAM_TREF 64 /* standard 64ms SDRAM */ ··· 86 86 /* Use the run mode frequencies for the CPUFREQ_POLICY_PERFORMANCE policy */ 87 87 #define CCLKCFG CCLKCFG_TURBO | CCLKCFG_FCS 88 88 89 - static pxa_freqs_t pxa255_run_freqs[] = 89 + static const struct pxa_freqs pxa255_run_freqs[] = 90 90 { 91 91 /* CPU MEMBUS CCCR DIV2 CCLKCFG run turbo PXbus SDRAM */ 92 92 { 99500, 99500, 0x121, 1, CCLKCFG, -1, -1}, /* 99, 99, 50, 50 */ ··· 98 98 }; 99 99 100 100 /* Use the turbo mode frequencies for the CPUFREQ_POLICY_POWERSAVE policy */ 101 - static pxa_freqs_t pxa255_turbo_freqs[] = 101 + static const struct pxa_freqs pxa255_turbo_freqs[] = 102 102 { 103 103 /* CPU MEMBUS CCCR DIV2 CCLKCFG run turbo PXbus SDRAM */ 104 104 { 99500, 99500, 0x121, 1, CCLKCFG, -1, -1}, /* 99, 99, 50, 50 */ ··· 153 153 ((HT) ? CCLKCFG_HALFTURBO : 0) | \ 154 154 ((T) ? CCLKCFG_TURBO : 0)) 155 155 156 - static pxa_freqs_t pxa27x_freqs[] = { 156 + static struct pxa_freqs pxa27x_freqs[] = { 157 157 {104000, 104000, PXA27x_CCCR(1, 8, 2), 0, CCLKCFG2(1, 0, 1), 900000, 1705000 }, 158 158 {156000, 104000, PXA27x_CCCR(1, 8, 3), 0, CCLKCFG2(1, 0, 1), 1000000, 1705000 }, 159 159 {208000, 208000, PXA27x_CCCR(0, 16, 2), 1, CCLKCFG2(0, 0, 1), 1180000, 1705000 }, ··· 171 171 172 172 #ifdef CONFIG_REGULATOR 173 173 174 - static int pxa_cpufreq_change_voltage(pxa_freqs_t *pxa_freq) 174 + static int pxa_cpufreq_change_voltage(const struct pxa_freqs *pxa_freq) 175 175 { 176 176 int ret = 0; 177 177 int vmin, vmax; ··· 202 202 } 203 203 } 204 204 #else 205 - static int pxa_cpufreq_change_voltage(pxa_freqs_t *pxa_freq) 205 + static int pxa_cpufreq_change_voltage(struct pxa_freqs *pxa_freq) 206 206 { 207 207 return 0; 208 208 } ··· 211 211 #endif 212 212 213 213 static void find_freq_tables(struct cpufreq_frequency_table **freq_table, 214 - pxa_freqs_t **pxa_freqs) 214 + const struct pxa_freqs **pxa_freqs) 215 215 { 216 216 if (cpu_is_pxa25x()) { 217 217 if (!pxa255_turbo_table) { ··· 270 270 static int pxa_set_target(struct cpufreq_policy *policy, unsigned int idx) 271 271 { 272 272 struct cpufreq_frequency_table *pxa_freqs_table; 273 - pxa_freqs_t *pxa_freq_settings; 273 + const struct pxa_freqs *pxa_freq_settings; 274 274 unsigned long flags; 275 275 unsigned int new_freq_cpu, new_freq_mem; 276 276 unsigned int unused, preset_mdrefr, postset_mdrefr, cclkcfg; ··· 361 361 int i; 362 362 unsigned int freq; 363 363 struct cpufreq_frequency_table *pxa255_freq_table; 364 - pxa_freqs_t *pxa255_freqs; 364 + const struct pxa_freqs *pxa255_freqs; 365 365 366 366 /* try to guess pxa27x cpu */ 367 367 if (cpu_is_pxa27x())
+21 -11
drivers/cpufreq/qoriq-cpufreq.c
··· 27 27 28 28 /** 29 29 * struct cpu_data 30 - * @parent: the parent node of cpu clock 30 + * @pclk: the parent clock of cpu 31 31 * @table: frequency table 32 32 */ 33 33 struct cpu_data { 34 - struct device_node *parent; 34 + struct clk **pclk; 35 35 struct cpufreq_frequency_table *table; 36 36 }; 37 37 ··· 196 196 197 197 static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) 198 198 { 199 - struct device_node *np; 199 + struct device_node *np, *pnode; 200 200 int i, count, ret; 201 201 u32 freq, mask; 202 202 struct clk *clk; ··· 219 219 goto err_nomem2; 220 220 } 221 221 222 - data->parent = of_parse_phandle(np, "clocks", 0); 223 - if (!data->parent) { 222 + pnode = of_parse_phandle(np, "clocks", 0); 223 + if (!pnode) { 224 224 pr_err("%s: could not get clock information\n", __func__); 225 225 goto err_nomem2; 226 226 } 227 227 228 - count = of_property_count_strings(data->parent, "clock-names"); 228 + count = of_property_count_strings(pnode, "clock-names"); 229 + data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL); 230 + if (!data->pclk) { 231 + pr_err("%s: no memory\n", __func__); 232 + goto err_node; 233 + } 234 + 229 235 table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL); 230 236 if (!table) { 231 237 pr_err("%s: no memory\n", __func__); 232 - goto err_node; 238 + goto err_pclk; 233 239 } 234 240 235 241 if (fmask) ··· 244 238 mask = 0x0; 245 239 246 240 for (i = 0; i < count; i++) { 247 - clk = of_clk_get(data->parent, i); 241 + clk = of_clk_get(pnode, i); 242 + data->pclk[i] = clk; 248 243 freq = clk_get_rate(clk); 249 244 /* 250 245 * the clock is valid if its frequency is not masked ··· 280 273 policy->cpuinfo.transition_latency = u64temp + 1; 281 274 282 275 of_node_put(np); 276 + of_node_put(pnode); 283 277 284 278 return 0; 285 279 286 280 err_nomem1: 287 281 kfree(table); 282 + err_pclk: 283 + kfree(data->pclk); 288 284 err_node: 289 - of_node_put(data->parent); 285 + of_node_put(pnode); 290 286 err_nomem2: 291 287 policy->driver_data = NULL; 292 288 kfree(data); ··· 303 293 { 304 294 struct cpu_data *data = policy->driver_data; 305 295 306 - of_node_put(data->parent); 296 + kfree(data->pclk); 307 297 kfree(data->table); 308 298 kfree(data); 309 299 policy->driver_data = NULL; ··· 317 307 struct clk *parent; 318 308 struct cpu_data *data = policy->driver_data; 319 309 320 - parent = of_clk_get(data->parent, data->table[index].driver_data); 310 + parent = data->pclk[data->table[index].driver_data]; 321 311 return clk_set_parent(policy->clk, parent); 322 312 } 323 313
+4 -1
include/linux/cpufreq.h
··· 65 65 66 66 unsigned int shared_type; /* ACPI: ANY or ALL affected CPUs 67 67 should set cpufreq */ 68 - unsigned int cpu; /* cpu nr of CPU managing this policy */ 68 + unsigned int cpu; /* cpu managing this policy, must be online */ 69 + unsigned int kobj_cpu; /* cpu managing sysfs files, can be offline */ 70 + 69 71 struct clk *clk; 70 72 struct cpufreq_cpuinfo cpuinfo;/* see above */ 71 73 ··· 82 80 struct cpufreq_governor *governor; /* see below */ 83 81 void *governor_data; 84 82 bool governor_enabled; /* governor start/stop flag */ 83 + char last_governor[CPUFREQ_NAME_LEN]; /* last governor used */ 85 84 86 85 struct work_struct update; /* if update_policy() needs to be 87 86 * called, but you're in IRQ context */
+17 -8
include/trace/events/power.h
··· 42 42 43 43 TP_PROTO(u32 core_busy, 44 44 u32 scaled_busy, 45 - u32 state, 45 + u32 from, 46 + u32 to, 46 47 u64 mperf, 47 48 u64 aperf, 49 + u64 tsc, 48 50 u32 freq 49 51 ), 50 52 51 53 TP_ARGS(core_busy, 52 54 scaled_busy, 53 - state, 55 + from, 56 + to, 54 57 mperf, 55 58 aperf, 59 + tsc, 56 60 freq 57 61 ), 58 62 59 63 TP_STRUCT__entry( 60 64 __field(u32, core_busy) 61 65 __field(u32, scaled_busy) 62 - __field(u32, state) 66 + __field(u32, from) 67 + __field(u32, to) 63 68 __field(u64, mperf) 64 69 __field(u64, aperf) 70 + __field(u64, tsc) 65 71 __field(u32, freq) 66 - 67 - ), 72 + ), 68 73 69 74 TP_fast_assign( 70 75 __entry->core_busy = core_busy; 71 76 __entry->scaled_busy = scaled_busy; 72 - __entry->state = state; 77 + __entry->from = from; 78 + __entry->to = to; 73 79 __entry->mperf = mperf; 74 80 __entry->aperf = aperf; 81 + __entry->tsc = tsc; 75 82 __entry->freq = freq; 76 83 ), 77 84 78 - TP_printk("core_busy=%lu scaled=%lu state=%lu mperf=%llu aperf=%llu freq=%lu ", 85 + TP_printk("core_busy=%lu scaled=%lu from=%lu to=%lu mperf=%llu aperf=%llu tsc=%llu freq=%lu ", 79 86 (unsigned long)__entry->core_busy, 80 87 (unsigned long)__entry->scaled_busy, 81 - (unsigned long)__entry->state, 88 + (unsigned long)__entry->from, 89 + (unsigned long)__entry->to, 82 90 (unsigned long long)__entry->mperf, 83 91 (unsigned long long)__entry->aperf, 92 + (unsigned long long)__entry->tsc, 84 93 (unsigned long)__entry->freq 85 94 ) 86 95