예제 #1
0
/*-----------------------------------------------------------------------------------*/
void
sys_init()
{
/*   struct timezone tz; */
/*   gettimeofday(&starttime, &tz); */
  starttime = syscall_now_in_nanosec() / 1000 / 1000;
}
예제 #2
0
파일: time.c 프로젝트: Nirlendu/mona
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
    if (tv) {
        uint64_t nowMsec = syscall_now_in_nanosec() / 1000000;
        tv->tv_sec = nowMsec / 1000;
        tv->tv_usec = (nowMsec - (nowMsec/1000) * 1000) * 1000;
    }
}
예제 #3
0
/*-----------------------------------------------------------------------------------*/
static u32_t
cond_wait(cond_t *cond, mutex_t *mutex, u32_t timeout)
{
  int tdiff;
/*   unsigned long sec, usec; */
/*   struct timeval rtime1, rtime2; */
/*   struct timespec ts; */
/*   struct timezone tz; */
  intptr_t retval;
  uint64_t start, end;

  if (timeout > 0) {
    /* Get a timestamp and add the timeout value. */
/*     gettimeofday(&rtime1, &tz); */
/*     sec = rtime1.tv_sec; */
/*     usec = rtime1.tv_usec; */
/*     usec += timeout % 1000 * 1000; */
/*     sec += (int)(timeout / 1000) + (int)(usec / 1000000); */
/*     usec = usec % 1000000; */
/*     ts.tv_nsec = usec * 1000; */
/*     ts.tv_sec = sec; */
    start = syscall_now_in_nanosec();
    retval = syscall_condition_wait_timeout(cond, mutex, timeout);

    if (retval == M_TIMED_OUT) {
      return SYS_ARCH_TIMEOUT;
    } else {
      /* Calculate for how long we waited for the cond. */
      end = syscall_now_in_nanosec();
/*       gettimeofday(&rtime2, &tz); */
/*       tdiff = (rtime2.tv_sec - rtime1.tv_sec) * 1000 + */
/*         (rtime2.tv_usec - rtime1.tv_usec) / 1000; */
      tdiff = (end - start) / 1000 / 1000;

      if (tdiff <= 0) {
        return 0;
      }

      return tdiff;
    }
  } else {
    syscall_condition_wait(cond, mutex);
    return SYS_ARCH_TIMEOUT;
  }
}
예제 #4
0
/*-----------------------------------------------------------------------------------*/
unsigned long
sys_unix_now()
{
/*   struct timeval tv; */
/*   struct timezone tz; */
/*   long sec, usec; */
/*   unsigned long msec; */
/*   gettimeofday(&tv, &tz); */

/*   sec = tv.tv_sec - starttime.tv_sec; */
/*   usec = tv.tv_usec - starttime.tv_usec; */
/*   msec = sec * 1000 + usec / 1000; */
  uint64_t msec = syscall_now_in_nanosec() / 1000 / 1000;

  return msec - starttime;
}