[uClinux-dev] usleep takes longer as expected
Harry Gunnarsson
mrharryg at gmail.com
Mon Feb 4 11:11:58 EST 2008
Hi,
Are you using m68k?
If so, take a look at linux-2.6.x/include/asm-m68knommu/param.h.
You'll see a line
#define HZ 100
That's your resolution for delay-like calls in uClinux, including the
'usleep' call. In this case, it is set by default to 100Hz, i.e. 10ms
resolution.
I experimented by setting this to 1000, thus enabling 1ms resolution. It
seemed to work, usleep behaves as expected.
I read somewhere that one might need to change other things as well, but
that posting might have been obsolete. My system behaves well with just the
HZ change.
Observe the following though:
I measured a 15.46% larger overhead with the 100 to 1000 HZ change. (10
times more frequent tick in kernel, and there is a lot of code executed with
each tick) In my case, we figured we could live with it, since in one
certain situation we preferably wanted ~1ms resolution.
Regards,
Harry
On Feb 4, 2008 7:57 AM, Siegfried Müller <mueller at mbconnectline.de> wrote:
> Hi,
> I work with the snapgear distro 3.4 and uClibc.
> I use usleep to wait for an exact time, but usleep takes a minimum
> of 10.000usec. If i use usleep(100) it takes 10.000usec. Why?
>
> int main(int argc, char *argv[])
> int i1=0;
> struct timeval mytime;
> struct timezone mytimezone;
>
> while(i1 < 10){
> gettimeofday(&mytime,&mytimezone);
> printf("Test %d, usec=%d,
> sec=%d\n",i1,mytime.tv_usec,mytime.tv_sec);
> usleep(100);
> i1++;
> }
> }
> Does anyone has an idea?
> Cheers
> Siegfried
>
> _______________________________________________
> uClinux-dev mailing list
> uClinux-dev at uclinux.org
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by uclinux-dev at uclinux.org
> To unsubscribe see:
> http://mailman.uclinux.org/mailman/options/uclinux-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.uclinux.org/pipermail/uclinux-dev/attachments/20080204/94ed48f8/attachment.html
More information about the uClinux-dev
mailing list