evtchn: simplify sending of notifications
PATCH 1/1 evtchn: simplify sending of notifications
The trivial wrapper evtchn_set_pending() is pretty pointless, as it only serves to invoke another wrapper evtchn_port_set_pending(). In turn, the latter is kind of inconsistent with its siblings in that is takes a struct vcpu * rather than a struct domain * - adjusting this allows for more efficient code in the majority of cases.
xen/common/event_channel.c +13 -22
@@ -95,8 +95,6 @@ static uint8_t get_xen_consumer(xen_even/* Get the notification function for a given Xen-bound event channel. */ #define xen_notification_fn (e) (xen_consumers[(e)->xen_consumer-1]) -static void evtchn_set_pending (struct vcpu *v,int port); -static int virq_is_global (uint32_t virq) {int rc;
@@ -287,7 +285,7 @@ static long evtchn_bind_interdomain(evtc* We may have lost notifications on the remote unbound port. Fix that up * here by conservatively always setting a notification on the local port. */ -evtchn_set_pending (ld->vcpu[lchn->notify_vcpu_id], lport); +evtchn_port_set_pending (ld, lchn->notify_vcpu_id, lchn); bind->local_port = lport;
@@ -599,11 +597,10 @@ static long evtchn_close(evtchn_close_treturn __evtchn_close (current->domain, close->port); } -int evtchn_send (struct domain *d,unsigned int lport) +int evtchn_send (struct domain *ld,unsigned int lport) {struct evtchn *lchn, *rchn; -struct domain *ld = d, *rd; -struct vcpu *rvcpu; +struct domain *rd;int rport, ret =0 ;spin_lock (&ld->event_lock);
@@ -633,14 +630,13 @@ int evtchn_send(struct domain *d, unsign rd = lchn->u.interdomain.remote_dom; rport = lchn->u.interdomain.remote_port; rchn =evtchn_from_port (rd, rport); - rvcpu = rd->vcpu[rchn->notify_vcpu_id];if (consumer_is_xen (rchn) ) - (*xen_notification_fn (rchn))(rvcpu, rport); +xen_notification_fn (rchn)(rd->vcpu[rchn->notify_vcpu_id], rport);else -evtchn_set_pending (rvcpu, rport); +evtchn_port_set_pending (rd, rchn->notify_vcpu_id, rchn);break ;case ECS_IPI : -evtchn_set_pending (ld->vcpu[lchn->notify_vcpu_id], lport); +evtchn_port_set_pending (ld, lchn->notify_vcpu_id, lchn);break ;case ECS_UNBOUND :/* silently drop the notification */
@@ -655,11 +651,6 @@ out:return ret; } -static void evtchn_set_pending (struct vcpu *v,int port) -{ -evtchn_port_set_pending (v,evtchn_from_port (v->domain, port)); -} -int guest_enabled_event (struct vcpu *v,uint32_t virq) {return ((v !=NULL ) && (v->virq_to_evtchn[virq] !=0 ));
@@ -669,6 +660,7 @@ void send_guest_vcpu_virq(struct vcpu *v {unsigned long flags;int port; +struct domain *d;ASSERT (!virq_is_global (virq));
@@ -678,7 +670,8 @@ void send_guest_vcpu_virq(struct vcpu *vif (unlikely (port ==0 ) ) goto out; -evtchn_set_pending (v, port); + d = v->domain; +evtchn_port_set_pending (d, v->vcpu_id,evtchn_from_port (d, port)); out:spin_unlock_irqrestore (&v->virq_lock, flags);
@@ -707,7 +700,7 @@ static void send_guest_global_virq(struc goto out; chn =evtchn_from_port (d, port); -evtchn_set_pending (d->vcpu[chn->notify_vcpu_id], port); +evtchn_port_set_pending (d, chn->notify_vcpu_id, chn); out:spin_unlock_irqrestore (&v->virq_lock, flags);
@@ -731,7 +724,7 @@ void send_guest_pirq(struct domain *d, c } chn =evtchn_from_port (d, port); -evtchn_set_pending (d->vcpu[chn->notify_vcpu_id], port); +evtchn_port_set_pending (d, chn->notify_vcpu_id, chn); }static struct domain *global_virq_handlers[NR_VIRQS ]__read_mostly ;
@@ -1202,7 +1195,6 @@ void notify_via_xen_event_channel(struct {struct evtchn *lchn, *rchn;struct domain *rd; -int rport;spin_lock (&ld->event_lock);
@@ -1219,9 +1211,8 @@ void notify_via_xen_event_channel(structif (likely (lchn->state ==ECS_INTERDOMAIN ) ) { rd = lchn->u.interdomain.remote_dom; - rport = lchn->u.interdomain.remote_port; - rchn =evtchn_from_port (rd, rport); -evtchn_set_pending (rd->vcpu[rchn->notify_vcpu_id], rport); + rchn =evtchn_from_port (rd, lchn->u.interdomain.remote_port); +evtchn_port_set_pending (rd, rchn->notify_vcpu_id, rchn); }spin_unlock (&ld->event_lock);
xen/include/xen/event.h +3 -2
@@ -152,10 +152,11 @@ static inline void evtchn_port_init(stru d->evtchn_port_ops->init (d, evtchn); } -static inline void evtchn_port_set_pending (struct vcpu *v, +static inline void evtchn_port_set_pending (struct domain *d, +unsigned int vcpu_id,struct evtchn *evtchn) { - v->domain->evtchn_port_ops->set_pending (v, evtchn); + d->evtchn_port_ops->set_pending (d->vcpu[vcpu_id], evtchn); } static inline void evtchn_port_clear_pending(struct domain *d,
evtchn: simplify sending of notifications
The trivial wrapper evtchn_set_pending() is pretty pointless, as it only serves to invoke another wrapper evtchn_port_set_pending(). In turn, the latter is kind of inconsistent with its siblings in that is takes a struct vcpu * rather than a struct domain * - adjusting this allows for more efficient code in the majority of cases.
xen/common/event_channel.c +13 -22
@@ -95,8 +95,6 @@ static uint8_t get_xen_consumer(xen_even/* Get the notification function for a given Xen-bound event channel. */ #define xen_notification_fn (e) (xen_consumers[(e)->xen_consumer-1]) -static void evtchn_set_pending (struct vcpu *v,int port); -static int virq_is_global (uint32_t virq) {int rc;
@@ -287,7 +285,7 @@ static long evtchn_bind_interdomain(evtc* We may have lost notifications on the remote unbound port. Fix that up * here by conservatively always setting a notification on the local port. */ -evtchn_set_pending (ld->vcpu[lchn->notify_vcpu_id], lport); +evtchn_port_set_pending (ld, lchn->notify_vcpu_id, lchn); bind->local_port = lport;
@@ -599,11 +597,10 @@ static long evtchn_close(evtchn_close_treturn __evtchn_close (current->domain, close->port); } -int evtchn_send (struct domain *d,unsigned int lport) +int evtchn_send (struct domain *ld,unsigned int lport) {struct evtchn *lchn, *rchn; -struct domain *ld = d, *rd; -struct vcpu *rvcpu; +struct domain *rd;int rport, ret =0 ;spin_lock (&ld->event_lock);
@@ -633,14 +630,13 @@ int evtchn_send(struct domain *d, unsign rd = lchn->u.interdomain.remote_dom; rport = lchn->u.interdomain.remote_port; rchn =evtchn_from_port (rd, rport); - rvcpu = rd->vcpu[rchn->notify_vcpu_id];if (consumer_is_xen (rchn) ) - (*xen_notification_fn (rchn))(rvcpu, rport); +xen_notification_fn (rchn)(rd->vcpu[rchn->notify_vcpu_id], rport);else -evtchn_set_pending (rvcpu, rport); +evtchn_port_set_pending (rd, rchn->notify_vcpu_id, rchn);break ;case ECS_IPI : -evtchn_set_pending (ld->vcpu[lchn->notify_vcpu_id], lport); +evtchn_port_set_pending (ld, lchn->notify_vcpu_id, lchn);break ;case ECS_UNBOUND :/* silently drop the notification */
@@ -655,11 +651,6 @@ out:return ret; } -static void evtchn_set_pending (struct vcpu *v,int port) -{ -evtchn_port_set_pending (v,evtchn_from_port (v->domain, port)); -} -int guest_enabled_event (struct vcpu *v,uint32_t virq) {return ((v !=NULL ) && (v->virq_to_evtchn[virq] !=0 ));
@@ -669,6 +660,7 @@ void send_guest_vcpu_virq(struct vcpu *v {unsigned long flags;int port; +struct domain *d;ASSERT (!virq_is_global (virq));
@@ -678,7 +670,8 @@ void send_guest_vcpu_virq(struct vcpu *vif (unlikely (port ==0 ) ) goto out; -evtchn_set_pending (v, port); + d = v->domain; +evtchn_port_set_pending (d, v->vcpu_id,evtchn_from_port (d, port)); out:spin_unlock_irqrestore (&v->virq_lock, flags);
@@ -707,7 +700,7 @@ static void send_guest_global_virq(struc goto out; chn =evtchn_from_port (d, port); -evtchn_set_pending (d->vcpu[chn->notify_vcpu_id], port); +evtchn_port_set_pending (d, chn->notify_vcpu_id, chn); out:spin_unlock_irqrestore (&v->virq_lock, flags);
@@ -731,7 +724,7 @@ void send_guest_pirq(struct domain *d, c } chn =evtchn_from_port (d, port); -evtchn_set_pending (d->vcpu[chn->notify_vcpu_id], port); +evtchn_port_set_pending (d, chn->notify_vcpu_id, chn); }static struct domain *global_virq_handlers[NR_VIRQS ]__read_mostly ;
@@ -1202,7 +1195,6 @@ void notify_via_xen_event_channel(struct {struct evtchn *lchn, *rchn;struct domain *rd; -int rport;spin_lock (&ld->event_lock);
@@ -1219,9 +1211,8 @@ void notify_via_xen_event_channel(structif (likely (lchn->state ==ECS_INTERDOMAIN ) ) { rd = lchn->u.interdomain.remote_dom; - rport = lchn->u.interdomain.remote_port; - rchn =evtchn_from_port (rd, rport); -evtchn_set_pending (rd->vcpu[rchn->notify_vcpu_id], rport); + rchn =evtchn_from_port (rd, lchn->u.interdomain.remote_port); +evtchn_port_set_pending (rd, rchn->notify_vcpu_id, rchn); }spin_unlock (&ld->event_lock);
xen/include/xen/event.h +3 -2
@@ -152,10 +152,11 @@ static inline void evtchn_port_init(stru d->evtchn_port_ops->init (d, evtchn); } -static inline void evtchn_port_set_pending (struct vcpu *v, +static inline void evtchn_port_set_pending (struct domain *d, +unsigned int vcpu_id,struct evtchn *evtchn) { - v->domain->evtchn_port_ops->set_pending (v, evtchn); + d->evtchn_port_ops->set_pending (d->vcpu[vcpu_id], evtchn); } static inline void evtchn_port_clear_pending(struct domain *d,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 5 lines · Jan Beulich
The trivial wrapper
evtchn_set_pending()is pretty pointless, as it only serves to invoke another wrapperevtchn_port_set_pending(). In turn, the latter is kind of inconsistent with its siblings in that is takes a struct vcpu * rather than a struct domain * - adjusting this allows for more efficient code in the majority of cases.
David
xen/include/xen/event.h static inline void evtchn_port_init(stru · line 157
Quoted 10 lines · Jan Beulich
xen/include/xen/event.h +2
-1@@ -152,10 +152,11 @@ static inline void evtchn_port_init(stru d->evtchn_port_ops->init (d, evtchn); } -static inline void evtchn_port_set_pending (struct vcpu *v, +static inline void evtchn_port_set_pending (struct domain *d, +unsigned int vcpu_id,struct evtchn *evtchn)
I would rename this to the, now vacant, evtchn_set_pending(). It takes an evtchn* not a port. (Its sole caller was evtchn_set_pending(), so the patch won't grow)
Furthermore, all callers except send_guest_vcpu_virq() currently use evtchn->notify_vcpu_id to get a struct vcpu* to pass. I think you can drop the vcpu_id parameter and use evtchn->notify_vcpu_id directly, which reduces the likelyhood of a bug where the evtchn is bound to one vcpu but a caller gets the wrong id and raises the event channel on the wrong vcpu.
~Andrew
Quoted 10 lines
xen/include/xen/event.h +1
-1{ - v->domain->evtchn_port_ops->set_pending (v, evtchn); + d->evtchn_port_ops->set_pending (d->vcpu[vcpu_id], evtchn); } static inline void evtchn_port_clear_pending(struct domain *d,
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.01.15 at 12:33, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/include/xen/event.h +0
-0@@ -152,10 +152,11 @@ static inline void evtchn_port_init(stru d->evtchn_port_ops->init (d, evtchn); }
Quoted 8 lines
xen/include/xen/event.h static inline void evtchn_port_init(stru · line 157
Quoted 4 lines
xen/include/xen/event.h +2
-1-static inline void evtchn_port_set_pending (struct vcpu *v, +static inline void evtchn_port_set_pending (struct domain *d, +unsigned int vcpu_id,struct evtchn *evtchn)I would rename this to the, now vacant,
evtchn_set_pending(). It takes an evtchn* not a port. (Its sole caller wasevtchn_set_pending(), so the patch won't grow)
No (and I had actually considered it) - that would get its name out of sync with all its sibling wrappers.
Quoted 6 lines
Furthermore, all callers except
send_guest_vcpu_virq()currently useevtchn->notify_vcpu_idto get a struct vcpu* to pass. I think you can drop thevcpu_idparameter and useevtchn->notify_vcpu_iddirectly, which reduces the likelyhood of a bug where the evtchn is bound to one vcpu but a caller gets the wrong id and raises the event channel on the wrong vcpu.
Generally a nice idea, but it doesn't immediately/obviously fit with the use in send_guest_vcpu_virq().
Jan
Quoted 15 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.01.15 at 12:33, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/include/xen/event.h +0
-0@@ -152,10 +152,11 @@ static inline void evtchn_port_init(stru d->evtchn_port_ops->init (d, evtchn); }Quoted 7 lines
xen/include/xen/event.h static inline void evtchn_port_init(stru · line 157
Quoted 4 lines
xen/include/xen/event.h +2
-1-static inline void evtchn_port_set_pending (struct vcpu *v, +static inline void evtchn_port_set_pending (struct domain *d, +unsigned int vcpu_id,struct evtchn *evtchn)I would rename this to the, now vacant,
evtchn_set_pending(). It takes an evtchn* not a port. (Its sole caller wasevtchn_set_pending(), so the patch won't grow)
Quoted 2 lines
No (and I had actually considered it) - that would get its name out of sync with all its sibling wrappers.
Ah yes - consistency is more important than correctness here.
Quoted 9 lines
Quoted 7 lines
Furthermore, all callers except
send_guest_vcpu_virq()currently useevtchn->notify_vcpu_idto get a struct vcpu* to pass. I think you can drop thevcpu_idparameter and useevtchn->notify_vcpu_iddirectly, which reduces the likelyhood of a bug where the evtchn is bound to one vcpu but a caller gets the wrong id and raises the event channel on the wrong vcpu.Generally a nice idea, but it doesn't immediately/obviously fit with the use in
send_guest_vcpu_virq().
It is awkward that some of the virqs will get delivered on an arbitrary vcpu, especially as the virq API requires the binding domain to choose a destination vcpu. Either way, this is not something to be addressed in a cleanup patch.
Therefore the original patch is Reviewed-by: Andrew Cooper <[email protected]>
~Andrew