Skip to contentSkip to conversation

normalize return value of chip->irq_set_affinity()

PATCH In review Jiang Liu 2 participants 14 messages Mar 30, 2012 – May 24, 2012

Subsystems (3)
lore
Share & tools
lore

Jiang Liu

author
#0 lore raw

v3 cover normalize return value of chip->irq_set_affinity()

On x86 platforms, interrupt controller chip's irq_set_affinity() method always copies affinity mask to irq_data->affinity field but still returns 0(IRQ_SET_MASK_OK). That return value causes the interrupt core logic unnecessarily copies the mask to irq_data->affinity field again. So return IRQ_SET_MASK_OK_NOCOPY instead of IRQ_SET_MASK_OK to get rid of the duplicated copy operation.

This patch also fixes a minor bug in irq_move_masked_irq(), which treats return value IRQ_SET_MASK_OK_NOCOPY as error code.

v2/v3: split patches to only do one thing in a patch according to Thomas'
suggestion

Jiang Liu (4):
IRQ: correctly handle return value from chip->irq_set_affinity() in
irq_move_masked_irq()
IRQ: introduce irq_do_set_affinity() to reduce duplicated code IRQ,x86: normalize return value of chip->irq_set_affinity() method IRQ,IA64: normalize return value of chip->irq_set_affinity() method

 arch/ia64/kernel/iosapic.c     |    4 +++-
 arch/ia64/kernel/msi_ia64.c    |    4 ++--
 arch/ia64/sn/kernel/irq.c      |    2 +-
 arch/ia64/sn/kernel/msi_sn.c   |    2 +-
 arch/x86/kernel/apic/io_apic.c |   11 ++++++-----
 arch/x86/platform/uv/uv_irq.c  |    2 +-
 kernel/irq/internals.h         |    3 +++
 kernel/irq/manage.c            |   39 ++++++++++++++++++++++-----------------
 kernel/irq/migration.c         |    6 +-----
 9 files changed, 40 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH v3 1/4 IRQ: correctly handle return value from chip->irq_set_affinity() in irq_move_masked_irq()

chip->irq_set_affinity() may return IRQ_SET_MASK_OK_NOCOPY if the mask has been copied to desc->irq_data.affinity, but irq_move_masked_irq() incorrectly treats that return value as error code.

---
 kernel/irq/migration.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
kernel/irq/migration.c +7 -3
index 4742090..c3c8975 100644
@@ -43,12 +43,16 @@ void irq_move_masked_irq(struct irq_data *idata)
 	 * masking the irqs.
 	 */
 	if (likely(cpumask_any_and(desc->pending_mask, cpu_online_mask)
-		   < nr_cpu_ids))
-		if (!chip->irq_set_affinity(&desc->irq_data,
-					    desc->pending_mask, false)) {
+		   < nr_cpu_ids)) {
+		int ret = chip->irq_set_affinity(&desc->irq_data,
+						 desc->pending_mask, false);
+		switch (ret) {
+		case IRQ_SET_MASK_OK:
 			cpumask_copy(desc->irq_data.affinity, desc->pending_mask);
+		case IRQ_SET_MASK_OK_NOCOPY:
 			irq_set_thread_affinity(desc);
 		}
+	}
 
 	cpumask_clear(desc->pending_mask);
 }
Signature · 1 line
1.7.5.4
#2 lore raw

[tip:irq/core] genirq: Adjust irq thread affinity on IRQ_SET_MASK_OK_NOCOPY return value

Commit-ID:  f5cb92ac82d06cb583c1f66666314c5c0a4d7913
Gitweb:     http://git.kernel.org/tip/f5cb92ac82d06cb583c1f66666314c5c0a4d7913
Author:     Jiang Liu <[email protected]>
AuthorDate: Fri, 30 Mar 2012 23:11:33 +0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 30 Mar 2012 23:13:46 +0200

genirq: Adjust irq thread affinity on IRQ_SET_MASK_OK_NOCOPY return value

irq_move_masked_irq() checks the return code of chip->irq_set_affinity() only for 0, but IRQ_SET_MASK_OK_NOCOPY is also a valid return code, which is there to avoid a redundant copy of the cpumask. But in case of IRQ_SET_MASK_OK_NOCOPY we not only avoid the redundant copy, we also fail to adjust the thread affinity of an eventually threaded interrupt handler.

