public inbox for ecos-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data
@ 2012-05-31 17:16 bugzilla-daemon
  2012-06-01  7:53 ` [Bug 1001603] " bugzilla-daemon
  0 siblings, 1 reply; 2+ messages in thread
From: bugzilla-daemon @ 2012-05-31 17:16 UTC (permalink / raw)
  To: ecos-bugs

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

           Summary: LPC2XXX/17XX HW RTC driver can report wrong time/date
                    data
           Product: eCos
           Version: CVS
          Platform: Other (please specify)
        OS/Version: Cortex-M
            Status: UNCONFIRMED
          Severity: normal
          Priority: low
         Component: Wallclock
        AssignedTo: unassigned@bugs.ecos.sourceware.org
        ReportedBy: bernard.fouche@kuantic.com
                CC: ecos-bugs@ecos.sourceware.org
             Class: Advice Request


I'm looking at the HW RTC driver for LPC2XXX/LP17XX and I see this:

struct time {
  volatile cyg_uint32 sec;
  volatile cyg_uint32 min;
  volatile cyg_uint32 hour;
  volatile cyg_uint32 dom;
  volatile cyg_uint32 dow;
  volatile cyg_uint32 doy;
  volatile cyg_uint32 month;
  volatile cyg_uint32 year;
};

struct rtcdev {
  volatile cyg_uint32 ilr;
  volatile cyg_uint32 ctc;
  volatile cyg_uint32 ccr;
  volatile cyg_uint32 ciir;
  volatile cyg_uint32 amr;
  volatile cyg_uint32 ctime[3];
  struct time time;
  cyg_uint32 dummy[8];
  struct time alarm;
#ifndef CYGHWR_HAL_LPC_RTC_32768HZ
  volatile cyg_uint32 preint;
  volatile cyg_uint32 prefrac;
#endif
};

static struct rtcdev * const rtc =
  (struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE;
...[snip]...

cyg_uint32
Cyg_WallClock::get_hw_seconds(void)
{
  return _simple_mktime(rtc->time.year,
                        rtc->time.month,
                        rtc->time.dom,
                        rtc->time.hour,
                        rtc->time.min,
                        rtc->time.sec);
}

The problem is:

- time data is spread in different HW registers that can't be read in a single
shot by the MCU.
- the code do not consider the case when unfortunately the RTC will change of
second exactly between different register reads.

For instance get_hw_seconds() is called at 23:59:59, a few ns before the RTC is
about to move to 00:00:00: the function can return 23:00:59, 00:59:00, 
anything is possible according to the way the compiler orders the processing of
the arguments before calling _simple_mktime() (the same for the date).

The solution is to read the whole set of registers twice: if they don't have
the same value, then read them again. If there are similar, then report the
result since it will be coherent.

  Bernard

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug 1001603] LPC2XXX/17XX HW RTC driver can report wrong time/date data
  2012-05-31 17:16 [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data bugzilla-daemon
@ 2012-06-01  7:53 ` bugzilla-daemon
  0 siblings, 0 replies; 2+ messages in thread
From: bugzilla-daemon @ 2012-06-01  7:53 UTC (permalink / raw)
  To: ecos-bugs

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

--- Comment #1 from Bernard Fouché <bernard.fouche@kuantic.com> 2012-06-01 08:53:23 BST ---
Created an attachment (id=1780)
 --> (http://bugs.ecos.sourceware.org/attachment.cgi?id=1780)
Fix race condition in get_hw_seconds()

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
>From ecos-bugs-return-9556-listarch-ecos-bugs=sources.redhat.com@sourceware.org Fri Jun 01 07:53:49 2012
Return-Path: <ecos-bugs-return-9556-listarch-ecos-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-ecos-bugs@sources.redhat.com
Received: (qmail 3186 invoked by alias); 1 Jun 2012 07:53:47 -0000
Received: (qmail 3177 invoked by uid 22791); 1 Jun 2012 07:53:45 -0000
X-SWARE-Spam-Status: No, hits=-2.8 required=5.0
	tests=AWL,BAYES_00,KHOP_THREADED,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197)
    by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 07:53:32 +0000
