Re: dependability of gettimeofday()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 18 July 2002 11:40 am, anton wilson wrote:
> On Thursday 18 July 2002 01:40 am, Amit Kucheria wrote:
> > On Wed, 17 Jul 2002, Karthik M wrote:
> > > hi everyone,
> > >
> > > as a follow up to the previous posting regarding
> > > effects of measurment, I was testing gettimeofday().
> > > The results that i got out of my test program were not
> > > consistent and were varying. Wanted to get an opinion
> > > abt it.
> > >
> > > ----snip-----
> > >
> > > the values are varying a lot and did'nt have a clue
> > > why it was the case. Did a little search on google but
> > > could'nt find an answer.
> >
> > IMHO "Scheduling granularity" is the key here. The linux system on x86
> > architectures has a heartbeat of 100Hz = 10ms. What this means is that
> > the system tries to complete its range of tasks such as scheduling
> > various subsystems, checking on blocked I/O, sending & receiving packets
> > etc etc. every 10ms. Since some tasks have more priority over others,
> > they might cause a delay for these low priority tasks which are
> > generally user processes.
>
> If you include
>
> #include <sched.h>
>
>   struct sched_param param;
>   param.sched_priority = sched_get_priority_max(SCHED_FIFO);
>
>
>    if( sched_setscheduler(0, SCHED_FIFO, &param) < 0)
>     {
>      printf("ERROR: Could not become realtime\n");
>      exit(0);
>      }
>
>
> You should see a lot less variation. In the tens or hundereds rather than
> thousands because no other normal processes can go pefore yours.


Better yet, if you put your original into a kernel module. Disable interrupts 
and preemption and then run it with do_gettimeofday you should see very 
little variation at all.

Anton
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux