From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <thomas.monjalon@6wind.com>
Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com
 [209.85.212.180]) by dpdk.org (Postfix) with ESMTP id 610DA3B5
 for <dev@dpdk.org>; Fri, 27 Mar 2015 16:41:00 +0100 (CET)
Received: by wibg7 with SMTP id g7so30910412wib.1
 for <dev@dpdk.org>; Fri, 27 Mar 2015 08:41:00 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:organization
 :user-agent:in-reply-to:references:mime-version
 :content-transfer-encoding:content-type;
 bh=vdvlFY0US6PYtCsOqxbn14oFGgPgoK802XuIkYDQ3TA=;
 b=NO+ibwUy5KKnDXuGvQHyyyHzwfZIVVZirO3o7J1baeKMq5JqAzsKMm8YlzjQMdSjMB
 qOC7KBb+r8j3FQAsqBXa9H+WjorqjQmqAyTBCSglhnXWeChBT31VvDz/t3BJawplLJt5
 Bc4R/kLlEkMCtyJI9RCpez3wF+B8VHe8NIJV5935s/Jp+m8clpxMXLfz3x7hncFUPVk/
 Q+euCKNtH0Gd9aHPRud34q49LfLBHlwedFdHAF1hnDJI3toQIXqqAj4uDkR1Us7+Lqli
 EV61NksTivxAmazP50ehRfWx8wprtIgGxQ7hsAcYiZRBx+3r4O3WoeWYHM8HRzE1Z11q
 8vdw==
X-Gm-Message-State: ALoCoQlS+oRdaeJbIlo6/xZNlDO7lMv5euEV3XiWQGOZip75u0cG8tVds/2HJlwg9JlnBeWnVjgm
X-Received: by 10.180.74.202 with SMTP id w10mr58848733wiv.0.1427470860157;
 Fri, 27 Mar 2015 08:41:00 -0700 (PDT)
Received: from xps13.localnet (130.20.90.92.rev.sfr.net. [92.90.20.130])
 by mx.google.com with ESMTPSA id xy2sm3354314wjc.14.2015.03.27.08.40.57
 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Fri, 27 Mar 2015 08:40:59 -0700 (PDT)
From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: "Ouyang, Changchun" <changchun.ouyang@intel.com>
Date: Fri, 27 Mar 2015 16:25:10 +0100
Message-ID: <1695384.4PXBXvUaFj@xps13>
Organization: 6WIND
User-Agent: KMail/4.14.4 (Linux/3.18.4-1-ARCH; KDE/4.14.4; x86_64; ; )
In-Reply-To: <F52918179C57134FAEC9EA62FA2F962511A78AD9@shsmsx102.ccr.corp.intel.com>
References: <1427093798-23078-1-git-send-email-changchun.ouyang@intel.com>
 <11509543.rOgWUoKvXr@xps13>
 <F52918179C57134FAEC9EA62FA2F962511A78AD9@shsmsx102.ccr.corp.intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="us-ascii"
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] virtio: Fix stats issue
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 27 Mar 2015 15:41:00 -0000

2015-03-27 14:26, Ouyang, Changchun:
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> > 2015-03-23 16:38, Ouyang, Changchun:
> > > On 3/23/2015 3:20 PM, David Marchand wrote:
> > > > On Mon, Mar 23, 2015 at 7:56 AM, Ouyang Changchun wrote:
> > > >     --- a/lib/librte_pmd_virtio/virtio_ethdev.c
> > > >     +++ b/lib/librte_pmd_virtio/virtio_ethdev.c
> > > >     @@ -572,6 +572,10 @@ virtio_dev_stats_get(struct rte_eth_dev *dev,
> > > >     struct rte_eth_stats *stats)
> > > >      {
> > > >             unsigned i;
> > > >
> > > >     +       stats->opackets = 0;
> > > >     +       stats->obytes = 0;
> > > >     +       stats->oerrors = 0;
> > > >
> > > >
> > > > stats are supposed to be zero'd in generic rte_ethdev.c before this
> > > > pmd function is called, so this patch seems useless to me.
> > > > Can you give some context ?
> > > >
> > > > Same comment for the i* part.
> > > >
> > > 2 reasons:
> > > 1. this change could keep the stats_get has consistent behavior with
> > > the one in other drivers;
> > 
> > If there are some useless reset in other drivers, they should be removed.
> > 
> > > 2. we don't rely on the assumption of caller always zero'd the stats,
> > > and still can return correct value;
> > 
> > The caller is ethdev and it is zero'ing the structure before the call:
> > 	http://dpdk.org/browse/dpdk/commit/?id=02331c16ec0
> > 
> 
> I have seen this patch is rejected in patch-work,
> But I'd like continue to discuss it here.
>  
> Do you guys see any big issues if we initialize 0 here in this function?
> Well, I don't see any big issue here, just once again zero'd the stats info before get the actual value, it doesn't affect the rx and tx perf.
> 
> do you guys think it is better way to make a function behave under some assumption like here, caller must zero'd some memory?
> It could work, but I think the better way is every function should make sure it has correct behavior even without any assumption.

Assumptions are everywhere, we call it API ;)

> On the other hand, I even think it is worthy to revert this patch, if you guys think the duplicated zero'd are not so nice:
> http://dpdk.org/browse/dpdk/commit/?id=02331c16ec0
> 
> the background is that 
> some guys want to implement another function(mostly like API in ethdev) which will call  virtio_dev_stats_get directly,
> and NOT zero'd the stats before the calling, and then get the incorrect stats info as stats use '+=' to calculate the value and nowhere zero'd it before
> do the '+='.  

You should think about zero'ing prerequisite as driver API of stats_get implementation.
If you want to call it in another place, you just have to respect this API and do the zero'ing.
This kind of API must be clear to show where are the responsibilities and make maintenance easier.

> So my opinion is we had better zero'd in virtio_dev_stats_get, instead of in rtedev,
> While other pmd use '=' rather than '+=',
> So they don't need explicitly zero'd the stats, but has similar effect.
> 
> Any thoughts?
> 
> Thanks
> Changchun