Handle IRQ_SET_MASK_OK (==0) and IRQ_SET_MASK_OK_NOCOPY(==1) return values correctly by checking the valid return values seperately.

---
 kernel/irq/migration.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
kernel/irq/migration.c +7 -3
index 4742090..c3c8975 100644
@@ -43,12 +43,16 @@ void irq_move_masked_irq(struct irq_data *idata)
 	 * masking the irqs.
 	 */
 	if (likely(cpumask_any_and(desc->pending_mask, cpu_online_mask)
-		   < nr_cpu_ids))
-		if (!chip->irq_set_affinity(&desc->irq_data,
-					    desc->pending_mask, false)) {
+		   < nr_cpu_ids)) {
+		int ret = chip->irq_set_affinity(&desc->irq_data,
+						 desc->pending_mask, false);
+		switch (ret) {
+		case IRQ_SET_MASK_OK:
 			cpumask_copy(desc->irq_data.affinity, desc->pending_mask);
+		case IRQ_SET_MASK_OK_NOCOPY:
 			irq_set_thread_affinity(desc);
 		}
+	}
 
 	cpumask_clear(desc->pending_mask);
 }
author
#3 lore raw

PATCH v3 2/4 IRQ: introduce irq_do_set_affinity() to reduce duplicated code

In reply to Jiang Liu

Introduce function irq_do_set_affinity() to reduce duplicated code.

---
 kernel/irq/internals.h |    3 +++
 kernel/irq/manage.c    |   39 ++++++++++++++++++++++-----------------
 kernel/irq/migration.c |   12 ++----------
 3 files changed, 27 insertions(+), 27 deletions(-)
kernel/irq/internals.h +3 -0
index 8e5c56b..001fa5b 100644
@@ -101,6 +101,9 @@ extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask);
 
 extern void irq_set_thread_affinity(struct irq_desc *desc);
 
+extern int irq_do_set_affinity(struct irq_data *data,
+			       const struct cpumask *dest, bool force);
+
 /* Inline functions for support of irq chips on slow busses */
 static inline void chip_bus_lock(struct irq_desc *desc)
 {
kernel/irq/manage.c +22 -17
index b0ccd1a..d2724a0 100644
@@ -139,6 +139,25 @@ static inline void
 irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { }
 #endif
 
+int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
+			bool force)
+{
+	struct irq_desc *desc = irq_data_to_desc(data);
+	struct irq_chip *chip = irq_data_get_irq_chip(data);
+	int ret;
+
+	ret = chip->irq_set_affinity(data, mask, false);
+	switch (ret) {
+	case IRQ_SET_MASK_OK:
+		cpumask_copy(data->affinity, mask);
+	case IRQ_SET_MASK_OK_NOCOPY:
+		irq_set_thread_affinity(desc);
+		ret = 0;
+	}
+
+	return ret;
+}
+
 int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask)
 {
 	struct irq_chip *chip = irq_data_get_irq_chip(data);
@@ -149,14 +168,7 @@ int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask)
 		return -EINVAL;
 
 	if (irq_can_move_pcntxt(data)) {
-		ret = chip->irq_set_affinity(data, mask, false);
-		switch (ret) {
-		case IRQ_SET_MASK_OK:
-			cpumask_copy(data->affinity, mask);
-		case IRQ_SET_MASK_OK_NOCOPY:
-			irq_set_thread_affinity(desc);
-			ret = 0;
-		}
+		ret = irq_do_set_affinity(data, mask, false);
 	} else {
 		irqd_set_move_pending(data);
 		irq_copy_pending(desc, mask);
@@ -280,9 +292,7 @@ EXPORT_SYMBOL_GPL(irq_set_affinity_notifier);
 static int
 setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask)
 {
-	struct irq_chip *chip = irq_desc_get_chip(desc);
 	struct cpumask *set = irq_default_affinity;
-	int ret;
 
 	/* Excludes PER_CPU and NO_BALANCE interrupts */
 	if (!irq_can_set_affinity(irq))
@@ -301,13 +311,8 @@ setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask)
 	}
 
 	cpumask_and(mask, cpu_online_mask, set);
