int usleep(int usec) { struct itimerval value, dumb; (void)signal(SIGALRM, usleep_sig); if(getitimer(ITIMER_REAL, &value) != 0) { perror("Error: couldn't get timer"); return(-1); } value.it_value.tv_sec = value.it_interval.tv_sec = (long) usec / 1000000; value.it_value.tv_usec = value.it_interval.tv_usec = (long) usec % 1000000; if(setitimer(ITIMER_REAL, &value, &dumb) != 0) /* ignore parameter 3 */ { perror("Error: couldn't set timer"); return(-1); } (void)sigpause(SIGALRM); if(getitimer(ITIMER_REAL, &value) != 0) { perror("Error: couldn't get timer"); return(-1); } usec = (value.it_value.tv_sec - value.it_interval.tv_sec) * 1000000; usec += (value.it_value.tv_usec - value.it_interval.tv_usec); return usec; }
ATF_TC_BODY(getitimer_empty, tc) { struct itimerval it; /* * Verify that the passed structure remains * empty after calling getitimer(2) but before * actually arming the timer with setitimer(2). */ (void)memset(&it, 0, sizeof(struct itimerval)); ATF_REQUIRE(getitimer(ITIMER_REAL, &it) == 0); if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0) goto fail; ATF_REQUIRE(getitimer(ITIMER_VIRTUAL, &it) == 0); if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0) goto fail; ATF_REQUIRE(getitimer(ITIMER_PROF, &it) == 0); if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0) goto fail; return; fail: atf_tc_fail("getitimer(2) modfied the timer before it was armed"); }
void *POSIX_Init( void *argument ) { int status; struct itimerval itimer; struct itimerval otimer; puts( "\n\n*** POSIX TEST ITIMER ***" ); /* test getitimer stub */ puts( "getitimer -- bad which - EINVAL " ); status = getitimer( 1234, &itimer ); rtems_test_assert( status == -1 && errno == EINVAL ); puts( "getitimer -- NULL pointer - EFAULT " ); status = getitimer( ITIMER_REAL, NULL ); rtems_test_assert( status == -1 && errno == EFAULT ); puts( "getitimer -- ITIMER_REAL - ENOSYS " ); status = getitimer( ITIMER_REAL, &itimer ); rtems_test_assert( status == -1 && errno == ENOSYS ); puts( "getitimer -- ITIMER_VIRTUAL - ENOSYS " ); status = getitimer( ITIMER_VIRTUAL, &itimer ); rtems_test_assert( status == -1 && errno == ENOSYS ); puts( "getitimer -- ITIMER_PROF - ENOSYS " ); status = getitimer( ITIMER_PROF, &itimer ); rtems_test_assert( status == -1 && errno == ENOSYS ); /* test setitimer stub */ puts( "setitimer -- bad which - EINVAL " ); status = setitimer( 1234, &itimer, &otimer ); rtems_test_assert( status == -1 && errno == EINVAL ); puts( "setitimer -- NULL value pointer - EFAULT " ); status = setitimer( ITIMER_REAL, NULL, &otimer ); rtems_test_assert( status == -1 && errno == EFAULT ); puts( "setitimer -- NULL value pointer - EFAULT " ); status = setitimer( ITIMER_REAL, &itimer, NULL ); rtems_test_assert( status == -1 && errno == EFAULT ); puts( "setitimer -- ITIMER_REAL - ENOSYS " ); status = setitimer( ITIMER_REAL, &itimer, &otimer ); rtems_test_assert( status == -1 && errno == ENOSYS ); puts( "setitimer -- ITIMER_VIRTUAL - ENOSYS " ); status = setitimer( ITIMER_VIRTUAL, &itimer, &otimer ); rtems_test_assert( status == -1 && errno == ENOSYS ); puts( "setitimer -- ITIMER_PROF - ENOSYS " ); status = setitimer( ITIMER_PROF, &itimer, &otimer ); rtems_test_assert( status == -1 && errno == ENOSYS ); puts( "*** END OF POSIX TEST ITIMER ***" ); rtems_test_exit(0); }
ATF_TC_BODY(getitimer_err, tc) { struct itimerval it; errno = 0; ATF_REQUIRE_ERRNO(EINVAL, getitimer(-1, &it) == -1); errno = 0; ATF_REQUIRE_ERRNO(EINVAL, getitimer(INT_MAX, &it) == -1); errno = 0; ATF_REQUIRE_ERRNO(EFAULT, getitimer(ITIMER_REAL, (void *)-1) == -1); }
/* return elapsed real seconds since call to init_etime */ static double get_etime(void) { struct itimerval v_curr; struct itimerval r_curr; struct itimerval p_curr; getitimer(ITIMER_VIRTUAL, &v_curr); getitimer(ITIMER_REAL,&r_curr); getitimer(ITIMER_PROF,&p_curr); return (double) ((first_p.it_value.tv_sec - r_curr.it_value.tv_sec) + (first_p.it_value.tv_usec - r_curr.it_value.tv_usec)*1e-6); }
int main(void) { struct itimerval* v1; struct itimerval* v2; struct itimerval* v3; ALLOCATE_GUARD(v1, 0); v1->it_interval.tv_sec = 10000; v1->it_interval.tv_usec = 0; v1->it_value.tv_sec = 10000; v1->it_value.tv_usec = 0; test_assert(0 == setitimer(ITIMER_REAL, v1, NULL)); VERIFY_GUARD(v1); ALLOCATE_GUARD(v2, 1); test_assert(0 == setitimer(ITIMER_REAL, v1, v2)); test_assert(v2->it_interval.tv_sec == v1->it_interval.tv_sec); VERIFY_GUARD(v2); ALLOCATE_GUARD(v3, 2); test_assert(0 == getitimer(ITIMER_REAL, v3)); test_assert(v3->it_interval.tv_sec == v1->it_interval.tv_sec); VERIFY_GUARD(v3); atomic_puts("EXIT-SUCCESS"); return 0; }
/* * Setup the systick timer to generate the tick interrupts at the required * frequency. */ void prvSetupTimerInterrupt( void ) { struct itimerval itimer, oitimer; portTickType xMicroSeconds = portTICK_RATE_MICROSECONDS; /* Initialise the structure with the current timer information. */ if ( 0 == getitimer( TIMER_TYPE, &itimer ) ) { /* Set the interval between timer events. */ itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = xMicroSeconds; /* Set the current count-down. */ itimer.it_value.tv_sec = 0; itimer.it_value.tv_usec = xMicroSeconds; /* Set-up the timer interrupt. */ if ( 0 != setitimer( TIMER_TYPE, &itimer, &oitimer ) ) { printf( "Set Timer problem.\n" ); } } else { printf( "Get Timer problem.\n" ); } }
unsigned char set_next_alarm ( unsigned int secs, unsigned int usecs ) { // assume that SIGALRM is already being caught, we just set the itimer here struct itimerval itv; // if no timer at all, set the 'current' one so it does something; otherwise // let it continue.. getitimer ( ITIMER_REAL, &itv ); if ( itv.it_value.tv_sec == 0 && itv.it_value.tv_sec == 0 ) { itv.it_value.tv_sec = secs; itv.it_value.tv_usec = usecs; } // set the next timer //bzero ( &itv, sizeof(struct itimerval) ); itv.it_interval.tv_sec = secs; itv.it_interval.tv_usec = usecs; // if next-timer is less than current, set current too if ( itv.it_value.tv_sec > itv.it_interval.tv_sec ) { itv.it_value.tv_sec = secs; itv.it_value.tv_usec = usecs; } if ( setitimer ( ITIMER_REAL, &itv, NULL /* old value returned here */ ) < 0 ) { // sucks return ( 0 ); } return ( 1 ); }
void timer_Show() { struct itimerval itimer; struct btTimer *pt; long rest; /* * Adjust the base time so that the deltas reflect what's really * happening. Changing TimerList->rest might cause it to become zero * (if getitimer() returns a value close to zero), and the * timer_InitService() call will call setitimer() with zero it_value, * stopping the itimer... so be careful! */ if (TimerList && getitimer(ITIMER_REAL, &itimer) == 0) rest = RESTVAL(itimer) - TimerList->rest; else rest = 0; #define SECS(val) ((val) / SECTICKS) #define HSECS(val) (((val) % SECTICKS) * 100 / SECTICKS) #define DISP \ "%s timer[%p]: freq = %ld.%02lds, next = %lu.%02lus, state = %s\n", \ pt->name, pt, SECS(pt->load), HSECS(pt->load), SECS(rest), \ HSECS(rest), tState2Nam(pt->state) ALOGI("---- Begin of Timer Service List---\n"); for (pt = TimerList; pt; pt = pt->next) { rest += pt->rest; ALOGI(DISP); } ALOGI("---- End of Timer Service List ---\n"); }
/*-------------------------------------------------------------------------- * * Initialize timer system * maxtimers -> how many timers we want in the system * Returns: 0= success, -1 = error */ int timer_init(int maxtimers) { atimer_t *tp; struct itimerval itvalue, itovalue; struct sigaction act; struct sigaction oldact; tp = (atimer_t *) malloc (maxtimers * sizeof (atimer_t)); if (tp == NULL) return -1; max_timers = maxtimers; /* Clear all timers */ memset(tp, 0, maxtimers * sizeof (atimer_t)); timers = tp; /* Setup timer handler */ memset ( &act, 0, sizeof (act) ); act.sa_handler = timer_process; act.sa_flags = SA_RESTART; sigaction(SIGALRM, &act, &oldact); /* Setup interval, and away we go... */ getitimer ( ITIMER_REAL, &itvalue ); itvalue.it_interval.tv_sec = 0; itvalue.it_interval.tv_usec = TIMER_INTERVAL; itvalue.it_value.tv_usec = TIMER_INTERVAL; if (setitimer ( ITIMER_REAL, &itvalue, &itovalue ) == -1) { perror ("setitimer"); } return 0; }
/** * @brief Low level HAL driver initialization. */ void hal_lld_init(void) { struct sigaction sigtick = { .sa_handler = port_tick_signal_handler, }; if (sigaction(PORT_TIMER_SIGNAL, &sigtick, NULL) < 0) port_halt(); const suseconds_t usecs = 1000000 / CH_FREQUENCY; struct itimerval itimer, oitimer; /* Initialize the structure with the current timer information. */ if (getitimer(PORT_TIMER_TYPE, &itimer) < 0) port_halt(); /* Set the interval between timer events. */ itimer.it_interval.tv_sec = usecs / 1000000; itimer.it_interval.tv_usec = usecs % 1000000; /* Set the current count-down. */ itimer.it_value.tv_sec = usecs / 1000000; itimer.it_value.tv_usec = usecs % 1000000; /* Set-up the timer interrupt. */ if (setitimer(PORT_TIMER_TYPE, &itimer, &oitimer) < 0) port_halt(); }
/*{{{ void ccsp_set_next_alarm (sched_t *sched, unsigned int usecs)*/ void ccsp_set_next_alarm (sched_t *sched, unsigned int usecs) { unsigned int next_alarm; struct itimerval itv; int ret; getitimer (ITIMER_REAL, &itv); next_alarm = ((unsigned int) (itv.it_value.tv_sec * 1000000U)) + ((unsigned int) itv.it_value.tv_usec); while (usecs && (next_alarm == 0 || next_alarm > usecs)) { itv.it_interval.tv_sec = 0; itv.it_interval.tv_usec = 0; #ifdef SOLARIS_TIMER_BUG itv.it_value.tv_sec = (usecs + quantum) / 1000000; itv.it_value.tv_usec = (usecs + quantum) % 1000000; #else itv.it_value.tv_sec = usecs / 1000000; itv.it_value.tv_usec = usecs % 1000000; #endif if ((ret = setitimer (ITIMER_REAL, &itv, &itv)) < 0) { BMESSAGE ("unable to set interval timer [%d] (%d)\n", usecs, ret); userproc_exit (1, 0); } next_alarm = usecs; usecs = ((unsigned int) (itv.it_value.tv_sec * 1000000U)) + ((unsigned int) itv.it_value.tv_usec); } }
int main(void) { struct itimerval it; sigset(SIGALRM, handler); it.it_value.tv_sec = 3; it.it_value.tv_usec = 0; it.it_interval.tv_sec = 2; it.it_interval.tv_usec = 0; if(setitimer(ITIMER_REAL, &it, (struct itimerval *)NULL) == -1) { perror("setitimer"); exit(1); } while(1) { if(getitimer(ITIMER_REAL,&it) == -1) { perror("gettimer"); exit(1); } printf("%d sec, %d msec.\n", (int)it.it_value.tv_sec, (int)it.it_value.tv_usec); sleep(1); } return 0; }
void slicetime_run_for(uint32_t microseconds) { struct itimerval value, ovalue, pvalue; int which = ITIMER_REAL; // only run when the slicetime communication works if (!slicetime_initialized) { printf("SliceTime not initialized!\n"); return; } // save the slicetime values slice = microseconds; first_time = 0; // ignore if the VM-es are still running if (!vm_running) { // resume all the VM-es vm_running = 1; // come before resume_all_vm so that the loop in main() works resume_all_vm(); // set the timer interrupt for "slice" microseconds signal(SIGALRM, slicetime_stop_timer_cb); getitimer( which, &pvalue ); value.it_interval.tv_sec = 0; /* Zero seconds */ value.it_interval.tv_usec = slice; /* "slice" microseconds */ value.it_value.tv_sec = 0; /* Zero seconds */ value.it_value.tv_usec = slice; /* "slice" microseconds */ setitimer( which, &value, &ovalue); } }
void mdsl_reset_itimer(void) { struct itimerval value, ovalue, pvalue; int err, interval; err = getitimer(ITIMER_REAL, &pvalue); if (err) { goto out; } interval = __gcd(hmo.conf.profiling_thread_interval, hmo.conf.gc_interval); if (interval) { value.it_interval.tv_sec = interval; value.it_interval.tv_usec = 0; value.it_value.tv_sec = interval; value.it_value.tv_usec = 0; err = setitimer(ITIMER_REAL, &value, &ovalue); if (err) { goto out; } hvfs_info(mdsl, "OK, we reset the itimer to %d second(s).\n", interval); } out: return; }
/* * Setup the systick timer to generate the tick interrupts at the required * frequency. */ LOCAL void portSetupTimerInterrupt( void ) { struct itimerval itimer, oitimer; int xMicroSeconds = 1000000 / 100; //100 ticks per second /* Initialise the structure with the current timer information. */ if ( 0 == getitimer( TIMER_TYPE, &itimer ) ) { /* Set the interval between timer events. */ itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = xMicroSeconds; /* Set the current count-down. */ itimer.it_value.tv_sec = 0; itimer.it_value.tv_usec = xMicroSeconds; /* Set-up the timer interrupt. */ if ( 0 != setitimer( TIMER_TYPE, &itimer, &oitimer ) ) { printf( "Set Timer problem.\n" ); } } else { printf( "Get Timer problem.\n" ); } }
long gethardwaretimer(){ if(getitimer(ITIMER_REAL, &t) == -1){ perror("failed to getharwaretimer() at hardwaretimer.c"); return -1; } return t.it_value.tv_usec; }
/** * implements alarm * seconds: number of seconds for realtime timer * returns: number of seconds remaing for prev timer or 0 if none * check for errno **/ unsigned int my_alarm(unsigned int seconds){ struct itimerval new_timer; struct itimerval cur_timer; new_timer.it_interval.tv_sec = 0; new_timer.it_interval.tv_usec = 0; new_timer.it_value.tv_usec = 0; if(seconds == 0){ if(getitimer(ITIMER_REAL,&cur_timer)!=0) return 0; if(cur_timer.it_value.tv_sec == 0 &&cur_timer.it_value.tv_usec ==0 ) return 0; else{ new_timer.it_value.tv_sec = 0; if(setitimer(ITIMER_REAL,&new_timer,NULL)!=0) return 0; return 0; } } else{ new_timer.it_value.tv_sec = seconds; if(setitimer(ITIMER_REAL,&new_timer,&cur_timer)!=0) return 0; return cur_timer.it_value.tv_sec; } }
double get_seconds(void) { struct itimerval curr; getitimer(ITIMER_PROF, &curr); return (double) ((first_u.it_value.tv_sec - curr.it_value.tv_sec) + (first_u.it_value.tv_usec - curr.it_value.tv_usec)*1e-6); }
/* Same prototype as pthread_create; use some #define magic to * * transparently replace it in other files */ int gprof_pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void * arg) { wrapper_t wrapper_data; int i_return; /* Initialize the wrapper structure */ wrapper_data.start_routine = start_routine; wrapper_data.arg = arg; getitimer(ITIMER_PROF, &wrapper_data.itimer); pthread_cond_init(&wrapper_data.wait, NULL); pthread_mutex_init(&wrapper_data.lock, NULL); pthread_mutex_lock(&wrapper_data.lock); /* The real pthread_create call */ i_return = pthread_create(thread, attr, &wrapper_routine, &wrapper_data); /* If the thread was successfully spawned, wait for the data * * to be released */ if(i_return == 0) { pthread_cond_wait(&wrapper_data.wait, &wrapper_data.lock); } pthread_mutex_unlock(&wrapper_data.lock); pthread_mutex_destroy(&wrapper_data.lock); pthread_cond_destroy(&wrapper_data.wait); return i_return; }
static void displayTimes(const char *msg, Boolean includeTimer) { struct itimerval itv; static struct timeval start; struct timeval curr; static int callNum = 0; /* Number of calls to this function */ if (callNum == 0) /* Initialize elapsed time meter */ if (gettimeofday(&start, NULL) == -1) errExit("gettimeofday"); if (callNum % 20 == 0) /* Print header every 20 lines */ printf(" Elapsed Value Interval\n"); if (gettimeofday(&curr, NULL) == -1) errExit("gettimeofday"); printf("%-7s %6.2f", msg, curr.tv_sec - start.tv_sec + (curr.tv_usec - start.tv_usec) / 1000000.0); if (includeTimer) { if (getitimer(ITIMER_REAL, &itv) == -1) errExit("getitimer"); printf(" %6.2f %6.2f", itv.it_value.tv_sec + itv.it_value.tv_usec / 1000000.0, itv.it_interval.tv_sec + itv.it_interval.tv_usec / 1000000.0); } printf("\n"); callNum++; }
/* * Setup the systick timer to generate the tick interrupts at the required * frequency. */ static void start_sys_timer(void) { struct itimerval itimer, oitimer; int us; RT_ASSERT(RT_TICK_PER_SECOND <= 1000000 || RT_TICK_PER_SECOND >= 1); us = 1000000 / RT_TICK_PER_SECOND - 1; TRACE("start system tick!\n"); /* Initialise the structure with the current timer information. */ if (0 != getitimer(TIMER_TYPE, &itimer)) { TRACE("get timer failed.\n"); exit(EXIT_FAILURE); } /* Set the interval between timer events. */ itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = us; /* Set the current count-down. */ itimer.it_value.tv_sec = 0; itimer.it_value.tv_usec = us; /* Set-up the timer interrupt. */ if (0 != setitimer(TIMER_TYPE, &itimer, &oitimer)) { TRACE("set timer failed.\n"); exit(EXIT_FAILURE); } }
ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter ( ACE_THR_FUNC user_func, void *arg, ACE_THR_C_FUNC entry_point, ACE_OS_Thread_Descriptor *td #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) , ACE_SEH_EXCEPT_HANDLER selector , ACE_SEH_EXCEPT_HANDLER handler #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ , long cancel_flags ) : user_func_ (user_func) , arg_ (arg) , entry_point_ (entry_point) , thr_desc_ (td) , ctx_ (ACE_Service_Config::current()) , flags_ (cancel_flags) { ACE_OS_TRACE ("ACE_Base_Thread_Adapter::ACE_Base_Thread_Adapter"); if (ACE_Base_Thread_Adapter::init_log_msg_hook_ != 0) (*ACE_Base_Thread_Adapter::init_log_msg_hook_) ( this->log_msg_attributes_ # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) , selector , handler # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ ); #ifdef ACE_USES_GPROF getitimer (ITIMER_PROF, &itimer_); #endif // ACE_USES_GPROF }
static void slicetime_stop_timer_cb(int sig) { struct itimerval value; int which = ITIMER_REAL; // stop the timer interrupts signal(SIGALRM, SIG_IGN); getitimer( which, &value ); value.it_value.tv_sec = 0; value.it_value.tv_usec = 0; setitimer( which, &value, NULL ); // suspend all the VM-es stop_all_vm(); vm_running = 0; // come after stop_all_vm to make sure all VM-es are stopped // calculate the running time (in nanoseconds) int64_t r_duration = (tp_end .tv_sec - tp_origin.tv_sec) - (tp_start.tv_sec - tp_origin.tv_sec); r_duration = r_duration * 1000000000LL + (tp_end.tv_nsec - tp_start.tv_nsec); // duration in nanoseconds // accumulate the running time r_total += r_duration; // send the FINISH message // content = time slice (us) + accumulated running time (ns) period_finished(slice, r_total); }
void start_timer() { getitimer(0, &timev); // repeat alarm every .1ms timev.it_interval = interval; // give each thread 10ms timev.it_value = value; setitimer(0, &timev, NULL); }
int gettimer (void) { struct itimerval timer; getitimer (ITIMER_REAL, &timer); return timer.it_interval.tv_usec; }
/* (copied from source pa_linux_oss/pa_linux_oss.c) */ static void Pa_StartUsageCalculation( internalPortAudioStream *past ) { struct itimerval itimer; PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData; if( pahsc == NULL ) return; /* Query system timer for usage analysis and to prevent overuse of CPU. */ getitimer( ITIMER_REAL, &pahsc->pahsc_EntryTime ); }
void timer_Start(struct pppTimer *tp) { struct itimerval itimer; struct pppTimer *t, *pt; u_long ticks = 0; sigset_t mask, omask; sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &omask); if (tp->state != TIMER_STOPPED) StopTimerNoBlock(tp); if (tp->load == 0) { log_Printf(LogTIMER, "%s timer[%p] has 0 load!\n", tp->name, tp); sigprocmask(SIG_SETMASK, &omask, NULL); return; } /* * We just need to insert tp in the correct relative place. We don't * need to adjust TimerList->rest (yet). */ if (TimerList && getitimer(ITIMER_REAL, &itimer) == 0) ticks = RESTVAL(itimer) - TimerList->rest; pt = NULL; for (t = TimerList; t; t = t->next) { if (ticks + t->rest >= tp->load) break; ticks += t->rest; pt = t; } tp->state = TIMER_RUNNING; tp->rest = tp->load - ticks; if (t) log_Printf(LogTIMER, "timer_Start: Inserting %s timer[%p] before %s " "timer[%p], delta = %ld\n", tp->name, tp, t->name, t, tp->rest); else log_Printf(LogTIMER, "timer_Start: Inserting %s timer[%p]\n", tp->name, tp); /* Insert given *tp just before *t */ tp->next = t; if (pt) { pt->next = tp; } else { TimerList = tp; timer_InitService(t != NULL); /* [re]Start the Timer Service */ } if (t) t->rest -= tp->rest; sigprocmask(SIG_SETMASK, &omask, NULL); }
int count_syscall(struct tcb *tcp, struct timeval *tv) { tcp->flags &= ~TCB_INSYSCALL; if (tcp->scno < 0 || tcp->scno >= nsyscalls) return 0; if (!counts) { counts = calloc(nsyscalls, sizeof(*counts)); if (!counts) { fprintf(stderr, "strace: out of memory for call counts\n"); exit(1); } } counts[tcp->scno].calls++; if (tcp->u_error) counts[tcp->scno].errors++; tv_sub(tv, tv, &tcp->etime); #ifdef LINUX if (tv_cmp(tv, &tcp->dtime) > 0) { static struct timeval one_tick; if (one_tick.tv_usec == 0) { /* Initialize it. */ struct itimerval it; memset(&it, 0, sizeof it); it.it_interval.tv_usec = 1; setitimer(ITIMER_REAL, &it, NULL); getitimer(ITIMER_REAL, &it); one_tick = it.it_interval; } if (tv_nz(&tcp->dtime)) *tv = tcp->dtime; else if (tv_cmp(tv, &one_tick) > 0) { if (tv_cmp(&shortest, &one_tick) < 0) *tv = shortest; else *tv = one_tick; } } #endif /* LINUX */ if (tv_cmp(tv, &shortest) < 0) shortest = *tv; tv_add(&counts[tcp->scno].time, &counts[tcp->scno].time, tv); return 0; }
/** For debugging convenience */ void print_timer(posix_timer_typ *ptmr) { getitimer(ITIMER_REAL, &ptmr->itmr); printf("timer interval %ld.%06ld\n", ptmr->itmr.it_interval.tv_sec, ptmr->itmr.it_interval.tv_usec); printf("timer it value %ld.%06ld\n", ptmr->itmr.it_value.tv_sec, ptmr->itmr.it_value.tv_usec); printf("timer value %d\n", ptmr->timer_value); }