Skip to content

Commit 7e62dd9

Browse files
author
Marc Zyngier
committed
Merge remote-tracking branch 'origin/irq/ipi-as-irq' into irq/irqchip-next
Signed-off-by: Marc Zyngier <maz@kernel.org>
2 parents 696966e + 8594c3b commit 7e62dd9

22 files changed

Lines changed: 769 additions & 461 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ config ARM
4949
select GENERIC_ARCH_TOPOLOGY if ARM_CPU_TOPOLOGY
5050
select GENERIC_ATOMIC64 if CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI
5151
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
52+
select GENERIC_IRQ_IPI if SMP
5253
select GENERIC_CPU_AUTOPROBE
5354
select GENERIC_EARLY_IOREMAP
5455
select GENERIC_IDLE_POLL_SETUP

‎arch/arm/include/asm/hardirq.h‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,12 @@
66
#include <linux/threads.h>
77
#include <asm/irq.h>
88

9-
/* number of IPIS _not_ including IPI_CPU_BACKTRACE */
10-
#define NR_IPI 7
11-
129
typedef struct {
1310
unsigned int __softirq_pending;
14-
#ifdef CONFIG_SMP
15-
unsigned int ipi_irqs[NR_IPI];
16-
#endif
1711
} ____cacheline_aligned irq_cpustat_t;
1812

1913
#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
2014

21-
#define __inc_irq_stat(cpu, member) __IRQ_STAT(cpu, member)++
22-
#define __get_irq_stat(cpu, member) __IRQ_STAT(cpu, member)
23-
24-
#ifdef CONFIG_SMP
25-
u64 smp_irq_stat_cpu(unsigned int cpu);
26-
#else
27-
#define smp_irq_stat_cpu(cpu) 0
28-
#endif
29-
30-
#define arch_irq_stat_cpu smp_irq_stat_cpu
31-
3215
#define __ARCH_IRQ_EXIT_IRQS_DISABLED 1
3316

3417
#endif /* __ASM_HARDIRQ_H */

‎arch/arm/include/asm/smp.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ void handle_IPI(int ipinr, struct pt_regs *regs);
3939
*/
4040
extern void smp_init_cpus(void);
4141

42-
4342
/*
44-
* Provide a function to raise an IPI cross call on CPUs in callmap.
43+
* Register IPI interrupts with the arch SMP code
4544
*/
46-
extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
45+
extern void set_smp_ipi_range(int ipi_base, int nr_ipi);
4746

4847
/*
4948
* Called from platform specific assembly code, this is the

‎arch/arm/kernel/irq.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* IRQ's are in fact implemented a bit like signal handlers for the kernel.
1919
* Naturally it's not a 1:1 relation, but there are similarities.
2020
*/
21-
#include <linux/kernel_stat.h>
2221
#include <linux/signal.h>
2322
#include <linux/ioport.h>
2423
#include <linux/interrupt.h>

‎arch/arm/kernel/smp.c‎

Lines changed: 90 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/completion.h>
2727
#include <linux/cpufreq.h>
2828
#include <linux/irq_work.h>
29+
#include <linux/kernel_stat.h>
2930

3031
#include <linux/atomic.h>
3132
#include <asm/bugs.h>
@@ -65,18 +66,27 @@ enum ipi_msg_type {
6566
IPI_CPU_STOP,
6667
IPI_IRQ_WORK,
6768
IPI_COMPLETION,
69+
NR_IPI,
6870
/*
6971
* CPU_BACKTRACE is special and not included in NR_IPI
7072
* or tracable with trace_ipi_*
7173
*/
72-
IPI_CPU_BACKTRACE,
74+
IPI_CPU_BACKTRACE = NR_IPI,
7375
/*
7476
* SGI8-15 can be reserved by secure firmware, and thus may
7577
* not be usable by the kernel. Please keep the above limited
7678
* to at most 8 entries.
7779
*/
80+
MAX_IPI
7881
};
7982

83+
static int ipi_irq_base __read_mostly;
84+
static int nr_ipi __read_mostly = NR_IPI;
85+
static struct irq_desc *ipi_desc[MAX_IPI] __read_mostly;
86+
87+
static void ipi_setup(int cpu);
88+
static void ipi_teardown(int cpu);
89+
8090
static DECLARE_COMPLETION(cpu_running);
8191

8292
static struct smp_operations smp_ops __ro_after_init;
@@ -247,6 +257,7 @@ int __cpu_disable(void)
247257
* and we must not schedule until we're ready to give up the cpu.
248258
*/
249259
set_cpu_online(cpu, false);
260+
ipi_teardown(cpu);
250261

