Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3653265pxf; Mon, 29 Mar 2021 07:59:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJhS5dUo1MeJPFOprw2IFXBOJ/PHWAtTYZiYeey8NgvBYoTRxzyGHveE4zpqhxJSe24d92 X-Received: by 2002:aa7:de11:: with SMTP id h17mr28254319edv.83.1617029984097; Mon, 29 Mar 2021 07:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617029984; cv=none; d=google.com; s=arc-20160816; b=yoxcgZvTGETl7K9IBI2lavpvT0SqGTrQEgSlJZRYJqCVhbHwIAALe/XByJ0/PNqqwx 8C8y5aSViF2IaiF8WFcH3TxvRLuwGc6H5vHbqZVGZ+ZdPae2MgNjR2tvFr6nUOpmtIIm g0djdx8DF3XtQdVuvmNaGZsk5gjEKAiB3LHmYJxOZTs5Dn0jeA/mFzGvz2fCH3Hqc2PM 7TDDup+hq88E4BKPw/3mosI6Cj30P/VtF5fD2aAGIkTWleeLgqdcp9LybPNQMZ4owjTP VlnFvyCShAIVSqK5rUnbfLreNOBvNd+IiZQQTefCB4SzgOSYcOlOr/sSoN3FpOvl+Tup 5wUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=89OLqGCmDiFG02ByiCM7EbSbXUpQdtx+NtSMTPYy5WE=; b=xqx+OnvIhI622gJIqUpkGNM9VqETFtwOXDWIEdHzIBf+sHuQ4zBPypt8WDfcccOesY f2sS85SrKD48ssc/ylwEp2KRrczQumqirzGGeEKa8aOtcsSh9Yg/rce8B9VB1DXD1iio KYcWmyFMk9QYQNUAQokn1atoMG/P/VmohGZ8bME6BFdQdQJ2rsse0iHwqHem7z5EPwC5 8HAfWYbh/XUKodEX3mfXKYwt8wxDAZk3cSrWcrtgfdBH/vLBdEnLr/FvrNnf/iTBW5Ig ksQV7SFOuHSVHuasnqXafpVnq48X8pIcMd9uWCwqZzPD/canLNGNbY8zw2bRy184lfru Xp7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Lmhimi7O; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me5si13884453ejb.166.2021.03.29.07.59.21; Mon, 29 Mar 2021 07:59:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Lmhimi7O; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbhC2O6Y (ORCPT + 99 others); Mon, 29 Mar 2021 10:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbhC2O56 (ORCPT ); Mon, 29 Mar 2021 10:57:58 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB51C061574 for ; Mon, 29 Mar 2021 07:57:57 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1617029875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=89OLqGCmDiFG02ByiCM7EbSbXUpQdtx+NtSMTPYy5WE=; b=Lmhimi7O/3OamvzUjpTUvz2LuuakYEsVHAqb1mpThPe5ujFSI0K0XylTHG3MIvcj0B2oiz xxDU19NDZlzkZeeBc5Llm+Qj9oo1Co3myfuZ10gTsfn4RFJhZ3+2/mYSpicWuaaEDUWg51 O6f58nKs8wK0nrCDe5rv4UxDvZpHekR7jtdqJRYWSuaJvjH7U1GemwjZ3TyCCK0557H6YX 1V50jPDRhmes4V5T/qdNEmxbCMqPCkVjHWpVsYla0/kWfGkaemxuIcABK5DWPuDylNK21K 6GKYv767eWOLnmqa4vze6T4n3mcd20xiLuOv17qw27y3bZ2kSj6HtPSknyjPUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1617029875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=89OLqGCmDiFG02ByiCM7EbSbXUpQdtx+NtSMTPYy5WE=; b=2c26pYtI3ud0zkqfdmNCtMZdihyn9If20Ml+PVNwyalvPD+LgqpVF0dR+saA11nUnsmGFu wu4e/E3BWgkQ1dDw== To: Richard Cochran , Miroslav Lichvar Cc: Daphne Preston-Kendall , LKML , John Stultz , "Michael Kerrisk \(man-pages\)" Subject: Re: [Bug 212265] New: clock_gettime(CLOCK_TAI, ...) should return an error when TAI has not been configured In-Reply-To: <20210329142612.GC20909@hoboy.vegasvil.org> References: <87sg4iupzs.fsf@nanos.tec.linutronix.de> <20210327032859.GA3168@hoboy.vegasvil.org> <20210329142612.GC20909@hoboy.vegasvil.org> Date: Mon, 29 Mar 2021 16:57:55 +0200 Message-ID: <87o8f26m8c.ffs@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 29 2021 at 07:26, Richard Cochran wrote: > On Mon, Mar 29, 2021 at 11:16:48AM +0200, Miroslav Lichvar wrote: >> There are at least two issues with handling a zero offset as a special >> value. One is that zero could potentially be a valid value in distant >> future. > > I not losing sleep over that, but > >> The other is that the kernel updates the offset when a leap >> second is inserted/deleted even if the original offset is zero, so >> checking for zero (in the kernel or an application) works only until >> the first leap second after boot. > > oh, I didn't think of that. I hate leap seconds. Good thing Earth is > picking up the pace again! > >> The kernel would need to set a flag that the offset was set. Returning >> an error in clock_gettime() until the offset is set sounds reasonable >> to me, but I have no idea how many of the existing applications it >> would break. > > I think it wiser to provide another way, sysfs or something else. I think adjtimex is the right place and not yet another random file somewhere. Something like the below. Thanks, tglx --- include/uapi/linux/timex.h | 7 +++++-- kernel/time/ntp.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) --- a/include/uapi/linux/timex.h +++ b/include/uapi/linux/timex.h @@ -188,9 +188,12 @@ struct __kernel_timex { #define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */ #define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */ +#define STA_TAISET 0x10000 /* TAI offset was set via adjtimex (ro) */ + /* read-only bits */ -#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ - STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) +#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ + STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | \ + STA_CLK | STA_TAISET) /* * Clock states (time_state) --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -741,8 +741,10 @@ static inline void process_adjtimex_mode } if (txc->modes & ADJ_TAI && - txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET) + txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET) { *time_tai = txc->constant; + time_status |= STA_TAISET; + } if (txc->modes & ADJ_OFFSET) ntp_update_offset(txc->offset);