diff mbox series

[net] ethtool: init tsinfo stats if requested

Message ID 20240530040814.1014446-1-vadfed@meta.com (mailing list archive)
State Accepted
Commit 89e281ebff72e6d37dce2df0e142b2909dafb267
Delegated to: Netdev Maintainers
Headers show
Series [net] ethtool: init tsinfo stats if requested | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 904 this patch: 904
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 1 blamed authors not CCed: dtatulea@nvidia.com; 2 maintainers not CCed: dtatulea@nvidia.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 906 this patch: 906
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 908 this patch: 908
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-05-30--06-00 (tests: 1042)

Commit Message

Vadim Fedorenko May 30, 2024, 4:08 a.m. UTC
Statistic values should be set to ETHTOOL_STAT_NOT_SET even if the
device doesn't support statistics. Otherwise zeros will be returned as
if they are proper values:

host# ethtool -I -T lo
Time stamping parameters for lo:
Capabilities:
	software-transmit
	software-receive
	software-system-clock
PTP Hardware Clock: none
Hardware Transmit Timestamp Modes: none
Hardware Receive Filter Modes: none
Statistics:
  tx_pkts: 0
  tx_lost: 0
  tx_err: 0

Fixes: 0e9c127729be ("ethtool: add interface to read Tx hardware timestamping statistics")
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
---
 net/ethtool/tsinfo.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Rahul Rameshbabu May 30, 2024, 4:42 a.m. UTC | #1
