2015-09-24 16:32:13 +07:00
|
|
|
/*
|
|
|
|
* Generic cpu hotunplug interrupt migration code copied from the
|
|
|
|
* arch/arm implementation
|
|
|
|
*
|
|
|
|
* Copyright (C) Russell King
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ratelimit.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
|
|
|
|
#include "internals.h"
|
|
|
|
|
|
|
|
static bool migrate_one_irq(struct irq_desc *desc)
|
|
|
|
{
|
|
|
|
struct irq_data *d = irq_desc_get_irq_data(desc);
|
2017-06-20 06:37:27 +07:00
|
|
|
struct irq_chip *chip = irq_data_get_irq_chip(d);
|
2015-09-24 16:32:13 +07:00
|
|
|
const struct cpumask *affinity = d->common->affinity;
|
2017-06-20 06:37:27 +07:00
|
|
|
bool brokeaff = false;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IRQ chip might be already torn down, but the irq descriptor is
|
|
|
|
* still in the radix tree. Also if the chip has no affinity setter,
|
|
|
|
* nothing can be done here.
|
|
|
|
*/
|
|
|
|
if (!chip || !chip->irq_set_affinity) {
|
|
|
|
pr_debug("IRQ %u: Unable to migrate away\n", d->irq);
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-24 16:32:13 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is a per-CPU interrupt, or the affinity does not
|
|
|
|
* include this CPU, then we have nothing to do.
|
|
|
|
*/
|
|
|
|
if (irqd_is_per_cpu(d) ||
|
|
|
|
!cpumask_test_cpu(smp_processor_id(), affinity))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) {
|
|
|
|
affinity = cpu_online_mask;
|
2017-06-20 06:37:27 +07:00
|
|
|
brokeaff = true;
|
2015-09-24 16:32:13 +07:00
|
|
|
}
|
|
|
|
|
2017-06-20 06:37:27 +07:00
|
|
|
err = irq_do_set_affinity(d, affinity, false);
|
|
|
|
if (err) {
|
|
|
|
pr_warn_ratelimited("IRQ%u: set affinity failed(%d).\n",
|
|
|
|
d->irq, err);
|
|
|
|
return false;
|
2015-09-24 16:32:13 +07:00
|
|
|
}
|
2017-06-20 06:37:27 +07:00
|
|
|
return brokeaff;
|
2015-09-24 16:32:13 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* irq_migrate_all_off_this_cpu - Migrate irqs away from offline cpu
|
|
|
|
*
|
|
|
|
* The current CPU has been marked offline. Migrate IRQs off this CPU.
|
|
|
|
* If the affinity settings do not allow other CPUs, force them onto any
|
|
|
|
* available CPU.
|
|
|
|
*
|
|
|
|
* Note: we must iterate over all IRQs, whether they have an attached
|
|
|
|
* action structure or not, as we need to get chained interrupts too.
|
|
|
|
*/
|
|
|
|
void irq_migrate_all_off_this_cpu(void)
|
|
|
|
{
|
|
|
|
struct irq_desc *desc;
|
2017-06-20 06:37:25 +07:00
|
|
|
unsigned int irq;
|
2015-09-24 16:32:13 +07:00
|
|
|
|
|
|
|
for_each_active_irq(irq) {
|
|
|
|
bool affinity_broken;
|
|
|
|
|
|
|
|
desc = irq_to_desc(irq);
|
|
|
|
raw_spin_lock(&desc->lock);
|
|
|
|
affinity_broken = migrate_one_irq(desc);
|
|
|
|
raw_spin_unlock(&desc->lock);
|
|
|
|
|
2017-06-20 06:37:25 +07:00
|
|
|
if (affinity_broken) {
|
|
|
|
pr_warn_ratelimited("IRQ %u: no longer affine to CPU%u\n",
|
2015-09-24 16:32:13 +07:00
|
|
|
irq, smp_processor_id());
|
2017-06-20 06:37:25 +07:00
|
|
|
}
|
2015-09-24 16:32:13 +07:00
|
|
|
}
|
|
|
|
}
|