[tip:x86/irq] x86/irq: Optimize free vector check in the CPU offline path

From: tip-bot for Chen Yu
Date: Thu Apr 20 2017 - 09:32:27 EST


Commit-ID: c0edbd4a1693600d6eb9e2faad452638c35391f7
Gitweb: http://git.kernel.org/tip/c0edbd4a1693600d6eb9e2faad452638c35391f7
Author: Chen Yu <yu.c.chen@xxxxxxxxx>
AuthorDate: Sun, 16 Apr 2017 23:43:30 +0800
Committer: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CommitDate: Thu, 20 Apr 2017 15:25:09 +0200

x86/irq: Optimize free vector check in the CPU offline path

Before offlining a CPU its required to check whether there are enough free
irq vectors available so interrupts can be migrated away from the CPU.

This check is executed whether its required or not and neither stops
searching when the number of required free vectors are reached.

Bypass the free vector check if the current CPU has no irq to migrate and
leave the for_each_online_cpu() loop when the free vector count reaches the
number of required vectors.

Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Chen Yu <yu.c.chen@xxxxxxxxx>
Cc: Prarit Bhargava <prarit@xxxxxxxxxx>
Cc: Len Brown <lenb@xxxxxxxxxx>
Cc: "Rafael J. Wysocki" <rjw@xxxxxxxxxxxxx>
Link: http://lkml.kernel.org/r/1492357410-510-1-git-send-email-yu.c.chen@xxxxxxxxx
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>

---
arch/x86/kernel/irq.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
index 4d8183b..f34fe74 100644
--- a/arch/x86/kernel/irq.c
+++ b/arch/x86/kernel/irq.c
@@ -394,6 +394,9 @@ int check_irq_vectors_for_cpu_disable(void)
!cpumask_subset(&affinity_new, &online_new))
this_count++;
}
+ /* No need to check any further. */
+ if (!this_count)
+ return 0;

count = 0;
for_each_online_cpu(cpu) {
@@ -411,8 +414,10 @@ int check_irq_vectors_for_cpu_disable(void)
for (vector = FIRST_EXTERNAL_VECTOR;
vector < first_system_vector; vector++) {
if (!test_bit(vector, used_vectors) &&
- IS_ERR_OR_NULL(per_cpu(vector_irq, cpu)[vector]))
- count++;
+ IS_ERR_OR_NULL(per_cpu(vector_irq, cpu)[vector])) {
+ if (++count == this_count)
+ return 0;
+ }
}
}