Skip to content

Commit 66fc5c9

Browse files
committed
timing framework: fix use of timers
Related to PR #11280 and issue #11213. Turns out owing to the libopal-core.la refactor that we have to add in a bit of plumbing to help the timing framework know when it can use native counters vs gettimeofday. With this patch, the timing framework now produces sensible time resuls even prior to initialization of opal, i.e. when there are timers present in the opal "util" initialization procedure. Note that currently the timing points in ompi_mpi_init in main are messed up so output isn't very useful. A subsequent PR wherein the PMIx fence usage in the init procedure is cleaned up will include refactored timing points. Signed-off-by: Howard Pritchard <howardp@lanl.gov>
1 parent d27799e commit 66fc5c9

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

opal/mca/timer/base/timer_base_open.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2023 Triad National Security, LLC. All rights
14+
* reserved.
1315
* $COPYRIGHT$
1416
*
1517
* Additional copyrights may follow
@@ -21,6 +23,7 @@
2123

2224
#include "opal/constants.h"
2325
#include "opal/mca/timer/base/base.h"
26+
#include "opal/util/timings.h"
2427

2528
bool mca_timer_base_monotonic = true;
2629

@@ -41,9 +44,31 @@ static int mca_timer_base_register(mca_base_register_flag_t flags)
4144
return OPAL_SUCCESS;
4245
}
4346

47+
static int opal_timer_base_open(mca_base_open_flag_t flags)
48+
{
49+
if (OPAL_SUCCESS != mca_base_framework_components_open(&opal_timer_base_framework, flags)) {
50+
return OPAL_ERROR;
51+
}
52+
53+
OPAL_TIMING_ENABLE_NATIVE_TIMERS;
54+
55+
return OPAL_SUCCESS;
56+
}
57+
58+
static int opal_timer_base_close(void)
59+
{
60+
int ret;
61+
62+
OPAL_TIMING_DISABLE_NATIVE_TIMERS;
63+
64+
return OPAL_SUCCESS;
65+
}
66+
4467
/*
4568
* Globals
4669
*/
4770
/* Use default register/open/close functions */
48-
MCA_BASE_FRAMEWORK_DECLARE(opal, timer, "OPAL OS timer", mca_timer_base_register, NULL, NULL,
71+
MCA_BASE_FRAMEWORK_DECLARE(opal, timer, "OPAL OS timer", mca_timer_base_register,
72+
opal_timer_base_open,
73+
opal_timer_base_close,
4974
mca_timer_base_static_components, 0);

opal/util/timings.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (C) 2014 Artem Polyakov <artpol84@gmail.com>
33
* Copyright (c) 2014 Intel, Inc. All rights reserved.
44
* Copyright (c) 2017 Mellanox Technologies Ltd. All rights reserved.
5+
* Copyright (c) 2023 Triad National Security, LLC. All rights
6+
* reserved.
57
* $COPYRIGHT$
68
*
79
* Additional copyrights may follow
@@ -41,6 +43,8 @@
4143

4244
#include MCA_timer_IMPLEMENTATION_HEADER
4345

46+
static bool opal_timer_native_timers_avail = false;
47+
4448
static double get_ts_gettimeofday(void)
4549
{
4650
double ret;
@@ -66,6 +70,17 @@ static double get_ts_usec(void)
6670
}
6771
#endif
6872

73+
void opal_timing_enable_native_timers(void)
74+
{
75+
opal_timer_native_timers_avail = true;
76+
}
77+
78+
void opal_timing_disable_native_timers(void)
79+
{
80+
opal_timer_native_timers_avail = false;
81+
}
82+
83+
6984
opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type)
7085
{
7186
switch (type) {
@@ -85,6 +100,9 @@ opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type)
85100
return NULL;
86101
#endif // OPAL_TIMER_USEC_NATIVE
87102
default:
103+
if( false == opal_timer_native_timers_avail ){
104+
return get_ts_gettimeofday;
105+
}
88106
#if OPAL_TIMER_CYCLE_NATIVE
89107
return get_ts_cycle;
90108
#elif OPAL_TIMER_USEC_NATIVE

opal/util/timings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (C) 2014 Artem Polyakov <artpol84@gmail.com>
33
* Copyright (c) 2014-2017 Intel, Inc. All rights reserved.
44
* Copyright (c) 2017-2018 Mellanox Technologies Ltd. All rights reserved.
5+
* Copyright (c) 2023 Triad National Security, LLC. All rights
6+
* reserved.
57
* $COPYRIGHT$
68
*
79
* Additional copyrights may follow
@@ -39,6 +41,11 @@ typedef struct {
3941
} opal_timing_env_t;
4042

4143
opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type);
44+
void opal_timing_enable_native_timers(void);
45+
void opal_timing_disable_native_timers(void);
46+
47+
# define OPAL_TIMING_ENABLE_NATIVE_TIMERS opal_timing_enable_native_timers()
48+
# define OPAL_TIMING_DISABLE_NATIVE_TIMERS opal_timing_disable_native_timers()
4249

4350
# define OPAL_TIMING_ENV_START_TYPE(func, _nm, type, prefix) \
4451
do { \
@@ -200,6 +207,9 @@ opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type);
200207

201208
#else
202209

210+
# define OPAL_TIMING_ENABLE_NATIVE_TIMERS
211+
# define OPAL_TIMING_DISABLE_NATIVE_TIMERS
212+
203213
# define OPAL_TIMING_ENV_START_TYPE(func, type, prefix)
204214

205215
# define OPAL_TIMING_ENV_INIT(name)

0 commit comments

Comments
 (0)