From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0EE74A0524; Fri, 31 Jan 2020 09:48:13 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8C8FA1C0B9; Fri, 31 Jan 2020 09:48:11 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id EC9861C033 for ; Fri, 31 Jan 2020 09:48:09 +0100 (CET) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2020 00:47:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,385,1574150400"; d="scan'208";a="218550172" Received: from yexl-server.sh.intel.com (HELO localhost) ([10.67.117.17]) by orsmga007.jf.intel.com with ESMTP; 31 Jan 2020 00:47:11 -0800 Date: Fri, 31 Jan 2020 16:46:23 +0800 From: Ye Xiaolong To: Ferruh Yigit Cc: David Harton , dev@dpdk.org, wenzhuo.lu@intel.com, konstantin.ananyev@intel.com, intel.com@cisco.com Message-ID: <20200131084623.GA108127@intel.com> References: <20191211024802.17978-1-dharton@cisco.com> <20200126172548.23327-1-dharton@cisco.com> <558f34ae-e577-62ca-04e1-1097e6ee1abb@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <558f34ae-e577-62ca-04e1-1097e6ee1abb@intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Subject: Re: [dpdk-dev] [PATCH v2] net/e1000: update UPDATE_VF_STAT to handle rollover X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 01/29, Ferruh Yigit wrote: >On 1/26/2020 5:25 PM, David Harton wrote: >> Modified UPDATE_VF_STAT to properly handle rollover conditions. >> >> Fixes: d82170d27918 ("igb: add VF support") >> Cc: intel.com >> >> Signed-off-by: David Harton >> --- >> drivers/net/e1000/igb_ethdev.c | 14 +++++++++----- >> 1 file changed, 9 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c >> index a3e30dbe5..825663267 100644 >> --- a/drivers/net/e1000/igb_ethdev.c >> +++ b/drivers/net/e1000/igb_ethdev.c >> @@ -261,11 +261,15 @@ static int igb_filter_restore(struct rte_eth_dev *dev); >> /* >> * Define VF Stats MACRO for Non "cleared on read" register >> */ >> -#define UPDATE_VF_STAT(reg, last, cur) \ >> -{ \ >> - u32 latest = E1000_READ_REG(hw, reg); \ >> - cur += (latest - last) & UINT_MAX; \ > >Why this is wrong? Both 'latest' and 'last' are 'u32', so diff should be correct >'u32' value. And it is added to 'u64' 'cur' value. What I am missing? Per my understanding, stat value read from HW reg would be rolled over after it reaches its maximum, so we need to handle both normal case (latest >= last) and rollover case (latest < last) here. Wait for the original author for more explanation. > >> - last = latest; \ >> +#define UPDATE_VF_STAT(reg, last, cur) \ >> +{ \ >> + u32 latest = E1000_READ_REG(hw, reg); \ >> + if (latest >= last) \ >> + cur += (latest - last); \ >> + else \ >> + cur += ((latest + ((uint64_t)1 << 32)) - last); \ >> + cur &= UINT_MAX; \ > >Why & with UINT_MAX, won't this limit the value to 32bits which has 64bit storage? > Agree & with UINT_MAX should be removed here. Thanks, Xiaolong >> + last = latest; \ >> } >> >> #define IGB_FC_PAUSE_TIME 0x0680 >> >