Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp681671iog; Wed, 15 Jun 2022 10:01:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vuEzqQPel0vJZuw3fhJ9NYuRxJQ/XETLGAqC3nEcADxVTSWX0d9/58ZoL8gLu6lPIswkEN X-Received: by 2002:a17:906:51c5:b0:711:f4ee:6574 with SMTP id v5-20020a17090651c500b00711f4ee6574mr642422ejk.509.1655312473278; Wed, 15 Jun 2022 10:01:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655312473; cv=none; d=google.com; s=arc-20160816; b=MXGFhKFYJZ8kTghLHVKdqBrjJqXolbA3vYIXIb9bJlGFmWk05JXYQjFlO3roTEl4fW ZxGgUX/TC53WhvovD3Q91vemeXrB/KrnZk2e7nHAAAe2KLK6ECr/d8eHFy001A79fKT1 Y5KURrkdEM0YNpOrP/Dww4941MoNLSXtHibIg7CddfAG2w6cW7/MQrp4KL1UZQoXfMCB eR8Hxe3+/poOhPwvJJSTqTBnyan9GW+xzmGhJ+sL0SisDdeI/d7xK26Tgo0pCSIICXuK tS+nDD0eOySBPfR12kytUjNsNb4GxohD5hiecwUn06RH9AD4UdSy96kdzrvdmAJ30Pc3 JUvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=K8Qz7Vs9q7nXvzUppMlOI1ipfpO9oprPDhdKtEoC/cE=; b=D04U7BAy6ysQpTqgmgD7ujF28zikV6NASfxfEd2Tanm2v8aHY55DWneXgnzMYKHlnq +1LFNtMShziBccUdnG4Au1p9ZfA4wRo3ZJKRiHOm0A/QVM32qq99UZMX/C79NBHymrSn Yfv+l91+23xisC3+FnB6efRmFJzGBfMbhwXdVWToz7ImJi4qg4RRxO9oNsPWrpq5PvBX pr40V+lpw2vlP5jrg6Lnkgd8ta9rcx7TzsAnidNEx/AbNn+0IQMEBzpIlXzU04Sc6mwt m5oIJcHS0WY3T/DFrtwxzLtQXmPzAIi69uBPCsmeOcAil6Z65sgxjvsYG6brZP7mdINc DS4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aoMavuh7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g20-20020a056402425400b0042ad03b5aacsi18882182edb.5.2022.06.15.10.00.46; Wed, 15 Jun 2022 10:01:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aoMavuh7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346509AbiFOQzM (ORCPT + 99 others); Wed, 15 Jun 2022 12:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346442AbiFOQzI (ORCPT ); Wed, 15 Jun 2022 12:55:08 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6E14C42E for ; Wed, 15 Jun 2022 09:55:07 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id 3-20020a17090a174300b001e426a02ac5so2693743pjm.2 for ; Wed, 15 Jun 2022 09:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=K8Qz7Vs9q7nXvzUppMlOI1ipfpO9oprPDhdKtEoC/cE=; b=aoMavuh7wK4rAf319BPW0UnFM7vqpdOqzns9SsFphs2vsczwbT4Lq5B7c8AJiy4fsR YNvD1jZMhUpjTiHq0KhSEvVXKEk4QzLFc64Qb20BNTTWXp2GP9jNoA8XCe0iijZUr2Y3 lxFtFXjZ5JswRu7VwN/Y1AWd3QHuBlrMBXevga1RCbh/1oF+BPecssT/Ou8vDxFAWW4v WKujbRpZ3I7gcY+YQ5FrXtasAAsHA/p9Np68Dmg0oG4/KkzfefjAdT5yfMoeqa2tplys ztn3FUfXz/At8hF3Am46sL3qsT80x7dGttJqjPu/28uDNdFWGRS48f9qImyilU75iNr4 kb6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=K8Qz7Vs9q7nXvzUppMlOI1ipfpO9oprPDhdKtEoC/cE=; b=eoxoXIefE2B+AyUpGZjmbQuz2HaRxqlzHrAiX4QqN0lcLW/O2Bs1abw1QnvZSQtO4K 4envJF/tvxpyG4vlmq/f+DKjitGRDh9HTdYlZedZWTButsaaFCcnmXSRdxf0IeZULrho DBc1+Th+I6W9WYskqAPfjnmuXZI+vmHnhPCToAp5IMgdK3Y1v5GEdJTTtoi8U891W7Ap sBpNYjAwlVMONhLVbJQrE/KepBcg9j2lDFfax0XZ27gbC+pBamBAUV3tnVGSjSAOGeXN Udps6I7SbuoYHMR57w8h1IT64XkVqfsKUTY5hvc7i27umzwUAg++ak1+Nbkp7298tbIB alpg== X-Gm-Message-State: AJIora92dSLNxox563CG8e434UR31UiEP0SpabsWZQChBWtvrZ+HqRhK 2qU1MT1O7HNuS2hom0zGHhmdPA== X-Received: by 2002:a17:90b:4b4b:b0:1e8:9e0e:c362 with SMTP id mi11-20020a17090b4b4b00b001e89e0ec362mr352044pjb.187.1655312106819; Wed, 15 Jun 2022 09:55:06 -0700 (PDT) Received: from smtpclient.apple ([192.77.111.2]) by smtp.gmail.com with ESMTPSA id d13-20020a170902654d00b001637704269fsm9583307pln.223.2022.06.15.09.55.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jun 2022 09:55:06 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Subject: Re: [musl] Question about musl's time() implementation in time.c From: Adhemerval Zanella In-Reply-To: Date: Wed, 15 Jun 2022 09:55:04 -0700 Cc: musl@lists.openwall.com, John Stultz , Stephen Boyd , Linux Kernel Mailing List , Thomas Gleixner Content-Transfer-Encoding: quoted-printable Message-Id: <929C8485-D7F2-470A-B704-8068540DC358@linaro.org> References: <20220607163053.GD7074@brightrain.aerifal.cx> <20220614170013.GH7074@brightrain.aerifal.cx> <20220614204900.GI7074@brightrain.aerifal.cx> <20220614232826.GJ7074@brightrain.aerifal.cx> To: Arnd Bergmann X-Mailer: Apple Mail (2.3696.100.31) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 15 Jun 2022, at 05:09, Arnd Bergmann wrote: >=20 > On Wed, Jun 15, 2022 at 1:28 AM Rich Felker wrote: >> On Tue, Jun 14, 2022 at 11:11:32PM +0200, Arnd Bergmann wrote: >>>=20 >>> The thing is that a lot of file systems would still behave the same = way >>> because they round times down to a filesystem specific resolution, >>> often one microsecond or one second, while the kernel time = accounting >>> is in nanoseconds. There have been discussions about an interface >>> to find out what the actual resolution on a given mount point is = (similar >>> to clock_getres), but that never made it in. The guarantees that you >>> get from file systems at the moment are: >>=20 >> It's normal that they may be rounded down the the filesystem = timestamp >> granularity. I thought what was going on here was worse. >=20 > It gets rounded down twice: first down to the start of the current > timer tick, which is at an arbitrary nanosecond value in the past = 10ms, > and then to the resolution of the file system. The result is that the > file timestamp can point to a slightly earlier value, up to max(timer = tick > cycle, fs resolution) before the actual nanosecond value. We don't > advertise the granule of the file system though, so I would expect > this to be within the expected behavior. >=20 >> OK, the time syscall doing the wrong thing here (using a different >> clock that's not correctly ordered with respect to CLOCK_REALTIME) >> seems to be the worst problem here -- if I'm understanding it right. >> The filesystem issue might be a non-issue if it's truly equivalent to >> just having coarser fs timestamp granularity, which is allowed. >=20 > Adding the kernel timekeeping maintainers to Cc. I think this is a > reasonable argument, but it goes against the current behavior. >=20 > We have four implementations of the time() syscall that one would > commonly encounter: >=20 > - The kernel syscall, using (effectively) CLOCK_REALTIME_COARSE > - The kernel vdso, using (effectively) CLOCK_REALTIME_COARSE > - The glibc interface, calling = __clock_gettime64(CLOCK_REALTIME_COARSE, ...) > - The musl interface, calling __clock_gettime64(CLOCK_REALTIME, ...) >=20 > So even if everyone agrees that the musl implementation is the > correct one, I think both linux and glibc are more likely to stick = with > the traditional behavior to avoid breaking user space code such as the > libc-test case that Zev brought up initially. At least Adhemerval's > time() implementation in glibc[1] appears to have done this = intentionally, > while the Linux implementation has simply never changed this in an > incompatible way since Linux-0.01 added time() and 0.99.13k added > the high-resolution gettimeofday(). >=20 > Arnd >=20 > [1] https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommitdiff;h=3D0d56378= 349 Indeed I have changed glibc to be consistent on all architectures to = mimic kernel behavior time syscall and avoid this very issue. We did not have a = consistent implementation before, so glibc varied depending of architecture and = kernel version whether it uses CLOCK_REALTIME or CLOCK_REALTIME_COARSE. If kernel does change to make time() use CLOCK_REALTIME, it would make sense to make glibc __clock_gettime64 to use it as well. We will also = need to either disable time vDSO usage on x86 and powerpc or make kernel = implementation=09 to use CLOCK_REALTIME as well.