diff options
Diffstat (limited to 'kernel/irq/manage.c')
| -rw-r--r-- | kernel/irq/manage.c | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 50da67672901..61c679db4687 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c | |||
| @@ -80,14 +80,22 @@ int irq_can_set_affinity(unsigned int irq) | |||
| 80 | return 1; | 80 | return 1; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | void | 83 | /** |
| 84 | irq_set_thread_affinity(struct irq_desc *desc, const struct cpumask *cpumask) | 84 | * irq_set_thread_affinity - Notify irq threads to adjust affinity |
| 85 | * @desc: irq descriptor which has affitnity changed | ||
| 86 | * | ||
| 87 | * We just set IRQTF_AFFINITY and delegate the affinity setting | ||
| 88 | * to the interrupt thread itself. We can not call | ||
| 89 | * set_cpus_allowed_ptr() here as we hold desc->lock and this | ||
| 90 | * code can be called from hard interrupt context. | ||
| 91 | */ | ||
| 92 | void irq_set_thread_affinity(struct irq_desc *desc) | ||
| 85 | { | 93 | { |
| 86 | struct irqaction *action = desc->action; | 94 | struct irqaction *action = desc->action; |
| 87 | 95 | ||
| 88 | while (action) { | 96 | while (action) { |
| 89 | if (action->thread) | 97 | if (action->thread) |
| 90 | set_cpus_allowed_ptr(action->thread, cpumask); | 98 | set_bit(IRQTF_AFFINITY, &action->thread_flags); |
| 91 | action = action->next; | 99 | action = action->next; |
| 92 | } | 100 | } |
| 93 | } | 101 | } |
| @@ -112,7 +120,7 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask) | |||
| 112 | if (desc->status & IRQ_MOVE_PCNTXT) { | 120 | if (desc->status & IRQ_MOVE_PCNTXT) { |
| 113 | if (!desc->chip->set_affinity(irq, cpumask)) { | 121 | if (!desc->chip->set_affinity(irq, cpumask)) { |
| 114 | cpumask_copy(desc->affinity, cpumask); | 122 | cpumask_copy(desc->affinity, cpumask); |
| 115 | irq_set_thread_affinity(desc, cpumask); | 123 | irq_set_thread_affinity(desc); |
| 116 | } | 124 | } |
| 117 | } | 125 | } |
| 118 | else { | 126 | else { |
| @@ -122,7 +130,7 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask) | |||
| 122 | #else | 130 | #else |
| 123 | if (!desc->chip->set_affinity(irq, cpumask)) { | 131 | if (!desc->chip->set_affinity(irq, cpumask)) { |
| 124 | cpumask_copy(desc->affinity, cpumask); | 132 | cpumask_copy(desc->affinity, cpumask); |
| 125 | irq_set_thread_affinity(desc, cpumask); | 133 | irq_set_thread_affinity(desc); |
| 126 | } | 134 | } |
| 127 | #endif | 135 | #endif |
| 128 | desc->status |= IRQ_AFFINITY_SET; | 136 | desc->status |= IRQ_AFFINITY_SET; |
| @@ -176,7 +184,7 @@ int irq_select_affinity_usr(unsigned int irq) | |||
| 176 | spin_lock_irqsave(&desc->lock, flags); | 184 | spin_lock_irqsave(&desc->lock, flags); |
| 177 | ret = setup_affinity(irq, desc); | 185 | ret = setup_affinity(irq, desc); |
| 178 | if (!ret) | 186 | if (!ret) |
| 179 | irq_set_thread_affinity(desc, desc->affinity); | 187 | irq_set_thread_affinity(desc); |
| 180 | spin_unlock_irqrestore(&desc->lock, flags); | 188 | spin_unlock_irqrestore(&desc->lock, flags); |
| 181 | 189 | ||
| 182 | return ret; | 190 | return ret; |
| @@ -443,6 +451,39 @@ static int irq_wait_for_interrupt(struct irqaction *action) | |||
| 443 | return -1; | 451 | return -1; |
| 444 | } | 452 | } |
| 445 | 453 | ||
| 454 | #ifdef CONFIG_SMP | ||
| 455 | /* | ||
| 456 | * Check whether we need to change the affinity of the interrupt thread. | ||
| 457 | */ | ||
| 458 | static void | ||
| 459 | irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action) | ||
| 460 | { | ||
| 461 | cpumask_var_t mask; | ||
| 462 | |||
| 463 | if (!test_and_clear_bit(IRQTF_AFFINITY, &action->thread_flags)) | ||
| 464 | return; | ||
| 465 | |||
| 466 | /* | ||
| 467 | * In case we are out of memory we set IRQTF_AFFINITY again and | ||
| 468 | * try again next time | ||
| 469 | */ | ||
| 470 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) { | ||
| 471 | set_bit(IRQTF_AFFINITY, &action->thread_flags); | ||
| 472 | return; | ||
| 473 | } | ||
| 474 | |||
| 475 | spin_lock_irq(&desc->lock); | ||
| 476 | cpumask_copy(mask, desc->affinity); | ||
| 477 | spin_unlock_irq(&desc->lock); | ||
| 478 | |||
| 479 | set_cpus_allowed_ptr(current, mask); | ||
| 480 | free_cpumask_var(mask); | ||
| 481 | } | ||
| 482 | #else | ||
| 483 | static inline void | ||
| 484 | irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *action) { } | ||
| 485 | #endif | ||
| 486 | |||
| 446 | /* | 487 | /* |
| 447 | * Interrupt handler thread | 488 | * Interrupt handler thread |
| 448 | */ | 489 | */ |
| @@ -458,6 +499,8 @@ static int irq_thread(void *data) | |||
| 458 | 499 | ||
| 459 | while (!irq_wait_for_interrupt(action)) { | 500 | while (!irq_wait_for_interrupt(action)) { |
| 460 | 501 | ||
| 502 | irq_thread_check_affinity(desc, action); | ||
| 503 | |||
| 461 | atomic_inc(&desc->threads_active); | 504 | atomic_inc(&desc->threads_active); |
| 462 | 505 | ||
| 463 | spin_lock_irq(&desc->lock); | 506 | spin_lock_irq(&desc->lock); |
