* [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user @ 2016-05-05 8:59 Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan ` (4 more replies) 0 siblings, 5 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-05-05 8:59 UTC (permalink / raw) To: dev; +Cc: Jianfeng Tan, yuanhan.liu, nakajima.yoshihiro, nhorman This patch set depends on below patch sets: - http://dpdk.org/ml/archives/dev/2016-April/038111.html - http://dpdk.org/ml/archives/dev/2016-April/038118.html - http://dpdk.org/ml/archives/dev/2016-April/038121.html Add multi queue support for virtio-user virtual port. Patch 1 adds vhost user adapter communications for enable/disable queues. Patch 2 adds features check for multi queue and provides a method for virtio-user driver to enable/disable queues. Patch 3 partially implements ctrl-q to handle VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command from PMD. Test case: 1. start testpmd with a vhost-user port: $ TESTPMD -c 0x7 -n 4 --socket-mem 1024,0 --no-pci \ --vdev 'eth_vhost0,iface=/tmp/sock0,queues=2' \ -- -i --rxq=2 --txq=2 --nb-cores=2 2. start testpmd with a virtio-user port: $ TESTPMD -c 0x70 -n 4 --socket-mem 1024,0 --no-pci --file-prefix=testpmd \ --vdev=virtio-user0,mac=00:01:02:03:04:05,path=/tmp/sock0,queues=2 \ -- -i --rxq=2 --txq=2 --nb-cores=2 --txqflags=0xf01 --disable-hw-vlan 3. use below commands to see if all queues are working: testpmd> show port xstats all Jianfeng Tan (3): virtio-user: add mq in vhost user adapter virtio-user: add mq in device emulation virtio-user: add mq in virtual pci driver drivers/net/virtio/virtio_user/vhost.h | 4 ++ drivers/net/virtio/virtio_user/vhost_user.c | 21 ++++++ drivers/net/virtio/virtio_user/virtio_user_dev.c | 65 ++++++++++++++--- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 + drivers/net/virtio/virtio_user/virtio_user_pci.c | 89 +++++++++++++++++++++++- 5 files changed, 170 insertions(+), 11 deletions(-) -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH 1/3] virtio-user: add mq in vhost user adapter 2016-05-05 8:59 [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user Jianfeng Tan @ 2016-05-05 8:59 ` Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 2/3] virtio-user: add mq in device emulation Jianfeng Tan ` (3 subsequent siblings) 4 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-05-05 8:59 UTC (permalink / raw) To: dev; +Cc: Jianfeng Tan, yuanhan.liu, nakajima.yoshihiro, nhorman This patch mainly adds method in vhost user adapter to communicate enable/disable queues messages with vhost user backend. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/vhost.h | 4 ++++ drivers/net/virtio/virtio_user/vhost_user.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h index 5cd3543..fe236a7 100644 --- a/drivers/net/virtio/virtio_user/vhost.h +++ b/drivers/net/virtio/virtio_user/vhost.h @@ -209,8 +209,12 @@ enum { #define VHOST_KERNEL 0 #define VHOST_USER 1 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_MQ (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) + int vhost_user_sock(int vhostfd, unsigned long int req, void *arg); int vhost_user_setup(const char *path); +int vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable); int vhost_kernel_ioctl(int vhostfd, unsigned long int req, void *arg); int vhost_kernel_setup(const char *path, const char *ifname, int *p_tapfd); diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 6fd648c..d8f7996 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -263,6 +263,7 @@ vhost_user_sock(int vhostfd, unsigned long int req, void *arg) case VHOST_USER_SET_VRING_NUM: case VHOST_USER_SET_VRING_BASE: + case VHOST_USER_SET_VRING_ENABLE: memcpy(&msg.payload.state, arg, sizeof(msg.payload.state)); msg.size = sizeof(m.payload.state); break; @@ -373,3 +374,23 @@ vhost_user_setup(const char *path) return fd; } + +int +vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable) +{ + int i; + + for (i = 0; i < 2; ++i) { + struct vhost_vring_state state = { + .index = pair_idx * 2 + i, + .num = enable, + }; + + if (vhost_user_sock(vhostfd, + VHOST_USER_SET_VRING_ENABLE, &state)) + return -1; + } + + return 0; + +} -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH 2/3] virtio-user: add mq in device emulation 2016-05-05 8:59 [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan @ 2016-05-05 8:59 ` Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 3/3] virtio-user: add mq in virtual pci driver Jianfeng Tan ` (2 subsequent siblings) 4 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-05-05 8:59 UTC (permalink / raw) To: dev; +Cc: Jianfeng Tan, yuanhan.liu, nakajima.yoshihiro, nhorman Multi-queue requires VIRTIO_NET_F_MQ and VIRTIO_NET_F_CTRL_VQ in feature negotiation. Mainly two changes in virtio-user device emulation layer. - Multi-queue requires ctrl-queue. So ctrl-queue will by enabled automatically when multi-queue is specified. - Provide a method virtio_user_enable_queue_pair() for virtio-user driver to enable/disable queues. Note: Do not support multiple queue for vhost kernel backend. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 65 ++++++++++++++++++++---- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 + 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index a8e58c0..ea0d4c4 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -136,11 +136,14 @@ virtio_user_start_device(struct virtio_user_hw *hw) } } - /* After setup all virtqueues, we need to set_features so that - * these features can be set into each virtqueue in vhost side. - * And before that, make sure VIRTIO_NET_F_MAC is stripped. + /* After setup all virtqueues, we need to set_features so that these + * features can be set into each virtqueue in vhost side. And before + * that, make sure VHOST_USER_F_PROTOCOL_FEATURES is added if mq is + * enabled, and VIRTIO_NET_F_MAC is stripped. */ features = hw->features; + if (hw->type == VHOST_USER && hw->max_queue_pairs > 1) + features |= VHOST_USER_MQ; features &= ~(1ull << VIRTIO_NET_F_MAC); ret = vhost_call(hw->vhostfd, hw->type, VHOST_MSG_SET_FEATURES, &features); @@ -161,6 +164,18 @@ error: return -1; } +int +virtio_user_enable_queue_pair(struct virtio_user_hw *hw, + unsigned pair_idx, int enable) +{ + int r = -1; + + if (hw->type == VHOST_USER) + r = vhost_user_enable_queue_pair(hw->vhostfd, pair_idx, enable); + + return r; +} + int virtio_user_stop_device(struct virtio_user_hw *hw) { return vhost_call(hw->vhostfd, hw->type, VHOST_MSG_RESET_OWNER, NULL); @@ -188,7 +203,7 @@ static inline void parse_mac(struct virtio_user_hw *hw, const char *mac) static int virtio_vdev_init(struct rte_eth_dev_data *data, char *path, - int queues, int nb_cq __rte_unused, + int queues, int enable_ctrl_q, int queue_size, const char *mac, char *ifname) { struct stat s; @@ -204,8 +219,6 @@ virtio_vdev_init(struct rte_eth_dev_data *data, char *path, uhw->vhostfd = -1; uhw->tapfd = -1; - /* TODO: cq */ - if (stat(uhw->path, &s) < 0) { PMD_INIT_LOG(ERR, "stat: %s failed, %s", uhw->path, strerror(errno)); @@ -243,9 +256,36 @@ virtio_vdev_init(struct rte_eth_dev_data *data, char *path, } if (uhw->mac_specified) uhw->features |= (1ull << VIRTIO_NET_F_MAC); - /* disable it until we support CQ */ - uhw->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); - uhw->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); + + if (!enable_ctrl_q) { + uhw->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); + /* Also disable features depends on VIRTIO_NET_F_CTRL_VQ */ + uhw->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); + uhw->features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN); + uhw->features &= ~(1ull << VIRTIO_NET_F_GUEST_ANNOUNCE); + uhw->features &= ~(1ull << VIRTIO_NET_F_MQ); + uhw->features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR); + } else { + /* vhost user backend does not need to know ctrl-q, so + * actually we need add this bit into features. However, + * DPDK vhost-user does send features with this bit, so we + * check it instead of OR it for now. + */ + if (!(uhw->features & (1ull << VIRTIO_NET_F_CTRL_VQ))) + PMD_INIT_LOG(INFO, "vhost does not support ctrl-q"); + } + + if (uhw->max_queue_pairs > 1) { + if (uhw->type == VHOST_KERNEL) { + PMD_INIT_LOG(ERR, "MQ not supported for vhost kernel"); + return -1; + } + + if (!(uhw->features & VHOST_USER_MQ)) { + PMD_INIT_LOG(ERR, "MQ not supported by the backend"); + return -1; + } + } return 0; @@ -411,6 +451,13 @@ rte_virtio_user_pmd_devinit(const char *name, const char *params) if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1) rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM, &get_integer_arg, &nb_cq); + else if (queues > 1) + nb_cq = 1; + + if (queues > 1 && nb_cq == 0) { + PMD_INIT_LOG(ERR, "multi-q requires ctrl-q"); + goto end; + } eth_dev = virtio_user_eth_dev_alloc(name); if (!eth_dev) { diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index bc4dc1a..1834a6e 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -55,6 +55,8 @@ struct virtio_user_hw { int virtio_user_start_device(struct virtio_user_hw *hw); int virtio_user_stop_device(struct virtio_user_hw *hw); +int virtio_user_enable_queue_pair(struct virtio_user_hw *hw, + unsigned pair_idx, int enable); const struct virtio_pci_ops vdev_ops; -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH 3/3] virtio-user: add mq in virtual pci driver 2016-05-05 8:59 [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 2/3] virtio-user: add mq in device emulation Jianfeng Tan @ 2016-05-05 8:59 ` Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan 4 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-05-05 8:59 UTC (permalink / raw) To: dev; +Cc: Jianfeng Tan, yuanhan.liu, nakajima.yoshihiro, nhorman Partially implement ctrl-queue to handle control command with class of VIRTIO_NET_CTRL_MQ and with cmd of VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET to handle mq support. After filling the command into ctrl-queue, we dequeue it when notify_queue(), and invoke method from device emulation to enable/disable queues. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/virtio_user_pci.c | 89 +++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_pci.c b/drivers/net/virtio/virtio_user/virtio_user_pci.c index 873e619..aa02c60 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_pci.c +++ b/drivers/net/virtio/virtio_user/virtio_user_pci.c @@ -38,6 +38,7 @@ #include "../virtio_logs.h" #include "../virtio_pci.h" #include "../virtqueue.h" +#include "../virtio_ring.h" #include "virtio_user_dev.h" static void @@ -157,8 +158,10 @@ vdev_setup_queue(struct virtio_hw *hw __rte_unused, struct virtqueue *vq) if (vq->virtio_net_hdr_mz) { vq->virtio_net_hdr_mem = (phys_addr_t)vq->virtio_net_hdr_mz->addr; - /* Do it one more time after we reset virtio_net_hdr_mem */ - vring_hdr_desc_init(vq); + + /* Do it again after we reset virtio_net_hdr_mem for tx */ + if ((vq->vq_queue_index % VTNET_CQ) == VTNET_TQ) + vring_hdr_desc_init(vq); } vq->offset = offsetof(struct rte_mbuf, buf_addr); return 0; @@ -182,11 +185,93 @@ vdev_del_queue(struct virtio_hw *hw, struct virtqueue *vq) close(uhw->kickfds[vq->vq_queue_index]); } +static uint8_t +handle_mq(struct virtqueue *vq, uint16_t queues) +{ + struct virtio_hw *hw = vq->hw; + struct virtio_user_hw *uhw = (struct virtio_user_hw *)hw->vdev_private; + uint32_t i; + uint8_t ret = 0; + + if (queues > uhw->max_queue_pairs) { + PMD_INIT_LOG(ERR, "multi-q config %u, but only %u supported", + queues, uhw->max_queue_pairs); + return -1; + } + + for (i = 0; i < queues; ++i) + ret |= virtio_user_enable_queue_pair(uhw, i, 1); + for (i = queues; i < uhw->max_queue_pairs; ++i) + ret |= virtio_user_enable_queue_pair(uhw, i, 0); + + return ret; +} + +static uint32_t +handle_ctrl(struct virtqueue *vq, uint16_t desc_idx_hdr) +{ + struct virtio_net_ctrl_hdr *hdr; + virtio_net_ctrl_ack status = ~0; + uint16_t i, desc_idx_data, desc_idx_status; + uint32_t num_of_descs = 0; + + /* locate desc for header, data, and status */ + desc_idx_data = vq->vq_ring.desc[desc_idx_hdr].next; + num_of_descs++; + + + i = desc_idx_data; + while (vq->vq_ring.desc[i].flags == VRING_DESC_F_NEXT) { + i = vq->vq_ring.desc[i].next; + num_of_descs++; + } + + /* locate desc for status */ + desc_idx_status = i; + num_of_descs++; + + hdr = (struct virtio_net_ctrl_hdr *)vq->vq_ring.desc[desc_idx_hdr].addr; + if (hdr->class == VIRTIO_NET_CTRL_MQ && + hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + uint16_t queues; + + queues = *(uint16_t *)vq->vq_ring.desc[desc_idx_data].addr; + status = handle_mq(vq, queues); + } + + /* Update status */ + *(virtio_net_ctrl_ack *)vq->vq_ring.desc[desc_idx_status].addr = status; + + return num_of_descs; +} + static void vdev_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) { uint64_t buf = 1; struct virtio_user_hw *uhw = (struct virtio_user_hw *)hw->vdev_private; + uint16_t avail_idx, desc_idx; + struct vring_used_elem *uep; + uint32_t num_of_descs; + + if (vq == hw->cvq) { + /* Consume avail ring, using used ring idx as first one */ + while (vq->vq_ring.used->idx != vq->vq_ring.avail->idx) { + avail_idx = (vq->vq_ring.used->idx) & + (vq->vq_nentries - 1); + desc_idx = vq->vq_ring.avail->ring[avail_idx]; + + num_of_descs = handle_ctrl(vq, desc_idx); + + /* Update used ring */ + uep = &vq->vq_ring.used->ring[avail_idx]; + uep->id = avail_idx; + uep->len = num_of_descs; + + vq->vq_ring.used->idx++; + } + return; + } if (write(uhw->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s\n", strerror(errno)); -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user 2016-05-05 8:59 [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user Jianfeng Tan ` (2 preceding siblings ...) 2016-05-05 8:59 ` [dpdk-dev] [PATCH 3/3] virtio-user: add mq in virtual pci driver Jianfeng Tan @ 2016-06-13 6:43 ` Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq Jianfeng Tan ` (3 more replies) 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan 4 siblings, 4 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-13 6:43 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman v2: - Move the ctrl queue handler and multi queue logic into device emulation. - Rebase on newest code. This patch set depends on below patch sets: - http://dpdk.org/ml/archives/dev/2016-June/040979.html - http://dpdk.org/ml/archives/dev/2016-June/040954.html Add multi queue support for virtio-user virtual port. Patch 1 adds vhost user adapter communications for enable/disable queues. Patch 2 adds features check for multi queue and provides a method for virtio-user driver to enable/disable queues. Patch 3 partially implements ctrl-q to handle VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command from PMD. Test case: 1. start testpmd with a vhost-user port: $ TESTPMD -c 0x7 -n 4 --socket-mem 1024,0 --no-pci \ --vdev 'eth_vhost0,iface=/tmp/sock0,queues=2' \ -- -i --rxq=2 --txq=2 --nb-cores=2 2. start testpmd with a virtio-user port: $ TESTPMD -c 0x70 -n 4 --socket-mem 1024,0 --no-pci --file-prefix=testpmd \ --vdev=virtio-user0,mac=00:01:02:03:04:05,path=/tmp/sock0,queues=2 \ -- -i --rxq=2 --txq=2 --nb-cores=2 --txqflags=0xf01 --disable-hw-vlan 3. use below commands to see if all queues are working: testpmd> show port xstats all Jianfeng Tan (4): virtio-user: use virtual address in cq virtio-user: add mq in vhost user adapter virtio-user: add ctrl-q and mq in device emulation virtio-user: handle ctrl-q in driver drivers/net/virtio/virtio_ethdev.c | 6 +- drivers/net/virtio/virtio_user/vhost.h | 5 + drivers/net/virtio/virtio_user/vhost_user.c | 21 ++++ drivers/net/virtio/virtio_user/virtio_user_dev.c | 124 +++++++++++++++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +- drivers/net/virtio/virtio_user_ethdev.c | 13 +++ 6 files changed, 158 insertions(+), 13 deletions(-) -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan @ 2016-06-13 6:43 ` Jianfeng Tan 2016-06-13 10:19 ` Yuanhan Liu 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 2/4] virtio-user: add mq in vhost user adapter Jianfeng Tan ` (2 subsequent siblings) 3 siblings, 1 reply; 17+ messages in thread From: Jianfeng Tan @ 2016-06-13 6:43 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman Change to use virtio_net_hdr_mem instead of physical addr of memzone when sending contrl queue commands. The virtio_net_hdr_mem has been initialized to use virtual address under the case of virtio-user. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 4523ceb..86ea07a 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -187,14 +187,14 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, * One RX packet for ACK. */ vq->vq_ring.desc[head].flags = VRING_DESC_F_NEXT; - vq->vq_ring.desc[head].addr = cvq->virtio_net_hdr_mz->phys_addr; + vq->vq_ring.desc[head].addr = cvq->virtio_net_hdr_mem; vq->vq_ring.desc[head].len = sizeof(struct virtio_net_ctrl_hdr); vq->vq_free_cnt--; i = vq->vq_ring.desc[head].next; for (k = 0; k < pkt_num; k++) { vq->vq_ring.desc[i].flags = VRING_DESC_F_NEXT; - vq->vq_ring.desc[i].addr = cvq->virtio_net_hdr_mz->phys_addr + vq->vq_ring.desc[i].addr = cvq->virtio_net_hdr_mem + sizeof(struct virtio_net_ctrl_hdr) + sizeof(ctrl->status) + sizeof(uint8_t)*sum; vq->vq_ring.desc[i].len = dlen[k]; @@ -204,7 +204,7 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, } vq->vq_ring.desc[i].flags = VRING_DESC_F_WRITE; - vq->vq_ring.desc[i].addr = cvq->virtio_net_hdr_mz->phys_addr + vq->vq_ring.desc[i].addr = cvq->virtio_net_hdr_mem + sizeof(struct virtio_net_ctrl_hdr); vq->vq_ring.desc[i].len = sizeof(ctrl->status); vq->vq_free_cnt--; -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq Jianfeng Tan @ 2016-06-13 10:19 ` Yuanhan Liu 0 siblings, 0 replies; 17+ messages in thread From: Yuanhan Liu @ 2016-06-13 10:19 UTC (permalink / raw) To: Jianfeng Tan Cc: dev, rich.lane, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman On Mon, Jun 13, 2016 at 06:43:40AM +0000, Jianfeng Tan wrote: > Change to use virtio_net_hdr_mem instead of physical addr of memzone > when sending contrl queue commands. The virtio_net_hdr_mem has been > initialized to use virtual address under the case of virtio-user. I'd suggest to squash this patch to "[PATCH v8 2/6] virtio: enable use virtual address to fill desc". There is really no good reason to make 2 patches to do same/similar thing. --yliu ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v2 2/4] virtio-user: add mq in vhost user adapter 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq Jianfeng Tan @ 2016-06-13 6:43 ` Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 3/4] virtio-user: add ctrl-q and mq in device emulation Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver Jianfeng Tan 3 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-13 6:43 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman This patch mainly adds method in vhost user adapter to communicate enable/disable queues messages with vhost user backend. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/vhost.h | 5 +++++ drivers/net/virtio/virtio_user/vhost_user.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h index 4e04ede..8d1e505 100644 --- a/drivers/net/virtio/virtio_user/vhost.h +++ b/drivers/net/virtio/virtio_user/vhost.h @@ -136,6 +136,11 @@ struct vhost_user_msg { /* The version of the protocol we support */ #define VHOST_USER_VERSION 0x1 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_MQ (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) + int vhost_user_sock(int vhostfd, uint64_t req, void *arg); int vhost_user_setup(const char *path); +int vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable); + #endif diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 8e5c0a9..1df532f 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -286,6 +286,7 @@ vhost_user_sock(int vhostfd, uint64_t req, void *arg) case VHOST_USER_SET_VRING_NUM: case VHOST_USER_SET_VRING_BASE: + case VHOST_USER_SET_VRING_ENABLE: memcpy(&msg.payload.state, arg, sizeof(msg.payload.state)); msg.size = sizeof(m.payload.state); break; @@ -402,3 +403,23 @@ vhost_user_setup(const char *path) return fd; } + +int +vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable) +{ + int i; + + for (i = 0; i < 2; ++i) { + struct vhost_vring_state state = { + .index = pair_idx * 2 + i, + .num = enable, + }; + + if (vhost_user_sock(vhostfd, + VHOST_USER_SET_VRING_ENABLE, &state)) + return -1; + } + + return 0; + +} -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v2 3/4] virtio-user: add ctrl-q and mq in device emulation 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 2/4] virtio-user: add mq in vhost user adapter Jianfeng Tan @ 2016-06-13 6:43 ` Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver Jianfeng Tan 3 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-13 6:43 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman The main purpose of this patch is to enable multi-queue. But multi-queue requires ctrl-queue so that driver can send how many queues will be enabled through ctrl-queue messages. So we partially implement ctrl-queue to handle control command with class of VIRTIO_NET_CTRL_MQ and with cmd of VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET to handle mq support. This patch provides an API, virtio_user_handle_cq(), for driver to handle ctrl-queue messages. Besides, multi-queue requires VIRTIO_NET_F_MQ and VIRTIO_NET_F_CTRL_VQ are enabled when we do feature negotiation. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 124 +++++++++++++++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +- 2 files changed, 116 insertions(+), 10 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 93cb758..3c72a2a 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -131,11 +131,14 @@ virtio_user_start_device(struct virtio_user_dev *dev) } } - /* After setup all virtqueues, we need to set_features so that - * these features can be set into each virtqueue in vhost side. - * And before that, make sure VIRTIO_NET_F_MAC is stripped. + /* After setup all virtqueues, we need to set_features so that these + * features can be set into each virtqueue in vhost side. And before + * that, make sure VHOST_USER_F_PROTOCOL_FEATURES is added if mq is + * enabled, and VIRTIO_NET_F_MAC is stripped. */ features = dev->features; + if (dev->max_queue_pairs > 1) + features |= VHOST_USER_MQ; features &= ~(1ull << VIRTIO_NET_F_MAC); ret = vhost_user_sock(dev->vhostfd, VHOST_USER_SET_FEATURES, &features); if (ret < 0) @@ -185,8 +188,6 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, dev->mac_specified = 0; parse_mac(dev, mac); dev->vhostfd = -1; - /* TODO: cq */ - RTE_SET_USED(cq); dev->vhostfd = vhost_user_setup(dev->path); if (dev->vhostfd < 0) { @@ -205,12 +206,33 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, } if (dev->mac_specified) dev->features |= (1ull << VIRTIO_NET_F_MAC); - /* disable it until we support CQ */ - dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); - dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); - return 0; + if (!cq) { + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); + /* Also disable features depends on VIRTIO_NET_F_CTRL_VQ */ + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN); + dev->features &= ~(1ull << VIRTIO_NET_F_GUEST_ANNOUNCE); + dev->features &= ~(1ull << VIRTIO_NET_F_MQ); + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR); + } else { + /* vhost user backend does not need to know ctrl-q, so + * actually we need add this bit into features. However, + * DPDK vhost-user does send features with this bit, so we + * check it instead of OR it for now. + */ + if (!(dev->features & (1ull << VIRTIO_NET_F_CTRL_VQ))) + PMD_INIT_LOG(INFO, "vhost does not support ctrl-q"); + } + + if (dev->max_queue_pairs > 1) { + if (!(dev->features & VHOST_USER_MQ)) { + PMD_INIT_LOG(ERR, "MQ not supported by the backend"); + return -1; + } + } + return 0; } void @@ -225,3 +247,87 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev) close(dev->vhostfd); } + +static uint8_t +virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs) +{ + uint16_t i; + uint8_t ret = 0; + + if (q_pairs > dev->max_queue_pairs) { + PMD_INIT_LOG(ERR, "multi-q config %u, but only %u supported", + q_pairs, dev->max_queue_pairs); + return -1; + } + + for (i = 0; i < q_pairs; ++i) + ret |= vhost_user_enable_queue_pair(dev->vhostfd, i, 1); + for (i = q_pairs; i < dev->max_queue_pairs; ++i) + ret |= vhost_user_enable_queue_pair(dev->vhostfd, i, 0); + + dev->queue_pairs = q_pairs; + + return ret; +} + +static uint32_t +virtio_user_handle_ctrl_msg(struct virtio_user_dev *dev, struct vring *vring, + uint16_t desc_idx_hdr) +{ + struct virtio_net_ctrl_hdr *hdr; + virtio_net_ctrl_ack status = ~0; + uint16_t i, desc_idx_data, desc_idx_status; + uint32_t n_descs = 0; + + /* locate desc for header, data, and status */ + desc_idx_data = vring->desc[desc_idx_hdr].next; + n_descs++; + + i = desc_idx_data; + while (vring->desc[i].flags == VRING_DESC_F_NEXT) { + i = vring->desc[i].next; + n_descs++; + } + + /* locate desc for status */ + desc_idx_status = i; + n_descs++; + + hdr = (struct virtio_net_ctrl_hdr *)vring->desc[desc_idx_hdr].addr; + if (hdr->class == VIRTIO_NET_CTRL_MQ && + hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + uint16_t queues; + + queues = *(uint16_t *)vring->desc[desc_idx_data].addr; + status = virtio_user_handle_mq(dev, queues); + } + + /* Update status */ + *(virtio_net_ctrl_ack *)vring->desc[desc_idx_status].addr = status; + + return n_descs; +} + +void +virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx) +{ + uint16_t avail_idx, desc_idx; + struct vring_used_elem *uep; + uint32_t n_descs; + struct vring *vring = &dev->vrings[queue_idx]; + + /* Consume avail ring, using used ring idx as first one */ + while (vring->used->idx != vring->avail->idx) { + avail_idx = (vring->used->idx) & (vring->num - 1); + desc_idx = vring->avail->ring[avail_idx]; + + n_descs = virtio_user_handle_ctrl_msg(dev, vring, desc_idx); + + /* Update used ring */ + uep = &vring->used->ring[avail_idx]; + uep->id = avail_idx; + uep->len = n_descs; + + vring->used->idx++; + } +} diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 68bee37..33690b5 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -58,5 +58,5 @@ int virtio_user_stop_device(struct virtio_user_dev *dev); int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, int cq, int queue_size, const char *mac); void virtio_user_dev_uninit(struct virtio_user_dev *dev); - +void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx); #endif -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan ` (2 preceding siblings ...) 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 3/4] virtio-user: add ctrl-q and mq in device emulation Jianfeng Tan @ 2016-06-13 6:43 ` Jianfeng Tan 2016-06-13 10:14 ` Yuanhan Liu 3 siblings, 1 reply; 17+ messages in thread From: Jianfeng Tan @ 2016-06-13 6:43 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman In virtio-user driver, when notify ctrl-queue, invoke API of virtio-user device emulation to handle ctrl-q command. Besides, multi-queue requires ctrl-queue and ctrl-queue will be enabled automatically when multi-queue is specified. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user_ethdev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 8f401a3..4c9279e 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -42,6 +42,7 @@ #include "virtio_logs.h" #include "virtio_pci.h" #include "virtqueue.h" +#include "virtio_rxtx.h" #include "virtio_user/virtio_user_dev.h" #define virtio_user_get_dev(hw) \ @@ -200,6 +201,11 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) uint64_t buf = 1; struct virtio_user_dev *dev = virtio_user_get_dev(hw); + if (hw->cvq && (hw->cvq->vq == vq)) { + virtio_user_handle_cq(dev, vq->vq_queue_index); + return; + } + if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s\n", strerror(errno)); @@ -360,6 +366,13 @@ virtio_user_pmd_devinit(const char *name, const char *params) if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1) rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM, &get_integer_arg, &cq); + else if (queues > 1) + cq = 1; + + if (queues > 1 && cq == 0) { + PMD_INIT_LOG(ERR, "multi-q requires ctrl-q"); + goto end; + } eth_dev = virtio_user_eth_dev_alloc(name); if (!eth_dev) { -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver Jianfeng Tan @ 2016-06-13 10:14 ` Yuanhan Liu 2016-06-13 10:20 ` Tan, Jianfeng 0 siblings, 1 reply; 17+ messages in thread From: Yuanhan Liu @ 2016-06-13 10:14 UTC (permalink / raw) To: Jianfeng Tan Cc: dev, rich.lane, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman On Mon, Jun 13, 2016 at 06:43:43AM +0000, Jianfeng Tan wrote: > In virtio-user driver, when notify ctrl-queue, invoke API of > virtio-user device emulation to handle ctrl-q command. > > Besides, multi-queue requires ctrl-queue and ctrl-queue will be > enabled automatically when multi-queue is specified. > > Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> > --- > drivers/net/virtio/virtio_user_ethdev.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c > index 8f401a3..4c9279e 100644 > --- a/drivers/net/virtio/virtio_user_ethdev.c > +++ b/drivers/net/virtio/virtio_user_ethdev.c > @@ -42,6 +42,7 @@ > #include "virtio_logs.h" > #include "virtio_pci.h" > #include "virtqueue.h" > +#include "virtio_rxtx.h" What's this include for? --yliu ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver 2016-06-13 10:14 ` Yuanhan Liu @ 2016-06-13 10:20 ` Tan, Jianfeng 0 siblings, 0 replies; 17+ messages in thread From: Tan, Jianfeng @ 2016-06-13 10:20 UTC (permalink / raw) To: Yuanhan Liu Cc: dev, rich.lane, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman > -----Original Message----- > From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com] > Sent: Monday, June 13, 2016 6:14 PM > To: Tan, Jianfeng > Cc: dev@dpdk.org; rich.lane@bigswitch.com; mst@redhat.com; > nakajima.yoshihiro@lab.ntt.co.jp; p.fedin@samsung.com; > ann.zhuangyanying@huawei.com; mukawa@igel.co.jp; > nhorman@tuxdriver.com > Subject: Re: [PATCH v2 4/4] virtio-user: handle ctrl-q in driver > > On Mon, Jun 13, 2016 at 06:43:43AM +0000, Jianfeng Tan wrote: > > In virtio-user driver, when notify ctrl-queue, invoke API of > > virtio-user device emulation to handle ctrl-q command. > > > > Besides, multi-queue requires ctrl-queue and ctrl-queue will be > > enabled automatically when multi-queue is specified. > > > > Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> > > --- > > drivers/net/virtio/virtio_user_ethdev.c | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > > diff --git a/drivers/net/virtio/virtio_user_ethdev.c > b/drivers/net/virtio/virtio_user_ethdev.c > > index 8f401a3..4c9279e 100644 > > --- a/drivers/net/virtio/virtio_user_ethdev.c > > +++ b/drivers/net/virtio/virtio_user_ethdev.c > > @@ -42,6 +42,7 @@ > > #include "virtio_logs.h" > > #include "virtio_pci.h" > > #include "virtqueue.h" > > +#include "virtio_rxtx.h" > > What's this include for? It's because hw->cvq->cq needs type of hw->cvq (struct virtnet_ctl). > > --yliu ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user 2016-05-05 8:59 [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user Jianfeng Tan ` (3 preceding siblings ...) 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan @ 2016-06-15 9:07 ` Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan ` (3 more replies) 4 siblings, 4 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-15 9:07 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman v3: - Fix compiling issue on 32-bit system. - Fix a segment fault issue when sending VHOST_USER_SET_VRING_ENABLE. - Squash the patch (use virtual address in mq) into "virtio for container" patch series. v2: - Move the ctrl queue handler and multi queue logic into device emulation. - Rebase on newest code. This patch set depends on below patch sets: - http://dpdk.org/ml/archives/dev/2016-April/038111.html - http://dpdk.org/ml/archives/dev/2016-April/038118.html - http://dpdk.org/ml/archives/dev/2016-April/038121.html Add multi queue support for virtio-user virtual port. Patch 1 adds vhost user adapter communications for enable/disable queues. Patch 2 adds features check for multi queue and provides a method for virtio-user driver to enable/disable queues. Patch 3 partially implements ctrl-q to handle VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET command from PMD. Test case: 1. start testpmd with a vhost-user port: $ TESTPMD -c 0x7 -n 4 --socket-mem 1024,0 --no-pci \ --vdev 'eth_vhost0,iface=/tmp/sock0,queues=2' \ -- -i --rxq=2 --txq=2 --nb-cores=2 2. start testpmd with a virtio-user port: $ TESTPMD -c 0x70 -n 4 --socket-mem 1024,0 --no-pci --file-prefix=testpmd \ --vdev=virtio-user0,mac=00:01:02:03:04:05,path=/tmp/sock0,queues=2 \ -- -i --rxq=2 --txq=2 --nb-cores=2 --txqflags=0xf01 --disable-hw-vlan 3. use below commands to see if all queues are working: testpmd> show port xstats all Jianfeng Tan (3): virtio-user: add mq in vhost user adapter virtio-user: add ctrl-q and mq in device emulation virtio-user: handle ctrl-q in driver drivers/net/virtio/virtio_user/vhost.h | 5 + drivers/net/virtio/virtio_user/vhost_user.c | 22 ++++ drivers/net/virtio/virtio_user/virtio_user_dev.c | 124 +++++++++++++++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +- drivers/net/virtio/virtio_user_ethdev.c | 13 +++ 5 files changed, 156 insertions(+), 10 deletions(-) -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v3 1/3] virtio-user: add mq in vhost user adapter 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan @ 2016-06-15 9:07 ` Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 2/3] virtio-user: add ctrl-q and mq in device emulation Jianfeng Tan ` (2 subsequent siblings) 3 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-15 9:07 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman This patch mainly adds method in vhost user adapter to communicate enable/disable queues messages with vhost user backend, aka, VHOST_USER_SET_VRING_ENABLE. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/vhost.h | 5 +++++ drivers/net/virtio/virtio_user/vhost_user.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h index 4e04ede..8d1e505 100644 --- a/drivers/net/virtio/virtio_user/vhost.h +++ b/drivers/net/virtio/virtio_user/vhost.h @@ -136,6 +136,11 @@ struct vhost_user_msg { /* The version of the protocol we support */ #define VHOST_USER_VERSION 0x1 +#define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_MQ (1ULL << VHOST_USER_F_PROTOCOL_FEATURES) + int vhost_user_sock(int vhostfd, uint64_t req, void *arg); int vhost_user_setup(const char *path); +int vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable); + #endif diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 47bbf74..98d98b6 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -234,6 +234,7 @@ static const char * const vhost_msg_strings[] = { [VHOST_USER_SET_VRING_ADDR] = "VHOST_USER_SET_VRING_ADDR", [VHOST_USER_SET_VRING_KICK] = "VHOST_USER_SET_VRING_KICK", [VHOST_USER_SET_MEM_TABLE] = "VHOST_USER_SET_MEM_TABLE", + [VHOST_USER_SET_VRING_ENABLE] = "VHOST_USER_SET_VRING_ENABLE", NULL, }; @@ -286,6 +287,7 @@ vhost_user_sock(int vhostfd, uint64_t req, void *arg) case VHOST_USER_SET_VRING_NUM: case VHOST_USER_SET_VRING_BASE: + case VHOST_USER_SET_VRING_ENABLE: memcpy(&msg.payload.state, arg, sizeof(msg.payload.state)); msg.size = sizeof(m.payload.state); break; @@ -402,3 +404,23 @@ vhost_user_setup(const char *path) return fd; } + +int +vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable) +{ + int i; + + for (i = 0; i < 2; ++i) { + struct vhost_vring_state state = { + .index = pair_idx * 2 + i, + .num = enable, + }; + + if (vhost_user_sock(vhostfd, + VHOST_USER_SET_VRING_ENABLE, &state)) + return -1; + } + + return 0; + +} -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v3 2/3] virtio-user: add ctrl-q and mq in device emulation 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan @ 2016-06-15 9:07 ` Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] virtio-user: handle ctrl-q in driver Jianfeng Tan 2016-06-15 9:54 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Yuanhan Liu 3 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-15 9:07 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman The main purpose of this patch is to enable multi-queue. But multi-queue requires ctrl-queue so that driver can send how many queues will be enabled through ctrl-queue messages. So we partially implement ctrl-queue to handle control command with class of VIRTIO_NET_CTRL_MQ and with cmd of VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET to handle mq support. This patch provides an API, virtio_user_handle_cq(), for driver to handle ctrl-queue messages. Besides, multi-queue requires VIRTIO_NET_F_MQ and VIRTIO_NET_F_CTRL_VQ are enabled when we do feature negotiation. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user/virtio_user_dev.c | 124 +++++++++++++++++++++-- drivers/net/virtio/virtio_user/virtio_user_dev.h | 2 +- 2 files changed, 116 insertions(+), 10 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 93cb758..3d12a32 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -131,11 +131,14 @@ virtio_user_start_device(struct virtio_user_dev *dev) } } - /* After setup all virtqueues, we need to set_features so that - * these features can be set into each virtqueue in vhost side. - * And before that, make sure VIRTIO_NET_F_MAC is stripped. + /* After setup all virtqueues, we need to set_features so that these + * features can be set into each virtqueue in vhost side. And before + * that, make sure VHOST_USER_F_PROTOCOL_FEATURES is added if mq is + * enabled, and VIRTIO_NET_F_MAC is stripped. */ features = dev->features; + if (dev->max_queue_pairs > 1) + features |= VHOST_USER_MQ; features &= ~(1ull << VIRTIO_NET_F_MAC); ret = vhost_user_sock(dev->vhostfd, VHOST_USER_SET_FEATURES, &features); if (ret < 0) @@ -185,8 +188,6 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, dev->mac_specified = 0; parse_mac(dev, mac); dev->vhostfd = -1; - /* TODO: cq */ - RTE_SET_USED(cq); dev->vhostfd = vhost_user_setup(dev->path); if (dev->vhostfd < 0) { @@ -205,12 +206,33 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, } if (dev->mac_specified) dev->features |= (1ull << VIRTIO_NET_F_MAC); - /* disable it until we support CQ */ - dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); - dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); - return 0; + if (!cq) { + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ); + /* Also disable features depends on VIRTIO_NET_F_CTRL_VQ */ + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_RX); + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_VLAN); + dev->features &= ~(1ull << VIRTIO_NET_F_GUEST_ANNOUNCE); + dev->features &= ~(1ull << VIRTIO_NET_F_MQ); + dev->features &= ~(1ull << VIRTIO_NET_F_CTRL_MAC_ADDR); + } else { + /* vhost user backend does not need to know ctrl-q, so + * actually we need add this bit into features. However, + * DPDK vhost-user does send features with this bit, so we + * check it instead of OR it for now. + */ + if (!(dev->features & (1ull << VIRTIO_NET_F_CTRL_VQ))) + PMD_INIT_LOG(INFO, "vhost does not support ctrl-q"); + } + + if (dev->max_queue_pairs > 1) { + if (!(dev->features & VHOST_USER_MQ)) { + PMD_INIT_LOG(ERR, "MQ not supported by the backend"); + return -1; + } + } + return 0; } void @@ -225,3 +247,87 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev) close(dev->vhostfd); } + +static uint8_t +virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs) +{ + uint16_t i; + uint8_t ret = 0; + + if (q_pairs > dev->max_queue_pairs) { + PMD_INIT_LOG(ERR, "multi-q config %u, but only %u supported", + q_pairs, dev->max_queue_pairs); + return -1; + } + + for (i = 0; i < q_pairs; ++i) + ret |= vhost_user_enable_queue_pair(dev->vhostfd, i, 1); + for (i = q_pairs; i < dev->max_queue_pairs; ++i) + ret |= vhost_user_enable_queue_pair(dev->vhostfd, i, 0); + + dev->queue_pairs = q_pairs; + + return ret; +} + +static uint32_t +virtio_user_handle_ctrl_msg(struct virtio_user_dev *dev, struct vring *vring, + uint16_t idx_hdr) +{ + struct virtio_net_ctrl_hdr *hdr; + virtio_net_ctrl_ack status = ~0; + uint16_t i, idx_data, idx_status; + uint32_t n_descs = 0; + + /* locate desc for header, data, and status */ + idx_data = vring->desc[idx_hdr].next; + n_descs++; + + i = idx_data; + while (vring->desc[i].flags == VRING_DESC_F_NEXT) { + i = vring->desc[i].next; + n_descs++; + } + + /* locate desc for status */ + idx_status = i; + n_descs++; + + hdr = (void *)(uintptr_t)vring->desc[idx_hdr].addr; + if (hdr->class == VIRTIO_NET_CTRL_MQ && + hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + uint16_t queues; + + queues = *(uint16_t *)(uintptr_t)vring->desc[idx_data].addr; + status = virtio_user_handle_mq(dev, queues); + } + + /* Update status */ + *(virtio_net_ctrl_ack *)(uintptr_t)vring->desc[idx_status].addr = status; + + return n_descs; +} + +void +virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx) +{ + uint16_t avail_idx, desc_idx; + struct vring_used_elem *uep; + uint32_t n_descs; + struct vring *vring = &dev->vrings[queue_idx]; + + /* Consume avail ring, using used ring idx as first one */ + while (vring->used->idx != vring->avail->idx) { + avail_idx = (vring->used->idx) & (vring->num - 1); + desc_idx = vring->avail->ring[avail_idx]; + + n_descs = virtio_user_handle_ctrl_msg(dev, vring, desc_idx); + + /* Update used ring */ + uep = &vring->used->ring[avail_idx]; + uep->id = avail_idx; + uep->len = n_descs; + + vring->used->idx++; + } +} diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 68bee37..33690b5 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -58,5 +58,5 @@ int virtio_user_stop_device(struct virtio_user_dev *dev); int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, int cq, int queue_size, const char *mac); void virtio_user_dev_uninit(struct virtio_user_dev *dev); - +void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx); #endif -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [dpdk-dev] [PATCH v3 0/3] virtio-user: handle ctrl-q in driver 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 2/3] virtio-user: add ctrl-q and mq in device emulation Jianfeng Tan @ 2016-06-15 9:07 ` Jianfeng Tan 2016-06-15 9:54 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Yuanhan Liu 3 siblings, 0 replies; 17+ messages in thread From: Jianfeng Tan @ 2016-06-15 9:07 UTC (permalink / raw) To: dev Cc: Jianfeng Tan, rich.lane, yuanhan.liu, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman In virtio-user driver, when notify ctrl-queue, invoke API of virtio-user device emulation to handle ctrl-q command. Besides, multi-queue requires ctrl-queue and ctrl-queue will be enabled automatically when multi-queue is specified. Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com> --- drivers/net/virtio/virtio_user_ethdev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 8f401a3..4c9279e 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -42,6 +42,7 @@ #include "virtio_logs.h" #include "virtio_pci.h" #include "virtqueue.h" +#include "virtio_rxtx.h" #include "virtio_user/virtio_user_dev.h" #define virtio_user_get_dev(hw) \ @@ -200,6 +201,11 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) uint64_t buf = 1; struct virtio_user_dev *dev = virtio_user_get_dev(hw); + if (hw->cvq && (hw->cvq->vq == vq)) { + virtio_user_handle_cq(dev, vq->vq_queue_index); + return; + } + if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) PMD_DRV_LOG(ERR, "failed to kick backend: %s\n", strerror(errno)); @@ -360,6 +366,13 @@ virtio_user_pmd_devinit(const char *name, const char *params) if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1) rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM, &get_integer_arg, &cq); + else if (queues > 1) + cq = 1; + + if (queues > 1 && cq == 0) { + PMD_INIT_LOG(ERR, "multi-q requires ctrl-q"); + goto end; + } eth_dev = virtio_user_eth_dev_alloc(name); if (!eth_dev) { -- 2.1.4 ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan ` (2 preceding siblings ...) 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] virtio-user: handle ctrl-q in driver Jianfeng Tan @ 2016-06-15 9:54 ` Yuanhan Liu 3 siblings, 0 replies; 17+ messages in thread From: Yuanhan Liu @ 2016-06-15 9:54 UTC (permalink / raw) To: Jianfeng Tan Cc: dev, rich.lane, mst, nakajima.yoshihiro, p.fedin, ann.zhuangyanying, mukawa, nhorman Applied to dpdk-next-virtio, with following small changes, for addressing a build error and some checkpatch warnings. Thanks. --yliu --- diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 026b8a1..ea7a48e 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -307,9 +307,9 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, const struct rte_memzone *mz = NULL, *hdr_mz = NULL; unsigned int vq_size, size; struct virtio_hw *hw = dev->data->dev_private; - struct virtnet_rx *rxvq; - struct virtnet_tx *txvq; - struct virtnet_ctl *cvq; + struct virtnet_rx *rxvq = NULL; + struct virtnet_tx *txvq = NULL; + struct virtnet_ctl *cvq = NULL; struct virtqueue *vq; const char *queue_names[] = {"rvq", "txq", "cvq"}; size_t sz_vq, sz_q = 0, sz_hdr_mz = 0; diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h index 8d1e505..897042f 100644 --- a/drivers/net/virtio/virtio_user/vhost.h +++ b/drivers/net/virtio/virtio_user/vhost.h @@ -141,6 +141,6 @@ struct vhost_user_msg { int vhost_user_sock(int vhostfd, uint64_t req, void *arg); int vhost_user_setup(const char *path); -int vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable); +int vhost_user_enable_queue_pair(int vhostfd, uint16_t pair_idx, int enable); #endif diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 98d98b6..95e80f8 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -100,8 +100,9 @@ vhost_user_read(int fd, struct vhost_user_msg *msg) if (sz_payload) { ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0); if (ret < sz_payload) { - PMD_DRV_LOG(ERR, "Failed to recv msg payload: %d instead of %d.", - ret, msg->size); + PMD_DRV_LOG(ERR, + "Failed to recv msg payload: %d instead of %d.", + ret, msg->size); goto fail; } } @@ -406,7 +407,7 @@ vhost_user_setup(const char *path) } int -vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable) +vhost_user_enable_queue_pair(int vhostfd, uint16_t pair_idx, int enable) { int i; @@ -422,5 +423,4 @@ vhost_user_enable_queue_pair(int vhostfd, unsigned pair_idx, int enable) } return 0; - } diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 4c9279e..9216182 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -46,7 +46,7 @@ #include "virtio_user/virtio_user_dev.h" #define virtio_user_get_dev(hw) \ - ((struct virtio_user_dev *)(hw)->virtio_user_dev); + ((struct virtio_user_dev *)(hw)->virtio_user_dev) static void virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset, ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2016-06-15 9:54 UTC | newest] Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-05-05 8:59 [dpdk-dev] [PATCH 0/3] add multi queue support for virtio-user Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 2/3] virtio-user: add mq in device emulation Jianfeng Tan 2016-05-05 8:59 ` [dpdk-dev] [PATCH 3/3] virtio-user: add mq in virtual pci driver Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 0/4] add multi queue support for virtio-user Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 1/4] virtio-user: use virtual address in cq Jianfeng Tan 2016-06-13 10:19 ` Yuanhan Liu 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 2/4] virtio-user: add mq in vhost user adapter Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 3/4] virtio-user: add ctrl-q and mq in device emulation Jianfeng Tan 2016-06-13 6:43 ` [dpdk-dev] [PATCH v2 4/4] virtio-user: handle ctrl-q in driver Jianfeng Tan 2016-06-13 10:14 ` Yuanhan Liu 2016-06-13 10:20 ` Tan, Jianfeng 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 1/3] virtio-user: add mq in vhost user adapter Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 2/3] virtio-user: add ctrl-q and mq in device emulation Jianfeng Tan 2016-06-15 9:07 ` [dpdk-dev] [PATCH v3 0/3] virtio-user: handle ctrl-q in driver Jianfeng Tan 2016-06-15 9:54 ` [dpdk-dev] [PATCH v3 0/3] add multi queue support for virtio-user Yuanhan Liu
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).