From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52EDEC00144 for ; Mon, 1 Aug 2022 15:00:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5DD5984413; Mon, 1 Aug 2022 17:00:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="CooT0PHP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 46B67844B4; Mon, 1 Aug 2022 17:00:19 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BDF2D83F9A for ; Mon, 1 Aug 2022 17:00:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659366015; bh=z3w+dLMz8Xqam7+l2hAZ5sMMtO8VsOrCMcT4kCFjtxk=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=CooT0PHPo0SA5BdATWY33WWuDB/GmeHlCdCI0/Kkxwx9239MM5gNZ9f/vHD61dDX7 9Q7K4aXA5Gc10Ki2itkjvjapzPbuUnLohw3b7mdIqtzjtz1+Hm4P8QQrDXPT7zSbnw zPW8sOwPHJwSRuaA5G7W9ZV7QLfXC8EIA8vKv3Dk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([62.143.94.109]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTiPv-1nsqjT3Hsj-00U3IC; Mon, 01 Aug 2022 17:00:14 +0200 Message-ID: <8dc1ec38-3ec9-fa7c-3b35-290fcbb86a85@gmx.de> Date: Mon, 1 Aug 2022 17:00:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.0 Subject: Re: [PATCH 5/5] dm: rtc: Try to handle the localtime() race Content-Language: en-US To: Simon Glass , U-Boot Mailing List Cc: Tom Rini , Marek Vasut , Pavel Herrmann References: <20220801135848.992449-1-sjg@chromium.org> <20220801135848.992449-6-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20220801135848.992449-6-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ocGokQg1RUvVb6HiXKlD487cRPkEZihVjEOa5kGKk2lZ3lwNjQu COHoe/GyvFS60AFHA67R1cK1NWdWLnlMuey1dqYTWlu+jBtE4Q36c21c+Z9GVxSZXWo75lR zoinGOOMzoiawlTViPx1W87WyhrtSyEEZRnf7vpfYn/1SY7EDIPHRIlrPaLtFxsgfnzHBoh M0oJvcCFaXtbe8V1V76+Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:QqRjJgomYsY=:nCsE7SUeBJkQOJgA11pvwG SyV+TrCxbFktfjrFt2YAJnAJyzrOGngwB1gisN/ob9Jwo25ZMr3OC1TMcUs+YvtNJ98om/QZT f4N6uBrtNBbtD5gEYo805nbxFNA1B3ssqcY88mHBOIiwkh3saJFMijn4I+Lqj6iPB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U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 8/1/22 15:58, Simon Glass wrote: > At present the sandbox timer uses localtime() which can jump around twic= e > a year when daylight-saving time changes. > > It would be tricky to make use of gmtime() since we still need to presen= t > the time in local time, as seems to be required by U-Boot's RTC interfac= e. > > The problem can only happen once, so use a loop to detect it and try > again. This should be sufficient to detect either a change in the 'secon= d' > value, or a daylight-saving change. We can assume that the latter also > incorporates a 'second' change, so there is no need to loop more than > twice. > > Signed-off-by: Simon Glass Linux systems tend to use UTC on the RTC. There is no reason for sandbox_defconfig to deviate. Please, avoid all this complication by reading the time with gmtime() instead of localtime(). Best regards Heinrich > --- > > test/dm/rtc.c | 32 +++++++++++++++++++------------- > 1 file changed, 19 insertions(+), 13 deletions(-) > > diff --git a/test/dm/rtc.c b/test/dm/rtc.c > index 50086ffcf36..bf97dbbd2f9 100644 > --- a/test/dm/rtc.c > +++ b/test/dm/rtc.c > @@ -252,6 +252,7 @@ static int dm_test_rtc_reset(struct unit_test_state = *uts) > struct rtc_time now; > struct udevice *dev, *emul; > long old_base_time, base_time; > + int i; > > ut_assertok(uclass_get_device(UCLASS_RTC, 0, &dev)); > ut_assertok(dm_rtc_get(dev, &now)); > @@ -259,19 +260,24 @@ static int dm_test_rtc_reset(struct unit_test_stat= e *uts) > ut_assertok(i2c_emul_find(dev, &emul)); > ut_assertnonnull(emul); > > - old_base_time =3D sandbox_i2c_rtc_get_set_base_time(emul, 0); > - > - ut_asserteq(0, sandbox_i2c_rtc_get_set_base_time(emul, -1)); > - > - /* > - * Resetting the RTC should put the base time back to normal. Allow fo= r > - * a one-second adjustment in case the time flips over while this > - * test process is pre-empted, since reset_time() in i2c_rtc_emul.c > - * reads the time from the OS. > - */ > - ut_assertok(dm_rtc_reset(dev)); > - base_time =3D sandbox_i2c_rtc_get_set_base_time(emul, -1); > - ut_assert(base_time - old_base_time <=3D 1); > + i =3D 0; > + do { > + old_base_time =3D sandbox_i2c_rtc_get_set_base_time(emul, 0); > + > + ut_asserteq(0, sandbox_i2c_rtc_get_set_base_time(emul, -1)); > + > + ut_assertok(dm_rtc_reset(dev)); > + base_time =3D sandbox_i2c_rtc_get_set_base_time(emul, -1); > + > + /* > + * Resetting the RTC should put the base time back to normal. > + * Allow for a one-timeadjustment in case the time flips over > + * while this test process is pre-empted (either by a second > + * or a daylight-saving change), since reset_time() in > + * i2c_rtc_emul.c reads the time from the OS. > + */ > + } while (++i < 2 && base_time !=3D old_base_time); > + ut_asserteq(old_base_time, base_time); > > return 0; > }