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

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



Hi Costin,

I have one comment down there about gettimeofday. It's pretty small though, so if you're fine with it, I would just fix that before pushing the patch.

Other than that:
Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>

Thanks,
Florian

On 08/22/2018 12:26 PM, Costin Lupu wrote:
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;
+}
+

I don't think we need gettimeofday() right now, plus it's a non-working dummy function anyway. We needed that in newlib for some reason that I can't completely remember, but I would not port this one to nolibc. I would remove those 6 lines and then push the patch.

+#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;
+}


--
Dr. Florian Schmidt
フローリアン・シュミット
Research Scientist,
Systems and Machine Learning Group
NEC Laboratories Europe
Kurfürsten-Anlage 36, D-69115 Heidelberg
Tel.     +49 (0)6221 4342-265
Fax:     +49 (0)6221 4342-155
e-mail:  florian.schmidt@xxxxxxxxx
============================================================
Registered at Amtsgericht Mannheim, Germany, HRB728558

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