From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751710AbcFWSlN (ORCPT ); Thu, 23 Jun 2016 14:41:13 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35417 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751166AbcFWSlM (ORCPT ); Thu, 23 Jun 2016 14:41:12 -0400 Subject: Re: futex: Allow FUTEX_CLOCK_REALTIME with FUTEX_WAIT op To: Darren Hart , Thomas Gleixner References: <20160620162652.2c4619c3@perruche.parrot.biz> <20160623044828.GA3379@f23x64.localdomain> <520d203a-83ad-0277-79d5-2209d6853628@gmail.com> <20160623161643.GA106079@f23x64.localdomain> <20160623182821.GB106079@f23x64.localdomain> Cc: mtk.manpages@gmail.com, Matthieu CASTET , linux-kernel@vger.kernel.org, Darren Hart , Peter Zijlstra , Davidlohr Bueso , Eric Dumazet From: "Michael Kerrisk (man-pages)" Message-ID: Date: Thu, 23 Jun 2016 20:41:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <20160623182821.GB106079@f23x64.localdomain> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/23/2016 08:28 PM, Darren Hart wrote: > On Thu, Jun 23, 2016 at 07:26:52PM +0200, Thomas Gleixner wrote: >> On Thu, 23 Jun 2016, Darren Hart wrote: >>> On Thu, Jun 23, 2016 at 03:40:36PM +0200, Thomas Gleixner wrote: >>> In my opinion, we should treat the timeout value as relative for FUTEX_WAIT >>> regardless of the CLOCK used. >> >> Which requires even more changes as you have to select which clock you are >> using for adding the base time. > > Right, something like the following? > > > diff --git a/kernel/futex.c b/kernel/futex.c > index 33664f7..c39d807 100644 > --- a/kernel/futex.c > +++ b/kernel/futex.c > @@ -3230,8 +3230,12 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val, > return -EINVAL; > > t = timespec_to_ktime(ts); > - if (cmd == FUTEX_WAIT) > - t = ktime_add_safe(ktime_get(), t); > + if (cmd == FUTEX_WAIT) { > + if (cmd & FUTEX_CLOCK_REALTIME) > + t = ktime_add_safe(ktime_get_real(), t); > + else > + t = ktime_add_safe(ktime_get(), t); > + } > tp = &t; > } > /* Just in the interests of readability/maintainability, might it not make some sense to recode the timeout handling for FUTEX_WAIT within futex_wait(). I think that part of the reason we're in this mess of inconsistency is that timeout interpretation is being handled at too many different points in the code. > And as a follow-on, what is the reason for FUTEX_LOCK_PI only using > CLOCK_REALTIME? It seems reasonable to me that a user may want to wait a > specific amount of time, regardless of wall time. Yes, that's another weird inconsistency. Thanks, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/