From: "Jan Beulich" Subject: Re: [PATCH v8 for-xen-4.5 2/2] dpci: Replace tasklet with an softirq (v8) Date: Wed, 29 Oct 2014 08:28:14 +0000 Message-ID: <5450B32E0200007800042FC8@mail.emea.novell.com> References: <544E1F590200007800042517@mail.emea.novell.com> <544E2105.1000907@citrix.com> <544E33B902000078000425F0@mail.emea.novell.com> <544E27D6.1040305@citrix.com> <544E397F0200007800042651@mail.emea.novell.com> <20141027170115.GC11893@laptop.dumpdata.com> <544E8283.1030907@citrix.com> <20141027180010.GB12989@laptop.dumpdata.com> <20141027211338.GA17750@laptop.dumpdata.com> <544F81640200007800042BE5@mail.emea.novell.com> <20141028200734.GA31298@laptop.dumpdata.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XjOc5-00066R-Hz for xen-devel@lists.xenproject.org; Wed, 29 Oct 2014 08:28:17 +0000 In-Reply-To: <20141028200734.GA31298@laptop.dumpdata.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: Konrad Rzeszutek Wilk Cc: keir@xen.org, ian.campbell@citrix.com, Andrew Cooper , tim@xen.org, xen-devel@lists.xenproject.org, ian.jackson@eu.citrix.com List-Id: xen-devel@lists.xenproject.org >>> On 28.10.14 at 21:07, wrote: > On Tue, Oct 28, 2014 at 10:43:32AM +0000, Jan Beulich wrote: >> >>> On 27.10.14 at 22:13, wrote: >> > + /* >> > + * A crude 'while' loop with us dropping the spinlock and giving >> > + * the softirq_dpci a chance to run. >> > + * We MUST check for this condition as the softirq could be scheduled >> > + * and hasn't run yet. Note that this code replaced tasklet_kill which >> > + * would have spun forever and would do the same thing (wait to flush out >> > + * outstanding hvm_dirq_assist calls. >> > + */ >> > + if ( pt_pirq_softirq_active(pirq_dpci) ) >> > + { >> > + spin_unlock(&d->event_lock); >> > + if ( pirq_dpci->cpu >= 0 && pirq_dpci->cpu != smp_processor_id() ) >> > + { >> > + /* >> > + * The 'raise_softirq_for' sets the CPU and raises the softirq bit >> > + * so we do not need to set the target CPU's HVM_DPCI_SOFTIRQ. >> > + */ >> > + smp_send_event_check_cpu(pirq_dpci->cpu); >> > + pirq_dpci->cpu = -1; >> > + } >> > + cpu_relax(); >> > + goto restart; >> > + } >> >> As said in an earlier reply to Andrew, I think this open coding goes >> too far. And with the softirq known to have got sent, I also don't >> really see why it needs to be resent _at all_ (and the comments >> don't explain this either). > > In the other emails you and Andrew said: > > ">> > Can it ever be the case that we are waiting for a remote pcpu to run its > >> > softirq handler? If so, the time spent looping here could be up to 1 > >> > scheduling timeslice in the worst case, and 30ms is a very long time to > >> > wait. > >> > >> Good point - I think this can be the case. But there seems to be a > >> simple counter measure: The first time we get to this point, send an > >> event check IPI to the CPU in question (or in the worst case > >> broadcast one if the CPU can't be determined in a race free way). > > > " And I was wrong to agree with Andrew. We can't be waiting for a full time slice - that would be contrary to the concept of softirqs. Locally raised ones cause them to be executed before returning back to guest context; remotely raised ones issue an IPI. > Which is true. That is what this is trying to address. > > But if we use 'cpu_raise_softirq' which you advocate it would inhibit the > IPI > if the HVM_DPCI_SOFTIRQ is set on the remote CPU: > > void cpu_raise_softirq(unsigned int cpu, unsigned int nr) > { > unsigned int this_cpu = smp_processor_id(); > > if ( test_and_set_bit(nr, &softirq_pending(cpu)) <=== that will be true > || (cpu == this_cpu) > || arch_skip_send_event_check(cpu) ) > return; > > if ( !per_cpu(batching, this_cpu) || in_irq() ) > smp_send_event_check_cpu(cpu); > else > set_bit(nr, &per_cpu(batch_mask, this_cpu)); > } > > In which case we still won't be sending the IPI. And we don't need to, as it was already done by whoever set that flag. Jan