aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/processor_idle.c
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2007-11-20 01:18:37 -0500
committerLen Brown <len.brown@intel.com>2007-11-20 01:18:37 -0500
commit95b00786f3b8fa99f53931361beeb4c10504ad87 (patch)
tree0f2de0587f08f1d0bd80a70a3d18ca5eb3dfb75c /drivers/acpi/processor_idle.c
parent22201f7402851b9a47e64139ca589bd8555f7138 (diff)
parentddc081a19585c8ba5aad437779950c2ef215360a (diff)
Pull cpuidle into release branch
Diffstat (limited to 'drivers/acpi/processor_idle.c')
-rw-r--r--drivers/acpi/processor_idle.c111
1 files changed, 63 insertions, 48 deletions
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index f996d0e37689..7b6c20eeeaff 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -197,6 +197,19 @@ static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2)
197 return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2); 197 return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2);
198} 198}
199 199
200static void acpi_safe_halt(void)
201{
202 current_thread_info()->status &= ~TS_POLLING;
203 /*
204 * TS_POLLING-cleared state must be visible before we
205 * test NEED_RESCHED:
206 */
207 smp_mb();
208 if (!need_resched())
209 safe_halt();
210 current_thread_info()->status |= TS_POLLING;
211}
212
200#ifndef CONFIG_CPU_IDLE 213#ifndef CONFIG_CPU_IDLE
201 214
202static void 215static void
@@ -239,19 +252,6 @@ acpi_processor_power_activate(struct acpi_processor *pr,
239 return; 252 return;
240} 253}
241 254
242static void acpi_safe_halt(void)
243{
244 current_thread_info()->status &= ~TS_POLLING;
245 /*
246 * TS_POLLING-cleared state must be visible before we
247 * test NEED_RESCHED:
248 */
249 smp_mb();
250 if (!need_resched())
251 safe_halt();
252 current_thread_info()->status |= TS_POLLING;
253}
254
255static atomic_t c3_cpu_count; 255static atomic_t c3_cpu_count;
256 256
257/* Common C-state entry for C2, C3, .. */ 257/* Common C-state entry for C2, C3, .. */
@@ -1373,15 +1373,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
1373 if (pr->flags.bm_check) 1373 if (pr->flags.bm_check)
1374 acpi_idle_update_bm_rld(pr, cx); 1374 acpi_idle_update_bm_rld(pr, cx);
1375 1375
1376 current_thread_info()->status &= ~TS_POLLING; 1376 acpi_safe_halt();
1377 /*
1378 * TS_POLLING-cleared state must be visible before we test
1379 * NEED_RESCHED:
1380 */
1381 smp_mb();
1382 if (!need_resched())
1383 safe_halt();
1384 current_thread_info()->status |= TS_POLLING;
1385 1377
1386 cx->usage++; 1378 cx->usage++;
1387 1379
@@ -1399,6 +1391,8 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1399 struct acpi_processor *pr; 1391 struct acpi_processor *pr;
1400 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 1392 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1401 u32 t1, t2; 1393 u32 t1, t2;
1394 int sleep_ticks = 0;
1395
1402 pr = processors[smp_processor_id()]; 1396 pr = processors[smp_processor_id()];
1403 1397
1404 if (unlikely(!pr)) 1398 if (unlikely(!pr))
@@ -1428,6 +1422,8 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1428 ACPI_FLUSH_CPU_CACHE(); 1422 ACPI_FLUSH_CPU_CACHE();
1429 1423
1430 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1424 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1425 /* Tell the scheduler that we are going deep-idle: */
1426 sched_clock_idle_sleep_event();
1431 acpi_state_timer_broadcast(pr, cx, 1); 1427 acpi_state_timer_broadcast(pr, cx, 1);
1432 acpi_idle_do_entry(cx); 1428 acpi_idle_do_entry(cx);
1433 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1429 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
@@ -1436,6 +1432,10 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1436 /* TSC could halt in idle, so notify users */ 1432 /* TSC could halt in idle, so notify users */
1437 mark_tsc_unstable("TSC halts in idle");; 1433 mark_tsc_unstable("TSC halts in idle");;
1438#endif 1434#endif
1435 sleep_ticks = ticks_elapsed(t1, t2);
1436
1437 /* Tell the scheduler how much we idled: */
1438 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
1439 1439
1440 local_irq_enable(); 1440 local_irq_enable();
1441 current_thread_info()->status |= TS_POLLING; 1441 current_thread_info()->status |= TS_POLLING;
@@ -1443,7 +1443,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1443 cx->usage++; 1443 cx->usage++;
1444 1444
1445 acpi_state_timer_broadcast(pr, cx, 0); 1445 acpi_state_timer_broadcast(pr, cx, 0);
1446 cx->time += ticks_elapsed(t1, t2); 1446 cx->time += sleep_ticks;
1447 return ticks_elapsed_in_us(t1, t2); 1447 return ticks_elapsed_in_us(t1, t2);
1448} 1448}
1449 1449
@@ -1463,6 +1463,8 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1463 struct acpi_processor *pr; 1463 struct acpi_processor *pr;
1464 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 1464 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1465 u32 t1, t2; 1465 u32 t1, t2;
1466 int sleep_ticks = 0;
1467
1466 pr = processors[smp_processor_id()]; 1468 pr = processors[smp_processor_id()];
1467 1469
1468 if (unlikely(!pr)) 1470 if (unlikely(!pr))
@@ -1471,6 +1473,15 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1471 if (acpi_idle_suspend) 1473 if (acpi_idle_suspend)
1472 return(acpi_idle_enter_c1(dev, state)); 1474 return(acpi_idle_enter_c1(dev, state));
1473 1475
1476 if (acpi_idle_bm_check()) {
1477 if (dev->safe_state) {
1478 return dev->safe_state->enter(dev, dev->safe_state);
1479 } else {
1480 acpi_safe_halt();
1481 return 0;
1482 }
1483 }
1484
1474 local_irq_disable(); 1485 local_irq_disable();
1475 current_thread_info()->status &= ~TS_POLLING; 1486 current_thread_info()->status &= ~TS_POLLING;
1476 /* 1487 /*
@@ -1485,38 +1496,45 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1485 return 0; 1496 return 0;
1486 } 1497 }
1487 1498
1499 /* Tell the scheduler that we are going deep-idle: */
1500 sched_clock_idle_sleep_event();
1488 /* 1501 /*
1489 * Must be done before busmaster disable as we might need to 1502 * Must be done before busmaster disable as we might need to
1490 * access HPET ! 1503 * access HPET !
1491 */ 1504 */
1492 acpi_state_timer_broadcast(pr, cx, 1); 1505 acpi_state_timer_broadcast(pr, cx, 1);
1493 1506
1494 if (acpi_idle_bm_check()) { 1507 acpi_idle_update_bm_rld(pr, cx);
1495 cx = pr->power.bm_state;
1496
1497 acpi_idle_update_bm_rld(pr, cx);
1498
1499 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1500 acpi_idle_do_entry(cx);
1501 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1502 } else {
1503 acpi_idle_update_bm_rld(pr, cx);
1504 1508
1509 /*
1510 * disable bus master
1511 * bm_check implies we need ARB_DIS
1512 * !bm_check implies we need cache flush
1513 * bm_control implies whether we can do ARB_DIS
1514 *
1515 * That leaves a case where bm_check is set and bm_control is
1516 * not set. In that case we cannot do much, we enter C3
1517 * without doing anything.
1518 */
1519 if (pr->flags.bm_check && pr->flags.bm_control) {
1505 spin_lock(&c3_lock); 1520 spin_lock(&c3_lock);
1506 c3_cpu_count++; 1521 c3_cpu_count++;
1507 /* Disable bus master arbitration when all CPUs are in C3 */ 1522 /* Disable bus master arbitration when all CPUs are in C3 */
1508 if (c3_cpu_count == num_online_cpus()) 1523 if (c3_cpu_count == num_online_cpus())
1509 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); 1524 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
1510 spin_unlock(&c3_lock); 1525 spin_unlock(&c3_lock);
1526 } else if (!pr->flags.bm_check) {
1527 ACPI_FLUSH_CPU_CACHE();
1528 }
1511 1529
1512 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1530 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1513 acpi_idle_do_entry(cx); 1531 acpi_idle_do_entry(cx);
1514 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1532 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1515 1533
1534 /* Re-enable bus master arbitration */
1535 if (pr->flags.bm_check && pr->flags.bm_control) {
1516 spin_lock(&c3_lock); 1536 spin_lock(&c3_lock);
1517 /* Re-enable bus master arbitration */ 1537 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
1518 if (c3_cpu_count == num_online_cpus())
1519 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
1520 c3_cpu_count--; 1538 c3_cpu_count--;
1521 spin_unlock(&c3_lock); 1539 spin_unlock(&c3_lock);
1522 } 1540 }
@@ -1525,6 +1543,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1525 /* TSC could halt in idle, so notify users */ 1543 /* TSC could halt in idle, so notify users */
1526 mark_tsc_unstable("TSC halts in idle"); 1544 mark_tsc_unstable("TSC halts in idle");
1527#endif 1545#endif
1546 sleep_ticks = ticks_elapsed(t1, t2);
1547 /* Tell the scheduler how much we idled: */
1548 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
1528 1549
1529 local_irq_enable(); 1550 local_irq_enable();
1530 current_thread_info()->status |= TS_POLLING; 1551 current_thread_info()->status |= TS_POLLING;
@@ -1532,7 +1553,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1532 cx->usage++; 1553 cx->usage++;
1533 1554
1534 acpi_state_timer_broadcast(pr, cx, 0); 1555 acpi_state_timer_broadcast(pr, cx, 0);
1535 cx->time += ticks_elapsed(t1, t2); 1556 cx->time += sleep_ticks;
1536 return ticks_elapsed_in_us(t1, t2); 1557 return ticks_elapsed_in_us(t1, t2);
1537} 1558}
1538 1559
@@ -1584,12 +1605,14 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1584 case ACPI_STATE_C1: 1605 case ACPI_STATE_C1:
1585 state->flags |= CPUIDLE_FLAG_SHALLOW; 1606 state->flags |= CPUIDLE_FLAG_SHALLOW;
1586 state->enter = acpi_idle_enter_c1; 1607 state->enter = acpi_idle_enter_c1;
1608 dev->safe_state = state;
1587 break; 1609 break;
1588 1610
1589 case ACPI_STATE_C2: 1611 case ACPI_STATE_C2:
1590 state->flags |= CPUIDLE_FLAG_BALANCED; 1612 state->flags |= CPUIDLE_FLAG_BALANCED;
1591 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1613 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1592 state->enter = acpi_idle_enter_simple; 1614 state->enter = acpi_idle_enter_simple;
1615 dev->safe_state = state;
1593 break; 1616 break;
1594 1617
1595 case ACPI_STATE_C3: 1618 case ACPI_STATE_C3:
@@ -1610,14 +1633,6 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1610 if (!count) 1633 if (!count)
1611 return -EINVAL; 1634 return -EINVAL;
1612 1635
1613 /* find the deepest state that can handle active BM */
1614 if (pr->flags.bm_check) {
1615 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++)
1616 if (pr->power.states[i].type == ACPI_STATE_C3)
1617 break;
1618 pr->power.bm_state = &pr->power.states[i-1];
1619 }
1620
1621 return 0; 1636 return 0;
1622} 1637}
1623 1638