This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v1.1][BZ #12515] Improve precision of clock function
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 21 May 2013 20:53:42 +0530
- Subject: [PATCH v1.1][BZ #12515] Improve precision of clock function
- References: <20130521145611 dot GM8927 at spoyarek dot pnq dot redhat dot com> <mvmfvxgpdn4 dot fsf at hawking dot suse dot de>
On Tue, May 21, 2013 at 05:15:59PM +0200, Andreas Schwab wrote:
> Siddhesh Poyarekar <siddhesh@redhat.com> writes:
>
> > + /* clock_gettime failed. This will only occur if CLOCK_PROCESS_CPUTIME_ID is
> > + * not supported by the kernel. Fall back to __times. */
>
> Style: no leading *.
>
Ugh, vim snuck that in when I wasn't looking. Here's the updated
version.
Siddhesh
[BZ #12515]
* sysdeps/unix/sysv/linux/clock.c (clock): Use result from
CLOCK_PROCESS_CPUTIME_ID clock if available.
diff --git a/sysdeps/unix/sysv/linux/clock.c b/sysdeps/unix/sysv/linux/clock.c
index 5268d33..3f6c547 100644
--- a/sysdeps/unix/sysv/linux/clock.c
+++ b/sysdeps/unix/sysv/linux/clock.c
@@ -23,6 +23,14 @@
clock_t
clock (void)
{
+ struct timespec ts;
+
+ if (__clock_gettime (CLOCK_REALTIME, &ts) == 0)
+ return (clock_t) ((ts.tv_nsec * CLOCKS_PER_SEC) / 1000000000
+ + ts.tv_sec * CLOCKS_PER_SEC);
+
+ /* clock_gettime failed. This will only occur if CLOCK_PROCESS_CPUTIME_ID is
+ not supported by the kernel. Fall back to __times. */
struct tms buf;
long clk_tck = __sysconf (_SC_CLK_TCK);