#include #include #include #include #include #include "hist.h" #define RTPRIO 1 #define START 1000000 /* start time to sleep for in nanoseconds */ #define END 50000000 /* end time to sleep for in nanoseconds */ #define ITER 10000 /* iter time to sleep for in nanoseconds */ main(int argc, char *argv[]) { unsigned int numtimes, c1, c2; HIST hs; double dt, low, hi; struct timeval ts, te; struct timespec tfs; FILE *ofile; #ifdef RTPRIO struct sched_param p; p.sched_priority = 20; if (sched_setscheduler(0, SCHED_FIFO, &p) < 0) { perror("sched_setscheduler failure: RUN WITH PROPER PRIVLEDGES"); } #endif /* RTPRIO */ if (argc != 3) {printf("%s \n", argv[0]); exit(-1);} numtimes = atoi(argv[1]); stats_init(); low = START/1000.0 - 10000.0; if (low < 0.0) low = 0.0; hi = END/1000.0 + 20000.0; hs = histogram("Sleep Duration(usec)", 1000, low, hi); set_outer(100, hs); ofile = fopen(argv[2], "w"); tfs.tv_sec = 0; for (c1 = START; c1 <= END; c1 += ITER) { printf("c1 : %d\n", c1); for (c2 = 0; c2 < numtimes; c2++) { tfs.tv_nsec = c1; gettimeofday(&ts, NULL); if (nanosleep(&tfs, NULL) == -1) { perror("nanosleep failed."); exit(1); } gettimeofday(&te, NULL); dt = (te.tv_usec - ts.tv_usec); dt += (te.tv_sec - ts.tv_sec)*1000000.0; record(dt,hs); fprintf(ofile, "sleep_duration_actual_usec %8.8g duration_requested_usec %d\n", dt, c1/1000); } } report(); /* fprintf(ofile, "%8.8g %8.8g %8.8g %8.8g %10d\n", hs->tsum/hs->tcount, hs->tmin,hs->tmax,sqrt(table_var(hs)), hs->tcount); */ fclose(ofile); return 0; }