2022-09-01 06:07:57

by Guo Zhi

[permalink] [raw]
Subject: [RFC v3 2/7] vhost_test: batch used buffer

Only add to used ring when a batch of buffer have all been used. And if
in order feature negotiated, only add the last used descriptor for a
batch of buffer.

Signed-off-by: Guo Zhi <[email protected]>
---
drivers/vhost/test.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index bc8e7fb1e635..20548a5eb3de 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -28,6 +28,11 @@
*/
#define VHOST_TEST_PKT_WEIGHT 256

+enum {
+ VHOST_TEST_FEATURES = VHOST_FEATURES |
+ (1ULL << VIRTIO_F_IN_ORDER)
+};
+
enum {
VHOST_TEST_VQ = 0,
VHOST_TEST_VQ_MAX = 1,
@@ -44,7 +49,7 @@ static void handle_vq(struct vhost_test *n)
{
struct vhost_virtqueue *vq = &n->vqs[VHOST_TEST_VQ];
unsigned out, in;
- int head;
+ int head, add = 0;
size_t len, total_len = 0;
void *private;

@@ -84,11 +89,14 @@ static void handle_vq(struct vhost_test *n)
vq_err(vq, "Unexpected 0 len for TX\n");
break;
}
- vhost_add_used_and_signal(&n->dev, vq, head, 0);
+ vq->heads[add].id = cpu_to_vhost32(vq, head);
+ vq->heads[add++].len = cpu_to_vhost32(vq, len);
total_len += len;
if (unlikely(vhost_exceeds_weight(vq, 0, total_len)))
break;
}
+ if (add)
+ vhost_add_used_and_signal_n(&n->dev, vq, vq->heads, add);

mutex_unlock(&vq->mutex);
}
@@ -328,7 +336,7 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,
return -EFAULT;
return vhost_test_set_backend(n, backend.index, backend.fd);
case VHOST_GET_FEATURES:
- features = VHOST_FEATURES;
+ features = VHOST_TEST_FEATURES;
if (copy_to_user(featurep, &features, sizeof features))
return -EFAULT;
return 0;
@@ -337,7 +345,7 @@ static long vhost_test_ioctl(struct file *f, unsigned int ioctl,
if (copy_from_user(&features, featurep, sizeof features))
return -EFAULT;
printk(KERN_ERR "2\n");
- if (features & ~VHOST_FEATURES)
+ if (features & ~VHOST_TEST_FEATURES)
return -EOPNOTSUPP;
printk(KERN_ERR "3\n");
return vhost_test_set_features(n, features);
--
2.17.1