Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp837233pxu; Thu, 3 Dec 2020 14:03:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxChPHVBV4QM+YB+BGm8zAlh22Xjl5aZE0NFOHPiR/E+LeKuTs5LS99yzFU1M0FsTb1+yER X-Received: by 2002:a50:d6dc:: with SMTP id l28mr4710361edj.286.1607032989135; Thu, 03 Dec 2020 14:03:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607032989; cv=none; d=google.com; s=arc-20160816; b=M3rt+YyPDYuwEGn7LlsPRKmZ4OpOT/wEH4P9Ihnqt7cEVmFjLiwdLxbVE131wYrKH5 6QaDDBSQehi+w2xXmsX7SrNqS3OXoZW3VkjYvbb5F1F/CZSPQGjJ21wA1Wv9Cf+8lvmV 3o6V3qRBcdHWAVs/4TKuYKUZnx97/4IFiuq6Z+n6BBAi3c2G3Tfd4jLjD/mrrhzmEIYl mKrTKFHDMYVci1j38np3S7NJHMalSZrKtB9Of6ac2Z7CG/+jDSivG/4Ezps1z9qk0GEr fhF4JizA4MCx8LVTWAR0/JDk6S7W4rOIoUZhH7h7F4uuIKaIHu5s//m8WGr1DoEvEZGn sCRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eF1o9afv1p8ZMN2O6oout7kSk/Q2X015bGdwbPTXC2A=; b=HUQb2fqZwrEVvUVr5+GqM+Fb+X1nmzORI0oO1jJ0ot0N6qTtx6sR6N9n/wlqGcsBxb UbBnClz6yjzEHuKl1HNsHhFNXC7ejUJKq0+SNF9vnH8m14q4/UTtqe37CYH9EISu8E8R +pqmSCA11mittMWAmgI2Fbp0gCOHyvSdho2DVPhJrOOmpr6+4qe/odFfCg58xzjiwAV4 FSpNcCdGYOOE3sn17SkA6NYyYyqPcJsMuRAzoWngOutBZfwIOn18X6epRoA+YwOdYStr B3Ox4ig0rpH3/AmcIQRQahBRm4nWRptjE0B9Nkc18+753SGmt+s6jSYKkNYjdxXP8z/A oHoQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si1813301edv.458.2020.12.03.14.02.44; Thu, 03 Dec 2020 14:03:09 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729592AbgLCWBL (ORCPT + 99 others); Thu, 3 Dec 2020 17:01:11 -0500 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:50607 "EHLO relay2-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728177AbgLCWBL (ORCPT ); Thu, 3 Dec 2020 17:01:11 -0500 X-Originating-IP: 86.194.74.19 Received: from localhost (lfbn-lyo-1-997-19.w86-194.abo.wanadoo.fr [86.194.74.19]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 9CE9340007; Thu, 3 Dec 2020 22:00:27 +0000 (UTC) Date: Thu, 3 Dec 2020 23:00:27 +0100 From: Alexandre Belloni To: Thomas Gleixner Cc: Jason Gunthorpe , Miroslav Lichvar , linux-kernel@vger.kernel.org, John Stultz , Prarit Bhargava , Alessandro Zummo , linux-rtc@vger.kernel.org, Peter Zijlstra Subject: Re: [PATCH] rtc: adapt allowed RTC update error Message-ID: <20201203220027.GB74177@piout.net> References: <87mtywe2zu.fsf@nanos.tec.linutronix.de> <20201202162723.GJ5487@ziepe.ca> <87a6uwdnfn.fsf@nanos.tec.linutronix.de> <20201202205418.GN5487@ziepe.ca> <874kl3eu8p.fsf@nanos.tec.linutronix.de> <87zh2vd72z.fsf@nanos.tec.linutronix.de> <20201203021047.GG3544@piout.net> <87pn3qdhli.fsf@nanos.tec.linutronix.de> <20201203161622.GA1317829@ziepe.ca> <87zh2ubny2.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87zh2ubny2.fsf@nanos.tec.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/12/2020 22:05:09+0100, Thomas Gleixner wrote: > 2) I2C/SPI ... > > tsched t0 t1 t2 > transfer(newsec) RTC update (newsec) RTC increments seconds > > Lets assume that ttransfer = t1 - t0 is known. Note that ttransfer is one of the reason why setting set_offset_nsec from the RTC driver is not a good idea. The same RTC may be on busses with different rates and there is no way to know that. I think that was one of my objections at the time. ttransfer is not a function of the RTC model but rather of how it is integrated in the system. > > tinc is the same as above = t2 - t1 > > Again, lets assume that the event is accurate for now and ignore the fuzz > logic, i.e. tsched == t0 > > So tsched has to be ttot = t2 - t0 _before_ wallclock reaches t2 and > increments seconds. > I had a rough week and I'm probably not awake enough to follow completely but is that thinking correct? For the mc146818, you have t1 - t0 which is probably negligible and t2 - T& == 500 ms For most of the other RTCs, you have t1 - t0 is somewhat important, probably around 100 to 150?s and t2 - t1 is 1s. I would think that what is needed is tsched has to be t1-t0 before wallclock reaches t1. In that case t2 doesn't matter, it will always be 1s after t1. > In this case newsec = t1.tv_sec = (t0 + ttransfer).tv_sec > > So now the fuzz logic for this is: > > newtime = t0 + ttransfer; > > if (newtime.tv_nsec < FUZZ) > newsec = newtime.tv_sec; > else if (newtime.tv_nsec > NSEC_PER_SEC - FUZZ) > newsec = newtime.tv_sec + 1; > else > goto fail; > > Again the first condition handles the case where t1 >= tsched and the > second one where t1 < tsched. > > So now we have two options to fix this: > > 1) Use a negative sync_offset for devices which need #1 above > (rtc_cmos & similar) > > That requires setting tsched to t2 - abs(sync_offset) > > 2) Use always a positive sync_offset and a flag which tells > rtc_tv_nsec_ok() whether it needs to add or subtract. > > #1 is good enough. All it takes is a comment at the timer start code why > abs() is required. > > Let me hack that up along with the hrtimer muck. > > Thanks, > > tglx -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com