Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Feb 2008 14:40:56 +0530
From:      Sharad Chandra <sharadc@in.niksun.com>
To:        freebsd-hackers@freebsd.org
Cc:        "Heiko Wundram \(Beenic\)" <wundram@beenic.net>
Subject:   Re: usleep
Message-ID:  <200802251440.56435.sharadc@in.niksun.com>
In-Reply-To: <200802221437.48293.wundram@beenic.net>
References:  <200802221558.42443.sharadc@in.niksun.com> <200802221437.48293.wundram@beenic.net>

next in thread | previous in thread | raw e-mail | index | archive | help
 ,---- [Heiko Wundram (Beenic) wrote:]
| Am Freitag, 22. Februar 2008 11:28:42 schrieb Sharad Chandra:
| > 	Does usleep work for you? i just saw it is implemented over nanosleep
| > which passes a struct timeval to "select".
|
| Quoting from POSIX:
|
| """
| The usleep() function will cause the calling thread to be suspended from
| execution until either the number of real-time microseconds specified by
| the argument useconds has elapsed or a signal is delivered to the calling
| thread and its action is to invoke a signal-catching function or to
| terminate the process. The suspension time may be longer than requested due
| to the scheduling of other activity by the system.
| """

Yes, exactly. "microseconds" is giving me image we can go up to 1 micro but 
not a single time it sleeps for that much, or +- 10-20 micro sec. does 
suspension time mean 1000 micro secs?

|
| See the last sentence, specifically.
|
| So, yes, the behaviour you're seeing is pretty much expected, simply
| because _user_ processes are scheduled in timeslices, which depend on the
| HZ setting of the kernel.

I was looking some where and i found process switching time is around 10ms. 
That means time slice is 10ms. say some peace of code just called usleep or 
nanosleep and scheduling occurs so at least it will take 10 ms. I didn't find 
sleeping more than 10 ms if usec = 1 to few us.

Similarly, For setitimer, it goes the same too. if my code is right 

    value.it_interval.tv_sec = 0;        /* Zero seconds */
    value.it_interval.tv_usec = 000000;
    value.it_value.tv_sec = 0;           /* Zero seconds */
    value.it_value.tv_usec = 1;     /* 1 us */

    result = setitimer( which, &value, &ovalue );

    gettimeofday (&t1, NULL);
    for( count=0; ((count<LOOP_LIMIT) && (sigcount<1)); count++ );

t2 is timeval in signal handler. delta of t1 and t2 is big enough (1-2 ms)

So does it mean, freebsd has limitation. sleeping will only work for its value 
more than 1 milli sec because % of +- error value is comparitivly low? I am 
curious to know, is there any method which sleeps for few microseconds. Some 
one please give me link where to look for "select".

|
`----

--

Thanks
Sharad Chandra



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802251440.56435.sharadc>