Re: [LTP] [PATCH 3/3] rtc02: loosen the compare precision with few seconds

Li Wang
2022-05-08T02:22:50Z

[-- Attachment #1.1: Type: text/plain, Size: 2089 bytes --]

On Thu, May 5, 2022 at 10:03 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> > + * To handle the normal and special situations:
> > + * 1#
> > + * set_tm: 2022-04-28 13:00:50
> > + * read_tm: 2022-04-28 13:00:50
> > + * 2#
> > + * set_tm: 2022-04-28 13:00:50
> > + * read_tm: 2022-04-28 13:00:51
> > + * 3#
> > + * set_tm: 2022-04-28 13:00:59
> > + * read_tm: 2022-04-28 13:01:00
> > + * 4#
> > + * set_tm: 2022-04-28 13:59:59
> > + * read_tm: 2022-04-28 14:00:00
> > + *
> > + * Note: as we have avoided testing around the zero
> > + * clock, so it's impossible to hit situation 5#
> > + * set_tm: 2022-04-28 23:59:59
> > + * read_tm: 2022-04-29 00:00:00
> > + */
> > +
> > + /* 1~3 */
> > + if (set_tm->tm_hour == read_tm->tm_hour) {
> > + if (set_tm->tm_min == read_tm->tm_min - 1)
> > + delta += 60;
> > + else if (set_tm->tm_min != read_tm->tm_min)
> > + return 1;
> > + }
> > +
> > + /* 4 */
> > + if ((set_tm->tm_hour == read_tm->tm_hour - 1) &&
> > + (set_tm->tm_min == read_tm->tm_min + 59))
> > + delta += 60;
> > + else if ((set_tm->tm_hour != read_tm->tm_hour))
> > + return 1;
> > +
> > + if (delta < 0 || delta > 3)
> > + return 1;
> > +
> > + return !((set_tm->tm_mday == read_tm->tm_mday)
> > && (set_tm->tm_mon == read_tm->tm_mon)
> > && (set_tm->tm_year == read_tm->tm_year));
>
> Wouldn't it be easier to convert both dates into a 64bit timestamp and
> compare the timestamps?
>

Yeah, this is a good thought. And we don't even need to convert all dates
because we have avoided the zero clock setting. IOW, just take the
hours/min/sec to be compared should be enough.
Update process:
patch1/3: drop this one until we find a good way to detect hardware
support.
patch2/3: pushed.
patch3/3: will send a V2.

--
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 3601 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]