1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
13 * Copyright (c) 2015-2016 Research Organization for Information Science
14 * and Technology (RIST). All rights reserved.
15 * Copyright (c) 2017 IBM Corporation. All rights reserved.
16 * Copyright (c) 2017 Los Alamos National Security, LLC. All rights
17 * reserved.
18 * $COPYRIGHT$
19 *
20 * Additional copyrights may follow
21 *
22 * $HEADER$
23 */
24 #include "ompi_config.h"
25
26 #ifdef HAVE_SYS_TIME_H
27 #include <sys/time.h>
28 #endif
29 #include <stdio.h>
30 #ifdef HAVE_TIME_H
31 #include <time.h>
32 #endif
33
34 #include MCA_timer_IMPLEMENTATION_HEADER
35 #include "ompi/mpi/c/bindings.h"
36 #include "ompi/runtime/mpiruntime.h"
37
38 #if OMPI_BUILD_MPI_PROFILING
39 #if OPAL_HAVE_WEAK_SYMBOLS
40 #pragma weak MPI_Wtick = PMPI_Wtick
41 #endif
42 #define MPI_Wtick PMPI_Wtick
43 #endif
44
45 double MPI_Wtick(void)
46 {
47 OPAL_CR_NOOP_PROGRESS();
48
49 /*
50 * See https://github.com/open-mpi/ompi/issues/3003
51 * to get an idea what's going on here.
52 */
53 #if 0
54 #if OPAL_TIMER_CYCLE_NATIVE
55 {
56 opal_timer_t freq = opal_timer_base_get_freq();
57 if (0 == freq) {
58 /* That should never happen, but if it does, return a bogus value
59 * rather than crashing with a division by zero */
60 return (double)0.0;
61 }
62 return (double)1.0 / (double)freq;
63 }
64 #elif OPAL_TIMER_USEC_NATIVE
65 return 0.000001;
66 #endif
67 #else
68 #if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
69 struct timespec spec;
70 double wtick = 0.0;
71 if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
72 wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
73 } else {
74 /* guess */
75 wtick = 1.0e-09;
76 }
77 return wtick;
78 #else
79 /* Otherwise, we already return usec precision. */
80 return 0.000001;
81 #endif
82 #endif
83 }