Browse Source

Properly report the remaining time on the last alarm (fix #93) (#101)

Properly report the remaining time on the last alarm for the alarm system call (fixes issue #93).  Add some alarm-related LTP tests to the list that should pass.
Don Porter 6 years ago
parent
commit
f122ea7b55

+ 3 - 3
LibOS/shim/include/shim_utils.h

@@ -235,9 +235,9 @@ int create_handle (const char * prefix, char * path, size_t size,
 
 /* Asynchronous event support */
 int init_async (void);
-int install_async_event (PAL_HANDLE object, unsigned long time,
-                         void (*callback) (IDTYPE caller, void * arg),
-                         void * arg);
+uint64_t install_async_event (PAL_HANDLE object, unsigned long time,
+                              void (*callback) (IDTYPE caller, void * arg),
+                              void * arg);
 int create_async_helper (void);
 int terminate_async_helper (void);
 

+ 8 - 5
LibOS/shim/src/shim_async.c

@@ -53,15 +53,17 @@ static AEVENTTYPE           async_helper_event;
 
 static LOCKTYPE async_helper_lock;
 
-int install_async_event (PAL_HANDLE object, unsigned long time,
-                         void (*callback) (IDTYPE caller, void * arg),
-                         void * arg)
+/* Returns remaining usecs */
+uint64_t install_async_event (PAL_HANDLE object, unsigned long time,
+                              void (*callback) (IDTYPE caller, void * arg),
+                              void * arg)
 {
     struct async_event * event =
                     malloc(sizeof(struct async_event));
 
     unsigned long install_time = DkSystemTimeQuery();
-
+    uint64_t rv = 0;
+    
     debug("install async event at %llu\n", install_time);
 
     event->callback     = callback;
@@ -97,6 +99,7 @@ int install_async_event (PAL_HANDLE object, unsigned long time,
          */
 		listp_del(tmp, &async_list, list);
         free(tmp);
+        rv = tmp->expire_time - install_time;
     } else
 	   tmp = NULL;
     
@@ -114,7 +117,7 @@ int install_async_event (PAL_HANDLE object, unsigned long time,
     unlock(async_helper_lock);
     
     set_event(&async_helper_event, 1);
-    return 0;
+    return rv;
 }
 
 int init_async (void)

+ 7 - 3
LibOS/shim/src/sys/shim_alarm.c

@@ -43,7 +43,11 @@ void signal_alarm (IDTYPE target, void * arg)
 int shim_do_alarm (unsigned int seconds)
 {
     uint64_t usecs = 1000000ULL * seconds;
-    return install_async_event(NULL, usecs, &signal_alarm, NULL);
+    uint64_t usecs_left = install_async_event(NULL, usecs, &signal_alarm, NULL);
+    // Alarm expects the number of seconds remaining.  Round up.
+    int secs = usecs_left / 1000000ULL;
+    if (usecs_left % 1000000ULL) secs++;
+    return secs;
 }
 
 static struct {
@@ -91,8 +95,8 @@ int shim_do_setitimer (int which, struct __kernel_itimerval * value,
                                     real_itimer.timeout - setup_time : 0;
     unsigned long current_reset = real_itimer.reset;
 
-    int ret = install_async_event(NULL, next_value, &signal_itimer,
-                                  (void *) (setup_time + next_value));
+    uint64_t ret = install_async_event(NULL, next_value, &signal_itimer,
+                                       (void *) (setup_time + next_value));
 
     if (ret < 0) {
         master_unlock();

+ 3 - 0
LibOS/shim/test/apps/ltp/PASSED

@@ -9,6 +9,9 @@ alarm01,1
 alarm02,1
 alarm02,2
 alarm02,3
+alarm03,2
+alarm05,1
+alarm06,1
 asyncio02,1
 asyncio02,2
 asyncio02,3

+ 17 - 1
LibOS/shim/test/apps/ltp/TIMEOUTS

@@ -1,10 +1,16 @@
 testcase,timeout
 alarm01,5
+alarm02,40
+alarm03,40
+alarm05,40
 alarm06,16
+brk01,40
+chmod02,40
 clock_nanosleep01,40
 clone03,40
 clone05,30
 clone06,40
+dup204,40
 exit01,40
 faccessat01,80
 fchdir02,40
@@ -15,27 +21,37 @@ fork02,40
 futex_wait_bitset02,40
 fsync03,40
 gethostname01,40
+getgid03,40
+getpid02,40
 gettid01,40
 msgsnd01,40
 mprotect04,40
 newuname01,40
-kill09,40
+kill09,80
 lseek02,40
+poll01,40
 pread01_64,40
 pread01,40
 pread02,40
+preadv01,40
+pwrite04_64,40
+pwritev01,40
 read01,40
 readdir01,40
 readv01,40
+semop04,40
 sendfile03_64,40
+setuid01,40
 setuid02,40
 sockioctl01,40
 sigaltstack02,40
 socket01,40
 socket02,40
 stat05_64,40
+sync01,40
 syscall01,80
 wait401,40
 waitpid03,80
 waitpid05,240
 write03,40
+write05,40