From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D995C2D0E7 for ; Wed, 1 Apr 2020 11:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1B12206E9 for ; Wed, 1 Apr 2020 11:16:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XUI7+JbE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732494AbgDALQ1 (ORCPT ); Wed, 1 Apr 2020 07:16:27 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:34361 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732258AbgDALQ1 (ORCPT ); Wed, 1 Apr 2020 07:16:27 -0400 Received: by mail-lf1-f65.google.com with SMTP id e7so20131412lfq.1; Wed, 01 Apr 2020 04:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=c2W2ZCFW75Hzmvi2Z1dJsLhmnnF1F/Vk/OMpx9dRAIs=; b=XUI7+JbE+o6HCbh48Ajper+T9aduNVwgn25i5zLtWNFdwmmUv7rwocoqrBzVOX7aYa bBnZ2Iug7N46NS8+5H8HqK0ZQasjJ7Rb7LQkyFzTcNUpQPZVCphn0HsowdOFduqukIBn Jmu7oygcvyVAu903qPvzJoN4nUXJUY+cuRGWrIzoWIKPwHqslX6sDJIFKC63tAmVdC9s rof7ApkRn1hX/TtzYFhq9Gi6hkmXW/P7kOSGZQHcfxp2PAcTHZ9hMSQomfzV44+IkBdW n0PJQAqIcONDp8dct4Sxa99cu1CaVw8lQXE7FkmL6rcVpHcL9KrHwPAAdnb2ey/rZNOM UrJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=c2W2ZCFW75Hzmvi2Z1dJsLhmnnF1F/Vk/OMpx9dRAIs=; b=FfeWjXd1sl5L0FoM0j43sEvaH3msG1hC0AZAMhiKubr25UofP3feec/3HmNzpy9bQz KVhtszJ0/xa3GZ3y5v05sJpmsPmj5zjoqwNNZb44djkDSAA2T7c4ClhwDleBBVhEvRKO kPeAiwgAUHb7DD8qk09ZRlAyGXUdIp4Z/31H8QRtm1KQiComovrH8E3ZpBJ50jHwCjip cLWuLHf5ISAserwg51HkmStluWg/RXp5ecOwnBorVDFrp26naLkr/2qTVS3VbzLliFPv eGXwLGxeXoLC1gAjiSSHeXkXuBUoTv0tWcuhohsecTbVOq75jA5pvgqGH8qcG0jxV2cL MPSA== X-Gm-Message-State: AGi0PubfiwvIy7cJ6X7uxnXAUYt7lW4eYnhG2rDB6EczkxGIS+ycy8ev 087KCsCx7JwdkbxMinF/MGM= X-Google-Smtp-Source: APiQypIcnkCb/DlDilD9iXAqcdBzVfyD1VeNAdgN2eI+5gP75WI1nFFQaeH22bZ3Y5FynCt5ivP/BQ== X-Received: by 2002:ac2:4113:: with SMTP id b19mr4809568lfi.70.1585739784413; Wed, 01 Apr 2020 04:16:24 -0700 (PDT) Received: from uranus.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id w24sm1002776ljh.57.2020.04.01.04.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 04:16:23 -0700 (PDT) Received: by uranus.localdomain (Postfix, from userid 1000) id B6BE74617E0; Wed, 1 Apr 2020 14:16:22 +0300 (MSK) Date: Wed, 1 Apr 2020 14:16:22 +0300 From: Cyrill Gorcunov To: "Michael Kerrisk (man-pages)" Cc: Thomas Gleixner , linux-man , lkml , arul.jeniston@gmail.com, "devi R.K" , Marc Lehmann , John Stultz , Andrei Vagin Subject: Re: timer_settime() and ECANCELED Message-ID: <20200401111622.GQ3197@uranus> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 01, 2020 at 11:01:18AM +0200, Michael Kerrisk (man-pages) wrote: > Hello Thomas, et al, > > Following on from our discussion of read() on a timerfd [1], I > happened to remember a Debian bug report [2] that points out that > timer_settime() can fail with the error ECANCELED, which is both > surprising and odd (because despite the error, the timer does get > updated). > > The relevant kernel code (I think, from your commit [3]) seems to be > the following in timerfd_setup(): > > if (texp != 0) { > if (flags & TFD_TIMER_ABSTIME) > texp = timens_ktime_to_host(clockid, texp); > if (isalarm(ctx)) { > if (flags & TFD_TIMER_ABSTIME) > alarm_start(&ctx->t.alarm, texp); > else > alarm_start_relative(&ctx->t.alarm, texp); > } else { > hrtimer_start(&ctx->t.tmr, texp, htmode); > } > > if (timerfd_canceled(ctx)) > return -ECANCELED; > } > > Using a small test program [4] shows the behavior. The program loops, > repeatedly calling timerfd_settime() (with a delay of a few seconds > before each call). In another terminal window, enter the following > command a few times: > > $ sudo date -s "5 seconds" # Add 5 secs to wall-clock time > > I see behavior as follows (the /sudo date -s "5 seconds"/ command was > executed before loop iterations 0, 2, and 4): Hi Michael, I can be wrong (since I didn't look into timerfd code for long time) but I guess if we wanna preserve the timer value we will have to lock timekeeper which is inacceptable. Thus looks like this is a tradeoff in a sake of speed (not sure though, better wait for Thomas reply)