From: Wei Liu Subject: Re: [PATCH 2/3] xen-netback: switch to per-cpu scratch space Date: Tue, 28 May 2013 11:17:44 +0100 Message-ID: <20130528101744.GC4394@zion.uk.xensource.com> References: <1369654183-10536-1-git-send-email-wei.liu2@citrix.com> <1369654183-10536-3-git-send-email-wei.liu2@citrix.com> <51A47D2D.5080204@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <51A47D2D.5080204@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: annie li Cc: david.vrabel@citrix.com, Wei Liu , ian.campbell@citrix.com, konrad.wilk@oracle.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, May 28, 2013 at 05:47:25PM +0800, annie li wrote: [...] > >- struct gnttab_copy grant_copy_op[2*XEN_NETIF_RX_RING_SIZE]; > >- struct netbk_rx_meta meta[2*XEN_NETIF_RX_RING_SIZE]; > > }; > > static struct xen_netbk *xen_netbk; > >@@ -608,12 +613,31 @@ static void xen_netbk_rx_action(struct xen_netbk *netbk) > > int count; > > unsigned long offset; > > struct skb_cb_overlay *sco; > >+ struct gnttab_copy *gco = get_cpu_var(grant_copy_op); > >+ struct netbk_rx_meta *m = get_cpu_var(meta); > > Change m to a friendly name? Changed to "meta". > > >+ static int unusable_count; > > struct netrx_pending_operations npo = { > >- .copy = netbk->grant_copy_op, > >- .meta = netbk->meta, > >+ .copy = gco, > >+ .meta = m, > > }; > >+ if (gco == NULL || m == NULL) { > >+ put_cpu_var(grant_copy_op); > >+ put_cpu_var(meta); > >+ if (unusable_count == 1000) { > > It is better to use a macro to replace this number here. > BTW, can you explain why using 1000 here? > This is just a random number chosen to avoid flooding dmesg log. :-) Re macro, this is the only place that use this test, so no need for a macro. Following test in TX path look similar, but the put_cpu_var() in that branch is different, I doubt we can get much from defining a macro here. > >+ printk(KERN_ALERT > >+ "xen-netback: " > >+ "CPU %d scratch space is not available," > >+ " not doing any TX work for netback/%d\n", > >+ smp_processor_id(), > >+ (int)(netbk - xen_netbk)); > > unusable_count is not a value based on netbk here. I assume you use > unusable_count to judge whether scratch space is available for > specific netbk, if so, then unusable_count needs to be counter for > specific netbk, not for all netbk. > No, it is not based on netbk. It is for a particular CPU. Per-cpu scratch is for CPUs not netbks. Netback thread can always be scheduled on other CPU in 1:1 model, so in practice it will almost never print out this warning if unusable_count is for netbk. [...] > >+ > >+ if (unusable_count == 1000) { > > Same as above > [...] > >+ return 0; > >+} > >+ > >+static void __free_percpu_scratch_space(unsigned int cpu) > >+{ > >+ void *tmp; > >+ > >+ tmp = per_cpu(tx_copy_ops, cpu); > > It is better to verify whether tmp is available before freeing it, > for example: if (tmp) > No need to do this, as it is legit to free() a NULL pointer. > [...] > >+ > >+static struct notifier_block netback_notifier_block = { > >+ .notifier_call = __netback_percpu_callback, > >+}; > > Moving this to the top of this file? > It is sort of convention to put this sort of things in the back rather in the front. > >+ [...] Wei. > > Thanks > Annie >