Received: by mail.ecoscentric.com (Postfix, from userid 48)
	id 7ECEB2F78001; Fri,  1 Jun 2012 08:53:31 +0100 (BST)
X-Original-To: unassigned@bugs.ecos.sourceware.org
Delivered-To: unassigned@bugs.ecos.sourceware.org
From: bugzilla-daemon@bugs.ecos.sourceware.org
To: unassigned@bugs.ecos.sourceware.org
Subject: [Bug 1001603] LPC2XXX/17XX HW RTC driver can report wrong time/date
 data
X-Bugzilla-Reason: AssignedTo
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: eCos
X-Bugzilla-Component: Wallclock
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: bernard.fouche@kuantic.com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: low
X-Bugzilla-Assigned-To: unassigned@bugs.ecos.sourceware.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields:
In-Reply-To: <bug-1001603-777@http.bugs.ecos.sourceware.org/>
References: <bug-1001603-777@http.bugs.ecos.sourceware.org/>
X-Bugzilla-URL: http://bugs.ecos.sourceware.org/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Date: Fri, 01 Jun 2012 07:53:00 -0000
Message-Id: <20120601075327.EA4362F78001@mail.ecoscentric.com>
Mailing-List: contact ecos-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <ecos-bugs.sourceware.org>
List-Subscribe: <mailto:ecos-bugs-subscribe@sourceware.org>
List-Post: <mailto:ecos-bugs@sourceware.org>
List-Help: <mailto:ecos-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: ecos-bugs-owner@sourceware.org
Delivered-To: mailing list ecos-bugs@sourceware.org
X-SW-Source: 2012/txt/msg00985.txt.bz2
Content-length: 536

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

--- Comment #1 from Bernard Fouché <bernard.fouche@kuantic.com> 2012-06-01 08:53:23 BST ---
Created an attachment (id=1780)
 --> (http://bugs.ecos.sourceware.org/attachment.cgi?id=1780)
Fix race condition in get_hw_seconds()

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
>From ecos-bugs-return-9558-listarch-ecos-bugs=sources.redhat.com@sourceware.org Fri Jun 01 07:56:09 2012
Return-Path: <ecos-bugs-return-9558-listarch-ecos-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-ecos-bugs@sources.redhat.com
Received: (qmail 4263 invoked by alias); 1 Jun 2012 07:56:07 -0000
Received: (qmail 4252 invoked by uid 22791); 1 Jun 2012 07:56:07 -0000
X-SWARE-Spam-Status: No, hits=-2.7 required=5.0
	tests=AWL,BAYES_00,KHOP_THREADED
X-Spam-Check-By: sourceware.org
Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197)
    by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 07:55:54 +0000
Received: from localhost (hagrid.ecoscentric.com [127.0.0.1])
	by mail.ecoscentric.com (Postfix) with ESMTP id 9363B2F78001
	for <ecos-bugs@ecos.sourceware.org>; Fri,  1 Jun 2012 08:55:53 +0100 (BST)
