blob: 09b20e127aee18297db93612374fd6d2e4c34125 [file] [log] [blame]
Yang Yingliangf1e0bb02015-09-24 17:32:13 +08001/*
2 * Generic cpu hotunplug interrupt migration code copied from the
3 * arch/arm implementation
4 *
5 * Copyright (C) Russell King
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/interrupt.h>
12#include <linux/ratelimit.h>
13#include <linux/irq.h>
14
15#include "internals.h"
16
17static bool migrate_one_irq(struct irq_desc *desc)
18{
19 struct irq_data *d = irq_desc_get_irq_data(desc);
Thomas Gleixnere8a70352017-06-20 01:37:27 +020020 struct irq_chip *chip = irq_data_get_irq_chip(d);
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080021 const struct cpumask *affinity = d->common->affinity;
Thomas Gleixnere8a70352017-06-20 01:37:27 +020022 bool brokeaff = false;
23 int err;
24
25 /*
26 * IRQ chip might be already torn down, but the irq descriptor is
27 * still in the radix tree. Also if the chip has no affinity setter,
28 * nothing can be done here.
29 */
30 if (!chip || !chip->irq_set_affinity) {
31 pr_debug("IRQ %u: Unable to migrate away\n", d->irq);
32 return false;
33 }
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080034
35 /*
Thomas Gleixner91f26cb2017-06-20 01:37:28 +020036 * No move required, if:
37 * - Interrupt is per cpu
38 * - Interrupt is not started
39 * - Affinity mask does not include this CPU.
40 *
41 * Note: Do not check desc->action as this might be a chained
42 * interrupt.
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080043 */
Thomas Gleixner91f26cb2017-06-20 01:37:28 +020044 if (irqd_is_per_cpu(d) || !irqd_is_started(d) ||
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080045 !cpumask_test_cpu(smp_processor_id(), affinity))
46 return false;
47
48 if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) {
49 affinity = cpu_online_mask;
Thomas Gleixnere8a70352017-06-20 01:37:27 +020050 brokeaff = true;
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080051 }
52
Thomas Gleixnere8a70352017-06-20 01:37:27 +020053 err = irq_do_set_affinity(d, affinity, false);
54 if (err) {
55 pr_warn_ratelimited("IRQ%u: set affinity failed(%d).\n",
56 d->irq, err);
57 return false;
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080058 }
Thomas Gleixnere8a70352017-06-20 01:37:27 +020059 return brokeaff;
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080060}
61
62/**
63 * irq_migrate_all_off_this_cpu - Migrate irqs away from offline cpu
64 *
65 * The current CPU has been marked offline. Migrate IRQs off this CPU.
66 * If the affinity settings do not allow other CPUs, force them onto any
67 * available CPU.
68 *
69 * Note: we must iterate over all IRQs, whether they have an attached
70 * action structure or not, as we need to get chained interrupts too.
71 */
72void irq_migrate_all_off_this_cpu(void)
73{
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080074 struct irq_desc *desc;
Thomas Gleixner0dd945f2017-06-20 01:37:25 +020075 unsigned int irq;
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080076
77 for_each_active_irq(irq) {
78 bool affinity_broken;
79
80 desc = irq_to_desc(irq);
81 raw_spin_lock(&desc->lock);
82 affinity_broken = migrate_one_irq(desc);
83 raw_spin_unlock(&desc->lock);
84
Thomas Gleixner0dd945f2017-06-20 01:37:25 +020085 if (affinity_broken) {
86 pr_warn_ratelimited("IRQ %u: no longer affine to CPU%u\n",
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080087 irq, smp_processor_id());
Thomas Gleixner0dd945f2017-06-20 01:37:25 +020088 }
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080089 }
Yang Yingliangf1e0bb02015-09-24 17:32:13 +080090}