[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT/NEWLIB PATCH] Fix remaining time in nanosleep
Hi Dafna, looking good, thanks for the patch. On 09/17/2018 09:42 PM, Dafna Hirschfeld wrote: Add the fix of commit 96f68ab in unikraft to newlib: Calculate the remaining time to sleep and update the rem parameter if it is given. If the remaining time is larger than 0, it means that the thread was waken up explicitly and nanosleep returns -1 to indicate that. Otherwise nanosleep returns 0. Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx> Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx> --- time.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/time.c b/time.c index 9f12329..16747eb 100644 --- a/time.c +++ b/time.c @@ -37,12 +37,12 @@#include <sys/time.h>#include <utime.h> +#include <uk/plat/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> #endifint@@ -71,9 +71,16 @@ static void __spin_wait(__nsec nsec)int nanosleep(const struct timespec *req, struct timespec *rem){ - __nsec nsec = (__nsec) req->tv_sec * 1000000000L; + __nsec before, after, diff, nsec;+ if (!req || req->tv_nsec < 0 || req->tv_nsec > 999999999) {+ errno = EINVAL; + return -1; + } + + nsec = (__nsec) req->tv_sec * 1000000000L; nsec += req->tv_nsec; + before = ukplat_monotonic_clock();#if CONFIG_HAVE_SCHEDuk_sched_thread_sleep(nsec); @@ -81,9 +88,16 @@ int nanosleep(const struct timespec *req, struct timespec *rem) __spin_wait(nsec); #endif- if (rem) {- rem->tv_sec = 0; - rem->tv_nsec = 0; + after = ukplat_monotonic_clock(); + diff = after - before; + + if (diff < nsec) { + if (rem) { + rem->tv_sec = ukarch_time_nsec_to_sec(nsec - diff); + rem->tv_nsec = ukarch_time_subsec(nsec - diff); + } + errno = EINTR; + return -1; } 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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |