Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6495777yba; Wed, 1 May 2019 13:32:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzF4M3vhteR37LBK1fqzLMJjh+dIhMP/HLEPN4dtDvHuCWsrtDgclj75Vx+ra9UqqYP0r9x X-Received: by 2002:a62:46c7:: with SMTP id o68mr20748920pfi.54.1556742728092; Wed, 01 May 2019 13:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556742728; cv=none; d=google.com; s=arc-20160816; b=yYmO7msYBxrPAyZ0gws9OuGOzLznJCBN0AJYTIN8V5lGp/APW48tMd9FEZZ9FMOYLz ozv1OS3NuUP5x5lRwP9z15G/bUTRYPfqRE+sg0ivAwtzyO0pceMHrRGR2UCcHiGkfTzr zcQ4eLzmqBxxV1HTwDv1JGTnKsIsi4iftVotkqITRBPHC/MRbXWRCp+xH43g3EobDK6T FSEYk90ecSLgLNwQ9BNVn3C2euPAHUsYCf0gjgAzo9nW6GzdMOLFiNMhSw1I2tp0O/Md 7v8qa4AzA5+sxEVWq74PoYpLQH4R1nruA47m+SzzR7555A6SjDSv6PA8yJeOdvfVKABD 2Rog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=DUSg8q6pkLyf+61b8d95P80UxVVZi30wVab9yISBGFA=; b=B694A9u5S4B2Mnap0aRz42nvSMo4LtaDBS2naiQoYM9ecpQbU1MRRBzWynt8wXRTtV fRXhZ1nJygTzceItC5uTX4JkK1l2+29EauS/6EnHT/fSoo+iccOlkIEr0qvTDXxULdUy EJ78CU99un4KQNWsI7O/UKt5PvrY4UumeAD5gbANJ2QhCOP5kavtWevis0/gIMFOFHLg vKLxHqYfMGAIohB0jPqpyigyI1WrsiOuuYJ01Zoc2FBTk2vBu3Sqqd4L9XGEyojxYQKC BJgxmJjrFMg73VGbE9CtWRin7WFlgDDzQcWkuu4LHfkqT0A7rJPpQh4ptTje4zgPYv+D 1Y4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cj4si18774638plb.66.2019.05.01.13.31.53; Wed, 01 May 2019 13:32:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbfEAUae (ORCPT + 99 others); Wed, 1 May 2019 16:30:34 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:60931 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfEAUae (ORCPT ); Wed, 1 May 2019 16:30:34 -0400 Received: from localhost (lfbn-1-3034-80.w90-66.abo.wanadoo.fr [90.66.53.80]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id BE03B240008; Wed, 1 May 2019 20:30:23 +0000 (UTC) Date: Wed, 1 May 2019 22:30:23 +0200 From: Alexandre Belloni To: Trent Piepho Cc: "patrice.chotard@st.com" , "linux-rtc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH] rtc: st-lpc: remove unnecessary check Message-ID: <20190501203023.GL11339@piout.net> References: <20190430201834.12634-1-alexandre.belloni@bootlin.com> <1556663479.31309.36.camel@impinj.com> <20190501142513.GK11339@piout.net> <1556730703.31309.53.camel@impinj.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1556730703.31309.53.camel@impinj.com> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/05/2019 17:11:44+0000, Trent Piepho wrote: > > I can't believe you can possibly have more than one second between the > > check in the core and the check in the driver, it doesn't make much > > sense to check, even in the current state of the core. > > It's certainly possible to have multiple seconds pass. For an external > device over SPI or I2C, one has to wait for the bus to become free. > And on SPI that requires the kernel thread running the bus to be > scheduled. Just put in some real-time tasks and maybe a big transfer > to a flash chip and it could be a while before that happens. > > I don't think this device has that issue as I don't think it's > external. And ever for a device on an external bus, delays > 1 second > are unlikely. Possible, but unlikely. > > You can also get them when Linux is running under a hypervisor, i.e. a > Linux VM. But also something like an NMI and ACPI BIOS. If the Linux > guest is not scheduled to run for while anything that is supposed to be > based on real time, like the value returned by an RTC, will still > advance. It is possible that multiple seconds elapse from the guest > CPU executing one instruction to the next. > > But even ignoring that, does it require > 1 second to elapse. Can't it > happen when the clock ticks from one second to the next, which happens > effectively instantly? > > If the time from the check to the time when the alarm is set is 1 > microsecond, and the time this call to set the alarm is made is > randomly done and not synchronized to the RTC, then isn't there a 1 out > of 1 million chance (1 microsecond / 1 second), that the once per > second clock tick will hit our 1 us window? No, let's say you want Talarm == Tcurrent + 1, if the core check happens right before the next second, then you necessarily end up with Talarm == Tcurrent after the check. This means that you now have one second before the time read in st-lpc to avoid the alarm_secs -= now_secs; underflow. Obviously, in that case, you are likely to miss the alarm but this is as likely to happen with the check that is in the driver. This check doesn't provide anything but a false sense of security. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com