Lines Matching +full:break +full:- +full:control

1 // SPDX-License-Identifier: GPL-2.0
22 #define RANDOM_BATCH -1
33 /* copy used for control */
40 int control; member
49 static const struct vhost_vring_file no_backend = { .fd = -1 },
55 struct vq_info *info = vq->priv; in vq_notify()
58 r = write(info->kick, &v, sizeof v); in vq_notify()
70 struct vhost_vring_state state = { .index = info->idx }; in vhost_vq_setup()
71 struct vhost_vring_file file = { .index = info->idx }; in vhost_vq_setup()
72 unsigned long long features = dev->vdev.features; in vhost_vq_setup()
74 .index = info->idx, in vhost_vq_setup()
75 .desc_user_addr = (uint64_t)(unsigned long)info->vring.desc, in vhost_vq_setup()
76 .avail_user_addr = (uint64_t)(unsigned long)info->vring.avail, in vhost_vq_setup()
77 .used_user_addr = (uint64_t)(unsigned long)info->vring.used, in vhost_vq_setup()
80 r = ioctl(dev->control, VHOST_SET_FEATURES, &features); in vhost_vq_setup()
82 state.num = info->vring.num; in vhost_vq_setup()
83 r = ioctl(dev->control, VHOST_SET_VRING_NUM, &state); in vhost_vq_setup()
86 r = ioctl(dev->control, VHOST_SET_VRING_BASE, &state); in vhost_vq_setup()
88 r = ioctl(dev->control, VHOST_SET_VRING_ADDR, &addr); in vhost_vq_setup()
90 file.fd = info->kick; in vhost_vq_setup()
91 r = ioctl(dev->control, VHOST_SET_VRING_KICK, &file); in vhost_vq_setup()
93 file.fd = info->call; in vhost_vq_setup()
94 r = ioctl(dev->control, VHOST_SET_VRING_CALL, &file); in vhost_vq_setup()
100 if (info->vq) in vq_reset()
101 vring_del_virtqueue(info->vq); in vq_reset()
103 memset(info->ring, 0, vring_size(num, 4096)); in vq_reset()
104 vring_init(&info->vring, num, info->ring, 4096); in vq_reset()
105 info->vq = vring_new_virtqueue(info->idx, num, 4096, vdev, true, false, in vq_reset()
106 info->ring, vq_notify, vq_callback, "test"); in vq_reset()
107 assert(info->vq); in vq_reset()
108 info->vq->priv = info; in vq_reset()
113 struct vq_info *info = &dev->vqs[dev->nvqs]; in vq_info_add()
115 info->idx = dev->nvqs; in vq_info_add()
116 info->kick = eventfd(0, EFD_NONBLOCK); in vq_info_add()
117 info->call = eventfd(0, EFD_NONBLOCK); in vq_info_add()
118 r = posix_memalign(&info->ring, 4096, vring_size(num, 4096)); in vq_info_add()
120 vq_reset(info, num, &dev->vdev); in vq_info_add()
122 dev->fds[info->idx].fd = info->call; in vq_info_add()
123 dev->fds[info->idx].events = POLLIN; in vq_info_add()
124 dev->nvqs++; in vq_info_add()
131 dev->vdev.features = features; in vdev_info_init()
132 INIT_LIST_HEAD(&dev->vdev.vqs); in vdev_info_init()
133 spin_lock_init(&dev->vdev.vqs_list_lock); in vdev_info_init()
134 dev->buf_size = 1024; in vdev_info_init()
135 dev->buf = malloc(dev->buf_size); in vdev_info_init()
136 assert(dev->buf); in vdev_info_init()
137 dev->control = open("/dev/vhost-test", O_RDWR); in vdev_info_init()
138 assert(dev->control >= 0); in vdev_info_init()
139 r = ioctl(dev->control, VHOST_SET_OWNER, NULL); in vdev_info_init()
141 dev->mem = malloc(offsetof(struct vhost_memory, regions) + in vdev_info_init()
142 sizeof dev->mem->regions[0]); in vdev_info_init()
143 assert(dev->mem); in vdev_info_init()
144 memset(dev->mem, 0, offsetof(struct vhost_memory, regions) + in vdev_info_init()
145 sizeof dev->mem->regions[0]); in vdev_info_init()
146 dev->mem->nregions = 1; in vdev_info_init()
147 dev->mem->regions[0].guest_phys_addr = (long)dev->buf; in vdev_info_init()
148 dev->mem->regions[0].userspace_addr = (long)dev->buf; in vdev_info_init()
149 dev->mem->regions[0].memory_size = dev->buf_size; in vdev_info_init()
150 r = ioctl(dev->control, VHOST_SET_MEM_TABLE, dev->mem); in vdev_info_init()
162 poll(dev->fds, dev->nvqs, -1); in wait_for_interrupt()
163 for (i = 0; i < dev->nvqs; ++i) in wait_for_interrupt()
164 if (dev->fds[i].revents & POLLIN) { in wait_for_interrupt()
165 read(dev->fds[i].fd, &val, sizeof val); in wait_for_interrupt()
180 r = ioctl(dev->control, VHOST_TEST_RUN, &test); in run_test()
187 virtqueue_disable_cb(vq->vq); in run_test()
193 batch = (random() % vq->vring.num) + 1; in run_test()
196 (started - completed) < batch) { in run_test()
197 sg_init_one(&sl, dev->buf, dev->buf_size); in run_test()
198 r = virtqueue_add_outbuf(vq->vq, &sl, 1, in run_test()
199 dev->buf + started, in run_test()
202 if (r == -ENOSPC && in run_test()
206 r = -1; in run_test()
207 break; in run_test()
212 if (unlikely(!virtqueue_kick(vq->vq))) { in run_test()
213 r = -1; in run_test()
214 break; in run_test()
219 r = -1; in run_test()
222 r = ioctl(dev->control, VHOST_TEST_SET_BACKEND, in run_test()
228 while (virtqueue_get_buf(vq->vq, &len)) { in run_test()
236 vq_reset(vq, vq->vring.num, &dev->vdev); in run_test()
238 r = ioctl(dev->control, VHOST_GET_VRING_BASE, in run_test()
243 r = ioctl(dev->control, VHOST_SET_VRING_BASE, in run_test()
247 r = ioctl(dev->control, VHOST_TEST_SET_BACKEND, in run_test()
261 break; in run_test()
263 if (virtqueue_enable_cb_delayed(vq->vq)) in run_test()
266 if (virtqueue_enable_cb(vq->vq)) in run_test()
271 r = ioctl(dev->control, VHOST_TEST_RUN, &test); in run_test()
285 .name = "event-idx",
289 .name = "no-event-idx",
297 .name = "no-indirect",
301 .name = "virtio-1",
305 .name = "no-virtio-1",
309 .name = "delayed-interrupt",
313 .name = "no-delayed-interrupt",
332 fprintf(stderr, "Usage: virtio_test [--help]" in help()
333 " [--no-indirect]" in help()
334 " [--no-event-idx]" in help()
335 " [--no-virtio-1]" in help()
336 " [--delayed-interrupt]" in help()
337 " [--batch=random/N]" in help()
338 " [--reset=N]" in help()
354 case -1: in main()
361 break; in main()
367 break; in main()
370 break; in main()
373 break; in main()
382 break; in main()
391 break; in main()
394 break; in main()