> Ben Pfaff <[email protected]> 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
> >> >> <[email protected]>
> >> >
> >> >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-
> equival
> > ent-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#waitfunctionsandtim
> e-outintervals).
> 
> Prefer those to Sleep(), as Sleep(MS) can stall or deadlock the process
(at
> least from what I remember a lifetime ago).
There is no direct equivalent unfortunately.
I would use
CreateWaitableTimer(https://msdn.microsoft.com/en-us/library/windows/desktop
/ms682492(v=vs.85).aspx) with SetWaitableTimer
(https://msdn.microsoft.com/en-us/library/windows/desktop/ms686289(v=vs.85).
aspx) and then wait on the timer(WaitForSingleObject) although you have 100
nanosecond intervals.
To go lower you can use: QueryPerformanceCounter
(https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).
aspx) .
I can try to do some benchmarks if you need such a high resolution. 

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to