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.

> > 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);
> >  
> > 
> > 

Reply via email to