* [dpdk-dev] [PATCH] net/i40e: fix corruption of VF stats via port representor
@ 2018-05-18 7:59 Remy Horton
2018-05-18 11:48 ` Remy Horton
2018-05-18 11:49 ` [dpdk-dev] [PATCH v2] i40e: " Remy Horton
0 siblings, 2 replies; 5+ messages in thread
From: Remy Horton @ 2018-05-18 7:59 UTC (permalink / raw)
To: dev; +Cc: Ferruh Yigit, Qi Zhang, Beilei Xing
The resetting of stats on a VF involves the setting of an offset
that is subtracted from future calls, rather zeroing of counters.
However doing a stats reset on the port representor was also
adjusting the values forwarded to the VF, which had the effect of
corrupting the VF's counters. The fix is for the port representor
to maintain its own stats offset, so the port representor and VF
maintain independently-resettable counters
Signed-off-by: Remy Horton <remy.horton@intel.com>
---
drivers/net/i40e/i40e_ethdev.h | 2 +
drivers/net/i40e/i40e_vf_representor.c | 119 +++++++++++++++++++++++++++++++--
2 files changed, 117 insertions(+), 4 deletions(-)
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index 55c8875..11c4c76 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -1083,6 +1083,8 @@ struct i40e_vf_representor {
/**< Virtual Function ID */
struct i40e_adapter *adapter;
/**< Private data store of assocaiated physical function */
+ struct i40e_eth_stats stats_offset;
+ /**< Zero-point of VF statistics*/
};
extern const struct rte_flow_ops i40e_flow_ops;
diff --git a/drivers/net/i40e/i40e_vf_representor.c b/drivers/net/i40e/i40e_vf_representor.c
index 6026ec9..8dc94b4 100644
--- a/drivers/net/i40e/i40e_vf_representor.c
+++ b/drivers/net/i40e/i40e_vf_representor.c
@@ -139,15 +139,126 @@ i40e_vf_representor_tx_queue_setup(__rte_unused struct rte_eth_dev *dev,
return 0;
}
+static void
+i40evf_stat_update_48(uint64_t *offset,
+ uint64_t *stat)
+{
+ if (*stat >= *offset)
+ *stat = *stat - *offset;
+ else
+ *stat = (uint64_t)((*stat +
+ ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
+
+ *stat &= I40E_48_BIT_MASK;
+}
+
+static void
+i40evf_stat_update_32(uint64_t *offset,
+ uint64_t *stat)
+{
+ if (*stat >= *offset)
+ *stat = (uint64_t)(*stat - *offset);
+ else
+ *stat = (uint64_t)((*stat +
+ ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
+}
+
+static int
+rte_pmd_i40e_get_vf_native_stats(uint16_t port,
+ uint16_t vf_id,
+ struct i40e_eth_stats *stats)
+{
+ struct rte_eth_dev *dev;
+ struct i40e_pf *pf;
+ struct i40e_vsi *vsi;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+ dev = &rte_eth_devices[port];
+
+ if (!is_i40e_supported(dev))
+ return -ENOTSUP;
+
+ pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+ if (vf_id >= pf->vf_num || !pf->vfs) {
+ PMD_DRV_LOG(ERR, "Invalid VF ID.");
+ return -EINVAL;
+ }
+
+ vsi = pf->vfs[vf_id].vsi;
+ if (!vsi) {
+ PMD_DRV_LOG(ERR, "Invalid VSI.");
+ return -EINVAL;
+ }
+
+ i40e_update_vsi_stats(vsi);
+ memcpy(stats, &vsi->eth_stats, sizeof(vsi->eth_stats));
+
+ return 0;
+}
+
static int
i40e_vf_representor_stats_get(struct rte_eth_dev *ethdev,
struct rte_eth_stats *stats)
{
struct i40e_vf_representor *representor = ethdev->data->dev_private;
+ struct i40e_eth_stats native_stats;
+ int ret;
- return rte_pmd_i40e_get_vf_stats(
+ ret = rte_pmd_i40e_get_vf_native_stats(
representor->adapter->eth_dev->data->port_id,
- representor->vf_id, stats);
+ representor->vf_id, &native_stats);
+ if (ret == 0) {
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_bytes,
+ &native_stats.rx_bytes);
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_unicast,
+ &native_stats.rx_unicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_multicast,
+ &native_stats.rx_multicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_broadcast,
+ &native_stats.rx_broadcast);
+ i40evf_stat_update_32(
+ &representor->stats_offset.rx_discards,
+ &native_stats.rx_discards);
+ i40evf_stat_update_32(
+ &representor->stats_offset.rx_unknown_protocol,
+ &native_stats.rx_unknown_protocol);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_bytes,
+ &native_stats.tx_bytes);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_unicast,
+ &native_stats.tx_unicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_multicast,
+ &native_stats.tx_multicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_broadcast,
+ &native_stats.tx_broadcast);
+ i40evf_stat_update_32(
+ &representor->stats_offset.tx_errors,
+ &native_stats.tx_errors);
+ i40evf_stat_update_32(
+ &representor->stats_offset.tx_discards,
+ &native_stats.tx_discards);
+
+ stats->ipackets = native_stats.rx_unicast +
+ native_stats.rx_multicast +
+ native_stats.rx_broadcast;
+ stats->opackets = native_stats.tx_unicast +
+ native_stats.tx_multicast +
+ native_stats.tx_broadcast;
+ stats->ibytes = native_stats.rx_bytes;
+ stats->obytes = native_stats.tx_bytes;
+ stats->ierrors = native_stats.rx_discards;
+ stats->oerrors = native_stats.tx_errors + native_stats.tx_discards;
+ }
+ return ret;
}
static void
@@ -155,9 +266,9 @@ i40e_vf_representor_stats_reset(struct rte_eth_dev *ethdev)
{
struct i40e_vf_representor *representor = ethdev->data->dev_private;
- rte_pmd_i40e_reset_vf_stats(
+ rte_pmd_i40e_get_vf_native_stats(
representor->adapter->eth_dev->data->port_id,
- representor->vf_id);
+ representor->vf_id, &representor->stats_offset);
}
static void
--
2.9.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH] net/i40e: fix corruption of VF stats via port representor
2018-05-18 7:59 [dpdk-dev] [PATCH] net/i40e: fix corruption of VF stats via port representor Remy Horton
@ 2018-05-18 11:48 ` Remy Horton
2018-05-18 11:49 ` [dpdk-dev] [PATCH v2] i40e: " Remy Horton
1 sibling, 0 replies; 5+ messages in thread
From: Remy Horton @ 2018-05-18 11:48 UTC (permalink / raw)
To: dev; +Cc: Ferruh Yigit, Qi Zhang, Beilei Xing
Missing fixline, so v2 coming..
On 18/05/2018 08:59, Remy Horton wrote:
> The resetting of stats on a VF involves the setting of an offset
> that is subtracted from future calls, rather zeroing of counters.
> However doing a stats reset on the port representor was also
> adjusting the values forwarded to the VF, which had the effect of
> corrupting the VF's counters. The fix is for the port representor
> to maintain its own stats offset, so the port representor and VF
> maintain independently-resettable counters
>
> Signed-off-by: Remy Horton <remy.horton@intel.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [PATCH v2] i40e: fix corruption of VF stats via port representor
2018-05-18 7:59 [dpdk-dev] [PATCH] net/i40e: fix corruption of VF stats via port representor Remy Horton
2018-05-18 11:48 ` Remy Horton
@ 2018-05-18 11:49 ` Remy Horton
2018-05-19 2:17 ` Zhang, Qi Z
1 sibling, 1 reply; 5+ messages in thread
From: Remy Horton @ 2018-05-18 11:49 UTC (permalink / raw)
To: dev; +Cc: Ferruh Yigit, Qi Zhang, Beilei Xing, Helin Zhang, Jingjing Wu
The resetting of stats on a VF involves the setting of an offset
that is subtracted from future calls, rather zeroing of counters.
However doing a stats reset on the port representor was also
adjusting the values forwarded to the VF, which had the effect of
corrupting the VF's counters. The fix is for the port representor
to maintain its own stats offset, so the port representor and VF
maintain independently-resettable counters.
Fixes: e0cb96204b71 ("net/i40e: add support for representor ports")
Signed-off-by: Remy Horton <remy.horton@intel.com>
---
drivers/net/i40e/i40e_ethdev.h | 2 +
drivers/net/i40e/i40e_vf_representor.c | 119 +++++++++++++++++++++++++++++++--
2 files changed, 117 insertions(+), 4 deletions(-)
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index 55c8875..11c4c76 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -1083,6 +1083,8 @@ struct i40e_vf_representor {
/**< Virtual Function ID */
struct i40e_adapter *adapter;
/**< Private data store of assocaiated physical function */
+ struct i40e_eth_stats stats_offset;
+ /**< Zero-point of VF statistics*/
};
extern const struct rte_flow_ops i40e_flow_ops;
diff --git a/drivers/net/i40e/i40e_vf_representor.c b/drivers/net/i40e/i40e_vf_representor.c
index 6026ec9..8dc94b4 100644
--- a/drivers/net/i40e/i40e_vf_representor.c
+++ b/drivers/net/i40e/i40e_vf_representor.c
@@ -139,15 +139,126 @@ i40e_vf_representor_tx_queue_setup(__rte_unused struct rte_eth_dev *dev,
return 0;
}
+static void
+i40evf_stat_update_48(uint64_t *offset,
+ uint64_t *stat)
+{
+ if (*stat >= *offset)
+ *stat = *stat - *offset;
+ else
+ *stat = (uint64_t)((*stat +
+ ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
+
+ *stat &= I40E_48_BIT_MASK;
+}
+
+static void
+i40evf_stat_update_32(uint64_t *offset,
+ uint64_t *stat)
+{
+ if (*stat >= *offset)
+ *stat = (uint64_t)(*stat - *offset);
+ else
+ *stat = (uint64_t)((*stat +
+ ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
+}
+
+static int
+rte_pmd_i40e_get_vf_native_stats(uint16_t port,
+ uint16_t vf_id,
+ struct i40e_eth_stats *stats)
+{
+ struct rte_eth_dev *dev;
+ struct i40e_pf *pf;
+ struct i40e_vsi *vsi;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+ dev = &rte_eth_devices[port];
+
+ if (!is_i40e_supported(dev))
+ return -ENOTSUP;
+
+ pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+ if (vf_id >= pf->vf_num || !pf->vfs) {
+ PMD_DRV_LOG(ERR, "Invalid VF ID.");
+ return -EINVAL;
+ }
+
+ vsi = pf->vfs[vf_id].vsi;
+ if (!vsi) {
+ PMD_DRV_LOG(ERR, "Invalid VSI.");
+ return -EINVAL;
+ }
+
+ i40e_update_vsi_stats(vsi);
+ memcpy(stats, &vsi->eth_stats, sizeof(vsi->eth_stats));
+
+ return 0;
+}
+
static int
i40e_vf_representor_stats_get(struct rte_eth_dev *ethdev,
struct rte_eth_stats *stats)
{
struct i40e_vf_representor *representor = ethdev->data->dev_private;
+ struct i40e_eth_stats native_stats;
+ int ret;
- return rte_pmd_i40e_get_vf_stats(
+ ret = rte_pmd_i40e_get_vf_native_stats(
representor->adapter->eth_dev->data->port_id,
- representor->vf_id, stats);
+ representor->vf_id, &native_stats);
+ if (ret == 0) {
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_bytes,
+ &native_stats.rx_bytes);
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_unicast,
+ &native_stats.rx_unicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_multicast,
+ &native_stats.rx_multicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.rx_broadcast,
+ &native_stats.rx_broadcast);
+ i40evf_stat_update_32(
+ &representor->stats_offset.rx_discards,
+ &native_stats.rx_discards);
+ i40evf_stat_update_32(
+ &representor->stats_offset.rx_unknown_protocol,
+ &native_stats.rx_unknown_protocol);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_bytes,
+ &native_stats.tx_bytes);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_unicast,
+ &native_stats.tx_unicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_multicast,
+ &native_stats.tx_multicast);
+ i40evf_stat_update_48(
+ &representor->stats_offset.tx_broadcast,
+ &native_stats.tx_broadcast);
+ i40evf_stat_update_32(
+ &representor->stats_offset.tx_errors,
+ &native_stats.tx_errors);
+ i40evf_stat_update_32(
+ &representor->stats_offset.tx_discards,
+ &native_stats.tx_discards);
+
+ stats->ipackets = native_stats.rx_unicast +
+ native_stats.rx_multicast +
+ native_stats.rx_broadcast;
+ stats->opackets = native_stats.tx_unicast +
+ native_stats.tx_multicast +
+ native_stats.tx_broadcast;
+ stats->ibytes = native_stats.rx_bytes;
+ stats->obytes = native_stats.tx_bytes;
+ stats->ierrors = native_stats.rx_discards;
+ stats->oerrors = native_stats.tx_errors + native_stats.tx_discards;
+ }
+ return ret;
}
static void
@@ -155,9 +266,9 @@ i40e_vf_representor_stats_reset(struct rte_eth_dev *ethdev)
{
struct i40e_vf_representor *representor = ethdev->data->dev_private;
- rte_pmd_i40e_reset_vf_stats(
+ rte_pmd_i40e_get_vf_native_stats(
representor->adapter->eth_dev->data->port_id,
- representor->vf_id);
+ representor->vf_id, &representor->stats_offset);
}
static void
--
2.9.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH v2] i40e: fix corruption of VF stats via port representor
2018-05-18 11:49 ` [dpdk-dev] [PATCH v2] i40e: " Remy Horton
@ 2018-05-19 2:17 ` Zhang, Qi Z
2018-05-21 1:17 ` Zhang, Helin
0 siblings, 1 reply; 5+ messages in thread
From: Zhang, Qi Z @ 2018-05-19 2:17 UTC (permalink / raw)
To: Horton, Remy, dev; +Cc: Yigit, Ferruh, Xing, Beilei, Zhang, Helin, Wu, Jingjing
> -----Original Message-----
> From: Horton, Remy
> Sent: Friday, May 18, 2018 7:50 PM
> To: dev@dpdk.org
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>;
> Xing, Beilei <beilei.xing@intel.com>; Zhang, Helin <helin.zhang@intel.com>;
> Wu, Jingjing <jingjing.wu@intel.com>
> Subject: [PATCH v2] i40e: fix corruption of VF stats via port representor
>
> The resetting of stats on a VF involves the setting of an offset that is subtracted
> from future calls, rather zeroing of counters.
> However doing a stats reset on the port representor was also adjusting the
> values forwarded to the VF, which had the effect of corrupting the VF's
> counters. The fix is for the port representor to maintain its own stats offset, so
> the port representor and VF maintain independently-resettable counters.
>
> Fixes: e0cb96204b71 ("net/i40e: add support for representor ports")
>
> Signed-off-by: Remy Horton <remy.horton@intel.com>
Title prefix should be "net/i40e", could be fix during apply
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH v2] i40e: fix corruption of VF stats via port representor
2018-05-19 2:17 ` Zhang, Qi Z
@ 2018-05-21 1:17 ` Zhang, Helin
0 siblings, 0 replies; 5+ messages in thread
From: Zhang, Helin @ 2018-05-21 1:17 UTC (permalink / raw)
To: Zhang, Qi Z, Horton, Remy, dev; +Cc: Yigit, Ferruh, Xing, Beilei, Wu, Jingjing
> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Saturday, May 19, 2018 10:18 AM
> To: Horton, Remy; dev@dpdk.org
> Cc: Yigit, Ferruh; Xing, Beilei; Zhang, Helin; Wu, Jingjing
> Subject: RE: [PATCH v2] i40e: fix corruption of VF stats via port representor
>
>
>
> > -----Original Message-----
> > From: Horton, Remy
> > Sent: Friday, May 18, 2018 7:50 PM
> > To: dev@dpdk.org
> > Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; Zhang, Qi Z
> > <qi.z.zhang@intel.com>; Xing, Beilei <beilei.xing@intel.com>; Zhang,
> > Helin <helin.zhang@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>
> > Subject: [PATCH v2] i40e: fix corruption of VF stats via port
> > representor
> >
> > The resetting of stats on a VF involves the setting of an offset that
> > is subtracted from future calls, rather zeroing of counters.
> > However doing a stats reset on the port representor was also adjusting
> > the values forwarded to the VF, which had the effect of corrupting the
> > VF's counters. The fix is for the port representor to maintain its own
> > stats offset, so the port representor and VF maintain independently-
> resettable counters.
> >
> > Fixes: e0cb96204b71 ("net/i40e: add support for representor ports")
> >
> > Signed-off-by: Remy Horton <remy.horton@intel.com>
>
> Title prefix should be "net/i40e", could be fix during apply
>
> Acked-by: Qi Zhang <qi.z.zhang@intel.com>
Applied to dpdk-next-net-intel, thanks!
/Helin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-05-21 1:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 7:59 [dpdk-dev] [PATCH] net/i40e: fix corruption of VF stats via port representor Remy Horton
2018-05-18 11:48 ` Remy Horton
2018-05-18 11:49 ` [dpdk-dev] [PATCH v2] i40e: " Remy Horton
2018-05-19 2:17 ` Zhang, Qi Z
2018-05-21 1:17 ` Zhang, Helin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).