Home | History | Annotate | Line # | Download | only in posix
time.c revision 1.1.1.2
      1  1.1.1.2  mrg /* Copyright (C) 2005-2013 Free Software Foundation, Inc.
      2      1.1  mrg    Contributed by Richard Henderson <rth (at) redhat.com>.
      3      1.1  mrg 
      4      1.1  mrg    This file is part of the GNU OpenMP Library (libgomp).
      5      1.1  mrg 
      6      1.1  mrg    Libgomp is free software; you can redistribute it and/or modify it
      7      1.1  mrg    under the terms of the GNU General Public License as published by
      8      1.1  mrg    the Free Software Foundation; either version 3, or (at your option)
      9      1.1  mrg    any later version.
     10      1.1  mrg 
     11      1.1  mrg    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
     12      1.1  mrg    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     13      1.1  mrg    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     14      1.1  mrg    more details.
     15      1.1  mrg 
     16      1.1  mrg    Under Section 7 of GPL version 3, you are granted additional
     17      1.1  mrg    permissions described in the GCC Runtime Library Exception, version
     18      1.1  mrg    3.1, as published by the Free Software Foundation.
     19      1.1  mrg 
     20      1.1  mrg    You should have received a copy of the GNU General Public License and
     21      1.1  mrg    a copy of the GCC Runtime Library Exception along with this program;
     22      1.1  mrg    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23      1.1  mrg    <http://www.gnu.org/licenses/>.  */
     24      1.1  mrg 
     25      1.1  mrg /* This file contains system specific timer routines.  It is expected that
     26      1.1  mrg    a system may well want to write special versions of each of these.
     27      1.1  mrg 
     28      1.1  mrg    The following implementation uses the most simple POSIX routines.
     29      1.1  mrg    If present, POSIX 4 clocks should be used instead.  */
     30      1.1  mrg 
     31      1.1  mrg #include "libgomp.h"
     32      1.1  mrg #include <unistd.h>
     33      1.1  mrg #if TIME_WITH_SYS_TIME
     34      1.1  mrg # include <sys/time.h>
     35      1.1  mrg # include <time.h>
     36      1.1  mrg #else
     37      1.1  mrg # if HAVE_SYS_TIME_H
     38      1.1  mrg #  include <sys/time.h>
     39      1.1  mrg # else
     40      1.1  mrg #  include <time.h>
     41      1.1  mrg # endif
     42      1.1  mrg #endif
     43      1.1  mrg 
     44      1.1  mrg 
     45      1.1  mrg double
     46      1.1  mrg omp_get_wtime (void)
     47      1.1  mrg {
     48      1.1  mrg #ifdef HAVE_CLOCK_GETTIME
     49      1.1  mrg   struct timespec ts;
     50      1.1  mrg # ifdef CLOCK_MONOTONIC
     51      1.1  mrg   if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0)
     52      1.1  mrg # endif
     53      1.1  mrg     clock_gettime (CLOCK_REALTIME, &ts);
     54      1.1  mrg   return ts.tv_sec + ts.tv_nsec / 1e9;
     55      1.1  mrg #else
     56      1.1  mrg   struct timeval tv;
     57      1.1  mrg   gettimeofday (&tv, NULL);
     58      1.1  mrg   return tv.tv_sec + tv.tv_usec / 1e6;
     59      1.1  mrg #endif
     60      1.1  mrg }
     61      1.1  mrg 
     62      1.1  mrg double
     63      1.1  mrg omp_get_wtick (void)
     64      1.1  mrg {
     65      1.1  mrg #ifdef HAVE_CLOCK_GETTIME
     66      1.1  mrg   struct timespec ts;
     67      1.1  mrg # ifdef CLOCK_MONOTONIC
     68      1.1  mrg   if (clock_getres (CLOCK_MONOTONIC, &ts) < 0)
     69      1.1  mrg # endif
     70      1.1  mrg     clock_getres (CLOCK_REALTIME, &ts);
     71      1.1  mrg   return ts.tv_sec + ts.tv_nsec / 1e9;
     72      1.1  mrg #else
     73      1.1  mrg   return 1.0 / sysconf(_SC_CLK_TCK);
     74      1.1  mrg #endif
     75      1.1  mrg }
     76      1.1  mrg 
     77      1.1  mrg ialias (omp_get_wtime)
     78      1.1  mrg ialias (omp_get_wtick)
     79