[2/7] net/hns3: fix xstats statistics with id

Message ID 1607846585-2381-3-git-send-email-oulijun@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series some bugfixes for hns3 |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Lijun Ou Dec. 13, 2020, 8:03 a.m. UTC
  From: Huisong Li <lihuisong@huawei.com>

Number of xstats item in rte_eth_xstats_get_by_id is obtained
by the eth_dev_get_xstats_count API, and the xstats_get_by_id
ops of the driver only needs to report the corresponding stats
item result.
However, a redundant code for reporting the number of stats items
in the hns3_dev_xstats_get_by_id API causes a problem. Namely, if
the ID range of the xstats stats item does not include the basic
stats item, the app can not obtain the corresponding xstats
statistics in hns3_dev_xstats_get_by_id.

Fixes: 8839c5e202f3 ("net/hns3: support device stats")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 drivers/net/hns3/hns3_stats.c | 3 ---
 1 file changed, 3 deletions(-)
  

Comments

Ferruh Yigit Dec. 17, 2020, 3:20 p.m. UTC | #1
On 12/13/2020 8:03 AM, Lijun Ou wrote:
> From: Huisong Li <lihuisong@huawei.com>
> 
> Number of xstats item in rte_eth_xstats_get_by_id is obtained
> by the eth_dev_get_xstats_count API, and the xstats_get_by_id
> ops of the driver only needs to report the corresponding stats
> item result.
> However, a redundant code for reporting the number of stats items
> in the hns3_dev_xstats_get_by_id API causes a problem. Namely, if
> the ID range of the xstats stats item does not include the basic
> stats item, the app can not obtain the corresponding xstats
> statistics in hns3_dev_xstats_get_by_id.
> 
> Fixes: 8839c5e202f3 ("net/hns3: support device stats")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
> ---
>   drivers/net/hns3/hns3_stats.c | 3 ---
>   1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
> index 91168ac..b43143b 100644
> --- a/drivers/net/hns3/hns3_stats.c
> +++ b/drivers/net/hns3/hns3_stats.c
> @@ -933,9 +933,6 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
>   	uint32_t i;
>   	int ret;
>   
> -	if (ids == NULL || size < cnt_stats)
> -		return cnt_stats;
> -

Hi Lijun,

Above check seems wrong, but just removing it also wrong.

Following checks should be there:
ids==NULL && values==NULL ? return cnt_stats
ids==NULL ? return all values

Also 'hns3_dev_xstats_get_names_by_id()' seems wrong in that manner.
  
Lijun Ou Dec. 18, 2020, 7:06 a.m. UTC | #2
在 2020/12/17 23:20, Ferruh Yigit 写道:
> On 12/13/2020 8:03 AM, Lijun Ou wrote:
>> From: Huisong Li <lihuisong@huawei.com>
>>
>> Number of xstats item in rte_eth_xstats_get_by_id is obtained
>> by the eth_dev_get_xstats_count API, and the xstats_get_by_id
>> ops of the driver only needs to report the corresponding stats
>> item result.
>> However, a redundant code for reporting the number of stats items
>> in the hns3_dev_xstats_get_by_id API causes a problem. Namely, if
>> the ID range of the xstats stats item does not include the basic
>> stats item, the app can not obtain the corresponding xstats
>> statistics in hns3_dev_xstats_get_by_id.
>>
>> Fixes: 8839c5e202f3 ("net/hns3: support device stats")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>> ---
>>   drivers/net/hns3/hns3_stats.c | 3 ---
>>   1 file changed, 3 deletions(-)
>>
>> diff --git a/drivers/net/hns3/hns3_stats.c 
>> b/drivers/net/hns3/hns3_stats.c
>> index 91168ac..b43143b 100644
>> --- a/drivers/net/hns3/hns3_stats.c
>> +++ b/drivers/net/hns3/hns3_stats.c
>> @@ -933,9 +933,6 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, 
>> const uint64_t *ids,
>>       uint32_t i;
>>       int ret;
>> -    if (ids == NULL || size < cnt_stats)
>> -        return cnt_stats;
>> -
> 
> Hi Lijun,
> 
> Above check seems wrong, but just removing it also wrong.
> 
> Following checks should be there:
> ids==NULL && values==NULL ? return cnt_stats
> ids==NULL ? return all values
> 
> Also 'hns3_dev_xstats_get_names_by_id()' seems wrong in that manner.
> 
Thanks for your reviews. It should be deleted with the check in 
hns3_dev_xstats_get_by_id. Because the check have done in the API layer.
for example
   For rte_eth_xstats_get_by_id implementation:
   if ids == NULL and values == NULL, it returns the result of 
eth_dev_get_xstats_count and not run the hns3_dev_xstats_get_by_id

   if ids == NULL, it will not be able to run the hns3_dev_xstats_get_by_id.

However, Maybe the hns3_dev_xstats_get_names_by_id seems wrong and needs 
to fix it as flows:
diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
index 1d1f706..789ff6e 100644
--- a/drivers/net/hns3/hns3_stats.c
+++ b/drivers/net/hns3/hns3_stats.c
@@ -987,8 +987,8 @@ hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
         uint64_t len;
         uint32_t i;

