Re: timer with C



On a sunny day (Sun, 26 Mar 2006 11:31:36 +0200) it happened "Manu"
<info@xxxxxxxx> wrote in <44265f05$0$20141$8fcfb975@xxxxxxxxxxxxxxx>:

OK, here the same, with the start_timeval call added.

Better then this you will need a real time OS perhaps.


// vars
unsigned long lstart_usecs, lcurrent_usecs, ldiff_usecs;
struct timeval *start_timeval;
struct timeval *current_timeval;

// init
start_timeval = malloc(sizeof(struct timeval) );
if(!start_timeval)
{
fprintf(stderr, "mcamip: could not allocate space for start_timeval, aborting.\n");

exit(1);
}

current_timeval = malloc(sizeof(struct timeval) );
if(!current_timeval)
{
fprintf(stderr, "mcamip: could not allocate space for current_timeval, aborting.\n");

exit(1);
}


// your loop
while(1)
{
/* get elapsed time */
gettimeofday(current_timeval, NULL);

/* calculate time since previous picture */
lcurrent_usecs =\
current_timeval -> tv_usec + (1000000 * current_timeval -> tv_sec);

lstart_usecs =\
start_timeval -> tv_usec + (1000000 * start_timeval -> tv_sec);

ldiff_usecs = lcurrent_usecs - lstart_usecs;

// NOW your test
if(ldiff_usecs >= 100000)
{
fprintf(stderr, "Time is up dude!\n");
}

gettimeofday(start_timeval, NULL);

} // end while


It will ON AVERAGE generate a print statement every 100mS, but sometimes
it will be late by the time the kernel took to do other things with other
pids.


.



Relevant Pages

  • Re: Unix runs faster, maybe
    ... A kernel which can do hard real time is at the top of the list. ... I didn't think VMS was hard realtime. ...
    (comp.os.vms)
  • Re: RT patch acceptance
    ... > Bill, you can belittle me to your heart's content. ... you mean pervasively throughout the kernel for every system, ... should run within an interrupt plus a thread to enable if assuming ... practicality we're very close to hard real time. ...
    (Linux-Kernel)
  • Re: Newbie Question About Device Drivers
    ... I guess we are trying to achieve a more "Real Time" operating system. ... in the kernel you have access to the ... >if you can achieve what you want in user space, it is probably better to do ...
    (microsoft.public.development.device.drivers)
  • JAD and AppArmor problem
    ... during boot up that I can not modify, add or delete any AppArmor profiles. ... Has anybody booted to the rt kernel and got AppArmor ... jackd runs with real time capabilities enabled. ...
    (alt.os.linux.suse)
  • Re: Unix runs faster, maybe
    ... A kernel which can do hard real time is at the top of the list. ... Linus felt that the issues brought up by real time should be handled ... I don't ever expect real time Linux to keep up with pure real time OS ...
    (comp.os.vms)