Received: from mail.ecoscentric.com ([127.0.0.1])
	by localhost (hagrid.ecoscentric.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ITEAfgGrMW0k; Fri,  1 Jun 2012 08:55:52 +0100 (BST)
From: bugzilla-daemon@bugs.ecos.sourceware.org
To: ecos-bugs@ecos.sourceware.org
Subject: [Bug 1001603] LPC2XXX/17XX HW RTC driver can report wrong time/date
 data
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: eCos
X-Bugzilla-Component: Wallclock
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: bernard.fouche@kuantic.com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: low
X-Bugzilla-Assigned-To: unassigned@bugs.ecos.sourceware.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields:
In-Reply-To: <bug-1001603-13@http.bugs.ecos.sourceware.org/>
References: <bug-1001603-13@http.bugs.ecos.sourceware.org/>
X-Bugzilla-URL: http://bugs.ecos.sourceware.org/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Date: Fri, 01 Jun 2012 07:56:00 -0000
Message-Id: <20120601075552.79A202F78005@mail.ecoscentric.com>
Mailing-List: contact ecos-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <ecos-bugs.sourceware.org>
List-Subscribe: <mailto:ecos-bugs-subscribe@sourceware.org>
List-Post: <mailto:ecos-bugs@sourceware.org>
List-Help: <mailto:ecos-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: ecos-bugs-owner@sourceware.org
Delivered-To: mailing list ecos-bugs@sourceware.org
X-SW-Source: 2012/txt/msg00987.txt.bz2
Content-length: 797

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

--- Comment #2 from Bernard Fouché <bernard.fouche@kuantic.com> 2012-06-01 08:55:50 BST ---
An improvement would be to store in the 'General Purpose Registers' (the
'dummy' item of struct RTC), a string like 'ECOS' (fits in a single 4 bytes
register): if this string isn't found at init, then clears the set of
registers. If the string is found, considers the registers give correct time. I
do this at application level, it could be moved here and this feature added as
a CDL option.

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
>From ecos-bugs-return-9559-listarch-ecos-bugs=sources.redhat.com@sourceware.org Fri Jun 01 07:56:21 2012
Return-Path: <ecos-bugs-return-9559-listarch-ecos-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-ecos-bugs@sources.redhat.com
Received: (qmail 4381 invoked by alias); 1 Jun 2012 07:56:20 -0000
Received: (qmail 4373 invoked by uid 22791); 1 Jun 2012 07:56:19 -0000
X-SWARE-Spam-Status: No, hits=-2.8 required=5.0
	tests=AWL,BAYES_00,KHOP_THREADED,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197)
    by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 07:55:55 +0000
Received: by mail.ecoscentric.com (Postfix, from userid 48)
	id 4FD9E2F78005; Fri,  1 Jun 2012 08:55:53 +0100 (BST)
X-Original-To: unassigned@bugs.ecos.sourceware.org
Delivered-To: unassigned@bugs.ecos.sourceware.org
From: bugzilla-daemon@bugs.ecos.sourceware.org
To: unassigned@bugs.ecos.sourceware.org
Subject: [Bug 1001603] LPC2XXX/17XX HW RTC driver can report wrong time/date
 data
X-Bugzilla-Reason: AssignedTo
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: eCos
X-Bugzilla-Component: Wallclock
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: bernard.fouche@kuantic.com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: low
X-Bugzilla-Assigned-To: unassigned@bugs.ecos.sourceware.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields:
In-Reply-To: <bug-1001603-777@http.bugs.ecos.sourceware.org/>
References: <bug-1001603-777@http.bugs.ecos.sourceware.org/>
X-Bugzilla-URL: http://bugs.ecos.sourceware.org/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Date: Fri, 01 Jun 2012 07:56:00 -0000
Message-Id: <20120601075552.5C0FF2F78001@mail.ecoscentric.com>
Mailing-List: contact ecos-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <ecos-bugs.sourceware.org>
List-Subscribe: <mailto:ecos-bugs-subscribe@sourceware.org>
List-Post: <mailto:ecos-bugs@sourceware.org>
List-Help: <mailto:ecos-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: ecos-bugs-owner@sourceware.org
Delivered-To: mailing list ecos-bugs@sourceware.org
X-SW-Source: 2012/txt/msg00988.txt.bz2
Content-length: 795

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

--- Comment #2 from Bernard Fouché <bernard.fouche@kuantic.com> 2012-06-01 08:55:50 BST ---
An improvement would be to store in the 'General Purpose Registers' (the
'dummy' item of struct RTC), a string like 'ECOS' (fits in a single 4 bytes
register): if this string isn't found at init, then clears the set of
registers. If the string is found, considers the registers give correct time. I
do this at application level, it could be moved here and this feature added as
a CDL option.

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
>From ecos-bugs-return-9560-listarch-ecos-bugs=sources.redhat.com@sourceware.org Fri Jun 01 08:57:04 2012
Return-Path: <ecos-bugs-return-9560-listarch-ecos-bugs=sources.redhat.com@sourceware.org>
Delivered-To: listarch-ecos-bugs@sources.redhat.com
Received: (qmail 23808 invoked by alias); 1 Jun 2012 08:57:03 -0000
Received: (qmail 23796 invoked by uid 22791); 1 Jun 2012 08:57:02 -0000
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0
	tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197)
    by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 08:56:37 +0000