-	ret = chip->irq_set_affinity(&desc->irq_data, mask, false);
-	switch (ret) {
-	case IRQ_SET_MASK_OK:
-		cpumask_copy(desc->irq_data.affinity, mask);
-	case IRQ_SET_MASK_OK_NOCOPY:
-		irq_set_thread_affinity(desc);
-	}
+	irq_do_set_affinity(&desc->irq_data, mask, false);
+
 	return 0;
 }
 #else
kernel/irq/migration.c +2 -10
index c3c8975..ef04dab 100644
@@ -43,16 +43,8 @@ void irq_move_masked_irq(struct irq_data *idata)
 	 * masking the irqs.
 	 */
 	if (likely(cpumask_any_and(desc->pending_mask, cpu_online_mask)
-		   < nr_cpu_ids)) {
-		int ret = chip->irq_set_affinity(&desc->irq_data,
-						 desc->pending_mask, false);
-		switch (ret) {
-		case IRQ_SET_MASK_OK:
-			cpumask_copy(desc->irq_data.affinity, desc->pending_mask);
-		case IRQ_SET_MASK_OK_NOCOPY:
-			irq_set_thread_affinity(desc);
-		}
-	}
+		   < nr_cpu_ids))
+		irq_do_set_affinity(&desc->irq_data, desc->pending_mask, false);
 
 	cpumask_clear(desc->pending_mask);
 }
Signature · 1 line
1.7.5.4
#4 lore raw

[tip:irq/core] genirq: Introduce irq_do_set_affinity() to reduce duplicated code

Commit-ID:  818b0f3bfb236ae66cac3ff38e86b9e47f24b7aa
Gitweb:     http://git.kernel.org/tip/818b0f3bfb236ae66cac3ff38e86b9e47f24b7aa
Author:     Jiang Liu <[email protected]>
AuthorDate: Fri, 30 Mar 2012 23:11:34 +0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 24 May 2012 22:36:40 +0200

genirq: Introduce irq_do_set_affinity() to reduce duplicated code

All invocations of chip->irq_set_affinity() are doing the same return value checks. Let them all use a common function.

[ tglx: removed the silly likely while at it ]

---
 kernel/irq/internals.h |    3 +++
 kernel/irq/manage.c    |   39 ++++++++++++++++++++++-----------------
 kernel/irq/migration.c |   13 ++-----------
 3 files changed, 27 insertions(+), 28 deletions(-)
kernel/irq/internals.h +3 -0
index 8e5c56b..001fa5b 100644
@@ -101,6 +101,9 @@ extern int irq_select_affinity_usr(unsigned int irq, struct cpumask *mask);
 
 extern void irq_set_thread_affinity(struct irq_desc *desc);
 
+extern int irq_do_set_affinity(struct irq_data *data,
+			       const struct cpumask *dest, bool force);
+
 /* Inline functions for support of irq chips on slow busses */
 static inline void chip_bus_lock(struct irq_desc *desc)
 {
kernel/irq/manage.c +22 -17
index bb32326..a1b9033 100644
@@ -139,6 +139,25 @@ static inline void
 irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { }
 #endif
 
+int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
+			bool force)
+{
+	struct irq_desc *desc = irq_data_to_desc(data);
+	struct irq_chip *chip = irq_data_get_irq_chip(data);
+	int ret;
+
+	ret = chip->irq_set_affinity(data, mask, false);
+	switch (ret) {
+	case IRQ_SET_MASK_OK:
+		cpumask_copy(data->affinity, mask);
+	case IRQ_SET_MASK_OK_NOCOPY:
+		irq_set_thread_affinity(desc);
+		ret = 0;
+	}
+
+	return ret;
+}
+
 int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask)
 {
 	struct irq_chip *chip = irq_data_get_irq_chip(data);
@@ -149,14 +168,7 @@ int __irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask)
 		return -EINVAL;
 
 	if (irq_can_move_pcntxt(data)) {
-		ret = chip->irq_set_affinity(data, mask, false);
-		switch (ret) {
-		case IRQ_SET_MASK_OK:
-			cpumask_copy(data->affinity, mask);
-		case IRQ_SET_MASK_OK_NOCOPY:
-			irq_set_thread_affinity(desc);
-			ret = 0;
-		}
+		ret = irq_do_set_affinity(data, mask, false);
 	} else {
 		irqd_set_move_pending(data);
 		irq_copy_pending(desc, mask);
@@ -280,9 +292,8 @@ EXPORT_SYMBOL_GPL(irq_set_affinity_notifier);
 static int
 setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask)
 {
-	struct irq_chip *chip = irq_desc_get_chip(desc);
 	struct cpumask *set = irq_default_affinity;
-	int ret, node = desc->irq_data.node;
+	int node = desc->irq_data.node;
 
 	/* Excludes PER_CPU and NO_BALANCE interrupts */
 	if (!irq_can_set_affinity(irq))
@@ -308,13 +319,7 @@ setup_affinity(unsigned int irq, struct irq_desc *desc, struct cpumask *mask)
 		if (cpumask_intersects(mask, nodemask))
 			cpumask_and(mask, mask, nodemask);
 	}
