All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wake Liu" <wakel@google.com>
Cc: linux-rtc@vger.kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH RESEND] selftests: rtc: fix flaky date_read_loop test
Date: Tue, 29 Sep 2026 15:30:38 +0000	[thread overview]
Message-ID: <20260929153038.E0CF31F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929152212.2092062-1-wakel@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests: rtc: preemption race between ioctl and clock_gettime
- [Medium] selftests: rtc: CLOCK_MONOTONIC does not account for system suspend
--

commit 470d20b138e75cc7483b890fe5b4c4fbcf96a62c
Author: Wake Liu <wakel@google.com>

selftests: rtc: fix flaky date_read_loop test

This commit modifies the rtc.date_read_loop test to measure real elapsed time
between iterations using CLOCK_MONOTONIC. It then dynamically adjusts the
test assertion to make the test more resilient against OS scheduling delays.

> diff --git a/tools/testing/selftests/rtc/rtctest.c b/tools/testing/selftests/rtc/rtctest.c
> index 8047d9879039c..54eb5c255a452 100644
> --- a/tools/testing/selftests/rtc/rtctest.c
> +++ b/tools/testing/selftests/rtc/rtctest.c
[ ... ]
> @@ -126,25 +127,31 @@ TEST_F_TIMEOUT(rtc, date_read_loop, READ_LOOP_DURATION_SEC + 2) {
>  
>  	rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm);
>  	ASSERT_NE(-1, rc);
> +	clock_gettime(CLOCK_MONOTONIC, &prev_mono);

[Severity: Medium]
Does CLOCK_MONOTONIC adequately account for system suspend in this test?

Since CLOCK_MONOTONIC stops incrementing during suspend while the hardware
RTC continues ticking, if the system suspends during the sleep loop, could
the RTC advance significantly without delta_s reflecting it?

Would using CLOCK_BOOTTIME avoid this regression and correctly track elapsed
time across suspends?

>  	start_rtc_read = rtc_time_to_timestamp(&rtc_tm);
>  	prev_rtc_read = start_rtc_read;
>  
>  	do  {
>  		time_t rtc_read;
> +		time_t delta_s = 0;
>  
>  		rc = ioctl(self->fd, RTC_RD_TIME, &rtc_tm);
>  		ASSERT_NE(-1, rc);
> +		clock_gettime(CLOCK_MONOTONIC, &cur_mono);

[Severity: Medium]
Could a preemption between the ioctl() and clock_gettime() calls cause
spurious assertion failures?

If the thread is preempted immediately after ioctl(RTC_RD_TIME) in iteration
N, cur_mono will be delayed. When this delayed cur_mono is assigned to
prev_mono for iteration N+1, it artificially shrinks the measured delta_s for
the next iteration.

Could this make delta_s smaller than the actual elapsed RTC time, causing
the assertion below to fail?

>  
>  		rtc_read = rtc_time_to_timestamp(&rtc_tm);
> +		delta_s = cur_mono.tv_sec - prev_mono.tv_sec;
> +
>  		/* Time should not go backwards */
>  		ASSERT_LE(prev_rtc_read, rtc_read);
> -		/* Time should not increase more then 1s at a time */
> -		ASSERT_GE(prev_rtc_read + 1, rtc_read);
> +		/* Time should not increase more then elapsed time + 1s */
> +		ASSERT_GE(prev_rtc_read + delta_s + 1, rtc_read);
>  
>  		/* Sleep 11ms to avoid killing / overheating the RTC */
>  		nanosleep_with_retries(READ_LOOP_SLEEP_MS * 1000000);
>  
>  		prev_rtc_read = rtc_read;
> +		prev_mono = cur_mono;
>  		iter_count++;
>  	} while (prev_rtc_read <= start_rtc_read + READ_LOOP_DURATION_SEC);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260929152212.2092062-1-wakel@google.com?part=1

      reply	other threads:[~2026-09-29 15:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 15:22 [PATCH RESEND] selftests: rtc: fix flaky date_read_loop test Wake Liu
2026-09-29 15:30 ` sashiko-bot [this message]

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=20260929153038.E0CF31F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-rtc@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wakel@google.com \
    /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.