1 /* Copyright (C) 2005-2013 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU OpenMP Library (libgomp).
6 Libgomp is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 /* This file contains system specific timer routines. It is expected that
26 a system may well want to write special versions of each of these.
28 The following implementation uses the most simple POSIX routines.
29 If present, POSIX 4 clocks should be used instead. */
33 #if TIME_WITH_SYS_TIME
34 # include <sys/time.h>
38 # include <sys/time.h>
48 #ifdef HAVE_CLOCK_GETTIME
50 # ifdef CLOCK_MONOTONIC
51 if (clock_gettime (CLOCK_MONOTONIC
, &ts
) < 0)
53 clock_gettime (CLOCK_REALTIME
, &ts
);
54 return ts
.tv_sec
+ ts
.tv_nsec
/ 1e9
;
57 gettimeofday (&tv
, NULL
);
58 return tv
.tv_sec
+ tv
.tv_usec
/ 1e6
;
65 #ifdef HAVE_CLOCK_GETTIME
67 # ifdef CLOCK_MONOTONIC
68 if (clock_getres (CLOCK_MONOTONIC
, &ts
) < 0)
70 clock_getres (CLOCK_REALTIME
, &ts
);
71 return ts
.tv_sec
+ ts
.tv_nsec
/ 1e9
;
73 return 1.0 / sysconf(_SC_CLK_TCK
);
77 ialias (omp_get_wtime
)
78 ialias (omp_get_wtick
)