aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/acpi_pad.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/acpi_pad.c')
-rw-r--r--drivers/acpi/acpi_pad.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 97991ac6f5fc..7e52295f1ecc 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -208,7 +208,7 @@ static int power_saving_thread(void *data)
208 * the mechanism only works when all CPUs have RT task running, 208 * the mechanism only works when all CPUs have RT task running,
209 * as if one CPU hasn't RT task, RT task from other CPUs will 209 * as if one CPU hasn't RT task, RT task from other CPUs will
210 * borrow CPU time from this CPU and cause RT task use > 95% 210 * borrow CPU time from this CPU and cause RT task use > 95%
211 * CPU time. To make 'avoid staration' work, takes a nap here. 211 * CPU time. To make 'avoid starvation' work, takes a nap here.
212 */ 212 */
213 if (do_sleep) 213 if (do_sleep)
214 schedule_timeout_killable(HZ * idle_pct / 100); 214 schedule_timeout_killable(HZ * idle_pct / 100);
@@ -222,14 +222,18 @@ static struct task_struct *ps_tsks[NR_CPUS];
222static unsigned int ps_tsk_num; 222static unsigned int ps_tsk_num;
223static int create_power_saving_task(void) 223static int create_power_saving_task(void)
224{ 224{
225 int rc = -ENOMEM;
226
225 ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread, 227 ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread,
226 (void *)(unsigned long)ps_tsk_num, 228 (void *)(unsigned long)ps_tsk_num,
227 "power_saving/%d", ps_tsk_num); 229 "power_saving/%d", ps_tsk_num);
228 if (ps_tsks[ps_tsk_num]) { 230 rc = IS_ERR(ps_tsks[ps_tsk_num]) ? PTR_ERR(ps_tsks[ps_tsk_num]) : 0;
231 if (!rc)
229 ps_tsk_num++; 232 ps_tsk_num++;
230 return 0; 233 else
231 } 234 ps_tsks[ps_tsk_num] = NULL;
232 return -EINVAL; 235
236 return rc;
233} 237}
234 238
235static void destroy_power_saving_task(void) 239static void destroy_power_saving_task(void)
@@ -237,6 +241,7 @@ static void destroy_power_saving_task(void)
237 if (ps_tsk_num > 0) { 241 if (ps_tsk_num > 0) {
238 ps_tsk_num--; 242 ps_tsk_num--;
239 kthread_stop(ps_tsks[ps_tsk_num]); 243 kthread_stop(ps_tsks[ps_tsk_num]);
244 ps_tsks[ps_tsk_num] = NULL;
240 } 245 }
241} 246}
242 247
@@ -253,7 +258,7 @@ static void set_power_saving_task_num(unsigned int num)
253 } 258 }
254} 259}
255 260
256static int acpi_pad_idle_cpus(unsigned int num_cpus) 261static void acpi_pad_idle_cpus(unsigned int num_cpus)
257{ 262{
258 get_online_cpus(); 263 get_online_cpus();
259 264
@@ -261,7 +266,6 @@ static int acpi_pad_idle_cpus(unsigned int num_cpus)
261 set_power_saving_task_num(num_cpus); 266 set_power_saving_task_num(num_cpus);
262 267
263 put_online_cpus(); 268 put_online_cpus();
264 return 0;
265} 269}
266 270
267static uint32_t acpi_pad_idle_cpus_num(void) 271static uint32_t acpi_pad_idle_cpus_num(void)
@@ -369,19 +373,21 @@ static void acpi_pad_remove_sysfs(struct acpi_device *device)
369static int acpi_pad_pur(acpi_handle handle, int *num_cpus) 373static int acpi_pad_pur(acpi_handle handle, int *num_cpus)
370{ 374{
371 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; 375 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
372 acpi_status status;
373 union acpi_object *package; 376 union acpi_object *package;
374 int rev, num, ret = -EINVAL; 377 int rev, num, ret = -EINVAL;
375 378
376 status = acpi_evaluate_object(handle, "_PUR", NULL, &buffer); 379 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer)))
377 if (ACPI_FAILURE(status)) 380 return -EINVAL;
381
382 if (!buffer.length || !buffer.pointer)
378 return -EINVAL; 383 return -EINVAL;
384
379 package = buffer.pointer; 385 package = buffer.pointer;
380 if (package->type != ACPI_TYPE_PACKAGE || package->package.count != 2) 386 if (package->type != ACPI_TYPE_PACKAGE || package->package.count != 2)
381 goto out; 387 goto out;
382 rev = package->package.elements[0].integer.value; 388 rev = package->package.elements[0].integer.value;
383 num = package->package.elements[1].integer.value; 389 num = package->package.elements[1].integer.value;
384 if (rev != 1) 390 if (rev != 1 || num < 0)
385 goto out; 391 goto out;
386 *num_cpus = num; 392 *num_cpus = num;
387 ret = 0; 393 ret = 0;
@@ -410,7 +416,7 @@ static void acpi_pad_ost(acpi_handle handle, int stat,
410 416
411static void acpi_pad_handle_notify(acpi_handle handle) 417static void acpi_pad_handle_notify(acpi_handle handle)
412{ 418{
413 int num_cpus, ret; 419 int num_cpus;
414 uint32_t idle_cpus; 420 uint32_t idle_cpus;
415 421
416 mutex_lock(&isolated_cpus_lock); 422 mutex_lock(&isolated_cpus_lock);
@@ -418,12 +424,9 @@ static void acpi_pad_handle_notify(acpi_handle handle)
418 mutex_unlock(&isolated_cpus_lock); 424 mutex_unlock(&isolated_cpus_lock);
419 return; 425 return;
420 } 426 }
421 ret = acpi_pad_idle_cpus(num_cpus); 427 acpi_pad_idle_cpus(num_cpus);
422 idle_cpus = acpi_pad_idle_cpus_num(); 428 idle_cpus = acpi_pad_idle_cpus_num();
423 if (!ret) 429 acpi_pad_ost(handle, 0, idle_cpus);
424 acpi_pad_ost(handle, 0, idle_cpus);
425 else
426 acpi_pad_ost(handle, 1, 0);
427 mutex_unlock(&isolated_cpus_lock); 430 mutex_unlock(&isolated_cpus_lock);
428} 431}
429 432