Skip to contentSkip to conversation

xen/arm: minor improvement in smp_send_call_function_mask()

PATCH Superseded Anup Patel 3 participants 7 messages Aug 19, 2014 – Aug 21, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 xen/arm: minor improvement in smp_send_call_function_mask()

Currently, smp_send_call_function_mask() function implemented by xen arm/arm64 will use IPI to call function on current CPU.

This means that current smp_send_call_function_mask() will do the following on current CPU:
Trigger SGI for current CPU => Xen takes interrupt on current CPU => IPI interrupt handler will call smp_call_function_interrupt()

This patch improves the above by straight away calling smp_call_function_interrupt() for current CPU. This is very similar to smp_send_call_function_mask() implemented by Xen x86.

---
 xen/arch/arm/smp.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
xen/arch/arm/smp.c +13 -1
index 30203b8..c80c068 100644
@@ -19,7 +19,19 @@ void smp_send_event_check_mask(const cpumask_t *mask)
 
 void smp_send_call_function_mask(const cpumask_t *mask)
 {
-    send_SGI_mask(mask, GIC_SGI_CALL_FUNCTION);
+    cpumask_t target_mask;
+
+    cpumask_andnot(&target_mask, mask, cpumask_of(smp_processor_id()));
+
+    if ( cpumask_weight(&target_mask) )
+        send_SGI_mask(&target_mask, GIC_SGI_CALL_FUNCTION);
+
+    if ( cpumask_test_cpu(smp_processor_id(), mask) )
+    {
+        local_irq_disable();
+        smp_call_function_interrupt();
+        local_irq_enable();
+    }
 }
 
 /*
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Anup,

Quoted 8 lines · Anup Patel
  xen/arch/arm/smp.c |   14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
xen/arch/arm/smp.c +0 -0
index 30203b8..c80c068 100644

xen/arch/arm/smp.c void smp_send_event_check_mask(const cpumask_t *mask) · line 26

Quoted 9 lines
xen/arch/arm/smp.c +5 -1
@@ -19,7 +19,19 @@ void smp_send_event_check_mask(const cpumask_t *mask)
 
  void smp_send_call_function_mask(const cpumask_t *mask)
  {
-    send_SGI_mask(mask, GIC_SGI_CALL_FUNCTION);
+    cpumask_t target_mask;
+
+    cpumask_andnot(&target_mask, mask, cpumask_of(smp_processor_id()));
+
+    if ( cpumask_weight(&target_mask) )

Is it necessary? What happen if Xen tries to send an SGI with an empty mask?

AFAIU, the function cpumask_weight is complex so if we can avoid it, it would be better.

Signature · 1 line
Julien Grall
author
#2 lore raw
Quoted 14 lines · Julien Grall

Hi Anup,

Quoted 10 lines · Anup Patel
  xen/arch/arm/smp.c |   14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
xen/arch/arm/smp.c +0 -0
index 30203b8..c80c068 100644
@@ -19,7 +19,19 @@ void smp_send_event_check_mask(const cpumask_t *mask)
 
Quoted 11 lines

xen/arch/arm/smp.c void smp_send_event_check_mask(const cpumask_t *mask) · line 26

Quoted 8 lines
xen/arch/arm/smp.c +5 -1
  void smp_send_call_function_mask(const cpumask_t *mask)
  {
-    send_SGI_mask(mask, GIC_SGI_CALL_FUNCTION);
+    cpumask_t target_mask;
+
+    cpumask_andnot(&target_mask, mask, cpumask_of(smp_processor_id()));
+
+    if ( cpumask_weight(&target_mask) )

Is it necessary? What happen if Xen tries to send an SGI with an empty mask?

If Xen tries to send SGI with empty mask then target_mask will be empty hence cpumask_weight(&target_mask) will return 0

Quoted 3 lines

AFAIU, the function cpumask_weight is complex so if we can avoid it, it would be better.

Can you explain more about how cpumask_weight is complex ??

Other alternative is to use "cpumask_first(&target_mask) != NR_CPUS".

Quoted 3 lines

--
Julien Grall

--
Anup

#3 lore raw
Quoted 4 lines · Anup Patel
Quoted 1 line

Is it necessary? What happen if Xen tries to send an SGI with an empty mask?

If Xen tries to send SGI with empty mask then target_mask will be empty hence cpumask_weight(&target_mask) will return 0

The GIC documentation says:
"If this field is 0x00 when TargetListFilter is 0b00 , the Distributor does not forward the interrupt to any CPU interface."

TargetListFilter == 0b00 => Forward interrupt to a specific list of CPUs.

Quoted 5 lines
Quoted 3 lines

AFAIU, the function cpumask_weight is complex so if we can avoid it, it would be better.

Can you explain more about how cpumask_weight is complex ??

cpumask_weight contains a loop and multiple addition. I doubt the case where the mask only contains the current cpu happens often.

As the GIC won't forward the interrupt if the list of CPUs is empty, I don't think it's worth to add this check.

Quoted 1 line

Other alternative is to use "cpumask_first(&target_mask) != NR_CPUS".

The best alternative would be cpumask_empty.

Regards,

Signature · 1 line
Julien Grall
author
#4 lore raw
Quoted 31 lines · Julien Grall
Quoted 7 lines · Anup Patel
Quoted 3 lines

Is it necessary? What happen if Xen tries to send an SGI with an empty mask?

If Xen tries to send SGI with empty mask then target_mask will be empty hence cpumask_weight(&target_mask) will return 0

The GIC documentation says:
"If this field is 0x00 when TargetListFilter is 0b00 , the Distributor does not forward the interrupt to any
CPU interface."

TargetListFilter == 0b00 => Forward interrupt to a specific list of CPUs.

Quoted 6 lines
Quoted 3 lines

AFAIU, the function cpumask_weight is complex so if we can avoid it, it would be better.

Can you explain more about how cpumask_weight is complex ??

cpumask_weight contains a loop and multiple addition. I doubt the case where the mask only contains the current cpu happens often.

Quoted 8 lines

As the GIC won't forward the interrupt if the list of CPUs is empty, I don't think it's worth to add this check.

Quoted 1 line

Other alternative is to use "cpumask_first(&target_mask) != NR_CPUS".

The best alternative would be cpumask_empty.

All three cpumask_empty(), cpumask_first(), and cpumask_weight() are O(N) where N is number of bits in cpumask.

It really does not make much difference which of these operation is chosen.

Since empty target list is fine with GIC Distributor, I will drop the check.

--
Anup

Quoted 5 lines

Regards,

--
Julien Grall

Acked-by
#5 lore raw

Hi Anup,

Quoted 6 lines · Anup Patel
Quoted 1 line

The best alternative would be cpumask_empty.

All three cpumask_empty(), cpumask_first(), and cpumask_weight() are O(N) where N is number of bits in cpumask.
It really does not make much difference which of these operation is chosen.

Hmmm right. That the worst case for all, and always the case for cpumask_weight. Anyway...

Quoted 1 line

Since empty target list is fine with GIC Distributor, I will drop the check.

Assuming you only remove the check in the next version:

Regards,

Signature · 1 line
Julien Grall
#6 lore raw
Quoted 9 lines · Julien Grall

Hi Anup,

Quoted 6 lines · Anup Patel
Quoted 1 line

The best alternative would be cpumask_empty.

All three cpumask_empty(), cpumask_first(), and cpumask_weight() are O(N) where N is number of bits in cpumask.
It really does not make much difference which of these operation is chosen.

They are all O(N), but O() notation hides lesser factors.

cpumask_empty() is slightly cheaper than cpumask_first(), which are both substantially cheaper than cpumask_weight().

There is no fastpath for calculating the hamming weight of 0, resulting in a lot of dependent shift/mask operations.

~Andrew