All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>, Bin Meng <bmeng.cn@gmail.com>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Marek Vasut <marex@denx.de>,
	Pavel Herrmann <morpheus.ibis@gmail.com>,
	U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [PATCH] dm: rtc: Avoid a race in the rtc_reset test
Date: Mon, 1 Aug 2022 16:58:22 +0200	[thread overview]
Message-ID: <07c414a0-d072-d75c-a418-464ea8dfb89f@gmx.de> (raw)
In-Reply-To: <CAPnjgZ3WBd57OGd-2FQUNAASsyMyZpmz_rBbD_oTCiRUHsm=Rw@mail.gmail.com>

On 8/1/22 15:59, Simon Glass wrote:
> Hi Heinrich,
>
> On Mon, 1 Aug 2022 at 02:11, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> On 7/31/22 20:27, Simon Glass wrote:
>>> Since resetting the RTC on sandbox causes it to read the base time from
>>> the system, we cannot rely on this being unchanged since it was last read.
>>> Allow for a one-second delay.
>>>
>>> Fixes: https://source.denx.de/u-boot/u-boot/-/issues/4
>>> Reported-by: Bin Meng <bmeng.cn@gmail.com>
>>> Reported-by: Tom Rini <trini@konsulko.com>
>>> Suggested-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>>    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_state *uts)
>>>        ut_assertok(dm_rtc_get(dev, &now));
>>>
>>>        ut_assertok(i2c_emul_find(dev, &emul));
>>> -     ut_assert(emul != NULL);
>>> +     ut_assertnonnull(emul);
>>
>> This is an unrelated change. It would be preferable to describe it in
>> the commit message.
>>
>>>
>>>        old_base_time = 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. Allow for
>>> +      * 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 = sandbox_i2c_rtc_get_set_base_time(emul, -1);
>>> -     ut_asserteq(old_base_time, base_time);
>>> +     ut_assert(base_time - old_base_time <= 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 <xypron.glpk@gmx.de>
>>
>>>
>>>        return 0;
>>>    }
>>
>
> Regards,
> Simon


  reply	other threads:[~2022-08-01 14:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-31 18:27 [PATCH] dm: rtc: Avoid a race in the rtc_reset test Simon Glass
2022-08-01  8:11 ` Heinrich Schuchardt
2022-08-01 13:59   ` Simon Glass
2022-08-01 14:58     ` Heinrich Schuchardt [this message]
2022-08-01 19:13       ` Simon Glass
2022-08-02  7:08         ` Rasmus Villemoes
2022-08-02 12:41           ` Simon Glass
2022-08-02 13:51         ` Heinrich Schuchardt
2022-08-02 14:01           ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07c414a0-d072-d75c-a418-464ea8dfb89f@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=bmeng.cn@gmail.com \
    --cc=marex@denx.de \
    --cc=morpheus.ibis@gmail.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.