/*+ MODULE utimer - Test of Timer Services Package (POSIX Compliant) Description: This program test the UTIMER Timer Services Package by creating both time-of-day and per-process timers. The timing period which is measured is generated by cyclically evaluating the sin function. Since the timing interval may be comparable or shorter than the period of a clock tick, it is necessary to use the timing routines as a statistical sampler; and, therefore, generating the measured timing period by any method which is synchronous with the system clock would defeat the purpose of statistical sampling of the clock ticks. AUTHOR: J. Frederick Bartlett D0 Contruction Department Research Division Fermilab CREATION DATE: 05-Nov-1996 MODIFICATIONS: -*/ #include #include #include "utimer.h" #define CYCLE_MAX 20 /* Cycle count for statistics */ #define DELAY_COUNT 20000 /* Function cycle count for delay */ /* Function Declarations */ TmrStatus testTimer(const TmrMode); #ifdef __vxworks__ void utest(void) #else void main(void) #endif { TmrStatus rcode; printf("Begin UTEST\n"); /* Test the time-of-day clock timing */ printf("Calendar time\n"); rcode = testTimer(tmmClock); /* Test the process clock timing */ printf("Processor time\n"); rcode = testTimer(tmmCpu); printf("End UTEST\n"); } TmrStatus testTimer(const TmrMode mode) { /* Macro to generate an error message */ #define statusCheck(string) \ if (rcode != TM_SUCCESS) \ { \ printf("Timer error in " #string ", status: %3d\n", rcode); \ return (rcode); \ } TmrId id; TmrStatus rcode; int cycle, ndx, count; float interval, mean, sigma, min, max; double x; /* Create the timer object */ rcode = tmrCreate(&id, mode); if (rcode == TM_INVARG) { printf("This timing mode is not implemented, mode: %3d\n", mode); return (rcode); } /* Begin the sample cycle */ for (cycle = 1; cycle <= CYCLE_MAX; cycle += 1) { /* Start the timer */ rcode = tmrStart(id); statusCheck("tmrStart"); /* Execute the timed section */ for (ndx = 1; ndx <= DELAY_COUNT; ndx += 1) x = sin((double)ndx); /* Stop the timer */ rcode = tmrStop(id, &interval); statusCheck("tmrStop"); printf(" Interval - %10.3E\n", interval); } /* Compute the interval mean and standard deviation of the mean */ rcode = tmrCompute(id, &count, &mean, &sigma); statusCheck("tmrCompute"); /* Get the minimum and maximum intervals */ rcode = tmrLimit(id, &min, &max); statusCheck("tmrLimit"); printf("Count - %3d, Mean - %10.3E, Sigma - %10.3E\n", count, mean, sigma); printf("Minimum - %10.3E, Maximuum - %10.3E\n", min, max); /* Delete the timer */ rcode = tmrDelete(id); statusCheck("tmrDelete"); return (TM_SUCCESS); }