Re: [PATCH 1/3] signal: sys_rt_sigtimedwait: simplify the timeoutlogic

From: Oleg Nesterov
Date: Mon Apr 25 2011 - 13:57:31 EST


On 04/25, Linus Torvalds wrote:
>
> On Mon, Apr 25, 2011 at 10:26 AM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > If only I knew what this comment could say except
> >
> >        /* Why do we add (tv_sec || tv_nsec) ?  */
> >
> > I'd better send 4/3 which simply removes this (I hope) unneeded code.
>
> It's to guarantee that timeout is at least one tick more than asked
> for, because the rule is that you really have to wait for AT LEAST the
> time asked for.

Aah, thanks. This makes sense. I'll add the comment.

> So "+ (tv_sec || tv_nsec)" is just the "+1" for the "not zero timeout" case.

So, we have

timeout = timespec_to_jiffies(ts) + (tv_sec || tv_nsec);
...

if (timeout)
timeout = schedule_timeout_interruptible(timeout);

Perhaps it makes sense to turn this code into

timeout = timespec_to_jiffies(ts);

if (timeout)
// make sure we sleep at least the time we asked for
timeout = schedule_timeout_interruptible(timeout + 1);

Assuming that timespec_to_jiffies() always returns nonzero if ts is
"not zero timeout". I think it does.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/