Skip to content

Commit a005677

Browse files
committed
genirq: Mirror IRQ_PER_CPU and IRQ_NO_BALANCING in irq_data.state
That's the right data structure to look at for arch code. Accessor functions are provided. irqd_is_per_cpu(irqdata); irqd_can_balance(irqdata); Coders who access them directly will be tracked down and slapped with stinking trouts. Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 1ce6068 commit a005677

7 files changed

Lines changed: 84 additions & 15 deletions

File tree

‎include/linux/irq.h‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,31 @@ struct irq_data {
132132
* Bit masks for irq_data.state
133133
*
134134
* IRQD_SETAFFINITY_PENDING - Affinity setting is pending
135+
* IRQD_NO_BALANCING - Balancing disabled for this IRQ
136+
* IRQD_PER_CPU - Interrupt is per cpu
135137
*/
136138
enum {
137139
/* Bit 0 - 7 reserved for TYPE will use later */
138-
IRQD_SETAFFINITY_PENDING = (1 << 8),
140+
IRQD_SETAFFINITY_PENDING = (1 << 8),
141+
IRQD_NO_BALANCING = (1 << 10),
142+
IRQD_PER_CPU = (1 << 11),
139143
};
140144

141145
static inline bool irqd_is_setaffinity_pending(struct irq_data *d)
142146
{
143147
return d->state_use_accessors & IRQD_SETAFFINITY_PENDING;
144148
}
145149

150+
static inline bool irqd_is_per_cpu(struct irq_data *d)
151+
{
152+
return d->state_use_accessors & IRQD_PER_CPU;
153+
}
154+
155+
static inline bool irqd_can_balance(struct irq_data *d)
156+
{
157+
return !(d->state_use_accessors & (IRQD_PER_CPU | IRQD_NO_BALANCING));
158+
}
159+
146160
/**
147161
* struct irq_chip - hardware interrupt chip descriptor
148162
*

‎kernel/irq/chip.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,15 @@ void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
706706
if (!desc)
707707
return;
708708

709-
/* Sanitize flags */
710-
set &= IRQF_MODIFY_MASK;
711-
clr &= IRQF_MODIFY_MASK;
712-
713709
raw_spin_lock_irqsave(&desc->lock, flags);
714-
desc->status &= ~clr;
715-
desc->status |= set;
710+
711+
irq_settings_clr_and_set(desc, clr, set);
712+
713+
irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU);
714+
if (irq_settings_has_no_balance_set(desc))
715+
irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
716+
if (irq_settings_is_per_cpu(desc))
717+
irqd_set(&desc->irq_data, IRQD_PER_CPU);
718+
716719
raw_spin_unlock_irqrestore(&desc->lock, flags);
717720
}

‎kernel/irq/internals.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,14 @@ static inline void irqd_clr_move_pending(struct irq_data *d)
139139
d->state_use_accessors &= ~IRQD_SETAFFINITY_PENDING;
140140
irq_compat_clr_move_pending(irq_data_to_desc(d));
141141
}
142+
143+
static inline void irqd_clear(struct irq_data *d, unsigned int mask)
144+
{
145+
d->state_use_accessors &= ~mask;
146+
}
147+
148+
static inline void irqd_set(struct irq_data *d, unsigned int mask)
149+
{
150+
d->state_use_accessors |= mask;
151+
}
152+

‎kernel/irq/manage.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ int irq_can_set_affinity(unsigned int irq)
7373
{
7474
struct irq_desc *desc = irq_to_desc(irq);
7575

76-
if ((desc->status & (IRQ_PER_CPU | IRQ_NO_BALANCING)) ||
77-
!desc->irq_data.chip || !desc->irq_data.chip->irq_set_affinity)
76+
if (!irqd_can_balance(&desc->irq_data) || !desc->irq_data.chip ||
77+
!desc->irq_data.chip->irq_set_affinity)
7878
return 0;
7979

8080
return 1;
@@ -897,8 +897,10 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
897897
IRQS_INPROGRESS | IRQS_ONESHOT | \
898898
IRQS_WAITING);
899899

