diff --git a/lib/vhost/rte_vhost_user.c b/lib/vhost/rte_vhost_user.c index 3d5b36559f..3fe4c75b37 100644 --- a/lib/vhost/rte_vhost_user.c +++ b/lib/vhost/rte_vhost_user.c @@ -425,6 +425,55 @@ static const struct vhost_device_ops g_spdk_vhost_ops = { .destroy_connection = destroy_connection, }; +void +vhost_user_session_set_interrupt_mode(struct spdk_vhost_session *vsession, bool interrupt_mode) +{ + uint16_t i; + bool packed_ring; + int rc = 0; + + packed_ring = ((vsession->negotiated_features & (1ULL << VIRTIO_F_RING_PACKED)) != 0); + + for (i = 0; i < vsession->max_queues; i++) { + struct spdk_vhost_virtqueue *q = &vsession->virtqueue[i]; + uint64_t num_events = 1; + + /* vring.desc and vring.desc_packed are in a union struct + * so q->vring.desc can replace q->vring.desc_packed. + */ + if (q->vring.desc == NULL || q->vring.size == 0) { + continue; + } + + if (interrupt_mode) { + /* Enable I/O submission notifications, we'll be interrupting. */ + if (packed_ring) { + * (volatile uint16_t *) &q->vring.device_event->flags = VRING_PACKED_EVENT_FLAG_ENABLE; + } else { + * (volatile uint16_t *) &q->vring.used->flags = 0; + } + + /* In case of race condition, always kick vring when switch to intr */ + rc = write(q->vring.kickfd, &num_events, sizeof(num_events)); + if (rc < 0) { + SPDK_ERRLOG("failed to kick vring: %s.\n", spdk_strerror(errno)); + } + + vsession->interrupt_mode = true; + } else { + /* Disable I/O submission notifications, we'll be polling. */ + if (packed_ring) { + * (volatile uint16_t *) &q->vring.device_event->flags = VRING_PACKED_EVENT_FLAG_DISABLE; + } else { + * (volatile uint16_t *) &q->vring.used->flags = VRING_USED_F_NO_NOTIFY; + } + + vsession->interrupt_mode = false; + } + } +} + + static enum rte_vhost_msg_result extern_vhost_pre_msg_handler(int vid, void *_msg) { diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 3becb4b4c7..49833021c9 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1083,54 +1083,6 @@ vhost_dev_foreach_session(struct spdk_vhost_dev *vdev, spdk_thread_send_msg(vdev->thread, foreach_session, ev_ctx); } -void -vhost_session_set_interrupt_mode(struct spdk_vhost_session *vsession, bool interrupt_mode) -{ - uint16_t i; - bool packed_ring; - int rc = 0; - - packed_ring = ((vsession->negotiated_features & (1ULL << VIRTIO_F_RING_PACKED)) != 0); - - for (i = 0; i < vsession->max_queues; i++) { - struct spdk_vhost_virtqueue *q = &vsession->virtqueue[i]; - uint64_t num_events = 1; - - /* vring.desc and vring.desc_packed are in a union struct - * so q->vring.desc can replace q->vring.desc_packed. - */ - if (q->vring.desc == NULL || q->vring.size == 0) { - continue; - } - - if (interrupt_mode) { - /* Enable I/O submission notifications, we'll be interrupting. */ - if (packed_ring) { - * (volatile uint16_t *) &q->vring.device_event->flags = VRING_PACKED_EVENT_FLAG_ENABLE; - } else { - * (volatile uint16_t *) &q->vring.used->flags = 0; - } - - /* In case of race condition, always kick vring when switch to intr */ - rc = write(q->vring.kickfd, &num_events, sizeof(num_events)); - if (rc < 0) { - SPDK_ERRLOG("failed to kick vring: %s.\n", spdk_strerror(errno)); - } - - vsession->interrupt_mode = true; - } else { - /* Disable I/O submission notifications, we'll be polling. */ - if (packed_ring) { - * (volatile uint16_t *) &q->vring.device_event->flags = VRING_PACKED_EVENT_FLAG_DISABLE; - } else { - * (volatile uint16_t *) &q->vring.used->flags = VRING_USED_F_NO_NOTIFY; - } - - vsession->interrupt_mode = false; - } - } -} - void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w) { diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 5349a2ab09..fbcfa4bfec 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -1072,7 +1072,7 @@ vhost_blk_poller_set_interrupt_mode(struct spdk_poller *poller, void *cb_arg, bo { struct spdk_vhost_blk_session *bvsession = cb_arg; - vhost_session_set_interrupt_mode(&bvsession->vsession, interrupt_mode); + vhost_user_session_set_interrupt_mode(&bvsession->vsession, interrupt_mode); } static struct spdk_vhost_blk_dev * diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index a74f4c6420..9b5f8fa9e7 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -423,7 +423,8 @@ void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ct /* * Set vhost session to run in interrupt or poll mode */ -void vhost_session_set_interrupt_mode(struct spdk_vhost_session *vsession, bool interrupt_mode); +void vhost_user_session_set_interrupt_mode(struct spdk_vhost_session *vsession, + bool interrupt_mode); /* * Memory registration functions used in start/stop device callbacks