diff options
-rw-r--r-- | drivers/cpufreq/intel_pstate.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index ee61db93163c..73ccddf94cf4 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c | |||
@@ -349,7 +349,7 @@ static struct pstate_adjust_policy pid_params __read_mostly = { | |||
349 | static int hwp_active __read_mostly; | 349 | static int hwp_active __read_mostly; |
350 | static bool per_cpu_limits __read_mostly; | 350 | static bool per_cpu_limits __read_mostly; |
351 | 351 | ||
352 | static bool driver_registered __read_mostly; | 352 | static struct cpufreq_driver *intel_pstate_driver __read_mostly; |
353 | 353 | ||
354 | #ifdef CONFIG_ACPI | 354 | #ifdef CONFIG_ACPI |
355 | static bool acpi_ppc; | 355 | static bool acpi_ppc; |
@@ -1035,7 +1035,7 @@ static ssize_t show_turbo_pct(struct kobject *kobj, | |||
1035 | 1035 | ||
1036 | mutex_lock(&intel_pstate_driver_lock); | 1036 | mutex_lock(&intel_pstate_driver_lock); |
1037 | 1037 | ||
1038 | if (!driver_registered) { | 1038 | if (!intel_pstate_driver) { |
1039 | mutex_unlock(&intel_pstate_driver_lock); | 1039 | mutex_unlock(&intel_pstate_driver_lock); |
1040 | return -EAGAIN; | 1040 | return -EAGAIN; |
1041 | } | 1041 | } |
@@ -1060,7 +1060,7 @@ static ssize_t show_num_pstates(struct kobject *kobj, | |||
1060 | 1060 | ||
1061 | mutex_lock(&intel_pstate_driver_lock); | 1061 | mutex_lock(&intel_pstate_driver_lock); |
1062 | 1062 | ||
1063 | if (!driver_registered) { | 1063 | if (!intel_pstate_driver) { |
1064 | mutex_unlock(&intel_pstate_driver_lock); | 1064 | mutex_unlock(&intel_pstate_driver_lock); |
1065 | return -EAGAIN; | 1065 | return -EAGAIN; |
1066 | } | 1066 | } |
@@ -1080,7 +1080,7 @@ static ssize_t show_no_turbo(struct kobject *kobj, | |||
1080 | 1080 | ||
1081 | mutex_lock(&intel_pstate_driver_lock); | 1081 | mutex_lock(&intel_pstate_driver_lock); |
1082 | 1082 | ||
1083 | if (!driver_registered) { | 1083 | if (!intel_pstate_driver) { |
1084 | mutex_unlock(&intel_pstate_driver_lock); | 1084 | mutex_unlock(&intel_pstate_driver_lock); |
1085 | return -EAGAIN; | 1085 | return -EAGAIN; |
1086 | } | 1086 | } |
@@ -1108,7 +1108,7 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, | |||
1108 | 1108 | ||
1109 | mutex_lock(&intel_pstate_driver_lock); | 1109 | mutex_lock(&intel_pstate_driver_lock); |
1110 | 1110 | ||
1111 | if (!driver_registered) { | 1111 | if (!intel_pstate_driver) { |
1112 | mutex_unlock(&intel_pstate_driver_lock); | 1112 | mutex_unlock(&intel_pstate_driver_lock); |
1113 | return -EAGAIN; | 1113 | return -EAGAIN; |
1114 | } | 1114 | } |
@@ -1155,7 +1155,7 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, | |||
1155 | 1155 | ||
1156 | mutex_lock(&intel_pstate_driver_lock); | 1156 | mutex_lock(&intel_pstate_driver_lock); |
1157 | 1157 | ||
1158 | if (!driver_registered) { | 1158 | if (!intel_pstate_driver) { |
1159 | mutex_unlock(&intel_pstate_driver_lock); | 1159 | mutex_unlock(&intel_pstate_driver_lock); |
1160 | return -EAGAIN; | 1160 | return -EAGAIN; |
1161 | } | 1161 | } |
@@ -1185,7 +1185,7 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, | |||
1185 | 1185 | ||
1186 | mutex_lock(&intel_pstate_driver_lock); | 1186 | mutex_lock(&intel_pstate_driver_lock); |
1187 | 1187 | ||
1188 | if (!driver_registered) { | 1188 | if (!intel_pstate_driver) { |
1189 | mutex_unlock(&intel_pstate_driver_lock); | 1189 | mutex_unlock(&intel_pstate_driver_lock); |
1190 | return -EAGAIN; | 1190 | return -EAGAIN; |
1191 | } | 1191 | } |
@@ -2255,7 +2255,7 @@ static struct cpufreq_driver intel_cpufreq = { | |||
2255 | .name = "intel_cpufreq", | 2255 | .name = "intel_cpufreq", |
2256 | }; | 2256 | }; |
2257 | 2257 | ||
2258 | static struct cpufreq_driver *intel_pstate_driver = &intel_pstate; | 2258 | static struct cpufreq_driver *default_driver = &intel_pstate; |
2259 | 2259 | ||
2260 | static void intel_pstate_driver_cleanup(void) | 2260 | static void intel_pstate_driver_cleanup(void) |
2261 | { | 2261 | { |
@@ -2272,15 +2272,17 @@ static void intel_pstate_driver_cleanup(void) | |||
2272 | } | 2272 | } |
2273 | } | 2273 | } |
2274 | put_online_cpus(); | 2274 | put_online_cpus(); |
2275 | intel_pstate_driver = NULL; | ||
2275 | } | 2276 | } |
2276 | 2277 | ||
2277 | static int intel_pstate_register_driver(void) | 2278 | static int intel_pstate_register_driver(struct cpufreq_driver *driver) |
2278 | { | 2279 | { |
2279 | int ret; | 2280 | int ret; |
2280 | 2281 | ||
2281 | memset(&global, 0, sizeof(global)); | 2282 | memset(&global, 0, sizeof(global)); |
2282 | global.max_perf_pct = 100; | 2283 | global.max_perf_pct = 100; |
2283 | 2284 | ||
2285 | intel_pstate_driver = driver; | ||
2284 | ret = cpufreq_register_driver(intel_pstate_driver); | 2286 | ret = cpufreq_register_driver(intel_pstate_driver); |
2285 | if (ret) { | 2287 | if (ret) { |
2286 | intel_pstate_driver_cleanup(); | 2288 | intel_pstate_driver_cleanup(); |
@@ -2289,10 +2291,6 @@ static int intel_pstate_register_driver(void) | |||
2289 | 2291 | ||
2290 | global.min_perf_pct = min_perf_pct_min(); | 2292 | global.min_perf_pct = min_perf_pct_min(); |
2291 | 2293 | ||
2292 | mutex_lock(&intel_pstate_limits_lock); | ||
2293 | driver_registered = true; | ||
2294 | mutex_unlock(&intel_pstate_limits_lock); | ||
2295 | |||
2296 | if (intel_pstate_driver == &intel_pstate && !hwp_active && | 2294 | if (intel_pstate_driver == &intel_pstate && !hwp_active && |
2297 | pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load) | 2295 | pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load) |
2298 | intel_pstate_debug_expose_params(); | 2296 | intel_pstate_debug_expose_params(); |
@@ -2309,10 +2307,6 @@ static int intel_pstate_unregister_driver(void) | |||
2309 | pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load) | 2307 | pstate_funcs.get_target_pstate != get_target_pstate_use_cpu_load) |
2310 | intel_pstate_debug_hide_params(); | 2308 | intel_pstate_debug_hide_params(); |
2311 | 2309 | ||
2312 | mutex_lock(&intel_pstate_limits_lock); | ||
2313 | driver_registered = false; | ||
2314 | mutex_unlock(&intel_pstate_limits_lock); | ||
2315 | |||
2316 | cpufreq_unregister_driver(intel_pstate_driver); | 2310 | cpufreq_unregister_driver(intel_pstate_driver); |
2317 | intel_pstate_driver_cleanup(); | 2311 | intel_pstate_driver_cleanup(); |
2318 | 2312 | ||
@@ -2321,7 +2315,7 @@ static int intel_pstate_unregister_driver(void) | |||
2321 | 2315 | ||
2322 | static ssize_t intel_pstate_show_status(char *buf) | 2316 | static ssize_t intel_pstate_show_status(char *buf) |
2323 | { | 2317 | { |
2324 | if (!driver_registered) | 2318 | if (!intel_pstate_driver) |
2325 | return sprintf(buf, "off\n"); | 2319 | return sprintf(buf, "off\n"); |
2326 | 2320 | ||
2327 | return sprintf(buf, "%s\n", intel_pstate_driver == &intel_pstate ? | 2321 | return sprintf(buf, "%s\n", intel_pstate_driver == &intel_pstate ? |
@@ -2333,11 +2327,11 @@ static int intel_pstate_update_status(const char *buf, size_t size) | |||
2333 | int ret; | 2327 | int ret; |
2334 | 2328 | ||
2335 | if (size == 3 && !strncmp(buf, "off", size)) | 2329 | if (size == 3 && !strncmp(buf, "off", size)) |
2336 | return driver_registered ? | 2330 | return intel_pstate_driver ? |
2337 | intel_pstate_unregister_driver() : -EINVAL; | 2331 | intel_pstate_unregister_driver() : -EINVAL; |
2338 | 2332 | ||
2339 | if (size == 6 && !strncmp(buf, "active", size)) { | 2333 | if (size == 6 && !strncmp(buf, "active", size)) { |
2340 | if (driver_registered) { | 2334 | if (intel_pstate_driver) { |
2341 | if (intel_pstate_driver == &intel_pstate) | 2335 | if (intel_pstate_driver == &intel_pstate) |
2342 | return 0; | 2336 | return 0; |
2343 | 2337 | ||
@@ -2346,12 +2340,11 @@ static int intel_pstate_update_status(const char *buf, size_t size) | |||
2346 | return ret; | 2340 | return ret; |
2347 | } | 2341 | } |
2348 | 2342 | ||
2349 | intel_pstate_driver = &intel_pstate; | 2343 | return intel_pstate_register_driver(&intel_pstate); |
2350 | return intel_pstate_register_driver(); | ||
2351 | } | 2344 | } |
2352 | 2345 | ||
2353 | if (size == 7 && !strncmp(buf, "passive", size)) { | 2346 | if (size == 7 && !strncmp(buf, "passive", size)) { |
2354 | if (driver_registered) { | 2347 | if (intel_pstate_driver) { |
2355 | if (intel_pstate_driver != &intel_pstate) | 2348 | if (intel_pstate_driver != &intel_pstate) |
2356 | return 0; | 2349 | return 0; |
2357 | 2350 | ||
@@ -2360,8 +2353,7 @@ static int intel_pstate_update_status(const char *buf, size_t size) | |||
2360 | return ret; | 2353 | return ret; |
2361 | } | 2354 | } |
2362 | 2355 | ||
2363 | intel_pstate_driver = &intel_cpufreq; | 2356 | return intel_pstate_register_driver(&intel_cpufreq); |
2364 | return intel_pstate_register_driver(); | ||
2365 | } | 2357 | } |
2366 | 2358 | ||
2367 | return -EINVAL; | 2359 | return -EINVAL; |
@@ -2601,7 +2593,7 @@ hwp_cpu_matched: | |||
2601 | intel_pstate_sysfs_expose_params(); | 2593 | intel_pstate_sysfs_expose_params(); |
2602 | 2594 | ||
2603 | mutex_lock(&intel_pstate_driver_lock); | 2595 | mutex_lock(&intel_pstate_driver_lock); |
2604 | rc = intel_pstate_register_driver(); | 2596 | rc = intel_pstate_register_driver(default_driver); |
2605 | mutex_unlock(&intel_pstate_driver_lock); | 2597 | mutex_unlock(&intel_pstate_driver_lock); |
2606 | if (rc) | 2598 | if (rc) |
2607 | return rc; | 2599 | return rc; |
@@ -2622,7 +2614,7 @@ static int __init intel_pstate_setup(char *str) | |||
2622 | no_load = 1; | 2614 | no_load = 1; |
2623 | } else if (!strcmp(str, "passive")) { | 2615 | } else if (!strcmp(str, "passive")) { |
2624 | pr_info("Passive mode enabled\n"); | 2616 | pr_info("Passive mode enabled\n"); |
2625 | intel_pstate_driver = &intel_cpufreq; | 2617 | default_driver = &intel_cpufreq; |
2626 | no_hwp = 1; | 2618 | no_hwp = 1; |
2627 | } | 2619 | } |
2628 | if (!strcmp(str, "no_hwp")) { | 2620 | if (!strcmp(str, "no_hwp")) { |