All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, Thomas Monjalon <thomas.monjalon@6wind.com>,
	Panu Matilainen <pmatilai@redhat.com>,
	Tetsuya Mukawa <mukawa@igel.co.jp>,
	Traynor Kevin <kevin.traynor@intel.com>,
	Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [PATCH 09/16] vhost: add few more functions
Date: Mon,  2 May 2016 15:25:20 -0700	[thread overview]
Message-ID: <1462227927-22853-10-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1462227927-22853-1-git-send-email-yuanhan.liu@linux.intel.com>

Add few more functions to export few more fields or informations of
virtio_net struct, to applications, as we are gonna make them private.
It includes:

- rte_vhost_avail_entries
  It's actually a rename of "rte_vring_available_entries", with the
  "vring" to "vhost" name change to keep the consistency of other
  functions.

- rte_vhost_get_queue_num
  Exports the "virt_qp_nb" field.

- rte_vhost_get_numa_node
  Exports the numa node from where the virtio net device is allocated.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 18 ++++---------
 examples/vhost/main.c             |  4 +--
 lib/librte_vhost/rte_virtio_net.h | 37 +++++++++++++++++++++++++++
 lib/librte_vhost/virtio-net.c     | 54 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+), 15 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 290fd9e..9763cd4 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -33,9 +33,6 @@
 #include <unistd.h>
 #include <pthread.h>
 #include <stdbool.h>
-#ifdef RTE_LIBRTE_VHOST_NUMA
-#include <numaif.h>
-#endif
 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
@@ -228,7 +225,7 @@ new_device(struct virtio_net *dev)
 	struct vhost_queue *vq;
 	unsigned i;
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	int newnode, ret;
+	int newnode;
 #endif
 
 	if (dev == NULL) {
@@ -247,14 +244,9 @@ new_device(struct virtio_net *dev)
 	internal->vid = dev->vid;
 
 #ifdef RTE_LIBRTE_VHOST_NUMA
-	ret  = get_mempolicy(&newnode, NULL, 0, dev,
-			MPOL_F_NODE | MPOL_F_ADDR);
-	if (ret < 0) {
-		RTE_LOG(ERR, PMD, "Unknown numa node\n");
-		return -1;
-	}
-
-	eth_dev->data->numa_node = newnode;
+	newnode = rte_vhost_get_numa_node(dev->vid);
+	if (newnode > 0)
+		eth_dev->data->numa_node = newnode;
 #endif
 
 	for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
@@ -274,7 +266,7 @@ new_device(struct virtio_net *dev)
 		vq->port = eth_dev->data->port_id;
 	}
 
