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

[Minios-devel] [UNIKRAFT PATCH 1/3] lib/vfscore: Use a scalable bitmap for open file descriptors


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 2 Sep 2019 16:22:19 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Mon, 02 Sep 2019 13:22:51 +0000
  • Ironport-phdr: 9a23:+3AzbRM0om4vWoaQ7CAl6mtUPXoX/o7sNwtQ0KIMzox0I/j9rarrMEGX3/hxlliBBdydt6sezbOJ6+u+AyQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagf79+Ngi6oAfNusUZgIZuNLs6xwfUrHdPZ+lY335jK0iJnxb76Mew/Zpj/DpVtvk86cNOUrj0crohQ7BAAzsoL2465MvwtRneVgSP/WcTUn8XkhVTHQfI6gzxU4rrvSv7sup93zSaPdHzQLspVzmu87tnRRn1gyoBKjU38nzYitZogaxbvhyvuhJxzY3Tbo6XOvpzZb/Rcc8ASGZdRMtdSzBND4WhZIUPFeoBOuNYopHjqlsJthu+GQisBOXywTFOm3/2xbA62PkmHA7a2wwgBM4OsHXSrNnvMKcSTPi1zLTTwDrfdPNawy/96JXTfRw7u/GMWqt9fMzMwkcsDwPIlkicpIP4Mz+P1ekAs3KX4/R+We+tkWIqpRl9riWgy8sxkIXEhYIYxkra+Sh3zos5P8C0RUFlbdOiDZBerTuVN5FsTcMnW2xovSE6xaAYtpOjZygKzYgnxwbYa/yab4iE+hLjW/iVITd/nH9lZre/iAyz8Uik0OHzStK03ExSripYidbArGoN1xvL5siGTPty4Fuh1C6S2w3c9+1IO0M5mKrBJ5I/3LI9lIAfvErbEi/zgkr2jauWdks++uiv7uTqeqnpppiHN49oiwH+NL4imsiiAeQgLwgDRHSU+f+m2L374E32W69GjucxkqXBqpDVOdwbprKlAw9Syosj7he/DzGn0NQfhnkLNU9KdwyZj4f3P1HDO/T4Dfakg1Swizdn3f/HMaPnApnXKXjDirjhd65n60FA0Aoz0cxf55VMB7EPPv3zXk7xtMTGARMjMwy03ufnB8l81o4FX2KAHLOWMKfIvlCT/O4gPfSMbpcPuDnhM/gl++LujXghlF8Gfammx4EXZ2q+Hvh8OEWWe3zsgssBEWgQuAoxVunqhUaEUTFNe3myW7gz6SohBI24EIfJXpqtj6CZ3CenAp1WYXhLCkuNEXftcIWEXe0AaCGPIsB/lDwFVKauS5U62BGoqgD1175nIfDP9SECq53jyYs92+qGkBA09DtvSsiQzWyJZ2V1hX8TAS872uZ4u0Mu5E2E1P1ThOdEFNobw+5RT09uPpnH0+18TdTvQh/pdczPUEusBM+hV2JiBuktysMDNh4uU+6piQrOinKn
  • Ironport-sdr: YlV/W4fLh82uSuGIGvkKLd/UvmEQZg4tkSvVGL+n+cO4jCpmGuRObTNiip6k75LdYiofZ7Oa3T kcknrPyJTAaA==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Until now, the number of open file descriptors was limited to 64, which was the
number of bits of the underlying bitmap. We fix that by replacing with a
configurable bitmap. We set the default value of maximum open files to 1024.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/vfscore/Config.uk |  8 +++++++-
 lib/vfscore/fd.c      | 16 ++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/vfscore/Config.uk b/lib/vfscore/Config.uk
index 6cf6c63a..07319099 100644
--- a/lib/vfscore/Config.uk
+++ b/lib/vfscore/Config.uk
@@ -1,6 +1,12 @@
-config LIBVFSCORE
+menuconfig LIBVFSCORE
        bool "vfscore: VFS Core Interface"
        default n
        select LIBNOLIBC if !HAVE_LIBC
        select LIBUKDEBUG
        select LIBUKLOCK
+
+if LIBVFSCORE
+config LIBVFSCORE_MAX_FILES
+       int "Maximum number of open files"
+       default 1024
+endif
diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c
index 01025a46..e09dd54c 100644
--- a/lib/vfscore/fd.c
+++ b/lib/vfscore/fd.c
@@ -35,19 +35,19 @@
 
 #include <string.h>
 #include <uk/essentials.h>
-#include <uk/bitops.h>
+#include <uk/bitmap.h>
 #include <uk/assert.h>
 #include <vfscore/file.h>
 #include <uk/plat/lcpu.h>
 #include <errno.h>
 #include <uk/ctors.h>
 
-#define FDTABLE_MAX_FILES (sizeof(uint64_t) * 8)
+#define FDTABLE_MAX_FILES 1024
 
 void init_stdio(void);
 
 struct fdtable {
-       uint64_t bitmap;
+       unsigned long bitmap[UK_BITS_TO_LONGS(FDTABLE_MAX_FILES)];
        uint32_t fd_start;
        struct vfscore_file *files[FDTABLE_MAX_FILES];
 };
@@ -59,14 +59,14 @@ int vfscore_alloc_fd(void)
        int ret;
 
        flags = ukplat_lcpu_save_irqf();
-       ret = ukarch_ffsl(~fdtable.bitmap);
+       ret = uk_find_next_zero_bit(fdtable.bitmap, FDTABLE_MAX_FILES, 0);
 
        if (!ret) {
                ret = -ENFILE;
                goto exit;
        }
 
-       fdtable.bitmap |= (uint64_t) 1 << ret;
+       uk_bitmap_set(fdtable.bitmap, ret, 1);
 
 exit:
        ukplat_lcpu_restore_irqf(flags);
@@ -83,7 +83,7 @@ void vfscore_put_fd(int fd)
        UK_ASSERT(fd > 2);
 
        flags = ukplat_lcpu_save_irqf();
-       __uk_clear_bit(fd, &fdtable.bitmap);\
+       uk_bitmap_clear(fdtable.bitmap, fd, 1);
        fp = fdtable.files[fd];
        fdtable.files[fd] = NULL;
        ukplat_lcpu_restore_irqf(flags);
@@ -129,7 +129,7 @@ struct vfscore_file *vfscore_get_file(int fd)
        UK_ASSERT(fd < (int) FDTABLE_MAX_FILES);
 
        flags = ukplat_lcpu_save_irqf();
-       if (!(fdtable.bitmap & ((uint64_t) 1 << fd)))
+       if (!uk_test_bit(fd, fdtable.bitmap))
                goto exit;
        ret = fdtable.files[fd];
        fhold(ret);
@@ -186,7 +186,7 @@ static void fdtable_init(void)
        memset(&fdtable, 0, sizeof(fdtable));
 
        /* reserve stdin, stdout and stderr */
-       fdtable.bitmap = 7;
+       uk_bitmap_set(fdtable.bitmap, 0, 3);
        init_stdio();
 }
 
-- 
2.20.1


_______________________________________________
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®.