Received: from localhost (hagrid.ecoscentric.com [127.0.0.1])
	by mail.ecoscentric.com (Postfix) with ESMTP id A5A752F78009
	for <ecos-bugs@ecos.sourceware.org>; Fri,  1 Jun 2012 09:56:36 +0100 (BST)
Received: from mail.ecoscentric.com ([127.0.0.1])
	by localhost (hagrid.ecoscentric.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id lgU4NVViDyJ9; Fri,  1 Jun 2012 09:56:31 +0100 (BST)
From: bugzilla-daemon@bugs.ecos.sourceware.org
To: ecos-bugs@ecos.sourceware.org
Subject: [Bug 1001605] New: much faster and simpler(!) replacement for
 _simple_mktime() (in wallclock.inl)
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: eCos
X-Bugzilla-Component: Wallclock
X-Bugzilla-Keywords:
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: bernard.fouche@kuantic.com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: low
X-Bugzilla-Assigned-To: unassigned@bugs.ecos.sourceware.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields:
Message-ID: <bug-1001605-13@http.bugs.ecos.sourceware.org/>
X-Bugzilla-URL: http://bugs.ecos.sourceware.org/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
Date: Fri, 01 Jun 2012 08:57:00 -0000
Mailing-List: contact ecos-bugs-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <ecos-bugs.sourceware.org>
List-Subscribe: <mailto:ecos-bugs-subscribe@sourceware.org>
List-Post: <mailto:ecos-bugs@sourceware.org>
List-Help: <mailto:ecos-bugs-help@sourceware.org>, <http://sourceware.org/lists.html#faqs>
Sender: ecos-bugs-owner@sourceware.org
Delivered-To: mailing list ecos-bugs@sourceware.org
X-SW-Source: 2012/txt/msg00989.txt.bz2
Content-length: 2368

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id\x1001605

           Summary: much faster and simpler(!) replacement for
                    _simple_mktime() (in wallclock.inl)
           Product: eCos
           Version: CVS
          Platform: All
        OS/Version: All
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: low
         Component: Wallclock
        AssignedTo: unassigned@bugs.ecos.sourceware.org
        ReportedBy: bernard.fouche@kuantic.com
                CC: ecos-bugs@ecos.sourceware.org
             Class: Advice Request


If _simple_mktime() is called for Dec 31st 2012, it will do:

  42 (2012-1970) additions of a value requiring 3 modulo's
+ 12 additions (of the month)
+ 1 substraction
+ 3 multiplications and 3 additions

That is a total of (42*3)+12+1+(3+3)\x145 operations.

The proposed change makes _simple_mktime() to use:

- 1 substraction, 1 multiplication, 1 addition and 1 substraction to calculate
a 'base' second value.
- 1 comparison that can lead to 1 substraction
- 1 addition, 1 substraction, 1 division
- 2 substractions, 1 division
- 1 addition, 1 substraction, 1 division
- 1 addition
- 1 substraction
- 1 multiplication
- 1 addition
- 1 multiplication
- 1 addition
- 1 multiplication
- 1 addition

That is a total of:

(1+1+1+1)+(1+1)+(1+1+1)+(2+1)+(1+1+1)+1+1+1+1+1+1+1+1# operations.

This count is nearly always the same whatever the time/date processed, which is
not the case for the original code, which takes 3 modulo's more per invocation
each year, since this function is called by all RTC HW drivers.

I don't think eCos runs on MCU/CPU without HW division, but in such a case this
would mean that 2/3rd of the modulo's in the current code are also done in
software (for 100 and 400 values).

I attach an example of the proposed replacement code that compiles under Linux
and uses brute force to check all possible values: it takes about 6 minutes to
run in a recent computer.

If someone can review and accept this small code change, I can make a patch vs
ecos/packages/io/wallclock/current/include/wallclock/wallclock.inl

  Bernard

--
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-01  7:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-31 17:16 [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data bugzilla-daemon
2012-06-01  7:53 ` [Bug 1001603] " bugzilla-daemon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).