Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/virtio: Reset index in virtio_test --reset.

This way behavior for vhost is more like a VM.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Link: https://lore.kernel.org/r/20200418102217.32327-8-eperezma@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Eugenio Pérez and committed by
Michael S. Tsirkin
1d8bf5c3 67412392

+24 -2
+24 -2
tools/virtio/virtio_test.c
··· 48 48 49 49 static const struct vhost_vring_file no_backend = { .fd = -1 }, 50 50 backend = { .fd = 1 }; 51 + static const struct vhost_vring_state null_state = {}; 51 52 52 53 bool vq_notify(struct virtqueue *vq) 53 54 { ··· 174 173 unsigned len; 175 174 long long spurious = 0; 176 175 const bool random_batch = batch == RANDOM_BATCH; 176 + 177 177 r = ioctl(dev->control, VHOST_TEST_RUN, &test); 178 178 assert(r >= 0); 179 + if (!reset_n) { 180 + next_reset = INT_MAX; 181 + } 182 + 179 183 for (;;) { 180 184 virtqueue_disable_cb(vq->vq); 181 185 completed_before = completed; 182 186 started_before = started; 183 187 do { 184 - const bool reset = reset_n && completed > next_reset; 188 + const bool reset = completed > next_reset; 185 189 if (random_batch) 186 190 batch = (random() % vq->vring.num) + 1; 187 191 ··· 229 223 } 230 224 231 225 if (reset) { 226 + struct vhost_vring_state s = { .index = 0 }; 227 + 228 + vq_reset(vq, vq->vring.num, &dev->vdev); 229 + 230 + r = ioctl(dev->control, VHOST_GET_VRING_BASE, 231 + &s); 232 + assert(!r); 233 + 234 + s.num = 0; 235 + r = ioctl(dev->control, VHOST_SET_VRING_BASE, 236 + &null_state); 237 + assert(!r); 238 + 232 239 r = ioctl(dev->control, VHOST_TEST_SET_BACKEND, 233 240 &backend); 234 241 assert(!r); 235 242 243 + started = completed; 236 244 while (completed > next_reset) 237 245 next_reset += completed; 238 246 } ··· 268 248 test = 0; 269 249 r = ioctl(dev->control, VHOST_TEST_RUN, &test); 270 250 assert(r >= 0); 271 - fprintf(stderr, "spurious wakeups: 0x%llx\n", spurious); 251 + fprintf(stderr, 252 + "spurious wakeups: 0x%llx started=0x%lx completed=0x%lx\n", 253 + spurious, started, completed); 272 254 } 273 255 274 256 const char optstring[] = "h";