-	ret = chip->irq_set_affinity(&desc->irq_data, mask, false);
-	switch (ret) {
-	case IRQ_SET_MASK_OK:
-		cpumask_copy(desc->irq_data.affinity, mask);
-	case IRQ_SET_MASK_OK_NOCOPY:
-		irq_set_thread_affinity(desc);
-	}
+	irq_do_set_affinity(&desc->irq_data, mask, false);
 	return 0;
 }
 #else
kernel/irq/migration.c +2 -11
index c3c8975..ca3f4aa 100644
@@ -42,17 +42,8 @@ void irq_move_masked_irq(struct irq_data *idata)
 	 * For correct operation this depends on the caller
 	 * masking the irqs.
 	 */
-	if (likely(cpumask_any_and(desc->pending_mask, cpu_online_mask)
-		   < nr_cpu_ids)) {
-		int ret = chip->irq_set_affinity(&desc->irq_data,
-						 desc->pending_mask, false);
-		switch (ret) {
-		case IRQ_SET_MASK_OK:
-			cpumask_copy(desc->irq_data.affinity, desc->pending_mask);
-		case IRQ_SET_MASK_OK_NOCOPY:
-			irq_set_thread_affinity(desc);
-		}
-	}
+	if (cpumask_any_and(desc->pending_mask, cpu_online_mask) < nr_cpu_ids)
+		irq_do_set_affinity(&desc->irq_data, desc->pending_mask, false);
 
 	cpumask_clear(desc->pending_mask);
 }
author
#5 lore raw

PATCH v3 3/4 IRQ,x86: normalize return value of chip->irq_set_affinity() method

In reply to Jiang Liu

On x86 platforms, interrupt controller chip's irq_set_affinity() method always copies affinity mask to irq_data->affinity field but still returns 0(IRQ_SET_MASK_OK). That return value causes the interrupt core logic unnecessarily copies the mask to irq_data->affinity field again. So return IRQ_SET_MASK_OK_NOCOPY instead of IRQ_SET_MASK_OK to get rid of the duplicated copy operation.

---
 arch/x86/kernel/apic/io_apic.c |   11 ++++++-----
 arch/x86/platform/uv/uv_irq.c  |    2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/io_apic.c +6 -5
index 6d10a66..092a715 100644
@@ -2346,6 +2346,7 @@ ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 		/* Only the high 8 bits are valid. */
 		dest = SET_APIC_LOGICAL_ID(dest);
 		__target_IO_APIC_irq(irq, dest, data->chip_data);
+		ret = IRQ_SET_MASK_OK_NOCOPY;
 	}
 	raw_spin_unlock_irqrestore(&ioapic_lock, flags);
 	return ret;
