diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2008-09-29 09:47:42 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2008-09-29 11:09:14 -0400 |
commit | ccc7dadf736639da86f3e0c86832c11a66fc8221 (patch) | |
tree | 3f1c0df0a291fec4a10d72cc1ab278ad81e697c5 /kernel/hrtimer.c | |
parent | b00c1a99e7758f794923c61e5cd55268d61c9469 (diff) |
hrtimer: prevent migration of per CPU hrtimers
Impact: per CPU hrtimers can be migrated from a dead CPU
The hrtimer code has no knowledge about per CPU timers, but we need to
prevent the migration of such timers and warn when such a timer is
active at migration time.
Explicitely mark the timers as per CPU and use a more understandable
mode descriptor for the interrupts safe unlocked callback mode, which
is used by hrtimer_sleeper and the scheduler code.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r-- | kernel/hrtimer.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index ace723dd1e52..cdec83e722fa 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -672,13 +672,14 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
672 | */ | 672 | */ |
673 | BUG_ON(timer->function(timer) != HRTIMER_NORESTART); | 673 | BUG_ON(timer->function(timer) != HRTIMER_NORESTART); |
674 | return 1; | 674 | return 1; |
675 | case HRTIMER_CB_IRQSAFE_NO_SOFTIRQ: | 675 | case HRTIMER_CB_IRQSAFE_PERCPU: |
676 | case HRTIMER_CB_IRQSAFE_UNLOCKED: | ||
676 | /* | 677 | /* |
677 | * This is solely for the sched tick emulation with | 678 | * This is solely for the sched tick emulation with |
678 | * dynamic tick support to ensure that we do not | 679 | * dynamic tick support to ensure that we do not |
679 | * restart the tick right on the edge and end up with | 680 | * restart the tick right on the edge and end up with |
680 | * the tick timer in the softirq ! The calling site | 681 | * the tick timer in the softirq ! The calling site |
681 | * takes care of this. | 682 | * takes care of this. Also used for hrtimer sleeper ! |
682 | */ | 683 | */ |
683 | debug_hrtimer_deactivate(timer); | 684 | debug_hrtimer_deactivate(timer); |
684 | return 1; | 685 | return 1; |
@@ -1245,7 +1246,8 @@ static void __run_hrtimer(struct hrtimer *timer) | |||
1245 | timer_stats_account_hrtimer(timer); | 1246 | timer_stats_account_hrtimer(timer); |
1246 | 1247 | ||
1247 | fn = timer->function; | 1248 | fn = timer->function; |
1248 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_NO_SOFTIRQ) { | 1249 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU || |
1250 | timer->cb_mode == HRTIMER_CB_IRQSAFE_UNLOCKED) { | ||
1249 | /* | 1251 | /* |
1250 | * Used for scheduler timers, avoid lock inversion with | 1252 | * Used for scheduler timers, avoid lock inversion with |
1251 | * rq->lock and tasklist_lock. | 1253 | * rq->lock and tasklist_lock. |
@@ -1452,7 +1454,7 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) | |||
1452 | sl->timer.function = hrtimer_wakeup; | 1454 | sl->timer.function = hrtimer_wakeup; |
1453 | sl->task = task; | 1455 | sl->task = task; |
1454 | #ifdef CONFIG_HIGH_RES_TIMERS | 1456 | #ifdef CONFIG_HIGH_RES_TIMERS |
1455 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | 1457 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED; |
1456 | #endif | 1458 | #endif |
1457 | } | 1459 | } |
1458 | 1460 | ||
@@ -1592,7 +1594,7 @@ static void __cpuinit init_hrtimers_cpu(int cpu) | |||
1592 | #ifdef CONFIG_HOTPLUG_CPU | 1594 | #ifdef CONFIG_HOTPLUG_CPU |
1593 | 1595 | ||
1594 | static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | 1596 | static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, |
1595 | struct hrtimer_clock_base *new_base) | 1597 | struct hrtimer_clock_base *new_base, int dcpu) |
1596 | { | 1598 | { |
1597 | struct hrtimer *timer; | 1599 | struct hrtimer *timer; |
1598 | struct rb_node *node; | 1600 | struct rb_node *node; |
@@ -1604,6 +1606,18 @@ static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | |||
1604 | debug_hrtimer_deactivate(timer); | 1606 | debug_hrtimer_deactivate(timer); |
1605 | 1607 | ||
1606 | /* | 1608 | /* |
1609 | * Should not happen. Per CPU timers should be | ||
1610 | * canceled _before_ the migration code is called | ||
1611 | */ | ||
1612 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU) { | ||
1613 | __remove_hrtimer(timer, old_base, | ||
1614 | HRTIMER_STATE_INACTIVE, 0); | ||
1615 | WARN(1, "hrtimer (%p %p)active but cpu %d dead\n", | ||
1616 | timer, timer->function, dcpu); | ||
1617 | continue; | ||
1618 | } | ||
1619 | |||
1620 | /* | ||
1607 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the | 1621 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the |
1608 | * timer could be seen as !active and just vanish away | 1622 | * timer could be seen as !active and just vanish away |
1609 | * under us on another CPU | 1623 | * under us on another CPU |
@@ -1619,12 +1633,11 @@ static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | |||
1619 | /* | 1633 | /* |
1620 | * Happens with high res enabled when the timer was | 1634 | * Happens with high res enabled when the timer was |
1621 | * already expired and the callback mode is | 1635 | * already expired and the callback mode is |
1622 | * HRTIMER_CB_IRQSAFE_NO_SOFTIRQ | 1636 | * HRTIMER_CB_IRQSAFE_UNLOCKED (hrtimer_sleeper). The |
1623 | * (hrtimer_sleeper). The enqueue code does not move | 1637 | * enqueue code does not move them to the soft irq |
1624 | * them to the soft irq pending list for | 1638 | * pending list for performance/latency reasons, but |
1625 | * performance/latency reasons, but in the migration | 1639 | * in the migration state, we need to do that |
1626 | * state, we need to do that otherwise we end up with | 1640 | * otherwise we end up with a stale timer. |
1627 | * a stale timer. | ||
1628 | */ | 1641 | */ |
1629 | if (timer->state == HRTIMER_STATE_MIGRATE) { | 1642 | if (timer->state == HRTIMER_STATE_MIGRATE) { |
1630 | timer->state = HRTIMER_STATE_PENDING; | 1643 | timer->state = HRTIMER_STATE_PENDING; |
@@ -1682,7 +1695,7 @@ static void migrate_hrtimers(int cpu) | |||
1682 | 1695 | ||
1683 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { | 1696 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { |
1684 | if (migrate_hrtimer_list(&old_base->clock_base[i], | 1697 | if (migrate_hrtimer_list(&old_base->clock_base[i], |
1685 | &new_base->clock_base[i])) | 1698 | &new_base->clock_base[i], cpu)) |
1686 | raise = 1; | 1699 | raise = 1; |
1687 | } | 1700 | } |
1688 | 1701 | ||