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

[Minios-devel] [UNIKRAFT PATCH v2 1/5] lib/vfscore: introduce vfscore_uioforeach



This is a template-type of function, to avoid code
duplication. Compiler optimizes extra call to the function pointer
passed as argument, so this should not have any performance impacts

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 lib/vfscore/include/vfscore/uio.h | 39 +++++++++++++++++++++++++++++++
 lib/vfscore/subr_uio.c            | 34 +++++++--------------------
 2 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/lib/vfscore/include/vfscore/uio.h 
b/lib/vfscore/include/vfscore/uio.h
index c734fa19..f9885b94 100644
--- a/lib/vfscore/include/vfscore/uio.h
+++ b/lib/vfscore/include/vfscore/uio.h
@@ -57,6 +57,45 @@ struct uio {
        enum    uio_rw uio_rw;          /* operation */
 };
 
+static inline
+int vfscore_uioforeach(int (*f)(void *, void *, size_t *), void *cp,
+                     size_t n, struct uio *uio)
+{
+       int ret = 0;
+
+       UK_ASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
+
+       while (n > 0 && uio->uio_resid) {
+               struct iovec *iov = uio->uio_iov;
+               size_t cnt = iov->iov_len;
+
+               if (cnt == 0) {
+                       uio->uio_iov++;
+                       uio->uio_iovcnt--;
+                       continue;
+               }
+               if (cnt > n)
+                       cnt = n;
+
+               if (uio->uio_rw == UIO_READ)
+                       ret = f(iov->iov_base, cp, &cnt);
+               else
+                       ret = f(cp, iov->iov_base, &cnt);
+
+               iov->iov_base = (char *)iov->iov_base + cnt;
+               iov->iov_len -= cnt;
+               uio->uio_resid -= cnt;
+               uio->uio_offset += cnt;
+               cp = (char *)cp + cnt;
+               n -= cnt;
+
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
 int    vfscore_uiomove(void *cp, int n, struct uio *uio);
 
 #endif /* !_UIO_H_ */
diff --git a/lib/vfscore/subr_uio.c b/lib/vfscore/subr_uio.c
index aa176074..e6e1cdf0 100644
--- a/lib/vfscore/subr_uio.c
+++ b/lib/vfscore/subr_uio.c
@@ -45,34 +45,16 @@
 #include <string.h>
 #include <vfscore/uio.h>
 
+static int __memcpy_wrapper(void *dst, void *src, size_t *cnt)
+{
+       memcpy(dst, src, *cnt);
+       return 0;
+}
+
 int
 vfscore_uiomove(void *cp, int n, struct uio *uio)
 {
-       UK_ASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
+       int ret = vfscore_uioforeach(__memcpy_wrapper, cp, n, uio);
 
-       while (n > 0 && uio->uio_resid) {
-               struct iovec *iov = uio->uio_iov;
-               int cnt = iov->iov_len;
-               if (cnt == 0) {
-                       uio->uio_iov++;
-                       uio->uio_iovcnt--;
-                       continue;
-               }
-               if (cnt > n)
-                       cnt = n;
-
-               if (uio->uio_rw == UIO_READ)
-                       memcpy(iov->iov_base, cp, cnt);
-               else
-                       memcpy(cp, iov->iov_base, cnt);
-
-               iov->iov_base = (char *)iov->iov_base + cnt;
-               iov->iov_len -= cnt;
-               uio->uio_resid -= cnt;
-               uio->uio_offset += cnt;
-               cp = (char *)cp + cnt;
-               n -= cnt;
-       }
-
-       return 0;
+       return ret;
 }
-- 
2.19.2


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