DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, jfreimann@redhat.com, tiwei.bie@intel.com,
	zhihong.wang@intel.com, jasowang@redhat.com, mst@redhat.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [dpdk-dev] [PATCH v3 1/2] vhost: add packed ring support to vring base requests
Date: Thu, 18 Oct 2018 11:41:49 +0200	[thread overview]
Message-ID: <20181018094150.11219-2-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20181018094150.11219-1-maxime.coquelin@redhat.com>

For packed ring layout, we need save and restore avail and
used indexes, and their wrap counter values.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/vhost_user.c | 41 ++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 508228a3c..ff80bef8e 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -696,10 +696,24 @@ vhost_user_set_vring_base(struct virtio_net **pdev,
 			int main_fd __rte_unused)
 {
 	struct virtio_net *dev = *pdev;
-	dev->virtqueue[msg->payload.state.index]->last_used_idx  =
-			msg->payload.state.num;
-	dev->virtqueue[msg->payload.state.index]->last_avail_idx =
-			msg->payload.state.num;
+	struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
+	uint64_t val = msg->payload.state.num;
+
+	if (vq_is_packed(dev)) {
+		/*
+		 * Bit[0:14]: avail index
+		 * Bit[15]: avail wrap counter
+		 * Bit[16:30]: used index
+		 * Bit[31]: used wrap counter
+		 */
+		vq->last_avail_idx = val & 0x7fff;
+		vq->avail_wrap_counter = (val & (0x1 << 15)) >> 15;
+		vq->last_used_idx = (val & (0x7fff << 16)) >> 16;
+		vq->used_wrap_counter = (val & (0x1 << 31)) >> 31;
+	} else {
+		vq->last_used_idx = msg->payload.state.num;
+		vq->last_avail_idx = msg->payload.state.num;
+	}
 
 	return VH_RESULT_OK;
 }
@@ -1208,6 +1222,7 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 {
 	struct virtio_net *dev = *pdev;
 	struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
+	uint64_t val;
 
 	/* We have to stop the queue (virtio) if it is running. */
 	vhost_destroy_device_notify(dev);
@@ -1215,8 +1230,22 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 	dev->flags &= ~VIRTIO_DEV_READY;
 	dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED;
 
-	/* Here we are safe to get the last avail index */
-	msg->payload.state.num = vq->last_avail_idx;
+	/* Here we are safe to get the indexes */
+	if (vq_is_packed(dev)) {
+		/*
+		 * Bit[0:14]: avail index
+		 * Bit[15]: avail wrap counter
+		 * Bit[16:30]: used index
+		 * Bit[31]: used wrap counter
+		 */
+		val = vq->last_avail_idx & 0x7fff;
+		val |= vq->avail_wrap_counter << 15;
+		val |= (vq->last_used_idx & 0x7fff) << 16;
+		val |= vq->used_wrap_counter << 31;
+		msg->payload.state.num = val;
+	} else {
+		msg->payload.state.num = vq->last_avail_idx;
+	}
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring base idx:%d file:%d\n", msg->payload.state.index,
-- 
2.17.1

  reply	other threads:[~2018-10-18  9:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-18  9:41 [dpdk-dev] [PATCH v3 0/2] vhost: packed ring support completion Maxime Coquelin
2018-10-18  9:41 ` Maxime Coquelin [this message]
2018-10-18  9:41 ` [dpdk-dev] [PATCH v3 2/2] vhost: advertize packed ring layout support Maxime Coquelin

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=20181018094150.11219-2-maxime.coquelin@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jasowang@redhat.com \
    --cc=jfreimann@redhat.com \
    --cc=mst@redhat.com \
    --cc=tiwei.bie@intel.com \
    --cc=zhihong.wang@intel.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 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).