|
16 | 16 | #include <linux/acpi.h> |
17 | 17 | #include <linux/dmi.h> |
18 | 18 | #include <linux/sched.h> /* need_resched() */ |
19 | | -#include <linux/sort.h> |
20 | 19 | #include <linux/tick.h> |
21 | 20 | #include <linux/cpuidle.h> |
22 | 21 | #include <linux/cpu.h> |
@@ -386,25 +385,24 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr, |
386 | 385 | acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 1); |
387 | 386 | } |
388 | 387 |
|
389 | | -static int acpi_cst_latency_cmp(const void *a, const void *b) |
| 388 | +static void acpi_cst_latency_sort(struct acpi_processor_cx *states, size_t length) |
390 | 389 | { |
391 | | - const struct acpi_processor_cx *x = a, *y = b; |
| 390 | + int i, j, k; |
392 | 391 |
|
393 | | - if (!(x->valid && y->valid)) |
394 | | - return 0; |
395 | | - if (x->latency > y->latency) |
396 | | - return 1; |
397 | | - if (x->latency < y->latency) |
398 | | - return -1; |
399 | | - return 0; |
400 | | -} |
401 | | -static void acpi_cst_latency_swap(void *a, void *b, int n) |
402 | | -{ |
403 | | - struct acpi_processor_cx *x = a, *y = b; |
| 392 | + for (i = 1; i < length; i++) { |
| 393 | + if (!states[i].valid) |
| 394 | + continue; |
404 | 395 |
|
405 | | - if (!(x->valid && y->valid)) |
406 | | - return; |
407 | | - swap(x->latency, y->latency); |
| 396 | + for (j = i - 1, k = i; j >= 0; j--) { |
| 397 | + if (!states[j].valid) |
| 398 | + continue; |
| 399 | + |
| 400 | + if (states[j].latency > states[k].latency) |
| 401 | + swap(states[j].latency, states[k].latency); |
| 402 | + |
| 403 | + k = j; |
| 404 | + } |
| 405 | + } |
408 | 406 | } |
409 | 407 |
|
410 | 408 | static int acpi_processor_power_verify(struct acpi_processor *pr) |
@@ -449,10 +447,7 @@ static int acpi_processor_power_verify(struct acpi_processor *pr) |
449 | 447 |
|
450 | 448 | if (buggy_latency) { |
451 | 449 | pr_notice("FW issue: working around C-state latencies out of order\n"); |
452 | | - sort(&pr->power.states[1], max_cstate, |
453 | | - sizeof(struct acpi_processor_cx), |
454 | | - acpi_cst_latency_cmp, |
455 | | - acpi_cst_latency_swap); |
| 450 | + acpi_cst_latency_sort(&pr->power.states[1], max_cstate); |
456 | 451 | } |
457 | 452 |
|
458 | 453 | lapic_timer_propagate_broadcast(pr); |
|
0 commit comments