1169695Skan/* Copyright (C) 2005 Free Software Foundation, Inc. 2169695Skan Contributed by Richard Henderson <rth@redhat.com>. 3169695Skan 4169695Skan This file is part of the GNU OpenMP Library (libgomp). 5169695Skan 6169695Skan Libgomp is free software; you can redistribute it and/or modify it 7169695Skan under the terms of the GNU Lesser General Public License as published by 8169695Skan the Free Software Foundation; either version 2.1 of the License, or 9169695Skan (at your option) any later version. 10169695Skan 11169695Skan Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY 12169695Skan WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13169695Skan FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 14169695Skan more details. 15169695Skan 16169695Skan You should have received a copy of the GNU Lesser General Public License 17169695Skan along with libgomp; see the file COPYING.LIB. If not, write to the 18169695Skan Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19169695Skan MA 02110-1301, USA. */ 20169695Skan 21169695Skan/* As a special exception, if you link this library with other files, some 22169695Skan of which are compiled with GCC, to produce an executable, this library 23169695Skan does not by itself cause the resulting executable to be covered by the 24169695Skan GNU General Public License. This exception does not however invalidate 25169695Skan any other reasons why the executable file might be covered by the GNU 26169695Skan General Public License. */ 27169695Skan 28169695Skan/* This file contains system specific timer routines. It is expected that 29169695Skan a system may well want to write special versions of each of these. 30169695Skan 31169695Skan The following implementation uses the most simple POSIX routines. 32169695Skan If present, POSIX 4 clocks should be used instead. */ 33169695Skan 34169695Skan#include "libgomp.h" 35169695Skan#include <unistd.h> 36169695Skan#if TIME_WITH_SYS_TIME 37169695Skan# include <sys/time.h> 38169695Skan# include <time.h> 39169695Skan#else 40169695Skan# if HAVE_SYS_TIME_H 41169695Skan# include <sys/time.h> 42169695Skan# else 43169695Skan# include <time.h> 44169695Skan# endif 45169695Skan#endif 46169695Skan 47169695Skan 48169695Skandouble 49169695Skanomp_get_wtime (void) 50169695Skan{ 51169695Skan#ifdef HAVE_CLOCK_GETTIME 52169695Skan struct timespec ts; 53169695Skan# ifdef CLOCK_MONOTONIC 54169695Skan if (clock_gettime (CLOCK_MONOTONIC, &ts) < 0) 55169695Skan# endif 56169695Skan clock_gettime (CLOCK_REALTIME, &ts); 57169695Skan return ts.tv_sec + ts.tv_nsec / 1e9; 58169695Skan#else 59169695Skan struct timeval tv; 60169695Skan gettimeofday (&tv, NULL); 61169695Skan return tv.tv_sec + tv.tv_usec / 1e6; 62169695Skan#endif 63169695Skan} 64169695Skan 65169695Skandouble 66169695Skanomp_get_wtick (void) 67169695Skan{ 68169695Skan#ifdef HAVE_CLOCK_GETTIME 69169695Skan struct timespec ts; 70169695Skan# ifdef CLOCK_MONOTONIC 71169695Skan if (clock_getres (CLOCK_MONOTONIC, &ts) < 0) 72169695Skan# endif 73169695Skan clock_getres (CLOCK_REALTIME, &ts); 74169695Skan return ts.tv_sec + ts.tv_nsec / 1e9; 75169695Skan#else 76169695Skan return 1.0 / sysconf(_SC_CLK_TCK); 77169695Skan#endif 78169695Skan} 79169695Skan 80169695Skanialias (omp_get_wtime) 81169695Skanialias (omp_get_wtick) 82