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 F2482C00144 for ; Mon, 1 Aug 2022 14:58:37 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B439484413; Mon, 1 Aug 2022 16:58:35 +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="LGV/G5il"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 81348844A4; Mon, 1 Aug 2022 16:58:33 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (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 CAEC183F9A for ; Mon, 1 Aug 2022 16:58:30 +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=1659365907; bh=0CrPcD8XurIp4nCgcdV8ZluntoNsO3MVLXutqPKRe5Y=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=LGV/G5ilrYBs79kojVXpnVK6nK/LvCfd1fkJNYR7JP9c/uER/NDypMYqs8OpQCaxK 0bxpwFEnouh6z+RMrG2JnA18yFg1pc73daVVCjTeQytV2Tu7EYwDoNxhHsDXwWiFKK LjY+30PsvqIZBUNVfZT6MSBUfz8k/lWcDKT2Gz5g= 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 1MMXQ5-1nywM82ycp-00Jdg0; Mon, 01 Aug 2022 16:58:27 +0200 Message-ID: <07c414a0-d072-d75c-a418-464ea8dfb89f@gmx.de> Date: Mon, 1 Aug 2022 16:58:22 +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] dm: rtc: Avoid a race in the rtc_reset test To: Simon Glass Cc: Tom Rini , Bin Meng , Rasmus Villemoes , Marek Vasut , Pavel Herrmann , U-Boot Mailing List References: <20220731182707.921722-1-sjg@chromium.org> <82a1f909-7855-e8f8-a0dd-5e065fa3aa76@gmx.de> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Ht3vLBA2SweH9KdbpipSDsIKYnkciI1VMMUM0tVCGMDhBll98Gj qqH8HkR+rUfOnQkK2+qNhf8b2naOgbvkaJxeMdnCfAjdm1cCjtG0Sfe5tNICTvWbJZd3u8i uv10q8j1QUHfCxRW+ntQxNjrbVKGp0DmeN2dPY9FiTtK95BrF2KWrOPyNBjC7H9UoJnQ4pZ qIUQB5UUJdglLIDSC1uEQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:xJgAI1sdjUo=:Rftt5+DSMEXw8dJ72hvP7i im3Q3eYhCshLkPivR5E68kqfpOeBqJXiJ2C0fJeVg/JuUk7Xvn1uRJyoVTgJy0/vngHtV5EqI Qwb7YqaC23g88n9V703aAudWcDG8ZIRW/+lz5Kx+NLHJ7Z/nVHAQfk7n4FBsOoqqdidNxzPrV Sz6IRo7jVT7AMfZ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ussion 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:59, Simon Glass wrote: > Hi Heinrich, > > On Mon, 1 Aug 2022 at 02:11, Heinrich Schuchardt wr= ote: >> >> On 7/31/22 20:27, Simon Glass wrote: >>> Since resetting the RTC on sandbox causes it to read the base time fro= m >>> the system, we cannot rely on this being unchanged since it was last r= ead. >>> Allow for a one-second delay. >>> >>> Fixes: https://source.denx.de/u-boot/u-boot/-/issues/4 >>> Reported-by: Bin Meng >>> Reported-by: Tom Rini >>> Suggested-by: Rasmus Villemoes >>> Signed-off-by: Simon Glass >>> --- >>> >>> test/dm/rtc.c | 11 ++++++++--- >>> 1 file changed, 8 insertions(+), 3 deletions(-) >>> >>> diff --git a/test/dm/rtc.c b/test/dm/rtc.c >>> index c7f9f8f0ce7..403bf5c640a 100644 >>> --- a/test/dm/rtc.c >>> +++ b/test/dm/rtc.c >>> @@ -245,16 +245,21 @@ static int dm_test_rtc_reset(struct unit_test_st= ate *uts) >>> ut_assertok(dm_rtc_get(dev, &now)); >>> >>> ut_assertok(i2c_emul_find(dev, &emul)); >>> - ut_assert(emul !=3D NULL); >>> + ut_assertnonnull(emul); >> >> This is an unrelated change. It would be preferable to describe it in >> the commit message. >> >>> >>> 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 he base time back to normal */ >>> + /* >>> + * Resetting the RTC should put the base time back to normal. Al= low for >>> + * a one-second adjustment in case the time flips over while thi= s >>> + * test process is pre-empted, since reset_time() in i2c_rtc_emu= l.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_asserteq(old_base_time, base_time); >>> + ut_assert(base_time - old_base_time <=3D 1); >> >> If the operating system uses daylight saving time, this may still fail >> (very rarely). >> >> How about using gmtime() instead of localtime()? But that would be a >> separate patch. > > I'm not sure how to do this, as U-Boot expects local time. Of course > we could enhance the rtc API to support both (and use gmtime for the What makes you think that U-Boot expects local time? U-Boot has no notion of time zones. Linux systems tend to use UTC on the RTC. Why should sandbox_defconfig deviate? $ sudo hwclock --show -v hwclock from util-linux 2.38 System Time: 1659365754.792540 Trying to open: /dev/rtc0 Using the rtc interface to the clock. Assuming hardware clock is kept in UTC time. If you dual boot into Windows, you should better adjust Windows to use UTC= . Best regards Heinrich > test). > > I've got an idea how to deal with daylight savings, and an alternative > approach for this patch, so will send a series. > >> >> Reviewed-by: Heinrich Schuchardt >> >>> >>> return 0; >>> } >> > > Regards, > Simon