> Date: Tue, 25 Dec 2018 09:31:25 -0500 > From: Scott Cheloha <scottchel...@gmail.com> > > On Tue, Dec 25, 2018 at 02:19:46PM +0100, Mark Kettenis wrote: > > > Date: Mon, 24 Dec 2018 16:28:20 -0500 > > > From: Scott Cheloha <scottchel...@gmail.com> > > > > > > ok? > > > > How can this happen? Only if the user asks to sleep for exactly 0ns. > > That is a bit nonsensical. Currently we punish such a process by > > making it sleep. Which means that other processes can run. Why do > > you want to change this? > > Punishment is relative. I'm coming at this from a bughunting angle. > > If I get my math wrong and my timeout is truncated to zero I don't > want the code to appear as if it is behaving correctly by sleeping > for a tick or two. This could go unnoticed. However, if the same > code polls *hard* in a loop it's very obvious that something is > wrong. > > You could argue that it's not our problem... but to my mind doing what > the caller asked, i.e. "don't sleep," helps the programmer more than > it might help other processes by yielding.
Time to beat you over the head with POSIX ;) The nanosleep() function shall cause the current thread to be suspended from execution until... Which can be interpreted such that nanosleep() should always suspend the thread (unless an error is returned) even if te interval is 0ns. I think you need a more convincing argument to change this (actual code that misbehaves with the current implementation) especially since your diff adds complexity. > > > Index: sys/kern/kern_time.c > > > =================================================================== > > > RCS file: /cvs/src/sys/kern/kern_time.c,v > > > retrieving revision 1.103 > > > diff -u -p -r1.103 kern_time.c > > > --- sys/kern/kern_time.c 28 May 2018 18:05:42 -0000 1.103 > > > +++ sys/kern/kern_time.c 24 Dec 2018 21:21:40 -0000 > > > @@ -288,13 +288,18 @@ sys_nanosleep(struct proc *p, void *v, r > > > if (rmtp) > > > getnanouptime(&sts); > > > > > > + if (!timespecisset(&rqt)) { > > > + error = 0; > > > + goto out; > > > + } > > > + > > > error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep", > > > MAX(1, tstohz(&rqt))); > > > if (error == ERESTART) > > > error = EINTR; > > > if (error == EWOULDBLOCK) > > > error = 0; > > > - > > > +out: > > > if (rmtp) { > > > getnanouptime(&ets); > > > > > > > > > >