vhost ABI/API refactoring
cover vhost ABI/API refactoring
Every time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf from vhost_virtqueue struct) also break ABI.
This patch set is meant to resolve above issue ultimately, by hiding virtio_net structure (as well as few others) internaly, and export the virtio_net dev strut to applications by a number, vid, like the way kernel exposes an fd to user space.
Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".
After that, "vrtio_net_device_ops" is the only left open struct that an application can acces, thefeore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more (5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.
The last bit of this patch set is some cleanups, including the one from Ilya.
Note that this refactoring breaks the tep_termination example. Well, it's just another copy of the original messy vhost example, and I have no interest to cleanup it again. Therefore, I might consider to remove that example later, and add the vxlan bits into vhost example.
Few more TODOs: update release note, update lib version, update version.map
Thanks.
--yliu
---
Ilya Maximets (1):
vhost: make buf vector for scatter Rx local
Yuanhan Liu (15):
vhost: declare backend with int type
vhost: set/reset dev flags internally
vhost: declare device_fh as int
example/vhost: make a copy of virtio device id
vhost: rename device_fh to vid
vhost: get device by vid only
vhost: move vhost_device_ctx to cuse
vhost: query pmd internal by vid
vhost: add few more functions
vhost: export vid as the only interface to applications
vhost: hide internal structs/macros/functions
vhost: remove unnecessary fields
vhost: remove virtio-net.h
vhost: reserve few more space for future extension
vhost: per device vhost_hlen
drivers/net/vhost/rte_eth_vhost.c | 86 ++++------- examples/vhost/main.c | 126 ++++++++------- examples/vhost/main.h | 1 + lib/librte_vhost/rte_virtio_net.h | 197 ++++++------------------ lib/librte_vhost/vhost-net.h | 195 +++++++++++++++++++---- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 83 +++++----- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 30 ++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 +- lib/librte_vhost/vhost_rxtx.c | 133 ++++++++-------- lib/librte_vhost/vhost_user/vhost-net-user.c | 53 +++---- lib/librte_vhost/vhost_user/virtio-net-user.c | 64 ++++---- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 +-- lib/librte_vhost/virtio-net.c | 213 ++++++++++++++++---------- lib/librte_vhost/virtio-net.h | 43 ------ 14 files changed, 644 insertions(+), 610 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.h
Signature · 1 line
1.9.0
PATCH 1/16 vhost: declare backend with int type
It's an fd; so define it as "int", which could also save the unncessary (int) case.
--- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/virtio-net.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -85,7 +85,7 @@ struct vhost_virtqueue {struct vring_avail *avail;/**< Virtqueue available ring. */ struct vring_used *used;/**< Virtqueue used ring. */ uint32_t size;/**< Size of descriptor ring. */ -uint32_t backend;/**< Backend value to determine if device should started/stopped. */ +int backend;/**< Backend value to determine if device should started/stopped. */ uint16_t vhost_hlen;/**< Vhost header length (varies depending on RX merge buffers. */ volatile uint16_t last_used_idx;/**< Last index used on the available ring */ volatile uint16_t last_used_idx_res;/**< Used for multiple devices reserving buffers. */
lib/librte_vhost/virtio-net.c +2 -2
@@ -716,8 +716,8 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)* we add the device. */ if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (((int )dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED ) && - ((int )dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED )) { +if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && + dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) {return notify_ops->new_device (dev); }/* Otherwise we remove it. */
Signature · 1 line
1.9.0
PATCH 2/16 vhost: set/reset dev flags internally
In reply to Yuanhan LiuIt does not make sense to ask the application to set/unset the flag VIRTIO_DEV_RUNNING (that used internal only) at new_device()/ destroy_device() callback.
Instead, it should be set after new_device() succeeds and reset before destroy_device() is invoked inside vhost lib. This patch fixes it.
--- drivers/net/vhost/rte_eth_vhost.c | 2 -- examples/vhost/main.c | 3 --- lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++---- lib/librte_vhost/virtio-net.c | 21 ++++++++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +0 -2
@@ -278,7 +278,6 @@ new_device(struct virtio_net *dev)for (i =0 ; i < dev->virt_qp_nb *VIRTIO_QNUM ; i++)rte_vhost_enable_guest_notification (dev, i,0 ); - dev->flags |=VIRTIO_DEV_RUNNING ; dev->priv = eth_dev; eth_dev->data->dev_link.link_status =ETH_LINK_UP ;
@@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status =ETH_LINK_DOWN ; dev->priv =NULL ; - dev->flags &= ~VIRTIO_DEV_RUNNING ;for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i];
examples/vhost/main.c +0 -3
@@ -1180,8 +1180,6 @@ destroy_device (volatile struct virtio_net *dev)struct vhost_dev *vdev;int lcore; - dev->flags &= ~VIRTIO_DEV_RUNNING ; - vdev = (struct vhost_dev *)dev->priv;/*set the remove flag. */ vdev->remove =1 ;
@@ -1258,7 +1256,6 @@ new_device (struct virtio_net *dev)/* Disable notifications. */ rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 );rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); - dev->flags |=VIRTIO_DEV_RUNNING ;RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , dev->device_fh, vdev->coreid);
lib/librte_vhost/vhost_user/virtio-net-user.c +7 -4
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)return -1 ;/* Remove from the data plane. */ -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }if (dev->mem) {free_mem_region (dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) "vring kick idx:%d file:%d\n", file.index, file.fd);vhost_set_vring_kick (ctx, &file); -if (virtio_is_ready (dev) && - !(dev->flags &VIRTIO_DEV_RUNNING )) - notify_ops->new_device (dev); +if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { +if (notify_ops->new_device (dev) ==0 ) + dev->flags |=VIRTIO_DEV_RUNNING ; + } }/*
lib/librte_vhost/virtio-net.c +14 -7
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)if (dev ==NULL )return ; -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }cleanup_device (dev,1 );free_device (dev);
@@ -352,8 +354,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)if (dev ==NULL )return -1 ; -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }cleanup_device (dev,0 );reset_device (dev);
@@ -718,12 +722,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)if (!(dev->flags &VIRTIO_DEV_RUNNING )) {if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) { -return notify_ops->new_device (dev); +if (notify_ops->new_device (dev) <0 ) +return -1 ; + dev->flags |=VIRTIO_DEV_RUNNING ; } -/* Otherwise we remove it. */ - }else -if (file->fd ==VIRTIO_DEV_STOPPED ) - notify_ops->destroy_device (dev); + }else if (file->fd ==VIRTIO_DEV_STOPPED ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; + notify_ops->destroy_device (dev); + } +return 0 ; }
Signature · 1 line
1.9.0
PATCH 3/16 vhost: declare device_fh as int
In reply to Yuanhan LiuFirstly, "int" would be big enough: we don't need 64 bit to represent a virtio-net device id.
Secondly, this could let us avoid the ugly "%" PRIu64 ".." stuff.
And since ctx.fh is derived from device_fh, declare it as int, too.
--- examples/vhost/main.c | 45 ++++++++++++++------------- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/vhost-net.h | 8 ++--- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 34 ++++++++++---------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 7 ++--- lib/librte_vhost/vhost_rxtx.c | 34 +++++++++----------- lib/librte_vhost/vhost_user/virtio-net-user.c | 2 +- lib/librte_vhost/virtio-net.c | 21 ++++++------- 8 files changed, 74 insertions(+), 79 deletions(-)
examples/vhost/main.c +24 -21
@@ -717,7 +717,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA , -"Device (%" PRIu64") is using a registered MAC!\n" , +"(%d) device is using a registered MAC!\n" , dev->device_fh);return -1 ; }
@@ -729,7 +729,8 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->vlan_tag = vlan_tags[dev->device_fh];/* Print out VMDQ registration info. */ - RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VLAN_TAG %d registered\n", + RTE_LOG(INFO, VHOST_DATA, + "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", dev->device_fh, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
@@ -740,8 +741,9 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, (uint32_t )dev->device_fh + vmdq_pool_base);if (ret) -RTE_LOG (ERR ,VHOST_DATA ,"(%" PRIu64") Failed to add device MAC address to VMDQ\n" , - dev->device_fh); +RTE_LOG (ERR ,VHOST_DATA , +"(%d) failed to add device MAC address to VMDQ\n" , + dev->device_fh);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -813,7 +815,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) {struct ether_hdr *pkt_hdr;struct vhost_dev *dst_vdev; -uint64_t fh; +int fh; pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -824,17 +826,16 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) fh = dst_vdev->dev->device_fh;if (fh == vdev->dev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: src and dst MAC is same. " -"Dropping packet.\n" , fh); +"(%d) TX: src and dst MAC is same. Dropping packet.\n" , + fh);return 0 ; } -RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: MAC address is local\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is local\n" , fh);if (unlikely (dst_vdev->remove)) { -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") " -"Device is marked for removal\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) device is marked for removal\n" , fh);return 0 ; }
@@ -859,8 +860,8 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,if (dst_vdev->dev->device_fh == dev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: src and dst MAC is same. " -" Dropping packet.\n" , dst_vdev->dev->device_fh); +"(%d) TX: src and dst MAC is same. Dropping packet.\n" , + dst_vdev->dev->device_fh);return -1 ; }
@@ -873,8 +874,7 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m, *vlan_tag = vlan_tags[(uint16_t )dst_vdev->dev->device_fh];RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: pkt to local VM device id: (%" PRIu64") " -"vlan tag: %u.\n" , +"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n" , dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);return 0 ;
@@ -965,8 +965,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) } } -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") TX: " -"MAC address is external\n" , dev->device_fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) TX: MAC is external\n" , dev->device_fh); queue2nic:
@@ -1207,7 +1207,7 @@ destroy_device (volatile struct virtio_net *dev) lcore_info[vdev->coreid].device_num--;RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") Device has been removed from data core\n" , +"(%d) device has been removed from data core\n" , dev->device_fh);rte_free (vdev);
@@ -1226,7 +1226,8 @@ new_device (struct virtio_net *dev) vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) { -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Couldn't allocate memory for vhost dev\n" , +RTE_LOG (INFO ,VHOST_DATA , +"(%d) Couldn't allocate memory for vhost dev\n" , dev->device_fh);return -1 ; }
@@ -1257,7 +1258,9 @@ new_device (struct virtio_net *dev)rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 );rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , dev->device_fh, vdev->coreid); +RTE_LOG (INFO ,VHOST_DATA , +"(%d) device has been added to data core %d\n" , + dev->device_fh, vdev->coreid);return 0 ; }
@@ -1301,7 +1304,7 @@ print_stats(void) rx =rte_atomic64_read (&vdev->stats.rx_atomic); rx_dropped = rx_total - rx; -printf ("Statistics for device %" PRIu64"\n" +printf ("Statistics for device %d\n" "-----------------------\n" "TX total: %" PRIu64"\n" "TX dropped: %" PRIu64 "\n"
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -133,7 +133,7 @@ struct virtio_net {struct virtio_memory *mem;/**< QEMU memory and memory region information. */ uint64_t features;/**< Negotiated feature set. */ uint64_t protocol_features;/**< Negotiated protocol feature set. */ -uint64_t device_fh;/**< device identifier. */ +int device_fh;/**< device identifier. */ uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */
lib/librte_vhost/vhost-net.h +4 -4
@@ -57,9 +57,9 @@char packet[VHOST_MAX_PRINT_BUFF ]; \ \if ((header)) \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%" PRIu64") Header size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->device_fh), (size)); \else \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%" PRIu64") Packet size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->device_fh), (size)); \for (index =0 ; index < (size); index++) { \snprintf (packet +strnlen (packet,VHOST_MAX_PRINT_BUFF ),VHOST_MAX_PRINT_BUFF -strnlen (packet,VHOST_MAX_PRINT_BUFF ), \"%02hhx " , pkt_addr[index]); \
@@ -79,8 +79,8 @@* Structure used to identify device context. */ struct vhost_device_ctx { -pid_t pid;/* PID of process calling the IOCTL. */ -uint64_t fh;/* Populated with fi->fh to track the device index. */ +pid_t pid;/* PID of process calling the IOCTL. */ +int fh;/* Populated with fi->fh to track the device index. */ };int vhost_new_device (struct vhost_device_ctx );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +17 -17
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) fi->fh = err;RTE_LOG (INFO ,VHOST_CONFIG , -"(%" PRIu64") Device configuration started\n" , fi->fh); +"(%d) device configuration started\n" , fi->fh);fuse_reply_open (req, fi); }
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx); -RTE_LOG (INFO ,VHOST_CONFIG ,"(%" PRIu64") Device released\n" , ctx.fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.fh);fuse_reply_err (req, err); }
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,switch (cmd) {case VHOST_NET_SET_BACKEND :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh); +"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh);if (!in_buf) {VHOST_IOCTL_RETRY (sizeof (file),0 );break ;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_GET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_GET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.fh);VHOST_IOCTL_W (uint64_t, features, vhost_get_features);break ;case VHOST_SET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.fh);VHOST_IOCTL_R (uint64_t, features, vhost_set_features);break ;case VHOST_RESET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_RESET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.fh);VHOST_IOCTL (vhost_reset_owner);break ;case VHOST_SET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.fh);VHOST_IOCTL (vhost_set_owner);break ;case VHOST_SET_MEM_TABLE :/*TODO fix race condition.*/ LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh);static struct vhost_memory mem_temp;switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_NUM :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num);break ;case VHOST_SET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base);break ;case VHOST_GET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh);VHOST_IOCTL_RW (uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base);break ;case VHOST_SET_VRING_ADDR :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr);break ;
@@ -294,11 +294,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_CALL :if (cmd ==VHOST_SET_VRING_KICK )LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_KICK\n" , +"(%d) IOCTL: VHOST_SET_VRING_KICK\n" , ctx.fh);else LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_CALL\n" , +"(%d) IOCTL: VHOST_SET_VRING_CALL\n" , ctx.fh);if (!in_buf)VHOST_IOCTL_RETRY (sizeof (struct vhost_vring_file ),0 );
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,default :RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") IOCTL: DOESN NOT EXIST\n" , ctx.fh); +"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.fh); result =-1 ;fuse_reply_ioctl (req, result,NULL ,0 ); }if (result <0 )LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: FAIL\n" , ctx.fh); +"(%d) IOCTL: FAIL\n" , ctx.fh);else LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: SUCCESS\n" , ctx.fh); +"(%d) IOCTL: SUCCESS\n" , ctx.fh); }/*
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +3 -4
@@ -289,7 +289,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx, sizeof(struct virtio_memory_regions) * nregions);if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev->mem\n" , +"(%d) failed to allocate memory for dev->mem\n" , dev->device_fh);return -1 ; }
@@ -393,8 +393,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret =ioctl (fd_tap,TUNGETIFF , &ifr);if (close (fd_tap) <0 ) -RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") fd close failed\n" , +RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , dev->device_fh);if (ret >=0 ) {
@@ -402,7 +401,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, intvhost_set_ifname (ctx, ifr.ifr_name, ifr_size); }else RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") TUNGETIFF ioctl failed\n" , +"(%d) TUNGETIFF ioctl failed\n" , dev->device_fh);return 0 ;
lib/librte_vhost/vhost_rxtx.c +14 -20
@@ -264,11 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t desc_indexes[MAX_PKT_BURST ];uint32_t i; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") virtio_dev_rx()\n" , dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -280,8 +279,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,if (count ==0 )return 0 ; -LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") res_start_idx %d| res_end_idx Index %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) res_start_idx %d | res_end_idx Index %d\n" , dev->device_fh, res_start_idx, res_end_idx);/* Retrieve all of the desc indexes first to avoid caching issues. */
@@ -443,8 +441,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,if (unlikely (m ==NULL ))return 0 ; -LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") Current Index %d| End Index %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , dev->device_fh, cur_idx, res_end_idx);if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
@@ -454,7 +451,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,rte_prefetch0 ((void *)(uintptr_t )desc_addr); virtio_hdr.num_buffers = res_end_idx - res_start_idx; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") RX: Num merge buffers %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) RX: num merge buffers %d\n" , dev->device_fh, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr);
@@ -533,12 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint32_t pkt_idx =0 , nr_used =0 ;uint16_t start, end; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") virtio_dev_merge_rx()\n" , - dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -556,7 +551,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (unlikely (reserve_avail_buf_mergeable (vq, pkt_len, &start, &end) <0 )) {LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") Failed to get enough desc from vring\n" , +"(%d) failed to get enough desc from vring\n" , dev->device_fh);break ; }
@@ -832,9 +827,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,uint16_t avail_idx;if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -870,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (free_entries ==0 ) goto out; -LOG_DEBUG (VHOST_DATA ,"%s (%" PRIu64")\n" , __func__, dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);/* Prefetch available ring to retrieve head indexes. */ used_idx = vq->last_used_idx & (vq->size -1 );
@@ -878,7 +872,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, count =RTE_MIN (count,MAX_PKT_BURST ); count =RTE_MIN (count, free_entries); -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") about to dequeue %u buffers\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) about to dequeue %u buffers\n" , dev->device_fh, count);/* Retrieve all of the head indexes first to avoid caching issues. */
lib/librte_vhost/vhost_user/virtio-net-user.c +1 -1
@@ -132,7 +132,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) sizeof(struct orig_region_map) * memory.nregions);if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev->mem\n" , +"(%d) failed to allocate memory for dev->mem\n" , dev->device_fh);return -1 ; }
lib/librte_vhost/virtio-net.c +10 -11
@@ -116,7 +116,7 @@ get_device(struct vhost_device_ctx ctx)if (unlikely (!dev)) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") device not found.\n" , ctx.fh); +"(%d) device not found.\n" , ctx.fh); }return dev;
@@ -263,8 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev.\n" , - ctx.fh); +"(%d) failed to allocate memory for dev.\n" , ctx.fh);return -1 ; }
@@ -407,7 +406,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) vhost_hlen =sizeof (struct virtio_net_hdr ); }LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") Mergeable RX buffers %s, virtio 1 %s\n" , +"(%d) mergeable RX buffers %s, virtio 1 %s\n" , dev->device_fh, (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL <<VIRTIO_F_VERSION_1 )) ?"on" :"off" );
@@ -548,7 +547,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->desc_user_addr);if (vq->desc ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find desc ring address.\n" , +"(%d) failed to find desc ring address.\n" , dev->device_fh);return -1 ; }
@@ -560,7 +559,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->avail_user_addr);if (vq->avail ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find avail ring address.\n" , +"(%d) failed to find avail ring address.\n" , dev->device_fh);return -1 ; }
@@ -569,20 +568,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->used_user_addr);if (vq->used ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find used ring address.\n" , +"(%d) failed to find used ring address.\n" , dev->device_fh);return -1 ; } vq->log_guest_addr = addr->log_guest_addr; -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address desc: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address desc: %p\n" , dev->device_fh, vq->desc); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address avail: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address avail: %p\n" , dev->device_fh, vq->avail); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address used: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address used: %p\n" , dev->device_fh, vq->used); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") log_guest_addr: %" PRIx64"\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) log_guest_addr: %" PRIx64"\n" , dev->device_fh, vq->log_guest_addr);return 0 ;
Signature · 1 line
1.9.0
PATCH 4/16 example/vhost: make a copy of virtio device id
In reply to Yuanhan LiuMake a copy of virtio device id (device_fh) from the virtio_net struct, so that we could have less dependency on the virtio_net struct.
--- examples/vhost/main.c | 59 ++++++++++++++++++++++++--------------------------- examples/vhost/main.h | 1 + 2 files changed, 29 insertions(+), 31 deletions(-)
examples/vhost/main.c +28 -31
@@ -709,7 +709,6 @@ static int link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) { struct ether_hdr *pkt_hdr; -struct virtio_net *dev = vdev->dev;int i, ret;/* Learn MAC address of guest device from packet */
@@ -718,7 +717,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) device is using a registered MAC!\n" , - dev->device_fh); + vdev->device_fh);return -1 ; }
@@ -726,12 +725,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];/* vlan_tag currently uses the device_id. */ - vdev->vlan_tag = vlan_tags[dev->device_fh]; + vdev->vlan_tag = vlan_tags[vdev->device_fh];/* Print out VMDQ registration info. */ RTE_LOG(INFO, VHOST_DATA, "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", - dev->device_fh, + vdev->device_fh, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3], vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -739,11 +738,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)/* Register the MAC address. */ ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, - (uint32_t )dev->device_fh + vmdq_pool_base); + (uint32_t )vdev->device_fh + vmdq_pool_base);if (ret)RTE_LOG (ERR ,VHOST_DATA ,"(%d) failed to add device MAC address to VMDQ\n" , - dev->device_fh); + vdev->device_fh);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -815,7 +814,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) {struct ether_hdr *pkt_hdr;struct vhost_dev *dst_vdev; -int fh; pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -823,19 +821,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)if (!dst_vdev)return -1 ; - fh = dst_vdev->dev->device_fh; -if (fh == vdev->dev->device_fh) { +if (vdev->device_fh == dst_vdev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - fh); + vdev->device_fh);return 0 ; } -RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is local\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) TX: MAC address is local\n" , dst_vdev->device_fh);if (unlikely (dst_vdev->remove)) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) device is marked for removal\n" , fh); +"(%d) device is marked for removal\n" , dst_vdev->device_fh);return 0 ; }
@@ -848,7 +846,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)* and get its vlan tag, and offset if it is. */ static inline int __attribute__((always_inline)) -find_local_dest (struct virtio_net *dev,struct rte_mbuf *m, +find_local_dest (struct vhost_dev *vdev,struct rte_mbuf *m,uint32_t *offset,uint16_t *vlan_tag) {struct vhost_dev *dst_vdev;
@@ -858,10 +856,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,if (!dst_vdev)return 0 ; -if (dst_vdev->dev->device_fh == dev->device_fh) { +if (vdev->device_fh == dst_vdev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - dst_vdev->dev->device_fh); + vdev->device_fh);return -1 ; }
@@ -871,11 +869,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,* the packet length by plus it. */ *offset =VLAN_HLEN ; - *vlan_tag = vlan_tags[(uint16_t )dst_vdev->dev->device_fh]; + *vlan_tag = vlan_tags[vdev->device_fh];RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n" , - dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag); +"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n" , + vdev->device_fh, dst_vdev->device_fh, *vlan_tag);return 0 ; }
@@ -938,7 +936,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)struct mbuf_table *tx_q;unsigned offset =0 ;const uint16_t lcore_id =rte_lcore_id (); -struct virtio_net *dev = vdev->dev;struct ether_hdr *nh;
@@ -959,14 +956,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) }if (unlikely (vm2vm_mode ==VM2VM_HARDWARE )) { -if (unlikely (find_local_dest (dev, m, &offset, &vlan_tag) !=0 )) { +if (unlikely (find_local_dest (vdev, m, &offset, + &vlan_tag) !=0 )) {rte_pktmbuf_free (m);return ; } }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC is external\n" , dev->device_fh); +"(%d) TX: MAC address is external\n" , vdev->device_fh); queue2nic:
@@ -1096,10 +1094,8 @@ drain_virtio_tx(struct vhost_dev *vdev)free_pkts (pkts, count); } -for (i =0 ; i < count; ++i) { -virtio_tx_route (vdev, pkts[i], - vlan_tags[(uint16_t )vdev->dev->device_fh]); - } +for (i =0 ; i < count; ++i) +virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->device_fh]); }/*
@@ -1208,7 +1204,7 @@ destroy_device (volatile struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been removed from data core\n" , - dev->device_fh); + vdev->device_fh);rte_free (vdev); }
@@ -1223,20 +1219,21 @@ new_device (struct virtio_net *dev)int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; +int device_fh = dev->device_fh; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA , -"(%d) Couldn't allocate memory for vhost dev\n" , - dev->device_fh); +"(%d) couldn't allocate memory for vhost dev\n" , + device_fh);return -1 ; } vdev->dev = dev; dev->priv = vdev; + vdev->device_fh = device_fh;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, next); - vdev->vmdq_rx_q - = dev->device_fh * queues_per_pool + vmdq_queue_base; + vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;/*reset ready flag*/ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1260,7 +1257,7 @@ new_device (struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been added to data core %d\n" , - dev->device_fh, vdev->coreid); + device_fh, vdev->coreid);return 0 ; }
examples/vhost/main.h +1 -0
@@ -66,6 +66,7 @@ struct vhost_dev {/**< Device is marked for removal from the data core. */ volatile uint8_t remove; +int device_fh;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) next; } __rte_cache_aligned;
Signature · 1 line
1.9.0
PATCH 5/16 vhost: rename device_fh to vid
In reply to Yuanhan LiuI failed to figure out what does "fh" mean here for a long while. The only guess I could have had is "file handle". So, you get the point that it's not well named.
I then figured it out that "fh" is derived from the fuse lib, and my above guess is right. However, device_fh represents a virtio net device ID. Therefore, here I rename it to vid (Virtio-net device ID, or Vhost device ID; choose one you prefer) to make it easier for understanding.
This name (vid) then will be considered to the only interface to applications. That's another reason to do the rename: it's our interface, make it more understandable.
--- examples/vhost/main.c | 44 +++++++++++++-------------- examples/vhost/main.h | 2 +- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/vhost-net.h | 6 ++-- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 36 +++++++++++----------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 6 ++-- lib/librte_vhost/vhost_rxtx.c | 22 +++++++------- lib/librte_vhost/vhost_user/vhost-net-user.c | 16 +++++----- lib/librte_vhost/vhost_user/virtio-net-user.c | 2 +- lib/librte_vhost/virtio-net.c | 30 +++++++++--------- 10 files changed, 83 insertions(+), 83 deletions(-)
examples/vhost/main.c +22 -22
@@ -717,7 +717,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) device is using a registered MAC!\n" , - vdev->device_fh); + vdev->vid);return -1 ; }
@@ -725,12 +725,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];/* vlan_tag currently uses the device_id. */ - vdev->vlan_tag = vlan_tags[vdev->device_fh]; + vdev->vlan_tag = vlan_tags[vdev->vid];/* Print out VMDQ registration info. */ RTE_LOG(INFO, VHOST_DATA, "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", - vdev->device_fh, + vdev->vid, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3], vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +738,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)/* Register the MAC address. */ ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, - (uint32_t )vdev->device_fh + vmdq_pool_base); + (uint32_t )vdev->vid + vmdq_pool_base);if (ret)RTE_LOG (ERR ,VHOST_DATA ,"(%d) failed to add device MAC address to VMDQ\n" , - vdev->device_fh); + vdev->vid);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -821,19 +821,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)if (!dst_vdev)return -1 ; -if (vdev->device_fh == dst_vdev->device_fh) { +if (vdev->vid == dst_vdev->vid) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - vdev->device_fh); + vdev->vid);return 0 ; }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC address is local\n" , dst_vdev->device_fh); +"(%d) TX: MAC address is local\n" , dst_vdev->vid);if (unlikely (dst_vdev->remove)) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) device is marked for removal\n" , dst_vdev->device_fh); +"(%d) device is marked for removal\n" , dst_vdev->vid);return 0 ; }
@@ -856,10 +856,10 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,if (!dst_vdev)return 0 ; -if (vdev->device_fh == dst_vdev->device_fh) { +if (vdev->vid == dst_vdev->vid) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - vdev->device_fh); + vdev->vid);return -1 ; }
@@ -869,11 +869,11 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,* the packet length by plus it. */ *offset =VLAN_HLEN ; - *vlan_tag = vlan_tags[vdev->device_fh]; + *vlan_tag = vlan_tags[vdev->vid];RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n" , - vdev->device_fh, dst_vdev->device_fh, *vlan_tag); + vdev->vid, dst_vdev->vid, *vlan_tag);return 0 ; }
@@ -964,7 +964,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC address is external\n" , vdev->device_fh); +"(%d) TX: MAC address is external\n" , vdev->vid); queue2nic:
@@ -1095,7 +1095,7 @@ drain_virtio_tx(struct vhost_dev *vdev) }for (i =0 ; i < count; ++i) -virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->device_fh]); +virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->vid]); }/*
@@ -1204,7 +1204,7 @@ destroy_device (volatile struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been removed from data core\n" , - vdev->device_fh); + vdev->vid);rte_free (vdev); }
@@ -1219,21 +1219,21 @@ new_device (struct virtio_net *dev)int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; -int device_fh = dev->device_fh; +int vid = dev->vid; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA ,"(%d) couldn't allocate memory for vhost dev\n" , - device_fh); + vid);return -1 ; } vdev->dev = dev; dev->priv = vdev; - vdev->device_fh = device_fh; + vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, next); - vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base; + vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;/*reset ready flag*/ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1257,7 +1257,7 @@ new_device (struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been added to data core %d\n" , - device_fh, vdev->coreid); + vid, vdev->coreid);return 0 ; }
@@ -1309,7 +1309,7 @@ print_stats(void)"RX total: %" PRIu64"\n" "RX dropped: %" PRIu64"\n" "RX successful: %" PRIu64"\n" , - vdev->dev->device_fh, + vdev->dev->vid, tx_total, tx_dropped, tx, rx_total, rx_dropped, rx); }
examples/vhost/main.h +1 -1
@@ -66,7 +66,7 @@ struct vhost_dev {/**< Device is marked for removal from the data core. */ volatile uint8_t remove; -int device_fh; +int vid;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) next; } __rte_cache_aligned;
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -133,7 +133,7 @@ struct virtio_net {struct virtio_memory *mem;/**< QEMU memory and memory region information. */ uint64_t features;/**< Negotiated feature set. */ uint64_t protocol_features;/**< Negotiated protocol feature set. */ -int device_fh;/**< device identifier. */ +int vid;/**< device identifier. */ uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */
lib/librte_vhost/vhost-net.h +3 -3
@@ -57,9 +57,9 @@char packet[VHOST_MAX_PRINT_BUFF ]; \ \if ((header)) \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->vid), (size)); \else \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->vid), (size)); \for (index =0 ; index < (size); index++) { \snprintf (packet +strnlen (packet,VHOST_MAX_PRINT_BUFF ),VHOST_MAX_PRINT_BUFF -strnlen (packet,VHOST_MAX_PRINT_BUFF ), \"%02hhx " , pkt_addr[index]); \
@@ -80,7 +80,7 @@*/ struct vhost_device_ctx {pid_t pid;/* PID of process calling the IOCTL. */ -int fh;/* Populated with fi->fh to track the device index. */ +int vid;/* Virtio-net device ID */ };int vhost_new_device (struct vhost_device_ctx );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +18 -18
@@ -70,7 +70,7 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)struct fuse_ctx const *const req_ctx =fuse_req_ctx (req); ctx.pid = req_ctx->pid; - ctx.fh = fi->fh; + ctx.vid = (int )fi->fh;return ctx; }
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) fi->fh = err;RTE_LOG (INFO ,VHOST_CONFIG , -"(%d) device configuration started\n" , fi->fh); +"(%d) device configuration started\n" , err);fuse_reply_open (req, fi); }
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx); -RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.vid);fuse_reply_err (req, err); }
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,switch (cmd) {case VHOST_NET_SET_BACKEND :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh); +"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.vid);if (!in_buf) {VHOST_IOCTL_RETRY (sizeof (file),0 );break ;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_GET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.vid);VHOST_IOCTL_W (uint64_t, features, vhost_get_features);break ;case VHOST_SET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.vid);VHOST_IOCTL_R (uint64_t, features, vhost_set_features);break ;case VHOST_RESET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.vid);VHOST_IOCTL (vhost_reset_owner);break ;case VHOST_SET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.vid);VHOST_IOCTL (vhost_set_owner);break ;case VHOST_SET_MEM_TABLE :/*TODO fix race condition.*/ LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.vid);static struct vhost_memory mem_temp;switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_NUM :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num);break ;case VHOST_SET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base);break ;case VHOST_GET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.vid);VHOST_IOCTL_RW (uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base);break ;case VHOST_SET_VRING_ADDR :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr);break ;
@@ -295,11 +295,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,if (cmd ==VHOST_SET_VRING_KICK )LOG_DEBUG (VHOST_CONFIG ,"(%d) IOCTL: VHOST_SET_VRING_KICK\n" , - ctx.fh); + ctx.vid);else LOG_DEBUG (VHOST_CONFIG ,"(%d) IOCTL: VHOST_SET_VRING_CALL\n" , - ctx.fh); + ctx.vid);if (!in_buf)VHOST_IOCTL_RETRY (sizeof (struct vhost_vring_file ),0 );else {
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,default :RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.fh); +"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.vid); result =-1 ;fuse_reply_ioctl (req, result,NULL ,0 ); }if (result <0 )LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: FAIL\n" , ctx.fh); +"(%d) IOCTL: FAIL\n" , ctx.vid);else LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: SUCCESS\n" , ctx.fh); +"(%d) IOCTL: SUCCESS\n" , ctx.vid); }/*
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +3 -3
@@ -290,7 +290,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to allocate memory for dev->mem\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -394,7 +394,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, intif (close (fd_tap) <0 )RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , - dev->device_fh); + dev->vid);if (ret >=0 ) { ifr_size =strnlen (ifr.ifr_name,sizeof (ifr.ifr_name));
@@ -402,7 +402,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int }else RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) TUNGETIFF ioctl failed\n" , - dev->device_fh); + dev->vid);return 0 ; }
lib/librte_vhost/vhost_rxtx.c +11 -11
@@ -264,10 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t desc_indexes[MAX_PKT_BURST ];uint32_t i; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -280,7 +280,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,return 0 ;LOG_DEBUG (VHOST_DATA ,"(%d) res_start_idx %d | res_end_idx Index %d\n" , - dev->device_fh, res_start_idx, res_end_idx); + dev->vid, res_start_idx, res_end_idx);/* Retrieve all of the desc indexes first to avoid caching issues. */ rte_prefetch0 (&vq->avail->ring[res_start_idx & (vq->size -1 )]);
@@ -442,7 +442,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,return 0 ;LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , - dev->device_fh, cur_idx, res_end_idx); + dev->vid, cur_idx, res_end_idx);if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)return -1 ;
@@ -452,7 +452,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, virtio_hdr.num_buffers = res_end_idx - res_start_idx;LOG_DEBUG (VHOST_DATA ,"(%d) RX: num merge buffers %d\n" , - dev->device_fh, virtio_hdr.num_buffers); + dev->vid, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr);copy_virtio_net_hdr (vq, desc_addr, virtio_hdr);
@@ -530,10 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint32_t pkt_idx =0 , nr_used =0 ;uint16_t start, end; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -552,7 +552,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, &start, &end) < 0)) {LOG_DEBUG (VHOST_DATA ,"(%d) failed to get enough desc from vring\n" , - dev->device_fh); + dev->vid);break ; }
@@ -828,7 +828,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -864,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (free_entries ==0 ) goto out; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);/* Prefetch available ring to retrieve head indexes. */ used_idx = vq->last_used_idx & (vq->size -1 );
@@ -873,7 +873,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, count =RTE_MIN (count,MAX_PKT_BURST ); count =RTE_MIN (count, free_entries);LOG_DEBUG (VHOST_DATA ,"(%d) about to dequeue %u buffers\n" , - dev->device_fh, count); + dev->vid, count);/* Retrieve all of the head indexes first to avoid caching issues. */ for (i =0 ; i < count; i++) {
lib/librte_vhost/vhost_user/vhost-net-user.c +8 -8
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);struct connfd_ctx {struct vhost_server *vserver; -uint32_t fh; +uint32_t vid; };#define MAX_VHOST_SERVER 1024
@@ -285,7 +285,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)struct vhost_server *vserver = (struct vhost_server *)dat;int conn_fd;struct connfd_ctx *ctx; -int fh; +int vid;struct vhost_device_ctx vdev_ctx = { (pid_t )0 ,0 };unsigned int size;
@@ -301,22 +301,22 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)return ; } - fh =vhost_new_device (vdev_ctx); -if (fh ==-1 ) { + vid =vhost_new_device (vdev_ctx); +if (vid ==-1 ) {free (ctx);close (conn_fd);return ; } - vdev_ctx.fh = fh; + vdev_ctx.vid = vid; size =strnlen (vserver->path,PATH_MAX );vhost_set_ifname (vdev_ctx, vserver->path, size); -RTE_LOG (INFO ,VHOST_CONFIG ,"new device, handle is %d\n" , fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"new device, handle is %d\n" , vid); ctx->vserver = vserver; - ctx->fh = fh; + ctx->vid = vid;fdset_add (&g_vhost_server.fdset, conn_fd, vserver_message_handler,NULL , ctx); }
@@ -331,7 +331,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)uint64_t features;int ret; - ctx.fh = cfd_ctx->fh; + ctx.vid = cfd_ctx->vid; ret =read_vhost_message (connfd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
lib/librte_vhost/vhost_user/virtio-net-user.c +1 -1
@@ -133,7 +133,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to allocate memory for dev->mem\n" , - dev->device_fh); + dev->vid);return -1 ; } dev->mem->nregions = memory.nregions;
lib/librte_vhost/virtio-net.c +15 -15
@@ -112,11 +112,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)struct virtio_net *get_device (struct vhost_device_ctx ctx) { -struct virtio_net *dev = vhost_devices[ctx.fh]; +struct virtio_net *dev = vhost_devices[ctx.vid];if (unlikely (!dev)) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) device not found.\n" , ctx.fh); +"(%d) device not found.\n" , ctx.vid); }return dev;
@@ -233,7 +233,7 @@ alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)/* * Reset some variables in device structure, while keeping few -* others untouched, such as device_fh, ifname, virt_qp_nb: they +* others untouched, such as vid, ifname, virt_qp_nb: they * should be same unless the device is removed. */ static void
@@ -263,7 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) failed to allocate memory for dev.\n" , ctx.fh); +"(%d) failed to allocate memory for dev.\n" , ctx.vid);return -1 ; }
@@ -278,7 +278,7 @@ vhost_new_device(struct vhost_device_ctx ctx) } vhost_devices[i] = dev; - dev->device_fh = i; + dev->vid = i;return i; }
@@ -303,7 +303,7 @@ vhost_destroy_device(struct vhost_device_ctx ctx)cleanup_device (dev,1 );free_device (dev); - vhost_devices[ctx.fh] =NULL ; + vhost_devices[ctx.vid] =NULL ; }void
@@ -407,7 +407,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) }LOG_DEBUG (VHOST_CONFIG ,"(%d) mergeable RX buffers %s, virtio 1 %s\n" , - dev->device_fh, + dev->vid, (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL <<VIRTIO_F_VERSION_1 )) ?"on" :"off" );
@@ -512,7 +512,7 @@ numa_realloc(struct virtio_net *dev, int index) out: dev->virtqueue[index] = vq; dev->virtqueue[index +1 ] = vq +1 ; - vhost_devices[dev->device_fh] = dev; + vhost_devices[dev->vid] = dev;return dev; }
@@ -548,7 +548,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->desc ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find desc ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -560,7 +560,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->avail ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find avail ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -569,20 +569,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->used ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find used ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; } vq->log_guest_addr = addr->log_guest_addr;LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address desc: %p\n" , - dev->device_fh, vq->desc); + dev->vid, vq->desc);LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address avail: %p\n" , - dev->device_fh, vq->avail); + dev->vid, vq->avail);LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address used: %p\n" , - dev->device_fh, vq->used); + dev->vid, vq->used);LOG_DEBUG (VHOST_CONFIG ,"(%d) log_guest_addr: %" PRIx64"\n" , - dev->device_fh, vq->log_guest_addr); + dev->vid, vq->log_guest_addr);return 0 ; }
Signature · 1 line
1.9.0
PATCH 6/16 vhost: get device by vid only
In reply to Yuanhan Liuget_device() just needs vid, so pass vid as the parameter only.
--- lib/librte_vhost/vhost-net.h | 30 ++++++------ lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 64 ++++++++++++------------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++--- lib/librte_vhost/vhost_user/vhost-net-user.c | 43 ++++++++--------- lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++------- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++--- lib/librte_vhost/virtio-net.c | 68 +++++++++++++-------------- lib/librte_vhost/virtio-net.h | 2 +- 8 files changed, 132 insertions(+), 147 deletions(-)
lib/librte_vhost/vhost-net.h +14 -16
@@ -83,28 +83,26 @@ struct vhost_device_ctx {int vid;/* Virtio-net device ID */ }; -int vhost_new_device (struct vhost_device_ctx ); -void vhost_destroy_device (struct vhost_device_ctx ); +int vhost_new_device (void ); +void vhost_destroy_device (int ); -void vhost_set_ifname (struct vhost_device_ctx , -const char *if_name,unsigned int if_len); +void vhost_set_ifname (int ,const char *if_name,unsigned int if_len); -int vhost_get_features (struct vhost_device_ctx ,uint64_t *); -int vhost_set_features (struct vhost_device_ctx ,uint64_t *); +int vhost_get_features (int ,uint64_t *); +int vhost_set_features (int ,uint64_t *); -int vhost_set_vring_num (struct vhost_device_ctx ,struct vhost_vring_state *); -int vhost_set_vring_addr (struct vhost_device_ctx ,struct vhost_vring_addr *); -int vhost_set_vring_base (struct vhost_device_ctx ,struct vhost_vring_state *); -int vhost_get_vring_base (struct vhost_device_ctx , -uint32_t ,struct vhost_vring_state *); +int vhost_set_vring_num (int ,struct vhost_vring_state *); +int vhost_set_vring_addr (int ,struct vhost_vring_addr *); +int vhost_set_vring_base (int ,struct vhost_vring_state *); +int vhost_get_vring_base (int ,uint32_t ,struct vhost_vring_state *); -int vhost_set_vring_kick (struct vhost_device_ctx ,struct vhost_vring_file *); -int vhost_set_vring_call (struct vhost_device_ctx ,struct vhost_vring_file *); +int vhost_set_vring_kick (int ,struct vhost_vring_file *); +int vhost_set_vring_call (int ,struct vhost_vring_file *); -int vhost_set_backend (struct vhost_device_ctx ,struct vhost_vring_file *); +int vhost_set_backend (int ,struct vhost_vring_file *); -int vhost_set_owner (struct vhost_device_ctx ); -int vhost_reset_owner (struct vhost_device_ctx ); +int vhost_set_owner (int ); +int vhost_reset_owner (int );/* * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +31 -33
213 lines not on this page · raw message
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +8 -10
@@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,uint64_t base_address =0 , mapped_address, mapped_size;struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (ctx.vid);if (dev ==NULL )return -1 ;
@@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,* save it in the device structure. */ static int -get_ifname (struct vhost_device_ctx ctx,struct virtio_net *dev,int tap_fd,int pid) +get_ifname (int vid,int tap_fd,int pid) {int fd_tap;struct ifreq ifr;
@@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret =ioctl (fd_tap,TUNGETIFF , &ifr);if (close (fd_tap) <0 ) -RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , - dev->vid); +RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , vid);if (ret >=0 ) { ifr_size =strnlen (ifr.ifr_name,sizeof (ifr.ifr_name)); -vhost_set_ifname (ctx, ifr.ifr_name, ifr_size); +vhost_set_ifname (vid, ifr.ifr_name, ifr_size); }else RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) TUNGETIFF ioctl failed\n" , - dev->vid); +"(%d) TUNGETIFF ioctl failed\n" , vid);return 0 ; }
@@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) {struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (ctx.vid);if (dev ==NULL )return -1 ;if (!(dev->flags &VIRTIO_DEV_RUNNING ) && file->fd !=VIRTIO_DEV_STOPPED ) -get_ifname (ctx, dev, file->fd, ctx.pid); +get_ifname (ctx.vid, file->fd, ctx.pid); -return vhost_set_backend (ctx, file); +return vhost_set_backend (ctx.vid, file); }void
lib/librte_vhost/vhost_user/vhost-net-user.c +20 -23
136 lines not on this page · raw message
lib/librte_vhost/vhost_user/virtio-net-user.c +18 -18
@@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev) }int -user_set_mem_table (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_mem_table (int vid,struct VhostUserMsg *pmsg) {struct VhostUserMemory memory = pmsg->payload.memory;struct virtio_memory_regions *pregion;
@@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)uint64_t alignment;/* unmap old memory regions one by one*/ - dev =get_device (ctx); + dev =get_device (vid);if (dev ==NULL )return -1 ;
@@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev) }void -user_set_vring_call (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_vring_call (int vid,struct VhostUserMsg *pmsg) {struct vhost_vring_file file;
@@ -265,7 +265,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) file.fd = pmsg->fds[0 ];RTE_LOG (INFO ,VHOST_CONFIG ,"vring call idx:%d file:%d\n" , file.index, file.fd); -vhost_set_vring_call (ctx, &file); +vhost_set_vring_call (vid, &file); }
@@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)* device is ready for packet processing. */ void -user_set_vring_kick (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_vring_kick (int vid,struct VhostUserMsg *pmsg) {struct vhost_vring_file file; -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid); file.index = pmsg->payload.u64 &VHOST_USER_VRING_IDX_MASK ;if (pmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK )
@@ -286,7 +286,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) file.fd = pmsg->fds[0 ];RTE_LOG (INFO ,VHOST_CONFIG ,"vring kick idx:%d file:%d\n" , file.index, file.fd); -vhost_set_vring_kick (ctx, &file); +vhost_set_vring_kick (vid, &file);if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) {if (notify_ops->new_device (dev) ==0 )
@@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)* when virtio is stopped, qemu will send us the GET_VRING_BASE message. */ int -user_get_vring_base (struct vhost_device_ctx ctx, +user_get_vring_base (int vid,struct vhost_vring_state *state) { -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid);if (dev ==NULL )return -1 ;
@@ -310,7 +310,7 @@ user_get_vring_base(struct vhost_device_ctx ctx, notify_ops->destroy_device (dev);/* Here we are safe to get the last used index */ -vhost_get_vring_base (ctx, state->index, state); +vhost_get_vring_base (vid, state->index, state);RTE_LOG (INFO ,VHOST_CONFIG ,"vring base idx:%d file:%d\n" , state->index, state->num);
@@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,* enable the virtio queue pair. */ int -user_set_vring_enable (struct vhost_device_ctx ctx, +user_set_vring_enable (int vid,struct vhost_vring_state *state) { -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid);int enable = (int )state->num; RTE_LOG(INFO, VHOST_CONFIG,
@@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx, }void -user_set_protocol_features (struct vhost_device_ctx ctx, +user_set_protocol_features (int vid,uint64_t protocol_features) {struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (vid);if (dev ==NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES )return ;
@@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx, }int -user_set_log_base (struct vhost_device_ctx ctx, +user_set_log_base (int vid,struct VhostUserMsg *msg) {struct virtio_net *dev;
@@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx,uint64_t size, off;void *addr; - dev =get_device (ctx); + dev =get_device (vid);if (!dev)return -1 ;
@@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx,* a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it. */ int -user_send_rarp (struct vhost_device_ctx ctx,struct VhostUserMsg *msg) +user_send_rarp (int vid,struct VhostUserMsg *msg) {struct virtio_net *dev;uint8_t *mac = (uint8_t *)&msg->payload.u64; - dev =get_device (ctx); + dev =get_device (vid);if (!dev)return -1 ;
lib/librte_vhost/vhost_user/virtio-net-user.h +8 -10
@@ -45,20 +45,18 @@ (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\ (1ULL << VHOST_USER_PROTOCOL_F_RARP)) -int user_set_mem_table (struct vhost_device_ctx ,struct VhostUserMsg *); +int user_set_mem_table (int ,struct VhostUserMsg *); -void user_set_vring_call (struct vhost_device_ctx ,struct VhostUserMsg *); +void user_set_vring_call (int ,struct VhostUserMsg *); -void user_set_vring_kick (struct vhost_device_ctx ,struct VhostUserMsg *); +void user_set_vring_kick (int ,struct VhostUserMsg *); -void user_set_protocol_features (struct vhost_device_ctx ctx, -uint64_t protocol_features); -int user_set_log_base (struct vhost_device_ctx ctx,struct VhostUserMsg *); -int user_send_rarp (struct vhost_device_ctx ctx,struct VhostUserMsg *); +void user_set_protocol_features (int vid,uint64_t protocol_features); +int user_set_log_base (int vid,struct VhostUserMsg *); +int user_send_rarp (int vid,struct VhostUserMsg *); -int user_get_vring_base (struct vhost_device_ctx ,struct vhost_vring_state *); +int user_get_vring_base (int ,struct vhost_vring_state *); -int user_set_vring_enable (struct vhost_device_ctx ctx, -struct vhost_vring_state *state); +int user_set_vring_enable (int vid,struct vhost_vring_state *state);#endif
lib/librte_vhost/virtio-net.c +32 -36
217 lines not on this page · raw message
lib/librte_vhost/virtio-net.h +1 -1
@@ -38,6 +38,6 @@#include "rte_virtio_net.h" struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (struct vhost_device_ctx ctx); +struct virtio_net *get_device (int vid);#endif
Signature · 1 line
1.9.0
PATCH 7/16 vhost: move vhost_device_ctx to cuse
In reply to Yuanhan Liuvhost cuse is now the last reference of the vhost_device_ctx struct; move it there, and do a rename to "vhost_cuse_device_ctx", to make it clear that it's "cuse only".
--- lib/librte_vhost/vhost-net.h | 8 -------- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 13 +++++++------ lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 6 ++++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 ++++++++++-- 4 files changed, 21 insertions(+), 18 deletions(-)
lib/librte_vhost/vhost-net.h +0 -8
@@ -75,14 +75,6 @@#endif -/* -* Structure used to identify device context. -*/ -struct vhost_device_ctx { -pid_t pid;/* PID of process calling the IOCTL. */ -int vid;/* Virtio-net device ID */ -}; -int vhost_new_device (void );void vhost_destroy_device (int );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +7 -6
@@ -60,13 +60,14 @@ static const char default_cdev[] = "vhost-net";static struct fuse_session *session;/* -* Returns vhost_device_ctx from given fuse_req_t. The index is populated later -* when the device is added to the device linked list. +* Returns vhost_cuse_device_ctx from given fuse_req_t. The +* index is populated later when the device is added to the +* device linked list. */ -static struct vhost_device_ctx +static struct vhost_cuse_device_ctx fuse_req_to_vhost_ctx (fuse_req_t req,struct fuse_file_info *fi) { -struct vhost_device_ctx ctx; +struct vhost_cuse_device_ctx ctx;struct fuse_ctx const *const req_ctx =fuse_req_ctx (req); ctx.pid = req_ctx->pid;
@@ -104,7 +105,7 @@ static void vhost_net_release(fuse_req_t req, struct fuse_file_info *fi) { int err = 0; -struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi); +struct vhost_cuse_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx.vid);RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.vid);
@@ -182,7 +183,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, struct fuse_file_info *fi, __rte_unused unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz) { - struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi); + struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);struct vhost_vring_file file;struct vhost_vring_state state;struct vhost_vring_addr addr;
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +4 -2
@@ -263,7 +263,7 @@ host_memory_map(pid_t pid, uint64_t addr, }int -cuse_set_mem_table (struct vhost_device_ctx ctx, +cuse_set_mem_table (struct vhost_cuse_device_ctx ctx,const struct vhost_memory *mem_regions_addr,uint32_t nregions) {uint64_t size = offsetof(struct vhost_memory , regions);
@@ -405,7 +405,9 @@ get_ifname(int vid, int tap_fd, int pid)return 0 ; } -int cuse_set_backend (struct vhost_device_ctx ctx,struct vhost_vring_file *file) +int +cuse_set_backend (struct vhost_cuse_device_ctx ctx, +struct vhost_vring_file *file) {struct virtio_net *dev;
lib/librte_vhost/vhost_cuse/virtio-net-cdev.h +10 -2
@@ -38,11 +38,19 @@#include "vhost-net.h" +/* +* Structure used to identify device context. +*/ +struct vhost_cuse_device_ctx { +pid_t pid;/* PID of process calling the IOCTL. */ +int vid;/* Virtio-net device ID */ +}; +int -cuse_set_mem_table (struct vhost_device_ctx ctx, +cuse_set_mem_table (struct vhost_cuse_device_ctx ctx,const struct vhost_memory *mem_regions_addr,uint32_t nregions);int -cuse_set_backend (struct vhost_device_ctx ctx,struct vhost_vring_file *); +cuse_set_backend (struct vhost_cuse_device_ctx ctx,struct vhost_vring_file *);#endif
Signature · 1 line
1.9.0
PATCH 8/16 vhost: query pmd internal by vid
In reply to Yuanhan LiuQuery internal by vid instead of "ifname", to avoid the dependency of virtio_net struct.
--- drivers/net/vhost/rte_eth_vhost.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +9 -10
@@ -86,6 +86,7 @@ struct vhost_queue { };struct pmd_internal { +int vid;char *dev_name;char *iface_name;uint16_t max_queues;
@@ -194,20 +195,17 @@ eth_dev_configure(struct rte_eth_dev *dev __rte_unused) }static inline struct internal_list * -find_internal_resource (char *ifname) +find_internal_resource (int vid) {int found =0 ;struct internal_list *list;struct pmd_internal *internal; -if (ifname ==NULL ) -return NULL ; -pthread_mutex_lock (&internal_list_lock); TAILQ_FOREACH(list, &internal_list, next) { internal = list->eth_dev->data->dev_private; -if (!strcmp (internal->iface_name, ifname)) { +if (internal->vid == vid) { found =1 ;break ; }
@@ -238,14 +236,15 @@ new_device(struct virtio_net *dev)return -1 ; } - list =find_internal_resource (dev->ifname); + list =find_internal_resource (dev->vid);if (list ==NULL ) { -RTE_LOG (INFO ,PMD ,"Invalid device name\n" ); +RTE_LOG (INFO ,PMD ,"Invalid vid %d\n" , dev->vid);return -1 ; } eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; + internal->vid = dev->vid;#ifdef RTE_LIBRTE_VHOST_NUMA ret = get_mempolicy(&newnode, NULL, 0, dev,
@@ -371,9 +370,9 @@ vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)return -1 ; } - list =find_internal_resource (dev->ifname); + list =find_internal_resource (dev->vid);if (list ==NULL ) { -RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , dev->ifname); +RTE_LOG (ERR ,PMD ,"Invalid vid %d\n" , dev->vid);return -1 ; }
@@ -884,7 +883,7 @@ rte_pmd_vhost_devuninit(const char *name)if (internal ==NULL )return -ENODEV ; - list =find_internal_resource (internal->iface_name); + list =find_internal_resource (internal->vid);if (list ==NULL )return -ENODEV ;
Signature · 1 line
1.9.0
PATCH 9/16 vhost: add few more functions
In reply to Yuanhan LiuAdd 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.
--- 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(-)
drivers/net/vhost/rte_eth_vhost.c +5 -13
@@ -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;
examples/vhost/main.c +2 -2
@@ -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 ; }
lib/librte_vhost/rte_virtio_net.h +37 -0
@@ -245,6 +245,43 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * consint 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
lib/librte_vhost/virtio-net.c +54 -0
60 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 10/16 vhost: export vid as the only interface to applications
In reply to Yuanhan LiuWith all the previous prepare works, we are just one step away from the final ABI refactoring. That is, to change current API to let them stick to vid instead of the old virtio_net dev.
--- drivers/net/vhost/rte_eth_vhost.c | 61 ++++++++++----------------- examples/vhost/main.c | 41 ++++++++++++------ lib/librte_vhost/rte_virtio_net.h | 30 +++++-------- lib/librte_vhost/vhost_rxtx.c | 15 ++++++- lib/librte_vhost/vhost_user/virtio-net-user.c | 14 +++--- lib/librte_vhost/virtio-net.c | 17 +++++--- 6 files changed, 91 insertions(+), 87 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +22 -39
@@ -68,9 +68,9 @@ static struct ether_addr base_eth_addr = { };struct vhost_queue { +int vid;rte_atomic32_t allow_queuing;rte_atomic32_t while_queuing; -struct virtio_net *device;struct pmd_internal *internal;struct rte_mempool *mb_pool;uint8_t port;
@@ -137,7 +137,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) goto out;/* Dequeue packets from guest TX queue */ - nb_rx =rte_vhost_dequeue_burst (r->device, + nb_rx =rte_vhost_dequeue_burst (r->vid, r->virtqueue_id, r->mb_pool, bufs, nb_bufs); r->rx_pkts += nb_rx;
@@ -168,7 +168,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) goto out;/* Enqueue packets to guest RX queue */ - nb_tx =rte_vhost_enqueue_burst (r->device, + nb_tx =rte_vhost_enqueue_burst (r->vid, r->virtqueue_id, bufs, nb_bufs); r->tx_pkts += nb_tx;
@@ -217,7 +217,7 @@ find_internal_resource(int vid) }static int -new_device (struct virtio_net *dev) +new_device (int vid) {struct rte_eth_dev *eth_dev;struct internal_list *list;
@@ -228,23 +228,17 @@ new_device(struct virtio_net *dev)int newnode;#endif -if (dev ==NULL ) { -RTE_LOG (INFO ,PMD ,"Invalid argument\n" ); -return -1 ; - } - - list =find_internal_resource (dev->vid); + list =find_internal_resource (vid);if (list ==NULL ) { -RTE_LOG (INFO ,PMD ,"Invalid vid %d\n" , dev->vid); +RTE_LOG (INFO ,PMD ,"Invalid vid %d\n" , vid);return -1 ; } eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; - internal->vid = dev->vid;#ifdef RTE_LIBRTE_VHOST_NUMA - newnode =rte_vhost_get_numa_node (dev->vid); + newnode =rte_vhost_get_numa_node (vid);if (newnode >0 ) eth_dev->data->numa_node = newnode;#endif
@@ -253,7 +247,7 @@ new_device(struct virtio_net *dev) vq = eth_dev->data->rx_queues[i];if (vq ==NULL )continue ; - vq->device = dev; + vq->vid = vid; vq->internal = internal; vq->port = eth_dev->data->port_id; }
@@ -261,15 +255,14 @@ new_device(struct virtio_net *dev) vq = eth_dev->data->tx_queues[i];if (vq ==NULL )continue ; - vq->device = dev; + vq->vid = vid; vq->internal = internal; vq->port = eth_dev->data->port_id; } -for (i =0 ; i <rte_vhost_get_queue_num (dev->vid) *VIRTIO_QNUM ; i++) -rte_vhost_enable_guest_notification (dev, i,0 ); +for (i =0 ; i <rte_vhost_get_queue_num (vid) *VIRTIO_QNUM ; i++) +rte_vhost_enable_guest_notification (vid, i,0 ); - dev->priv = eth_dev; eth_dev->data->dev_link.link_status =ETH_LINK_UP ;for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) {
@@ -293,22 +286,19 @@ new_device(struct virtio_net *dev) }static void -destroy_device (volatile struct virtio_net *dev) +destroy_device (int vid) { +struct internal_list *list;struct rte_eth_dev *eth_dev;struct vhost_queue *vq;unsigned i; -if (dev ==NULL ) { -RTE_LOG (INFO ,PMD ,"Invalid argument\n" ); -return ; - } - - eth_dev = (struct rte_eth_dev *)dev->priv; -if (eth_dev ==NULL ) { -RTE_LOG (INFO ,PMD ,"Failed to find a ethdev\n" ); + list =find_internal_resource (vid); +if (list ==NULL ) { +RTE_LOG (INFO ,PMD ,"Invalid vid %d\n" , vid);return ; } + eth_dev = list->eth_dev;/* Wait until rx/tx_pkt_burst stops accessing vhost device */ for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) {
@@ -330,19 +320,17 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status =ETH_LINK_DOWN ; - dev->priv =NULL ; -for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i];if (vq ==NULL )continue ; - vq->device =NULL ; + vq->vid =-1 ; }for (i =0 ; i < eth_dev->data->nb_tx_queues; i++) { vq = eth_dev->data->tx_queues[i];if (vq ==NULL )continue ; - vq->device =NULL ; + vq->vid =-1 ; }RTE_LOG (INFO ,PMD ,"Connection closed\n" );
@@ -351,20 +339,15 @@ destroy_device(volatile struct virtio_net *dev) }static int -vring_state_changed (struct virtio_net *dev,uint16_t vring,int enable) +vring_state_changed (int vid,uint16_t vring,int enable) {struct rte_vhost_vring_state *state;struct rte_eth_dev *eth_dev;struct internal_list *list; -if (dev ==NULL ) { -RTE_LOG (ERR ,PMD ,"Invalid argument\n" ); -return -1 ; - } - - list =find_internal_resource (dev->vid); + list =find_internal_resource (vid);if (list ==NULL ) { -RTE_LOG (ERR ,PMD ,"Invalid vid %d\n" , dev->vid); +RTE_LOG (ERR ,PMD ,"Invalid vid %d\n" , vid);return -1 ; }
examples/vhost/main.c +27 -14
109 lines not on this page · raw message
lib/librte_vhost/rte_virtio_net.h +10 -20
@@ -178,23 +178,12 @@ struct virtio_memory {* */ struct virtio_net_device_ops { -int (*new_device)(struct virtio_net *);/**< Add device. */ -void (*destroy_device)(volatile struct virtio_net *);/**< Remove device. */ +int (*new_device)(int vid);/**< Add device. */ +void (*destroy_device)(int vid);/**< Remove device. */ -int (*vring_state_changed)(struct virtio_net *dev,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ +int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ }; -static inline uint16_t __attribute__((always_inline)) -rte_vring_available_entries (struct virtio_net *dev,uint16_t queue_id) -{ -struct vhost_virtqueue *vq = dev->virtqueue[queue_id]; - -if (!vq->enabled) -return 0 ; - -return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res; -} -/** * Function to convert guest physical addresses to vhost virtual addresses. * This is used to convert guest virtio buffer addresses.
@@ -231,7 +220,7 @@ int rte_vhost_feature_enable(uint64_t feature_mask);/* Returns currently supported vhost features */ uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable); +int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/* Register vhost driver. dev_name could be different for multiple instance support. */ int rte_vhost_driver_register (const char *dev_name);
@@ -286,8 +275,8 @@ int rte_vhost_get_numa_node(int vid);* 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 * added to the RX queue. -* @param dev -* virtio-net device +* @param vid +* virtio-net device ID * @param queue_id * virtio queue index in mq case * @param pkts
@@ -297,14 +286,14 @@ int rte_vhost_get_numa_node(int vid);* @return * num of packets enqueued */ -uint16_t rte_vhost_enqueue_burst (struct virtio_net *dev,uint16_t queue_id, +uint16_t rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count);/** * This function gets guest buffers from the virtio device TX virtqueue, * construct host mbufs, copies guest buffer content to host mbufs and * store them in pkts to be processed. -* @param dev +* @param vid * virtio-net device * @param queue_id * virtio queue index in mq case
@@ -317,7 +306,8 @@ uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,* @return * num of packets dequeued */ -uint16_t rte_vhost_dequeue_burst (struct virtio_net *dev,uint16_t queue_id, +uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count); +#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost_rxtx.c +13 -2
@@ -46,6 +46,7 @@#include <rte_arp.h> #include "vhost-net.h" +#include "virtio-net.h" #define MAX_PKT_BURST 32#define VHOST_LOG_PAGE 4096
@@ -587,9 +588,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, }uint16_t -rte_vhost_enqueue_burst (struct virtio_net *dev,uint16_t queue_id, +rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count) { +struct virtio_net *dev =get_device (vid); + +if (!dev) +return 0 ; +if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF ))return virtio_dev_merge_rx (dev, queue_id, pkts, count);else
@@ -815,9 +821,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, }uint16_t -rte_vhost_dequeue_burst (struct virtio_net *dev,uint16_t queue_id, +rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) { +struct virtio_net *dev;struct rte_mbuf *rarp_mbuf =NULL ;struct vhost_virtqueue *vq;uint32_t desc_indexes[MAX_PKT_BURST ];
@@ -826,6 +833,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,uint16_t free_entries;uint16_t avail_idx; + dev =get_device (vid); +if (!dev) +return 0 ; +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);
lib/librte_vhost/vhost_user/virtio-net-user.c +8 -6
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)struct vhost_vring_file file;struct virtio_net *dev =get_device (vid); +if (!dev) +return ; + file.index = pmsg->payload.u64 &VHOST_USER_VRING_IDX_MASK ;if (pmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK ) file.fd =VIRTIO_INVALID_EVENTFD ;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)vhost_set_vring_kick (vid, &file);if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { -if (notify_ops->new_device (dev) ==0 ) +if (notify_ops->new_device (vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -307,7 +310,7 @@ user_get_vring_base(int vid,return -1 ;/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid);/* Here we are safe to get the last used index */ vhost_get_vring_base (vid, state->index, state);
@@ -342,9 +345,8 @@ user_set_vring_enable(int vid,"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) { - notify_ops->vring_state_changed (dev, state->index, enable); - } +if (notify_ops->vring_state_changed) + notify_ops->vring_state_changed (vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
lib/librte_vhost/virtio-net.c +11 -6
@@ -296,7 +296,7 @@ vhost_destroy_device(int vid)if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -353,7 +353,7 @@ vhost_reset_owner(int vid)if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }cleanup_device (dev,0 );
@@ -717,21 +717,26 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)if (!(dev->flags &VIRTIO_DEV_RUNNING )) {if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) { -if (notify_ops->new_device (dev) <0 ) +if (notify_ops->new_device (vid) <0 )return -1 ; dev->flags |=VIRTIO_DEV_RUNNING ; } }else if (file->fd ==VIRTIO_DEV_STOPPED ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }return 0 ; } -int rte_vhost_enable_guest_notification (struct virtio_net *dev, -uint16_t queue_id,int enable) +int +rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable) { +struct virtio_net *dev =get_device (vid); + +if (!dev) +return -1 ; +if (enable) {RTE_LOG (ERR ,VHOST_CONFIG ,"guest notification isn't supported.\n" );
Signature · 1 line
1.9.0
Re: [PATCH 10/16] vhost: export vid as the only interface to applications
Quoted 4 lines · Yuanhan Liu
With all the previous prepare works, we are just one step away from the final ABI refactoring. That is, to change current API to let them stick to vid instead of the old
virtio_netdev.
This patch removes the only assignment to internal->vid in the PMD. It's initialized to zero, so only the first vhost connection will work.
Re: [PATCH 10/16] vhost: export vid as the only interface to applications
Quoted 10 lines · Rich Lane
On Mon, May 2, 2016 at 3:25 PM, Yuanhan Liu <[email protected]> wrote:
With all the previous prepare works, we are just one step away from the final ABI refactoring. That is, to change current API to let them stick to vid instead of the old
virtio_netdev.This patch removes the only assignment to
internal->vidin the PMD. It's initialized to zero, so only the first vhost connection will work.
I assume you meant to following diff:
- if (dev == NULL) {
- RTE_LOG(INFO, PMD, "Invalid argument\n");
- return -1;
- }
-
- list = find_internal_resource(dev->vid);
+ list = find_internal_resource(vid);
if (list == NULL) {
- RTE_LOG(INFO, PMD, "Invalid vid %d\n", dev->vid);
+ RTE_LOG(INFO, PMD, "Invalid vid %d\n", vid);
return -1;
}
eth_dev = list->eth_dev;
internal = eth_dev->data->dev_private;- internal->vid = dev->vid;
Then yes, I have no idea why I did that; it's a careless and hard-to-catch issue. So, thanks a lot for catching it!
Rich, would you help try by adding following line there and do a test? It would be great if this patch has your Tested-by :)
internal->vid = vid;
Thanks.
--yliu
Re: [PATCH 10/16] vhost: export vid as the only interface to applications
Quoted 6 lines · Yuanhan Liu
Rich, would you help try by adding following line there and do a test? It would be great if this patch has your Tested-by :)
internal->vid = vid;
The problem is new_device has already returned before that point because find_internal_resource failed.
I suggest adding a cookie parameter to rte_vhost_driver_register and passing the cookie to each of the vhost_ops. The PMD can use pmd_internals for the cookie and the whole internal_list can go away.
ps. Could you push git branches somewhere for these larger vhost patch series? That would make it a lot easier to test than getting patches individually from patchwork.
Re: [PATCH 10/16] vhost: export vid as the only interface to applications
Quoted 11 lines · Rich Lane
On Tue, May 10, 2016 at 9:39 AM, Yuanhan Liu <[email protected]> wrote:
Rich, would you help try by adding following line there and do a test? It would be great if this patch has your Tested-by :)
internal->vid= vid;
The problem isnew_devicehas already returned before that point becausefind_internal_resourcefailed.
Oh. right.
Quoted 3 lines
I suggest adding a cookie parameter to rte_vhost_driver_register and passing the cookie to each of the
vhost_ops. The PMD can usepmd_internalsfor the cookie and the wholeinternal_listcan go away.
TBH, I don't quite like messing rte_vhost_driver_register here.
Maybe I could switch back to the old way to find_internal_resource by ifname. In such case, I need introduce an API to expose that field from vhost lib.
Quoted 3 lines
ps. Could you push git branches somewhere for these larger vhost patch series? That would make it a lot easier to test than getting patches individually from patchwork.
Yes, indeeded. And I have a tree on dpdk.org, but that is mainly for holding patches for the mainline. I'm thinking I may could add a new branch there, say staging, just for testing. Thomas, will it work for you? Or, should I push it to github?
--yliu
Re: [PATCH 10/16] vhost: export vid as the only interface to applications
2016-05-10 10:29, Yuanhan Liu:
Quoted 9 lines · Rich Lane
Quoted 3 lines
ps. Could you push git branches somewhere for these larger vhost patch series? That would make it a lot easier to test than getting patches individually from patchwork.
Yes, indeeded. And I have a tree on dpdk.org, but that is mainly for holding patches for the mainline. I'm thinking I may could add a new branch there, say staging, just for testing. Thomas, will it work for you? Or, should I push it to github?
You are free to create the branches you like on dpdk.org.
PATCH 11/16 vhost: hide internal structs/macros/functions
In reply to Yuanhan LiuWe are now safe to move all those internal structs/macros/functions to vhost-net.h, to hide them from external access.
This patch also breaks long lines and removes some redundant comments.
--- lib/librte_vhost/rte_virtio_net.h | 128 ---------------------------------- lib/librte_vhost/vhost-net.h | 142 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 128 deletions(-)
lib/librte_vhost/rte_virtio_net.h +0 -128
@@ -65,111 +65,6 @@ struct rte_mbuf;/* Enum for virtqueue management. */ enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; -#define BUF_VECTOR_MAX 256 - -/** -* Structure contains buffer address, length and descriptor index -* from vring to do scatter RX. -*/ -struct buf_vector { -uint64_t buf_addr; -uint32_t buf_len; -uint32_t desc_idx; -}; - -/** -* Structure contains variables relevant to RX/TX virtqueues. -*/ -struct vhost_virtqueue { -struct vring_desc *desc;/**< Virtqueue descriptor ring. */ -struct vring_avail *avail;/**< Virtqueue available ring. */ -struct vring_used *used;/**< Virtqueue used ring. */ -uint32_t size;/**< Size of descriptor ring. */ -int backend;/**< Backend value to determine if device should started/stopped. */ -uint16_t vhost_hlen;/**< Vhost header length (varies depending on RX merge buffers. */ -volatile uint16_t last_used_idx;/**< Last index used on the available ring */ -volatile uint16_t last_used_idx_res;/**< Used for multiple devices reserving buffers. */ -#define VIRTIO_INVALID_EVENTFD (-1) -#define VIRTIO_UNINITIALIZED_EVENTFD (-2) -int callfd;/**< Used to notify the guest (trigger interrupt). */ -int kickfd;/**< Currently unused as polling mode is enabled. */ -int enabled; -uint64_t log_guest_addr;/**< Physical address of used ring, for logging */ -uint64_t reserved[15 ];/**< Reserve some spaces for future extension. */ -struct buf_vector buf_vec[BUF_VECTOR_MAX ];/**< for scatter RX. */ -} __rte_cache_aligned; - -/* Old kernels have no such macro defined */ -#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE -#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 -#endif - - -/* -* Make an extra wrapper for VIRTIO_NET_F_MQ and -* VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are -* introduced since kernel v3.8. This makes our -* code buildable for older kernel. -*/ -#ifdef VIRTIO_NET_F_MQ -#define VHOST_MAX_QUEUE_PAIRS VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX -#define VHOST_SUPPORTS_MQ (1ULL << VIRTIO_NET_F_MQ) -#else -#define VHOST_MAX_QUEUE_PAIRS 1 -#define VHOST_SUPPORTS_MQ 0 -#endif - -/* -* Define virtio 1.0 for older kernels -*/ -#ifndef VIRTIO_F_VERSION_1 -#define VIRTIO_F_VERSION_1 32 -#endif - -/** -* Device structure contains all configuration information relating to the device. -*/ -struct virtio_net { -struct virtio_memory *mem;/**< QEMU memory and memory region information. */ -uint64_t features;/**< Negotiated feature set. */ -uint64_t protocol_features;/**< Negotiated protocol feature set. */ -int vid;/**< device identifier. */ -uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ -#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) -char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */ -uint32_t virt_qp_nb;/**< number of queue pair we have allocated */ -void *priv;/**< private context */ -uint64_t log_size;/**< Size of log area */ -uint64_t log_base;/**< Where dirty pages are logged */ -struct ether_addr mac;/**< MAC address */ -rte_atomic16_t broadcast_rarp;/**< A flag to tell if we need broadcast rarp packet */ -uint64_t reserved[61 ];/**< Reserve some spaces for future extension. */ -struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ];/**< Contains all virtqueue information. */ -} __rte_cache_aligned; - -/** -* Information relating to memory regions including offsets to addresses in QEMUs memory file. -*/ -struct virtio_memory_regions { -uint64_t guest_phys_address;/**< Base guest physical address of region. */ -uint64_t guest_phys_address_end;/**< End guest physical address of region. */ -uint64_t memory_size;/**< Size of region. */ -uint64_t userspace_address;/**< Base userspace address of region. */ -uint64_t address_offset;/**< Offset of region for address translation. */ -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint64_t base_address;/**< Base QEMU userspace address of the memory file. */ -uint64_t mapped_address;/**< Mapped address of memory file base in our applications memory space. */ -uint64_t mapped_size;/**< Total size of memory file. */ -uint32_t nregions;/**< Number of memory regions. */ -struct virtio_memory_regions regions[0 ];/**< Memory region information. */ -}; -/** * Device and vring operations. *
@@ -185,29 +80,6 @@ struct virtio_net_device_ops { };/** -* Function to convert guest physical addresses to vhost virtual addresses. -* This is used to convert guest virtio buffer addresses. -*/ -static inline uint64_t __attribute__((always_inline)) -gpa_to_vva (struct virtio_net *dev,uint64_t guest_pa) -{ -struct virtio_memory_regions *region; -uint32_t regionidx; -uint64_t vhost_va =0 ; - -for (regionidx =0 ; regionidx < dev->mem->nregions; regionidx++) { - region = &dev->mem->regions[regionidx]; -if ((guest_pa >= region->guest_phys_address) && - (guest_pa <= region->guest_phys_address_end)) { - vhost_va = region->address_offset + guest_pa; -break ; - } - } -return vhost_va; -} - - -/** * Disable features in feature_mask. Returns 0 on success. */ int rte_vhost_feature_disable (uint64_t feature_mask);
lib/librte_vhost/vhost-net.h +142 -0
154 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 12/16 vhost: remove unnecessary fields
In reply to Yuanhan LiuThe "reserved" field in virtio_net and vhost_virtqueue struct is not necessary any more. We now expose virtio_net device with a number "vid".
This patch also removes the "priv" field: all fields are priviate now:
application can't access it now. The only way that we could still access it is to expose it by a function, but I doubt that's needed or worthwhile.
--- lib/librte_vhost/vhost-net.h | 3 --- 1 file changed, 3 deletions(-)
lib/librte_vhost/vhost-net.h +0 -3
@@ -82,7 +82,6 @@ struct vhost_virtqueue {/* Physical address of used ring, for logging */ uint64_t log_guest_addr; -uint64_t reserved[15 ];struct buf_vector buf_vec[BUF_VECTOR_MAX ]; } __rte_cache_aligned;
@@ -127,14 +126,12 @@ struct virtio_net {#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];uint32_t virt_qp_nb; -void *priv;uint64_t log_size;uint64_t log_base;struct ether_addr mac;/* to tell if we need broadcast rarp packet */ rte_atomic16_t broadcast_rarp; -uint64_t reserved[61 ];struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned;
Signature · 1 line
1.9.0
PATCH 13/16 vhost: remove virtio-net.h
In reply to Yuanhan LiuIt barely has anything useful there, just 2 functions prototype. Here move them to vhost-net.h, and delete it.
--- lib/librte_vhost/vhost-net.h | 3 ++ lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 1 - lib/librte_vhost/vhost_rxtx.c | 1 - lib/librte_vhost/vhost_user/virtio-net-user.c | 1 - lib/librte_vhost/virtio-net.c | 1 - lib/librte_vhost/virtio-net.h | 43 --------------------------- 6 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.h
lib/librte_vhost/vhost-net.h +3 -0
@@ -214,6 +214,9 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)return vhost_va; } +struct virtio_net_device_ops const *notify_ops; +struct virtio_net *get_device (int vid); +int vhost_new_device (void );void vhost_destroy_device (int );
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +0 -1
@@ -54,7 +54,6 @@#include "rte_virtio_net.h" #include "vhost-net.h" #include "virtio-net-cdev.h" -#include "virtio-net.h" #include "eventfd_copy.h" /* Line size for reading maps file. */
lib/librte_vhost/vhost_rxtx.c +0 -1
@@ -46,7 +46,6 @@#include <rte_arp.h> #include "vhost-net.h" -#include "virtio-net.h" #define MAX_PKT_BURST 32#define VHOST_LOG_PAGE 4096
lib/librte_vhost/vhost_user/virtio-net-user.c +0 -1
@@ -43,7 +43,6 @@#include <rte_common.h> #include <rte_log.h> -#include "virtio-net.h" #include "virtio-net-user.h" #include "vhost-net-user.h" #include "vhost-net.h"
lib/librte_vhost/virtio-net.c +0 -1
@@ -53,7 +53,6 @@#include <rte_virtio_net.h> #include "vhost-net.h" -#include "virtio-net.h" #define MAX_VHOST_DEVICE 1024static struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ];
lib/librte_vhost/virtio-net.h deleted +0 -43
43 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 14/16 vhost: reserve few more space for future extension
In reply to Yuanhan Liu"virtio_net_device_ops" is the only left open struct that an application can access, therefore, it's the only place that might introduce potential ABI break in future for extension.
So, do some reservation for it. 5 should be pretty enough, considering that we have barely touched it for a long while. Another reason to choose 5 is for cache alignment: 5 makes the struct 64 bytes for 64 bit machine.
With this, it's confidence to say that we might be able to be free from the ABI violation forever.
--- lib/librte_vhost/rte_virtio_net.h | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_vhost/rte_virtio_net.h +2 -0
@@ -77,6 +77,8 @@ struct virtio_net_device_ops {void (*destroy_device)(int vid);/**< Remove device. */ int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ + +void *reserved[5 ];/**< Reserved for future extension */ };/**
Signature · 1 line
1.9.0
PATCH 15/16 vhost: per device vhost_hlen
In reply to Yuanhan LiuVirtio net header length is set per device, but not per queue. So, there is no reason to store it in vhost_virtqueue struct, instead, we should store it in virtio_net struct, to make one copy only.
--- lib/librte_vhost/vhost-net.h | 2 +- lib/librte_vhost/vhost_rxtx.c | 40 ++++++++++++++++++++-------------------- lib/librte_vhost/virtio-net.c | 13 ++----------- 3 files changed, 23 insertions(+), 32 deletions(-)
lib/librte_vhost/vhost-net.h +1 -1
@@ -63,7 +63,6 @@ struct vhost_virtqueue {struct vring_avail *avail;struct vring_used *used;uint32_t size; -uint16_t vhost_hlen;/* Last index used on the available ring */ volatile uint16_t last_used_idx;
@@ -123,6 +122,7 @@ struct virtio_net {uint64_t protocol_features;int vid;uint32_t flags; +uint16_t vhost_hlen;#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];uint32_t virt_qp_nb;
lib/librte_vhost/vhost_rxtx.c +20 -20
@@ -126,10 +126,10 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr) }static inline void -copy_virtio_net_hdr (struct vhost_virtqueue *vq,uint64_t desc_addr, +copy_virtio_net_hdr (struct virtio_net *dev,uint64_t desc_addr,struct virtio_net_hdr_mrg_rxbuf hdr) { -if (vq->vhost_hlen ==sizeof (struct virtio_net_hdr_mrg_rxbuf )) +if (dev->vhost_hlen ==sizeof (struct virtio_net_hdr_mrg_rxbuf )) *(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t )desc_addr = hdr;else *(struct virtio_net_hdr *)(uintptr_t )desc_addr = hdr.hdr;
@@ -147,19 +147,19 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0 ,0 ,0 ,0 ,0 ,0 },0 }; desc = &vq->desc[desc_idx]; -if (unlikely (desc->len < vq->vhost_hlen)) +if (unlikely (desc->len < dev->vhost_hlen))return -1 ; desc_addr =gpa_to_vva (dev, desc->addr);rte_prefetch0 ((void *)(uintptr_t )desc_addr);virtio_enqueue_offload (m, &virtio_hdr.hdr); -copy_virtio_net_hdr (vq, desc_addr, virtio_hdr); -vhost_log_write (dev, desc->addr, vq->vhost_hlen); -PRINT_PACKET (dev, (uintptr_t )desc_addr, vq->vhost_hlen,0 ); +copy_virtio_net_hdr (dev, desc_addr, virtio_hdr); +vhost_log_write (dev, desc->addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); - desc_offset = vq->vhost_hlen; - desc_avail = desc->len - vq->vhost_hlen; + desc_offset = dev->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; *copied =rte_pktmbuf_pkt_len (m); mbuf_avail =rte_pktmbuf_data_len (m);
@@ -300,9 +300,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, vq->used->ring[used_idx].id = desc_idx;if (unlikely (err)) - vq->used->ring[used_idx].len = vq->vhost_hlen; + vq->used->ring[used_idx].len = dev->vhost_hlen;else - vq->used->ring[used_idx].len = copied + vq->vhost_hlen; + vq->used->ring[used_idx].len = copied + dev->vhost_hlen;vhost_log_used_vring (dev, vq, offsetof(struct vring_used, ring[used_idx]), sizeof(vq->used->ring[used_idx]));
@@ -444,7 +444,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , dev->vid, cur_idx, res_end_idx); -if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen) +if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)return -1 ; desc_addr =gpa_to_vva (dev, vq->buf_vec[vec_idx].buf_addr);
@@ -455,12 +455,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, dev->vid, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr); -copy_virtio_net_hdr (vq, desc_addr, virtio_hdr); -vhost_log_write (dev, vq->buf_vec[vec_idx].buf_addr, vq->vhost_hlen); -PRINT_PACKET (dev, (uintptr_t )desc_addr, vq->vhost_hlen,0 ); +copy_virtio_net_hdr (dev, desc_addr, virtio_hdr); +vhost_log_write (dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); - desc_avail = vq->buf_vec[vec_idx].buf_len - vq->vhost_hlen; - desc_offset = vq->vhost_hlen; + desc_avail = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; mbuf_avail =rte_pktmbuf_data_len (m); mbuf_offset =0 ;
@@ -546,7 +546,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,return 0 ;for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) { -uint32_t pkt_len = pkts[pkt_idx]->pkt_len + vq->vhost_hlen; +uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;if (unlikely (reserve_avail_buf_mergeable (vq, pkt_len, &start, &end) <0 )) {
@@ -747,7 +747,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,uint32_t nr_desc =1 ; desc = &vq->desc[desc_idx]; -if (unlikely (desc->len < vq->vhost_hlen)) +if (unlikely (desc->len < dev->vhost_hlen))return -1 ; desc_addr =gpa_to_vva (dev, desc->addr);
@@ -755,8 +755,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,/* Retrieve virtio net header */ hdr = (struct virtio_net_hdr *)((uintptr_t )desc_addr); - desc_avail = desc->len - vq->vhost_hlen; - desc_offset = vq->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; mbuf_offset =0 ; mbuf_avail = m->buf_len -RTE_PKTMBUF_HEADROOM ;
lib/librte_vhost/virtio-net.c +2 -11
@@ -386,8 +386,6 @@ int vhost_set_features(int vid, uint64_t *pu) { struct virtio_net *dev; -uint16_t vhost_hlen; -uint16_t i; dev =get_device (vid);if (dev ==NULL )
@@ -398,9 +396,9 @@ vhost_set_features(int vid, uint64_t *pu) dev->features = *pu;if (dev->features & ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) { - vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); + dev->vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); }else { - vhost_hlen =sizeof (struct virtio_net_hdr ); + dev->vhost_hlen =sizeof (struct virtio_net_hdr ); } LOG_DEBUG(VHOST_CONFIG, "(%d) mergeable RX buffers %s, virtio 1 %s\n",
@@ -408,13 +406,6 @@ vhost_set_features(int vid, uint64_t *pu) (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off"); -for (i =0 ; i < dev->virt_qp_nb; i++) { -uint16_t base_idx = i *VIRTIO_QNUM ; - - dev->virtqueue[base_idx +VIRTIO_RXQ ]->vhost_hlen = vhost_hlen; - dev->virtqueue[base_idx +VIRTIO_TXQ ]->vhost_hlen = vhost_hlen; - } -return 0 ; }
Signature · 1 line
1.9.0
PATCH 16/16 vhost: make buf vector for scatter Rx local
In reply to Yuanhan LiuFrom: Ilya Maximets <[email protected]>
Array of buf_vector's is just an array for temporary storing information about available descriptors. It used only locally in virtio_dev_merge_rx() and there is no reason for that array to be shared.
Fix that by allocating local buf_vec inside virtio_dev_merge_rx().
--- lib/librte_vhost/vhost-net.h | 1 - lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-)
lib/librte_vhost/vhost-net.h +0 -1
@@ -81,7 +81,6 @@ struct vhost_virtqueue {/* Physical address of used ring, for logging */ uint64_t log_guest_addr; -struct buf_vector buf_vec[BUF_VECTOR_MAX ]; } __rte_cache_aligned;/* Old kernels have no such macro defined */
lib/librte_vhost/vhost_rxtx.c +22 -19
133 lines not on this page · raw message
Signature · 1 line
1.9.0
v2 cover vhost ABI/API refactoring
In reply to Yuanhan Liuv2: - exported ifname as well to fix a vhost-pmd issue reported
by Rich
- separated the big patch that introduces several new APIs into some small patches.
- updated release note
- updated version.map
NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]: git://dpdk.org/next/dpdk-next-virtio for-testing
Every time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf from vhost_virtqueue struct) also break ABI.
This patch set is meant to resolve above issue ultimately, by hiding virtio_net structure (as well as few others) internaly, and export the virtio_net dev strut to applications by a number, vid, like the way kernel exposes an fd to user space.
Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".
After that, "vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more (5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.
The last bit of this patch set is some cleanups, including the one from Ilya.
Note that this refactoring breaks the tep_termination example. Well, it's just another copy of the original messy vhost example, and I have no interest to cleanup it again. Therefore, I might consider to remove that example later, and add the vxlan bits into vhost example.
Thanks.
--yliu
---
Ilya Maximets (1):
vhost: make buf vector for scatter Rx local
Yuanhan Liu (18):
vhost: declare backend with int type
vhost: set/reset dev flags internally
vhost: declare device fh as int examples/vhost: make a copy of virtio device id
vhost: rename device fh to vid
vhost: get device by vid only
vhost: move vhost device ctx to cuse
vhost: introduce new API to export numa node
vhost: introduce new API to export number of queues
vhost: introduce new API to export ifname
vhost: introduce new API to export queue free entries
vhost: remove dependency on priv field
vhost: export vid as the only interface to applications
vhost: hide internal structs/macros/functions
vhost: remove unnecessary fields
vhost: remove virtio-net.h
vhost: reserve few more space for future extension
vhost: per device virtio net header len
doc/guides/rel_notes/release_16_07.rst | 9 + drivers/net/vhost/rte_eth_vhost.c | 79 ++++----- examples/vhost/main.c | 124 +++++++------- examples/vhost/main.h | 1 + lib/librte_vhost/rte_vhost_version.map | 10 ++ lib/librte_vhost/rte_virtio_net.h | 223 +++++++------------------ lib/librte_vhost/vhost-net.h | 201 ++++++++++++++++++---- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 83 +++++----- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 30 ++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 +- lib/librte_vhost/vhost_rxtx.c | 133 ++++++++------- lib/librte_vhost/vhost_user/vhost-net-user.c | 53 +++--- lib/librte_vhost/vhost_user/vhost-net-user.h | 2 + lib/librte_vhost/vhost_user/virtio-net-user.c | 64 +++---- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 +- lib/librte_vhost/virtio-net.c | 229 +++++++++++++++++--------- lib/librte_vhost/virtio-net.h | 43 ----- 17 files changed, 702 insertions(+), 612 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.h
Signature · 1 line
1.9.0
PATCH v2 1/19 vhost: declare backend with int type
It's an fd; so define it as "int", which could also save the unncessary (int) case.
--- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/virtio-net.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -85,7 +85,7 @@ struct vhost_virtqueue {struct vring_avail *avail;/**< Virtqueue available ring. */ struct vring_used *used;/**< Virtqueue used ring. */ uint32_t size;/**< Size of descriptor ring. */ -uint32_t backend;/**< Backend value to determine if device should started/stopped. */ +int backend;/**< Backend value to determine if device should started/stopped. */ uint16_t vhost_hlen;/**< Vhost header length (varies depending on RX merge buffers. */ volatile uint16_t last_used_idx;/**< Last index used on the available ring */ volatile uint16_t last_used_idx_res;/**< Used for multiple devices reserving buffers. */
lib/librte_vhost/virtio-net.c +2 -2
@@ -717,8 +717,8 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)* we add the device. */ if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (((int )dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED ) && - ((int )dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED )) { +if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && + dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) {return notify_ops->new_device (dev); }/* Otherwise we remove it. */
Signature · 1 line
1.9.0
PATCH v2 2/19 vhost: set/reset dev flags internally
In reply to Yuanhan LiuIt does not make sense to ask the application to set/unset the flag VIRTIO_DEV_RUNNING (that used internal only) at new_device()/ destroy_device() callback.
Instead, it should be set after new_device() succeeds and reset before destroy_device() is invoked inside vhost lib. This patch fixes it.
--- drivers/net/vhost/rte_eth_vhost.c | 2 -- examples/vhost/main.c | 3 --- lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++---- lib/librte_vhost/virtio-net.c | 21 ++++++++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +0 -2
@@ -278,7 +278,6 @@ new_device(struct virtio_net *dev)for (i =0 ; i < dev->virt_qp_nb *VIRTIO_QNUM ; i++)rte_vhost_enable_guest_notification (dev, i,0 ); - dev->flags |=VIRTIO_DEV_RUNNING ; dev->priv = eth_dev; eth_dev->data->dev_link.link_status =ETH_LINK_UP ;
@@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status =ETH_LINK_DOWN ; dev->priv =NULL ; - dev->flags &= ~VIRTIO_DEV_RUNNING ;for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i];
examples/vhost/main.c +0 -3
@@ -1179,8 +1179,6 @@ destroy_device (volatile struct virtio_net *dev)struct vhost_dev *vdev;int lcore; - dev->flags &= ~VIRTIO_DEV_RUNNING ; - vdev = (struct vhost_dev *)dev->priv;/*set the remove flag. */ vdev->remove =1 ;
@@ -1257,7 +1255,6 @@ new_device (struct virtio_net *dev)/* Disable notifications. */ rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 );rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); - dev->flags |=VIRTIO_DEV_RUNNING ;RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , dev->device_fh, vdev->coreid);
lib/librte_vhost/vhost_user/virtio-net-user.c +7 -4
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)return -1 ;/* Remove from the data plane. */ -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }if (dev->mem) {free_mem_region (dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) "vring kick idx:%d file:%d\n", file.index, file.fd);vhost_set_vring_kick (ctx, &file); -if (virtio_is_ready (dev) && - !(dev->flags &VIRTIO_DEV_RUNNING )) - notify_ops->new_device (dev); +if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { +if (notify_ops->new_device (dev) ==0 ) + dev->flags |=VIRTIO_DEV_RUNNING ; + } }/*
lib/librte_vhost/virtio-net.c +14 -7
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)if (dev ==NULL )return ; -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }cleanup_device (dev,1 );free_device (dev);
@@ -353,8 +355,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)if (dev ==NULL )return -1 ; -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }cleanup_device (dev,0 );reset_device (dev);
@@ -719,12 +723,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)if (!(dev->flags &VIRTIO_DEV_RUNNING )) {if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) { -return notify_ops->new_device (dev); +if (notify_ops->new_device (dev) <0 ) +return -1 ; + dev->flags |=VIRTIO_DEV_RUNNING ; } -/* Otherwise we remove it. */ - }else -if (file->fd ==VIRTIO_DEV_STOPPED ) - notify_ops->destroy_device (dev); + }else if (file->fd ==VIRTIO_DEV_STOPPED ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; + notify_ops->destroy_device (dev); + } +return 0 ; }
Signature · 1 line
1.9.0
PATCH v2 3/19 vhost: declare device fh as int
In reply to Yuanhan LiuFirstly, "int" would be big enough: we don't need 64 bit to represent a virtio-net device id. Secondly, this could let us avoid the ugly "%" PRIu64 ".." stuff.
And since ctx.fh is derived from device_fh, declare it as int, too.
--- examples/vhost/main.c | 45 ++++++++++++++------------- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/vhost-net.h | 8 ++--- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 34 ++++++++++---------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 7 ++--- lib/librte_vhost/vhost_rxtx.c | 34 +++++++++----------- lib/librte_vhost/vhost_user/vhost-net-user.c | 2 +- lib/librte_vhost/vhost_user/virtio-net-user.c | 2 +- lib/librte_vhost/virtio-net.c | 21 ++++++------- 9 files changed, 75 insertions(+), 80 deletions(-)
examples/vhost/main.c +24 -21
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA , -"Device (%" PRIu64") is using a registered MAC!\n" , +"(%d) device is using a registered MAC!\n" , dev->device_fh);return -1 ; }
@@ -728,7 +728,8 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->vlan_tag = vlan_tags[dev->device_fh];/* Print out VMDQ registration info. */ - RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VLAN_TAG %d registered\n", + RTE_LOG(INFO, VHOST_DATA, + "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", dev->device_fh, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
@@ -739,8 +740,9 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, (uint32_t )dev->device_fh + vmdq_pool_base);if (ret) -RTE_LOG (ERR ,VHOST_DATA ,"(%" PRIu64") Failed to add device MAC address to VMDQ\n" , - dev->device_fh); +RTE_LOG (ERR ,VHOST_DATA , +"(%d) failed to add device MAC address to VMDQ\n" , + dev->device_fh);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -812,7 +814,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) {struct ether_hdr *pkt_hdr;struct vhost_dev *dst_vdev; -uint64_t fh; +int fh; pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -823,17 +825,16 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) fh = dst_vdev->dev->device_fh;if (fh == vdev->dev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: src and dst MAC is same. " -"Dropping packet.\n" , fh); +"(%d) TX: src and dst MAC is same. Dropping packet.\n" , + fh);return 0 ; } -RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: MAC address is local\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is local\n" , fh);if (unlikely (dst_vdev->remove)) { -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") " -"Device is marked for removal\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) device is marked for removal\n" , fh);return 0 ; }
@@ -858,8 +859,8 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,if (dst_vdev->dev->device_fh == dev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: src and dst MAC is same. " -" Dropping packet.\n" , dst_vdev->dev->device_fh); +"(%d) TX: src and dst MAC is same. Dropping packet.\n" , + dst_vdev->dev->device_fh);return -1 ; }
@@ -872,8 +873,7 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m, *vlan_tag = vlan_tags[(uint16_t )dst_vdev->dev->device_fh];RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: pkt to local VM device id: (%" PRIu64") " -"vlan tag: %u.\n" , +"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n" , dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);return 0 ;
@@ -964,8 +964,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) } } -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") TX: " -"MAC address is external\n" , dev->device_fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) TX: MAC is external\n" , dev->device_fh); queue2nic:
@@ -1206,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev) lcore_info[vdev->coreid].device_num--;RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") Device has been removed from data core\n" , +"(%d) device has been removed from data core\n" , dev->device_fh);rte_free (vdev);
@@ -1225,7 +1225,8 @@ new_device (struct virtio_net *dev) vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) { -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Couldn't allocate memory for vhost dev\n" , +RTE_LOG (INFO ,VHOST_DATA , +"(%d) Couldn't allocate memory for vhost dev\n" , dev->device_fh);return -1 ; }
@@ -1256,7 +1257,9 @@ new_device (struct virtio_net *dev)rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 );rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , dev->device_fh, vdev->coreid); +RTE_LOG (INFO ,VHOST_DATA , +"(%d) device has been added to data core %d\n" , + dev->device_fh, vdev->coreid);return 0 ; }
@@ -1300,7 +1303,7 @@ print_stats(void) rx =rte_atomic64_read (&vdev->stats.rx_atomic); rx_dropped = rx_total - rx; -printf ("Statistics for device %" PRIu64"\n" +printf ("Statistics for device %d\n" "-----------------------\n" "TX total: %" PRIu64"\n" "TX dropped: %" PRIu64 "\n"
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -133,7 +133,7 @@ struct virtio_net {struct virtio_memory *mem;/**< QEMU memory and memory region information. */ uint64_t features;/**< Negotiated feature set. */ uint64_t protocol_features;/**< Negotiated protocol feature set. */ -uint64_t device_fh;/**< device identifier. */ +int device_fh;/**< device identifier. */ uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */
lib/librte_vhost/vhost-net.h +4 -4
@@ -57,9 +57,9 @@char packet[VHOST_MAX_PRINT_BUFF ]; \ \if ((header)) \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%" PRIu64") Header size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->device_fh), (size)); \else \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%" PRIu64") Packet size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->device_fh), (size)); \for (index =0 ; index < (size); index++) { \snprintf (packet +strnlen (packet,VHOST_MAX_PRINT_BUFF ),VHOST_MAX_PRINT_BUFF -strnlen (packet,VHOST_MAX_PRINT_BUFF ), \"%02hhx " , pkt_addr[index]); \
@@ -79,8 +79,8 @@* Structure used to identify device context. */ struct vhost_device_ctx { -pid_t pid;/* PID of process calling the IOCTL. */ -uint64_t fh;/* Populated with fi->fh to track the device index. */ +pid_t pid;/* PID of process calling the IOCTL. */ +int fh;/* Populated with fi->fh to track the device index. */ };int vhost_new_device (struct vhost_device_ctx );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +17 -17
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) fi->fh = err;RTE_LOG (INFO ,VHOST_CONFIG , -"(%" PRIu64") Device configuration started\n" , fi->fh); +"(%d) device configuration started\n" , fi->fh);fuse_reply_open (req, fi); }
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx); -RTE_LOG (INFO ,VHOST_CONFIG ,"(%" PRIu64") Device released\n" , ctx.fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.fh);fuse_reply_err (req, err); }
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,switch (cmd) {case VHOST_NET_SET_BACKEND :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh); +"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh);if (!in_buf) {VHOST_IOCTL_RETRY (sizeof (file),0 );break ;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_GET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_GET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.fh);VHOST_IOCTL_W (uint64_t, features, vhost_get_features);break ;case VHOST_SET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.fh);VHOST_IOCTL_R (uint64_t, features, vhost_set_features);break ;case VHOST_RESET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_RESET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.fh);VHOST_IOCTL (vhost_reset_owner);break ;case VHOST_SET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.fh);VHOST_IOCTL (vhost_set_owner);break ;case VHOST_SET_MEM_TABLE :/*TODO fix race condition.*/ LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh);static struct vhost_memory mem_temp;switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_NUM :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num);break ;case VHOST_SET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base);break ;case VHOST_GET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh);VHOST_IOCTL_RW (uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base);break ;case VHOST_SET_VRING_ADDR :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr);break ;
@@ -294,11 +294,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_CALL :if (cmd ==VHOST_SET_VRING_KICK )LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_KICK\n" , +"(%d) IOCTL: VHOST_SET_VRING_KICK\n" , ctx.fh);else LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_CALL\n" , +"(%d) IOCTL: VHOST_SET_VRING_CALL\n" , ctx.fh);if (!in_buf)VHOST_IOCTL_RETRY (sizeof (struct vhost_vring_file ),0 );
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,default :RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") IOCTL: DOESN NOT EXIST\n" , ctx.fh); +"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.fh); result =-1 ;fuse_reply_ioctl (req, result,NULL ,0 ); }if (result <0 )LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: FAIL\n" , ctx.fh); +"(%d) IOCTL: FAIL\n" , ctx.fh);else LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: SUCCESS\n" , ctx.fh); +"(%d) IOCTL: SUCCESS\n" , ctx.fh); }/*
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +3 -4
@@ -289,7 +289,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx, sizeof(struct virtio_memory_regions) * nregions);if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev->mem\n" , +"(%d) failed to allocate memory for dev->mem\n" , dev->device_fh);return -1 ; }
@@ -393,8 +393,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret =ioctl (fd_tap,TUNGETIFF , &ifr);if (close (fd_tap) <0 ) -RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") fd close failed\n" , +RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , dev->device_fh);if (ret >=0 ) {
@@ -402,7 +401,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, intvhost_set_ifname (ctx, ifr.ifr_name, ifr_size); }else RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") TUNGETIFF ioctl failed\n" , +"(%d) TUNGETIFF ioctl failed\n" , dev->device_fh);return 0 ;
lib/librte_vhost/vhost_rxtx.c +14 -20
@@ -264,11 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t desc_indexes[MAX_PKT_BURST ];uint32_t i; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") virtio_dev_rx()\n" , dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -280,8 +279,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,if (count ==0 )return 0 ; -LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") res_start_idx %d| res_end_idx Index %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) res_start_idx %d | res_end_idx Index %d\n" , dev->device_fh, res_start_idx, res_end_idx);/* Retrieve all of the desc indexes first to avoid caching issues. */
@@ -443,8 +441,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,if (unlikely (m ==NULL ))return 0 ; -LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") Current Index %d| End Index %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , dev->device_fh, cur_idx, res_end_idx);if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
@@ -454,7 +451,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,rte_prefetch0 ((void *)(uintptr_t )desc_addr); virtio_hdr.num_buffers = res_end_idx - res_start_idx; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") RX: Num merge buffers %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) RX: num merge buffers %d\n" , dev->device_fh, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr);
@@ -533,12 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint32_t pkt_idx =0 , nr_used =0 ;uint16_t start, end; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") virtio_dev_merge_rx()\n" , - dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -556,7 +551,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (unlikely (reserve_avail_buf_mergeable (vq, pkt_len, &start, &end) <0 )) {LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") Failed to get enough desc from vring\n" , +"(%d) failed to get enough desc from vring\n" , dev->device_fh);break ; }
@@ -832,9 +827,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,uint16_t avail_idx;if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -870,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (free_entries ==0 ) goto out; -LOG_DEBUG (VHOST_DATA ,"%s (%" PRIu64")\n" , __func__, dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);/* Prefetch available ring to retrieve head indexes. */ used_idx = vq->last_used_idx & (vq->size -1 );
@@ -878,7 +872,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, count =RTE_MIN (count,MAX_PKT_BURST ); count =RTE_MIN (count, free_entries); -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") about to dequeue %u buffers\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) about to dequeue %u buffers\n" , dev->device_fh, count);/* Retrieve all of the head indexes first to avoid caching issues. */
lib/librte_vhost/vhost_user/vhost-net-user.c +1 -1
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);struct connfd_ctx {struct vhost_server *vserver; -uint32_t fh; +int fh; };#define MAX_VHOST_SERVER 1024
lib/librte_vhost/vhost_user/virtio-net-user.c +1 -1
@@ -132,7 +132,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) sizeof(struct orig_region_map) * memory.nregions);if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev->mem\n" , +"(%d) failed to allocate memory for dev->mem\n" , dev->device_fh);return -1 ; }
lib/librte_vhost/virtio-net.c +10 -11
@@ -116,7 +116,7 @@ get_device(struct vhost_device_ctx ctx)if (unlikely (!dev)) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") device not found.\n" , ctx.fh); +"(%d) device not found.\n" , ctx.fh); }return dev;
@@ -263,8 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev.\n" , - ctx.fh); +"(%d) failed to allocate memory for dev.\n" , ctx.fh);return -1 ; }
@@ -408,7 +407,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) vhost_hlen =sizeof (struct virtio_net_hdr ); }LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") Mergeable RX buffers %s, virtio 1 %s\n" , +"(%d) mergeable RX buffers %s, virtio 1 %s\n" , dev->device_fh, (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL <<VIRTIO_F_VERSION_1 )) ?"on" :"off" );
@@ -549,7 +548,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->desc_user_addr);if (vq->desc ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find desc ring address.\n" , +"(%d) failed to find desc ring address.\n" , dev->device_fh);return -1 ; }
@@ -561,7 +560,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->avail_user_addr);if (vq->avail ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find avail ring address.\n" , +"(%d) failed to find avail ring address.\n" , dev->device_fh);return -1 ; }
@@ -570,20 +569,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->used_user_addr);if (vq->used ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find used ring address.\n" , +"(%d) failed to find used ring address.\n" , dev->device_fh);return -1 ; } vq->log_guest_addr = addr->log_guest_addr; -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address desc: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address desc: %p\n" , dev->device_fh, vq->desc); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address avail: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address avail: %p\n" , dev->device_fh, vq->avail); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address used: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address used: %p\n" , dev->device_fh, vq->used); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") log_guest_addr: %" PRIx64"\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) log_guest_addr: %" PRIx64"\n" , dev->device_fh, vq->log_guest_addr);return 0 ;
Signature · 1 line
1.9.0
PATCH v2 4/19 examples/vhost: make a copy of virtio device id
In reply to Yuanhan LiuMake a copy of virtio device id (device_fh) from the virtio_net struct, so that we could have less dependency on the virtio_net struct.
--- examples/vhost/main.c | 59 ++++++++++++++++++++++++--------------------------- examples/vhost/main.h | 1 + 2 files changed, 29 insertions(+), 31 deletions(-)
examples/vhost/main.c +28 -31
@@ -708,7 +708,6 @@ static int link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) { struct ether_hdr *pkt_hdr; -struct virtio_net *dev = vdev->dev;int i, ret;/* Learn MAC address of guest device from packet */
@@ -717,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) device is using a registered MAC!\n" , - dev->device_fh); + vdev->device_fh);return -1 ; }
@@ -725,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];/* vlan_tag currently uses the device_id. */ - vdev->vlan_tag = vlan_tags[dev->device_fh]; + vdev->vlan_tag = vlan_tags[vdev->device_fh];/* Print out VMDQ registration info. */ RTE_LOG(INFO, VHOST_DATA, "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", - dev->device_fh, + vdev->device_fh, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3], vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)/* Register the MAC address. */ ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, - (uint32_t )dev->device_fh + vmdq_pool_base); + (uint32_t )vdev->device_fh + vmdq_pool_base);if (ret)RTE_LOG (ERR ,VHOST_DATA ,"(%d) failed to add device MAC address to VMDQ\n" , - dev->device_fh); + vdev->device_fh);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -814,7 +813,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) {struct ether_hdr *pkt_hdr;struct vhost_dev *dst_vdev; -int fh; pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -822,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)if (!dst_vdev)return -1 ; - fh = dst_vdev->dev->device_fh; -if (fh == vdev->dev->device_fh) { +if (vdev->device_fh == dst_vdev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - fh); + vdev->device_fh);return 0 ; } -RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is local\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) TX: MAC address is local\n" , dst_vdev->device_fh);if (unlikely (dst_vdev->remove)) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) device is marked for removal\n" , fh); +"(%d) device is marked for removal\n" , dst_vdev->device_fh);return 0 ; }
@@ -847,7 +845,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)* and get its vlan tag, and offset if it is. */ static inline int __attribute__((always_inline)) -find_local_dest (struct virtio_net *dev,struct rte_mbuf *m, +find_local_dest (struct vhost_dev *vdev,struct rte_mbuf *m,uint32_t *offset,uint16_t *vlan_tag) {struct vhost_dev *dst_vdev;
@@ -857,10 +855,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,if (!dst_vdev)return 0 ; -if (dst_vdev->dev->device_fh == dev->device_fh) { +if (vdev->device_fh == dst_vdev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - dst_vdev->dev->device_fh); + vdev->device_fh);return -1 ; }
@@ -870,11 +868,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,* the packet length by plus it. */ *offset =VLAN_HLEN ; - *vlan_tag = vlan_tags[(uint16_t )dst_vdev->dev->device_fh]; + *vlan_tag = vlan_tags[vdev->device_fh];RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n" , - dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag); +"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n" , + vdev->device_fh, dst_vdev->device_fh, *vlan_tag);return 0 ; }
@@ -937,7 +935,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)struct mbuf_table *tx_q;unsigned offset =0 ;const uint16_t lcore_id =rte_lcore_id (); -struct virtio_net *dev = vdev->dev;struct ether_hdr *nh;
@@ -958,14 +955,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) }if (unlikely (vm2vm_mode ==VM2VM_HARDWARE )) { -if (unlikely (find_local_dest (dev, m, &offset, &vlan_tag) !=0 )) { +if (unlikely (find_local_dest (vdev, m, &offset, + &vlan_tag) !=0 )) {rte_pktmbuf_free (m);return ; } }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC is external\n" , dev->device_fh); +"(%d) TX: MAC address is external\n" , vdev->device_fh); queue2nic:
@@ -1095,10 +1093,8 @@ drain_virtio_tx(struct vhost_dev *vdev)free_pkts (pkts, count); } -for (i =0 ; i < count; ++i) { -virtio_tx_route (vdev, pkts[i], - vlan_tags[(uint16_t )vdev->dev->device_fh]); - } +for (i =0 ; i < count; ++i) +virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->device_fh]); }/*
@@ -1207,7 +1203,7 @@ destroy_device (volatile struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been removed from data core\n" , - dev->device_fh); + vdev->device_fh);rte_free (vdev); }
@@ -1222,20 +1218,21 @@ new_device (struct virtio_net *dev)int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; +int device_fh = dev->device_fh; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA , -"(%d) Couldn't allocate memory for vhost dev\n" , - dev->device_fh); +"(%d) couldn't allocate memory for vhost dev\n" , + device_fh);return -1 ; } vdev->dev = dev; dev->priv = vdev; + vdev->device_fh = device_fh;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, next); - vdev->vmdq_rx_q - = dev->device_fh * queues_per_pool + vmdq_queue_base; + vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;/*reset ready flag*/ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1259,7 +1256,7 @@ new_device (struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been added to data core %d\n" , - dev->device_fh, vdev->coreid); + device_fh, vdev->coreid);return 0 ; }
examples/vhost/main.h +1 -0
@@ -66,6 +66,7 @@ struct vhost_dev {/**< Device is marked for removal from the data core. */ volatile uint8_t remove; +int device_fh;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) next; } __rte_cache_aligned;
Signature · 1 line
1.9.0
PATCH v2 5/19 vhost: rename device fh to vid
In reply to Yuanhan LiuI failed to figure out what does "fh" mean here for a long while. The only guess I could have had is "file handle". So, you get the point that it's not well named.
I then figured it out that "fh" is derived from the fuse lib, and my above guess is right. However, device_fh represents a virtio net device ID. Therefore, here I rename it to vid (Virtio-net device ID, or Vhost device ID; choose one you prefer) to make it easier for understanding.
This name (vid) then will be considered to the only interface to applications. That's another reason to do the rename: it's our interface, make it more understandable.
--- examples/vhost/main.c | 44 +++++++++++++-------------- examples/vhost/main.h | 2 +- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/vhost-net.h | 6 ++-- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 36 +++++++++++----------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 6 ++-- lib/librte_vhost/vhost_rxtx.c | 22 +++++++------- lib/librte_vhost/vhost_user/vhost-net-user.c | 16 +++++----- lib/librte_vhost/vhost_user/virtio-net-user.c | 2 +- lib/librte_vhost/virtio-net.c | 30 +++++++++--------- 10 files changed, 83 insertions(+), 83 deletions(-)
examples/vhost/main.c +22 -22
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) device is using a registered MAC!\n" , - vdev->device_fh); + vdev->vid);return -1 ; }
@@ -724,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];/* vlan_tag currently uses the device_id. */ - vdev->vlan_tag = vlan_tags[vdev->device_fh]; + vdev->vlan_tag = vlan_tags[vdev->vid];/* Print out VMDQ registration info. */ RTE_LOG(INFO, VHOST_DATA, "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", - vdev->device_fh, + vdev->vid, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3], vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -737,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)/* Register the MAC address. */ ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, - (uint32_t )vdev->device_fh + vmdq_pool_base); + (uint32_t )vdev->vid + vmdq_pool_base);if (ret)RTE_LOG (ERR ,VHOST_DATA ,"(%d) failed to add device MAC address to VMDQ\n" , - vdev->device_fh); + vdev->vid);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -820,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)if (!dst_vdev)return -1 ; -if (vdev->device_fh == dst_vdev->device_fh) { +if (vdev->vid == dst_vdev->vid) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - vdev->device_fh); + vdev->vid);return 0 ; }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC address is local\n" , dst_vdev->device_fh); +"(%d) TX: MAC address is local\n" , dst_vdev->vid);if (unlikely (dst_vdev->remove)) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) device is marked for removal\n" , dst_vdev->device_fh); +"(%d) device is marked for removal\n" , dst_vdev->vid);return 0 ; }
@@ -855,10 +855,10 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,if (!dst_vdev)return 0 ; -if (vdev->device_fh == dst_vdev->device_fh) { +if (vdev->vid == dst_vdev->vid) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - vdev->device_fh); + vdev->vid);return -1 ; }
@@ -868,11 +868,11 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,* the packet length by plus it. */ *offset =VLAN_HLEN ; - *vlan_tag = vlan_tags[vdev->device_fh]; + *vlan_tag = vlan_tags[vdev->vid];RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n" , - vdev->device_fh, dst_vdev->device_fh, *vlan_tag); + vdev->vid, dst_vdev->vid, *vlan_tag);return 0 ; }
@@ -963,7 +963,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC address is external\n" , vdev->device_fh); +"(%d) TX: MAC address is external\n" , vdev->vid); queue2nic:
@@ -1094,7 +1094,7 @@ drain_virtio_tx(struct vhost_dev *vdev) }for (i =0 ; i < count; ++i) -virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->device_fh]); +virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->vid]); }/*
@@ -1203,7 +1203,7 @@ destroy_device (volatile struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been removed from data core\n" , - vdev->device_fh); + vdev->vid);rte_free (vdev); }
@@ -1218,21 +1218,21 @@ new_device (struct virtio_net *dev)int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; -int device_fh = dev->device_fh; +int vid = dev->vid; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA ,"(%d) couldn't allocate memory for vhost dev\n" , - device_fh); + vid);return -1 ; } vdev->dev = dev; dev->priv = vdev; - vdev->device_fh = device_fh; + vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, next); - vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base; + vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;/*reset ready flag*/ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1256,7 +1256,7 @@ new_device (struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been added to data core %d\n" , - device_fh, vdev->coreid); + vid, vdev->coreid);return 0 ; }
@@ -1308,7 +1308,7 @@ print_stats(void)"RX total: %" PRIu64"\n" "RX dropped: %" PRIu64"\n" "RX successful: %" PRIu64"\n" , - vdev->dev->device_fh, + vdev->dev->vid, tx_total, tx_dropped, tx, rx_total, rx_dropped, rx); }
examples/vhost/main.h +1 -1
@@ -66,7 +66,7 @@ struct vhost_dev {/**< Device is marked for removal from the data core. */ volatile uint8_t remove; -int device_fh; +int vid;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) next; } __rte_cache_aligned;
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -133,7 +133,7 @@ struct virtio_net {struct virtio_memory *mem;/**< QEMU memory and memory region information. */ uint64_t features;/**< Negotiated feature set. */ uint64_t protocol_features;/**< Negotiated protocol feature set. */ -int device_fh;/**< device identifier. */ +int vid;/**< device identifier. */ uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */
lib/librte_vhost/vhost-net.h +3 -3
@@ -57,9 +57,9 @@char packet[VHOST_MAX_PRINT_BUFF ]; \ \if ((header)) \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->vid), (size)); \else \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->vid), (size)); \for (index =0 ; index < (size); index++) { \snprintf (packet +strnlen (packet,VHOST_MAX_PRINT_BUFF ),VHOST_MAX_PRINT_BUFF -strnlen (packet,VHOST_MAX_PRINT_BUFF ), \"%02hhx " , pkt_addr[index]); \
@@ -80,7 +80,7 @@*/ struct vhost_device_ctx {pid_t pid;/* PID of process calling the IOCTL. */ -int fh;/* Populated with fi->fh to track the device index. */ +int vid;/* Virtio-net device ID */ };int vhost_new_device (struct vhost_device_ctx );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +18 -18
@@ -70,7 +70,7 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)struct fuse_ctx const *const req_ctx =fuse_req_ctx (req); ctx.pid = req_ctx->pid; - ctx.fh = fi->fh; + ctx.vid = (int )fi->fh;return ctx; }
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) fi->fh = err;RTE_LOG (INFO ,VHOST_CONFIG , -"(%d) device configuration started\n" , fi->fh); +"(%d) device configuration started\n" , err);fuse_reply_open (req, fi); }
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx); -RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.vid);fuse_reply_err (req, err); }
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,switch (cmd) {case VHOST_NET_SET_BACKEND :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh); +"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.vid);if (!in_buf) {VHOST_IOCTL_RETRY (sizeof (file),0 );break ;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_GET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.vid);VHOST_IOCTL_W (uint64_t, features, vhost_get_features);break ;case VHOST_SET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.vid);VHOST_IOCTL_R (uint64_t, features, vhost_set_features);break ;case VHOST_RESET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.vid);VHOST_IOCTL (vhost_reset_owner);break ;case VHOST_SET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.vid);VHOST_IOCTL (vhost_set_owner);break ;case VHOST_SET_MEM_TABLE :/*TODO fix race condition.*/ LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.vid);static struct vhost_memory mem_temp;switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_NUM :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num);break ;case VHOST_SET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base);break ;case VHOST_GET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.vid);VHOST_IOCTL_RW (uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base);break ;case VHOST_SET_VRING_ADDR :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr);break ;
@@ -295,11 +295,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,if (cmd ==VHOST_SET_VRING_KICK )LOG_DEBUG (VHOST_CONFIG ,"(%d) IOCTL: VHOST_SET_VRING_KICK\n" , - ctx.fh); + ctx.vid);else LOG_DEBUG (VHOST_CONFIG ,"(%d) IOCTL: VHOST_SET_VRING_CALL\n" , - ctx.fh); + ctx.vid);if (!in_buf)VHOST_IOCTL_RETRY (sizeof (struct vhost_vring_file ),0 );else {
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,default :RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.fh); +"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.vid); result =-1 ;fuse_reply_ioctl (req, result,NULL ,0 ); }if (result <0 )LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: FAIL\n" , ctx.fh); +"(%d) IOCTL: FAIL\n" , ctx.vid);else LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: SUCCESS\n" , ctx.fh); +"(%d) IOCTL: SUCCESS\n" , ctx.vid); }/*
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +3 -3
@@ -290,7 +290,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to allocate memory for dev->mem\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -394,7 +394,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, intif (close (fd_tap) <0 )RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , - dev->device_fh); + dev->vid);if (ret >=0 ) { ifr_size =strnlen (ifr.ifr_name,sizeof (ifr.ifr_name));
@@ -402,7 +402,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int }else RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) TUNGETIFF ioctl failed\n" , - dev->device_fh); + dev->vid);return 0 ; }
lib/librte_vhost/vhost_rxtx.c +11 -11
@@ -264,10 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t desc_indexes[MAX_PKT_BURST ];uint32_t i; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -280,7 +280,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,return 0 ;LOG_DEBUG (VHOST_DATA ,"(%d) res_start_idx %d | res_end_idx Index %d\n" , - dev->device_fh, res_start_idx, res_end_idx); + dev->vid, res_start_idx, res_end_idx);/* Retrieve all of the desc indexes first to avoid caching issues. */ rte_prefetch0 (&vq->avail->ring[res_start_idx & (vq->size -1 )]);
@@ -442,7 +442,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,return 0 ;LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , - dev->device_fh, cur_idx, res_end_idx); + dev->vid, cur_idx, res_end_idx);if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)return -1 ;
@@ -452,7 +452,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, virtio_hdr.num_buffers = res_end_idx - res_start_idx;LOG_DEBUG (VHOST_DATA ,"(%d) RX: num merge buffers %d\n" , - dev->device_fh, virtio_hdr.num_buffers); + dev->vid, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr);copy_virtio_net_hdr (vq, desc_addr, virtio_hdr);
@@ -530,10 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint32_t pkt_idx =0 , nr_used =0 ;uint16_t start, end; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -552,7 +552,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, &start, &end) < 0)) {LOG_DEBUG (VHOST_DATA ,"(%d) failed to get enough desc from vring\n" , - dev->device_fh); + dev->vid);break ; }
@@ -828,7 +828,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -864,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (free_entries ==0 ) goto out; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);/* Prefetch available ring to retrieve head indexes. */ used_idx = vq->last_used_idx & (vq->size -1 );
@@ -873,7 +873,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, count =RTE_MIN (count,MAX_PKT_BURST ); count =RTE_MIN (count, free_entries);LOG_DEBUG (VHOST_DATA ,"(%d) about to dequeue %u buffers\n" , - dev->device_fh, count); + dev->vid, count);/* Retrieve all of the head indexes first to avoid caching issues. */ for (i =0 ; i < count; i++) {
lib/librte_vhost/vhost_user/vhost-net-user.c +8 -8
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);struct connfd_ctx {struct vhost_server *vserver; -int fh; +int vid; };#define MAX_VHOST_SERVER 1024
@@ -285,7 +285,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)struct vhost_server *vserver = (struct vhost_server *)dat;int conn_fd;struct connfd_ctx *ctx; -int fh; +int vid;struct vhost_device_ctx vdev_ctx = { (pid_t )0 ,0 };unsigned int size;
@@ -301,22 +301,22 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)return ; } - fh =vhost_new_device (vdev_ctx); -if (fh ==-1 ) { + vid =vhost_new_device (vdev_ctx); +if (vid ==-1 ) {free (ctx);close (conn_fd);return ; } - vdev_ctx.fh = fh; + vdev_ctx.vid = vid; size =strnlen (vserver->path,PATH_MAX );vhost_set_ifname (vdev_ctx, vserver->path, size); -RTE_LOG (INFO ,VHOST_CONFIG ,"new device, handle is %d\n" , fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"new device, handle is %d\n" , vid); ctx->vserver = vserver; - ctx->fh = fh; + ctx->vid = vid;fdset_add (&g_vhost_server.fdset, conn_fd, vserver_message_handler,NULL , ctx); }
@@ -331,7 +331,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)uint64_t features;int ret; - ctx.fh = cfd_ctx->fh; + ctx.vid = cfd_ctx->vid; ret =read_vhost_message (connfd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
lib/librte_vhost/vhost_user/virtio-net-user.c +1 -1
@@ -133,7 +133,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to allocate memory for dev->mem\n" , - dev->device_fh); + dev->vid);return -1 ; } dev->mem->nregions = memory.nregions;
lib/librte_vhost/virtio-net.c +15 -15
@@ -112,11 +112,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)struct virtio_net *get_device (struct vhost_device_ctx ctx) { -struct virtio_net *dev = vhost_devices[ctx.fh]; +struct virtio_net *dev = vhost_devices[ctx.vid];if (unlikely (!dev)) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) device not found.\n" , ctx.fh); +"(%d) device not found.\n" , ctx.vid); }return dev;
@@ -233,7 +233,7 @@ alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)/* * Reset some variables in device structure, while keeping few -* others untouched, such as device_fh, ifname, virt_qp_nb: they +* others untouched, such as vid, ifname, virt_qp_nb: they * should be same unless the device is removed. */ static void
@@ -263,7 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) failed to allocate memory for dev.\n" , ctx.fh); +"(%d) failed to allocate memory for dev.\n" , ctx.vid);return -1 ; }
@@ -278,7 +278,7 @@ vhost_new_device(struct vhost_device_ctx ctx) } vhost_devices[i] = dev; - dev->device_fh = i; + dev->vid = i;return i; }
@@ -303,7 +303,7 @@ vhost_destroy_device(struct vhost_device_ctx ctx)cleanup_device (dev,1 );free_device (dev); - vhost_devices[ctx.fh] =NULL ; + vhost_devices[ctx.vid] =NULL ; }void
@@ -408,7 +408,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) }LOG_DEBUG (VHOST_CONFIG ,"(%d) mergeable RX buffers %s, virtio 1 %s\n" , - dev->device_fh, + dev->vid, (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL <<VIRTIO_F_VERSION_1 )) ?"on" :"off" );
@@ -513,7 +513,7 @@ numa_realloc(struct virtio_net *dev, int index) out: dev->virtqueue[index] = vq; dev->virtqueue[index +1 ] = vq +1 ; - vhost_devices[dev->device_fh] = dev; + vhost_devices[dev->vid] = dev;return dev; }
@@ -549,7 +549,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->desc ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find desc ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -561,7 +561,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->avail ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find avail ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -570,20 +570,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->used ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find used ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; } vq->log_guest_addr = addr->log_guest_addr;LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address desc: %p\n" , - dev->device_fh, vq->desc); + dev->vid, vq->desc);LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address avail: %p\n" , - dev->device_fh, vq->avail); + dev->vid, vq->avail);LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address used: %p\n" , - dev->device_fh, vq->used); + dev->vid, vq->used);LOG_DEBUG (VHOST_CONFIG ,"(%d) log_guest_addr: %" PRIx64"\n" , - dev->device_fh, vq->log_guest_addr); + dev->vid, vq->log_guest_addr);return 0 ; }
Signature · 1 line
1.9.0
PATCH v2 6/19 vhost: get device by vid only
In reply to Yuanhan Liuget_device() just needs vid, so pass vid as the parameter only.
--- lib/librte_vhost/vhost-net.h | 30 ++++++------ lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 64 ++++++++++++------------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++--- lib/librte_vhost/vhost_user/vhost-net-user.c | 43 ++++++++--------- lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++------- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++--- lib/librte_vhost/virtio-net.c | 68 +++++++++++++-------------- lib/librte_vhost/virtio-net.h | 2 +- 8 files changed, 132 insertions(+), 147 deletions(-)
lib/librte_vhost/vhost-net.h +14 -16
@@ -83,28 +83,26 @@ struct vhost_device_ctx {int vid;/* Virtio-net device ID */ }; -int vhost_new_device (struct vhost_device_ctx ); -void vhost_destroy_device (struct vhost_device_ctx ); +int vhost_new_device (void ); +void vhost_destroy_device (int ); -void vhost_set_ifname (struct vhost_device_ctx , -const char *if_name,unsigned int if_len); +void vhost_set_ifname (int ,const char *if_name,unsigned int if_len); -int vhost_get_features (struct vhost_device_ctx ,uint64_t *); -int vhost_set_features (struct vhost_device_ctx ,uint64_t *); +int vhost_get_features (int ,uint64_t *); +int vhost_set_features (int ,uint64_t *); -int vhost_set_vring_num (struct vhost_device_ctx ,struct vhost_vring_state *); -int vhost_set_vring_addr (struct vhost_device_ctx ,struct vhost_vring_addr *); -int vhost_set_vring_base (struct vhost_device_ctx ,struct vhost_vring_state *); -int vhost_get_vring_base (struct vhost_device_ctx , -uint32_t ,struct vhost_vring_state *); +int vhost_set_vring_num (int ,struct vhost_vring_state *); +int vhost_set_vring_addr (int ,struct vhost_vring_addr *); +int vhost_set_vring_base (int ,struct vhost_vring_state *); +int vhost_get_vring_base (int ,uint32_t ,struct vhost_vring_state *); -int vhost_set_vring_kick (struct vhost_device_ctx ,struct vhost_vring_file *); -int vhost_set_vring_call (struct vhost_device_ctx ,struct vhost_vring_file *); +int vhost_set_vring_kick (int ,struct vhost_vring_file *); +int vhost_set_vring_call (int ,struct vhost_vring_file *); -int vhost_set_backend (struct vhost_device_ctx ,struct vhost_vring_file *); +int vhost_set_backend (int ,struct vhost_vring_file *); -int vhost_set_owner (struct vhost_device_ctx ); -int vhost_reset_owner (struct vhost_device_ctx ); +int vhost_set_owner (int ); +int vhost_reset_owner (int );/* * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +31 -33
213 lines not on this page · raw message
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +8 -10
@@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,uint64_t base_address =0 , mapped_address, mapped_size;struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (ctx.vid);if (dev ==NULL )return -1 ;
@@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,* save it in the device structure. */ static int -get_ifname (struct vhost_device_ctx ctx,struct virtio_net *dev,int tap_fd,int pid) +get_ifname (int vid,int tap_fd,int pid) {int fd_tap;struct ifreq ifr;
@@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret =ioctl (fd_tap,TUNGETIFF , &ifr);if (close (fd_tap) <0 ) -RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , - dev->vid); +RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , vid);if (ret >=0 ) { ifr_size =strnlen (ifr.ifr_name,sizeof (ifr.ifr_name)); -vhost_set_ifname (ctx, ifr.ifr_name, ifr_size); +vhost_set_ifname (vid, ifr.ifr_name, ifr_size); }else RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) TUNGETIFF ioctl failed\n" , - dev->vid); +"(%d) TUNGETIFF ioctl failed\n" , vid);return 0 ; }
@@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) {struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (ctx.vid);if (dev ==NULL )return -1 ;if (!(dev->flags &VIRTIO_DEV_RUNNING ) && file->fd !=VIRTIO_DEV_STOPPED ) -get_ifname (ctx, dev, file->fd, ctx.pid); +get_ifname (ctx.vid, file->fd, ctx.pid); -return vhost_set_backend (ctx, file); +return vhost_set_backend (ctx.vid, file); }void
lib/librte_vhost/vhost_user/vhost-net-user.c +20 -23
136 lines not on this page · raw message
lib/librte_vhost/vhost_user/virtio-net-user.c +18 -18
@@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev) }int -user_set_mem_table (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_mem_table (int vid,struct VhostUserMsg *pmsg) {struct VhostUserMemory memory = pmsg->payload.memory;struct virtio_memory_regions *pregion;
@@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)uint64_t alignment;/* unmap old memory regions one by one*/ - dev =get_device (ctx); + dev =get_device (vid);if (dev ==NULL )return -1 ;
@@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev) }void -user_set_vring_call (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_vring_call (int vid,struct VhostUserMsg *pmsg) {struct vhost_vring_file file;
@@ -265,7 +265,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) file.fd = pmsg->fds[0 ];RTE_LOG (INFO ,VHOST_CONFIG ,"vring call idx:%d file:%d\n" , file.index, file.fd); -vhost_set_vring_call (ctx, &file); +vhost_set_vring_call (vid, &file); }
@@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)* device is ready for packet processing. */ void -user_set_vring_kick (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_vring_kick (int vid,struct VhostUserMsg *pmsg) {struct vhost_vring_file file; -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid); file.index = pmsg->payload.u64 &VHOST_USER_VRING_IDX_MASK ;if (pmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK )
@@ -286,7 +286,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) file.fd = pmsg->fds[0 ];RTE_LOG (INFO ,VHOST_CONFIG ,"vring kick idx:%d file:%d\n" , file.index, file.fd); -vhost_set_vring_kick (ctx, &file); +vhost_set_vring_kick (vid, &file);if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) {if (notify_ops->new_device (dev) ==0 )
@@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)* when virtio is stopped, qemu will send us the GET_VRING_BASE message. */ int -user_get_vring_base (struct vhost_device_ctx ctx, +user_get_vring_base (int vid,struct vhost_vring_state *state) { -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid);if (dev ==NULL )return -1 ;
@@ -310,7 +310,7 @@ user_get_vring_base(struct vhost_device_ctx ctx, notify_ops->destroy_device (dev);/* Here we are safe to get the last used index */ -vhost_get_vring_base (ctx, state->index, state); +vhost_get_vring_base (vid, state->index, state);RTE_LOG (INFO ,VHOST_CONFIG ,"vring base idx:%d file:%d\n" , state->index, state->num);
@@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,* enable the virtio queue pair. */ int -user_set_vring_enable (struct vhost_device_ctx ctx, +user_set_vring_enable (int vid,struct vhost_vring_state *state) { -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid);int enable = (int )state->num; RTE_LOG(INFO, VHOST_CONFIG,
@@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx, }void -user_set_protocol_features (struct vhost_device_ctx ctx, +user_set_protocol_features (int vid,uint64_t protocol_features) {struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (vid);if (dev ==NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES )return ;
@@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx, }int -user_set_log_base (struct vhost_device_ctx ctx, +user_set_log_base (int vid,struct VhostUserMsg *msg) {struct virtio_net *dev;
@@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx,uint64_t size, off;void *addr; - dev =get_device (ctx); + dev =get_device (vid);if (!dev)return -1 ;
@@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx,* a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it. */ int -user_send_rarp (struct vhost_device_ctx ctx,struct VhostUserMsg *msg) +user_send_rarp (int vid,struct VhostUserMsg *msg) {struct virtio_net *dev;uint8_t *mac = (uint8_t *)&msg->payload.u64; - dev =get_device (ctx); + dev =get_device (vid);if (!dev)return -1 ;
lib/librte_vhost/vhost_user/virtio-net-user.h +8 -10
@@ -45,20 +45,18 @@ (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\ (1ULL << VHOST_USER_PROTOCOL_F_RARP)) -int user_set_mem_table (struct vhost_device_ctx ,struct VhostUserMsg *); +int user_set_mem_table (int ,struct VhostUserMsg *); -void user_set_vring_call (struct vhost_device_ctx ,struct VhostUserMsg *); +void user_set_vring_call (int ,struct VhostUserMsg *); -void user_set_vring_kick (struct vhost_device_ctx ,struct VhostUserMsg *); +void user_set_vring_kick (int ,struct VhostUserMsg *); -void user_set_protocol_features (struct vhost_device_ctx ctx, -uint64_t protocol_features); -int user_set_log_base (struct vhost_device_ctx ctx,struct VhostUserMsg *); -int user_send_rarp (struct vhost_device_ctx ctx,struct VhostUserMsg *); +void user_set_protocol_features (int vid,uint64_t protocol_features); +int user_set_log_base (int vid,struct VhostUserMsg *); +int user_send_rarp (int vid,struct VhostUserMsg *); -int user_get_vring_base (struct vhost_device_ctx ,struct vhost_vring_state *); +int user_get_vring_base (int ,struct vhost_vring_state *); -int user_set_vring_enable (struct vhost_device_ctx ctx, -struct vhost_vring_state *state); +int user_set_vring_enable (int vid,struct vhost_vring_state *state);#endif
lib/librte_vhost/virtio-net.c +32 -36
217 lines not on this page · raw message
lib/librte_vhost/virtio-net.h +1 -1
@@ -38,6 +38,6 @@#include "rte_virtio_net.h" struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (struct vhost_device_ctx ctx); +struct virtio_net *get_device (int vid);#endif
Signature · 1 line
1.9.0
PATCH v2 7/19 vhost: move vhost device ctx to cuse
In reply to Yuanhan Liuvhost cuse is now the last reference of the vhost_device_ctx struct; move it there, and do a rename to "vhost_cuse_device_ctx", to make it clear that it's "cuse only".
--- lib/librte_vhost/vhost-net.h | 8 -------- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 13 +++++++------ lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 6 ++++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 ++++++++++-- 4 files changed, 21 insertions(+), 18 deletions(-)
lib/librte_vhost/vhost-net.h +0 -8
@@ -75,14 +75,6 @@#endif -/* -* Structure used to identify device context. -*/ -struct vhost_device_ctx { -pid_t pid;/* PID of process calling the IOCTL. */ -int vid;/* Virtio-net device ID */ -}; -int vhost_new_device (void );void vhost_destroy_device (int );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +7 -6
@@ -60,13 +60,14 @@ static const char default_cdev[] = "vhost-net";static struct fuse_session *session;/* -* Returns vhost_device_ctx from given fuse_req_t. The index is populated later -* when the device is added to the device linked list. +* Returns vhost_cuse_device_ctx from given fuse_req_t. The +* index is populated later when the device is added to the +* device linked list. */ -static struct vhost_device_ctx +static struct vhost_cuse_device_ctx fuse_req_to_vhost_ctx (fuse_req_t req,struct fuse_file_info *fi) { -struct vhost_device_ctx ctx; +struct vhost_cuse_device_ctx ctx;struct fuse_ctx const *const req_ctx =fuse_req_ctx (req); ctx.pid = req_ctx->pid;
@@ -104,7 +105,7 @@ static void vhost_net_release(fuse_req_t req, struct fuse_file_info *fi) { int err = 0; -struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi); +struct vhost_cuse_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx.vid);RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.vid);
@@ -182,7 +183,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, struct fuse_file_info *fi, __rte_unused unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz) { - struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi); + struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);struct vhost_vring_file file;struct vhost_vring_state state;struct vhost_vring_addr addr;
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +4 -2
@@ -263,7 +263,7 @@ host_memory_map(pid_t pid, uint64_t addr, }int -cuse_set_mem_table (struct vhost_device_ctx ctx, +cuse_set_mem_table (struct vhost_cuse_device_ctx ctx,const struct vhost_memory *mem_regions_addr,uint32_t nregions) {uint64_t size = offsetof(struct vhost_memory , regions);
@@ -405,7 +405,9 @@ get_ifname(int vid, int tap_fd, int pid)return 0 ; } -int cuse_set_backend (struct vhost_device_ctx ctx,struct vhost_vring_file *file) +int +cuse_set_backend (struct vhost_cuse_device_ctx ctx, +struct vhost_vring_file *file) {struct virtio_net *dev;
lib/librte_vhost/vhost_cuse/virtio-net-cdev.h +10 -2
@@ -38,11 +38,19 @@#include "vhost-net.h" +/* +* Structure used to identify device context. +*/ +struct vhost_cuse_device_ctx { +pid_t pid;/* PID of process calling the IOCTL. */ +int vid;/* Virtio-net device ID */ +}; +int -cuse_set_mem_table (struct vhost_device_ctx ctx, +cuse_set_mem_table (struct vhost_cuse_device_ctx ctx,const struct vhost_memory *mem_regions_addr,uint32_t nregions);int -cuse_set_backend (struct vhost_device_ctx ctx,struct vhost_vring_file *); +cuse_set_backend (struct vhost_cuse_device_ctx ctx,struct vhost_vring_file *);#endif
Signature · 1 line
1.9.0
PATCH v2 8/19 vhost: introduce new API to export numa node
In reply to Yuanhan LiuIntroduce a new API rte_vhost_get_numa_node() to get the numa node from which the virtio_net struct is allocated.
--- drivers/net/vhost/rte_eth_vhost.c | 13 ++++--------- lib/librte_vhost/rte_vhost_version.map | 7 +++++++ lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/virtio-net.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +4 -9
@@ -230,7 +230,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 ) {
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev) internal = eth_dev->data->dev_private;#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++) {
lib/librte_vhost/rte_vhost_version.map +7 -0
@@ -20,3 +20,10 @@ DPDK_2.1 { rte_vhost_driver_unregister; } DPDK_2.0; + +DPDK_16.07 { + global: + + rte_vhost_get_numa_node; + +} DPDK_16.04;
lib/librte_vhost/rte_virtio_net.h +12 -0
@@ -245,6 +245,18 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * consint rte_vhost_driver_session_start (void );/** +* 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
lib/librte_vhost/virtio-net.c +26 -0
@@ -730,6 +730,32 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)return 0 ; } +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_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v2 9/19 vhost: introduce new API to export number of queues
In reply to Yuanhan LiuIntroduce a new API rte_vhost_get_queue_num() to export the number of queues.
--- drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 11 +++++++++++ lib/librte_vhost/virtio-net.c | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-)
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -270,7 +270,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;
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -25,5 +25,6 @@ DPDK_16.07 { global: rte_vhost_get_numa_node; + rte_vhost_get_queue_num; } DPDK_16.04;
lib/librte_vhost/rte_virtio_net.h +11 -0
@@ -257,6 +257,17 @@ int rte_vhost_driver_session_start(void);int rte_vhost_get_numa_node (int vid);/** +* 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); + +/** * 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
lib/librte_vhost/virtio-net.c +11 -0
@@ -756,6 +756,17 @@ rte_vhost_get_numa_node(int vid)#endif } +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_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v2 10/19 vhost: introduce new API to export ifname
In reply to Yuanhan LiuIntroduce a new API rte_vhost_get_ifname() to export the ifname to application.
--- drivers/net/vhost/rte_eth_vhost.c | 12 ++++++++---- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/virtio-net.c | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +8 -4
@@ -229,6 +229,7 @@ new_device(struct virtio_net *dev)struct pmd_internal *internal;struct vhost_queue *vq;unsigned i; +char ifname[PATH_MAX ];#ifdef RTE_LIBRTE_VHOST_NUMA int newnode;#endif
@@ -238,9 +239,10 @@ new_device(struct virtio_net *dev)return -1 ; } - list =find_internal_resource (dev->ifname); +rte_vhost_get_ifname (dev->vid, ifname,sizeof (ifname)); + list =find_internal_resource (ifname);if (list ==NULL ) { -RTE_LOG (INFO ,PMD ,"Invalid device name\n" ); +RTE_LOG (INFO ,PMD ,"Invalid device name: %s\n" , ifname);return -1 ; }
@@ -360,15 +362,17 @@ vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)struct rte_vhost_vring_state *state;struct rte_eth_dev *eth_dev;struct internal_list *list; +char ifname[PATH_MAX ];if (dev ==NULL ) {RTE_LOG (ERR ,PMD ,"Invalid argument\n" );return -1 ; } - list =find_internal_resource (dev->ifname); +rte_vhost_get_ifname (dev->vid, ifname,sizeof (ifname)); + list =find_internal_resource (ifname);if (list ==NULL ) { -RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , dev->ifname); +RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , ifname);return -1 ; }
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -24,6 +24,7 @@ DPDK_2.1 { DPDK_16.07 { global: + rte_vhost_get_ifname; rte_vhost_get_numa_node; rte_vhost_get_queue_num;
lib/librte_vhost/rte_virtio_net.h +17 -0
@@ -268,6 +268,23 @@ int rte_vhost_get_numa_node(int vid);uint32_t rte_vhost_get_queue_num (int vid);/** +* Get the virtio net device's ifname. For vhost-cuse, ifname is the +* path of the char device. For vhost-user, ifname is the vhost-user +* socket file path. +* +* @param vid +* virtio-net device ID +* @param buf +* The buffer to stored the queried ifname +* @param len +* The length of buf +* +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_ifname (int vid,char *buf,size_t len); + +/** * 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
lib/librte_vhost/virtio-net.c +16 -0
@@ -767,6 +767,22 @@ rte_vhost_get_queue_num(int vid)return dev->virt_qp_nb; } +int +rte_vhost_get_ifname (int vid,char *buf,size_t len) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return -1 ; + + len =RTE_MIN (len,sizeof (dev->ifname)); + +strncpy (buf, dev->ifname, len); + buf[len -1 ] ='\0' ; + +return 0 ; +} +int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v2 11/19 vhost: introduce new API to export queue free entries
In reply to Yuanhan LiuThe new API rte_vhost_avail_entries() is actually a rename of rte_vring_available_entries(), with the "vring" to "vhost" name change to keep the consistency of other vhost exported APIs.
This change could let us avoid the dependency of "virtio_net" struct, to prepare for the ABI refactoring.
--- doc/guides/rel_notes/release_16_07.rst | 2 ++ examples/vhost/main.c | 4 ++-- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 24 +++++++++++++----------- lib/librte_vhost/virtio-net.c | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 13 deletions(-)
doc/guides/rel_notes/release_16_07.rst +2 -0
@@ -97,6 +97,8 @@ This section should contain API changes. Sample format: ibadcrc, ibadlen, imcasts, fdirmatch, fdirmiss, tx_pause_xon, rx_pause_xon, tx_pause_xoff, rx_pause_xoff. +* ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``. + ABI Changes -----------
examples/vhost/main.c +2 -2
@@ -1055,13 +1055,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 (dev->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 (dev->vid,VIRTIO_RXQ ))break ; }
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -24,6 +24,7 @@ DPDK_2.1 { DPDK_16.07 { global: + rte_vhost_avail_entries; rte_vhost_get_ifname; rte_vhost_get_numa_node; rte_vhost_get_queue_num;
lib/librte_vhost/rte_virtio_net.h +13 -11
@@ -184,17 +184,6 @@ struct virtio_net_device_ops {int (*vring_state_changed)(struct virtio_net *dev,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ }; -static inline uint16_t __attribute__((always_inline)) -rte_vring_available_entries (struct virtio_net *dev,uint16_t queue_id) -{ -struct vhost_virtqueue *vq = dev->virtqueue[queue_id]; - -if (!vq->enabled) -return 0 ; - -return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res; -} -/** * Function to convert guest physical addresses to vhost virtual addresses. * This is used to convert guest virtio buffer addresses.
@@ -285,6 +274,19 @@ uint32_t rte_vhost_get_queue_num(int vid);int rte_vhost_get_ifname (int vid,char *buf,size_t len);/** +* Get how many avail entries are left in the queue +* +* @param vid +* virtio-net device ID +* @param queue_id +* virtio queue index +* +* @return +* num of avail entires left +*/ +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id); + +/** * 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
lib/librte_vhost/virtio-net.c +17 -0
@@ -783,6 +783,23 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len)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; +} +int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v2 12/19 vhost: remove dependency on priv field
In reply to Yuanhan LiuThis change could let us avoid the dependency of "virtio_net" struct, to prepare for the ABI refactoring.
--- drivers/net/vhost/rte_eth_vhost.c | 13 +++++++------ examples/vhost/main.c | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +7 -6
@@ -275,7 +275,6 @@ new_device(struct virtio_net *dev)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; eth_dev->data->dev_link.link_status =ETH_LINK_UP ;for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) {
@@ -303,6 +302,8 @@ destroy_device(volatile struct virtio_net *dev) {struct rte_eth_dev *eth_dev;struct vhost_queue *vq; +struct internal_list *list; +char ifname[PATH_MAX ];unsigned i;if (dev ==NULL ) {
@@ -310,11 +311,13 @@ destroy_device(volatile struct virtio_net *dev)return ; } - eth_dev = (struct rte_eth_dev *)dev->priv; -if (eth_dev ==NULL ) { -RTE_LOG (INFO ,PMD ,"Failed to find a ethdev\n" ); +rte_vhost_get_ifname (dev->vid, ifname,sizeof (ifname)); + list =find_internal_resource (ifname); +if (list ==NULL ) { +RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , ifname);return ; } + eth_dev = list->eth_dev;/* Wait until rx/tx_pkt_burst stops accessing vhost device */ for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) {
@@ -336,8 +339,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status =ETH_LINK_DOWN ; - dev->priv =NULL ; -for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i];if (vq ==NULL )
examples/vhost/main.c +16 -2
@@ -700,6 +700,19 @@ find_vhost_dev(struct ether_addr *mac)return NULL ; } +static inline struct vhost_dev *__attribute__((always_inline)) +find_vhost_dev_by_vid(int vid) +{ +struct vhost_dev *vdev; + + TAILQ_FOREACH(vdev, &vhost_dev_list, next) { +if (vdev->ready ==DEVICE_RX && vdev->vid == vid) +return vdev; + } + +return NULL ; +} +/* * This function learns the MAC address of the device and registers this along with a * vlan tag to a VMDQ.
@@ -1175,7 +1188,9 @@ destroy_device (volatile struct virtio_net *dev)struct vhost_dev *vdev;int lcore; - vdev = (struct vhost_dev *)dev->priv; + vdev =find_vhost_dev_by_vid (dev->vid); +if (!vdev) +return ;/*set the remove flag. */ vdev->remove =1 ;while (vdev->ready !=DEVICE_SAFE_REMOVE ) {
@@ -1228,7 +1243,6 @@ new_device (struct virtio_net *dev)return -1 ; } vdev->dev = dev; - dev->priv = vdev; vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, next);
Signature · 1 line
1.9.0
PATCH v2 13/19 vhost: export vid as the only interface to applications
In reply to Yuanhan LiuWith all the previous prepare works, we are just one step away from the final ABI refactoring. That is, to change current API to let them stick to vid instead of the old virtio_net dev.
---
v2: update release note
--- doc/guides/rel_notes/release_16_07.rst | 7 ++++ drivers/net/vhost/rte_eth_vhost.c | 47 +++++++++------------------ examples/vhost/main.c | 25 +++++++------- lib/librte_vhost/rte_virtio_net.h | 18 +++++----- lib/librte_vhost/vhost_rxtx.c | 15 +++++++-- lib/librte_vhost/vhost_user/virtio-net-user.c | 14 ++++---- lib/librte_vhost/virtio-net.c | 17 ++++++---- 7 files changed, 75 insertions(+), 68 deletions(-)
doc/guides/rel_notes/release_16_07.rst +7 -0
@@ -99,6 +99,10 @@ This section should contain API changes. Sample format: * ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``. +* All existing vhost APIs and callbacks with ``virtio_net`` struct pointer + as the parameter have been changed due to the ABI refactoring mentioned + below: it's replaced by "int vid". + ABI Changes -----------
@@ -110,6 +114,9 @@ ABI Changes * The ``rte_port_source_params`` structure has new fields to support PCAP file. It was already in release 16.04 with ``RTE_NEXT_ABI`` flag. +* vhost ABI refactoring has been made: ``virtio_net`` structure is never + exported to application any more. Instead, a handle, ``vid``, has been + used to represent this structure internally. Shared Library Versions -----------------------
drivers/net/vhost/rte_eth_vhost.c +16 -31
136 lines not on this page · raw message
examples/vhost/main.c +11 -14
@@ -808,7 +808,7 @@ virtio_xmit(struct vhost_dev *dst_vdev, struct vhost_dev *src_vdev, {uint16_t ret; - ret =rte_vhost_enqueue_burst (dst_vdev->dev,VIRTIO_RXQ , &m,1 ); + ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 );if (enable_stats) {rte_atomic64_inc (&dst_vdev->stats.rx_total_atomic);rte_atomic64_add (&dst_vdev->stats.rx_atomic, ret);
@@ -1054,7 +1054,6 @@ static inline void __attribute__((always_inline)) drain_eth_rx(struct vhost_dev *vdev) {uint16_t rx_count, enqueue_count; -struct virtio_net *dev = vdev->dev;struct rte_mbuf *pkts[MAX_PKT_BURST ]; rx_count = rte_eth_rx_burst(ports[0], vdev->vmdq_rx_q,
@@ -1068,19 +1067,19 @@ drain_eth_rx(struct vhost_dev *vdev)* to diminish packet loss. */ if (enable_retry && -unlikely (rx_count >rte_vhost_avail_entries (dev->vid, +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_vhost_avail_entries (dev->vid, +if (rx_count <=rte_vhost_avail_entries (vdev->vid,VIRTIO_RXQ ))break ; } } - enqueue_count =rte_vhost_enqueue_burst (dev,VIRTIO_RXQ , + enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , pkts, rx_count);if (enable_stats) {rte_atomic64_add (&vdev->stats.rx_total_atomic, rx_count);
@@ -1097,7 +1096,7 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; - count =rte_vhost_dequeue_burst (vdev->dev,VIRTIO_TXQ , mbuf_pool, + count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */
@@ -1183,12 +1182,12 @@ switch_worker(void *arg __rte_unused)* of dev->remove=1 which can cause an infinite loop in the rte_pause loop. */ static void -destroy_device (volatile struct virtio_net *dev) +destroy_device (int vid) {struct vhost_dev *vdev;int lcore; - vdev =find_vhost_dev_by_vid (dev->vid); + vdev =find_vhost_dev_by_vid (vid);if (!vdev)return ;/*set the remove flag. */
@@ -1228,12 +1227,11 @@ destroy_device (volatile struct virtio_net *dev)* and the allocated to a specific data core. */ static int -new_device (struct virtio_net *dev) +new_device (int vid) {int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; -int vid = dev->vid; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {
@@ -1242,7 +1240,6 @@ new_device (struct virtio_net *dev) vid);return -1 ; } - vdev->dev = dev; vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, next);
@@ -1265,8 +1262,8 @@ new_device (struct virtio_net *dev) lcore_info[vdev->coreid].device_num++;/* Disable notifications. */ -rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 ); -rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); +rte_vhost_enable_guest_notification (vid,VIRTIO_RXQ ,0 ); +rte_vhost_enable_guest_notification (vid,VIRTIO_TXQ ,0 ); RTE_LOG(INFO, VHOST_DATA, "(%d) device has been added to data core %d\n",
@@ -1322,7 +1319,7 @@ print_stats(void)"RX total: %" PRIu64"\n" "RX dropped: %" PRIu64"\n" "RX successful: %" PRIu64"\n" , - vdev->dev->vid, + vdev->vid, tx_total, tx_dropped, tx, rx_total, rx_dropped, rx); }
lib/librte_vhost/rte_virtio_net.h +9 -9
@@ -178,10 +178,10 @@ struct virtio_memory {* */ struct virtio_net_device_ops { -int (*new_device)(struct virtio_net *);/**< Add device. */ -void (*destroy_device)(volatile struct virtio_net *);/**< Remove device. */ +int (*new_device)(int vid);/**< Add device. */ +void (*destroy_device)(int vid);/**< Remove device. */ -int (*vring_state_changed)(struct virtio_net *dev,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ +int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ };/**
@@ -220,7 +220,7 @@ int rte_vhost_feature_enable(uint64_t feature_mask);/* Returns currently supported vhost features */ uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable); +int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/* Register vhost driver. dev_name could be different for multiple instance support. */ int rte_vhost_driver_register (const char *dev_name);
@@ -291,8 +291,8 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);* 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 * added to the RX queue. -* @param dev -* virtio-net device +* @param vid +* virtio-net device ID * @param queue_id * virtio queue index in mq case * @param pkts
@@ -302,14 +302,14 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);* @return * num of packets enqueued */ -uint16_t rte_vhost_enqueue_burst (struct virtio_net *dev,uint16_t queue_id, +uint16_t rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count);/** * This function gets guest buffers from the virtio device TX virtqueue, * construct host mbufs, copies guest buffer content to host mbufs and * store them in pkts to be processed. -* @param dev +* @param vid * virtio-net device * @param queue_id * virtio queue index in mq case
@@ -322,7 +322,7 @@ uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,* @return * num of packets dequeued */ -uint16_t rte_vhost_dequeue_burst (struct virtio_net *dev,uint16_t queue_id, +uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count);#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost_rxtx.c +13 -2
@@ -46,6 +46,7 @@#include <rte_arp.h> #include "vhost-net.h" +#include "virtio-net.h" #define MAX_PKT_BURST 32#define VHOST_LOG_PAGE 4096
@@ -587,9 +588,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, }uint16_t -rte_vhost_enqueue_burst (struct virtio_net *dev,uint16_t queue_id, +rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count) { +struct virtio_net *dev =get_device (vid); + +if (!dev) +return 0 ; +if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF ))return virtio_dev_merge_rx (dev, queue_id, pkts, count);else
@@ -815,9 +821,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, }uint16_t -rte_vhost_dequeue_burst (struct virtio_net *dev,uint16_t queue_id, +rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) { +struct virtio_net *dev;struct rte_mbuf *rarp_mbuf =NULL ;struct vhost_virtqueue *vq;uint32_t desc_indexes[MAX_PKT_BURST ];
@@ -826,6 +833,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,uint16_t free_entries;uint16_t avail_idx; + dev =get_device (vid); +if (!dev) +return 0 ; +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);
lib/librte_vhost/vhost_user/virtio-net-user.c +8 -6
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)struct vhost_vring_file file;struct virtio_net *dev =get_device (vid); +if (!dev) +return ; + file.index = pmsg->payload.u64 &VHOST_USER_VRING_IDX_MASK ;if (pmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK ) file.fd =VIRTIO_INVALID_EVENTFD ;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)vhost_set_vring_kick (vid, &file);if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { -if (notify_ops->new_device (dev) ==0 ) +if (notify_ops->new_device (vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -307,7 +310,7 @@ user_get_vring_base(int vid,return -1 ;/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid);/* Here we are safe to get the last used index */ vhost_get_vring_base (vid, state->index, state);
@@ -342,9 +345,8 @@ user_set_vring_enable(int vid,"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) { - notify_ops->vring_state_changed (dev, state->index, enable); - } +if (notify_ops->vring_state_changed) + notify_ops->vring_state_changed (vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
lib/librte_vhost/virtio-net.c +11 -6
@@ -296,7 +296,7 @@ vhost_destroy_device(int vid)if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -354,7 +354,7 @@ vhost_reset_owner(int vid)if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }cleanup_device (dev,0 );
@@ -718,13 +718,13 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)if (!(dev->flags &VIRTIO_DEV_RUNNING )) {if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) { -if (notify_ops->new_device (dev) <0 ) +if (notify_ops->new_device (vid) <0 )return -1 ; dev->flags |=VIRTIO_DEV_RUNNING ; } }else if (file->fd ==VIRTIO_DEV_STOPPED ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }return 0 ;
@@ -800,9 +800,14 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res; } -int rte_vhost_enable_guest_notification (struct virtio_net *dev, -uint16_t queue_id,int enable) +int +rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable) { +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return -1 ; +if (enable) {RTE_LOG (ERR ,VHOST_CONFIG ,"guest notification isn't supported.\n" );
Signature · 1 line
1.9.0
PATCH v2 14/19 vhost: hide internal structs/macros/functions
In reply to Yuanhan LiuWe are now safe to move all those internal structs/macros/functions to vhost-net.h, to hide them from external access.
This patch also breaks long lines and removes some redundant comments.
--- lib/librte_vhost/rte_virtio_net.h | 139 ------------------------- lib/librte_vhost/vhost-net.h | 148 +++++++++++++++++++++++++++ lib/librte_vhost/vhost_user/vhost-net-user.h | 2 + 3 files changed, 150 insertions(+), 139 deletions(-)
lib/librte_vhost/rte_virtio_net.h +0 -139
@@ -51,125 +51,9 @@#include <rte_mempool.h> #include <rte_ether.h> -struct rte_mbuf ; - -#define VHOST_MEMORY_MAX_NREGIONS 8 - -/* Used to indicate that the device is running on a data core */ -#define VIRTIO_DEV_RUNNING 1 - -/* Backend value set by guest. */ -#define VIRTIO_DEV_STOPPED -1 - -/* Enum for virtqueue management. */ enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; -#define BUF_VECTOR_MAX 256 - -/** -* Structure contains buffer address, length and descriptor index -* from vring to do scatter RX. -*/ -struct buf_vector { -uint64_t buf_addr; -uint32_t buf_len; -uint32_t desc_idx; -}; - -/** -* Structure contains variables relevant to RX/TX virtqueues. -*/ -struct vhost_virtqueue { -struct vring_desc *desc;/**< Virtqueue descriptor ring. */ -struct vring_avail *avail;/**< Virtqueue available ring. */ -struct vring_used *used;/**< Virtqueue used ring. */ -uint32_t size;/**< Size of descriptor ring. */ -int backend;/**< Backend value to determine if device should started/stopped. */ -uint16_t vhost_hlen;/**< Vhost header length (varies depending on RX merge buffers. */ -volatile uint16_t last_used_idx;/**< Last index used on the available ring */ -volatile uint16_t last_used_idx_res;/**< Used for multiple devices reserving buffers. */ -#define VIRTIO_INVALID_EVENTFD (-1) -#define VIRTIO_UNINITIALIZED_EVENTFD (-2) -int callfd;/**< Used to notify the guest (trigger interrupt). */ -int kickfd;/**< Currently unused as polling mode is enabled. */ -int enabled; -uint64_t log_guest_addr;/**< Physical address of used ring, for logging */ -uint64_t reserved[15 ];/**< Reserve some spaces for future extension. */ -struct buf_vector buf_vec[BUF_VECTOR_MAX ];/**< for scatter RX. */ -} __rte_cache_aligned; - -/* Old kernels have no such macro defined */ -#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE -#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 -#endif - - -/* -* Make an extra wrapper for VIRTIO_NET_F_MQ and -* VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are -* introduced since kernel v3.8. This makes our -* code buildable for older kernel. -*/ -#ifdef VIRTIO_NET_F_MQ -#define VHOST_MAX_QUEUE_PAIRS VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX -#define VHOST_SUPPORTS_MQ (1ULL << VIRTIO_NET_F_MQ) -#else -#define VHOST_MAX_QUEUE_PAIRS 1 -#define VHOST_SUPPORTS_MQ 0 -#endif - -/* -* Define virtio 1.0 for older kernels -*/ -#ifndef VIRTIO_F_VERSION_1 -#define VIRTIO_F_VERSION_1 32 -#endif - -/** -* Device structure contains all configuration information relating to the device. -*/ -struct virtio_net { -struct virtio_memory *mem;/**< QEMU memory and memory region information. */ -uint64_t features;/**< Negotiated feature set. */ -uint64_t protocol_features;/**< Negotiated protocol feature set. */ -int vid;/**< device identifier. */ -uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ -#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) -char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */ -uint32_t virt_qp_nb;/**< number of queue pair we have allocated */ -void *priv;/**< private context */ -uint64_t log_size;/**< Size of log area */ -uint64_t log_base;/**< Where dirty pages are logged */ -struct ether_addr mac;/**< MAC address */ -rte_atomic16_t broadcast_rarp;/**< A flag to tell if we need broadcast rarp packet */ -uint64_t reserved[61 ];/**< Reserve some spaces for future extension. */ -struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ];/**< Contains all virtqueue information. */ -} __rte_cache_aligned; - -/** -* Information relating to memory regions including offsets to addresses in QEMUs memory file. -*/ -struct virtio_memory_regions { -uint64_t guest_phys_address;/**< Base guest physical address of region. */ -uint64_t guest_phys_address_end;/**< End guest physical address of region. */ -uint64_t memory_size;/**< Size of region. */ -uint64_t userspace_address;/**< Base userspace address of region. */ -uint64_t address_offset;/**< Offset of region for address translation. */ -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint64_t base_address;/**< Base QEMU userspace address of the memory file. */ -uint64_t mapped_address;/**< Mapped address of memory file base in our applications memory space. */ -uint64_t mapped_size;/**< Total size of memory file. */ -uint32_t nregions;/**< Number of memory regions. */ -struct virtio_memory_regions regions[0 ];/**< Memory region information. */ -}; -/** * Device and vring operations. *
@@ -185,29 +69,6 @@ struct virtio_net_device_ops { };/** -* Function to convert guest physical addresses to vhost virtual addresses. -* This is used to convert guest virtio buffer addresses. -*/ -static inline uint64_t __attribute__((always_inline)) -gpa_to_vva (struct virtio_net *dev,uint64_t guest_pa) -{ -struct virtio_memory_regions *region; -uint32_t regionidx; -uint64_t vhost_va =0 ; - -for (regionidx =0 ; regionidx < dev->mem->nregions; regionidx++) { - region = &dev->mem->regions[regionidx]; -if ((guest_pa >= region->guest_phys_address) && - (guest_pa <= region->guest_phys_address_end)) { - vhost_va = region->address_offset + guest_pa; -break ; - } - } -return vhost_va; -} - - -/** * Disable features in feature_mask. Returns 0 on success. */ int rte_vhost_feature_disable (uint64_t feature_mask);
lib/librte_vhost/vhost-net.h +148 -0
160 lines not on this page · raw message
lib/librte_vhost/vhost_user/vhost-net-user.h +2 -0
@@ -47,6 +47,8 @@ struct vhost_server {/* refer to hw/virtio/vhost-user.c */ +#define VHOST_MEMORY_MAX_NREGIONS 8 + typedef enum VhostUserRequest { VHOST_USER_NONE = 0, VHOST_USER_GET_FEATURES = 1,
Signature · 1 line
1.9.0
PATCH v2 15/19 vhost: remove unnecessary fields
In reply to Yuanhan LiuThe "reserved" field in virtio_net and vhost_virtqueue struct is not necessary any more. We now expose virtio_net device with a number "vid".
This patch also removes the "priv" field: all fields are priviate now:
application can't access it now. The only way that we could still access it is to expose it by a function, but I doubt that's needed or worthwhile.
--- lib/librte_vhost/vhost-net.h | 3 --- 1 file changed, 3 deletions(-)
lib/librte_vhost/vhost-net.h +0 -3
@@ -88,7 +88,6 @@ struct vhost_virtqueue {/* Physical address of used ring, for logging */ uint64_t log_guest_addr; -uint64_t reserved[15 ];struct buf_vector buf_vec[BUF_VECTOR_MAX ]; } __rte_cache_aligned;
@@ -133,14 +132,12 @@ struct virtio_net {#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];uint32_t virt_qp_nb; -void *priv;uint64_t log_size;uint64_t log_base;struct ether_addr mac;/* to tell if we need broadcast rarp packet */ rte_atomic16_t broadcast_rarp; -uint64_t reserved[61 ];struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned;
Signature · 1 line
1.9.0
PATCH v2 16/19 vhost: remove virtio-net.h
In reply to Yuanhan LiuIt barely has anything useful there, just 2 functions prototype. Here move them to vhost-net.h, and delete it.
--- lib/librte_vhost/vhost-net.h | 3 ++ lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 1 - lib/librte_vhost/vhost_rxtx.c | 1 - lib/librte_vhost/vhost_user/virtio-net-user.c | 1 - lib/librte_vhost/virtio-net.c | 1 - lib/librte_vhost/virtio-net.h | 43 --------------------------- 6 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.h
lib/librte_vhost/vhost-net.h +3 -0
@@ -220,6 +220,9 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)return vhost_va; } +struct virtio_net_device_ops const *notify_ops; +struct virtio_net *get_device (int vid); +int vhost_new_device (void );void vhost_destroy_device (int );
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +0 -1
@@ -54,7 +54,6 @@#include "rte_virtio_net.h" #include "vhost-net.h" #include "virtio-net-cdev.h" -#include "virtio-net.h" #include "eventfd_copy.h" /* Line size for reading maps file. */
lib/librte_vhost/vhost_rxtx.c +0 -1
@@ -46,7 +46,6 @@#include <rte_arp.h> #include "vhost-net.h" -#include "virtio-net.h" #define MAX_PKT_BURST 32#define VHOST_LOG_PAGE 4096
lib/librte_vhost/vhost_user/virtio-net-user.c +0 -1
@@ -43,7 +43,6 @@#include <rte_common.h> #include <rte_log.h> -#include "virtio-net.h" #include "virtio-net-user.h" #include "vhost-net-user.h" #include "vhost-net.h"
lib/librte_vhost/virtio-net.c +0 -1
@@ -53,7 +53,6 @@#include <rte_virtio_net.h> #include "vhost-net.h" -#include "virtio-net.h" #define MAX_VHOST_DEVICE 1024static struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ];
lib/librte_vhost/virtio-net.h deleted +0 -43
43 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v2 17/19 vhost: reserve few more space for future extension
In reply to Yuanhan Liu"virtio_net_device_ops" is the only left open struct that an application can access, therefore, it's the only place that might introduce potential ABI break in future for extension.
So, do some reservation for it. 5 should be pretty enough, considering that we have barely touched it for a long while. Another reason to choose 5 is for cache alignment: 5 makes the struct 64 bytes for 64 bit machine.
With this, it's confidence to say that we might be able to be free from the ABI violation forever.
--- lib/librte_vhost/rte_virtio_net.h | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_vhost/rte_virtio_net.h +2 -0
@@ -66,6 +66,8 @@ struct virtio_net_device_ops {void (*destroy_device)(int vid);/**< Remove device. */ int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ + +void *reserved[5 ];/**< Reserved for future extension */ };/**
Signature · 1 line
1.9.0
PATCH v2 18/19 vhost: per device virtio net header len
In reply to Yuanhan LiuVirtio net header length is set per device, but not per queue. So, there is no reason to store it in vhost_virtqueue struct, instead, we should store it in virtio_net struct, to make one copy only.
--- lib/librte_vhost/vhost-net.h | 2 +- lib/librte_vhost/vhost_rxtx.c | 40 ++++++++++++++++++++-------------------- lib/librte_vhost/virtio-net.c | 13 ++----------- 3 files changed, 23 insertions(+), 32 deletions(-)
lib/librte_vhost/vhost-net.h +1 -1
@@ -69,7 +69,6 @@ struct vhost_virtqueue {struct vring_avail *avail;struct vring_used *used;uint32_t size; -uint16_t vhost_hlen;/* Last index used on the available ring */ volatile uint16_t last_used_idx;
@@ -129,6 +128,7 @@ struct virtio_net {uint64_t protocol_features;int vid;uint32_t flags; +uint16_t vhost_hlen;#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];uint32_t virt_qp_nb;
lib/librte_vhost/vhost_rxtx.c +20 -20
@@ -126,10 +126,10 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr) }static inline void -copy_virtio_net_hdr (struct vhost_virtqueue *vq,uint64_t desc_addr, +copy_virtio_net_hdr (struct virtio_net *dev,uint64_t desc_addr,struct virtio_net_hdr_mrg_rxbuf hdr) { -if (vq->vhost_hlen ==sizeof (struct virtio_net_hdr_mrg_rxbuf )) +if (dev->vhost_hlen ==sizeof (struct virtio_net_hdr_mrg_rxbuf )) *(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t )desc_addr = hdr;else *(struct virtio_net_hdr *)(uintptr_t )desc_addr = hdr.hdr;
@@ -147,19 +147,19 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0 ,0 ,0 ,0 ,0 ,0 },0 }; desc = &vq->desc[desc_idx]; -if (unlikely (desc->len < vq->vhost_hlen)) +if (unlikely (desc->len < dev->vhost_hlen))return -1 ; desc_addr =gpa_to_vva (dev, desc->addr);rte_prefetch0 ((void *)(uintptr_t )desc_addr);virtio_enqueue_offload (m, &virtio_hdr.hdr); -copy_virtio_net_hdr (vq, desc_addr, virtio_hdr); -vhost_log_write (dev, desc->addr, vq->vhost_hlen); -PRINT_PACKET (dev, (uintptr_t )desc_addr, vq->vhost_hlen,0 ); +copy_virtio_net_hdr (dev, desc_addr, virtio_hdr); +vhost_log_write (dev, desc->addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); - desc_offset = vq->vhost_hlen; - desc_avail = desc->len - vq->vhost_hlen; + desc_offset = dev->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; *copied =rte_pktmbuf_pkt_len (m); mbuf_avail =rte_pktmbuf_data_len (m);
@@ -300,9 +300,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, vq->used->ring[used_idx].id = desc_idx;if (unlikely (err)) - vq->used->ring[used_idx].len = vq->vhost_hlen; + vq->used->ring[used_idx].len = dev->vhost_hlen;else - vq->used->ring[used_idx].len = copied + vq->vhost_hlen; + vq->used->ring[used_idx].len = copied + dev->vhost_hlen;vhost_log_used_vring (dev, vq, offsetof(struct vring_used, ring[used_idx]), sizeof(vq->used->ring[used_idx]));
@@ -444,7 +444,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , dev->vid, cur_idx, res_end_idx); -if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen) +if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)return -1 ; desc_addr =gpa_to_vva (dev, vq->buf_vec[vec_idx].buf_addr);
@@ -455,12 +455,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, dev->vid, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr); -copy_virtio_net_hdr (vq, desc_addr, virtio_hdr); -vhost_log_write (dev, vq->buf_vec[vec_idx].buf_addr, vq->vhost_hlen); -PRINT_PACKET (dev, (uintptr_t )desc_addr, vq->vhost_hlen,0 ); +copy_virtio_net_hdr (dev, desc_addr, virtio_hdr); +vhost_log_write (dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); - desc_avail = vq->buf_vec[vec_idx].buf_len - vq->vhost_hlen; - desc_offset = vq->vhost_hlen; + desc_avail = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; mbuf_avail =rte_pktmbuf_data_len (m); mbuf_offset =0 ;
@@ -546,7 +546,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,return 0 ;for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) { -uint32_t pkt_len = pkts[pkt_idx]->pkt_len + vq->vhost_hlen; +uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;if (unlikely (reserve_avail_buf_mergeable (vq, pkt_len, &start, &end) <0 )) {
@@ -747,7 +747,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,uint32_t nr_desc =1 ; desc = &vq->desc[desc_idx]; -if (unlikely (desc->len < vq->vhost_hlen)) +if (unlikely (desc->len < dev->vhost_hlen))return -1 ; desc_addr =gpa_to_vva (dev, desc->addr);
@@ -755,8 +755,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,/* Retrieve virtio net header */ hdr = (struct virtio_net_hdr *)((uintptr_t )desc_addr); - desc_avail = desc->len - vq->vhost_hlen; - desc_offset = vq->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; mbuf_offset =0 ; mbuf_avail = m->buf_len -RTE_PKTMBUF_HEADROOM ;
lib/librte_vhost/virtio-net.c +2 -11
@@ -387,8 +387,6 @@ int vhost_set_features(int vid, uint64_t *pu) { struct virtio_net *dev; -uint16_t vhost_hlen; -uint16_t i; dev =get_device (vid);if (dev ==NULL )
@@ -399,9 +397,9 @@ vhost_set_features(int vid, uint64_t *pu) dev->features = *pu;if (dev->features & ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) { - vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); + dev->vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); }else { - vhost_hlen =sizeof (struct virtio_net_hdr ); + dev->vhost_hlen =sizeof (struct virtio_net_hdr ); } LOG_DEBUG(VHOST_CONFIG, "(%d) mergeable RX buffers %s, virtio 1 %s\n",
@@ -409,13 +407,6 @@ vhost_set_features(int vid, uint64_t *pu) (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off"); -for (i =0 ; i < dev->virt_qp_nb; i++) { -uint16_t base_idx = i *VIRTIO_QNUM ; - - dev->virtqueue[base_idx +VIRTIO_RXQ ]->vhost_hlen = vhost_hlen; - dev->virtqueue[base_idx +VIRTIO_TXQ ]->vhost_hlen = vhost_hlen; - } -return 0 ; }
Signature · 1 line
1.9.0
PATCH v2 19/19 vhost: make buf vector for scatter Rx local
In reply to Yuanhan LiuFrom: Ilya Maximets <[email protected]>
Array of buf_vector's is just an array for temporary storing information about available descriptors. It used only locally in virtio_dev_merge_rx() and there is no reason for that array to be shared.
Fix that by allocating local buf_vec inside virtio_dev_merge_rx().
--- lib/librte_vhost/vhost-net.h | 1 - lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-)
lib/librte_vhost/vhost-net.h +0 -1
@@ -87,7 +87,6 @@ struct vhost_virtqueue {/* Physical address of used ring, for logging */ uint64_t log_guest_addr; -struct buf_vector buf_vec[BUF_VECTOR_MAX ]; } __rte_cache_aligned;/* Old kernels have no such macro defined */
lib/librte_vhost/vhost_rxtx.c +22 -19
133 lines not on this page · raw message
Signature · 1 line
1.9.0
Quoted 7 lines · Yuanhan Liu
v2: - exported ifname as well to fix a vhost-pmd issue reported
by Rich
- separated the big patch that introduces several new APIs into some small patches.
- updated release note
- updated version.map
Quoted 11 lines · Rich Lane
On Thu, May 12, 2016 at 10:24 PM, Yuanhan Liu <[email protected]> wrote:
v2: - exported ifname as well to fix a vhost-pmd issue reported by Rich
- separated the big patch that introduces several new APIs into some small patches.
- updated release note
- updated version.map
Quoted 2 lines
Tested-by Rich Lane <[email protected]>Acked-by Rich Lane <[email protected]>
Rich, appreciate your time for reviewing and testing!
--yliu
v3 cover vhost ABI/API refactoring
In reply to Yuanhan Liuv3: - adapted the new vhost ABI/API changes to tep_term example, to make
sure not break build at least.
- bumped the ABI version to 3
NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]: git://dpdk.org/next/dpdk-next-virtio for-testing
Every time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove vec_buf from vhost_virtqueue struct) also break ABI.
This patch set is meant to resolve above issue ultimately, by hiding virtio_net structure (as well as few others) internaly, and export the virtio_net dev strut to applications by a number, vid, like the way kernel exposes an fd to user space.
Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".
After that, "vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.
The last bit of this patch set is some cleanups, including the one from Ilya.
v2: - exported ifname as well to fix a vhost-pmd issue reported by Rich
- separated the big patch that introduces several new APIs into some small patches.
- updated release note
- updated version.map
Thanks.
--yliu
---
Ilya Maximets (1):
vhost: make buf vector for scatter Rx local
Yuanhan Liu (19):
vhost: declare backend with int type
vhost: set/reset dev flags internally
vhost: declare device fh as int examples/vhost: make a copy of virtio device id
vhost: rename device fh to vid
vhost: get device by vid only
vhost: move vhost device ctx to cuse
vhost: introduce new API to export numa node
vhost: introduce new API to export number of queues
vhost: introduce new API to export ifname
vhost: introduce new API to export queue free entries
vhost: remove dependency on priv field
vhost: export vid as the only interface to applications
vhost: hide internal structs/macros/functions
vhost: remove unnecessary fields
vhost: remove virtio-net.h
vhost: reserve few more space for future extension examples/tep_term: adapt to new vhost ABI/API changes
vhost: per device virtio net header len
doc/guides/rel_notes/release_16_07.rst | 11 +- drivers/net/vhost/rte_eth_vhost.c | 79 ++++----- examples/tep_termination/main.c | 83 +++++----- examples/tep_termination/main.h | 5 +- examples/tep_termination/vxlan_setup.c | 20 +-- examples/tep_termination/vxlan_setup.h | 6 +- examples/vhost/main.c | 116 +++++++------ examples/vhost/main.h | 3 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost_version.map | 10 ++ lib/librte_vhost/rte_virtio_net.h | 223 +++++++------------------ lib/librte_vhost/vhost-net.h | 201 ++++++++++++++++++---- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 83 +++++----- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 30 ++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 +- lib/librte_vhost/vhost_rxtx.c | 133 ++++++++------- lib/librte_vhost/vhost_user/vhost-net-user.c | 53 +++--- lib/librte_vhost/vhost_user/vhost-net-user.h | 2 + lib/librte_vhost/vhost_user/virtio-net-user.c | 64 +++---- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 +- lib/librte_vhost/virtio-net.c | 229 +++++++++++++++++--------- lib/librte_vhost/virtio-net.h | 43 ----- 22 files changed, 752 insertions(+), 674 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.h
Signature · 1 line
1.9.0
PATCH v3 1/20 vhost: declare backend with int type
It's an fd; so define it as "int", which could also save the unncessary (int) case.
--- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/virtio-net.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -85,7 +85,7 @@ struct vhost_virtqueue {struct vring_avail *avail;/**< Virtqueue available ring. */ struct vring_used *used;/**< Virtqueue used ring. */ uint32_t size;/**< Size of descriptor ring. */ -uint32_t backend;/**< Backend value to determine if device should started/stopped. */ +int backend;/**< Backend value to determine if device should started/stopped. */ uint16_t vhost_hlen;/**< Vhost header length (varies depending on RX merge buffers. */ volatile uint16_t last_used_idx;/**< Last index used on the available ring */ volatile uint16_t last_used_idx_res;/**< Used for multiple devices reserving buffers. */
lib/librte_vhost/virtio-net.c +2 -2
@@ -717,8 +717,8 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)* we add the device. */ if (!(dev->flags &VIRTIO_DEV_RUNNING )) { -if (((int )dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED ) && - ((int )dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED )) { +if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && + dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) {return notify_ops->new_device (dev); }/* Otherwise we remove it. */
Signature · 1 line
1.9.0
PATCH v3 2/20 vhost: set/reset dev flags internally
In reply to Yuanhan LiuIt does not make sense to ask the application to set/unset the flag VIRTIO_DEV_RUNNING (that used internal only) at new_device()/ destroy_device() callback.
Instead, it should be set after new_device() succeeds and reset before destroy_device() is invoked inside vhost lib. This patch fixes it.
--- drivers/net/vhost/rte_eth_vhost.c | 2 -- examples/vhost/main.c | 3 --- lib/librte_vhost/vhost_user/virtio-net-user.c | 11 +++++++---- lib/librte_vhost/virtio-net.c | 21 ++++++++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +0 -2
@@ -278,7 +278,6 @@ new_device(struct virtio_net *dev)for (i =0 ; i < dev->virt_qp_nb *VIRTIO_QNUM ; i++)rte_vhost_enable_guest_notification (dev, i,0 ); - dev->flags |=VIRTIO_DEV_RUNNING ; dev->priv = eth_dev; eth_dev->data->dev_link.link_status =ETH_LINK_UP ;
@@ -341,7 +340,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status =ETH_LINK_DOWN ; dev->priv =NULL ; - dev->flags &= ~VIRTIO_DEV_RUNNING ;for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i];
examples/vhost/main.c +0 -3
@@ -1180,8 +1180,6 @@ destroy_device (volatile struct virtio_net *dev)struct vhost_dev *vdev;int lcore; - dev->flags &= ~VIRTIO_DEV_RUNNING ; - vdev = (struct vhost_dev *)dev->priv;/*set the remove flag. */ vdev->remove =1 ;
@@ -1261,7 +1259,6 @@ new_device (struct virtio_net *dev)/* Disable notifications. */ rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 );rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); - dev->flags |=VIRTIO_DEV_RUNNING ;RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , dev->device_fh, vdev->coreid);
lib/librte_vhost/vhost_user/virtio-net-user.c +7 -4
@@ -115,8 +115,10 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)return -1 ;/* Remove from the data plane. */ -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }if (dev->mem) {free_mem_region (dev);
@@ -286,9 +288,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) "vring kick idx:%d file:%d\n", file.index, file.fd);vhost_set_vring_kick (ctx, &file); -if (virtio_is_ready (dev) && - !(dev->flags &VIRTIO_DEV_RUNNING )) - notify_ops->new_device (dev); +if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { +if (notify_ops->new_device (dev) ==0 ) + dev->flags |=VIRTIO_DEV_RUNNING ; + } }/*
lib/librte_vhost/virtio-net.c +14 -7
@@ -296,8 +296,10 @@ vhost_destroy_device(struct vhost_device_ctx ctx)if (dev ==NULL )return ; -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }cleanup_device (dev,1 );free_device (dev);
@@ -353,8 +355,10 @@ vhost_reset_owner(struct vhost_device_ctx ctx)if (dev ==NULL )return -1 ; -if (dev->flags &VIRTIO_DEV_RUNNING ) +if (dev->flags &VIRTIO_DEV_RUNNING ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; notify_ops->destroy_device (dev); + }cleanup_device (dev,0 );reset_device (dev);
@@ -719,12 +723,15 @@ vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)if (!(dev->flags &VIRTIO_DEV_RUNNING )) {if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) { -return notify_ops->new_device (dev); +if (notify_ops->new_device (dev) <0 ) +return -1 ; + dev->flags |=VIRTIO_DEV_RUNNING ; } -/* Otherwise we remove it. */ - }else -if (file->fd ==VIRTIO_DEV_STOPPED ) - notify_ops->destroy_device (dev); + }else if (file->fd ==VIRTIO_DEV_STOPPED ) { + dev->flags &= ~VIRTIO_DEV_RUNNING ; + notify_ops->destroy_device (dev); + } +return 0 ; }
Signature · 1 line
1.9.0
PATCH v3 3/20 vhost: declare device fh as int
In reply to Yuanhan LiuFirstly, "int" would be big enough: we don't need 64 bit to represent a virtio-net device id. Secondly, this could let us avoid the ugly "%" PRIu64 ".." stuff.
And since ctx.fh is derived from device_fh, declare it as int, too.
--- examples/vhost/main.c | 45 ++++++++++++++------------- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/vhost-net.h | 8 ++--- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 34 ++++++++++---------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 7 ++--- lib/librte_vhost/vhost_rxtx.c | 34 +++++++++----------- lib/librte_vhost/vhost_user/vhost-net-user.c | 2 +- lib/librte_vhost/vhost_user/virtio-net-user.c | 2 +- lib/librte_vhost/virtio-net.c | 21 ++++++------- 9 files changed, 75 insertions(+), 80 deletions(-)
examples/vhost/main.c +24 -21
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA , -"Device (%" PRIu64") is using a registered MAC!\n" , +"(%d) device is using a registered MAC!\n" , dev->device_fh);return -1 ; }
@@ -728,7 +728,8 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->vlan_tag = vlan_tags[dev->device_fh];/* Print out VMDQ registration info. */ - RTE_LOG(INFO, VHOST_DATA, "(%"PRIu64") MAC_ADDRESS %02x:%02x:%02x:%02x:%02x:%02x and VLAN_TAG %d registered\n", + RTE_LOG(INFO, VHOST_DATA, + "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", dev->device_fh, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3],
@@ -739,8 +740,9 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, (uint32_t )dev->device_fh + vmdq_pool_base);if (ret) -RTE_LOG (ERR ,VHOST_DATA ,"(%" PRIu64") Failed to add device MAC address to VMDQ\n" , - dev->device_fh); +RTE_LOG (ERR ,VHOST_DATA , +"(%d) failed to add device MAC address to VMDQ\n" , + dev->device_fh);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -812,7 +814,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) {struct ether_hdr *pkt_hdr;struct vhost_dev *dst_vdev; -uint64_t fh; +int fh; pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -823,17 +825,16 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) fh = dst_vdev->dev->device_fh;if (fh == vdev->dev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: src and dst MAC is same. " -"Dropping packet.\n" , fh); +"(%d) TX: src and dst MAC is same. Dropping packet.\n" , + fh);return 0 ; } -RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: MAC address is local\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is local\n" , fh);if (unlikely (dst_vdev->remove)) { -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") " -"Device is marked for removal\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) device is marked for removal\n" , fh);return 0 ; }
@@ -858,8 +859,8 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,if (dst_vdev->dev->device_fh == dev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: src and dst MAC is same. " -" Dropping packet.\n" , dst_vdev->dev->device_fh); +"(%d) TX: src and dst MAC is same. Dropping packet.\n" , + dst_vdev->dev->device_fh);return -1 ; }
@@ -872,8 +873,7 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m, *vlan_tag = vlan_tags[(uint16_t )dst_vdev->dev->device_fh];RTE_LOG (DEBUG ,VHOST_DATA , -"(%" PRIu64") TX: pkt to local VM device id: (%" PRIu64") " -"vlan tag: %u.\n" , +"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n" , dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag);return 0 ;
@@ -964,8 +964,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) } } -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") TX: " -"MAC address is external\n" , dev->device_fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) TX: MAC is external\n" , dev->device_fh); queue2nic:
@@ -1209,7 +1209,7 @@ destroy_device (volatile struct virtio_net *dev) lcore_info[vdev->coreid].device_num--;RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") Device has been removed from data core\n" , +"(%d) device has been removed from data core\n" , dev->device_fh);rte_free (vdev);
@@ -1228,7 +1228,8 @@ new_device (struct virtio_net *dev) vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) { -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Couldn't allocate memory for vhost dev\n" , +RTE_LOG (INFO ,VHOST_DATA , +"(%d) Couldn't allocate memory for vhost dev\n" , dev->device_fh);return -1 ; }
@@ -1260,7 +1261,9 @@ new_device (struct virtio_net *dev)rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 );rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , dev->device_fh, vdev->coreid); +RTE_LOG (INFO ,VHOST_DATA , +"(%d) device has been added to data core %d\n" , + dev->device_fh, vdev->coreid);return 0 ; }
@@ -1304,7 +1307,7 @@ print_stats(void) rx =rte_atomic64_read (&vdev->stats.rx_atomic); rx_dropped = rx_total - rx; -printf ("Statistics for device %" PRIu64"\n" +printf ("Statistics for device %d\n" "-----------------------\n" "TX total: %" PRIu64"\n" "TX dropped: %" PRIu64 "\n"
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -133,7 +133,7 @@ struct virtio_net {struct virtio_memory *mem;/**< QEMU memory and memory region information. */ uint64_t features;/**< Negotiated feature set. */ uint64_t protocol_features;/**< Negotiated protocol feature set. */ -uint64_t device_fh;/**< device identifier. */ +int device_fh;/**< device identifier. */ uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */
lib/librte_vhost/vhost-net.h +4 -4
@@ -57,9 +57,9 @@char packet[VHOST_MAX_PRINT_BUFF ]; \ \if ((header)) \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%" PRIu64") Header size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->device_fh), (size)); \else \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%" PRIu64") Packet size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->device_fh), (size)); \for (index =0 ; index < (size); index++) { \snprintf (packet +strnlen (packet,VHOST_MAX_PRINT_BUFF ),VHOST_MAX_PRINT_BUFF -strnlen (packet,VHOST_MAX_PRINT_BUFF ), \"%02hhx " , pkt_addr[index]); \
@@ -79,8 +79,8 @@* Structure used to identify device context. */ struct vhost_device_ctx { -pid_t pid;/* PID of process calling the IOCTL. */ -uint64_t fh;/* Populated with fi->fh to track the device index. */ +pid_t pid;/* PID of process calling the IOCTL. */ +int fh;/* Populated with fi->fh to track the device index. */ };int vhost_new_device (struct vhost_device_ctx );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +17 -17
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) fi->fh = err;RTE_LOG (INFO ,VHOST_CONFIG , -"(%" PRIu64") Device configuration started\n" , fi->fh); +"(%d) device configuration started\n" , fi->fh);fuse_reply_open (req, fi); }
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx); -RTE_LOG (INFO ,VHOST_CONFIG ,"(%" PRIu64") Device released\n" , ctx.fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.fh);fuse_reply_err (req, err); }
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,switch (cmd) {case VHOST_NET_SET_BACKEND :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh); +"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh);if (!in_buf) {VHOST_IOCTL_RETRY (sizeof (file),0 );break ;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_GET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_GET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.fh);VHOST_IOCTL_W (uint64_t, features, vhost_get_features);break ;case VHOST_SET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.fh);VHOST_IOCTL_R (uint64_t, features, vhost_set_features);break ;case VHOST_RESET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_RESET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.fh);VHOST_IOCTL (vhost_reset_owner);break ;case VHOST_SET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.fh);VHOST_IOCTL (vhost_set_owner);break ;case VHOST_SET_MEM_TABLE :/*TODO fix race condition.*/ LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh);static struct vhost_memory mem_temp;switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_NUM :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num);break ;case VHOST_SET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base);break ;case VHOST_GET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh);VHOST_IOCTL_RW (uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base);break ;case VHOST_SET_VRING_ADDR :LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr);break ;
@@ -294,11 +294,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_CALL :if (cmd ==VHOST_SET_VRING_KICK )LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_KICK\n" , +"(%d) IOCTL: VHOST_SET_VRING_KICK\n" , ctx.fh);else LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: VHOST_SET_VRING_CALL\n" , +"(%d) IOCTL: VHOST_SET_VRING_CALL\n" , ctx.fh);if (!in_buf)VHOST_IOCTL_RETRY (sizeof (struct vhost_vring_file ),0 );
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,default :RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") IOCTL: DOESN NOT EXIST\n" , ctx.fh); +"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.fh); result =-1 ;fuse_reply_ioctl (req, result,NULL ,0 ); }if (result <0 )LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: FAIL\n" , ctx.fh); +"(%d) IOCTL: FAIL\n" , ctx.fh);else LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") IOCTL: SUCCESS\n" , ctx.fh); +"(%d) IOCTL: SUCCESS\n" , ctx.fh); }/*
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +3 -4
@@ -289,7 +289,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx, sizeof(struct virtio_memory_regions) * nregions);if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev->mem\n" , +"(%d) failed to allocate memory for dev->mem\n" , dev->device_fh);return -1 ; }
@@ -393,8 +393,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret =ioctl (fd_tap,TUNGETIFF , &ifr);if (close (fd_tap) <0 ) -RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") fd close failed\n" , +RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , dev->device_fh);if (ret >=0 ) {
@@ -402,7 +401,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, intvhost_set_ifname (ctx, ifr.ifr_name, ifr_size); }else RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") TUNGETIFF ioctl failed\n" , +"(%d) TUNGETIFF ioctl failed\n" , dev->device_fh);return 0 ;
lib/librte_vhost/vhost_rxtx.c +14 -20
@@ -264,11 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t desc_indexes[MAX_PKT_BURST ];uint32_t i; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") virtio_dev_rx()\n" , dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -280,8 +279,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,if (count ==0 )return 0 ; -LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") res_start_idx %d| res_end_idx Index %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) res_start_idx %d | res_end_idx Index %d\n" , dev->device_fh, res_start_idx, res_end_idx);/* Retrieve all of the desc indexes first to avoid caching issues. */
@@ -443,8 +441,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,if (unlikely (m ==NULL ))return 0 ; -LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") Current Index %d| End Index %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , dev->device_fh, cur_idx, res_end_idx);if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)
@@ -454,7 +451,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,rte_prefetch0 ((void *)(uintptr_t )desc_addr); virtio_hdr.num_buffers = res_end_idx - res_start_idx; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") RX: Num merge buffers %d\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) RX: num merge buffers %d\n" , dev->device_fh, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr);
@@ -533,12 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint32_t pkt_idx =0 , nr_used =0 ;uint16_t start, end; -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") virtio_dev_merge_rx()\n" , - dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -556,7 +551,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,if (unlikely (reserve_avail_buf_mergeable (vq, pkt_len, &start, &end) <0 )) {LOG_DEBUG (VHOST_DATA , -"(%" PRIu64") Failed to get enough desc from vring\n" , +"(%d) failed to get enough desc from vring\n" , dev->device_fh);break ; }
@@ -832,9 +827,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,uint16_t avail_idx;if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) { -RTE_LOG (ERR ,VHOST_DATA , -"%s (%" PRIu64"): virtqueue idx:%d invalid.\n" , - __func__, dev->device_fh, queue_id); +RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , + dev->device_fh, __func__, queue_id);return 0 ; }
@@ -870,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (free_entries ==0 ) goto out; -LOG_DEBUG (VHOST_DATA ,"%s (%" PRIu64")\n" , __func__, dev->device_fh); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__);/* Prefetch available ring to retrieve head indexes. */ used_idx = vq->last_used_idx & (vq->size -1 );
@@ -878,7 +872,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, count =RTE_MIN (count,MAX_PKT_BURST ); count =RTE_MIN (count, free_entries); -LOG_DEBUG (VHOST_DATA ,"(%" PRIu64") about to dequeue %u buffers\n" , +LOG_DEBUG (VHOST_DATA ,"(%d) about to dequeue %u buffers\n" , dev->device_fh, count);/* Retrieve all of the head indexes first to avoid caching issues. */
lib/librte_vhost/vhost_user/vhost-net-user.c +1 -1
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);struct connfd_ctx {struct vhost_server *vserver; -uint32_t fh; +int fh; };#define MAX_VHOST_SERVER 1024
lib/librte_vhost/vhost_user/virtio-net-user.c +1 -1
@@ -132,7 +132,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) sizeof(struct orig_region_map) * memory.nregions);if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev->mem\n" , +"(%d) failed to allocate memory for dev->mem\n" , dev->device_fh);return -1 ; }
lib/librte_vhost/virtio-net.c +10 -11
@@ -116,7 +116,7 @@ get_device(struct vhost_device_ctx ctx)if (unlikely (!dev)) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") device not found.\n" , ctx.fh); +"(%d) device not found.\n" , ctx.fh); }return dev;
@@ -263,8 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to allocate memory for dev.\n" , - ctx.fh); +"(%d) failed to allocate memory for dev.\n" , ctx.fh);return -1 ; }
@@ -408,7 +407,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) vhost_hlen =sizeof (struct virtio_net_hdr ); }LOG_DEBUG (VHOST_CONFIG , -"(%" PRIu64") Mergeable RX buffers %s, virtio 1 %s\n" , +"(%d) mergeable RX buffers %s, virtio 1 %s\n" , dev->device_fh, (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL <<VIRTIO_F_VERSION_1 )) ?"on" :"off" );
@@ -549,7 +548,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->desc_user_addr);if (vq->desc ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find desc ring address.\n" , +"(%d) failed to find desc ring address.\n" , dev->device_fh);return -1 ; }
@@ -561,7 +560,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->avail_user_addr);if (vq->avail ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find avail ring address.\n" , +"(%d) failed to find avail ring address.\n" , dev->device_fh);return -1 ; }
@@ -570,20 +569,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) addr->used_user_addr);if (vq->used ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find used ring address.\n" , +"(%d) failed to find used ring address.\n" , dev->device_fh);return -1 ; } vq->log_guest_addr = addr->log_guest_addr; -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address desc: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address desc: %p\n" , dev->device_fh, vq->desc); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address avail: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address avail: %p\n" , dev->device_fh, vq->avail); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") mapped address used: %p\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address used: %p\n" , dev->device_fh, vq->used); -LOG_DEBUG (VHOST_CONFIG ,"(%" PRIu64") log_guest_addr: %" PRIx64"\n" , +LOG_DEBUG (VHOST_CONFIG ,"(%d) log_guest_addr: %" PRIx64"\n" , dev->device_fh, vq->log_guest_addr);return 0 ;
Signature · 1 line
1.9.0
PATCH v3 4/20 examples/vhost: make a copy of virtio device id
In reply to Yuanhan LiuMake a copy of virtio device id (device_fh) from the virtio_net struct, so that we could have less dependency on the virtio_net struct.
--- examples/vhost/main.c | 59 ++++++++++++++++++++++++--------------------------- examples/vhost/main.h | 1 + 2 files changed, 29 insertions(+), 31 deletions(-)
examples/vhost/main.c +28 -31
@@ -708,7 +708,6 @@ static int link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) { struct ether_hdr *pkt_hdr; -struct virtio_net *dev = vdev->dev;int i, ret;/* Learn MAC address of guest device from packet */
@@ -717,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) device is using a registered MAC!\n" , - dev->device_fh); + vdev->device_fh);return -1 ; }
@@ -725,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];/* vlan_tag currently uses the device_id. */ - vdev->vlan_tag = vlan_tags[dev->device_fh]; + vdev->vlan_tag = vlan_tags[vdev->device_fh];/* Print out VMDQ registration info. */ RTE_LOG(INFO, VHOST_DATA, "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", - dev->device_fh, + vdev->device_fh, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3], vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -738,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)/* Register the MAC address. */ ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, - (uint32_t )dev->device_fh + vmdq_pool_base); + (uint32_t )vdev->device_fh + vmdq_pool_base);if (ret)RTE_LOG (ERR ,VHOST_DATA ,"(%d) failed to add device MAC address to VMDQ\n" , - dev->device_fh); + vdev->device_fh);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -814,7 +813,6 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m) {struct ether_hdr *pkt_hdr;struct vhost_dev *dst_vdev; -int fh; pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
@@ -822,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)if (!dst_vdev)return -1 ; - fh = dst_vdev->dev->device_fh; -if (fh == vdev->dev->device_fh) { +if (vdev->device_fh == dst_vdev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - fh); + vdev->device_fh);return 0 ; } -RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is local\n" , fh); +RTE_LOG (DEBUG ,VHOST_DATA , +"(%d) TX: MAC address is local\n" , dst_vdev->device_fh);if (unlikely (dst_vdev->remove)) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) device is marked for removal\n" , fh); +"(%d) device is marked for removal\n" , dst_vdev->device_fh);return 0 ; }
@@ -847,7 +845,7 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)* and get its vlan tag, and offset if it is. */ static inline int __attribute__((always_inline)) -find_local_dest (struct virtio_net *dev,struct rte_mbuf *m, +find_local_dest (struct vhost_dev *vdev,struct rte_mbuf *m,uint32_t *offset,uint16_t *vlan_tag) {struct vhost_dev *dst_vdev;
@@ -857,10 +855,10 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,if (!dst_vdev)return 0 ; -if (dst_vdev->dev->device_fh == dev->device_fh) { +if (vdev->device_fh == dst_vdev->device_fh) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - dst_vdev->dev->device_fh); + vdev->device_fh);return -1 ; }
@@ -870,11 +868,11 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,* the packet length by plus it. */ *offset =VLAN_HLEN ; - *vlan_tag = vlan_tags[(uint16_t )dst_vdev->dev->device_fh]; + *vlan_tag = vlan_tags[vdev->device_fh];RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: pkt to local VM device id (%d) vlan tag: %u.\n" , - dev->device_fh, dst_vdev->dev->device_fh, *vlan_tag); +"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n" , + vdev->device_fh, dst_vdev->device_fh, *vlan_tag);return 0 ; }
@@ -937,7 +935,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)struct mbuf_table *tx_q;unsigned offset =0 ;const uint16_t lcore_id =rte_lcore_id (); -struct virtio_net *dev = vdev->dev;struct ether_hdr *nh;
@@ -958,14 +955,15 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) }if (unlikely (vm2vm_mode ==VM2VM_HARDWARE )) { -if (unlikely (find_local_dest (dev, m, &offset, &vlan_tag) !=0 )) { +if (unlikely (find_local_dest (vdev, m, &offset, + &vlan_tag) !=0 )) {rte_pktmbuf_free (m);return ; } }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC is external\n" , dev->device_fh); +"(%d) TX: MAC address is external\n" , vdev->device_fh); queue2nic:
@@ -1095,10 +1093,8 @@ drain_virtio_tx(struct vhost_dev *vdev)free_pkts (pkts, count); } -for (i =0 ; i < count; ++i) { -virtio_tx_route (vdev, pkts[i], - vlan_tags[(uint16_t )vdev->dev->device_fh]); - } +for (i =0 ; i < count; ++i) +virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->device_fh]); }/*
@@ -1210,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been removed from data core\n" , - dev->device_fh); + vdev->device_fh);rte_free (vdev); }
@@ -1225,20 +1221,21 @@ new_device (struct virtio_net *dev)int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; +int device_fh = dev->device_fh; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA , -"(%d) Couldn't allocate memory for vhost dev\n" , - dev->device_fh); +"(%d) couldn't allocate memory for vhost dev\n" , + device_fh);return -1 ; } vdev->dev = dev; dev->priv = vdev; + vdev->device_fh = device_fh;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry); - vdev->vmdq_rx_q - = dev->device_fh * queues_per_pool + vmdq_queue_base; + vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base;/*reset ready flag*/ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1263,7 +1260,7 @@ new_device (struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been added to data core %d\n" , - dev->device_fh, vdev->coreid); + device_fh, vdev->coreid);return 0 ; }
examples/vhost/main.h +1 -0
@@ -66,6 +66,7 @@ struct vhost_dev {/**< Device is marked for removal from the data core. */ volatile uint8_t remove; +int device_fh;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) global_vdev_entry;TAILQ_ENTRY (vhost_dev) lcore_vdev_entry;
Signature · 1 line
1.9.0
PATCH v3 5/20 vhost: rename device fh to vid
In reply to Yuanhan LiuI failed to figure out what does "fh" mean here for a long while. The only guess I could have had is "file handle". So, you get the point that it's not well named.
I then figured it out that "fh" is derived from the fuse lib, and my above guess is right. However, device_fh represents a virtio net device ID. Therefore, here I rename it to vid (Virtio-net device ID, or Vhost device ID; choose one you prefer) to make it easier for understanding.
This name (vid) then will be considered to the only interface to applications. That's another reason to do the rename: it's our interface, make it more understandable.
--- examples/vhost/main.c | 44 +++++++++++++-------------- examples/vhost/main.h | 2 +- lib/librte_vhost/rte_virtio_net.h | 2 +- lib/librte_vhost/vhost-net.h | 6 ++-- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 36 +++++++++++----------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 6 ++-- lib/librte_vhost/vhost_rxtx.c | 22 +++++++------- lib/librte_vhost/vhost_user/vhost-net-user.c | 16 +++++----- lib/librte_vhost/vhost_user/virtio-net-user.c | 2 +- lib/librte_vhost/virtio-net.c | 30 +++++++++--------- 10 files changed, 83 insertions(+), 83 deletions(-)
examples/vhost/main.c +22 -22
@@ -716,7 +716,7 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)if (find_vhost_dev (&pkt_hdr->s_addr)) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) device is using a registered MAC!\n" , - vdev->device_fh); + vdev->vid);return -1 ; }
@@ -724,12 +724,12 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m) vdev->mac_address.addr_bytes[i] = pkt_hdr->s_addr.addr_bytes[i];/* vlan_tag currently uses the device_id. */ - vdev->vlan_tag = vlan_tags[vdev->device_fh]; + vdev->vlan_tag = vlan_tags[vdev->vid];/* Print out VMDQ registration info. */ RTE_LOG(INFO, VHOST_DATA, "(%d) mac %02x:%02x:%02x:%02x:%02x:%02x and vlan %d registered\n", - vdev->device_fh, + vdev->vid, vdev->mac_address.addr_bytes[0], vdev->mac_address.addr_bytes[1], vdev->mac_address.addr_bytes[2], vdev->mac_address.addr_bytes[3], vdev->mac_address.addr_bytes[4], vdev->mac_address.addr_bytes[5],
@@ -737,11 +737,11 @@ link_vmdq(struct vhost_dev *vdev, struct rte_mbuf *m)/* Register the MAC address. */ ret =rte_eth_dev_mac_addr_add (ports[0 ], &vdev->mac_address, - (uint32_t )vdev->device_fh + vmdq_pool_base); + (uint32_t )vdev->vid + vmdq_pool_base);if (ret)RTE_LOG (ERR ,VHOST_DATA ,"(%d) failed to add device MAC address to VMDQ\n" , - vdev->device_fh); + vdev->vid);/* Enable stripping of the vlan tag as we handle routing. */ if (vlan_strip)
@@ -820,19 +820,19 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)if (!dst_vdev)return -1 ; -if (vdev->device_fh == dst_vdev->device_fh) { +if (vdev->vid == dst_vdev->vid) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - vdev->device_fh); + vdev->vid);return 0 ; }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC address is local\n" , dst_vdev->device_fh); +"(%d) TX: MAC address is local\n" , dst_vdev->vid);if (unlikely (dst_vdev->remove)) {RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) device is marked for removal\n" , dst_vdev->device_fh); +"(%d) device is marked for removal\n" , dst_vdev->vid);return 0 ; }
@@ -855,10 +855,10 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,if (!dst_vdev)return 0 ; -if (vdev->device_fh == dst_vdev->device_fh) { +if (vdev->vid == dst_vdev->vid) {RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: src and dst MAC is same. Dropping packet.\n" , - vdev->device_fh); + vdev->vid);return -1 ; }
@@ -868,11 +868,11 @@ find_local_dest(struct vhost_dev *vdev, struct rte_mbuf *m,* the packet length by plus it. */ *offset =VLAN_HLEN ; - *vlan_tag = vlan_tags[vdev->device_fh]; + *vlan_tag = vlan_tags[vdev->vid];RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: pkt to local VM device id: (%d), vlan tag: %u.\n" , - vdev->device_fh, dst_vdev->device_fh, *vlan_tag); + vdev->vid, dst_vdev->vid, *vlan_tag);return 0 ; }
@@ -963,7 +963,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag) }RTE_LOG (DEBUG ,VHOST_DATA , -"(%d) TX: MAC address is external\n" , vdev->device_fh); +"(%d) TX: MAC address is external\n" , vdev->vid); queue2nic:
@@ -1094,7 +1094,7 @@ drain_virtio_tx(struct vhost_dev *vdev) }for (i =0 ; i < count; ++i) -virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->device_fh]); +virtio_tx_route (vdev, pkts[i], vlan_tags[vdev->vid]); }/*
@@ -1206,7 +1206,7 @@ destroy_device (volatile struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been removed from data core\n" , - vdev->device_fh); + vdev->vid);rte_free (vdev); }
@@ -1221,21 +1221,21 @@ new_device (struct virtio_net *dev)int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; -int device_fh = dev->device_fh; +int vid = dev->vid; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA ,"(%d) couldn't allocate memory for vhost dev\n" , - device_fh); + vid);return -1 ; } vdev->dev = dev; dev->priv = vdev; - vdev->device_fh = device_fh; + vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry); - vdev->vmdq_rx_q = device_fh * queues_per_pool + vmdq_queue_base; + vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;/*reset ready flag*/ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1260,7 +1260,7 @@ new_device (struct virtio_net *dev)RTE_LOG (INFO ,VHOST_DATA ,"(%d) device has been added to data core %d\n" , - device_fh, vdev->coreid); + vid, vdev->coreid);return 0 ; }
@@ -1312,7 +1312,7 @@ print_stats(void)"RX total: %" PRIu64"\n" "RX dropped: %" PRIu64"\n" "RX successful: %" PRIu64"\n" , - vdev->dev->device_fh, + vdev->dev->vid, tx_total, tx_dropped, tx, rx_total, rx_dropped, rx); }
examples/vhost/main.h +1 -1
@@ -66,7 +66,7 @@ struct vhost_dev {/**< Device is marked for removal from the data core. */ volatile uint8_t remove; -int device_fh; +int vid;struct device_statistics stats;TAILQ_ENTRY (vhost_dev) global_vdev_entry;TAILQ_ENTRY (vhost_dev) lcore_vdev_entry;
lib/librte_vhost/rte_virtio_net.h +1 -1
@@ -133,7 +133,7 @@ struct virtio_net {struct virtio_memory *mem;/**< QEMU memory and memory region information. */ uint64_t features;/**< Negotiated feature set. */ uint64_t protocol_features;/**< Negotiated protocol feature set. */ -int device_fh;/**< device identifier. */ +int vid;/**< device identifier. */ uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ #define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */
lib/librte_vhost/vhost-net.h +3 -3
@@ -57,9 +57,9 @@char packet[VHOST_MAX_PRINT_BUFF ]; \ \if ((header)) \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Header size %d: " , (device->vid), (size)); \else \ -snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->device_fh), (size)); \ +snprintf (packet,VHOST_MAX_PRINT_BUFF ,"(%d) Packet size %d: " , (device->vid), (size)); \for (index =0 ; index < (size); index++) { \snprintf (packet +strnlen (packet,VHOST_MAX_PRINT_BUFF ),VHOST_MAX_PRINT_BUFF -strnlen (packet,VHOST_MAX_PRINT_BUFF ), \"%02hhx " , pkt_addr[index]); \
@@ -80,7 +80,7 @@*/ struct vhost_device_ctx {pid_t pid;/* PID of process calling the IOCTL. */ -int fh;/* Populated with fi->fh to track the device index. */ +int vid;/* Virtio-net device ID */ };int vhost_new_device (struct vhost_device_ctx );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +18 -18
@@ -70,7 +70,7 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi)struct fuse_ctx const *const req_ctx =fuse_req_ctx (req); ctx.pid = req_ctx->pid; - ctx.fh = fi->fh; + ctx.vid = (int )fi->fh;return ctx; }
@@ -94,7 +94,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) fi->fh = err;RTE_LOG (INFO ,VHOST_CONFIG , -"(%d) device configuration started\n" , fi->fh); +"(%d) device configuration started\n" , err);fuse_reply_open (req, fi); }
@@ -108,7 +108,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx); -RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.vid);fuse_reply_err (req, err); }
@@ -194,7 +194,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,switch (cmd) {case VHOST_NET_SET_BACKEND :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.fh); +"(%d) IOCTL: VHOST_NET_SET_BACKEND\n" , ctx.vid);if (!in_buf) {VHOST_IOCTL_RETRY (sizeof (file),0 );break ;
@@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_GET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_FEATURES\n" , ctx.vid);VHOST_IOCTL_W (uint64_t, features, vhost_get_features);break ;case VHOST_SET_FEATURES :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_FEATURES\n" , ctx.vid);VHOST_IOCTL_R (uint64_t, features, vhost_set_features);break ;case VHOST_RESET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_RESET_OWNER\n" , ctx.vid);VHOST_IOCTL (vhost_reset_owner);break ;case VHOST_SET_OWNER :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_OWNER\n" , ctx.vid);VHOST_IOCTL (vhost_set_owner);break ;case VHOST_SET_MEM_TABLE :/*TODO fix race condition.*/ LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_MEM_TABLE\n" , ctx.vid);static struct vhost_memory mem_temp;switch (in_bufsz) {
@@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,case VHOST_SET_VRING_NUM :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_NUM\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num);break ;case VHOST_SET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_BASE\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base);break ;case VHOST_GET_VRING_BASE :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.fh); +"(%d) IOCTL: VHOST_GET_VRING_BASE\n" , ctx.vid);VHOST_IOCTL_RW (uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base);break ;case VHOST_SET_VRING_ADDR :LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.fh); +"(%d) IOCTL: VHOST_SET_VRING_ADDR\n" , ctx.vid); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr);break ;
@@ -295,11 +295,11 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,if (cmd ==VHOST_SET_VRING_KICK )LOG_DEBUG (VHOST_CONFIG ,"(%d) IOCTL: VHOST_SET_VRING_KICK\n" , - ctx.fh); + ctx.vid);else LOG_DEBUG (VHOST_CONFIG ,"(%d) IOCTL: VHOST_SET_VRING_CALL\n" , - ctx.fh); + ctx.vid);if (!in_buf)VHOST_IOCTL_RETRY (sizeof (struct vhost_vring_file ),0 );else {
@@ -326,17 +326,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,default :RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.fh); +"(%d) IOCTL: DOESN NOT EXIST\n" , ctx.vid); result =-1 ;fuse_reply_ioctl (req, result,NULL ,0 ); }if (result <0 )LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: FAIL\n" , ctx.fh); +"(%d) IOCTL: FAIL\n" , ctx.vid);else LOG_DEBUG (VHOST_CONFIG , -"(%d) IOCTL: SUCCESS\n" , ctx.fh); +"(%d) IOCTL: SUCCESS\n" , ctx.vid); }/*
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +3 -3
@@ -290,7 +290,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to allocate memory for dev->mem\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -394,7 +394,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, intif (close (fd_tap) <0 )RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , - dev->device_fh); + dev->vid);if (ret >=0 ) { ifr_size =strnlen (ifr.ifr_name,sizeof (ifr.ifr_name));
@@ -402,7 +402,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int }else RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) TUNGETIFF ioctl failed\n" , - dev->device_fh); + dev->vid);return 0 ; }
lib/librte_vhost/vhost_rxtx.c +11 -11
@@ -264,10 +264,10 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,uint16_t desc_indexes[MAX_PKT_BURST ];uint32_t i; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -280,7 +280,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,return 0 ;LOG_DEBUG (VHOST_DATA ,"(%d) res_start_idx %d | res_end_idx Index %d\n" , - dev->device_fh, res_start_idx, res_end_idx); + dev->vid, res_start_idx, res_end_idx);/* Retrieve all of the desc indexes first to avoid caching issues. */ rte_prefetch0 (&vq->avail->ring[res_start_idx & (vq->size -1 )]);
@@ -442,7 +442,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,return 0 ;LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , - dev->device_fh, cur_idx, res_end_idx); + dev->vid, cur_idx, res_end_idx);if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen)return -1 ;
@@ -452,7 +452,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, virtio_hdr.num_buffers = res_end_idx - res_start_idx;LOG_DEBUG (VHOST_DATA ,"(%d) RX: num merge buffers %d\n" , - dev->device_fh, virtio_hdr.num_buffers); + dev->vid, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr);copy_virtio_net_hdr (vq, desc_addr, virtio_hdr);
@@ -530,10 +530,10 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,uint32_t pkt_idx =0 , nr_used =0 ;uint16_t start, end; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);if (unlikely (!is_valid_virt_queue_idx (queue_id,0 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -552,7 +552,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, &start, &end) < 0)) {LOG_DEBUG (VHOST_DATA ,"(%d) failed to get enough desc from vring\n" , - dev->device_fh); + dev->vid);break ; }
@@ -828,7 +828,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , - dev->device_fh, __func__, queue_id); + dev->vid, __func__, queue_id);return 0 ; }
@@ -864,7 +864,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,if (free_entries ==0 ) goto out; -LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->device_fh, __func__); +LOG_DEBUG (VHOST_DATA ,"(%d) %s\n" , dev->vid, __func__);/* Prefetch available ring to retrieve head indexes. */ used_idx = vq->last_used_idx & (vq->size -1 );
@@ -873,7 +873,7 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, count =RTE_MIN (count,MAX_PKT_BURST ); count =RTE_MIN (count, free_entries);LOG_DEBUG (VHOST_DATA ,"(%d) about to dequeue %u buffers\n" , - dev->device_fh, count); + dev->vid, count);/* Retrieve all of the head indexes first to avoid caching issues. */ for (i =0 ; i < count; i++) {
lib/librte_vhost/vhost_user/vhost-net-user.c +8 -8
@@ -58,7 +58,7 @@ static void vserver_message_handler(int fd, void *dat, int *remove);struct connfd_ctx {struct vhost_server *vserver; -int fh; +int vid; };#define MAX_VHOST_SERVER 1024
@@ -285,7 +285,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)struct vhost_server *vserver = (struct vhost_server *)dat;int conn_fd;struct connfd_ctx *ctx; -int fh; +int vid;struct vhost_device_ctx vdev_ctx = { (pid_t )0 ,0 };unsigned int size;
@@ -301,22 +301,22 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)return ; } - fh =vhost_new_device (vdev_ctx); -if (fh ==-1 ) { + vid =vhost_new_device (vdev_ctx); +if (vid ==-1 ) {free (ctx);close (conn_fd);return ; } - vdev_ctx.fh = fh; + vdev_ctx.vid = vid; size =strnlen (vserver->path,PATH_MAX );vhost_set_ifname (vdev_ctx, vserver->path, size); -RTE_LOG (INFO ,VHOST_CONFIG ,"new device, handle is %d\n" , fh); +RTE_LOG (INFO ,VHOST_CONFIG ,"new device, handle is %d\n" , vid); ctx->vserver = vserver; - ctx->fh = fh; + ctx->vid = vid;fdset_add (&g_vhost_server.fdset, conn_fd, vserver_message_handler,NULL , ctx); }
@@ -331,7 +331,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)uint64_t features;int ret; - ctx.fh = cfd_ctx->fh; + ctx.vid = cfd_ctx->vid; ret =read_vhost_message (connfd, &msg);if (ret <=0 || msg.request >=VHOST_USER_MAX ) {if (ret <0 )
lib/librte_vhost/vhost_user/virtio-net-user.c +1 -1
@@ -133,7 +133,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)if (dev->mem ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to allocate memory for dev->mem\n" , - dev->device_fh); + dev->vid);return -1 ; } dev->mem->nregions = memory.nregions;
lib/librte_vhost/virtio-net.c +15 -15
@@ -112,11 +112,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)struct virtio_net *get_device (struct vhost_device_ctx ctx) { -struct virtio_net *dev = vhost_devices[ctx.fh]; +struct virtio_net *dev = vhost_devices[ctx.vid];if (unlikely (!dev)) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) device not found.\n" , ctx.fh); +"(%d) device not found.\n" , ctx.vid); }return dev;
@@ -233,7 +233,7 @@ alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx)/* * Reset some variables in device structure, while keeping few -* others untouched, such as device_fh, ifname, virt_qp_nb: they +* others untouched, such as vid, ifname, virt_qp_nb: they * should be same unless the device is removed. */ static void
@@ -263,7 +263,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev =rte_zmalloc (NULL ,sizeof (struct virtio_net ),0 );if (dev ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) failed to allocate memory for dev.\n" , ctx.fh); +"(%d) failed to allocate memory for dev.\n" , ctx.vid);return -1 ; }
@@ -278,7 +278,7 @@ vhost_new_device(struct vhost_device_ctx ctx) } vhost_devices[i] = dev; - dev->device_fh = i; + dev->vid = i;return i; }
@@ -303,7 +303,7 @@ vhost_destroy_device(struct vhost_device_ctx ctx)cleanup_device (dev,1 );free_device (dev); - vhost_devices[ctx.fh] =NULL ; + vhost_devices[ctx.vid] =NULL ; }void
@@ -408,7 +408,7 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) }LOG_DEBUG (VHOST_CONFIG ,"(%d) mergeable RX buffers %s, virtio 1 %s\n" , - dev->device_fh, + dev->vid, (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL <<VIRTIO_F_VERSION_1 )) ?"on" :"off" );
@@ -513,7 +513,7 @@ numa_realloc(struct virtio_net *dev, int index) out: dev->virtqueue[index] = vq; dev->virtqueue[index +1 ] = vq +1 ; - vhost_devices[dev->device_fh] = dev; + vhost_devices[dev->vid] = dev;return dev; }
@@ -549,7 +549,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->desc ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find desc ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -561,7 +561,7 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->avail ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find avail ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; }
@@ -570,20 +570,20 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)if (vq->used ==0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) failed to find used ring address.\n" , - dev->device_fh); + dev->vid);return -1 ; } vq->log_guest_addr = addr->log_guest_addr;LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address desc: %p\n" , - dev->device_fh, vq->desc); + dev->vid, vq->desc);LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address avail: %p\n" , - dev->device_fh, vq->avail); + dev->vid, vq->avail);LOG_DEBUG (VHOST_CONFIG ,"(%d) mapped address used: %p\n" , - dev->device_fh, vq->used); + dev->vid, vq->used);LOG_DEBUG (VHOST_CONFIG ,"(%d) log_guest_addr: %" PRIx64"\n" , - dev->device_fh, vq->log_guest_addr); + dev->vid, vq->log_guest_addr);return 0 ; }
Signature · 1 line
1.9.0
PATCH v3 6/20 vhost: get device by vid only
In reply to Yuanhan Liuget_device() just needs vid, so pass vid as the parameter only.
--- lib/librte_vhost/vhost-net.h | 30 ++++++------ lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 64 ++++++++++++------------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++--- lib/librte_vhost/vhost_user/vhost-net-user.c | 43 ++++++++--------- lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++------- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++--- lib/librte_vhost/virtio-net.c | 68 +++++++++++++-------------- lib/librte_vhost/virtio-net.h | 2 +- 8 files changed, 132 insertions(+), 147 deletions(-)
lib/librte_vhost/vhost-net.h +14 -16
@@ -83,28 +83,26 @@ struct vhost_device_ctx {int vid;/* Virtio-net device ID */ }; -int vhost_new_device (struct vhost_device_ctx ); -void vhost_destroy_device (struct vhost_device_ctx ); +int vhost_new_device (void ); +void vhost_destroy_device (int ); -void vhost_set_ifname (struct vhost_device_ctx , -const char *if_name,unsigned int if_len); +void vhost_set_ifname (int ,const char *if_name,unsigned int if_len); -int vhost_get_features (struct vhost_device_ctx ,uint64_t *); -int vhost_set_features (struct vhost_device_ctx ,uint64_t *); +int vhost_get_features (int ,uint64_t *); +int vhost_set_features (int ,uint64_t *); -int vhost_set_vring_num (struct vhost_device_ctx ,struct vhost_vring_state *); -int vhost_set_vring_addr (struct vhost_device_ctx ,struct vhost_vring_addr *); -int vhost_set_vring_base (struct vhost_device_ctx ,struct vhost_vring_state *); -int vhost_get_vring_base (struct vhost_device_ctx , -uint32_t ,struct vhost_vring_state *); +int vhost_set_vring_num (int ,struct vhost_vring_state *); +int vhost_set_vring_addr (int ,struct vhost_vring_addr *); +int vhost_set_vring_base (int ,struct vhost_vring_state *); +int vhost_get_vring_base (int ,uint32_t ,struct vhost_vring_state *); -int vhost_set_vring_kick (struct vhost_device_ctx ,struct vhost_vring_file *); -int vhost_set_vring_call (struct vhost_device_ctx ,struct vhost_vring_file *); +int vhost_set_vring_kick (int ,struct vhost_vring_file *); +int vhost_set_vring_call (int ,struct vhost_vring_file *); -int vhost_set_backend (struct vhost_device_ctx ,struct vhost_vring_file *); +int vhost_set_backend (int ,struct vhost_vring_file *); -int vhost_set_owner (struct vhost_device_ctx ); -int vhost_reset_owner (struct vhost_device_ctx ); +int vhost_set_owner (int ); +int vhost_reset_owner (int );/* * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +31 -33
213 lines not on this page · raw message
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +8 -10
@@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,uint64_t base_address =0 , mapped_address, mapped_size;struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (ctx.vid);if (dev ==NULL )return -1 ;
@@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx,* save it in the device structure. */ static int -get_ifname (struct vhost_device_ctx ctx,struct virtio_net *dev,int tap_fd,int pid) +get_ifname (int vid,int tap_fd,int pid) {int fd_tap;struct ifreq ifr;
@@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret =ioctl (fd_tap,TUNGETIFF , &ifr);if (close (fd_tap) <0 ) -RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , - dev->vid); +RTE_LOG (ERR ,VHOST_CONFIG ,"(%d) fd close failed\n" , vid);if (ret >=0 ) { ifr_size =strnlen (ifr.ifr_name,sizeof (ifr.ifr_name)); -vhost_set_ifname (ctx, ifr.ifr_name, ifr_size); +vhost_set_ifname (vid, ifr.ifr_name, ifr_size); }else RTE_LOG (ERR ,VHOST_CONFIG , -"(%d) TUNGETIFF ioctl failed\n" , - dev->vid); +"(%d) TUNGETIFF ioctl failed\n" , vid);return 0 ; }
@@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) {struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (ctx.vid);if (dev ==NULL )return -1 ;if (!(dev->flags &VIRTIO_DEV_RUNNING ) && file->fd !=VIRTIO_DEV_STOPPED ) -get_ifname (ctx, dev, file->fd, ctx.pid); +get_ifname (ctx.vid, file->fd, ctx.pid); -return vhost_set_backend (ctx, file); +return vhost_set_backend (ctx.vid, file); }void
lib/librte_vhost/vhost_user/vhost-net-user.c +20 -23
136 lines not on this page · raw message
lib/librte_vhost/vhost_user/virtio-net-user.c +18 -18
@@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev) }int -user_set_mem_table (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_mem_table (int vid,struct VhostUserMsg *pmsg) {struct VhostUserMemory memory = pmsg->payload.memory;struct virtio_memory_regions *pregion;
@@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)uint64_t alignment;/* unmap old memory regions one by one*/ - dev =get_device (ctx); + dev =get_device (vid);if (dev ==NULL )return -1 ;
@@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev) }void -user_set_vring_call (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_vring_call (int vid,struct VhostUserMsg *pmsg) {struct vhost_vring_file file;
@@ -265,7 +265,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) file.fd = pmsg->fds[0 ];RTE_LOG (INFO ,VHOST_CONFIG ,"vring call idx:%d file:%d\n" , file.index, file.fd); -vhost_set_vring_call (ctx, &file); +vhost_set_vring_call (vid, &file); }
@@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)* device is ready for packet processing. */ void -user_set_vring_kick (struct vhost_device_ctx ctx,struct VhostUserMsg *pmsg) +user_set_vring_kick (int vid,struct VhostUserMsg *pmsg) {struct vhost_vring_file file; -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid); file.index = pmsg->payload.u64 &VHOST_USER_VRING_IDX_MASK ;if (pmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK )
@@ -286,7 +286,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) file.fd = pmsg->fds[0 ];RTE_LOG (INFO ,VHOST_CONFIG ,"vring kick idx:%d file:%d\n" , file.index, file.fd); -vhost_set_vring_kick (ctx, &file); +vhost_set_vring_kick (vid, &file);if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) {if (notify_ops->new_device (dev) ==0 )
@@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)* when virtio is stopped, qemu will send us the GET_VRING_BASE message. */ int -user_get_vring_base (struct vhost_device_ctx ctx, +user_get_vring_base (int vid,struct vhost_vring_state *state) { -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid);if (dev ==NULL )return -1 ;
@@ -310,7 +310,7 @@ user_get_vring_base(struct vhost_device_ctx ctx, notify_ops->destroy_device (dev);/* Here we are safe to get the last used index */ -vhost_get_vring_base (ctx, state->index, state); +vhost_get_vring_base (vid, state->index, state);RTE_LOG (INFO ,VHOST_CONFIG ,"vring base idx:%d file:%d\n" , state->index, state->num);
@@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,* enable the virtio queue pair. */ int -user_set_vring_enable (struct vhost_device_ctx ctx, +user_set_vring_enable (int vid,struct vhost_vring_state *state) { -struct virtio_net *dev =get_device (ctx); +struct virtio_net *dev =get_device (vid);int enable = (int )state->num; RTE_LOG(INFO, VHOST_CONFIG,
@@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx, }void -user_set_protocol_features (struct vhost_device_ctx ctx, +user_set_protocol_features (int vid,uint64_t protocol_features) {struct virtio_net *dev; - dev =get_device (ctx); + dev =get_device (vid);if (dev ==NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES )return ;
@@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx, }int -user_set_log_base (struct vhost_device_ctx ctx, +user_set_log_base (int vid,struct VhostUserMsg *msg) {struct virtio_net *dev;
@@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx,uint64_t size, off;void *addr; - dev =get_device (ctx); + dev =get_device (vid);if (!dev)return -1 ;
@@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx,* a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it. */ int -user_send_rarp (struct vhost_device_ctx ctx,struct VhostUserMsg *msg) +user_send_rarp (int vid,struct VhostUserMsg *msg) {struct virtio_net *dev;uint8_t *mac = (uint8_t *)&msg->payload.u64; - dev =get_device (ctx); + dev =get_device (vid);if (!dev)return -1 ;
lib/librte_vhost/vhost_user/virtio-net-user.h +8 -10
@@ -45,20 +45,18 @@ (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\ (1ULL << VHOST_USER_PROTOCOL_F_RARP)) -int user_set_mem_table (struct vhost_device_ctx ,struct VhostUserMsg *); +int user_set_mem_table (int ,struct VhostUserMsg *); -void user_set_vring_call (struct vhost_device_ctx ,struct VhostUserMsg *); +void user_set_vring_call (int ,struct VhostUserMsg *); -void user_set_vring_kick (struct vhost_device_ctx ,struct VhostUserMsg *); +void user_set_vring_kick (int ,struct VhostUserMsg *); -void user_set_protocol_features (struct vhost_device_ctx ctx, -uint64_t protocol_features); -int user_set_log_base (struct vhost_device_ctx ctx,struct VhostUserMsg *); -int user_send_rarp (struct vhost_device_ctx ctx,struct VhostUserMsg *); +void user_set_protocol_features (int vid,uint64_t protocol_features); +int user_set_log_base (int vid,struct VhostUserMsg *); +int user_send_rarp (int vid,struct VhostUserMsg *); -int user_get_vring_base (struct vhost_device_ctx ,struct vhost_vring_state *); +int user_get_vring_base (int ,struct vhost_vring_state *); -int user_set_vring_enable (struct vhost_device_ctx ctx, -struct vhost_vring_state *state); +int user_set_vring_enable (int vid,struct vhost_vring_state *state);#endif
lib/librte_vhost/virtio-net.c +32 -36
217 lines not on this page · raw message
lib/librte_vhost/virtio-net.h +1 -1
@@ -38,6 +38,6 @@#include "rte_virtio_net.h" struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device (struct vhost_device_ctx ctx); +struct virtio_net *get_device (int vid);#endif
Signature · 1 line
1.9.0
PATCH v3 7/20 vhost: move vhost device ctx to cuse
In reply to Yuanhan Liuvhost cuse is now the last reference of the vhost_device_ctx struct; move it there, and do a rename to "vhost_cuse_device_ctx", to make it clear that it's "cuse only".
--- lib/librte_vhost/vhost-net.h | 8 -------- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 13 +++++++------ lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 6 ++++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 ++++++++++-- 4 files changed, 21 insertions(+), 18 deletions(-)
lib/librte_vhost/vhost-net.h +0 -8
@@ -75,14 +75,6 @@#endif -/* -* Structure used to identify device context. -*/ -struct vhost_device_ctx { -pid_t pid;/* PID of process calling the IOCTL. */ -int vid;/* Virtio-net device ID */ -}; -int vhost_new_device (void );void vhost_destroy_device (int );
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +7 -6
@@ -60,13 +60,14 @@ static const char default_cdev[] = "vhost-net";static struct fuse_session *session;/* -* Returns vhost_device_ctx from given fuse_req_t. The index is populated later -* when the device is added to the device linked list. +* Returns vhost_cuse_device_ctx from given fuse_req_t. The +* index is populated later when the device is added to the +* device linked list. */ -static struct vhost_device_ctx +static struct vhost_cuse_device_ctx fuse_req_to_vhost_ctx (fuse_req_t req,struct fuse_file_info *fi) { -struct vhost_device_ctx ctx; +struct vhost_cuse_device_ctx ctx;struct fuse_ctx const *const req_ctx =fuse_req_ctx (req); ctx.pid = req_ctx->pid;
@@ -104,7 +105,7 @@ static void vhost_net_release(fuse_req_t req, struct fuse_file_info *fi) { int err = 0; -struct vhost_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi); +struct vhost_cuse_device_ctx ctx =fuse_req_to_vhost_ctx (req, fi);vhost_destroy_device (ctx.vid);RTE_LOG (INFO ,VHOST_CONFIG ,"(%d) device released\n" , ctx.vid);
@@ -182,7 +183,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, struct fuse_file_info *fi, __rte_unused unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz) { - struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi); + struct vhost_cuse_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);struct vhost_vring_file file;struct vhost_vring_state state;struct vhost_vring_addr addr;
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +4 -2
@@ -263,7 +263,7 @@ host_memory_map(pid_t pid, uint64_t addr, }int -cuse_set_mem_table (struct vhost_device_ctx ctx, +cuse_set_mem_table (struct vhost_cuse_device_ctx ctx,const struct vhost_memory *mem_regions_addr,uint32_t nregions) {uint64_t size = offsetof(struct vhost_memory , regions);
@@ -405,7 +405,9 @@ get_ifname(int vid, int tap_fd, int pid)return 0 ; } -int cuse_set_backend (struct vhost_device_ctx ctx,struct vhost_vring_file *file) +int +cuse_set_backend (struct vhost_cuse_device_ctx ctx, +struct vhost_vring_file *file) {struct virtio_net *dev;
lib/librte_vhost/vhost_cuse/virtio-net-cdev.h +10 -2
@@ -38,11 +38,19 @@#include "vhost-net.h" +/* +* Structure used to identify device context. +*/ +struct vhost_cuse_device_ctx { +pid_t pid;/* PID of process calling the IOCTL. */ +int vid;/* Virtio-net device ID */ +}; +int -cuse_set_mem_table (struct vhost_device_ctx ctx, +cuse_set_mem_table (struct vhost_cuse_device_ctx ctx,const struct vhost_memory *mem_regions_addr,uint32_t nregions);int -cuse_set_backend (struct vhost_device_ctx ctx,struct vhost_vring_file *); +cuse_set_backend (struct vhost_cuse_device_ctx ctx,struct vhost_vring_file *);#endif
Signature · 1 line
1.9.0
PATCH v3 8/20 vhost: introduce new API to export numa node
In reply to Yuanhan LiuIntroduce a new API rte_vhost_get_numa_node() to get the numa node from which the virtio_net struct is allocated.
--- drivers/net/vhost/rte_eth_vhost.c | 13 ++++--------- lib/librte_vhost/rte_vhost_version.map | 7 +++++++ lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/virtio-net.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +4 -9
@@ -230,7 +230,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 ) {
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev) internal = eth_dev->data->dev_private;#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++) {
lib/librte_vhost/rte_vhost_version.map +7 -0
@@ -20,3 +20,10 @@ DPDK_2.1 { rte_vhost_driver_unregister; } DPDK_2.0; + +DPDK_16.07 { + global: + + rte_vhost_get_numa_node; + +} DPDK_16.04;
lib/librte_vhost/rte_virtio_net.h +12 -0
@@ -245,6 +245,18 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * consint rte_vhost_driver_session_start (void );/** +* 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
lib/librte_vhost/virtio-net.c +26 -0
@@ -730,6 +730,32 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)return 0 ; } +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_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
Re: [PATCH v3 08/20] vhost: introduce new API to export numa node
Quoted 13 lines · Yuanhan Liu
Introduce a new API
rte_vhost_get_numa_node()to get the numa node from which thevirtio_netstruct is allocated.Signed-off-by Yuanhan Liu <[email protected]>Tested-by Rich Lane <[email protected]>Acked-by Rich Lane <[email protected]>--- drivers/net/vhost/rte_eth_vhost.c | 13 ++++--------- lib/librte_vhost/rte_vhost_version.map | 7 +++++++ lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/virtio-net.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-)
[...]
Quoted 5 lines
lib/librte_vhost/rte_vhost_version.map +0
-0
lib/librte_vhost/rte_vhost_version.map DPDK_2.1 { · line 29
Quoted 10 lines
lib/librte_vhost/rte_vhost_version.map +7
-0@@ -20,3 +20,10 @@ DPDK_2.1 { rte_vhost_driver_unregister; } DPDK_2.0; + +DPDK_16.07 { + global: + + rte_vhost_get_numa_node; + +} DPDK_16.04;
This fails to compile in shared library configuration:
LD librte_vhost.so.3.1/usr/bin/ld: unable to find version dependency `DPDK_16.04'
collect2: error: ld returned 1 exit status
Problem obviously being that DPDK_16.04 does not exist, the most recent version symbol for librte_vhost is DPDK_2.1 so you need to inherit from that instead.
- Panu -
Re: [PATCH v3 08/20] vhost: introduce new API to export numa node
Quoted 33 lines · Panu Matilainen
Quoted 13 lines · Yuanhan Liu
Introduce a new API
rte_vhost_get_numa_node()to get the numa node from which thevirtio_netstruct is allocated.Signed-off-by Yuanhan Liu <[email protected]>Tested-by Rich Lane <[email protected]>Acked-by Rich Lane <[email protected]>---
drivers/net/vhost/rte_eth_vhost.c | 13 ++++--------- lib/librte_vhost/rte_vhost_version.map | 7 +++++++ lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/virtio-net.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-)[...]
Quoted 5 lines
lib/librte_vhost/rte_vhost_version.map +0
-0lib/librte_vhost/rte_vhost_version.map DPDK_2.1 { · line 29
Quoted 10 lines
lib/librte_vhost/rte_vhost_version.map +7
-0@@ -20,3 +20,10 @@ DPDK_2.1 { rte_vhost_driver_unregister; } DPDK_2.0; + +DPDK_16.07 { + global: + + rte_vhost_get_numa_node; + +} DPDK_16.04;This fails to compile in shared library configuration:
Quoted 7 lines
LD librte_vhost.so.3.1
/usr/bin/ld: unable to find version dependency `DPDK_16.04'
collect2: error: ld returned 1 exit statusProblem obviously being that DPDK_16.04 does not exist, the most recent version symbol for
librte_vhostis DPDK_2.1 so you need to inherit from that instead.
Panu, thanks for the catching, and will fix it.
--yliu
Re: [PATCH v3 08/20] vhost: introduce new API to export numa node
In reply to Yuanhan LiuQuoted 6 lines · Yuanhan Liu
drivers/net/vhost/rte_eth_vhost.c +0
-1@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev) internal = eth_dev->data->dev_private;#ifdef RTE_LIBRTE_VHOST_NUMA - ret = get_mempolicy(&newnode, NULL, 0, dev,
drivers/net/vhost/rte_eth_vhost.c new_device(struct virtio_net *dev) · line 253
Quoted 10 lines
drivers/net/vhost/rte_eth_vhost.c +2
-7- 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 )
Should be "newnode >= 0".
+ eth_dev->data->numa_node = newnode;
Quoted 2 lines
(quoted diff) +0
-0#endif
Re: [PATCH v3 08/20] vhost: introduce new API to export numa node
Quoted 19 lines · Rich Lane
On Mon, Jun 6, 2016 at 8:51 PM, Yuanhan Liu <[email protected]> wrote:
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev) internal = eth_dev->data->dev_private; #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)
Quoted 1 line
Should be "newnode >= 0".
Nice catch! Thanks.
--yliu
Re: [PATCH v3 08/20] vhost: introduce new API to export numa node
Quoted 20 lines · Yuanhan Liu
Quoted 19 lines · Rich Lane
On Mon, Jun 6, 2016 at 8:51 PM, Yuanhan Liu <[email protected]> wrote:
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev) internal = eth_dev->data->dev_private; #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)
Quoted 3 lines
Quoted 1 line
Should be "newnode >= 0".
Nice catch! Thanks.
Here is the update patch that includes the fix of two issues reported by Rich and Panu.
And if there is no objection, I'd like to apply this series plus some other series on virtio/vhost from mine in one or two days: it's close to the RC1 deadline now.
--yliu
---
Quoted 1 line
From
f378af61f6ba7dcfcd20ab180fba166619ea3d88Mon Sep 17 00:00:00 2001
From: Yuanhan Liu <[email protected]>
Date: Wed, 11 May 2016 06:12:57 +0800
Subject: [PATCH] vhost: introduce new API to export numa node
Introduce a new API rte_vhost_get_numa_node() to get the numa node from which the virtio_net struct is allocated.
---
v4: - fix build error in shared configuration reported by Panu
- fix numa node check reported by Rich
--- drivers/net/vhost/rte_eth_vhost.c | 13 ++++--------- lib/librte_vhost/rte_vhost_version.map | 7 +++++++ lib/librte_vhost/rte_virtio_net.h | 12 ++++++++++++ lib/librte_vhost/virtio-net.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +4 -9
@@ -230,7 +230,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 ) {
@@ -248,14 +248,9 @@ new_device(struct virtio_net *dev) internal = eth_dev->data->dev_private;#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++) {
lib/librte_vhost/rte_vhost_version.map +7 -0
@@ -20,3 +20,10 @@ DPDK_2.1 { rte_vhost_driver_unregister; } DPDK_2.0; + +DPDK_16.07 { + global: + + rte_vhost_get_numa_node; + +} DPDK_2.1;
lib/librte_vhost/rte_virtio_net.h +12 -0
@@ -245,6 +245,18 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * consint rte_vhost_driver_session_start (void );/** +* 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
lib/librte_vhost/virtio-net.c +26 -0
@@ -730,6 +730,32 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)return 0 ; } +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_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.3
PATCH v3 9/20 vhost: introduce new API to export number of queues
In reply to Yuanhan LiuIntroduce a new API rte_vhost_get_queue_num() to export the number of queues.
--- drivers/net/vhost/rte_eth_vhost.c | 2 +- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 11 +++++++++++ lib/librte_vhost/virtio-net.c | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-)
drivers/net/vhost/rte_eth_vhost.c +1 -1
@@ -270,7 +270,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;
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -25,5 +25,6 @@ DPDK_16.07 { global: rte_vhost_get_numa_node; + rte_vhost_get_queue_num; } DPDK_16.04;
lib/librte_vhost/rte_virtio_net.h +11 -0
@@ -257,6 +257,17 @@ int rte_vhost_driver_session_start(void);int rte_vhost_get_numa_node (int vid);/** +* 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); + +/** * 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
lib/librte_vhost/virtio-net.c +11 -0
@@ -756,6 +756,17 @@ rte_vhost_get_numa_node(int vid)#endif } +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_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v3 10/20 vhost: introduce new API to export ifname
In reply to Yuanhan LiuIntroduce a new API rte_vhost_get_ifname() to export the ifname to application.
--- drivers/net/vhost/rte_eth_vhost.c | 12 ++++++++---- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 17 +++++++++++++++++ lib/librte_vhost/virtio-net.c | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +8 -4
@@ -229,6 +229,7 @@ new_device(struct virtio_net *dev)struct pmd_internal *internal;struct vhost_queue *vq;unsigned i; +char ifname[PATH_MAX ];#ifdef RTE_LIBRTE_VHOST_NUMA int newnode;#endif
@@ -238,9 +239,10 @@ new_device(struct virtio_net *dev)return -1 ; } - list =find_internal_resource (dev->ifname); +rte_vhost_get_ifname (dev->vid, ifname,sizeof (ifname)); + list =find_internal_resource (ifname);if (list ==NULL ) { -RTE_LOG (INFO ,PMD ,"Invalid device name\n" ); +RTE_LOG (INFO ,PMD ,"Invalid device name: %s\n" , ifname);return -1 ; }
@@ -360,15 +362,17 @@ vring_state_changed(struct virtio_net *dev, uint16_t vring, int enable)struct rte_vhost_vring_state *state;struct rte_eth_dev *eth_dev;struct internal_list *list; +char ifname[PATH_MAX ];if (dev ==NULL ) {RTE_LOG (ERR ,PMD ,"Invalid argument\n" );return -1 ; } - list =find_internal_resource (dev->ifname); +rte_vhost_get_ifname (dev->vid, ifname,sizeof (ifname)); + list =find_internal_resource (ifname);if (list ==NULL ) { -RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , dev->ifname); +RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , ifname);return -1 ; }
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -24,6 +24,7 @@ DPDK_2.1 { DPDK_16.07 { global: + rte_vhost_get_ifname; rte_vhost_get_numa_node; rte_vhost_get_queue_num;
lib/librte_vhost/rte_virtio_net.h +17 -0
@@ -268,6 +268,23 @@ int rte_vhost_get_numa_node(int vid);uint32_t rte_vhost_get_queue_num (int vid);/** +* Get the virtio net device's ifname. For vhost-cuse, ifname is the +* path of the char device. For vhost-user, ifname is the vhost-user +* socket file path. +* +* @param vid +* virtio-net device ID +* @param buf +* The buffer to stored the queried ifname +* @param len +* The length of buf +* +* @return +* 0 on success, -1 on failure +*/ +int rte_vhost_get_ifname (int vid,char *buf,size_t len); + +/** * 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
lib/librte_vhost/virtio-net.c +16 -0
@@ -767,6 +767,22 @@ rte_vhost_get_queue_num(int vid)return dev->virt_qp_nb; } +int +rte_vhost_get_ifname (int vid,char *buf,size_t len) +{ +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return -1 ; + + len =RTE_MIN (len,sizeof (dev->ifname)); + +strncpy (buf, dev->ifname, len); + buf[len -1 ] ='\0' ; + +return 0 ; +} +int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v3 11/20 vhost: introduce new API to export queue free entries
In reply to Yuanhan LiuThe new API rte_vhost_avail_entries() is actually a rename of rte_vring_available_entries(), with the "vring" to "vhost" name change to keep the consistency of other vhost exported APIs.
This change could let us avoid the dependency of "virtio_net" struct, to prepare for the ABI refactoring.
--- doc/guides/rel_notes/release_16_07.rst | 2 ++ examples/vhost/main.c | 4 ++-- lib/librte_vhost/rte_vhost_version.map | 1 + lib/librte_vhost/rte_virtio_net.h | 24 +++++++++++++----------- lib/librte_vhost/virtio-net.c | 17 +++++++++++++++++ 5 files changed, 35 insertions(+), 13 deletions(-)
doc/guides/rel_notes/release_16_07.rst +2 -0
@@ -116,6 +116,8 @@ API Changes ibadcrc, ibadlen, imcasts, fdirmatch, fdirmiss, tx_pause_xon, rx_pause_xon, tx_pause_xoff, rx_pause_xoff. +* ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``. + ABI Changes -----------
examples/vhost/main.c +2 -2
@@ -1055,13 +1055,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 (dev->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 (dev->vid,VIRTIO_RXQ ))break ; }
lib/librte_vhost/rte_vhost_version.map +1 -0
@@ -24,6 +24,7 @@ DPDK_2.1 { DPDK_16.07 { global: + rte_vhost_avail_entries; rte_vhost_get_ifname; rte_vhost_get_numa_node; rte_vhost_get_queue_num;
lib/librte_vhost/rte_virtio_net.h +13 -11
@@ -184,17 +184,6 @@ struct virtio_net_device_ops {int (*vring_state_changed)(struct virtio_net *dev,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ }; -static inline uint16_t __attribute__((always_inline)) -rte_vring_available_entries (struct virtio_net *dev,uint16_t queue_id) -{ -struct vhost_virtqueue *vq = dev->virtqueue[queue_id]; - -if (!vq->enabled) -return 0 ; - -return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res; -} -/** * Function to convert guest physical addresses to vhost virtual addresses. * This is used to convert guest virtio buffer addresses.
@@ -285,6 +274,19 @@ uint32_t rte_vhost_get_queue_num(int vid);int rte_vhost_get_ifname (int vid,char *buf,size_t len);/** +* Get how many avail entries are left in the queue +* +* @param vid +* virtio-net device ID +* @param queue_id +* virtio queue index +* +* @return +* num of avail entires left +*/ +uint16_t rte_vhost_avail_entries (int vid,uint16_t queue_id); + +/** * 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
lib/librte_vhost/virtio-net.c +17 -0
@@ -783,6 +783,23 @@ rte_vhost_get_ifname(int vid, char *buf, size_t len)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; +} +int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable) {
Signature · 1 line
1.9.0
PATCH v3 12/20 vhost: remove dependency on priv field
In reply to Yuanhan LiuThis change could let us avoid the dependency of "virtio_net" struct, to prepare for the ABI refactoring.
--- drivers/net/vhost/rte_eth_vhost.c | 13 +++++++------ examples/vhost/main.c | 10 +++++++--- 2 files changed, 14 insertions(+), 9 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +7 -6
@@ -275,7 +275,6 @@ new_device(struct virtio_net *dev)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; eth_dev->data->dev_link.link_status =ETH_LINK_UP ;for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) {
@@ -303,6 +302,8 @@ destroy_device(volatile struct virtio_net *dev) {struct rte_eth_dev *eth_dev;struct vhost_queue *vq; +struct internal_list *list; +char ifname[PATH_MAX ];unsigned i;if (dev ==NULL ) {
@@ -310,11 +311,13 @@ destroy_device(volatile struct virtio_net *dev)return ; } - eth_dev = (struct rte_eth_dev *)dev->priv; -if (eth_dev ==NULL ) { -RTE_LOG (INFO ,PMD ,"Failed to find a ethdev\n" ); +rte_vhost_get_ifname (dev->vid, ifname,sizeof (ifname)); + list =find_internal_resource (ifname); +if (list ==NULL ) { +RTE_LOG (ERR ,PMD ,"Invalid interface name: %s\n" , ifname);return ; } + eth_dev = list->eth_dev;/* Wait until rx/tx_pkt_burst stops accessing vhost device */ for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) {
@@ -336,8 +339,6 @@ destroy_device(volatile struct virtio_net *dev) eth_dev->data->dev_link.link_status =ETH_LINK_DOWN ; - dev->priv =NULL ; -for (i =0 ; i < eth_dev->data->nb_rx_queues; i++) { vq = eth_dev->data->rx_queues[i];if (vq ==NULL )
examples/vhost/main.c +7 -3
@@ -1173,10 +1173,15 @@ switch_worker(void *arg __rte_unused)static void destroy_device (volatile struct virtio_net *dev) { -struct vhost_dev *vdev; +struct vhost_dev *vdev =NULL ;int lcore; - vdev = (struct vhost_dev *)dev->priv; + TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { +if (vdev->vid == dev->vid) +break ; + } +if (!vdev) +return ;/*set the remove flag. */ vdev->remove =1 ;while (vdev->ready !=DEVICE_SAFE_REMOVE ) {
@@ -1231,7 +1236,6 @@ new_device (struct virtio_net *dev)return -1 ; } vdev->dev = dev; - dev->priv = vdev; vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry);
Signature · 1 line
1.9.0
PATCH v3 13/20 vhost: export vid as the only interface to applications
In reply to Yuanhan LiuWith all the previous prepare works, we are just one step away from the final ABI refactoring. That is, to change current API to let them stick to vid instead of the old virtio_net dev.
---
v2: update release note
v3: - bump the ABI version to 3.
- remove "struct virtio_net *dev" field in vhost example
--- doc/guides/rel_notes/release_16_07.rst | 9 ++++- drivers/net/vhost/rte_eth_vhost.c | 47 +++++++++------------------ examples/vhost/main.c | 25 +++++++------- examples/vhost/main.h | 2 -- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_virtio_net.h | 18 +++++----- lib/librte_vhost/vhost_rxtx.c | 15 +++++++-- lib/librte_vhost/vhost_user/virtio-net-user.c | 14 ++++---- lib/librte_vhost/virtio-net.c | 17 ++++++---- 9 files changed, 77 insertions(+), 72 deletions(-)
doc/guides/rel_notes/release_16_07.rst +8 -1
@@ -118,6 +118,10 @@ API Changes * ``rte_vring_available_entries`` is renamed to ``rte_vhost_avail_entries``. +* All existing vhost APIs and callbacks with ``virtio_net`` struct pointer + as the parameter have been changed due to the ABI refactoring mentioned + below: it's replaced by ``int vid``. + ABI Changes -----------
@@ -129,6 +133,9 @@ ABI Changes * The ``rte_port_source_params`` structure has new fields to support PCAP file. It was already in release 16.04 with ``RTE_NEXT_ABI`` flag. +* vhost ABI refactoring has been made: ``virtio_net`` structure is never + exported to application any more. Instead, a handle, ``vid``, has been + used to represent this structure internally. Shared Library Versions -----------------------
@@ -165,7 +172,7 @@ The libraries prepended with a plus sign were incremented in this version. librte_sched.so.1 librte_table.so.2 librte_timer.so.1 - librte_vhost.so.2 + + librte_vhost.so.3 Tested Platforms
drivers/net/vhost/rte_eth_vhost.c +16 -31
136 lines not on this page · raw message
examples/vhost/main.c +11 -14
@@ -795,7 +795,7 @@ virtio_xmit(struct vhost_dev *dst_vdev, struct vhost_dev *src_vdev, {uint16_t ret; - ret =rte_vhost_enqueue_burst (dst_vdev->dev,VIRTIO_RXQ , &m,1 ); + ret =rte_vhost_enqueue_burst (dst_vdev->vid,VIRTIO_RXQ , &m,1 );if (enable_stats) {rte_atomic64_inc (&dst_vdev->stats.rx_total_atomic);rte_atomic64_add (&dst_vdev->stats.rx_atomic, ret);
@@ -1041,7 +1041,6 @@ static inline void __attribute__((always_inline)) drain_eth_rx(struct vhost_dev *vdev) {uint16_t rx_count, enqueue_count; -struct virtio_net *dev = vdev->dev;struct rte_mbuf *pkts[MAX_PKT_BURST ]; rx_count = rte_eth_rx_burst(ports[0], vdev->vmdq_rx_q,
@@ -1055,19 +1054,19 @@ drain_eth_rx(struct vhost_dev *vdev)* to diminish packet loss. */ if (enable_retry && -unlikely (rx_count >rte_vhost_avail_entries (dev->vid, +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_vhost_avail_entries (dev->vid, +if (rx_count <=rte_vhost_avail_entries (vdev->vid,VIRTIO_RXQ ))break ; } } - enqueue_count =rte_vhost_enqueue_burst (dev,VIRTIO_RXQ , + enqueue_count =rte_vhost_enqueue_burst (vdev->vid,VIRTIO_RXQ , pkts, rx_count);if (enable_stats) {rte_atomic64_add (&vdev->stats.rx_total_atomic, rx_count);
@@ -1084,7 +1083,7 @@ drain_virtio_tx(struct vhost_dev *vdev)uint16_t count;uint16_t i; - count =rte_vhost_dequeue_burst (vdev->dev,VIRTIO_TXQ , mbuf_pool, + count =rte_vhost_dequeue_burst (vdev->vid,VIRTIO_TXQ , mbuf_pool, pkts,MAX_PKT_BURST );/* setup VMDq for the first packet */
@@ -1171,13 +1170,13 @@ switch_worker(void *arg __rte_unused)* of dev->remove=1 which can cause an infinite loop in the rte_pause loop. */ static void -destroy_device (volatile struct virtio_net *dev) +destroy_device (int vid) {struct vhost_dev *vdev =NULL ;int lcore; TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { -if (vdev->vid == dev->vid) +if (vdev->vid == vid)break ; }if (!vdev)
@@ -1221,12 +1220,11 @@ destroy_device (volatile struct virtio_net *dev)* and the allocated to a specific data core. */ static int -new_device (struct virtio_net *dev) +new_device (int vid) {int lcore, core_add =0 ;uint32_t device_num_min = num_devices;struct vhost_dev *vdev; -int vid = dev->vid; vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {
@@ -1235,7 +1233,6 @@ new_device (struct virtio_net *dev) vid);return -1 ; } - vdev->dev = dev; vdev->vid = vid;TAILQ_INSERT_TAIL (&vhost_dev_list, vdev, global_vdev_entry);
@@ -1259,8 +1256,8 @@ new_device (struct virtio_net *dev) lcore_info[vdev->coreid].device_num++;/* Disable notifications. */ -rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 ); -rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); +rte_vhost_enable_guest_notification (vid,VIRTIO_RXQ ,0 ); +rte_vhost_enable_guest_notification (vid,VIRTIO_TXQ ,0 ); RTE_LOG(INFO, VHOST_DATA, "(%d) device has been added to data core %d\n",
@@ -1316,7 +1313,7 @@ print_stats(void)"RX total: %" PRIu64"\n" "RX dropped: %" PRIu64"\n" "RX successful: %" PRIu64"\n" , - vdev->dev->vid, + vdev->vid, tx_total, tx_dropped, tx, rx_total, rx_dropped, rx); }
examples/vhost/main.h +0 -2
@@ -49,8 +49,6 @@ struct device_statistics { };struct vhost_dev { -/**< Pointer to device created by vhost lib. */ -struct virtio_net *dev;/**< Number of memory regions for gpa to hpa translation. */ uint32_t nregions_hpa;/**< Device MAC address (Obtained on first TX packet). */
lib/librte_vhost/Makefile +1 -1
@@ -36,7 +36,7 @@ LIB = librte_vhost.a EXPORT_MAP := rte_vhost_version.map -LIBABIVER := 2 +LIBABIVER := 3 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y)
lib/librte_vhost/rte_virtio_net.h +9 -9
@@ -178,10 +178,10 @@ struct virtio_memory {* */ struct virtio_net_device_ops { -int (*new_device)(struct virtio_net *);/**< Add device. */ -void (*destroy_device)(volatile struct virtio_net *);/**< Remove device. */ +int (*new_device)(int vid);/**< Add device. */ +void (*destroy_device)(int vid);/**< Remove device. */ -int (*vring_state_changed)(struct virtio_net *dev,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ +int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ };/**
@@ -220,7 +220,7 @@ int rte_vhost_feature_enable(uint64_t feature_mask);/* Returns currently supported vhost features */ uint64_t rte_vhost_feature_get (void ); -int rte_vhost_enable_guest_notification (struct virtio_net *dev,uint16_t queue_id,int enable); +int rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable);/* Register vhost driver. dev_name could be different for multiple instance support. */ int rte_vhost_driver_register (const char *dev_name);
@@ -291,8 +291,8 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);* 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 * added to the RX queue. -* @param dev -* virtio-net device +* @param vid +* virtio-net device ID * @param queue_id * virtio queue index in mq case * @param pkts
@@ -302,14 +302,14 @@ uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);* @return * num of packets enqueued */ -uint16_t rte_vhost_enqueue_burst (struct virtio_net *dev,uint16_t queue_id, +uint16_t rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count);/** * This function gets guest buffers from the virtio device TX virtqueue, * construct host mbufs, copies guest buffer content to host mbufs and * store them in pkts to be processed. -* @param dev +* @param vid * virtio-net device * @param queue_id * virtio queue index in mq case
@@ -322,7 +322,7 @@ uint16_t rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,* @return * num of packets dequeued */ -uint16_t rte_vhost_dequeue_burst (struct virtio_net *dev,uint16_t queue_id, +uint16_t rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count);#endif /* _VIRTIO_NET_H_ */
lib/librte_vhost/vhost_rxtx.c +13 -2
@@ -46,6 +46,7 @@#include <rte_arp.h> #include "vhost-net.h" +#include "virtio-net.h" #define MAX_PKT_BURST 32#define VHOST_LOG_PAGE 4096
@@ -587,9 +588,14 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, }uint16_t -rte_vhost_enqueue_burst (struct virtio_net *dev,uint16_t queue_id, +rte_vhost_enqueue_burst (int vid,uint16_t queue_id,struct rte_mbuf **pkts,uint16_t count) { +struct virtio_net *dev =get_device (vid); + +if (!dev) +return 0 ; +if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF ))return virtio_dev_merge_rx (dev, queue_id, pkts, count);else
@@ -815,9 +821,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, }uint16_t -rte_vhost_dequeue_burst (struct virtio_net *dev,uint16_t queue_id, +rte_vhost_dequeue_burst (int vid,uint16_t queue_id,struct rte_mempool *mbuf_pool,struct rte_mbuf **pkts,uint16_t count) { +struct virtio_net *dev;struct rte_mbuf *rarp_mbuf =NULL ;struct vhost_virtqueue *vq;uint32_t desc_indexes[MAX_PKT_BURST ];
@@ -826,6 +833,10 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,uint16_t free_entries;uint16_t avail_idx; + dev =get_device (vid); +if (!dev) +return 0 ; +if (unlikely (!is_valid_virt_queue_idx (queue_id,1 , dev->virt_qp_nb))) {RTE_LOG (ERR ,VHOST_DATA ,"(%d) %s: invalid virtqueue idx %d.\n" , dev->vid, __func__, queue_id);
lib/librte_vhost/vhost_user/virtio-net-user.c +8 -6
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)/* Remove from the data plane. */ if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)struct vhost_vring_file file;struct virtio_net *dev =get_device (vid); +if (!dev) +return ; + file.index = pmsg->payload.u64 &VHOST_USER_VRING_IDX_MASK ;if (pmsg->payload.u64 &VHOST_USER_VRING_NOFD_MASK ) file.fd =VIRTIO_INVALID_EVENTFD ;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)vhost_set_vring_kick (vid, &file);if (virtio_is_ready (dev) && !(dev->flags &VIRTIO_DEV_RUNNING )) { -if (notify_ops->new_device (dev) ==0 ) +if (notify_ops->new_device (vid) ==0 ) dev->flags |=VIRTIO_DEV_RUNNING ; } }
@@ -307,7 +310,7 @@ user_get_vring_base(int vid,return -1 ;/* We have to stop the queue (virtio) if it is running. */ if (dev->flags &VIRTIO_DEV_RUNNING ) - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid);/* Here we are safe to get the last used index */ vhost_get_vring_base (vid, state->index, state);
@@ -342,9 +345,8 @@ user_set_vring_enable(int vid,"set queue enable: %d to qp idx: %d\n" , enable, state->index); -if (notify_ops->vring_state_changed) { - notify_ops->vring_state_changed (dev, state->index, enable); - } +if (notify_ops->vring_state_changed) + notify_ops->vring_state_changed (vid, state->index, enable); dev->virtqueue[state->index]->enabled = enable;
lib/librte_vhost/virtio-net.c +11 -6
@@ -296,7 +296,7 @@ vhost_destroy_device(int vid)if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }cleanup_device (dev,1 );
@@ -354,7 +354,7 @@ vhost_reset_owner(int vid)if (dev->flags &VIRTIO_DEV_RUNNING ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }cleanup_device (dev,0 );
@@ -718,13 +718,13 @@ vhost_set_backend(int vid, struct vhost_vring_file *file)if (!(dev->flags &VIRTIO_DEV_RUNNING )) {if (dev->virtqueue[VIRTIO_TXQ ]->backend !=VIRTIO_DEV_STOPPED && dev->virtqueue[VIRTIO_RXQ ]->backend !=VIRTIO_DEV_STOPPED ) { -if (notify_ops->new_device (dev) <0 ) +if (notify_ops->new_device (vid) <0 )return -1 ; dev->flags |=VIRTIO_DEV_RUNNING ; } }else if (file->fd ==VIRTIO_DEV_STOPPED ) { dev->flags &= ~VIRTIO_DEV_RUNNING ; - notify_ops->destroy_device (dev); + notify_ops->destroy_device (vid); }return 0 ;
@@ -800,9 +800,14 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)return *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx_res; } -int rte_vhost_enable_guest_notification (struct virtio_net *dev, -uint16_t queue_id,int enable) +int +rte_vhost_enable_guest_notification (int vid,uint16_t queue_id,int enable) { +struct virtio_net *dev =get_device (vid); + +if (dev ==NULL ) +return -1 ; +if (enable) {RTE_LOG (ERR ,VHOST_CONFIG ,"guest notification isn't supported.\n" );
Signature · 1 line
1.9.0
PATCH v3 14/20 vhost: hide internal structs/macros/functions
In reply to Yuanhan LiuWe are now safe to move all those internal structs/macros/functions to vhost-net.h, to hide them from external access.
This patch also breaks long lines and removes some redundant comments.
--- lib/librte_vhost/rte_virtio_net.h | 139 ------------------------- lib/librte_vhost/vhost-net.h | 148 +++++++++++++++++++++++++++ lib/librte_vhost/vhost_user/vhost-net-user.h | 2 + 3 files changed, 150 insertions(+), 139 deletions(-)
lib/librte_vhost/rte_virtio_net.h +0 -139
@@ -51,125 +51,9 @@#include <rte_mempool.h> #include <rte_ether.h> -struct rte_mbuf ; - -#define VHOST_MEMORY_MAX_NREGIONS 8 - -/* Used to indicate that the device is running on a data core */ -#define VIRTIO_DEV_RUNNING 1 - -/* Backend value set by guest. */ -#define VIRTIO_DEV_STOPPED -1 - -/* Enum for virtqueue management. */ enum {VIRTIO_RXQ ,VIRTIO_TXQ ,VIRTIO_QNUM }; -#define BUF_VECTOR_MAX 256 - -/** -* Structure contains buffer address, length and descriptor index -* from vring to do scatter RX. -*/ -struct buf_vector { -uint64_t buf_addr; -uint32_t buf_len; -uint32_t desc_idx; -}; - -/** -* Structure contains variables relevant to RX/TX virtqueues. -*/ -struct vhost_virtqueue { -struct vring_desc *desc;/**< Virtqueue descriptor ring. */ -struct vring_avail *avail;/**< Virtqueue available ring. */ -struct vring_used *used;/**< Virtqueue used ring. */ -uint32_t size;/**< Size of descriptor ring. */ -int backend;/**< Backend value to determine if device should started/stopped. */ -uint16_t vhost_hlen;/**< Vhost header length (varies depending on RX merge buffers. */ -volatile uint16_t last_used_idx;/**< Last index used on the available ring */ -volatile uint16_t last_used_idx_res;/**< Used for multiple devices reserving buffers. */ -#define VIRTIO_INVALID_EVENTFD (-1) -#define VIRTIO_UNINITIALIZED_EVENTFD (-2) -int callfd;/**< Used to notify the guest (trigger interrupt). */ -int kickfd;/**< Currently unused as polling mode is enabled. */ -int enabled; -uint64_t log_guest_addr;/**< Physical address of used ring, for logging */ -uint64_t reserved[15 ];/**< Reserve some spaces for future extension. */ -struct buf_vector buf_vec[BUF_VECTOR_MAX ];/**< for scatter RX. */ -} __rte_cache_aligned; - -/* Old kernels have no such macro defined */ -#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE -#define VIRTIO_NET_F_GUEST_ANNOUNCE 21 -#endif - - -/* -* Make an extra wrapper for VIRTIO_NET_F_MQ and -* VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX as they are -* introduced since kernel v3.8. This makes our -* code buildable for older kernel. -*/ -#ifdef VIRTIO_NET_F_MQ -#define VHOST_MAX_QUEUE_PAIRS VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX -#define VHOST_SUPPORTS_MQ (1ULL << VIRTIO_NET_F_MQ) -#else -#define VHOST_MAX_QUEUE_PAIRS 1 -#define VHOST_SUPPORTS_MQ 0 -#endif - -/* -* Define virtio 1.0 for older kernels -*/ -#ifndef VIRTIO_F_VERSION_1 -#define VIRTIO_F_VERSION_1 32 -#endif - -/** -* Device structure contains all configuration information relating to the device. -*/ -struct virtio_net { -struct virtio_memory *mem;/**< QEMU memory and memory region information. */ -uint64_t features;/**< Negotiated feature set. */ -uint64_t protocol_features;/**< Negotiated protocol feature set. */ -int vid;/**< device identifier. */ -uint32_t flags;/**< Device flags. Only used to check if device is running on data core. */ -#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ) -char ifname[IF_NAME_SZ ];/**< Name of the tap device or socket path. */ -uint32_t virt_qp_nb;/**< number of queue pair we have allocated */ -void *priv;/**< private context */ -uint64_t log_size;/**< Size of log area */ -uint64_t log_base;/**< Where dirty pages are logged */ -struct ether_addr mac;/**< MAC address */ -rte_atomic16_t broadcast_rarp;/**< A flag to tell if we need broadcast rarp packet */ -uint64_t reserved[61 ];/**< Reserve some spaces for future extension. */ -struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ];/**< Contains all virtqueue information. */ -} __rte_cache_aligned; - -/** -* Information relating to memory regions including offsets to addresses in QEMUs memory file. -*/ -struct virtio_memory_regions { -uint64_t guest_phys_address;/**< Base guest physical address of region. */ -uint64_t guest_phys_address_end;/**< End guest physical address of region. */ -uint64_t memory_size;/**< Size of region. */ -uint64_t userspace_address;/**< Base userspace address of region. */ -uint64_t address_offset;/**< Offset of region for address translation. */ -}; - - -/** -* Memory structure includes region and mapping information. -*/ -struct virtio_memory { -uint64_t base_address;/**< Base QEMU userspace address of the memory file. */ -uint64_t mapped_address;/**< Mapped address of memory file base in our applications memory space. */ -uint64_t mapped_size;/**< Total size of memory file. */ -uint32_t nregions;/**< Number of memory regions. */ -struct virtio_memory_regions regions[0 ];/**< Memory region information. */ -}; -/** * Device and vring operations. *
@@ -185,29 +69,6 @@ struct virtio_net_device_ops { };/** -* Function to convert guest physical addresses to vhost virtual addresses. -* This is used to convert guest virtio buffer addresses. -*/ -static inline uint64_t __attribute__((always_inline)) -gpa_to_vva (struct virtio_net *dev,uint64_t guest_pa) -{ -struct virtio_memory_regions *region; -uint32_t regionidx; -uint64_t vhost_va =0 ; - -for (regionidx =0 ; regionidx < dev->mem->nregions; regionidx++) { - region = &dev->mem->regions[regionidx]; -if ((guest_pa >= region->guest_phys_address) && - (guest_pa <= region->guest_phys_address_end)) { - vhost_va = region->address_offset + guest_pa; -break ; - } - } -return vhost_va; -} - - -/** * Disable features in feature_mask. Returns 0 on success. */ int rte_vhost_feature_disable (uint64_t feature_mask);
lib/librte_vhost/vhost-net.h +148 -0
160 lines not on this page · raw message
lib/librte_vhost/vhost_user/vhost-net-user.h +2 -0
@@ -47,6 +47,8 @@ struct vhost_server {/* refer to hw/virtio/vhost-user.c */ +#define VHOST_MEMORY_MAX_NREGIONS 8 + typedef enum VhostUserRequest { VHOST_USER_NONE = 0, VHOST_USER_GET_FEATURES = 1,
Signature · 1 line
1.9.0
PATCH v3 15/20 vhost: remove unnecessary fields
In reply to Yuanhan LiuThe "reserved" field in virtio_net and vhost_virtqueue struct is not necessary any more. We now expose virtio_net device with a number "vid".
This patch also removes the "priv" field: all fields are priviate now:
application can't access it now. The only way that we could still access it is to expose it by a function, but I doubt that's needed or worthwhile.
--- lib/librte_vhost/vhost-net.h | 3 --- 1 file changed, 3 deletions(-)
lib/librte_vhost/vhost-net.h +0 -3
@@ -88,7 +88,6 @@ struct vhost_virtqueue {/* Physical address of used ring, for logging */ uint64_t log_guest_addr; -uint64_t reserved[15 ];struct buf_vector buf_vec[BUF_VECTOR_MAX ]; } __rte_cache_aligned;
@@ -133,14 +132,12 @@ struct virtio_net {#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];uint32_t virt_qp_nb; -void *priv;uint64_t log_size;uint64_t log_base;struct ether_addr mac;/* to tell if we need broadcast rarp packet */ rte_atomic16_t broadcast_rarp; -uint64_t reserved[61 ];struct vhost_virtqueue *virtqueue[VHOST_MAX_QUEUE_PAIRS *2 ]; } __rte_cache_aligned;
Signature · 1 line
1.9.0
PATCH v3 16/20 vhost: remove virtio-net.h
In reply to Yuanhan LiuIt barely has anything useful there, just 2 functions prototype. Here move them to vhost-net.h, and delete it.
--- lib/librte_vhost/vhost-net.h | 3 ++ lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 1 - lib/librte_vhost/vhost_rxtx.c | 1 - lib/librte_vhost/vhost_user/virtio-net-user.c | 1 - lib/librte_vhost/virtio-net.c | 1 - lib/librte_vhost/virtio-net.h | 43 --------------------------- 6 files changed, 3 insertions(+), 47 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.h
lib/librte_vhost/vhost-net.h +3 -0
@@ -220,6 +220,9 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa)return vhost_va; } +struct virtio_net_device_ops const *notify_ops; +struct virtio_net *get_device (int vid); +int vhost_new_device (void );void vhost_destroy_device (int );
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +0 -1
@@ -54,7 +54,6 @@#include "rte_virtio_net.h" #include "vhost-net.h" #include "virtio-net-cdev.h" -#include "virtio-net.h" #include "eventfd_copy.h" /* Line size for reading maps file. */
lib/librte_vhost/vhost_rxtx.c +0 -1
@@ -46,7 +46,6 @@#include <rte_arp.h> #include "vhost-net.h" -#include "virtio-net.h" #define MAX_PKT_BURST 32#define VHOST_LOG_PAGE 4096
lib/librte_vhost/vhost_user/virtio-net-user.c +0 -1
@@ -43,7 +43,6 @@#include <rte_common.h> #include <rte_log.h> -#include "virtio-net.h" #include "virtio-net-user.h" #include "vhost-net-user.h" #include "vhost-net.h"
lib/librte_vhost/virtio-net.c +0 -1
@@ -53,7 +53,6 @@#include <rte_virtio_net.h> #include "vhost-net.h" -#include "virtio-net.h" #define MAX_VHOST_DEVICE 1024static struct virtio_net *vhost_devices[MAX_VHOST_DEVICE ];
lib/librte_vhost/virtio-net.h deleted +0 -43
43 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v3 17/20 vhost: reserve few more space for future extension
In reply to Yuanhan Liu"virtio_net_device_ops" is the only left open struct that an application can access, therefore, it's the only place that might introduce potential ABI break in future for extension.
So, do some reservation for it. 5 should be pretty enough, considering that we have barely touched it for a long while. Another reason to choose 5 is for cache alignment: 5 makes the struct 64 bytes for 64 bit machine.
With this, it's confidence to say that we might be able to be free from the ABI violation forever.
--- lib/librte_vhost/rte_virtio_net.h | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_vhost/rte_virtio_net.h +2 -0
@@ -66,6 +66,8 @@ struct virtio_net_device_ops {void (*destroy_device)(int vid);/**< Remove device. */ int (*vring_state_changed)(int vid,uint16_t queue_id,int enable);/**< triggered when a vring is enabled or disabled */ + +void *reserved[5 ];/**< Reserved for future extension */ };/**
Signature · 1 line
1.9.0
PATCH v3 18/20 examples/tep_term: adapt to new vhost ABI/API changes
In reply to Yuanhan LiuAdapt to the new vhost ABI/API refactoring changes, to not break the build. It's a straightforward change: replace "struct virtio_net *dev" with "int fd". Simple build test only so far.
---
tep_term is built on top of vhost switch example; they shared a lot of code (before the vhost example cleanup). Idealy, we might should move the vxlan part to vhost example, and introduce an option to enable it.
However, I found that would take more effort, including the effort of making it co-work with VLAN and VMDq stuff as well as the effort to not break anything, I found it's better to start simple first:
just do a new ABI/API adaption.
--- examples/tep_termination/main.c | 83 +++++++++++++++++----------------- examples/tep_termination/main.h | 5 +- examples/tep_termination/vxlan_setup.c | 20 ++++---- examples/tep_termination/vxlan_setup.h | 6 +-- 4 files changed, 57 insertions(+), 57 deletions(-)
examples/tep_termination/main.c +42 -41
@@ -566,10 +566,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m)struct rte_mbuf **m_table;unsigned len, ret =0 ;const uint16_t lcore_id =rte_lcore_id (); -struct virtio_net *dev = vdev->dev; +int vid = vdev->vid; -RTE_LOG (DEBUG ,VHOST_DATA ,"(%" PRIu64") TX: MAC address is external\n" , - dev->device_fh); +RTE_LOG (DEBUG ,VHOST_DATA ,"(%d) TX: MAC address is external\n" , vid);/* Add packet to the port tx queue */ tx_q = &lcore_tx_queue[lcore_id];
@@ -578,8 +577,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m) tx_q->m_table[len] = m; len++;if (enable_stats) { - dev_statistics[dev->device_fh].tx_total++; - dev_statistics[dev->device_fh].tx++; + dev_statistics[vid].tx_total++; + dev_statistics[vid].tx++; }if (unlikely (len ==MAX_PKT_BURST )) {
@@ -614,7 +613,7 @@ static int switch_worker(__rte_unused void *arg) {struct rte_mempool *mbuf_pool = arg; -struct virtio_net *dev =NULL ; +int vid;struct vhost_dev *vdev =NULL ;struct rte_mbuf *pkts_burst[MAX_PKT_BURST ];struct virtio_net_data_ll *dev_ll;
@@ -688,7 +687,7 @@ switch_worker(__rte_unused void *arg)while (dev_ll !=NULL ) { vdev = dev_ll->vdev; - dev = vdev->dev; + vid = vdev->vid;if (unlikely (vdev->remove)) { dev_ll = dev_ll->next;
@@ -709,22 +708,22 @@ switch_worker(__rte_unused void *arg)* must be less than virtio queue size */ if (enable_retry &&unlikely (rx_count > -rte_vring_available_entries (dev,VIRTIO_RXQ ))) { +rte_vhost_avail_entries (vid,VIRTIO_RXQ ))) {for (retry =0 ; retry < burst_rx_retry_num; retry++) {rte_delay_us (burst_rx_delay_time); -if (rx_count <=rte_vring_available_entries (dev,VIRTIO_RXQ )) +if (rx_count <=rte_vhost_avail_entries (vid,VIRTIO_RXQ ))break ; } } - ret_count = overlay_options.rx_handle (dev, pkts_burst, rx_count); + ret_count = overlay_options.rx_handle (vid, pkts_burst, rx_count);if (enable_stats) {rte_atomic64_add ( - &dev_statistics[dev->device_fh].rx_total_atomic, + &dev_statistics[vid].rx_total_atomic, rx_count);rte_atomic64_add ( - &dev_statistics[dev->device_fh].rx_atomic, ret_count); + &dev_statistics[vid].rx_atomic, ret_count); }while (likely (rx_count)) { rx_count--;
@@ -736,7 +735,7 @@ switch_worker(__rte_unused void *arg)if (likely (!vdev->remove)) {/* Handle guest TX*/ - tx_count =rte_vhost_dequeue_burst (dev, + tx_count =rte_vhost_dequeue_burst (vid,VIRTIO_TXQ , mbuf_pool, pkts_burst,MAX_PKT_BURST );/* If this is the first received packet we need to learn the MAC */
@@ -913,18 +912,24 @@ init_data_ll(void)* loop in the rte_pause loop. */ static void -destroy_device (volatile struct virtio_net *dev) +destroy_device (int vid) {struct virtio_net_data_ll *ll_lcore_dev_cur;struct virtio_net_data_ll *ll_main_dev_cur;struct virtio_net_data_ll *ll_lcore_dev_last =NULL ;struct virtio_net_data_ll *ll_main_dev_last =NULL ; -struct vhost_dev *vdev; +struct vhost_dev *vdev =NULL ;int lcore; - dev->flags &= ~VIRTIO_DEV_RUNNING ; - - vdev = (struct vhost_dev *)dev->priv; + ll_main_dev_cur = ll_root_used; +while (ll_main_dev_cur !=NULL ) { +if (ll_main_dev_cur->vdev->vid == vid) { + vdev = ll_main_dev_cur->vdev; +break ; + } + } +if (!vdev) +return ;/* set the remove flag. */ vdev->remove =1 ;
@@ -944,8 +949,7 @@ destroy_device(volatile struct virtio_net *dev)if (ll_lcore_dev_cur ==NULL ) {RTE_LOG (ERR ,VHOST_CONFIG , -"(%" PRIu64") Failed to find the dev to be destroy.\n" , - dev->device_fh); +"(%d) Failed to find the dev to be destroy.\n" , vid);return ; }
@@ -992,8 +996,8 @@ destroy_device(volatile struct virtio_net *dev)/* Decrement number of device on the lcore. */ lcore_info[vdev->coreid].lcore_ll->device_num--; -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been removed " -"from data core\n" , dev->device_fh); +RTE_LOG (INFO ,VHOST_DATA ,"(%d) Device has been removed " +"from data core\n" , vid);rte_free (vdev);
@@ -1004,7 +1008,7 @@ destroy_device(volatile struct virtio_net *dev)* to the main linked list and the allocated to a specific data core. */ static int -new_device (struct virtio_net *dev) +new_device (int vid) {struct virtio_net_data_ll *ll_dev;int lcore, core_add =0 ;
@@ -1014,18 +1018,16 @@ new_device(struct virtio_net *dev) vdev =rte_zmalloc ("vhost device" ,sizeof (*vdev),RTE_CACHE_LINE_SIZE );if (vdev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") Couldn't allocate memory for vhost dev\n" , - dev->device_fh); +"(%d) Couldn't allocate memory for vhost dev\n" , vid);return -1 ; } - vdev->dev = dev; - dev->priv = vdev; + vdev->vid = vid;/* Add device to main ll */ ll_dev =get_data_ll_free_entry (&ll_root_free);if (ll_dev ==NULL ) { -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") No free entry found in" +RTE_LOG (INFO ,VHOST_DATA ,"(%d) No free entry found in" " linked list Device limit of %d devices per core" -" has been reached\n" , dev->device_fh, nb_devices); +" has been reached\n" , vid, nb_devices);if (vdev->regions_hpa)rte_free (vdev->regions_hpa);rte_free (vdev);
@@ -1033,7 +1035,7 @@ new_device(struct virtio_net *dev) } ll_dev->vdev = vdev;add_data_ll_entry (&ll_root_used, ll_dev); - vdev->rx_q = dev->device_fh; + vdev->rx_q = vid;/* reset ready flag */ vdev->ready =DEVICE_MAC_LEARNING ;
@@ -1050,10 +1052,9 @@ new_device(struct virtio_net *dev) ll_dev =get_data_ll_free_entry (&lcore_info[core_add].lcore_ll->ll_root_free);if (ll_dev ==NULL ) {RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") Failed to add device to data core\n" , - dev->device_fh); +"(%d) Failed to add device to data core\n" , vid); vdev->ready =DEVICE_SAFE_REMOVE ; -destroy_device (dev); +destroy_device (vid);rte_free (vdev->regions_hpa);rte_free (vdev);return -1 ;
@@ -1065,17 +1066,17 @@ new_device(struct virtio_net *dev) ll_dev);/* Initialize device stats */ -memset (&dev_statistics[dev->device_fh],0 , +memset (&dev_statistics[vid],0 ,sizeof (struct device_statistics ));/* Disable notifications. */ -rte_vhost_enable_guest_notification (dev,VIRTIO_RXQ ,0 ); -rte_vhost_enable_guest_notification (dev,VIRTIO_TXQ ,0 ); +rte_vhost_enable_guest_notification (vid,VIRTIO_RXQ ,0 ); +rte_vhost_enable_guest_notification (vid,VIRTIO_TXQ ,0 ); lcore_info[vdev->coreid].lcore_ll->device_num++; - dev->flags |=VIRTIO_DEV_RUNNING ; -RTE_LOG (INFO ,VHOST_DATA ,"(%" PRIu64") Device has been added to data core %d\n" , - dev->device_fh, vdev->coreid); +RTE_LOG (INFO ,VHOST_DATA , +"(%d) Device has been added to data core %d\n" , + vid, vdev->coreid);return 0 ; }
@@ -1113,7 +1114,7 @@ print_stats(void) dev_ll = ll_root_used;while (dev_ll !=NULL ) { - device_fh = (uint32_t )dev_ll->vdev->dev->device_fh; + device_fh = dev_ll->vdev->vid; tx_total = dev_statistics[device_fh].tx_total; tx = dev_statistics[device_fh].tx; tx_dropped = tx_total - tx;
@@ -1257,7 +1258,7 @@ main(int argc, char *argv[])rte_vhost_feature_disable (1ULL <<VIRTIO_NET_F_MRG_RXBUF );/* Register CUSE device to handle IOCTLs. */ - ret =rte_vhost_driver_register ((char *)&dev_basename); + ret =rte_vhost_driver_register (dev_basename,0 );if (ret !=0 )rte_exit (EXIT_FAILURE ,"CUSE device setup failure.\n" );
examples/tep_termination/main.h +2 -3
@@ -71,8 +71,7 @@ struct device_statistics {* Device linked list structure for data path. */ struct vhost_dev { -/**< Pointer to device created by vhost lib. */ -struct virtio_net *dev; +int vid;/**< Number of memory regions for gpa to hpa translation. */ uint32_t nregions_hpa;/**< Memory region information for gpa to hpa translation. */
@@ -116,6 +115,6 @@ struct virtio_net_data_ll { };uint32_t -virtio_dev_rx (struct virtio_net *dev,struct rte_mbuf **pkts,uint32_t count); +virtio_dev_rx (int vid,struct rte_mbuf **pkts,uint32_t count);#endif /* _MAIN_H_ */
examples/tep_termination/vxlan_setup.c +10 -10
@@ -244,17 +244,17 @@ vxlan_link(struct vhost_dev *vdev, struct rte_mbuf *m) {int i, ret;struct ether_hdr *pkt_hdr; -struct virtio_net *dev = vdev->dev; -uint64_t portid = dev->device_fh; +int vid = vdev->vid; +uint64_t portid = vid;struct ipv4_hdr *ip;struct rte_eth_tunnel_filter_conf tunnel_filter_conf;if (unlikely (portid >VXLAN_N_PORTS )) {RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") WARNING: Not configuring device," +"(%d) WARNING: Not configuring device," "as already have %d ports for VXLAN." , - dev->device_fh,VXLAN_N_PORTS ); + vid,VXLAN_N_PORTS );return -1 ; }
@@ -262,9 +262,9 @@ vxlan_link(struct vhost_dev *vdev, struct rte_mbuf *m) pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);if (is_same_ether_addr (&(pkt_hdr->s_addr), &vdev->mac_address)) {RTE_LOG (INFO ,VHOST_DATA , -"(%" PRIu64") WARNING: This device is using an existing" +"(%d) WARNING: This device is using an existing" " MAC address and has not been registered.\n" , - dev->device_fh); + vid);return -1 ; }
@@ -425,7 +425,7 @@ vxlan_tx_pkts(uint8_t port_id, uint16_t queue_id,/* Check for decapsulation and pass packets directly to VIRTIO device */ int -vxlan_rx_pkts (struct virtio_net *dev,struct rte_mbuf **pkts_burst, +vxlan_rx_pkts (int vid,struct rte_mbuf **pkts_burst,uint32_t rx_count) {uint32_t i =0 ;
@@ -436,11 +436,11 @@ vxlan_rx_pkts(struct virtio_net *dev, struct rte_mbuf **pkts_burst,for (i =0 ; i < rx_count; i++) {if (enable_stats) {rte_atomic64_add ( - &dev_statistics[dev->device_fh].rx_bad_ip_csum, + &dev_statistics[vid].rx_bad_ip_csum, (pkts_burst[i]->ol_flags &PKT_RX_IP_CKSUM_BAD ) !=0 );rte_atomic64_add ( - &dev_statistics[dev->device_fh].rx_bad_ip_csum, + &dev_statistics[vid].rx_bad_ip_csum, (pkts_burst[i]->ol_flags &PKT_RX_L4_CKSUM_BAD ) !=0 ); }
@@ -452,6 +452,6 @@ vxlan_rx_pkts(struct virtio_net *dev, struct rte_mbuf **pkts_burst, count++; } - ret =rte_vhost_enqueue_burst (dev,VIRTIO_RXQ , pkts_valid, count); + ret =rte_vhost_enqueue_burst (vid,VIRTIO_RXQ , pkts_valid, count);return ret; }
examples/tep_termination/vxlan_setup.h +3 -3
@@ -55,10 +55,10 @@ typedef void (*ol_tunnel_destroy_t)(struct vhost_dev *vdev);typedef int (*ol_tx_handle_t )(uint8_t port_id,uint16_t queue_id,struct rte_mbuf **tx_pkts,uint16_t nb_pkts); -typedef int (*ol_rx_handle_t )(struct virtio_net *dev,struct rte_mbuf **pkts, +typedef int (*ol_rx_handle_t )(int vid,struct rte_mbuf **pkts,uint32_t count); -typedef int (*ol_param_handle )(struct virtio_net *dev); +typedef int (*ol_param_handle )(int vid);struct ol_switch_ops {ol_port_configure_t port_configure;
@@ -82,6 +82,6 @@ int vxlan_tx_pkts(uint8_t port_id, uint16_t queue_id, struct rte_mbuf **tx_pkts, uint16_t nb_pkts);int -vxlan_rx_pkts (struct virtio_net *dev,struct rte_mbuf **pkts,uint32_t count); +vxlan_rx_pkts (int vid,struct rte_mbuf **pkts,uint32_t count);#endif /* VXLAN_SETUP_H_ */
Signature · 1 line
1.9.0
PATCH v3 19/20 vhost: per device virtio net header len
In reply to Yuanhan LiuVirtio net header length is set per device, but not per queue. So, there is no reason to store it in vhost_virtqueue struct, instead, we should store it in virtio_net struct, to make one copy only.
--- lib/librte_vhost/vhost-net.h | 2 +- lib/librte_vhost/vhost_rxtx.c | 40 ++++++++++++++++++++-------------------- lib/librte_vhost/virtio-net.c | 13 ++----------- 3 files changed, 23 insertions(+), 32 deletions(-)
lib/librte_vhost/vhost-net.h +1 -1
@@ -69,7 +69,6 @@ struct vhost_virtqueue {struct vring_avail *avail;struct vring_used *used;uint32_t size; -uint16_t vhost_hlen;/* Last index used on the available ring */ volatile uint16_t last_used_idx;
@@ -129,6 +128,7 @@ struct virtio_net {uint64_t protocol_features;int vid;uint32_t flags; +uint16_t vhost_hlen;#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)char ifname[IF_NAME_SZ ];uint32_t virt_qp_nb;
lib/librte_vhost/vhost_rxtx.c +20 -20
@@ -126,10 +126,10 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr) }static inline void -copy_virtio_net_hdr (struct vhost_virtqueue *vq,uint64_t desc_addr, +copy_virtio_net_hdr (struct virtio_net *dev,uint64_t desc_addr,struct virtio_net_hdr_mrg_rxbuf hdr) { -if (vq->vhost_hlen ==sizeof (struct virtio_net_hdr_mrg_rxbuf )) +if (dev->vhost_hlen ==sizeof (struct virtio_net_hdr_mrg_rxbuf )) *(struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t )desc_addr = hdr;else *(struct virtio_net_hdr *)(uintptr_t )desc_addr = hdr.hdr;
@@ -147,19 +147,19 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0 ,0 ,0 ,0 ,0 ,0 },0 }; desc = &vq->desc[desc_idx]; -if (unlikely (desc->len < vq->vhost_hlen)) +if (unlikely (desc->len < dev->vhost_hlen))return -1 ; desc_addr =gpa_to_vva (dev, desc->addr);rte_prefetch0 ((void *)(uintptr_t )desc_addr);virtio_enqueue_offload (m, &virtio_hdr.hdr); -copy_virtio_net_hdr (vq, desc_addr, virtio_hdr); -vhost_log_write (dev, desc->addr, vq->vhost_hlen); -PRINT_PACKET (dev, (uintptr_t )desc_addr, vq->vhost_hlen,0 ); +copy_virtio_net_hdr (dev, desc_addr, virtio_hdr); +vhost_log_write (dev, desc->addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); - desc_offset = vq->vhost_hlen; - desc_avail = desc->len - vq->vhost_hlen; + desc_offset = dev->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; *copied =rte_pktmbuf_pkt_len (m); mbuf_avail =rte_pktmbuf_data_len (m);
@@ -300,9 +300,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, vq->used->ring[used_idx].id = desc_idx;if (unlikely (err)) - vq->used->ring[used_idx].len = vq->vhost_hlen; + vq->used->ring[used_idx].len = dev->vhost_hlen;else - vq->used->ring[used_idx].len = copied + vq->vhost_hlen; + vq->used->ring[used_idx].len = copied + dev->vhost_hlen;vhost_log_used_vring (dev, vq, offsetof(struct vring_used, ring[used_idx]), sizeof(vq->used->ring[used_idx]));
@@ -444,7 +444,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,LOG_DEBUG (VHOST_DATA ,"(%d) current index %d | end index %d\n" , dev->vid, cur_idx, res_end_idx); -if (vq->buf_vec[vec_idx].buf_len < vq->vhost_hlen) +if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)return -1 ; desc_addr =gpa_to_vva (dev, vq->buf_vec[vec_idx].buf_addr);
@@ -455,12 +455,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq, dev->vid, virtio_hdr.num_buffers);virtio_enqueue_offload (m, &virtio_hdr.hdr); -copy_virtio_net_hdr (vq, desc_addr, virtio_hdr); -vhost_log_write (dev, vq->buf_vec[vec_idx].buf_addr, vq->vhost_hlen); -PRINT_PACKET (dev, (uintptr_t )desc_addr, vq->vhost_hlen,0 ); +copy_virtio_net_hdr (dev, desc_addr, virtio_hdr); +vhost_log_write (dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen); +PRINT_PACKET (dev, (uintptr_t )desc_addr, dev->vhost_hlen,0 ); - desc_avail = vq->buf_vec[vec_idx].buf_len - vq->vhost_hlen; - desc_offset = vq->vhost_hlen; + desc_avail = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; mbuf_avail =rte_pktmbuf_data_len (m); mbuf_offset =0 ;
@@ -546,7 +546,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,return 0 ;for (pkt_idx =0 ; pkt_idx < count; pkt_idx++) { -uint32_t pkt_len = pkts[pkt_idx]->pkt_len + vq->vhost_hlen; +uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;if (unlikely (reserve_avail_buf_mergeable (vq, pkt_len, &start, &end) <0 )) {
@@ -747,7 +747,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,uint32_t nr_desc =1 ; desc = &vq->desc[desc_idx]; -if (unlikely (desc->len < vq->vhost_hlen)) +if (unlikely (desc->len < dev->vhost_hlen))return -1 ; desc_addr =gpa_to_vva (dev, desc->addr);
@@ -755,8 +755,8 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,/* Retrieve virtio net header */ hdr = (struct virtio_net_hdr *)((uintptr_t )desc_addr); - desc_avail = desc->len - vq->vhost_hlen; - desc_offset = vq->vhost_hlen; + desc_avail = desc->len - dev->vhost_hlen; + desc_offset = dev->vhost_hlen; mbuf_offset =0 ; mbuf_avail = m->buf_len -RTE_PKTMBUF_HEADROOM ;
lib/librte_vhost/virtio-net.c +2 -11
@@ -387,8 +387,6 @@ int vhost_set_features(int vid, uint64_t *pu) { struct virtio_net *dev; -uint16_t vhost_hlen; -uint16_t i; dev =get_device (vid);if (dev ==NULL )
@@ -399,9 +397,9 @@ vhost_set_features(int vid, uint64_t *pu) dev->features = *pu;if (dev->features & ((1 <<VIRTIO_NET_F_MRG_RXBUF ) | (1ULL <<VIRTIO_F_VERSION_1 ))) { - vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); + dev->vhost_hlen =sizeof (struct virtio_net_hdr_mrg_rxbuf ); }else { - vhost_hlen =sizeof (struct virtio_net_hdr ); + dev->vhost_hlen =sizeof (struct virtio_net_hdr ); } LOG_DEBUG(VHOST_CONFIG, "(%d) mergeable RX buffers %s, virtio 1 %s\n",
@@ -409,13 +407,6 @@ vhost_set_features(int vid, uint64_t *pu) (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) ?"on" :"off" , (dev->features & (1ULL << VIRTIO_F_VERSION_1)) ? "on" : "off"); -for (i =0 ; i < dev->virt_qp_nb; i++) { -uint16_t base_idx = i *VIRTIO_QNUM ; - - dev->virtqueue[base_idx +VIRTIO_RXQ ]->vhost_hlen = vhost_hlen; - dev->virtqueue[base_idx +VIRTIO_TXQ ]->vhost_hlen = vhost_hlen; - } -return 0 ; }
Signature · 1 line
1.9.0
PATCH v3 20/20 vhost: make buf vector for scatter Rx local
In reply to Yuanhan LiuFrom: Ilya Maximets <[email protected]>
Array of buf_vector's is just an array for temporary storing information about available descriptors. It used only locally in virtio_dev_merge_rx() and there is no reason for that array to be shared.
Fix that by allocating local buf_vec inside virtio_dev_merge_rx().
--- lib/librte_vhost/vhost-net.h | 1 - lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 20 deletions(-)
lib/librte_vhost/vhost-net.h +0 -1
@@ -87,7 +87,6 @@ struct vhost_virtqueue {/* Physical address of used ring, for logging */ uint64_t log_guest_addr; -struct buf_vector buf_vec[BUF_VECTOR_MAX ]; } __rte_cache_aligned;/* Old kernels have no such macro defined */
lib/librte_vhost/vhost_rxtx.c +22 -19
133 lines not on this page · raw message
Signature · 1 line
1.9.0
Yuanhan Liu
AppliedApplied to dpdk-next-virtio.
--yliu
Quoted 94 lines · Yuanhan Liu
v3: - adapted the new vhost ABI/API changes to
tep_termexample, to make
sure not break build at least.
- bumped the ABI version to 3NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]:
git://dpdk.org/next/dpdk-next-virtiofor-testingEvery time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove
vec_buffromvhost_virtqueuestruct) also break ABI.This patch set is meant to resolve above issue ultimately, by hiding
virtio_netstructure (as well as few others) internaly, and export thevirtio_netdev strut to applications by a number, vid, like the way kernel exposes an fd to user space.Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "
virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".After that, "
vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.The last bit of this patch set is some cleanups, including the one from Ilya.
v2: - exported ifname as well to fix a vhost-pmd issue reported by Rich
- separated the big patch that introduces several new APIs into some small patches.
- updated release note
- updated version.mapThanks.
--yliu---
Ilya Maximets (1):
vhost: make buf vector for scatter Rx localYuanhan Liu (19):
vhost: declare backend with int type
vhost: set/reset dev flags internally
vhost: declare device fh as int examples/vhost: make a copy of virtio device id
vhost: rename device fh to vid
vhost: get device by vid only
vhost: move vhost device ctx to cuse
vhost: introduce new API to export numa node
vhost: introduce new API to export number of queues
vhost: introduce new API to export ifname
vhost: introduce new API to export queue free entries
vhost: remove dependency on priv field
vhost: export vid as the only interface to applications
vhost: hide internal structs/macros/functions
vhost: remove unnecessary fields
vhost: removevirtio-net.h
vhost: reserve few more space for future extension examples/tep_term: adapt to new vhost ABI/API changes
vhost: per device virtio net header lendoc/guides/rel_notes/release_16_07.rst | 11 +- drivers/net/vhost/rte_eth_vhost.c | 79 ++++----- examples/tep_termination/main.c | 83 +++++----- examples/tep_termination/main.h | 5 +- examples/tep_termination/vxlan_setup.c | 20 +-- examples/tep_termination/vxlan_setup.h | 6 +- examples/vhost/main.c | 116 +++++++------ examples/vhost/main.h | 3 +- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/rte_vhost_version.map | 10 ++ lib/librte_vhost/rte_virtio_net.h | 223 +++++++------------------ lib/librte_vhost/vhost-net.h | 201 ++++++++++++++++++---- lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 83 +++++----- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 30 ++-- lib/librte_vhost/vhost_cuse/virtio-net-cdev.h | 12 +- lib/librte_vhost/vhost_rxtx.c | 133 ++++++++------- lib/librte_vhost/vhost_user/vhost-net-user.c | 53 +++--- lib/librte_vhost/vhost_user/vhost-net-user.h | 2 + lib/librte_vhost/vhost_user/virtio-net-user.c | 64 +++---- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 +- lib/librte_vhost/virtio-net.c | 229 +++++++++++++++++--------- lib/librte_vhost/virtio-net.h | 43 ----- 22 files changed, 752 insertions(+), 674 deletions(-) delete mode 100644 lib/librte_vhost/virtio-net.hSignature · 1 line
1.9.0
Quoted 23 lines · Yuanhan Liu
v3: - adapted the new vhost ABI/API changes to
tep_termexample, to make
sure not break build at least.
- bumped the ABI version to 3NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]:
git://dpdk.org/next/dpdk-next-virtiofor-testingEvery time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove
vec_buffromvhost_virtqueuestruct) also break ABI.This patch set is meant to resolve above issue ultimately, by hiding
virtio_netstructure (as well as few others) internaly, and export thevirtio_netdev strut to applications by a number, vid, like the way kernel exposes an fd to user space.Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "
virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".
Quoted 5 lines
After that, "
vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.
Been intending to say this for a while but seems I never actually got around to do so:
This is a really fine example of how to refactor an API against constant ABI breakages, thank you Yuanhan! Exported structs are one of the biggest obstacles in keeping a stable ABI while adding new features, and while its not always possible to hide everything to this extent, the damage (erm, exposure) can usually be considerably limited by careful API design.
Since the first and the foremost objection against doing this in the DPDK context is always "but performance!", I'm curious as to what sort of numbers you're getting with the new API vs the old one? I'm really hoping other libraries would follow suit after seeing that its possible to provide a future-proof API/ABI without sacrificing performance :)
Thanks again,
- Panu -
Quoted 30 lines · Panu Matilainen
Quoted 23 lines · Yuanhan Liu
v3: - adapted the new vhost ABI/API changes to
tep_termexample, to make
sure not break build at least.
- bumped the ABI version to 3NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]:
git://dpdk.org/next/dpdk-next-virtiofor-testingEvery time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove
vec_buffromvhost_virtqueuestruct) also break ABI.This patch set is meant to resolve above issue ultimately, by hiding
virtio_netstructure (as well as few others) internaly, and export thevirtio_netdev strut to applications by a number, vid, like the way kernel exposes an fd to user space.Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "
virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".Quoted 5 lines
After that, "
vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.
Quoted 5 lines
Been intending to say this for a while but seems I never actually got around to do so:
This is a really fine example of how to refactor an API against constant ABI breakages, thank you Yuanhan!
Panu, thanks!
Quoted 4 lines
Exported structs are one of the biggest
obstacles in keeping a stable ABI while adding new features, and while its not always possible to hide everything to this extent, the damage (erm, exposure) can usually be considerably limited by careful API design.
Agreed.
Quoted 7 lines
Since the first and the foremost objection against doing this in the DPDK context is always "but performance!", I'm curious as to what sort of numbers you're getting with the new API vs the old one? I'm really hoping other libraries would follow suit after seeing that its possible to provide a future-proof API/ABI without sacrificing performance :)
From my (limited) test, nope, I see no performance drop at all, not even a
little.
--yliu
Quoted 46 lines · Yuanhan Liu
Quoted 30 lines · Panu Matilainen
Quoted 23 lines · Yuanhan Liu
v3: - adapted the new vhost ABI/API changes to
tep_termexample, to make
sure not break build at least.
- bumped the ABI version to 3NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]:
git://dpdk.org/next/dpdk-next-virtiofor-testingEvery time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove
vec_buffromvhost_virtqueuestruct) also break ABI.This patch set is meant to resolve above issue ultimately, by hiding
virtio_netstructure (as well as few others) internaly, and export thevirtio_netdev strut to applications by a number, vid, like the way kernel exposes an fd to user space.Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "
virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".Quoted 5 lines
After that, "
vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.Quoted 5 lines
Been intending to say this for a while but seems I never actually got around to do so:
This is a really fine example of how to refactor an API against constant ABI breakages, thank you Yuanhan!
Panu, thanks!
Quoted 4 lines
Exported structs are one of the biggest
obstacles in keeping a stable ABI while adding new features, and while its not always possible to hide everything to this extent, the damage (erm, exposure) can usually be considerably limited by careful API design.Agreed.
Quoted 8 lines
Quoted 5 lines
Since the first and the foremost objection against doing this in the DPDK context is always "but performance!", I'm curious as to what sort of numbers you're getting with the new API vs the old one? I'm really hoping other libraries would follow suit after seeing that its possible to provide a future-proof API/ABI without sacrificing performance :)
From my (limited) test, nope, I see no performance drop at all, not even a little.
Awesome!
With that, hopefully others will see the light and follow its example. If nothing else, they ought to get a bit envious when you can add features left and right without ever having to wait for API/ABI break periods etc ;)
- Panu -
Quoted 3 lines
--yliu
Quoted 71 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Panu Matilainen
Sent: Thursday, June 30, 2016 10:05 AM
To: Yuanhan Liu <[email protected]>
Cc: [email protected]; Xie, Huawei <[email protected]>; Thomas Monjalon <[email protected]>; Rich Lane <[email protected]>; Tetsuya Mukawa <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoringQuoted 3 lines · Yuanhan Liu
Quoted 2 lines · Panu Matilainen
Quoted 1 line · Yuanhan Liu
v3: - adapted the new vhost ABI/API changes to
tep_termexample, tomake
Quoted 52 lines
Quoted 30 lines
Quoted 23 lines
sure not break build at least.
- bumped the ABI version to 3NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]:
git://dpdk.org/next/dpdk-next-virtiofor-testingEvery time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove
vec_buf
fromvhost_virtqueuestruct) also break ABI.This patch set is meant to resolve above issue ultimately, by hiding
virtio_netstructure (as well as few others) internaly, and export thevirtio_netdev strut to applications by a number, vid, like the way kernel exposes an fd to user space.Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "
virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".Quoted 6 lines
After that, "
vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.Quoted 5 lines
Been intending to say this for a while but seems I never actually got around to do so:
This is a really fine example of how to refactor an API against constant ABI breakages, thank you Yuanhan!
Panu, thanks!
Quoted 4 lines
Exported structs are one of the biggest obstacles in keeping a stable ABI while adding new features, and while its not always possible to hide everything to this extent, the damage (erm,
exposure) can usually be considerably limited by careful API design.Agreed.
Quoted 6 lines
Since the first and the foremost objection against doing this in the DPDK context is always "but performance!", I'm curious as to what sort of numbers you're getting with the new API vs the old one? I'm really hoping other libraries would follow suit after seeing that its possible to provide a future-proof API/ABI without sacrificing performance :)
Quoted 2 lines
From my (limited) test, nope, I see no performance drop at all, not even a little.
Quoted 6 lines
Awesome!
With that, hopefully others will see the light and follow its example. If nothing else, they ought to get a bit envious when you can add features left and right without ever having to wait for API/ABI break periods etc ;)
Agreed. We should be doing more of this type of refactoring work to make the API/ABI less easier to break.
John
2016-06-30 11:15, Mcnamara, John:
Quoted 61 lines
From: dev [mailto:[email protected]] On Behalf Of Panu Matilainen
Quoted 60 lines · Yuanhan Liu
Quoted 3 lines · Panu Matilainen
Quoted 2 lines · Yuanhan Liu
Quoted 1 line
v3: - adapted the new vhost ABI/API changes to
tep_termexample, tomake
Quoted 54 lines
Quoted 30 lines
Quoted 23 lines
sure not break build at least.
- bumped the ABI version to 3NOTE: I created a branch at dpdk.org [0] for more conveinient testing:
[0]:
git://dpdk.org/next/dpdk-next-virtiofor-testingEvery time we introduce a new feature to vhost, we are likely to break ABI. Moreover, some cleanups (such as the one from Ilya to remove
vec_buf
fromvhost_virtqueuestruct) also break ABI.This patch set is meant to resolve above issue ultimately, by hiding
virtio_netstructure (as well as few others) internaly, and export thevirtio_netdev strut to applications by a number, vid, like the way kernel exposes an fd to user space.Back to the patch set, the first part of this set makes some changes to vhost example, vhost-pmd and vhost, bit by bit, to remove the dependence to "
virtio_net" struct. And then do the final change to make the current APIs to adapt to using "vid".Quoted 6 lines
After that, "
vrtio_net_device_ops" is the only left open struct that an application can acces, therefore, it's the only place that might introduce potential ABI breakage in future for extension. Hence, I made few more
(5) space reservation, to make sure we will not break ABI for a long time, and hopefuly, forever.Quoted 5 lines
Been intending to say this for a while but seems I never actually got around to do so:
This is a really fine example of how to refactor an API against constant ABI breakages, thank you Yuanhan!
Panu, thanks!
Quoted 4 lines
Exported structs are one of the biggest obstacles in keeping a stable ABI while adding new features, and while its not always possible to hide everything to this extent, the damage (erm,
exposure) can usually be considerably limited by careful API design.Agreed.
Quoted 6 lines
Since the first and the foremost objection against doing this in the DPDK context is always "but performance!", I'm curious as to what sort of numbers you're getting with the new API vs the old one? I'm really hoping other libraries would follow suit after seeing that its possible to provide a future-proof API/ABI without sacrificing performance :)
From my (limited) test, nope, I see no performance drop at all, not even a little.
Quoted 8 lines
Quoted 6 lines
Awesome!
With that, hopefully others will see the light and follow its example. If nothing else, they ought to get a bit envious when you can add features left and right without ever having to wait for API/ABI break periods etc ;)
Agreed. We should be doing more of this type of refactoring work to make the API/ABI less easier to break.
+1
But we must check the possible performance degradation with care :)