251262
/*
252263
* OK - migrate IRQs away from this CPU
@@ -422,6 +433,8 @@ asmlinkage void secondary_start_kernel(void)
422433

423434
notify_cpu_starting(cpu);
424435

436+
ipi_setup(cpu);
437+
425438
calibrate_delay();
426439

427440
smp_store_cpu_info(cpu);
@@ -500,14 +513,6 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
500513
}
501514
}
502515

503-
static void (*__smp_cross_call)(const struct cpumask *, unsigned int);
504-
505-
void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
506-
{
507-
if (!__smp_cross_call)
508-
__smp_cross_call = fn;
509-
}
510-
511516
static const char *ipi_types[NR_IPI] __tracepoint_string = {
512517
#define S(x,s) [x] = s
513518
S(IPI_WAKEUP, "CPU wakeup interrupts"),
@@ -519,38 +524,23 @@ static const char *ipi_types[NR_IPI] __tracepoint_string = {
519524
S(IPI_COMPLETION, "completion interrupts"),
520525
};
521526

522-
static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
523-
{
524-
trace_ipi_raise_rcuidle(target, ipi_types[ipinr]);
525-
__smp_cross_call(target, ipinr);
526-
}
527+
static void smp_cross_call(const struct cpumask *target, unsigned int ipinr);
527528

528529
void show_ipi_list(struct seq_file *p, int prec)
529530
{
530531
unsigned int cpu, i;
531532

532533
for (i = 0; i < NR_IPI; i++) {
534+
unsigned int irq = irq_desc_get_irq(ipi_desc[i]);
533535
seq_printf(p, "%*s%u: ", prec - 1, "IPI", i);
534536

535537
for_each_online_cpu(cpu)
536-
seq_printf(p, "%10u ",
537-
__get_irq_stat(cpu, ipi_irqs[i]));
538+
seq_printf(p, "%10u ", kstat_irqs_cpu(irq, cpu));
538539

539540
seq_printf(p, " %s\n", ipi_types[i]);
540541
}
541542
}
542543

543-
u64 smp_irq_stat_cpu(unsigned int cpu)
544-
{
545-
u64 sum = 0;
546-
int i;
547-
548-
for (i = 0; i < NR_IPI; i++)
549-
sum += __get_irq_stat(cpu, ipi_irqs[i]);
550-
551-
return sum;
552-
}
553-
554544
void arch_send_call_function_ipi_mask(const struct cpumask *mask)
555545
{
556546
smp_cross_call(mask, IPI_CALL_FUNC);
@@ -627,25 +617,20 @@ asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
627617
handle_IPI(ipinr, regs);
628618
}
629619

630-
void handle_IPI(int ipinr, struct pt_regs *regs)
620+
static void do_handle_IPI(int ipinr)
631621
{
632622
unsigned int cpu = smp_processor_id();
633-
struct pt_regs *old_regs = set_irq_regs(regs);
634623

635-
if ((unsigned)ipinr < NR_IPI) {
624+
if ((unsigned)ipinr < NR_IPI)
636625
trace_ipi_entry_rcuidle(ipi_types[ipinr]);
637-
__inc_irq_stat(cpu, ipi_irqs[ipinr]);
638-
}
639626

640627
switch (ipinr) {
641628
case IPI_WAKEUP:
642629
break;
643630

644631
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
645632
case IPI_TIMER:
646-
irq_enter();
647633
tick_receive_broadcast();
648-
irq_exit();
649634
break;
650635
#endif
651636

@@ -654,36 +639,26 @@ void handle_IPI(int ipinr, struct pt_regs *regs)
654639
break;
655640

656641
case IPI_CALL_FUNC:
657-
irq_enter();
658642
generic_smp_call_function_interrupt();
659-
irq_exit();
660643
break;
661644

662645
case IPI_CPU_STOP:
663-
irq_enter();
664646
ipi_cpu_stop(cpu);
665-
irq_exit();
666647
break;
667648

668649
#ifdef CONFIG_IRQ_WORK
669650
case IPI_IRQ_WORK:
670-
irq_enter();
671651
irq_work_run();
672-
irq_exit();
673652
break;
674653
#endif
675654

676655
case IPI_COMPLETION:
677-
irq_enter();
678656
ipi_complete(cpu);
679-
irq_exit();
680657
break;
681658

682659
case IPI_CPU_BACKTRACE:
683660
printk_nmi_enter();
684-
irq_enter();
685-
nmi_cpu_backtrace(regs);
686-
irq_exit();
661+
nmi_cpu_backtrace(get_irq_regs());
687662
printk_nmi_exit();
688663
break;
689664

@@ -695,9 +670,78 @@ void handle_IPI(int ipinr, struct pt_regs *regs)
695670

696671
if ((unsigned)ipinr < NR_IPI)
697672
trace_ipi_exit_rcuidle(ipi_types[ipinr]);
673+
}
674+
675+
/* Legacy version, should go away once all irqchips have been converted */
676+
void handle_IPI(int ipinr, struct pt_regs *regs)
677+
{
678+
struct pt_regs *old_regs = set_irq_regs(regs);
679+
680+
irq_enter();
681+
do_handle_IPI(ipinr);
682+
irq_exit();
683+
698684
set_irq_regs(old_regs);
699685
}
700686

