fm10k: add helper functions to set strings and data for ethtool stats
Subsystems (2)
PATCH 1/2 fm10k: add helper functions to set strings and data for ethtool stats
Reduce duplicate code and the amount of indentation by adding fm10k_add_stat_strings and fm10k_add_ethtool_stats functions which help add fm10k_stat structures to the ethtool stats callbacks. This helps increase ease of use for future stat additions, and increases code readability. Skip handling of the per-queue stats as these will be reworked in a following patch.
---
These two patches apply on top of my previous series, though I don't expect there to be any conflicts.
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 164 ++++++++++++----------- 1 file changed, 83 insertions(+), 81 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +83 -81
@@ -153,57 +153,51 @@ static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = { "debug-statistics", }; +static void fm10k_add_stat_strings (char **p,const char *prefix, +const struct fm10k_stats stats[], +const unsigned int size) +{ +unsigned int i; + +for (i =0 ; i < size; i++) { +snprintf (*p,ETH_GSTRING_LEN ,"%s%s" , + prefix, stats[i].stat_string); + *p +=ETH_GSTRING_LEN ; + } +} +static void fm10k_get_stat_strings (struct net_device *dev,u8 *data) {struct fm10k_intfc *interface =netdev_priv (dev);struct fm10k_iov_data *iov_data = interface->iov_data;char *p = (char *)data;unsigned int i; -unsigned int j; -for (i =0 ; i <FM10K_NETDEV_STATS_LEN ; i++) { -memcpy (p, fm10k_gstrings_net_stats[i].stat_string, -ETH_GSTRING_LEN ); - p +=ETH_GSTRING_LEN ; - } +fm10k_add_stat_strings (&p,"" , fm10k_gstrings_net_stats, +FM10K_NETDEV_STATS_LEN ); -for (i =0 ; i <FM10K_GLOBAL_STATS_LEN ; i++) { -memcpy (p, fm10k_gstrings_global_stats[i].stat_string, -ETH_GSTRING_LEN ); - p +=ETH_GSTRING_LEN ; - } +fm10k_add_stat_strings (&p,"" , fm10k_gstrings_global_stats, +FM10K_GLOBAL_STATS_LEN ); -if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { -for (i =0 ; i <FM10K_DEBUG_STATS_LEN ; i++) { -memcpy (p, fm10k_gstrings_debug_stats[i].stat_string, -ETH_GSTRING_LEN ); - p +=ETH_GSTRING_LEN ; - } - } +if (interface->flags &FM10K_FLAG_DEBUG_STATS ) +fm10k_add_stat_strings (&p,"" , fm10k_gstrings_debug_stats, +FM10K_DEBUG_STATS_LEN ); -for (i =0 ; i <FM10K_MBX_STATS_LEN ; i++) { -memcpy (p, fm10k_gstrings_mbx_stats[i].stat_string, -ETH_GSTRING_LEN ); - p +=ETH_GSTRING_LEN ; - } +fm10k_add_stat_strings (&p,"" , fm10k_gstrings_mbx_stats, +FM10K_MBX_STATS_LEN ); -if (interface->hw.mac.type != fm10k_mac_vf) { -for (i =0 ; i <FM10K_PF_STATS_LEN ; i++) { -memcpy (p, fm10k_gstrings_pf_stats[i].stat_string, -ETH_GSTRING_LEN ); - p +=ETH_GSTRING_LEN ; - } - } +if (interface->hw.mac.type != fm10k_mac_vf) +fm10k_add_stat_strings (&p,"" , fm10k_gstrings_pf_stats, +FM10K_PF_STATS_LEN );if ((interface->flags &FM10K_FLAG_DEBUG_STATS ) && iov_data) {for (i =0 ; i < iov_data->num_vfs; i++) { -for (j =0 ; j <FM10K_MBX_STATS_LEN ; j++) { -snprintf (p, -ETH_GSTRING_LEN , -"vf_%u_%s" , i, - fm10k_gstrings_mbx_stats[j].stat_string); - p +=ETH_GSTRING_LEN ; - } +char prefix[ETH_GSTRING_LEN ]; + +snprintf (prefix,ETH_GSTRING_LEN ,"vf_%u_" , i); +fm10k_add_stat_strings (&p, prefix, + fm10k_gstrings_mbx_stats, +FM10K_MBX_STATS_LEN ); } }
@@ -271,6 +265,41 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset) } } +static void fm10k_add_ethtool_stats (u64 **data,void *pointer, +const struct fm10k_stats stats[], +const unsigned int size) +{ +unsigned int i; +char *p; + +/* simply skip forward if we were not given a valid pointer */ +if (!pointer) { + *data += size; +return ; + } + +for (i =0 ; i < size; i++) { + p = (char *)pointer + stats[i].stat_offset; + +switch (stats[i].sizeof_stat) { +case sizeof (u64): + *((*data)++) = *(u64 *)p; +break ; +case sizeof (u32): + *((*data)++) = *(u32 *)p; +break ; +case sizeof (u16): + *((*data)++) = *(u16 *)p; +break ; +case sizeof (u8): + *((*data)++) = *(u8 *)p; +break ; +default : + *((*data)++) =0 ; + } + } +} +static void fm10k_get_ethtool_stats (struct net_device *netdev,struct ethtool_stats __always_unused *stats,u64 *data)
@@ -279,47 +308,29 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,struct fm10k_intfc *interface =netdev_priv (netdev);struct fm10k_iov_data *iov_data = interface->iov_data;struct net_device_stats *net_stats = &netdev->stats; -char *p;int i, j;fm10k_update_stats (interface); -for (i =0 ; i <FM10K_NETDEV_STATS_LEN ; i++) { - p = (char *)net_stats + fm10k_gstrings_net_stats[i].stat_offset; - *(data++) = (fm10k_gstrings_net_stats[i].sizeof_stat == -sizeof (u64)) ? *(u64 *)p : *(u32 *)p; - } +fm10k_add_ethtool_stats (&data, net_stats, fm10k_gstrings_net_stats, +FM10K_NETDEV_STATS_LEN ); -for (i =0 ; i <FM10K_GLOBAL_STATS_LEN ; i++) { - p = (char *)interface + - fm10k_gstrings_global_stats[i].stat_offset; - *(data++) = (fm10k_gstrings_global_stats[i].sizeof_stat == -sizeof (u64)) ? *(u64 *)p : *(u32 *)p; - } +fm10k_add_ethtool_stats (&data, interface, fm10k_gstrings_global_stats, +FM10K_GLOBAL_STATS_LEN ); -if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { -for (i =0 ; i <FM10K_DEBUG_STATS_LEN ; i++) { - p = (char *)interface + - fm10k_gstrings_debug_stats[i].stat_offset; - *(data++) = (fm10k_gstrings_debug_stats[i].sizeof_stat == -sizeof (u64)) ? *(u64 *)p : *(u32 *)p; - } - } +if (interface->flags &FM10K_FLAG_DEBUG_STATS ) +fm10k_add_ethtool_stats (&data, interface, + fm10k_gstrings_debug_stats, +FM10K_DEBUG_STATS_LEN ); -for (i =0 ; i <FM10K_MBX_STATS_LEN ; i++) { - p = (char *)&interface->hw.mbx + - fm10k_gstrings_mbx_stats[i].stat_offset; - *(data++) = (fm10k_gstrings_mbx_stats[i].sizeof_stat == -sizeof (u64)) ? *(u64 *)p : *(u32 *)p; - } +fm10k_add_ethtool_stats (&data, &interface->hw.mbx, + fm10k_gstrings_mbx_stats, +FM10K_MBX_STATS_LEN );if (interface->hw.mac.type != fm10k_mac_vf) { -for (i =0 ; i <FM10K_PF_STATS_LEN ; i++) { - p = (char *)interface + - fm10k_gstrings_pf_stats[i].stat_offset; - *(data++) = (fm10k_gstrings_pf_stats[i].sizeof_stat == -sizeof (u64)) ? *(u64 *)p : *(u32 *)p; - } +fm10k_add_ethtool_stats (&data, interface, + fm10k_gstrings_pf_stats, +FM10K_PF_STATS_LEN ); }if ((interface->flags &FM10K_FLAG_DEBUG_STATS ) && iov_data) {
@@ -328,18 +339,9 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev, vf_info = &iov_data->vf_info[i]; -/* skip stats if we don't have a vf info */ -if (!vf_info) { - data +=FM10K_MBX_STATS_LEN ; -continue ; - } - -for (j =0 ; j <FM10K_MBX_STATS_LEN ; j++) { - p = (char *)&vf_info->mbx + - fm10k_gstrings_mbx_stats[j].stat_offset; - *(data++) = (fm10k_gstrings_mbx_stats[j].sizeof_stat == -sizeof (u64)) ? *(u64 *)p : *(u32 *)p; - } +fm10k_add_ethtool_stats (&data, &vf_info->mbx, + fm10k_gstrings_mbx_stats, +FM10K_MBX_STATS_LEN ); } }
Signature · 1 line
2.7.0.236.gda096a0.dirty
PATCH 2/2 fm10k: use fm10k_stats structures for per-queue statistics
This will allow us numerous advantages, including
(a) rework the per-queue stats to only display active queues, reducing clutter on the output. This is important since we often don't have all possible queues enabled.
(b) use the new streamlined helper functions, reducing duplicate code and increasing readability of the stats logic
(c) add the additional per-tx and per-rx statistics when debug-statistics is enabled, which may be helpful for future debug work.
The primary motivation for this change is (a), though (b) and (c) are useful additions which were noticed while developing the change.
Note that this code currently assumes we have the same number of Tx and Rx queues which should be true of our driver pretty much always. Even if there are a non equal number of Tx and Rx queues, the only result will be a few extra statistics displaying 0s. This is better than the current setup which shows every disabled queue with all 0s.
---
These two patches apply on top of my previous series, though I do not believe there would be any complications re-ordering them.
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c | 118 ++++++++++++++++++----- 1 file changed, 93 insertions(+), 25 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +93 -25
@@ -121,18 +121,52 @@ static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = { FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed), }; +#define FM10K_QUEUE_STAT (_name, _stat) { \ + .stat_string = _name, \ + .sizeof_stat = FIELD_SIZEOF(struct fm10k_ring, _stat), \ + .stat_offset = offsetof(struct fm10k_ring, _stat) \ +} + +static const struct fm10k_stats fm10k_gstrings_queue_stats[] = { +FM10K_QUEUE_STAT ("packets" , stats.packets), +FM10K_QUEUE_STAT ("bytes" , stats.packets), +}; + +static const struct fm10k_stats fm10k_gstrings_tx_queue_stats[] = { +FM10K_QUEUE_STAT ("restart_queue" , tx_stats.restart_queue), +FM10K_QUEUE_STAT ("csum_err" , tx_stats.restart_queue), +FM10K_QUEUE_STAT ("tx_busy" , tx_stats.restart_queue), +FM10K_QUEUE_STAT ("tx_done_old" , tx_stats.restart_queue), +FM10K_QUEUE_STAT ("csum_good" , tx_stats.restart_queue), +}; + +static const struct fm10k_stats fm10k_gstrings_rx_queue_stats[] = { +FM10K_QUEUE_STAT ("alloc_failed" , rx_stats.alloc_failed), +FM10K_QUEUE_STAT ("csum_err" , rx_stats.csum_err), +FM10K_QUEUE_STAT ("errors" , rx_stats.errors), +FM10K_QUEUE_STAT ("csum_good" , rx_stats.csum_good), +FM10K_QUEUE_STAT ("switch_errors" , rx_stats.switch_errors), +FM10K_QUEUE_STAT ("drops" , rx_stats.drops), +FM10K_QUEUE_STAT ("pp_errors" , rx_stats.pp_errors), +FM10K_QUEUE_STAT ("link_errors" , rx_stats.link_errors), +FM10K_QUEUE_STAT ("length_errors" , rx_stats.length_errors), + +}; +#define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)#define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats)#define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)#define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats) -#define FM10K_QUEUE_STATS_LEN (_n) \ - ((_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64))) -#define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \ FM10K_NETDEV_STATS_LEN + \ FM10K_MBX_STATS_LEN) +/* non-static stats based on number of Tx/Rx queues */ +#define FM10K_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_queue_stats) +#define FM10K_TX_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_tx_queue_stats) +#define FM10K_RX_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_rx_queue_stats) +static const char fm10k_gstrings_test[][ETH_GSTRING_LEN ] = {"Mailbox test (on/offline)" };
@@ -153,6 +187,11 @@ static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = { "debug-statistics", }; +static unsigned int fm10k_queues_in_use (struct fm10k_intfc *interface) +{ +return max (interface->num_tx_queues, interface->num_rx_queues); +} +static void fm10k_add_stat_strings (char **p,const char *prefix,const struct fm10k_stats stats[],const unsigned int size)
@@ -201,15 +240,30 @@ static void fm10k_get_stat_strings(struct net_device *dev, u8 *data) } } -for (i =0 ; i < interface->hw.mac.max_queues; i++) { -snprintf (p,ETH_GSTRING_LEN ,"tx_queue_%u_packets" , i); - p +=ETH_GSTRING_LEN ; -snprintf (p,ETH_GSTRING_LEN ,"tx_queue_%u_bytes" , i); - p +=ETH_GSTRING_LEN ; -snprintf (p,ETH_GSTRING_LEN ,"rx_queue_%u_packets" , i); - p +=ETH_GSTRING_LEN ; -snprintf (p,ETH_GSTRING_LEN ,"rx_queue_%u_bytes" , i); - p +=ETH_GSTRING_LEN ; +for (i =0 ; i <fm10k_queues_in_use (interface); i++) { +char prefix[ETH_GSTRING_LEN ]; + +snprintf (prefix,ETH_GSTRING_LEN ,"tx_queue_%u_" , i); +fm10k_add_stat_strings (&p, prefix, + fm10k_gstrings_queue_stats, +FM10K_QUEUE_STATS_LEN ); + +if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { +fm10k_add_stat_strings (&p, prefix, + fm10k_gstrings_tx_queue_stats, +FM10K_TX_QUEUE_STATS_LEN ); + } + +snprintf (prefix,ETH_GSTRING_LEN ,"rx_queue_%u_" , i); +fm10k_add_stat_strings (&p, prefix, + fm10k_gstrings_queue_stats, +FM10K_QUEUE_STATS_LEN ); + +if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { +fm10k_add_stat_strings (&p, prefix, + fm10k_gstrings_rx_queue_stats, +FM10K_RX_QUEUE_STATS_LEN ); + } } }
@@ -239,12 +293,15 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset)struct fm10k_iov_data *iov_data = interface->iov_data;struct fm10k_hw *hw = &interface->hw;int stats_len =FM10K_STATIC_STATS_LEN ; +int tx_queues = interface->num_tx_queues; +int rx_queues = interface->num_rx_queues; +switch (sset) {case ETH_SS_TEST :return FM10K_TEST_LEN ;case ETH_SS_STATS : - stats_len +=FM10K_QUEUE_STATS_LEN (hw->mac.max_queues); + stats_len += (tx_queues + rx_queues) *FM10K_QUEUE_STATS_LEN ;if (hw->mac.type != fm10k_mac_vf) stats_len +=FM10K_PF_STATS_LEN ;
@@ -252,6 +309,9 @@ static int fm10k_get_sset_count(struct net_device *dev, int sset)if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { stats_len +=FM10K_DEBUG_STATS_LEN ; + stats_len += tx_queues *FM10K_TX_QUEUE_STATS_LEN ; + stats_len += rx_queues *FM10K_RX_QUEUE_STATS_LEN ; +if (iov_data) stats_len +=FM10K_MBX_STATS_LEN * iov_data->num_vfs;
@@ -304,11 +364,10 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev,struct ethtool_stats __always_unused *stats, u64 *data) { - const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64); struct fm10k_intfc *interface = netdev_priv(netdev);struct fm10k_iov_data *iov_data = interface->iov_data;struct net_device_stats *net_stats = &netdev->stats; -int i, j; +int i;fm10k_update_stats (interface);
@@ -345,21 +404,30 @@ static void fm10k_get_ethtool_stats(struct net_device *netdev, } } -for (i =0 ; i < interface->hw.mac.max_queues; i++) { +for (i =0 ; i <fm10k_queues_in_use (interface); i++) {struct fm10k_ring *ring; -u64 *queue_stat; ring = interface->tx_ring[i]; -if (ring) - queue_stat = (u64 *)&ring->stats; -for (j =0 ; j < stat_count; j++) - *(data++) = ring ? queue_stat[j] :0 ; +fm10k_add_ethtool_stats (&data, ring, + fm10k_gstrings_queue_stats, +FM10K_QUEUE_STATS_LEN ); + +if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { +fm10k_add_ethtool_stats (&data, ring, + fm10k_gstrings_tx_queue_stats, +FM10K_TX_QUEUE_STATS_LEN ); + } ring = interface->rx_ring[i]; -if (ring) - queue_stat = (u64 *)&ring->stats; -for (j =0 ; j < stat_count; j++) - *(data++) = ring ? queue_stat[j] :0 ; +fm10k_add_ethtool_stats (&data, ring, + fm10k_gstrings_queue_stats, +FM10K_QUEUE_STATS_LEN ); + +if (interface->flags &FM10K_FLAG_DEBUG_STATS ) { +fm10k_add_ethtool_stats (&data, ring, + fm10k_gstrings_rx_queue_stats, +FM10K_RX_QUEUE_STATS_LEN ); + } } }
Signature · 1 line
2.7.0.236.gda096a0.dirty
Singh
PATCH 2/2 fm10k: use fm10k_stats structures for per-queue statistics
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Friday, February 5, 2016 10:43 AM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 2/2] fm10k: use fm10k_stats structures for per-queue statistics
This will allow us numerous advantages, including
(a) rework the per-queue stats to only display active queues, reducing clutter on the output. This is important since we often don't have all possible queues enabled.
(b) use the new streamlined helper functions, reducing duplicate code and increasing readability of the stats logic
(c) add the additional per-tx and per-rx statistics when debug-statistics is enabled, which may be helpful for future debug work.
The primary motivation for this change is (a), though (b) and (c) are useful additions which were noticed while developing the change.
Note that this code currently assumes we have the same number of Tx and Rx queues which should be true of our driver pretty much always. Even if there are a non equal number of Tx and Rx queues, the only result will be a few extra statistics displaying 0s. This is better than the current setup which shows every disabled queue with all 0s.
---
Allan
PATCH 2/2 fm10k: use fm10k_stats structures for per-queue statistics
Quoted 40 lines
-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Singh, Krishneil K
Sent: Thursday, February 25, 2016 12:33 PM
To: Keller, Jacob E; Intel Wired LAN
Subject: Re: [Intel-wired-lan] [PATCH 2/2] fm10k: usefm10k_statsstructures for per-queue statistics-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Friday, February 5, 2016 10:43 AM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 2/2] fm10k: usefm10k_statsstructures for per-queue statisticsThis will allow us numerous advantages, including
(a) rework the per-queue stats to only display active queues, reducing clutter on the output. This is important since we often don't have all possible queues enabled.
(b) use the new streamlined helper functions, reducing duplicate code and increasing readability of the stats logic
(c) add the additional per-tx and per-rx statistics when debug-statistics is enabled, which may be helpful for future debug work.
The primary motivation for this change is (a), though (b) and (c) are useful additions which were noticed while developing the change.
Note that this code currently assumes we have the same number of Tx and Rx queues which should be true of our driver pretty much always. Even if there are a non equal number of Tx and Rx queues, the only result will be a few extra statistics displaying 0s. This is better than the current setup which shows every disabled queue with all 0s.
Quoted 3 lines
Signed-off-by Jacob Keller <[email protected]>---
Tested-by Krishneil Singh <[email protected]>
This patch unwittingly adds an extraneous/unnecessary blank line after the local variable declarations in fm10k_get_sset_count() - checkpatch should have caught that.
Keller
PATCH 2/2 fm10k: use fm10k_stats structures for per-queue statistics
Quoted 6 lines · Bruce W
This patch unwittingly adds an extraneous/unnecessary blank line after the local
variable declarations infm10k_get_sset_count()- checkpatch should have caught
that.
I can clean that up.
Regards,
Jake
Singh
PATCH 1/2 fm10k: add helper functions to set strings and data for ethtool stats
In reply to Jacob Keller-----Original Message-----
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Jacob Keller
Sent: Friday, February 5, 2016 10:43 AM
To: Intel Wired LAN <[email protected]>
Subject: [Intel-wired-lan] [PATCH 1/2] fm10k: add helper functions to set strings and data for ethtool stats
Reduce duplicate code and the amount of indentation by adding fm10k_add_stat_strings and fm10k_add_ethtool_stats functions which help add fm10k_stat structures to the ethtool stats callbacks. This helps increase ease of use for future stat additions, and increases code readability. Skip handling of the per-queue stats as these will be reworked in a following patch.
---