Adds helper program to sleep / block
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 30 Apr 2013 22:25:19 +0000 (15:25 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 30 Apr 2013 22:31:36 +0000 (15:31 -0700)
$ usleep MICROSEC

kern/src/alarm.c
tests/usleep.c [new file with mode: 0644]

index 9af9263..7a73b6b 100644 (file)
@@ -71,7 +71,7 @@ void set_awaiter_rel(struct alarm_waiter *waiter, uint64_t usleep)
        then = now + usec2tsc(usleep);
        /* This will go off if we wrap-around the TSC.  It'll never happen for legit
         * values, but this might catch some bugs with large usleeps. */
-       assert(now < then);
+       assert(now <= then);
        set_awaiter_abs(waiter, then);
 }
 
diff --git a/tests/usleep.c b/tests/usleep.c
new file mode 100644 (file)
index 0000000..7808661
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <parlib.h>
+
+int main(int argc, char **argv)
+{
+       int sleep_time;
+       if (argc < 2) {
+               printf("Usage: %s MICROSEC\n", argv[0]);
+               exit(-1);
+       }
+       sleep_time = atoi(argv[1]);
+       if (sleep_time < 0)
+               exit(-1);
+       sys_block(sleep_time);
+       return 0;
+}