xen/evtchn: enable build optimization for evtchn_move_pirqs()/send_guest_pirq()
PATCH 1/1 xen/evtchn: enable build optimization for evtchn_move_pirqs()/send_guest_pirq()
From: Grygorii Strashko <[email protected]>
Enable build time optimization for evtchn_move_pirqs()/send_guest_pirq() on platforms without PIRQ support by adding compile time check for !IS_ENABLED(CONFIG_HAS_PIRQ) at the beginning of functions.
This will shrink them to (on Arm64 with -O1):000000000000264c <send_guest_pirq>:
264c: d65f03c0 ret
0000000000004644 <evtchn_move_pirqs>:
4644: d65f03c0 ret
--- xen/common/event_channel.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
xen/common/event_channel.c +9 -1
@@ -975,6 +975,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)int port;struct evtchn *chn; +if (!IS_ENABLED (CONFIG_HAS_PIRQ )) +return ; +/* * PV guests: It should not be possible to race with __evtchn_close(). The * caller of this function must synchronise with pirq_guest_unbind().
@@ -1710,10 +1713,15 @@ void evtchn_destroy_final(struct domain *d)void evtchn_move_pirqs (struct vcpu *v) {struct domain *d = v->domain; -const cpumask_t *mask =cpumask_of (v->processor); +const cpumask_t *mask;unsigned int port;struct evtchn *chn; +if (!IS_ENABLED (CONFIG_HAS_PIRQ )) +return ; + + mask =cpumask_of (v->processor); +read_lock (&d->event_lock);for ( port = v->pirq_evtchn_head; port; port = chn->u.pirq.next_port ) {
Signature · 1 line
2.34.1
xen/common/event_channel.c void send_guest_pirq(struct domain *d, const struct pirq *pirq) · line 983
Quoted 12 lines · Grygorii Strashko
xen/common/event_channel.c +3
-0@@ -975,6 +975,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)int port;struct evtchn *chn; +if (!IS_ENABLED (CONFIG_HAS_PIRQ )) +return ; +/* * PV guests: It should not be possible to race with __evtchn_close(). The * caller of this function must synchronise with pirq_guest_unbind().
Isn't this function unreachable on Arm, and hence a Misra rule 2.1 violation, requiring #ifdef around the entire function to address?
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1716
Quoted 6 lines
xen/common/event_channel.c +1
-1@@ -1710,10 +1713,15 @@ void evtchn_destroy_final(struct domain *d)void evtchn_move_pirqs (struct vcpu *v) {struct domain *d = v->domain; -const cpumask_t *mask =cpumask_of (v->processor); +const cpumask_t *mask;
This change shouldn't be necessary; compilers ought to be able to DCE the code.
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1720
Quoted 4 lines
xen/common/event_channel.c +1
-0unsigned int port;struct evtchn *chn; +if (!IS_ENABLED (CONFIG_HAS_PIRQ ))
Nit (style): Missing blanks (see other nearby if()-s).
I wonder though whether we wouldn't better have x86'es arch_move_irqs() invoke this function, and then #ifdef it out here altogether as well.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Grygorii Strashko
xen/common/event_channel.c +0
-0@@ -975,6 +975,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)int port;struct evtchn *chn;
Quoted 9 lines
xen/common/event_channel.c void send_guest_pirq(struct domain *d, const struct pirq *pirq) · line 983
Quoted 6 lines
xen/common/event_channel.c +3
-0+if (!IS_ENABLED (CONFIG_HAS_PIRQ )) +return ; +/* * PV guests: It should not be possible to race with __evtchn_close(). The * caller of this function must synchronise with pirq_guest_unbind(). Isn't this function unreachable on Arm, and hence a Misra rule 2.1 violation, requiring #ifdef around the entire function to address?
Yes. It's unused on Arm, only x86 is an user.
I can put it under ifdef.
Quoted 10 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1716
Quoted 7 lines
xen/common/event_channel.c +1
-1@@ -1710,10 +1713,15 @@ void evtchn_destroy_final(struct domain *d)void evtchn_move_pirqs (struct vcpu *v) {struct domain *d = v->domain; -const cpumask_t *mask =cpumask_of (v->processor); +const cpumask_t *mask;This change shouldn't be necessary; compilers ought to be able to DCE the code.
Unfortunately not, with "-O1" more code is generated as cpumask_of() is complicated inside.
Quoted 10 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1720
Quoted 5 lines
xen/common/event_channel.c +1
-0unsigned int port;struct evtchn *chn; +if (!IS_ENABLED (CONFIG_HAS_PIRQ ))Nit (style): Missing blanks (see other nearby if()-s).
I wonder though whether we wouldn't better have x86'es
arch_move_irqs()invoke this function, and then #ifdef it out here altogether as well.
Do you mean as in the below diff?
xen/arch/x86/include/asm/irq.h +1 -1
@@ -224,7 +224,7 @@ void cleanup_domain_irq_mapping(struct domain *d);bool cpu_has_pending_apic_eoi (void ); -static inline void arch_move_irqs (struct vcpu *v) { } +void arch_move_irqs (struct vcpu *v);struct msi_info ;int allocate_and_map_gsi_pirq (struct domain *d,int index,int *pirq_p);
xen/arch/x86/irq.c +4 -0
@@ -1851,6 +1851,10 @@ void pirq_guest_unbind(struct domain *d, struct pirq *pirq)cleanup_domain_irq_pirq (d, irq, pirq); } +void arch_move_irqs (struct vcpu *v) { +evtchn_move_pirqs (v); +} +static bool pirq_guest_force_unbind (struct domain *d,struct pirq *pirq) {struct irq_desc *desc;
xen/common/sched/core.c +0 -1
@@ -642,7 +642,6 @@ int sched_init_vcpu(struct vcpu *v)static void vcpu_move_irqs (struct vcpu *v) {arch_move_irqs (v); -evtchn_move_pirqs (v); }
Signature · 2 lines
Best regards, -grygorii
Quoted 40 lines · Grygorii Strashko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Grygorii Strashko
xen/common/event_channel.c +0
-0@@ -975,6 +975,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)int port;struct evtchn *chn;Quoted 9 lines
xen/common/event_channel.c void send_guest_pirq(struct domain *d, const struct pirq *pirq) · line 983
Quoted 6 lines
xen/common/event_channel.c +3
-0+if (!IS_ENABLED (CONFIG_HAS_PIRQ )) +return ; +/* * PV guests: It should not be possible to race with __evtchn_close(). The * caller of this function must synchronise with pirq_guest_unbind(). Isn't this function unreachable on Arm, and hence a Misra rule 2.1 violation, requiring #ifdef around the entire function to address?
Yes. It's unused on Arm, only x86 is an user.
I can put it under ifdef.Quoted 10 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1716
Quoted 7 lines
xen/common/event_channel.c +1
-1@@ -1710,10 +1713,15 @@ void evtchn_destroy_final(struct domain *d)void evtchn_move_pirqs (struct vcpu *v) {struct domain *d = v->domain; -const cpumask_t *mask =cpumask_of (v->processor); +const cpumask_t *mask;This change shouldn't be necessary; compilers ought to be able to DCE the code.
Unfortunately not, with "-O1" more code is generated as
cpumask_of()is complicated inside.Quoted 4 lines
Quoted 4 lines
xen/common/event_channel.c +0
-0unsigned int port;struct evtchn *chn;
Quoted 8 lines
Quoted 6 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1720
Quoted 1 line
xen/common/event_channel.c +1
-0+if (!IS_ENABLED (CONFIG_HAS_PIRQ ))Nit (style): Missing blanks (see other nearby if()-s).
I wonder though whether we wouldn't better have x86'es
arch_move_irqs()invoke this function, and then #ifdef it out here altogether as well.Do you mean as in the below diff?
Along these lines, yes. I guess personally I wouldn't convert to an out-of-line function. If an inline function fails to compile (and that isn't easily fixable), use a macro instead.
Jan
Quoted 38 lines
xen/arch/x86/include/asm/irq.h +1
-1@@ -224,7 +224,7 @@ void cleanup_domain_irq_mapping(struct domain *d);bool cpu_has_pending_apic_eoi (void ); -static inline void arch_move_irqs (struct vcpu *v) { } +void arch_move_irqs (struct vcpu *v);struct msi_info ;int allocate_and_map_gsi_pirq (struct domain *d,int index,int *pirq_p);xen/arch/x86/irq.c +4
-0@@ -1851,6 +1851,10 @@ void pirq_guest_unbind(struct domain *d, struct pirq *pirq)cleanup_domain_irq_pirq (d, irq, pirq); } +void arch_move_irqs (struct vcpu *v) { +evtchn_move_pirqs (v); +} +static bool pirq_guest_force_unbind (struct domain *d,struct pirq *pirq) {struct irq_desc *desc;xen/common/sched/core.c +0
-1@@ -642,7 +642,6 @@ int sched_init_vcpu(struct vcpu *v)static void vcpu_move_irqs (struct vcpu *v) {arch_move_irqs (v); -evtchn_move_pirqs (v); }
Quoted 45 lines · Jan Beulich
Quoted 44 lines · Grygorii Strashko
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Grygorii Strashko
xen/common/event_channel.c +0
-0@@ -975,6 +975,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq)int port;struct evtchn *chn;Quoted 9 lines
xen/common/event_channel.c void send_guest_pirq(struct domain *d, const struct pirq *pirq) · line 983
Quoted 6 lines
xen/common/event_channel.c +3
-0+if (!IS_ENABLED (CONFIG_HAS_PIRQ )) +return ; +/* * PV guests: It should not be possible to race with __evtchn_close(). The * caller of this function must synchronise with pirq_guest_unbind(). Isn't this function unreachable on Arm, and hence a Misra rule 2.1 violation, requiring #ifdef around the entire function to address?
Yes. It's unused on Arm, only x86 is an user.
I can put it under ifdef.Quoted 10 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1716
Quoted 7 lines
xen/common/event_channel.c +1
-1@@ -1710,10 +1713,15 @@ void evtchn_destroy_final(struct domain *d)void evtchn_move_pirqs (struct vcpu *v) {struct domain *d = v->domain; -const cpumask_t *mask =cpumask_of (v->processor); +const cpumask_t *mask;This change shouldn't be necessary; compilers ought to be able to DCE the code.
Unfortunately not, with "-O1" more code is generated as
cpumask_of()is complicated inside.Quoted 8 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1720
Quoted 5 lines
xen/common/event_channel.c +1
-0unsigned int port;struct evtchn *chn; +if (!IS_ENABLED (CONFIG_HAS_PIRQ ))Nit (style): Missing blanks (see other nearby if()-s).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I wonder though whether we wouldn't better have x86'es
arch_move_irqs()invoke this function, and then #ifdef it out here altogether as well.Do you mean as in the below diff?
Along these lines, yes. I guess personally I wouldn't convert to an out-of-line function. If an inline function fails to compile (and that isn't easily fixable), use a macro instead.
I'd prefer stick to out-of-line function, if you don't mind. Inline implementation causes cascade build failure:
adding
#include <xen/event.h>
#include <xen/sched.h>
in irq.h is not enough.
Quoted 40 lines
Quoted 39 lines
xen/arch/x86/include/asm/irq.h +1
-1@@ -224,7 +224,7 @@ void cleanup_domain_irq_mapping(struct domain *d);bool cpu_has_pending_apic_eoi (void ); -static inline void arch_move_irqs (struct vcpu *v) { } +void arch_move_irqs (struct vcpu *v);struct msi_info ;int allocate_and_map_gsi_pirq (struct domain *d,int index,int *pirq_p);xen/arch/x86/irq.c +4
-0@@ -1851,6 +1851,10 @@ void pirq_guest_unbind(struct domain *d, struct pirq *pirq)cleanup_domain_irq_pirq (d, irq, pirq); } +void arch_move_irqs (struct vcpu *v) { +evtchn_move_pirqs (v); +} +static bool pirq_guest_force_unbind (struct domain *d,struct pirq *pirq) {struct irq_desc *desc;xen/common/sched/core.c +0
-1@@ -642,7 +642,6 @@ int sched_init_vcpu(struct vcpu *v)static void vcpu_move_irqs (struct vcpu *v) {arch_move_irqs (v); -evtchn_move_pirqs (v); }
Signature · 2 lines
Best regards, -grygorii
Quoted 51 lines · Grygorii Strashko
Quoted 41 lines · Jan Beulich
Quoted 40 lines · Grygorii Strashko
Quoted 15 lines · Jan Beulich
xen/common/event_channel.c void send_guest_pirq(struct domain *d, const struct pirq *pirq) · line 982
Quoted 11 lines · Grygorii Strashko
xen/common/event_channel.c +2
-0@@ -975,6 +975,9 @@ void send_guest_pirq(struct domain *d, const struct pirq *pirq) int port; struct evtchn *chn; + if (!IS_ENABLED(CONFIG_HAS_PIRQ)) + return; + /** PV guests: It should not be possible to race with __evtchn_close(). The * caller of this function must synchronise with pirq_guest_unbind(). Isn't this function unreachable on Arm, and hence a Misra rule 2.1 violation, requiring #ifdef around the entire function to address?
Yes. It's unused on Arm, only x86 is an user.
I can put it under ifdef.Quoted 10 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1716
Quoted 7 lines
xen/common/event_channel.c +1
-1@@ -1710,10 +1713,15 @@ void evtchn_destroy_final(struct domain *d) void evtchn_move_pirqs(struct vcpu *v) { struct domain *d = v->domain; - const cpumask_t *mask = cpumask_of(v->processor); + const cpumask_t *mask;This change shouldn't be necessary; compilers ought to be able to DCE the code.
Unfortunately not, with "-O1" more code is generated as
cpumask_of()is complicated inside.Quoted 7 lines
xen/common/event_channel.c void evtchn_destroy_final(struct domain *d) · line 1719
Quoted 4 lines
xen/common/event_channel.c +0
-0unsigned int port; struct evtchn *chn; + if (!IS_ENABLED(CONFIG_HAS_PIRQ))Nit (style): Missing blanks (see other nearby if()-s).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I wonder though whether we wouldn't better have x86'es
arch_move_irqs()invoke this function, and then #ifdef it out here altogether as well.Do you mean as in the below diff?
Along these lines, yes. I guess personally I wouldn't convert to an out-of-line function. If an inline function fails to compile (and that isn't easily fixable), use a macro instead.
Quoted 7 lines
I'd prefer stick to out-of-line function, if you don't mind. Inline implementation causes cascade build failure:
adding
#include <xen/event.h>
#include <xen/sched.h>
inirq.his not enough.
Which is why I suggested using a macro; I kind of expected there to be #include issues.
Jan