From: "Jan Beulich" Subject: Re: [PATCH 2/8] evtchn: refactor low-level event channel port ops Date: Thu, 15 Aug 2013 15:05:47 +0100 Message-ID: <520CFC5B02000078000EC402@nat28.tlf.novell.com> References: <1376071720-17644-1-git-send-email-david.vrabel@citrix.com> <1376071720-17644-3-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1V9yBR-0001T4-3l for xen-devel@lists.xenproject.org; Thu, 15 Aug 2013 14:05:49 +0000 In-Reply-To: <1376071720-17644-3-git-send-email-david.vrabel@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel Cc: xen-devel , Keir Fraser , Wei Liu List-Id: xen-devel@lists.xenproject.org >>> On 09.08.13 at 20:08, David Vrabel wrote: > +static void evtchn_2l_set_pending(struct vcpu *v, struct evtchn *evtchn) > +{ > + struct domain *d = v->domain; > + unsigned port = evtchn->port; > + > + /* > + * The following bit operations must happen in strict order. > + * NB. On x86, the atomic bit operations also act as memory barriers. > + * There is therefore sufficiently strict ordering for this architecture -- > + * others may require explicit memory barriers. > + */ > + > + if ( test_and_set_bit(port, &shared_info(d, evtchn_pending)) ) > + return; > + > + if ( !test_bit (port, &shared_info(d, evtchn_mask)) && > + !test_and_set_bit(port / BITS_PER_EVTCHN_WORD(d), > + &vcpu_info(v, evtchn_pending_sel)) ) Up to here this is indeed 2-level specific, but the rest of the function isn't, and would therefore better go back into generic code. > + { > + vcpu_mark_events_pending(v); > + } > + > + evtchn_check_pollers(d, port); > +} >[...] > +static void evtchn_2l_unmask(struct domain *d, struct evtchn *evtchn) > +{ > + struct vcpu *v = d->vcpu[evtchn->notify_vcpu_id]; > + unsigned port = evtchn->port; > + > + /* > + * These operations must happen in strict order. Based on > + * evtchn_2l_set_pending() above. > + */ > + if ( test_and_clear_bit(port, &shared_info(d, evtchn_mask)) && > + test_bit (port, &shared_info(d, evtchn_pending)) && > + !test_and_set_bit (port / BITS_PER_EVTCHN_WORD(d), > + &vcpu_info(v, evtchn_pending_sel)) ) Similarly here. > + { > + vcpu_mark_events_pending(v); > + } > +} >[...] > @@ -615,43 +616,10 @@ out: > > static void evtchn_set_pending(struct vcpu *v, int port) > { > - struct domain *d = v->domain; > - int vcpuid; > - > - /* > - * The following bit operations must happen in strict order. > - * NB. On x86, the atomic bit operations also act as memory barriers. > - * There is therefore sufficiently strict ordering for this architecture > -- > - * others may require explicit memory barriers. > - */ > - > - if ( test_and_set_bit(port, &shared_info(d, evtchn_pending)) ) > - return; > - > - if ( !test_bit (port, &shared_info(d, evtchn_mask)) && > - !test_and_set_bit(port / BITS_PER_EVTCHN_WORD(d), > - &vcpu_info(v, evtchn_pending_sel)) ) > - { > - vcpu_mark_events_pending(v); > - } > - > - /* Check if some VCPU might be polling for this event. */ > - if ( likely(bitmap_empty(d->poll_mask, d->max_vcpus)) ) > - return; > + struct evtchn *evtchn; > > - /* Wake any interested (or potentially interested) pollers. */ > - for ( vcpuid = find_first_bit(d->poll_mask, d->max_vcpus); > - vcpuid < d->max_vcpus; > - vcpuid = find_next_bit(d->poll_mask, d->max_vcpus, vcpuid+1) ) > - { > - v = d->vcpu[vcpuid]; > - if ( ((v->poll_evtchn <= 0) || (v->poll_evtchn == port)) && > - test_and_clear_bit(vcpuid, d->poll_mask) ) > - { > - v->poll_evtchn = 0; > - vcpu_unblock(v); > - } > - } > + evtchn = evtchn_from_port(v->domain, port); > + evtchn_port_set_pending(v, evtchn); I know it's a matter of taste, but having a variable that's used just once is usually done only whether otherwise the code would get much harder to read. Similarly further down. Jan