From: "Jan Beulich" Subject: Re: Xen spinlock questions Date: Mon, 11 Aug 2008 13:22:06 +0100 Message-ID: <48A04B0E.76E4.0078.0@novell.com> References: <4896F39A.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5079B5FE.2__=" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: Jeremy Fitzhardinge , xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part5079B5FE.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline >>> Keir Fraser 04.08.08 12:24 >>> >On 4/8/08 11:18, "Jan Beulich" wrote: > >> 1) While the goal of the per-CPU kicker irq appears to be to avoid all = CPUs >> waiting for a particular lock to get kicked simultaneously, I think = this >> doesn't have the desired effect. This is because Xen doesn't track what >> event channel you poll for (through SCHEDOP_poll), and rather kicks all = CPUs >> polling for any event channel. > >Yes, this is true. We could easily do something better for VCPUs polling = a >single event channel though, but there hasn't been a need up to now. I >suppose it depends how often we have multiple VCPUs stuck waiting for >spinlocks. I can sort out a Xen-side patch if someone wanted to measure = the >benefits from more selective wakeup from poll. Running kernel builds on 8 vCPU-s competing for 4 pCPU-s shows a 10% improvement in performance with the individual wakeup (patch attached - probably sub-optimal, but I didn't seem to be able to think of a = lock-less mechanism to achieve the desired behavior), using ticket locks in the kernel. Jan --=__Part5079B5FE.2__= Content-Type: text/plain; name="poll-single-port.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="poll-single-port.patch" Index: 2008-08-06/xen/common/domain.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-08-06.orig/xen/common/domain.c 2008-08-07 11:03:33.000000000 = +0200 +++ 2008-08-06/xen/common/domain.c 2008-08-07 12:04:00.000000000 = +0200 @@ -209,6 +209,7 @@ struct domain *domain_create( atomic_set(&d->refcnt, 1); spin_lock_init(&d->domain_lock); spin_lock_init(&d->page_alloc_lock); + spin_lock_init(&d->poll_lock); spin_lock_init(&d->shutdown_lock); spin_lock_init(&d->hypercall_deadlock_mutex); INIT_LIST_HEAD(&d->page_list); @@ -653,7 +654,7 @@ void vcpu_reset(struct vcpu *v) =20 v->fpu_initialised =3D 0; v->fpu_dirtied =3D 0; - v->is_polling =3D 0; + v->poll_evtchn =3D 0; v->is_initialised =3D 0; v->nmi_pending =3D 0; v->mce_pending =3D 0; Index: 2008-08-06/xen/common/event_channel.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-08-06.orig/xen/common/event_channel.c 2008-08-07 11:03:33.0000000= 00 +0200 +++ 2008-08-06/xen/common/event_channel.c 2008-08-07 15:24:17.0000000= 00 +0200 @@ -545,6 +545,7 @@ out: static int evtchn_set_pending(struct vcpu *v, int port) { struct domain *d =3D v->domain; + unsigned long flags; =20 /* * The following bit operations must happen in strict order. @@ -564,19 +565,36 @@ static int evtchn_set_pending(struct vcp } =20 /* Check if some VCPU might be polling for this event. */ - if ( unlikely(d->is_polling) ) + if ( likely(!d->is_polling) ) + return 0; + + spin_lock_irqsave(&d->poll_lock, flags); + + if ( likely(d->is_polling) ) { - d->is_polling =3D 0; + bool_t is_polling =3D 0; + + d->is_polling =3D -1; smp_mb(); /* check vcpu poll-flags /after/ clearing domain = poll-flag */ for_each_vcpu ( d, v ) { - if ( !v->is_polling ) + int poll_evtchn =3D v->poll_evtchn; + + if ( !poll_evtchn ) + continue; + if ( poll_evtchn > 0 && poll_evtchn !=3D port ) + { + is_polling =3D 1; continue; - v->is_polling =3D 0; + } + v->poll_evtchn =3D 0; vcpu_unblock(v); } + cmpxchg(&d->is_polling, -1, is_polling); } =20 + spin_unlock_irqrestore(&d->poll_lock, flags); + return 0; } =20 Index: 2008-08-06/xen/common/schedule.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-08-06.orig/xen/common/schedule.c 2008-08-07 11:03:33.0000000= 00 +0200 +++ 2008-08-06/xen/common/schedule.c 2008-08-07 15:27:07.000000000 = +0200 @@ -348,7 +348,7 @@ static long do_poll(struct sched_poll *s return -EFAULT; =20 set_bit(_VPF_blocked, &v->pause_flags); - v->is_polling =3D 1; + v->poll_evtchn =3D -1; d->is_polling =3D 1; =20 /* Check for events /after/ setting flags: avoids wakeup waiting = race. */ @@ -369,6 +369,9 @@ static long do_poll(struct sched_poll *s goto out; } =20 + if ( i =3D=3D 1 ) + v->poll_evtchn =3D port; + if ( sched_poll->timeout !=3D 0 ) set_timer(&v->poll_timer, sched_poll->timeout); =20 @@ -378,7 +381,7 @@ static long do_poll(struct sched_poll *s return 0; =20 out: - v->is_polling =3D 0; + v->poll_evtchn =3D 0; clear_bit(_VPF_blocked, &v->pause_flags); return rc; } @@ -758,10 +761,10 @@ static void poll_timer_fn(void *data) { struct vcpu *v =3D data; =20 - if ( !v->is_polling ) + if ( !v->poll_evtchn ) return; =20 - v->is_polling =3D 0; + v->poll_evtchn =3D 0; vcpu_unblock(v); } =20 Index: 2008-08-06/xen/include/xen/sched.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2008-08-06.orig/xen/include/xen/sched.h 2008-08-07 11:03:33.0000000= 00 +0200 +++ 2008-08-06/xen/include/xen/sched.h 2008-08-07 10:07:56.000000000 = +0200 @@ -106,8 +106,6 @@ struct vcpu=20 bool_t fpu_initialised; /* Has the FPU been used since it was last saved? */ bool_t fpu_dirtied; - /* Is this VCPU polling any event channels (SCHEDOP_poll)? */ - bool_t is_polling; /* Initialization completed for this VCPU? */ bool_t is_initialised; /* Currently running on a CPU? */ @@ -137,6 +135,11 @@ struct vcpu=20 unsigned long pause_flags; atomic_t pause_count; =20 + /* Is this VCPU polling any event channels (SCHEDOP_poll)? + * Positive values indicate a single, negative values multiple = channels + * being polled. */ + int poll_evtchn; + /* IRQ-safe virq_lock protects against delivering VIRQ to stale = evtchn. */ u16 virq_to_evtchn[NR_VIRQS]; spinlock_t virq_lock; @@ -210,7 +213,7 @@ struct domain /* Is this guest being debugged by dom0? */ bool_t debugger_attached; /* Are any VCPUs polling event channels (SCHEDOP_poll)? */ - bool_t is_polling; + signed char is_polling; /* Is this guest dying (i.e., a zombie)? */ enum { DOMDYING_alive, DOMDYING_dying, DOMDYING_dead } is_dying; /* Domain is paused by controller software? */ @@ -218,6 +221,9 @@ struct domain /* Domain's VCPUs are pinned 1:1 to physical CPUs? */ bool_t is_pinned; =20 + /* Protects is_polling modification in evtchn_set_pending(). */ + spinlock_t poll_lock; + /* Guest has shut down (inc. reason code)? */ spinlock_t shutdown_lock; bool_t is_shutting_down; /* in process of shutting down? */ --=__Part5079B5FE.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part5079B5FE.2__=--