[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 04/12] plat/drivers: Configure virtio block device



This patch introduces the configuration of block device consisting of:
-> finding multi-queue-max-queue number provided by Backend;
-> setting the number of queues to be used (between 1 and max)

Signed-off-by: Roxana Nicolescu <nicolescu.roxana1996@xxxxxxxxx>
---
 plat/drivers/include/virtio/virtio_blk.h |  7 ++++
 plat/drivers/virtio/virtio_blk.c         | 55 +++++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/plat/drivers/include/virtio/virtio_blk.h 
b/plat/drivers/include/virtio/virtio_blk.h
index b4b566e2..822c440d 100644
--- a/plat/drivers/include/virtio/virtio_blk.h
+++ b/plat/drivers/include/virtio/virtio_blk.h
@@ -28,12 +28,19 @@
 #define VIRTIO_BLK_F_RO                5
 /* Block size of disk is in blk_size. */
 #define VIRTIO_BLK_F_BLK_SIZE  6
+/* Device supports multi-queues */
+#define VIRTIO_BLK_F_MQ                12
+
 
 struct virtio_blk_config {
        /* Dimension in sectors number */
        __u64 capacity;
        /* Block size */
        __u32 blk_size;
+       /* Number of vqs, only available when VIRTIO_BLK_F_MQ is set */
+       __u16 num_queues;
+};
+
 };
 
 #endif /* __PLAT_DRV_VIRTIO_BLK_H */
diff --git a/plat/drivers/virtio/virtio_blk.c b/plat/drivers/virtio/virtio_blk.c
index b01b39bd..bda37866 100644
--- a/plat/drivers/virtio/virtio_blk.c
+++ b/plat/drivers/virtio/virtio_blk.c
@@ -40,10 +40,11 @@
 /* Features are:
  *     Access Mode
  *     Sector_size;
+ *     Multi-queue,
  **/
 #define VIRTIO_BLK_DRV_FEATURES(features) \
        (VIRTIO_FEATURES_UPDATE(features, VIRTIO_BLK_F_RO | \
-       VIRTIO_BLK_F_BLK_SIZE))
+       VIRTIO_BLK_F_BLK_SIZE | VIRTIO_BLK_F_MQ))
 
 static struct uk_alloc *a;
 static const char *drv_name = DRIVER_NAME;
@@ -55,10 +56,28 @@ struct virtio_blk_device {
        __u16 uid;
        /* Virtio Device */
        struct virtio_dev *vdev;
+       /* Nb of max_queues supported by device */
+       __u16 max_vqueue_pairs;
 };
 
 };
 
+
+static int virtio_blkdev_configure(struct uk_blkdev *dev,
+               const struct uk_blkdev_conf *conf)
+{
+       int rc = 0;
+       struct virtio_blk_device *vbdev = NULL;
+
+       UK_ASSERT(dev != NULL);
+       UK_ASSERT(conf != NULL);
+
+       vbdev = to_virtioblkdev(dev);
+
+       uk_pr_info(DRIVER_NAME": %"__PRIu16" configured\n", vbdev->uid);
+       return rc;
+}
+
 static void virtio_blkdev_close(struct uk_blkdev *dev)
 {
        struct virtio_blk_device *d;
@@ -73,6 +92,17 @@ static void virtio_blkdev_close(struct uk_blkdev *dev)
        uk_pr_info(DRIVER_NAME": %"__PRIu16" closed\n", uid);
 }
 
+static void virtio_blkdev_get_info(struct uk_blkdev *dev,
+               struct uk_blkdev_info *dev_info)
+{
+       struct virtio_blk_device *vbdev = NULL;
+
+       UK_ASSERT(dev != NULL);
+       UK_ASSERT(dev_info != NULL);
+
+       vbdev = to_virtioblkdev(dev);
+       dev_info->max_queues = vbdev->max_vqueue_pairs;
+}
 
 static int virtio_blkdev_feature_negotiate(struct virtio_blk_device *vbdev)
 {
@@ -82,6 +112,7 @@ static int virtio_blkdev_feature_negotiate(struct 
virtio_blk_device *vbdev)
        int bytes_to_read;
        __sector sectors;
        __sector ssize;
+       __u16 num_queues;
 
        UK_ASSERT(vbdev);
        cap = &vbdev->blkdev.capabilities;
@@ -115,12 +146,32 @@ static int virtio_blkdev_feature_negotiate(struct 
virtio_blk_device *vbdev)
                }
        }
 
+       /* If device does not support multi-queues,
+        *  we will use only one queue.
+        */
+       if (virtio_has_features(host_features, VIRTIO_BLK_F_MQ)) {
+               bytes_to_read = virtio_config_get(vbdev->vdev,
+                                       __offsetof(struct virtio_blk_config,
+                                                       num_queues),
+                                       &num_queues,
+                                       sizeof(num_queues),
+                                       1);
+               if (bytes_to_read != sizeof(num_queues)) {
+                       uk_pr_err("Failed to read max-queues\n");
+                       rc = -EAGAIN;
+                       goto exit;
+               }
+       } else
+               num_queues = 1;
+
        cap->ssize = ssize;
        cap->sectors = sectors;
        cap->align = sizeof(void *);
        cap->mode = (virtio_has_features(
                        host_features, VIRTIO_BLK_F_RO)) ? O_RDONLY : O_RDWR;
 
+       vbdev->max_vqueue_pairs = num_queues;
+
        /**
         * Mask out features supported by both driver and device.
         */
@@ -140,6 +191,8 @@ static inline void virtio_blkdev_feature_set(struct 
virtio_blk_device *vbdev)
 }
 
 static const struct uk_blkdev_ops virtio_blkdev_ops = {
+               .get_info = virtio_blkdev_get_info,
+               .dev_configure = virtio_blkdev_configure,
                .dev_close = virtio_blkdev_close,
 };
 
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.