[ovs-dev] [PATCH v5 03/10] util: Add high resolution sleep support.

Aaron Conole aconole at redhat.com
Tue Nov 7 18:27:13 UTC 2017


Ben Pfaff <blp at ovn.org> writes:

> On Mon, Nov 06, 2017 at 05:29:26PM +0000, Bodireddy, Bhanuprakash wrote:
>> Hi Ben,
>> >
>> >On Fri, Sep 15, 2017 at 05:40:23PM +0100, Bhanuprakash Bodireddy wrote:
>> >> This commit introduces xnanosleep() for the threads needing high
>> >> resolution sleep timeouts.
>> >>
>> >> Signed-off-by: Bhanuprakash Bodireddy
>> >> <bhanuprakash.bodireddy at intel.com>
>> >
>> >This is a little confusing.  The name xnanosleep() implies that its argument
>> >would be in nanoseconds, but it's in fact in milliseconds.
>> >Second, I don't understand why it's only implemented for Linux.
>> 
>> I tried reworking this API with nanoseconds argument and
>> implementing nsec_to_timespec() today.
>> This changes works fine on Linux, however the windows build breaks
>> with below error as reported by appveyor.
>> 
>> error C4013: 'nanosleep' undefined; assuming extern returning int
>> (windows.h and time.h headers are included).
>> 
>> But looks like nanosleep is supported on windows. Any inputs on this
>> would be helpful.
>
> If nanosleep isn't available on Windows (it looks like it isn't), then
> I'd recommend using some other function that Windows does have.  If its
> argument isn't in nanoseconds, you can convert it.
>
> If you don't really need nanosecond resolution (the fact that the
> argument was in milliseconds seems like a hint), then maybe you could
> just use some other function instead of nanosleep, even on Linux.
>
> This stackoverflow page has some information:
> https://stackoverflow.com/questions/7827062/is-there-a-windows-equivalent-of-nanosleep

So, there's really no good way in windows of doing this - for OvS, I
would suggest reading up on the windows Wait calls
(https://msdn.microsoft.com/en-us/library/windows/desktop/ms687069(v=vs.85).aspx#waitfunctionsandtime-outintervals).

Prefer those to Sleep(), as Sleep(MS) can stall or deadlock the process
(at least from what I remember a lifetime ago).


More information about the dev mailing list