900-
if (new->flags & IRQF_PERCPU)
901-
desc->status |= IRQ_PER_CPU;
900+
if (new->flags & IRQF_PERCPU) {
901+
irqd_set(&desc->irq_data, IRQD_PER_CPU);
902+
irq_settings_set_per_cpu(desc);
903+
}
902904

903905
if (new->flags & IRQF_ONESHOT)
904906
desc->istate |= IRQS_ONESHOT;
@@ -910,8 +912,10 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
910912
desc->depth = 1;
911913

912914
/* Exclude IRQ from balancing if requested */
913-
if (new->flags & IRQF_NOBALANCING)
914-
desc->status |= IRQ_NO_BALANCING;
915+
if (new->flags & IRQF_NOBALANCING) {
916+
irq_settings_set_no_balancing(desc);
917+
irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
918+
}
915919

916920
/* Set default affinity mask once everything is setup */
917921
setup_affinity(irq, desc, mask);

‎kernel/irq/migration.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void move_masked_irq(int irq)
1515
/*
1616
* Paranoia: cpu-local interrupts shouldn't be calling in here anyway.
1717
*/
18-
if (desc->status & (IRQ_PER_CPU | IRQ_NO_BALANCING)) {
18+
if (!irqd_can_balance(&desc->irq_data)) {
1919
WARN_ON(1);
2020
return;
2121
}

‎kernel/irq/settings.h‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*/
55
enum {
66
_IRQ_DEFAULT_INIT_FLAGS = IRQ_DEFAULT_INIT_FLAGS,
7+
_IRQ_PER_CPU = IRQ_PER_CPU,
8+
_IRQ_NO_BALANCING = IRQ_NO_BALANCING,
9+
_IRQF_MODIFY_MASK = IRQF_MODIFY_MASK,
710
};
811

912
#undef IRQ_INPROGRESS
@@ -22,3 +25,36 @@ enum {
2225
#define IRQ_WAKEUP GOT_YOU_MORON
2326
#undef IRQ_MOVE_PENDING
2427
#define IRQ_MOVE_PENDING GOT_YOU_MORON
28+
#undef IRQ_PER_CPU
29+
#define IRQ_PER_CPU GOT_YOU_MORON
30+
#undef IRQ_NO_BALANCING
31+
#define IRQ_NO_BALANCING GOT_YOU_MORON
32+
#undef IRQF_MODIFY_MASK
33+
#define IRQF_MODIFY_MASK GOT_YOU_MORON
34+
35+
static inline void
36+
irq_settings_clr_and_set(struct irq_desc *desc, u32 clr, u32 set)
37+
{
38+
desc->status &= ~(clr & _IRQF_MODIFY_MASK);
39+
desc->status |= (set & _IRQF_MODIFY_MASK);
40+
}
41+
42+
static inline bool irq_settings_is_per_cpu(struct irq_desc *desc)
43+
{
44+
return desc->status & _IRQ_PER_CPU;
45+
}
46+
47+
static inline void irq_settings_set_per_cpu(struct irq_desc *desc)
48+
{
49+
desc->status |= _IRQ_PER_CPU;
50+
}
51+
52+
static inline void irq_settings_set_no_balancing(struct irq_desc *desc)
53+
{
54+
desc->status |= _IRQ_NO_BALANCING;
55+
}
56+
57+
static inline bool irq_settings_has_no_balance_set(struct irq_desc *desc)
58+
{
59+
return desc->status & _IRQ_NO_BALANCING;
60+
}

‎kernel/irq/spurious.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ static int try_one_irq(int irq, struct irq_desc *desc, bool force)
6868
raw_spin_lock(&desc->lock);
6969

7070
/* PER_CPU and nested thread interrupts are never polled */
71-
if (desc->status & (IRQ_PER_CPU | IRQ_NESTED_THREAD))
71+
if (irq_settings_is_per_cpu(desc) ||
72+
(desc->status & IRQ_NESTED_THREAD))
7273
goto out;
7374

7475
/*

0 commit comments

Comments
 (0)