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

[Minios-devel] [UNIKRAFT PATCH] lib/nolibc: Add time.c


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Wed, 22 Aug 2018 13:26:15 +0300
  • Cc: Costin Lupu <costin.lup@xxxxxxxxx>, Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Wed, 22 Aug 2018 10:26:29 +0000
  • Ironport-phdr: 9a23:cRs8bhCMR6tb3HNlTO7GUyQJP3N1i/DPJgcQr6AfoPdwSPXzocbcNUDSrc9gkEXOFd2Cra4c1KyO6+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglUhjexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Xymp4aV2Rx/ykCoJNyA3/nzZhMJzi6xWuw6tqwBlzoLIeoyZKOZyc6XAdt0aX2pBWcNRWjRfD4O7dIsPE+sBPeBFpIf7ulsOtQa+DhSrCezzzT9InWP23aw80+g7FQHGwRQgH88VvXvIt9X5Lr8SUf2uw6XS1zXDaOpb1DHg44bLahAsueyAUL1tfcbLykQiFxnJgkuOpYHnJT+Y2PwBv3WU4uZ9T+6iiG4qpxtvrjWhyMogkJTFi40Lxl3C6C532pw6JceiR05+edOkFZxQuDyEOIZuWcMiRn1ouD49yr0bpZ63ZCgKx4ojxx7Yc/GHbY2I7QjiVOaVOzt3mGlldKinhxav6kes0Pf8Vs6s3FZLqCpKjMXMu2gQ2xHc98SLUPhw80e71TqRyQze6PtILE4smareMZEhw7owlpQJsUTEGy/7gFn5jKiNdkU4++io7f7rYrH7pp+EKo95kR3xMr80lsynHOQ3KRICX3Kc+eikzr3s4VX5QKlWjv0xiqTWrJfaJd8Hpq64BQ9ZyIIj6wunDzq939QYmGMILFNBeB6dk4fpPFTOKujiDfijm1SsjCtrx/feM73kA5XNKHnDkLD6fbpk9kFT1hQzws5b559PDrEBIenzWlPqtNDCAR42LQq0z/zgCNVn2YMUQXiPDbOBMKPOrV+I4foiLemIZI8Sojb9KuIq5/j0gXEkhVAdfayp3ZoKZ3CkBflmJVuWbmbogtgbCmgGpBQxTPHygl2YTTFTf2qyX7475jwjE4KmDILDRoergLCb3ye7A4NZZmZHC1+SC3flbIOEVOkQZyKWOMBuiSYIWqa8S4U5zxGhqBf6y6Z7LurT4iAZtY/j1MJ05+HJixEy8jh0ANid02GOSGF0gHgFRzko069jpUxy0EyM3bJmjPxFRpRv4KZMUwE7MoWZw+FkBtTaXgPaYszPWFugBNK8DmIfVNU0lvQJeFp8HZ2Gkwjel36hBKQJlrrNAIEs74rXxD7pOsw70XGQh/pptEUvXsYabT7uvaV47QWGX4M=
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

From: Costin Lupu <costin.lup@xxxxxxxxx>

Ported from Newlib glue code for Unikraft.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 lib/nolibc/Makefile.uk    |  1 +
 lib/nolibc/include/time.h |  4 +++
 lib/nolibc/time.c         | 83 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100644 lib/nolibc/time.c

diff --git a/lib/nolibc/Makefile.uk b/lib/nolibc/Makefile.uk
index 5039ad9..bec5afe 100644
--- a/lib/nolibc/Makefile.uk
+++ b/lib/nolibc/Makefile.uk
@@ -28,6 +28,7 @@ LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/string.c
 LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/getopt.c
 LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/sscanf.c
 LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/asprintf.c
+LIBNOLIBC_SRCS-y += $(LIBNOLIBC_BASE)/time.c
 LIBNOLIBC_SRCS-$(CONFIG_LIBUKALLOC) += $(LIBNOLIBC_BASE)/malloc.c
 
 # Localize internal symbols (starting with __*)
diff --git a/lib/nolibc/include/time.h b/lib/nolibc/include/time.h
index 26270bf..a6b9585 100644
--- a/lib/nolibc/include/time.h
+++ b/lib/nolibc/include/time.h
@@ -35,6 +35,8 @@
 #ifndef __TIME_H__
 #define __TIME_H__
 
+#include <sys/time.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -49,6 +51,8 @@ struct itimerspec {
        struct timespec it_value;
 };
 
+int nanosleep(const struct timespec *req, struct timespec *rem);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/nolibc/time.c b/lib/nolibc/time.c
new file mode 100644
index 0000000..8b803fd
--- /dev/null
+++ b/lib/nolibc/time.c
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * libnewlib glue code
+ *
+ * Authors: Felipe Huici <felipe.huici@xxxxxxxxx>
+ *          Florian Schmidt <florian.schmidt@xxxxxxxxx>
+ *
+ * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <time.h>
+#include <uk/config.h>
+#if CONFIG_HAVE_SCHED
+#include <uk/sched.h>
+#else
+#include <uk/plat/lcpu.h>
+#include <uk/plat/time.h>
+#endif
+
+int
+gettimeofday(struct timeval *tv __unused, void *tz __unused)
+{
+       return 0;
+}
+
+#ifndef CONFIG_HAVE_SCHED
+/* Workaround until Unikraft changes interface for something more
+ * sensible
+ */
+static void __spin_wait(__nsec nsec)
+{
+       __nsec until = ukplat_monotonic_clock() + nsec;
+
+       while (until > ukplat_monotonic_clock())
+               ukplat_lcpu_halt_to(until);
+}
+#endif
+
+int nanosleep(const struct timespec *req, struct timespec *rem)
+{
+       __nsec nsec = (__nsec) req->tv_sec * 1000000000L;
+
+       nsec += req->tv_nsec;
+
+#if CONFIG_HAVE_SCHED
+       uk_sched_thread_sleep(nsec);
+#else
+       __spin_wait(nsec);
+#endif
+
+       if (rem) {
+               rem->tv_sec = 0;
+               rem->tv_nsec = 0;
+       }
+       return 0;
+}
-- 
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®.