@@ -2404,7 +2405,7 @@ ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 		send_cleanup_vector(cfg);
 
 	cpumask_copy(data->affinity, mask);
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #else
@@ -3209,7 +3210,7 @@ msi_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
 
 	__write_msi_msg(data->msi_desc, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 #endif /* CONFIG_SMP */
 
@@ -3366,7 +3367,7 @@ dmar_msi_set_affinity(struct irq_data *data, const struct cpumask *mask,
 
 	dmar_msi_write(irq, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #endif /* CONFIG_SMP */
@@ -3419,7 +3420,7 @@ static int hpet_msi_set_affinity(struct irq_data *data,
 
 	hpet_msi_write(data->handler_data, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #endif /* CONFIG_SMP */
@@ -3499,7 +3500,7 @@ ht_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
 		return -1;
 
 	target_ht_irq(data->irq, dest, cfg->vector);
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #endif
arch/x86/platform/uv/uv_irq.c +1 -1
index f25c276..a22c416 100644
@@ -222,7 +222,7 @@ uv_set_irq_affinity(struct irq_data *data, const struct cpumask *mask,
 	if (cfg->move_in_progress)
 		send_cleanup_vector(cfg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 /*
Signature · 1 line
1.7.5.4
#6 lore raw

Re: [PATCH v3 3/4] IRQ,x86: normalize return value of chip->irq_set_affinity() method

Quoted 2 lines · Jiang Liu

On x86 platforms, interrupt controller chip's irq_set_affinity() method always copies affinity mask to irq_data->affinity field but still returns

Now the question here is whether it copies the mask because it modified the mask in some way and want to reflect the change back.

If it just copies the unmodified mask, then this patch is wrong. It should remove the copy from the arch code and return IRQ_SET_MASK_OK so the core code can take care of the copying.

Ditto for the ia64 one.

Thanks,

tglx

author
#7 lore raw

Re: [PATCH v3 3/4] IRQ,x86: normalize return value of chip->irq_set_affinity() method

Hi Thomas,
Thanks for point this out. After checking related code again, I found
the method suggested by you will produce better code, so will send out another version to remove the duplicated memory copy operations in arch specific code.
When I was reading the comment for IRQ_SET_MASK_OK_NOCOPY, I thought
both way are ok to update the affinity mask by arch code or core logic, and haven't realized the issue raised by you.
Thanks!
Gerry

Quoted 17 lines · Thomas Gleixner
Quoted 2 lines · Jiang Liu

On x86 platforms, interrupt controller chip's irq_set_affinity() method always copies affinity mask to irq_data->affinity field but still returns

Now the question here is whether it copies the mask because it modified the mask in some way and want to reflect the change back.

If it just copies the unmodified mask, then this patch is wrong. It should remove the copy from the arch code and return IRQ_SET_MASK_OK so the core code can take care of the copying.

Ditto for the ia64 one.

Thanks,

tglx

author
#8 lore raw

PATCH v3 1/4 IRQ,x86: remove redundant memory copy operations in chip->irq_set_affinity()

Changeset 3b8249e7 has introduced standard return value IRQ_SET_MASK_OK(0) and IRQ_SET_MASK_OK_NOCOPY(1) for interrupt controller chip's set_irq_affinity() method. If chip->irq_set_affinity() doesn't change the affinity mask passed in, it should return IRQ_SET_MASK_OK and the core logic will copy the affinity mask to irq_data->affinity field.

Several xxx_irq_set_affinity() methods for x86 platforms still return 0(IRQ_SET_MASK_OK) after copying the affinity mask to irq_data->affinity field, so remove the redundant memory copy operations.

---
 arch/x86/kernel/apic/io_apic.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/apic/io_apic.c +3 -3
index 6d10a66..c68954e 100644
@@ -2326,9 +2326,8 @@ int __ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 	if (assign_irq_vector(data->irq, data->chip_data, mask))
 		return -1;
 
-	cpumask_copy(data->affinity, mask);
-
 	*dest_id = apic->cpu_mask_to_apicid_and(mask, cfg->domain);
+
 	return 0;
 }
 
@@ -2403,7 +2402,6 @@ ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 	if (cfg->move_in_progress)
 		send_cleanup_vector(cfg);
 
-	cpumask_copy(data->affinity, mask);
 	return 0;
 }
 
@@ -3832,6 +3830,8 @@ void __init setup_ioapic_dest(void)
 			ir_ioapic_set_affinity(idata, mask, false);
 		else
 			ioapic_set_affinity(idata, mask, false);
+
+		cpumask_copy(idata->affinity, mask);
 	}
 
 }
Signature · 1 line
1.7.5.4
author
#9 lore raw

PATCH v3 2/4 IRQ,x86: normalize return value of chip->irq_set_affinity() method

Changeset 3b8249e7 has introduced standard return value IRQ_SET_MASK_OK(0) and IRQ_SET_MASK_OK_NOCOPY(1) for interrupt controller chip's set_irq_affinity() method. So use IRQ_SET_MASK_OK instead of 0 for consistency.

---
 arch/x86/kernel/apic/io_apic.c |   11 ++++++-----
 arch/x86/platform/uv/uv_irq.c  |    2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/io_apic.c +6 -5
index c68954e..18e73b3 100644
@@ -2345,6 +2345,7 @@ ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 		/* Only the high 8 bits are valid. */
 		dest = SET_APIC_LOGICAL_ID(dest);
 		__target_IO_APIC_irq(irq, dest, data->chip_data);
+		ret = IRQ_SET_MASK_OK;
 	}
 	raw_spin_unlock_irqrestore(&ioapic_lock, flags);
 	return ret;
@@ -2402,7 +2403,7 @@ ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 	if (cfg->move_in_progress)
 		send_cleanup_vector(cfg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 
 #else
@@ -3207,7 +3208,7 @@ msi_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
 
 	__write_msi_msg(data->msi_desc, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 #endif /* CONFIG_SMP */
 
@@ -3364,7 +3365,7 @@ dmar_msi_set_affinity(struct irq_data *data, const struct cpumask *mask,
 
 	dmar_msi_write(irq, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 
 #endif /* CONFIG_SMP */
@@ -3417,7 +3418,7 @@ static int hpet_msi_set_affinity(struct irq_data *data,
 
 	hpet_msi_write(data->handler_data, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 
 #endif /* CONFIG_SMP */
@@ -3497,7 +3498,7 @@ ht_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
 		return -1;
 
 	target_ht_irq(data->irq, dest, cfg->vector);
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 
 #endif
arch/x86/platform/uv/uv_irq.c +1 -1
index f25c276..67e3509 100644
@@ -222,7 +222,7 @@ uv_set_irq_affinity(struct irq_data *data, const struct cpumask *mask,
 	if (cfg->move_in_progress)
 		send_cleanup_vector(cfg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 
 /*
Signature · 1 line
1.7.5.4
author
#10 lore raw

PATCH v3 3/4 IRQ,IA64: remove redundant memory copy operations in chip->irq_set_affinity()

In reply to Jiang Liu

Changeset 3b8249e7 has introduced standard return value IRQ_SET_MASK_OK(0) and IRQ_SET_MASK_OK_NOCOPY(1) for interrupt controller chip's set_irq_affinity() method. If chip->irq_set_affinity() doesn't change the affinity mask passed in, it should return IRQ_SET_MASK_OK and the core logic will copy the affinity mask to irq_data->affinity field.

Several xxx_irq_set_affinity() methods for IA64 platforms still return 0(IRQ_SET_MASK_OK) after copying the affinity mask to irq_data->affinity field, so remove the redundant memory copy operations.

---
 arch/ia64/kernel/msi_ia64.c  |    2 --
 arch/ia64/sn/kernel/msi_sn.c |    1 -
 2 files changed, 0 insertions(+), 3 deletions(-)
arch/ia64/kernel/msi_ia64.c +0 -2
index fb2f1e6..05f5dc6 100644
@@ -39,7 +39,6 @@ static int ia64_set_msi_irq_affinity(struct irq_data *idata,
 	msg.data = data;
 
 	write_msi_msg(irq, &msg);
-	cpumask_copy(idata->affinity, cpumask_of(cpu));
 
 	return 0;
 }
@@ -155,7 +154,6 @@ static int dmar_msi_set_affinity(struct irq_data *data,
 	msg.address_lo |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu));
 
 	dmar_msi_write(irq, &msg);
-	cpumask_copy(data->affinity, mask);
 
 	return 0;
 }
arch/ia64/sn/kernel/msi_sn.c +0 -1
index 2b98b9e..a033fc9 100644
@@ -206,7 +206,6 @@ static int sn_set_msi_irq_affinity(struct irq_data *data,
 	msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
 
 	write_msi_msg(irq, &msg);
-	cpumask_copy(data->affinity, cpu_mask);
 
 	return 0;
 }
Signature · 1 line
1.7.5.4
author
#11 lore raw

PATCH v3 4/4 IRQ,IA64: normalize return value of chip->irq_set_affinity() method

In reply to Jiang Liu

Changeset 3b8249e7 has introduced standard return value IRQ_SET_MASK_OK(0) and IRQ_SET_MASK_OK_NOCOPY(1) for interrupt controller chip's set_irq_affinity() method. So use IRQ_SET_MASK_OK instead of 0 for consistency.

---
 arch/ia64/kernel/iosapic.c   |    4 ++--
 arch/ia64/kernel/msi_ia64.c  |    4 ++--
 arch/ia64/sn/kernel/irq.c    |    2 +-
 arch/ia64/sn/kernel/msi_sn.c |    2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)
arch/ia64/kernel/iosapic.c +2 -2
index ef4b5d8..5f67fcb 100644
@@ -372,9 +372,9 @@ iosapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 		iosapic_write(iosapic, IOSAPIC_RTE_HIGH(rte_index), high32);
 		iosapic_write(iosapic, IOSAPIC_RTE_LOW(rte_index), low32);
 	}
-
 #endif
-	return 0;
+
+	return IRQ_SET_MASK_OK;
 }
 
 /*
arch/ia64/kernel/msi_ia64.c +2 -2
index 05f5dc6..e1cc71d 100644
@@ -40,7 +40,7 @@ static int ia64_set_msi_irq_affinity(struct irq_data *idata,
 
 	write_msi_msg(irq, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 #endif /* CONFIG_SMP */
 
@@ -155,7 +155,7 @@ static int dmar_msi_set_affinity(struct irq_data *data,
 
 	dmar_msi_write(irq, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 #endif /* CONFIG_SMP */
 
arch/ia64/sn/kernel/irq.c +1 -1
index 62cf4dd..57cedda 100644
@@ -216,7 +216,7 @@ static int sn_set_affinity_irq(struct irq_data *data,
 				 sn_irq_lh[irq], list)
 		(void)sn_retarget_vector(sn_irq_info, nasid, slice);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 
 #ifdef CONFIG_SMP
arch/ia64/sn/kernel/msi_sn.c +1 -1
index a033fc9..4249c87 100644
@@ -207,7 +207,7 @@ static int sn_set_msi_irq_affinity(struct irq_data *data,
 
 	write_msi_msg(irq, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK;
 }
 #endif /* CONFIG_SMP */
 
Signature · 1 line
1.7.5.4
#12 lore raw

[tip:x86/cleanups] x86: Return IRQ_SET_MASK_OK_NOCOPY from irq affinity functions

In reply to Jiang Liu
Commit-ID:  f841d792e38f75f5e25b0b66f7b5d235d180a735
Gitweb:     http://git.kernel.org/tip/f841d792e38f75f5e25b0b66f7b5d235d180a735
Author:     Jiang Liu <[email protected]>
AuthorDate: Fri, 30 Mar 2012 23:11:35 +0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Thu, 24 May 2012 23:16:33 +0200

x86: Return IRQ_SET_MASK_OK_NOCOPY from irq affinity functions

The interrupt chip irq_set_affinity() functions copy the affinity mask to irq_data->affinity but return 0, i.e. IRQ_SET_MASK_OK. IRQ_SET_MASK_OK causes the core code to do another redundant copy.

Return IRQ_SET_MASK_OK_NOCOPY to avoid this.

---
 arch/x86/kernel/apic/io_apic.c |    9 +++++----
 arch/x86/platform/uv/uv_irq.c  |    2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)
arch/x86/kernel/apic/io_apic.c +5 -4
index ac96561..bce2001 100644
@@ -2270,6 +2270,7 @@ ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 		/* Only the high 8 bits are valid. */
 		dest = SET_APIC_LOGICAL_ID(dest);
 		__target_IO_APIC_irq(irq, dest, data->chip_data);
+		ret = IRQ_SET_MASK_OK_NOCOPY;
 	}
 	raw_spin_unlock_irqrestore(&ioapic_lock, flags);
 	return ret;
@@ -3092,7 +3093,7 @@ msi_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
 
 	__write_msi_msg(data->msi_desc, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 #endif /* CONFIG_SMP */
 
@@ -3214,7 +3215,7 @@ dmar_msi_set_affinity(struct irq_data *data, const struct cpumask *mask,
 
 	dmar_msi_write(irq, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #endif /* CONFIG_SMP */
@@ -3267,7 +3268,7 @@ static int hpet_msi_set_affinity(struct irq_data *data,
 
 	hpet_msi_write(data->handler_data, &msg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #endif /* CONFIG_SMP */
@@ -3340,7 +3341,7 @@ ht_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
 		return -1;
 
 	target_ht_irq(data->irq, dest, cfg->vector);
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #endif
arch/x86/platform/uv/uv_irq.c +1 -1
index f25c276..a22c416 100644
@@ -222,7 +222,7 @@ uv_set_irq_affinity(struct irq_data *data, const struct cpumask *mask,
 	if (cfg->move_in_progress)
 		send_cleanup_vector(cfg);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 /*
author
#13 lore raw

PATCH v3 4/4 IRQ,IA64: normalize return value of chip->irq_set_affinity() method

In reply to Jiang Liu

On IA64 platforms, interrupt controller chip's irq_set_affinity() method always copies affinity mask to irq_data->affinity field but still returns 0(IRQ_SET_MASK_OK). That return value causes the interrupt core logic unnecessarily copies the mask to irq_data->affinity field again. So return IRQ_SET_MASK_OK_NOCOPY instead of IRQ_SET_MASK_OK to get rid of the duplicated copy operation.

---
 arch/ia64/kernel/iosapic.c   |    4 +++-
 arch/ia64/kernel/msi_ia64.c  |    4 ++--
 arch/ia64/sn/kernel/irq.c    |    2 +-
 arch/ia64/sn/kernel/msi_sn.c |    2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)
arch/ia64/kernel/iosapic.c +3 -1
index ef4b5d8..47a4d1e 100644
@@ -373,8 +373,10 @@ iosapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
 		iosapic_write(iosapic, IOSAPIC_RTE_LOW(rte_index), low32);
 	}
 
+	return IRQ_SET_MASK_OK_NOCOPY;
+#else
+	return IRQ_SET_MASK_OK;
 #endif
-	return 0;
 }
 
 /*
arch/ia64/kernel/msi_ia64.c +2 -2
index fb2f1e6..ca66c6a 100644
@@ -41,7 +41,7 @@ static int ia64_set_msi_irq_affinity(struct irq_data *idata,
 	write_msi_msg(irq, &msg);
 	cpumask_copy(idata->affinity, cpumask_of(cpu));
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 #endif /* CONFIG_SMP */
 
@@ -157,7 +157,7 @@ static int dmar_msi_set_affinity(struct irq_data *data,
 	dmar_msi_write(irq, &msg);
 	cpumask_copy(data->affinity, mask);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 #endif /* CONFIG_SMP */
 
arch/ia64/sn/kernel/irq.c +1 -1
index 62cf4dd..aa58931 100644
@@ -216,7 +216,7 @@ static int sn_set_affinity_irq(struct irq_data *data,
 				 sn_irq_lh[irq], list)
 		(void)sn_retarget_vector(sn_irq_info, nasid, slice);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 
 #ifdef CONFIG_SMP
arch/ia64/sn/kernel/msi_sn.c +1 -1
index 2b98b9e..ebb5b55 100644
@@ -208,7 +208,7 @@ static int sn_set_msi_irq_affinity(struct irq_data *data,
 	write_msi_msg(irq, &msg);
 	cpumask_copy(data->affinity, cpu_mask);
 
-	return 0;
+	return IRQ_SET_MASK_OK_NOCOPY;
 }
 #endif /* CONFIG_SMP */
 
Signature · 1 line
1.7.5.4