On Wed, 29 May, 2024 21:08:14 -0700 Vadim Fedorenko <vadfed@meta.com> wrote:
> Statistic values should be set to ETHTOOL_STAT_NOT_SET even if the
> device doesn't support statistics. Otherwise zeros will be returned as
> if they are proper values:
>
> host# ethtool -I -T lo
> Time stamping parameters for lo:
> Capabilities:
> 	software-transmit
> 	software-receive
> 	software-system-clock
> PTP Hardware Clock: none
> Hardware Transmit Timestamp Modes: none
> Hardware Receive Filter Modes: none
> Statistics:
>   tx_pkts: 0
>   tx_lost: 0
>   tx_err: 0
>
> Fixes: 0e9c127729be ("ethtool: add interface to read Tx hardware timestamping statistics")
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
> ---
>  net/ethtool/tsinfo.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
> index be2755c8d8fd..57d496287e52 100644
> --- a/net/ethtool/tsinfo.c
> +++ b/net/ethtool/tsinfo.c
> @@ -38,11 +38,11 @@ static int tsinfo_prepare_data(const struct ethnl_req_info *req_base,
>  	ret = ethnl_ops_begin(dev);
>  	if (ret < 0)
>  		return ret;
> -	if (req_base->flags & ETHTOOL_FLAG_STATS &&
> -	    dev->ethtool_ops->get_ts_stats) {
> +	if (req_base->flags & ETHTOOL_FLAG_STATS) {
>  		ethtool_stats_init((u64 *)&data->stats,
>  				   sizeof(data->stats) / sizeof(u64));
> -		dev->ethtool_ops->get_ts_stats(dev, &data->stats);
> +		if (dev->ethtool_ops->get_ts_stats)
> +			dev->ethtool_ops->get_ts_stats(dev, &data->stats);
>  	}
>  	ret = __ethtool_get_ts_info(dev, &data->ts_info);
>  	ethnl_ops_complete(dev);

Thanks for this catch! I agree with the change. If stats are requested
and the device does not support the statistics, the initial values need
to be set to illustrate the device does not support advertising
statistics. I think the patch should target "ethtool" instead of "net".
Also added Michal, the ethtool maintainer.

Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
Rahul Rameshbabu May 30, 2024, 4:47 a.m. UTC | #2
On Wed, 29 May, 2024 21:42:05 -0700 Rahul Rameshbabu <rrameshbabu@nvidia.com> wrote:
> On Wed, 29 May, 2024 21:08:14 -0700 Vadim Fedorenko <vadfed@meta.com> wrote:
>> Statistic values should be set to ETHTOOL_STAT_NOT_SET even if the
>> device doesn't support statistics. Otherwise zeros will be returned as
>> if they are proper values:
>>
>> host# ethtool -I -T lo
>> Time stamping parameters for lo:
>> Capabilities:
>> 	software-transmit
>> 	software-receive
>> 	software-system-clock
>> PTP Hardware Clock: none
>> Hardware Transmit Timestamp Modes: none
>> Hardware Receive Filter Modes: none
>> Statistics:
>>   tx_pkts: 0
>>   tx_lost: 0
>>   tx_err: 0
>>
>> Fixes: 0e9c127729be ("ethtool: add interface to read Tx hardware timestamping statistics")
>> Suggested-by: Jakub Kicinski <kuba@kernel.org>
>> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
>> ---
>>  net/ethtool/tsinfo.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
>> index be2755c8d8fd..57d496287e52 100644
>> --- a/net/ethtool/tsinfo.c
>> +++ b/net/ethtool/tsinfo.c
>> @@ -38,11 +38,11 @@ static int tsinfo_prepare_data(const struct ethnl_req_info *req_base,
>>  	ret = ethnl_ops_begin(dev);
>>  	if (ret < 0)
>>  		return ret;
>> -	if (req_base->flags & ETHTOOL_FLAG_STATS &&
>> -	    dev->ethtool_ops->get_ts_stats) {
>> +	if (req_base->flags & ETHTOOL_FLAG_STATS) {
>>  		ethtool_stats_init((u64 *)&data->stats,
>>  				   sizeof(data->stats) / sizeof(u64));
>> -		dev->ethtool_ops->get_ts_stats(dev, &data->stats);
>> +		if (dev->ethtool_ops->get_ts_stats)
>> +			dev->ethtool_ops->get_ts_stats(dev, &data->stats);
>>  	}
>>  	ret = __ethtool_get_ts_info(dev, &data->ts_info);
>>  	ethnl_ops_complete(dev);

<snip>

>I think the patch should target "ethtool" instead of "net".
> Also added Michal, the ethtool maintainer.

Ignore. Was thinking for some reason this would end up in the ethtool
tree. The patch is correct in targeting net.

>
> Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com>
patchwork-bot+netdevbpf@kernel.org June 1, 2024, 10:20 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 29 May 2024 21:08:14 -0700 you wrote:
> Statistic values should be set to ETHTOOL_STAT_NOT_SET even if the
> device doesn't support statistics. Otherwise zeros will be returned as
> if they are proper values:
> 
> host# ethtool -I -T lo
> Time stamping parameters for lo:
> Capabilities:
> 	software-transmit
> 	software-receive
> 	software-system-clock
> PTP Hardware Clock: none
> Hardware Transmit Timestamp Modes: none
> Hardware Receive Filter Modes: none
> Statistics:
>   tx_pkts: 0
>   tx_lost: 0
>   tx_err: 0
> 
> [...]

Here is the summary with links:
  - [net] ethtool: init tsinfo stats if requested
    https://git.kernel.org/netdev/net/c/89e281ebff72

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/ethtool/tsinfo.c b/net/ethtool/tsinfo.c
index be2755c8d8fd..57d496287e52 100644
--- a/net/ethtool/tsinfo.c
+++ b/net/ethtool/tsinfo.c
@@ -38,11 +38,11 @@  static int tsinfo_prepare_data(const struct ethnl_req_info *req_base,
 	ret = ethnl_ops_begin(dev);
 	if (ret < 0)
 		return ret;
-	if (req_base->flags & ETHTOOL_FLAG_STATS &&
-	    dev->ethtool_ops->get_ts_stats) {
+	if (req_base->flags & ETHTOOL_FLAG_STATS) {
 		ethtool_stats_init((u64 *)&data->stats,
 				   sizeof(data->stats) / sizeof(u64));
-		dev->ethtool_ops->get_ts_stats(dev, &data->stats);
+		if (dev->ethtool_ops->get_ts_stats)
+			dev->ethtool_ops->get_ts_stats(dev, &data->stats);
 	}
 	ret = __ethtool_get_ts_info(dev, &data->ts_info);
 	ethnl_ops_complete(dev);