687+
static irqreturn_t ipi_handler(int irq, void *data)
688+
{
689+
do_handle_IPI(irq - ipi_irq_base);
690+
return IRQ_HANDLED;
691+
}
692+
693+
static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
694+
{
695+
trace_ipi_raise_rcuidle(target, ipi_types[ipinr]);
696+
__ipi_send_mask(ipi_desc[ipinr], target);
697+
}
698+
699+
static void ipi_setup(int cpu)
700+
{
701+
int i;
702+
703+
if (WARN_ON_ONCE(!ipi_irq_base))
704+
return;
705+
706+
for (i = 0; i < nr_ipi; i++)
707+
enable_percpu_irq(ipi_irq_base + i, 0);
708+
}
709+
710+
static void ipi_teardown(int cpu)
711+
{
712+
int i;
713+
714+
if (WARN_ON_ONCE(!ipi_irq_base))
715+
return;
716+
717+
for (i = 0; i < nr_ipi; i++)
718+
disable_percpu_irq(ipi_irq_base + i);
719+
}
720+
721+
void __init set_smp_ipi_range(int ipi_base, int n)
722+
{
723+
int i;
724+
725+
WARN_ON(n < MAX_IPI);
726+
nr_ipi = min(n, MAX_IPI);
727+
728+
for (i = 0; i < nr_ipi; i++) {
729+
int err;
730+
731+
err = request_percpu_irq(ipi_base + i, ipi_handler,
732+
"IPI", &irq_stat);
733+
WARN_ON(err);
734+
735+
ipi_desc[i] = irq_to_desc(ipi_base + i);
736+
irq_set_status_flags(ipi_base + i, IRQ_HIDDEN);
737+
}
738+
739+
ipi_irq_base = ipi_base;
740+
741+
/* Setup the boot CPU immediately */
742+
ipi_setup(smp_processor_id());
743+
}
744+
701745
void smp_send_reschedule(int cpu)
702746
{
703747
smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
@@ -805,7 +849,7 @@ core_initcall(register_cpufreq_notifier);
805849

806850
static void raise_nmi(cpumask_t *mask)
807851
{
808-
__smp_cross_call(mask, IPI_CPU_BACKTRACE);
852+
__ipi_send_mask(ipi_desc[IPI_CPU_BACKTRACE], mask);
809853
}
810854

811855
void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ config ARM64
106106
select GENERIC_CPU_VULNERABILITIES
107107
select GENERIC_EARLY_IOREMAP
108108
select GENERIC_IDLE_POLL_SETUP
109+
select GENERIC_IRQ_IPI
109110
select GENERIC_IRQ_MULTI_HANDLER
110111
select GENERIC_IRQ_PROBE
111112
select GENERIC_IRQ_SHOW

‎arch/arm64/include/asm/hardirq.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@
1313
#include <asm/kvm_arm.h>
1414
#include <asm/sysreg.h>
1515

16-
#define NR_IPI 7
17-
1816
typedef struct {
1917
unsigned int __softirq_pending;
20-
unsigned int ipi_irqs[NR_IPI];
2118
} ____cacheline_aligned irq_cpustat_t;
2219

2320
#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
2421

25-
#define __inc_irq_stat(cpu, member) __IRQ_STAT(cpu, member)++
26-
#define __get_irq_stat(cpu, member) __IRQ_STAT(cpu, member)
27-
28-
u64 smp_irq_stat_cpu(unsigned int cpu);
29-
#define arch_irq_stat_cpu smp_irq_stat_cpu
30-
3122
#define __ARCH_IRQ_EXIT_IRQS_DISABLED 1
3223

3324
struct nmi_ctx {

‎arch/arm64/include/asm/irq_work.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
#ifndef __ASM_IRQ_WORK_H
33
#define __ASM_IRQ_WORK_H
44

5-
#include <asm/smp.h>
6-
75
static inline bool arch_irq_work_has_interrupt(void)
86
{
9-
return !!__smp_cross_call;
7+
return true;
108
}
119

1210
#endif /* __ASM_IRQ_WORK_H */

‎arch/arm64/include/asm/smp.h‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,16 @@ static inline void set_cpu_logical_map(int cpu, u64 hwid)
5555

5656
struct seq_file;
5757

58-
/*
59-
* generate IPI list text
60-
*/
61-
extern void show_ipi_list(struct seq_file *p, int prec);
62-
63-
/*
64-
* Called from C code, this handles an IPI.
65-
*/
66-
extern void handle_IPI(int ipinr, struct pt_regs *regs);
67-
6858
/*
6959
* Discover the set of possible CPUs and determine their
7060
* SMP operations.
7161
*/
7262
extern void smp_init_cpus(void);
7363

7464
/*
75-
* Provide a function to raise an IPI cross call on CPUs in callmap.
65+
* Register IPI interrupts with the arch SMP code
7666
*/
77-
extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
78-
79-
extern void (*__smp_cross_call)(const struct cpumask *, unsigned int);
67+
extern void set_smp_ipi_range(int ipi_base, int nr_ipi);
8068

8169
/*
8270
* Called from the secondary holding pen, this is the secondary CPU entry point.

0 commit comments

Comments
 (0)