[dpdk-dev,1/2] ixgbe: fix VF statistic wraparound handling macro

Message ID 1444656823-717-2-git-send-email-harry.van.haaren@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Van Haaren, Harry Oct. 12, 2015, 1:33 p.m. UTC
  Fix a misinterpretation of VF stats in ixgbe

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 drivers/net/ixgbe/ixgbe_ethdev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Roger Melton Oct. 12, 2015, 2:45 p.m. UTC | #1
ack

On 10/12/15 9:33 AM, Harry van Haaren wrote:
> Fix a misinterpretation of VF stats in ixgbe
>
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---
>   drivers/net/ixgbe/ixgbe_ethdev.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
> index ec2918c..d226e8d 100644
> --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> @@ -329,10 +329,14 @@ static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
>   /*
>    * Define VF Stats MACRO for Non "cleared on read" register
>    */
> -#define UPDATE_VF_STAT(reg, last, cur)	                        \
> +#define UPDATE_VF_STAT(reg, last, cur)                          \
>   {                                                               \
>   	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
> -	cur += latest - last;                                   \
> +	if(likely(latest > last)) {                             \
> +		cur += latest - last;                           \
> +	} else {                                                \
> +		cur += (UINT_MAX - last) + latest;              \
> +	}                                                       \
>   	last = latest;                                          \
>   }
>
  
Alexander Duyck Oct. 12, 2015, 3:41 p.m. UTC | #2
On 10/12/2015 06:33 AM, Harry van Haaren wrote:
> Fix a misinterpretation of VF stats in ixgbe
>
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> ---
>   drivers/net/ixgbe/ixgbe_ethdev.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
> index ec2918c..d226e8d 100644
> --- a/drivers/net/ixgbe/ixgbe_ethdev.c
> +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
> @@ -329,10 +329,14 @@ static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
>   /*
>    * Define VF Stats MACRO for Non "cleared on read" register
>    */
> -#define UPDATE_VF_STAT(reg, last, cur)	                        \
> +#define UPDATE_VF_STAT(reg, last, cur)                          \
>   {                                                               \
>   	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
> -	cur += latest - last;                                   \
> +	if(likely(latest > last)) {                             \
> +		cur += latest - last;                           \
> +	} else {                                                \
> +		cur += (UINT_MAX - last) + latest;              \
> +	}                                                       \
>   	last = latest;                                          \
>   }
>   

 From what I can tell your math is adding an off by one error.  You 
should probably be using UINT_MAX as a mask for the result, not as a 
part of the calculation itself.

So the correct way to compute this would be "cur += (latest - last) & 
UINT_MAX".  Also the mask approach should be faster as it avoids any 
conditional jumps.

- Alex
  
Van Haaren, Harry Oct. 12, 2015, 4:45 p.m. UTC | #3
The following two patches fix a misinterpretation of the cyclic
counters of igb and ixgbe VF. When the 32bit value wraps around,
the code now handles the wrapped new value appropriatly.

v2:
- Reimplemented with Alex's suggested fix for off-by-one

v1:
- Initial implementation

Harry van Haaren (2):
  ixgbe: fix VF statistic wraparound handling macro
  igb: fix VF statistic wraparound handling macro

 drivers/net/e1000/igb_ethdev.c   | 3 +--
 drivers/net/ixgbe/ixgbe_ethdev.c | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
  
Roger Melton Oct. 13, 2015, 7:43 p.m. UTC | #4
Agreed, this handles the off by one error on wrap around and should be 
faster.

-Roger


On 10/12/15 11:41 AM, Alexander Duyck wrote:
> On 10/12/2015 06:33 AM, Harry van Haaren wrote:
>> Fix a misinterpretation of VF stats in ixgbe
>>
>> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
>> ---
>>   drivers/net/ixgbe/ixgbe_ethdev.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c 
>> b/drivers/net/ixgbe/ixgbe_ethdev.c
>> index ec2918c..d226e8d 100644
>> --- a/drivers/net/ixgbe/ixgbe_ethdev.c
>> +++ b/drivers/net/ixgbe/ixgbe_ethdev.c
>> @@ -329,10 +329,14 @@ static int 
>> ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
>>   /*
>>    * Define VF Stats MACRO for Non "cleared on read" register
>>    */
>> -#define UPDATE_VF_STAT(reg, last, cur)                            \
>> +#define UPDATE_VF_STAT(reg, last, cur) \
>> { \
>>       uint32_t latest = IXGBE_READ_REG(hw, reg);              \
>> -    cur += latest - last;                                   \
>> +    if(likely(latest > last)) { \
>> +        cur += latest - last;                           \
>> +    } else {                                                \
>> +        cur += (UINT_MAX - last) + latest;              \
>> +    }                                                       \
>>       last = latest;                                          \
>>   }
>
> From what I can tell your math is adding an off by one error.  You 
> should probably be using UINT_MAX as a mask for the result, not as a 
> part of the calculation itself.
>
> So the correct way to compute this would be "cur += (latest - last) & 
> UINT_MAX".  Also the mask approach should be faster as it avoids any 
> conditional jumps.
>
> - Alex
> .
>
  
Thomas Monjalon Oct. 28, 2015, 1:40 p.m. UTC | #5
2015-10-12 17:45, Harry van Haaren:
> The following two patches fix a misinterpretation of the cyclic
> counters of igb and ixgbe VF. When the 32bit value wraps around,
> the code now handles the wrapped new value appropriatly.
> 
> v2:
> - Reimplemented with Alex's suggested fix for off-by-one
> 
> v1:
> - Initial implementation
> 
> Harry van Haaren (2):
>   ixgbe: fix VF statistic wraparound handling macro
>   igb: fix VF statistic wraparound handling macro

Applied (with spacing fixes), thanks
  

Patch

diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index ec2918c..d226e8d 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -329,10 +329,14 @@  static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
 /*
  * Define VF Stats MACRO for Non "cleared on read" register
  */
-#define UPDATE_VF_STAT(reg, last, cur)	                        \
+#define UPDATE_VF_STAT(reg, last, cur)                          \
 {                                                               \
 	uint32_t latest = IXGBE_READ_REG(hw, reg);              \
-	cur += latest - last;                                   \
+	if(likely(latest > last)) {                             \
+		cur += latest - last;                           \
+	} else {                                                \
+		cur += (UINT_MAX - last) + latest;              \
+	}                                                       \
 	last = latest;                                          \
 }