-	for (i = 0; i < dev->virt_qp_nb * VIRTIO_QNUM; i++)
+	for (i = 0; i < rte_vhost_get_queue_num(dev->vid) * VIRTIO_QNUM; i++)
 		rte_vhost_enable_guest_notification(dev, i, 0);
 
 	dev->priv = eth_dev;
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index e395e4a..145fa6f 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1056,13 +1056,13 @@ drain_eth_rx(struct vhost_dev *vdev)
 	 * to diminish packet loss.
 	 */
 	if (enable_retry &&
-	    unlikely(rx_count > rte_vring_available_entries(dev,
+	    unlikely(rx_count > rte_vhost_avail_entries(vdev->vid,
 			VIRTIO_RXQ))) {
 		uint32_t retry;
 
 		for (retry = 0; retry < burst_rx_retry_num; retry++) {
 			rte_delay_us(burst_rx_delay_time);
-			if (rx_count <= rte_vring_available_entries(dev,
+			if (rx_count <= rte_vhost_avail_entries(vdev->vid,
 					VIRTIO_RXQ))
 				break;
 		}
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index bc64e89..27f6847 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -245,6 +245,43 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
 int rte_vhost_driver_session_start(void);
 
 /**
+ * Get how many avail entries are left in the queue @queue_id.
+ *
+ * @param vid
+ *  virtio-net device ID
+ * @param queue_id
+ *  virtio queue index in mq case
+ *
+ * @return
+ *  num of avail entires left
+ */
+uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
+
+/**
+ * Get the number of queues the device supports.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The number of queues, 0 on failure
+ */
+uint32_t rte_vhost_get_queue_num(int vid);
+
+/**
+ * Get the numa node from which the virtio net device's memory
+ * is allocated.
+ *
+ * @param vid
+ *  virtio-net device ID
+ *
+ * @return
+ *  The numa node, -1 on failure
+ */
+int rte_vhost_get_numa_node(int vid);
+
+
+/**
  * This function adds buffers to the virtio devices RX virtqueue. Buffers can
  * be received from the physical port or from another virtual device. A packet
  * count is returned to indicate the number of packets that were succesfully
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index ea28090..6bf4d87 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -753,6 +753,60 @@ int rte_vhost_feature_disable(uint64_t feature_mask)
 	return 0;
 }
 
+uint16_t
+rte_vhost_avail_entries(int vid, uint16_t queue_id)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
+	vq = dev->virtqueue[queue_id];
+	if (!vq->enabled)
+		return 0;
+
+	return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res;
+}
+
+uint32_t
+rte_vhost_get_queue_num(int vid)
+{
+	struct virtio_net *dev = get_device(vid);
+
+	if (dev == NULL)
+		return 0;
+
+	return dev->virt_qp_nb;
+}
+
+int
+rte_vhost_get_numa_node(int vid)
+{
+#ifdef RTE_LIBRTE_VHOST_NUMA
+	struct virtio_net *dev = get_device(vid);
+	int numa_node;
+	int ret;
+
+	if (dev == NULL)
+		return -1;
+
+	ret = get_mempolicy(&numa_node, NULL, 0, dev,
+			MPOL_F_NODE | MPOL_F_ADDR);
+	if (ret < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"(%d) failed to query numa node: %d\n", vid, ret);
+		return -1;
+	}
+
+	return numa_node;
+#else
+	RTE_SET_USED(vid);
+	return -1;
+#endif
+}
+
 int rte_vhost_feature_enable(uint64_t feature_mask)
 {
 	if ((feature_mask & VHOST_SUPPORTED_FEATURES) == feature_mask) {
-- 
1.9.0

  parent reply	other threads:[~2016-05-02 22:22 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-02 22:25 [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
2016-05-02 22:25 ` [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
2016-05-02 22:25 ` [PATCH 02/16] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-02 22:25 ` [PATCH 03/16] vhost: declare device_fh as int Yuanhan Liu
2016-05-02 22:25 ` [PATCH 04/16] example/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-02 22:25 ` [PATCH 05/16] vhost: rename device_fh to vid Yuanhan Liu
2016-05-02 22:25 ` [PATCH 06/16] vhost: get device by vid only Yuanhan Liu
2016-05-02 22:25 ` [PATCH 07/16] vhost: move vhost_device_ctx to cuse Yuanhan Liu
2016-05-02 22:25 ` [PATCH 08/16] vhost: query pmd internal by vid Yuanhan Liu
2016-05-02 22:25 ` Yuanhan Liu [this message]
2016-05-02 22:25 ` [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-10 16:17   ` Rich Lane
2016-05-10 16:39     ` Yuanhan Liu
2016-05-10 17:13       ` Rich Lane
2016-05-10 17:29         ` Yuanhan Liu
2016-05-10 19:22           ` Thomas Monjalon
2016-05-02 22:25 ` [PATCH 11/16] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-02 22:25 ` [PATCH 12/16] vhost: remove unnecessary fields Yuanhan Liu
2016-05-02 22:25 ` [PATCH 13/16] vhost: remove virtio-net.h Yuanhan Liu
2016-05-02 22:25 ` [PATCH 14/16] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-02 22:25 ` [PATCH 15/16] vhost: per device vhost_hlen Yuanhan Liu
2016-05-02 22:25 ` [PATCH 16/16] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-13  5:24 ` [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 02/19] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 03/19] vhost: declare device fh as int Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 04/19] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 05/19] vhost: rename device fh to vid Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 06/19] vhost: get device by vid only Yuanhan Liu
2016-05-13  5:24   ` [PATCH v2 07/19] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 08/19] vhost: introduce new API to export numa node Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 09/19] vhost: introduce new API to export number of queues Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 10/19] vhost: introduce new API to export ifname Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 11/19] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 12/19] vhost: remove dependency on priv field Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 13/19] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 14/19] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 15/19] vhost: remove unnecessary fields Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 16/19] vhost: remove virtio-net.h Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 17/19] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 18/19] vhost: per device virtio net header len Yuanhan Liu
2016-05-13  5:25   ` [PATCH v2 19/19] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-26 17:04   ` [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
2016-05-27  1:36     ` Yuanhan Liu
2016-06-07  3:51   ` [PATCH v3 00/20] " Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 02/20] vhost: set/reset dev flags internally Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 03/20] vhost: declare device fh as int Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 04/20] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 05/20] vhost: rename device fh to vid Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 06/20] vhost: get device by vid only Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 07/20] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
2016-06-07 11:42       ` Panu Matilainen
2016-06-07 12:45         ` Yuanhan Liu
2016-06-08 21:51       ` Rich Lane
2016-06-09  4:45         ` Yuanhan Liu
2016-06-13 10:05           ` Yuanhan Liu
2016-06-07  3:51     ` [PATCH v3 09/20] vhost: introduce new API to export number of queues Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 10/20] vhost: introduce new API to export ifname Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 11/20] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 12/20] vhost: remove dependency on priv field Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 13/20] vhost: export vid as the only interface to applications Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 14/20] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 15/20] vhost: remove unnecessary fields Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 16/20] vhost: remove virtio-net.h Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 17/20] vhost: reserve few more space for future extension Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 19/20] vhost: per device virtio net header len Yuanhan Liu
2016-06-07  3:52     ` [PATCH v3 20/20] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-06-14 12:00     ` [PATCH v3 00/20] vhost ABI/API refactoring Yuanhan Liu
2016-06-30  7:39     ` Panu Matilainen
2016-06-30  7:57       ` Yuanhan Liu
2016-06-30  9:05         ` Panu Matilainen
2016-06-30 11:15           ` Mcnamara, John
2016-06-30 11:40             ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462227927-22853-10-git-send-email-yuanhan.liu@linux.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=dev@dpdk.org \
    --cc=huawei.xie@intel.com \
    --cc=kevin.traynor@intel.com \
    --cc=mukawa@igel.co.jp \
    --cc=pmatilai@redhat.com \
    --cc=thomas.monjalon@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.