From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 02D24393A416 for ; Wed, 4 Aug 2021 09:45:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 02D24393A416 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628070302; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=T8BlaRMp9m6ol9xNMR5Uk/T2R4zgoSxMzLqztE2NOXo=; b=fh/rk+5PVyAaICZ1weRaQpdhoGUHhbROUsqLdc+JX4KMleYGLXq/QyLynQD20cex52KrP6 Jcs8t5fCiK+Y8oZEmG975Kn7WBSuL53GICXBuY+rVPhFZG2JBDyM0/lqJBRETMvh8xaM7F DMQ5WvF1/D5F4D0lmlVUsnKTKEwClhs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-R_Q54al-PaSsD5iLErXnAA-1; Wed, 04 Aug 2021 05:45:01 -0400 X-MC-Unique: R_Q54al-PaSsD5iLErXnAA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9B1994DDF; Wed, 4 Aug 2021 09:44:59 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-112-6.ams2.redhat.com [10.36.112.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE4D05C1B4; Wed, 4 Aug 2021 09:44:59 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 328E6A80D5F; Wed, 4 Aug 2021 11:44:58 +0200 (CEST) Date: Wed, 4 Aug 2021 11:44:58 +0200 From: Corinna Vinschen To: Christoph Muellner Cc: newlib@sourceware.org, Christoph Muellner , Kito Cheng Subject: Re: [PATCH] RISC-V: Reliably initialize t0 in _times() Message-ID: Reply-To: newlib@sourceware.org Mail-Followup-To: Christoph Muellner , newlib@sourceware.org, Christoph Muellner , Kito Cheng References: <20210802164616.4099311-1-cmuellner@gcc.gnu.org> MIME-Version: 1.0 In-Reply-To: <20210802164616.4099311-1-cmuellner@gcc.gnu.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=vinschen@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Aug 2021 09:45:04 -0000 On Aug 2 18:46, Christoph Muellner wrote: > From: Christoph Muellner > > 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 > --- > libgloss/riscv/sys_times.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) Pushed. Thanks, Corinna