Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2740960rdb; Mon, 12 Feb 2024 15:22:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWAGaIqRvoY0RxuMc0rhYyxxeKCbq6WiajqWGV5AAoRqQGsL/y3ybjWgcPx9yXKsTM9eF/dcg2fGl1rfSTGXKKSmHshT2B9ASWTKiuR2g== X-Google-Smtp-Source: AGHT+IHh5VIsvBR+TI2MYxEsQU2j9LAsyVMShv2+XtGVebapEl7FiEBHR0jTMTbdllo0OWbSHpye X-Received: by 2002:a05:6a00:198e:b0:6e0:5960:861f with SMTP id d14-20020a056a00198e00b006e05960861fmr7865352pfl.17.1707780174363; Mon, 12 Feb 2024 15:22:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707780174; cv=pass; d=google.com; s=arc-20160816; b=pDkK/FV+VHHlmBR0Zjif5JXMBMz8x+SypAq1mmybOx7Fzn84zQOxnbKF1+wxoEmBu1 XtenXPRt5/9NmyZkmpJMO75WRmosNNr5wdl1E7k/xYu6MA3pbU4vcXqTr90YJOP8QqTP gYC30ozPfVI4R9gpWTQXn/DfrmJ46OC8JfzaVp4/YPR4oZQXB8c2lWGe9ftI+KDNKhk3 kHmGt+arMP9On2AqHdvsxSmByrV5OHW0VQds84fM5g501ia2BW0vmOlZjRB+WftFVLcG UObnAHER1I9GaT6B2wb/QnAIdMvBZkcqrzJ90uHG8Ak4V2+98mln+JF+Wmgx3Wk3Q/uE 1gFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=y18cEADXMAHj9yL9ELXLWBM2/DUY8Csq6elKaw1ee7Q=; fh=gBJ/DmF4c3rBMW5lHzwQB+KI2/nWPalVIqWlpKLFGes=; b=jTM5bc1uBfIP8kI6gWEXtlMfVIIAZ1ydyJ2EDp1ncvL/tDfnXZeQulpJxDTaKh/xMK x9+Y2MmFPvmGdLibw9pqbRjUycoQsE7UoPfa9H78iCH4wan6xldS8ega55CgLbZP9VnH vA6kYivVWSrKh82yWZPf+uOiKNIkqFPZi1piC8xQo10cFPbys142jsKUsw0Y2D2LoGz5 XSW9/rQQytukRRHuc6KVShgwJ+yyYjbyMT3n3RwZ1HRSQ+Kvt6dG81a+tX3kNdOc8YNQ UI/oCGMDSXOWxxGNaaQyHFFxzYbVEthLZAHTFTZA1gElmUlkaW2mnYF/IMzQudRqXjQN Z19A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TfM672aF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-62528-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62528-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCWaUYDM9FBC0tCKTzeuXHI716T6CNiyX6uRtdpig4Jsf0Q5mlktt4oN6H2gvyyTPngm1qV5fp4cZtXCoJPw7Jwp5a4ymgTsK5kgbb5hJg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jw16-20020a056a00929000b006e0deb27b4csi2372452pfb.72.2024.02.12.15.22.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:22:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62528-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TfM672aF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-62528-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62528-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 99CADB23B34 for ; Mon, 12 Feb 2024 23:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE6024F885; Mon, 12 Feb 2024 23:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TfM672aF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rjXFj7ao" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A967347A53 for ; Mon, 12 Feb 2024 23:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707780162; cv=none; b=Oj65Z99c/iTEl9ggyajhOGhjFctPT1GGtfas5qxRfkCcQvM3MwJOht/v3ljK9/yVXKY3dJrUtqkYLZBbKeJt2K2vSoDnHwwv2Yg1A5gtL+nWMwwSHft5r2pjJBeB80W6HipIugT+XouA31WjIvEL30DrPG1R1xf/rKl6sDjmero= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707780162; c=relaxed/simple; bh=5t5jG2Srhl2hwZZ31/oTgIWfmwPzLTzPV/Eflo/j54w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Cu7h/czS1s1FNiMbTLGwGWDa182s5PNkEMpdM0gMNM9BlH3qfUrm55t1bwAZ1hzIys8Ra5ssRFkSwRuFJLKvgyAAdmzO6HQebNmkSDXGqDEsfKXeh3mENOMk8awgLg1vhfTCE8LjKe8Axge7KyKWEcFxXJSsTelfKZMYPz0uCP8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TfM672aF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rjXFj7ao; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707780158; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y18cEADXMAHj9yL9ELXLWBM2/DUY8Csq6elKaw1ee7Q=; b=TfM672aFpL5RhC/Pb07QLYln4kCzK/pZU+JdWthBJbvud00XNlnkSyi28HPLOF4Vpc+pV4 /W6O8V/7tN2rML7MVrA1Gi8JlUA9KmZZfIV5vbUs5k7lP3Gsx6smPPD4N4eo/G186HPxSx IGKVrRgiyKZD1jNYUybCSvU65JJGPhHLoyS0Ro6Rua0Ocs7oBNNJV6NIS2qgvyGYBoANM8 Csb6PwUhk2BigS7YKy4Ilz4Y83S0KFzccay+r57vUvH+Fcr4sdDwKkyLpWem/aHTX1dxfT sOnZTOcQ8C7Cty3yH04XqhK33KfoF4KYRioCNSmdt11Bi157kpSTk7vGkZu9Jg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707780158; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y18cEADXMAHj9yL9ELXLWBM2/DUY8Csq6elKaw1ee7Q=; b=rjXFj7aoKHJfWSCXJ+faTMMPR78P2uqLlUXoXNGvBr3pi+AFvmb3mF5Y/HpvYzpfoINZR4 pIMUQn4kRHGuQBBQ== To: John Stultz , Joseph Beckenbach Cc: "linux-kernel@vger.kernel.org" Subject: Re: Setting real-time clock below monotonic clock In-Reply-To: References: Date: Tue, 13 Feb 2024 00:22:38 +0100 Message-ID: <87wmr9i7y9.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Jan 31 2024 at 11:12, John Stultz wrote: > On Wed, Jan 31, 2024 at 10:48=E2=80=AFAM Joseph Beckenbach > wrote: >> >> We have observed that we are not able to set the realtime clock=E2=80=99s >> time value below the monotonic clock=E2=80=99s time value in the Linux >> kernel. >> > > Indeed. That behavior was intentional. It's actually required as a CLOCK_REALTIME value before CLOCK_MONOTONIC would cause the offset to be negative which would result in a myriad of issues all over the timekeeping and timer code. Those could be solved but the price for it would be not worth it as it pretty much slows down every fast path. >> We have a situation where we will try to set the realtime clock time >> to a very low value (close to January 1, 1970) and below the >> monotonic clock value. In this situation, it does not matter what the >> date is, but we need the time to be synchronized across multiple >> devices (using generalized Precision Time Protocol or gPTP) for our >> application. It=E2=80=99s possible this synchronized time might be a low >> value (close to 1970) because the gPTP master starts its time from >> January 1, 1970 when it is booted, and when this gPTP master is >> booted after the gPTP slave, the master=E2=80=99s time is larger than the >> slave=E2=80=99s monotonic clock (which also starts from 0 when it is >> booted). When the slave tries to adjust its clock to match the >> master, we get an error. > > I appreciate there may be many constraints here, but it feels like the > device you're trying to sync to, reporting its time as close to Jan 1 > 1970 is misconfigured. That's a known issue for quite some time and has been reported before. Those systems use a non-standard clock master which itself is not synchronized to CLOCK_TAI. As the default startup time (if no RTC is available) is Jan. 1st 1970 this is expected in case that the master starts after the slaves. > So I'm not sure it's reasonable to expect the kernel to support that > case. I don't think it is. > Is there some different perspective I'm missing, though? Other than naive assumptions about how timekeeping works, no. >> Currently, we are planning to use a workaround where we keep track of >> a known offset between the =E2=80=9Csynchronized=E2=80=9D time which is = 1970 and the >> =E2=80=9Creal time=E2=80=9D such as 2024. Since the time only jumps once= at the >> beginning of sync and should not change by more than a second >> afterwards, we think this will work for now. What's wrong with having a reasonable synchronized time on the clock master to begin with? If a slave starts up before the master then it has to be able to deal with an initial time jump nd it does absolutely not matter in which direction this time jump goes, no? Thanks, tglx