x86/irq: Do not check available vectors if current CPU has no irq to migrate
PATCH 1/1 x86/irq: Do not check available vectors if current CPU has no irq to migrate
This is an optimization to bypass the free vector checking if the current CPU has no irq to migrate. This can especially speed up the CPU offline process when there are many CPUs in the system.
--- arch/x86/kernel/irq.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/irq.c +3 -0
@@ -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) {
Signature · 1 line
2.7.4
Quoted 3 lines · Chen Yu
This is an optimization to bypass the free vector checking if the current CPU has no irq to migrate. This can especially speed up the CPU offline process when there are many CPUs in the system.
Chen, OOC how much time does this save?
P.
Quoted 29 lines
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Prarit Bhargava <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Signed-off-by Chen Yu <[email protected]>--- arch/x86/kernel/irq.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/irq.c +3
-0@@ -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) {
Hi Prarit,
Quoted 9 lines · Prarit Bhargava
Quoted 3 lines · Chen Yu
This is an optimization to bypass the free vector checking if the current CPU has no irq to migrate. This can especially speed up the CPU offline process when there are many CPUs in the system.
Chen, OOC how much time does this save?
Previously I was doing some debugging on irq related issue when check_irq_vectors_for_cpu_disable() printed a warning on that platform, thus I incidentally look at this code and did not measure it : )
I've just done a comparison of the function duration of check_irq_vectors_for_cpu_disable() with/without the patch (32 online CPUs)
before patch:
[001] d..1 264.017803: check_irq_vectors_for_cpu_disable <-native_cpu_disable
[001] d..1 264.017886: clear_local_APIC <-native_cpu_disable
after patch:
[001] d..1 862.011847: check_irq_vectors_for_cpu_disable <-native_cpu_disable
[001] d..1 862.011850: clear_local_APIC <-native_cpu_disable
About (83 - 17) = 66 microsecond.
thanks,
Yu
Quoted 31 lines
P.
Quoted 29 lines
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc "H. Peter Anvin" <[email protected]>Cc Prarit Bhargava <[email protected]>Cc "Rafael J. Wysocki" <[email protected]>Cc Len Brown <[email protected]>Signed-off-by Chen Yu <[email protected]>--- arch/x86/kernel/irq.c | 3 +++ 1 file changed, 3 insertions(+)arch/x86/kernel/irq.c +3
-0@@ -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) {
Quoted 10 lines · Chen Yu
I've just done a comparison of the function duration of
check_irq_vectors_for_cpu_disable()with/without the patch (32 online CPUs)
before patch:
[001] d..1 264.017803:check_irq_vectors_for_cpu_disable<-native_cpu_disable
[001] d..1 264.017886:clear_local_APIC<-native_cpu_disable
after patch:
[001] d..1 862.011847:check_irq_vectors_for_cpu_disable<-native_cpu_disable
[001] d..1 862.011850:clear_local_APIC<-native_cpu_disable
About (83 - 17) = 66 microsecond.
Not really impressive if you subtract the tracer overhead. Though, if you want to micro optimize that, then you should do it proper and also break the for_each_cpu_loop() when the count reaches the required vectors.
Thanks,
tglx
arch/x86/kernel/irq.c +4 -2
@@ -411,8 +411,10 @@ int check_irq_vectors_for_cpu_disable(vofor (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 ; + } } }