vhost: improve performance by supporting large buffer
[dpdk.git] / lib / librte_vhost / socket.c
index c7a77a5..2d3d208 100644 (file)
@@ -40,6 +40,8 @@ struct vhost_user_socket {
        bool dequeue_zero_copy;
        bool iommu_support;
        bool use_builtin_virtio_net;
+       bool extbuf;
+       bool linearbuf;
 
        /*
         * The "supported_features" indicates the feature bits the
@@ -232,6 +234,12 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
        if (vsocket->dequeue_zero_copy)
                vhost_enable_dequeue_zero_copy(vid);
 
+       if (vsocket->extbuf)
+               vhost_enable_extbuf(vid);
+
+       if (vsocket->linearbuf)
+               vhost_enable_linearbuf(vid);
+
        RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
        if (vsocket->notify_ops->new_connection) {
@@ -297,13 +305,19 @@ vhost_user_read_cb(int connfd, void *dat, int *remove)
 
        ret = vhost_user_msg_handler(conn->vid, connfd);
        if (ret < 0) {
+               struct virtio_net *dev = get_device(conn->vid);
+
                close(connfd);
                *remove = 1;
-               vhost_destroy_device(conn->vid);
+
+               if (dev)
+                       vhost_destroy_device_notify(dev);
 
                if (vsocket->notify_ops->destroy_connection)
                        vsocket->notify_ops->destroy_connection(conn->vid);
 
+               vhost_destroy_device(conn->vid);
+
                pthread_mutex_lock(&vsocket->conn_mutex);
                TAILQ_REMOVE(&vsocket->conn_list, conn, next);
                pthread_mutex_unlock(&vsocket->conn_mutex);
@@ -864,6 +878,16 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
                goto out_free;
        }
        vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
+       vsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT;
+       vsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT;
+
+       if (vsocket->dequeue_zero_copy &&
+           (flags & RTE_VHOST_USER_IOMMU_SUPPORT)) {
+               RTE_LOG(ERR, VHOST_CONFIG,
+                       "error: enabling dequeue zero copy and IOMMU features "
+                       "simultaneously is not supported\n");
+               goto out_mutex;
+       }
 
        /*
         * Set the supported features correctly for the builtin vhost-user
@@ -888,6 +912,18 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
         * not compatible with postcopy.
         */
        if (vsocket->dequeue_zero_copy) {
+               if (vsocket->extbuf) {
+                       RTE_LOG(ERR, VHOST_CONFIG,
+                       "error: zero copy is incompatible with external buffers\n");
+                       ret = -1;
+                       goto out_mutex;
+               }
+               if (vsocket->linearbuf) {
+                       RTE_LOG(ERR, VHOST_CONFIG,
+                       "error: zero copy is incompatible with linear buffers\n");
+                       ret = -1;
+                       goto out_mutex;
+               }
                vsocket->supported_features &= ~(1ULL << VIRTIO_F_IN_ORDER);
                vsocket->features &= ~(1ULL << VIRTIO_F_IN_ORDER);