Skip to content

Commit 12a9e2a

Browse files
authored
[OpenMP][OMPT][OMPD] Fix frame flags for OpenMP tool APIs (llvm#114118)
In several cases the flags entries in ompt_frame_t are not initialized. According to @jdelsign the address provided as reenter and exit address is the canonical frame address (cfa) rather than a "framepointer". This patch makes sure that the flags entry is always initialized and changes the value from ompt_frame_framepointer to ompt_frame_cfa. The assertion in the tests makes sure that the flags are always set, when a tool (callback.h in this case) looks at the value. Fixes llvm#89058
1 parent 1e1b9bc commit 12a9e2a

File tree

6 files changed

+44
-20
lines changed

6 files changed

+44
-20
lines changed

openmp/runtime/src/kmp_tasking.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -714,22 +714,6 @@ static void __kmp_task_start(kmp_int32 gtid, kmp_task_t *task,
714714

715715
#if OMPT_SUPPORT
716716
//------------------------------------------------------------------------------
717-
// __ompt_task_init:
718-
// Initialize OMPT fields maintained by a task. This will only be called after
719-
// ompt_start_tool, so we already know whether ompt is enabled or not.
720-
721-
static inline void __ompt_task_init(kmp_taskdata_t *task, int tid) {
722-
// The calls to __ompt_task_init already have the ompt_enabled condition.
723-
task->ompt_task_info.task_data.value = 0;
724-
task->ompt_task_info.frame.exit_frame = ompt_data_none;
725-
task->ompt_task_info.frame.enter_frame = ompt_data_none;
726-
task->ompt_task_info.frame.exit_frame_flags =
727-
ompt_frame_runtime | ompt_frame_framepointer;
728-
task->ompt_task_info.frame.enter_frame_flags =
729-
ompt_frame_runtime | ompt_frame_framepointer;
730-
task->ompt_task_info.dispatch_chunk.start = 0;
731-
task->ompt_task_info.dispatch_chunk.iterations = 0;
732-
}
733717

734718
// __ompt_task_start:
735719
// Build and trigger task-begin event
@@ -804,7 +788,7 @@ static void __kmpc_omp_task_begin_if0_template(ident_t *loc_ref, kmp_int32 gtid,
804788
taskdata->ompt_task_info.frame.exit_frame.ptr = frame_address;
805789
current_task->ompt_task_info.frame.enter_frame_flags =
806790
taskdata->ompt_task_info.frame.exit_frame_flags =
807-
ompt_frame_application | ompt_frame_framepointer;
791+
OMPT_FRAME_FLAGS_APP;
808792
}
809793
if (ompt_enabled.ompt_callback_task_create) {
810794
ompt_task_info_t *parent_info = &(current_task->ompt_task_info);
@@ -1268,8 +1252,7 @@ static void __kmpc_omp_task_complete_if0_template(ident_t *loc_ref,
12681252
ompt_frame_t *ompt_frame;
12691253
__ompt_get_task_info_internal(0, NULL, NULL, &ompt_frame, NULL, NULL);
12701254
ompt_frame->enter_frame = ompt_data_none;
1271-
ompt_frame->enter_frame_flags =
1272-
ompt_frame_runtime | ompt_frame_framepointer;
1255+
ompt_frame->enter_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
12731256
}
12741257
#endif
12751258

@@ -2010,6 +1993,7 @@ kmp_int32 __kmpc_omp_task_parts(ident_t *loc_ref, kmp_int32 gtid,
20101993
#if OMPT_SUPPORT
20111994
if (UNLIKELY(ompt_enabled.enabled)) {
20121995
parent->ompt_task_info.frame.enter_frame = ompt_data_none;
1996+
parent->ompt_task_info.frame.enter_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
20131997
}
20141998
#endif
20151999
return TASK_CURRENT_NOT_QUEUED;

openmp/runtime/src/ompt-general.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ void ompt_post_init() {
498498
kmp_info_t *root_thread = ompt_get_thread();
499499

500500
ompt_set_thread_state(root_thread, ompt_state_overhead);
501+
__ompt_task_init(root_thread->th.th_current_task, 0);
501502

502503
if (ompt_enabled.ompt_callback_thread_begin) {
503504
ompt_callbacks.ompt_callback(ompt_callback_thread_begin)(

openmp/runtime/src/ompt-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void ompt_fini(void);
111111

112112
#define OMPT_GET_RETURN_ADDRESS(level) __builtin_return_address(level)
113113
#define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
114+
#define OMPT_FRAME_FLAGS_APP (ompt_frame_application | ompt_frame_cfa)
115+
#define OMPT_FRAME_FLAGS_RUNTIME (ompt_frame_runtime | ompt_frame_cfa)
114116

115117
int __kmp_control_tool(uint64_t command, uint64_t modifier, void *arg);
116118

openmp/runtime/src/ompt-specific.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr, int gtid,
266266
lwt->ompt_task_info.task_data.value = 0;
267267
lwt->ompt_task_info.frame.enter_frame = ompt_data_none;
268268
lwt->ompt_task_info.frame.exit_frame = ompt_data_none;
269+
lwt->ompt_task_info.frame.enter_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
270+
lwt->ompt_task_info.frame.exit_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
269271
lwt->ompt_task_info.scheduling_parent = NULL;
270272
lwt->heap = 0;
271273
lwt->parent = 0;

openmp/runtime/src/ompt-specific.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ int __ompt_get_task_info_internal(int ancestor_level, int *type,
5454

5555
ompt_data_t *__ompt_get_thread_data_internal();
5656

57+
// __ompt_task_init:
58+
// Initialize OMPT fields maintained by a task. This will only be called after
59+
// ompt_start_tool, so we already know whether ompt is enabled or not.
60+
61+
static inline void __ompt_task_init(kmp_taskdata_t *task, int tid) {
62+
// The calls to __ompt_task_init already have the ompt_enabled condition.
63+
task->ompt_task_info.task_data.value = 0;
64+
task->ompt_task_info.frame.exit_frame = ompt_data_none;
65+
task->ompt_task_info.frame.enter_frame = ompt_data_none;
66+
task->ompt_task_info.frame.exit_frame_flags =
67+
task->ompt_task_info.frame.enter_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
68+
task->ompt_task_info.dispatch_chunk.start = 0;
69+
task->ompt_task_info.dispatch_chunk.iterations = 0;
70+
}
71+
5772
/*
5873
* Unused currently
5974
static uint64_t __ompt_get_get_unique_id_internal();

openmp/runtime/test/ompt/callback.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <omp.h>
1313
#include <omp-tools.h>
1414
#include "ompt-signal.h"
15+
#include <stdlib.h>
16+
#include <assert.h>
1517

1618
// Used to detect architecture
1719
#include "../../src/kmp_platform.h"
@@ -147,6 +149,22 @@ static ompt_get_proc_id_t ompt_get_proc_id;
147149
static ompt_enumerate_states_t ompt_enumerate_states;
148150
static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls;
149151

152+
void assert_frame_flags(int enterf, int exitf) {
153+
if (!(enterf == (ompt_frame_application | ompt_frame_cfa) ||
154+
enterf == (ompt_frame_runtime | ompt_frame_cfa))) {
155+
printf("enter_frame_flags (%i) is invalid\n", enterf);
156+
fflush(NULL);
157+
}
158+
if (!(exitf == (ompt_frame_application | ompt_frame_cfa) ||
159+
exitf == (ompt_frame_runtime | ompt_frame_cfa))) {
160+
printf("exit_frame_flags (%i) is invalid\n", exitf);
161+
fflush(NULL);
162+
}
163+
assert(enterf == (ompt_frame_application | ompt_frame_cfa) ||
164+
enterf == (ompt_frame_runtime | ompt_frame_cfa));
165+
assert(exitf == (ompt_frame_application | ompt_frame_cfa) ||
166+
exitf == (ompt_frame_runtime | ompt_frame_cfa));
167+
}
150168
static void print_ids(int level)
151169
{
152170
int task_type, thread_num;
@@ -157,14 +175,16 @@ static void print_ids(int level)
157175
&task_parallel_data, &thread_num);
158176
char buffer[2048];
159177
format_task_type(task_type, buffer);
160-
if (frame)
178+
if (frame) {
161179
printf("%" PRIu64 ": task level %d: parallel_id=%" PRIu64
162180
", task_id=%" PRIu64 ", exit_frame=%p, reenter_frame=%p, "
163181
"task_type=%s=%d, thread_num=%d\n",
164182
ompt_get_thread_data()->value, level,
165183
exists_task ? task_parallel_data->value : 0,
166184
exists_task ? task_data->value : 0, frame->exit_frame.ptr,
167185
frame->enter_frame.ptr, buffer, task_type, thread_num);
186+
assert_frame_flags(frame->enter_frame_flags, frame->exit_frame_flags);
187+
}
168188
}
169189

170190
#define get_frame_address(level) __builtin_frame_address(level)

0 commit comments

Comments
 (0)