Add uthread_usleep which sleeps in microseconds.
authorDavid Zhu <yuzhu@cs.berkeley.edu>
Mon, 28 Jul 2014 06:38:16 +0000 (23:38 -0700)
committerDavid Zhu <yuzhu@cs.berkeley.edu>
Sun, 3 Aug 2014 06:55:28 +0000 (23:55 -0700)
Fixing a previous bug where rounding was causing inaccurate waiting.
wq

tests/ping.c
user/parlib/include/uthread.h
user/parlib/uthread.c

index 50399da..693f504 100644 (file)
@@ -268,7 +268,7 @@ sender(int fd, int msglen, int interval, int n)
                        if(pingrint != 0)
                                extra = rand();
                        /* uth_sleep takes seconds, interval is in ms */
-                       uthread_sleep((interval + extra) / 1000);
+                       uthread_usleep((interval + extra) * 1000);
                }
                r = calloc(sizeof *r, 1);
                if (r == NULL){
index 50faa90..a205c69 100644 (file)
@@ -75,6 +75,7 @@ void uthread_runnable(struct uthread *uthread);
 void uthread_yield(bool save_state, void (*yield_func)(struct uthread*, void*),
                    void *yield_arg);
 void uthread_sleep(unsigned int seconds);
+void uthread_usleep(unsigned int usecs);
 
 /* Utility functions */
 bool __check_preempt_pending(uint32_t vcoreid);        /* careful: check the code */
index 4ca8234..058d894 100644 (file)
@@ -378,6 +378,12 @@ void uthread_sleep(unsigned int seconds)
 {
        sys_block(seconds * 1000000);   /* usec sleep */
 }
+/* If we are providing a dummy sleep function, might as well provide the more
+ * accurate/useful one. */
+void uthread_usleep(unsigned int usecs)
+{
+       sys_block(usecs);       /* usec sleep */
+}
 
 /* Cleans up the uthread (the stuff we did in uthread_init()).  If you want to
  * destroy a currently running uthread, you'll want something like