From: Corinna Vinschen <vinschen@redhat.com>
To: Christoph Muellner <cmuellner@gcc.gnu.org>
Cc: newlib@sourceware.org, Christoph Muellner <cmuellner@linux.com>,
Kito Cheng <kito.cheng@sifive.com>
Subject: Re: [PATCH] RISC-V: Reliably initialize t0 in _times()
Date: Wed, 4 Aug 2021 11:44:58 +0200 [thread overview]
Message-ID: <YQphmjM5bHcvM3O6@calimero.vinschen.de> (raw)
In-Reply-To: <20210802164616.4099311-1-cmuellner@gcc.gnu.org>
On Aug 2 18:46, Christoph Muellner wrote:
> From: Christoph Muellner <cmuellner@linux.com>
>
> The current implementation does not reliably initialize t0 once.
> Additionally the initialization requires two calls to _gettimeofday().
> Let's sacrifice a byte to keep the initialization status
> and reduce the maximum number of calls to _gettimeofday().
>
> This has caused issues in an application that invokes clock().
> The problematic situation is as follows:
>
> 1) The program calls clock() which calls _times().
> 2) _gettimeofday(&t0, 0) puts 0 in t0.tv_usec (because less than 1 us has
> elapsed since the beginning of time).
> 3) _gettimeofday(&t, 0) puts 1 in t.tv_usec (since now more than 1 us has
> elapsed since the beginning of time).
> 4) That call to clock() returns 1 (the value from step 3 minus the value in
> step 2).
> 5) The program does a second call to clock().
> 6) The code above still sees 0 in t0 so it tries to update t0 again and
> _gettimeofday(&t0, 0) puts 1 in t0.tv_usec.
> 7) The _gettimeofday(&t, 0) puts 1 in t.tv_usec (since less than 1us has
> elapsed since step 3).
> 8) clock() returns 0 (step 7 minus step 6) and indicates that time is
> moving backwards.
>
> Signed-off-by: Christoph Muellner <cmuellner@gcc.gnu.org>
> ---
> libgloss/riscv/sys_times.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
Pushed.
Thanks,
Corinna
prev parent reply other threads:[~2021-08-04 9:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-02 16:46 Christoph Muellner
2021-08-04 9:44 ` Corinna Vinschen [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=YQphmjM5bHcvM3O6@calimero.vinschen.de \
--to=vinschen@redhat.com \
--cc=cmuellner@gcc.gnu.org \
--cc=cmuellner@linux.com \
--cc=kito.cheng@sifive.com \
--cc=newlib@sourceware.org \
/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 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).