1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpl.h"
7 
8 MPL_SUPPRESS_OSX_HAS_NO_SYMBOLS_WARNING;
9 
10 #if MPL_TIMER_KIND == MPL_TIMER_KIND__GCC_IA64_CYCLE
11 
12 #include <sys/time.h>
13 
14 static double seconds_per_tick = 0.0;
15 static int is_initialized = 0;
16 
MPL_wtick(double * wtick)17 int MPL_wtick(double *wtick)
18 {
19     *wtick = seconds_per_tick;
20 
21     return MPL_SUCCESS;
22 }
23 
MPL_wtime_init(void)24 int MPL_wtime_init(void)
25 {
26     unsigned long long t1, t2;
27     struct timeval tv1, tv2;
28     double td1, td2;
29 
30     if (is_initialized)
31         goto fn_exit;
32 
33     gettimeofday(&tv1, NULL);
34     MPL_wtime(&t1);
35     usleep(250000);
36     gettimeofday(&tv2, NULL);
37     MPL_wtime(&t2);
38 
39     td1 = tv1.tv_sec + tv1.tv_usec / 1000000.0;
40     td2 = tv2.tv_sec + tv2.tv_usec / 1000000.0;
41 
42     seconds_per_tick = (td2 - td1) / (double) (t2 - t1);
43 
44     is_initialized = 1;
45 
46   fn_exit:
47     return MPL_SUCCESS;
48 }
49 
50 /* Time stamps created by a macro */
MPL_wtime_diff(MPL_time_t * t1,MPL_time_t * t2,double * diff)51 int MPL_wtime_diff(MPL_time_t * t1, MPL_time_t * t2, double *diff)
52 {
53     *diff = (double) (*t2 - *t1) * seconds_per_tick;
54 
55     return MPL_SUCCESS;
56 }
57 
MPL_wtime_touint(MPL_time_t * t,unsigned int * val)58 int MPL_wtime_touint(MPL_time_t * t, unsigned int *val)
59 {
60     /* This returns the number of cycles as the "time".  This isn't correct
61      * for implementing MPI_Wtime, but it does allow us to insert cycle
62      * counters into test programs */
63     *val = (unsigned int) *t;
64 
65     return MPL_SUCCESS;
66 }
67 
MPL_wtime_todouble(MPL_time_t * t,double * val)68 int MPL_wtime_todouble(MPL_time_t * t, double *val)
69 {
70     /* This returns the number of cycles as the "time".  This isn't correct
71      * for implementing MPI_Wtime, but it does allow us to insert cycle
72      * counters into test programs */
73     *val = (double) *t * seconds_per_tick;
74 
75     return MPL_SUCCESS;
76 }
77 
MPL_wtime_acc(MPL_time_t * t1,MPL_time_t * t2,MPL_time_t * t3)78 int MPL_wtime_acc(MPL_time_t * t1, MPL_time_t * t2, MPL_time_t * t3)
79 {
80     *t3 += (*t2 - *t1);
81 
82     return MPL_SUCCESS;
83 }
84 
85 #endif
86