-       if (ids == NULL || xstats_names == NULL)
-               return cnt_stats;
+       if (ids == NULL)
+               return hns3_dev_xstats_get_names(dev, xstats_names, 
cnt_stats);

         len = cnt_stats * sizeof(struct rte_eth_xstat_name);
         names_copy = rte_zmalloc("hns3_xstats_names", len, 0);

What do you think?
> .
>
  
Ferruh Yigit Dec. 18, 2020, 1:34 p.m. UTC | #3
On 12/18/2020 7:06 AM, oulijun wrote:
> 
> 
> 在 2020/12/17 23:20, Ferruh Yigit 写道:
>> On 12/13/2020 8:03 AM, Lijun Ou wrote:
>>> From: Huisong Li <lihuisong@huawei.com>
>>>
>>> Number of xstats item in rte_eth_xstats_get_by_id is obtained
>>> by the eth_dev_get_xstats_count API, and the xstats_get_by_id
>>> ops of the driver only needs to report the corresponding stats
>>> item result.
>>> However, a redundant code for reporting the number of stats items
>>> in the hns3_dev_xstats_get_by_id API causes a problem. Namely, if
>>> the ID range of the xstats stats item does not include the basic
>>> stats item, the app can not obtain the corresponding xstats
>>> statistics in hns3_dev_xstats_get_by_id.
>>>
>>> Fixes: 8839c5e202f3 ("net/hns3: support device stats")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>>> ---
>>>   drivers/net/hns3/hns3_stats.c | 3 ---
>>>   1 file changed, 3 deletions(-)
>>>
>>> diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
>>> index 91168ac..b43143b 100644
>>> --- a/drivers/net/hns3/hns3_stats.c
>>> +++ b/drivers/net/hns3/hns3_stats.c
>>> @@ -933,9 +933,6 @@ hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const 
>>> uint64_t *ids,
>>>       uint32_t i;
>>>       int ret;
>>> -    if (ids == NULL || size < cnt_stats)
>>> -        return cnt_stats;
>>> -
>>
>> Hi Lijun,
>>
>> Above check seems wrong, but just removing it also wrong.
>>
>> Following checks should be there:
>> ids==NULL && values==NULL ? return cnt_stats
>> ids==NULL ? return all values
>>
>> Also 'hns3_dev_xstats_get_names_by_id()' seems wrong in that manner.
>>
> Thanks for your reviews. It should be deleted with the check in 
> hns3_dev_xstats_get_by_id. Because the check have done in the API layer.
> for example
>    For rte_eth_xstats_get_by_id implementation:
>    if ids == NULL and values == NULL, it returns the result of 
> eth_dev_get_xstats_count and not run the hns3_dev_xstats_get_by_id
> 

For the case "ids==NULL && values==NULL",
yes 'rte_eth_xstats_get_by_id()' is the wrapper of this dev_ops and it has the 
checks, but the dev_ops can be called from somewhere else, like being in 
'eth_dev_get_xstats_count()', currently 'xstats_get_names_by_id()' is used there 
but 'xstats_get_by_id()' may be used as well, please check how it is used in 
that function. dev_ops gets, "NULL, NULL, 0" arguments and it should be supported.

And for the "ids==NULL" case, it is not covered at all in 
'hns3_dev_xstats_get_names_by_id()' but it should, that is a valid usecase.
When dev_ops gets, "ids==NULL", that means all xstat values are requested.

>    if ids == NULL, it will not be able to run the hns3_dev_xstats_get_by_id.
> 
> However, Maybe the hns3_dev_xstats_get_names_by_id seems wrong and needs to fix 
> it as flows:
> diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
> index 1d1f706..789ff6e 100644
> --- a/drivers/net/hns3/hns3_stats.c
> +++ b/drivers/net/hns3/hns3_stats.c
> @@ -987,8 +987,8 @@ hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
>          uint64_t len;
>          uint32_t i;
> 
> -       if (ids == NULL || xstats_names == NULL)
> -               return cnt_stats;
> +       if (ids == NULL)
> +               return hns3_dev_xstats_get_names(dev, xstats_names, cnt_stats);
> 
>          len = cnt_stats * sizeof(struct rte_eth_xstat_name);
>          names_copy = rte_zmalloc("hns3_xstats_names", len, 0);
> 
> What do you think?

I think both 'xstats_names' & 'ids' should be checked, please check above 
comment, like:

if (xstats_names == NULL)
	return cnt_stats;

if (ids == NULL)
	return hns3_dev_xstats_get_names(dev, xstats_names, cnt_stats);
  

Patch

diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
index 91168ac..b43143b 100644
--- a/drivers/net/hns3/hns3_stats.c
+++ b/drivers/net/hns3/hns3_stats.c
@@ -933,9 +933,6 @@  hns3_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
 	uint32_t i;
 	int ret;
 
-	if (ids == NULL || size < cnt_stats)
-		return cnt_stats;
-
 	/* Update tqp stats by read register */
 	ret = hns3_update_tqp_stats(hw);
 	if (ret) {