[dpdk-dev] [PATCH v2 09/32] rte: add APIs for VF stats get/reset

Wenzhuo Lu wenzhuo.lu at intel.com
Wed Dec 7 04:31:52 CET 2016


This patch add below two APIs so that VF statistics
can be get/clear from PF side.
rte_eth_vf_stats_get.
rte_eth_vf_stats_reset.

Signed-off-by: Qi Zhang <qi.z.zhang at intel.com>
---
 lib/librte_ether/rte_ethdev.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h | 47 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index fde8112..03b4edf 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3270,3 +3270,50 @@ int rte_eth_dev_bypass_init(uint8_t port_id)
 				-ENOTSUP);
 	return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
 }
+
+int
+rte_eth_vf_stats_get(uint8_t port_id,
+		     uint16_t vf,
+		     struct rte_eth_stats *stats)
+{
+	struct rte_eth_dev *dev;
+	struct rte_eth_dev_info dev_info;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+	dev = &rte_eth_devices[port_id];
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vf_stats_get, -ENOTSUP);
+
+	if (vf >= dev_info.max_vfs) {
+		RTE_PMD_DEBUG_TRACE("Get VF Stats:port %d: "
+				"invalid vf id=%d\n", port_id, vf);
+		return -EINVAL;
+	}
+
+	return (*dev->dev_ops->vf_stats_get)(dev, vf, stats);
+}
+
+int
+rte_eth_vf_stats_reset(uint8_t port_id,
+		       uint16_t vf)
+{
+	struct rte_eth_dev *dev;
+	struct rte_eth_dev_info dev_info;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+	dev = &rte_eth_devices[port_id];
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vf_stats_reset, -ENOTSUP);
+
+	if (vf >= dev_info.max_vfs) {
+		RTE_PMD_DEBUG_TRACE("Reset VF Stats:port %d: "
+				"invalid vf id=%d\n", port_id, vf);
+		return -EINVAL;
+	}
+
+	return (*dev->dev_ops->vf_stats_reset)(dev, vf);
+}
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 9678179..8b564ee 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1271,6 +1271,15 @@ typedef int (*eth_set_vf_vlan_filter_t)(struct rte_eth_dev *dev,
 				  uint8_t vlan_on);
 /**< @internal Set VF VLAN pool filter */
 
+typedef int (*eth_vf_stats_get)(struct rte_eth_dev *dev,
+				uint16_t vf,
+				struct rte_eth_stats *stats);
+/**< @internal Get VF statistics */
+
+typedef int (*eth_vf_stats_reset)(struct rte_eth_dev *dev,
+				  uint16_t vf);
+/**< @internal Clear VF statistics */
+
 typedef int (*eth_set_queue_rate_limit_t)(struct rte_eth_dev *dev,
 				uint16_t queue_idx,
 				uint16_t tx_rate);
@@ -1483,6 +1492,8 @@ struct eth_dev_ops {
 	eth_set_vf_rx_t            set_vf_rx;  /**< enable/disable a VF receive */
 	eth_set_vf_tx_t            set_vf_tx;  /**< enable/disable a VF transmit */
 	eth_set_vf_vlan_filter_t   set_vf_vlan_filter;  /**< Set VF VLAN filter */
+	eth_vf_stats_get           vf_stats_get; /**< Get VF's statistics */
+	eth_vf_stats_reset         vf_stats_reset; /**< Reset VF's statistics */
 	/** Add UDP tunnel port. */
 	eth_udp_tunnel_port_add_t udp_tunnel_port_add;
 	/** Del UDP tunnel port. */
@@ -4379,6 +4390,42 @@ int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
  */
 int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
 
+/**
+ * Get VF's statistics
+ *
+ * @param port_id
+ *   pointer to port identifier of the device
+ * @param vf
+ *   VF id
+ * @param stats
+ *   A pointer to a structure of type *rte_eth_stats* to be filled with
+ *   the values of device counters for the following set of statistics:
+ *   - *ipackets* with the total of successfully received packets.
+ *   - *opackets* with the total of successfully transmitted packets.
+ *   - *ibytes*   with the total of successfully received bytes.
+ *   - *obytes*   with the total of successfully transmitted bytes.
+ *   - *ierrors*  with the total of erroneous received packets.
+ *   - *oerrors*  with the total of failed transmitted packets.
+ * @return
+ *   Zero if successful. Non-zero otherwise.
+ */
+int rte_eth_vf_stats_get(uint8_t port_id,
+			 uint16_t vf,
+			 struct rte_eth_stats *stats);
+
+/**
+ * Clear VF's statistics
+ *
+ * @param port_id
+ *   pointer to port identifier of the device
+ * @param vf
+ *   vf id
+ * @return
+ *   Zero if successful. Non-zero otherwise.
+ */
+int rte_eth_vf_stats_reset(uint8_t port_id,
+			   uint16_t vf);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.9.3



More information about the dev mailing list