Skip to content

Commit fd0614d

Browse files
Jonas HahnfeldJonas Hahnfeld
Jonas Hahnfeld
authored and
Jonas Hahnfeld
committedSep 14, 2016
[OMPT] Align implementation of reenter frame address to latest (frozen) version of OMPT spec
The latest OMPT spec changed the semantic of a tasks reenter frame to be the application frame, that will be entered, when the runtime frame drops. Before it was the last frame in the runtime. This doesn't work for some gcc execution pathes or even clang generated code for : Since there is no runtime frame between the executed task and the encountering task. The test case compares exit and reenter addresses against addresses captured in application code Patch by Joachim Protze! Differential Revision: https://reviews.llvm.org/D23305 llvm-svn: 281464
1 parent 464cdca commit fd0614d

File tree

6 files changed

+58
-34
lines changed

6 files changed

+58
-34
lines changed
 

‎openmp/runtime/src/kmp_csupport.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ __kmpc_fork_call(ident_t *loc, kmp_int32 argc, kmpc_micro microtask, ...)
306306
kmp_team_t *parent_team = master_th->th.th_team;
307307
if (ompt_enabled) {
308308
parent_team->t.t_implicit_task_taskdata[tid].
309-
ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(0);
309+
ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(1);
310310
}
311311
#endif
312312

@@ -341,7 +341,7 @@ __kmpc_fork_call(ident_t *loc, kmp_int32 argc, kmpc_micro microtask, ...)
341341
#if OMPT_SUPPORT
342342
if (ompt_enabled) {
343343
parent_team->t.t_implicit_task_taskdata[tid].
344-
ompt_task_info.frame.reenter_runtime_frame = 0;
344+
ompt_task_info.frame.reenter_runtime_frame = NULL;
345345
}
346346
#endif
347347
}
@@ -396,7 +396,7 @@ __kmpc_fork_teams(ident_t *loc, kmp_int32 argc, kmpc_micro microtask, ...)
396396
int tid = __kmp_tid_from_gtid( gtid );
397397
if (ompt_enabled) {
398398
parent_team->t.t_implicit_task_taskdata[tid].
399-
ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(0);
399+
ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(1);
400400
}
401401
#endif
402402

@@ -678,6 +678,14 @@ __kmpc_barrier(ident_t *loc, kmp_int32 global_tid)
678678
__kmp_check_barrier( global_tid, ct_barrier, loc );
679679
}
680680

681+
#if OMPT_SUPPORT && OMPT_TRACE
682+
ompt_frame_t * ompt_frame;
683+
if (ompt_enabled ) {
684+
ompt_frame = &( __kmp_threads[ global_tid ] -> th.th_team ->
685+
t.t_implicit_task_taskdata[__kmp_tid_from_gtid(global_tid)].ompt_task_info.frame);
686+
ompt_frame->reenter_runtime_frame = __builtin_frame_address(1);
687+
}
688+
#endif
681689
__kmp_threads[ global_tid ]->th.th_ident = loc;
682690
// TODO: explicit barrier_wait_id:
683691
// this function is called when 'barrier' directive is present or
@@ -687,6 +695,11 @@ __kmpc_barrier(ident_t *loc, kmp_int32 global_tid)
687695
// 4) no sync is required
688696

689697
__kmp_barrier( bs_plain_barrier, global_tid, FALSE, 0, NULL, NULL );
698+
#if OMPT_SUPPORT && OMPT_TRACE
699+
if (ompt_enabled ) {
700+
ompt_frame->reenter_runtime_frame = NULL;
701+
}
702+
#endif
690703
}
691704

692705
/* The BARRIER for a MASTER section is always explicit */

‎openmp/runtime/src/kmp_gsupport.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ __kmp_GOMP_serialized_parallel(ident_t *loc, kmp_int32 gtid, void (*task)(void *
416416
__kmp_allocate(sizeof(ompt_lw_taskteam_t));
417417
__ompt_lw_taskteam_init(lwt, thr, gtid, (void *) task, ompt_parallel_id);
418418
lwt->ompt_task_info.task_id = my_ompt_task_id;
419-
lwt->ompt_task_info.frame.exit_runtime_frame = 0;
419+
lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
420420
__ompt_lw_taskteam_link(lwt, thr);
421421

422422
#if OMPT_TRACE
@@ -442,7 +442,7 @@ xexpand(KMP_API_NAME_GOMP_PARALLEL_START)(void (*task)(void *), void *data, unsi
442442

443443
if (ompt_enabled) {
444444
parent_frame = __ompt_get_task_frame_internal(0);
445-
parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
445+
parent_frame->reenter_runtime_frame = __builtin_frame_address(1);
446446
}
447447
#endif
448448

@@ -495,7 +495,7 @@ xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
495495
// Record that we re-entered the runtime system in the implicit
496496
// task frame representing the parallel region.
497497
ompt_frame = &task_info->frame;
498-
ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
498+
ompt_frame->reenter_runtime_frame = __builtin_frame_address(1);
499499

500500
// unlink if necessary. no-op if there is not a lightweight task.
501501
ompt_lw_taskteam_t *lwt = __ompt_lw_taskteam_unlink(thr);
@@ -509,7 +509,7 @@ xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
509509
// remaining deepest task knows the stack frame where the runtime
510510
// was reentered.
511511
ompt_frame = __ompt_get_task_frame_internal(0);
512-
ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
512+
ompt_frame->reenter_runtime_frame = __builtin_frame_address(1);
513513
}
514514
#endif
515515
}
@@ -525,7 +525,7 @@ xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
525525
// Set reenter frame in parent task, which will become current task
526526
// in the midst of join. This is needed before the end_parallel callback.
527527
ompt_frame = __ompt_get_task_frame_internal(1);
528-
ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
528+
ompt_frame->reenter_runtime_frame = __builtin_frame_address(1);
529529
}
530530
#endif
531531

@@ -555,7 +555,7 @@ xexpand(KMP_API_NAME_GOMP_PARALLEL_END)(void)
555555
if (ompt_enabled) {
556556
// Record that we re-entered the runtime system in the frame that
557557
// created the parallel region.
558-
ompt_frame->reenter_runtime_frame = __builtin_frame_address(0);
558+
ompt_frame->reenter_runtime_frame = __builtin_frame_address(1);
559559

560560
if (ompt_callbacks.ompt_callback(ompt_event_parallel_end)) {
561561
ompt_task_info_t *task_info = __ompt_get_taskinfo(0);
@@ -898,7 +898,7 @@ LOOP_NEXT_ULL(xexpand(KMP_API_NAME_GOMP_LOOP_ULL_ORDERED_RUNTIME_NEXT), \
898898
ompt_frame_t *parent_frame; \
899899
if (ompt_enabled) { \
900900
parent_frame = __ompt_get_task_frame_internal(0); \
901-
parent_frame->reenter_runtime_frame = __builtin_frame_address(0); \
901+
parent_frame->reenter_runtime_frame = __builtin_frame_address(1); \
902902
}
903903

904904

@@ -1002,7 +1002,7 @@ xexpand(KMP_API_NAME_GOMP_TASK)(void (*func)(void *), void *data, void (*copy_fu
10021002
#if OMPT_SUPPORT
10031003
if (ompt_enabled) {
10041004
thread->th.ompt_thread_info = oldInfo;
1005-
taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
1005+
taskdata->ompt_task_info.frame.exit_runtime_frame = NULL;
10061006
}
10071007
#endif
10081008
}
@@ -1101,7 +1101,7 @@ xexpand(KMP_API_NAME_GOMP_PARALLEL_SECTIONS_START)(void (*task) (void *), void *
11011101

11021102
if (ompt_enabled) {
11031103
parent_frame = __ompt_get_task_frame_internal(0);
1104-
parent_frame->reenter_runtime_frame = __builtin_frame_address(0);
1104+
parent_frame->reenter_runtime_frame = __builtin_frame_address(1);
11051105
}
11061106
#endif
11071107

‎openmp/runtime/src/kmp_runtime.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ __kmp_fork_call(
15501550
#if OMPT_SUPPORT
15511551
if (ompt_enabled) {
15521552
#if OMPT_TRACE
1553-
lw_taskteam.ompt_task_info.frame.exit_runtime_frame = 0;
1553+
lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
15541554

15551555
if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
15561556
ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
@@ -1746,7 +1746,7 @@ __kmp_fork_call(
17461746

17471747
#if OMPT_SUPPORT
17481748
if (ompt_enabled) {
1749-
lw_taskteam.ompt_task_info.frame.exit_runtime_frame = 0;
1749+
lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
17501750

17511751
#if OMPT_TRACE
17521752
if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
@@ -1853,7 +1853,7 @@ __kmp_fork_call(
18531853
#if OMPT_SUPPORT
18541854
if (ompt_enabled) {
18551855
#if OMPT_TRACE
1856-
lw_taskteam.ompt_task_info.frame.exit_runtime_frame = 0;
1856+
lw_taskteam.ompt_task_info.frame.exit_runtime_frame = NULL;
18571857

18581858
if (ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)) {
18591859
ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
@@ -1885,7 +1885,7 @@ __kmp_fork_call(
18851885
unwrapped_task, ompt_parallel_id);
18861886

18871887
lwt->ompt_task_info.task_id = __ompt_task_id_new(gtid);
1888-
lwt->ompt_task_info.frame.exit_runtime_frame = 0;
1888+
lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
18891889
__ompt_lw_taskteam_link(lwt, master_th);
18901890
#endif
18911891

@@ -2434,7 +2434,7 @@ __kmp_join_call(ident_t *loc, int gtid
24342434
ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
24352435
parallel_id, task_info->task_id);
24362436
}
2437-
task_info->frame.exit_runtime_frame = 0;
2437+
task_info->frame.exit_runtime_frame = NULL;
24382438
task_info->task_id = 0;
24392439
}
24402440
#endif
@@ -5503,7 +5503,7 @@ __kmp_launch_thread( kmp_info_t *this_thr )
55035503
#if OMPT_SUPPORT
55045504
if (ompt_enabled) {
55055505
/* no frame set while outside task */
5506-
task_info->frame.exit_runtime_frame = 0;
5506+
task_info->frame.exit_runtime_frame = NULL;
55075507

55085508
this_thr->th.ompt_thread_info.state = ompt_state_overhead;
55095509
}
@@ -5522,7 +5522,7 @@ __kmp_launch_thread( kmp_info_t *this_thr )
55225522
ompt_callbacks.ompt_callback(ompt_event_implicit_task_end)(
55235523
my_parallel_id, task_info->task_id);
55245524
}
5525-
task_info->frame.exit_runtime_frame = 0;
5525+
task_info->frame.exit_runtime_frame = NULL;
55265526
task_info->task_id = 0;
55275527
}
55285528
#endif

‎openmp/runtime/src/kmp_tasking.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ __kmp_invoke_task( kmp_int32 gtid, kmp_task_t *task, kmp_taskdata_t * current_ta
12581258
#if OMPT_SUPPORT
12591259
if (ompt_enabled) {
12601260
thread->th.ompt_thread_info = oldInfo;
1261-
taskdata->ompt_task_info.frame.exit_runtime_frame = 0;
1261+
taskdata->ompt_task_info.frame.exit_runtime_frame = NULL;
12621262
}
12631263
#endif
12641264

@@ -1334,7 +1334,7 @@ __kmp_omp_task( kmp_int32 gtid, kmp_task_t * new_task, bool serialize_immediate
13341334
#if OMPT_SUPPORT
13351335
if (ompt_enabled) {
13361336
new_taskdata->ompt_task_info.frame.reenter_runtime_frame =
1337-
__builtin_frame_address(0);
1337+
__builtin_frame_address(1);
13381338
}
13391339
#endif
13401340

@@ -1354,7 +1354,7 @@ __kmp_omp_task( kmp_int32 gtid, kmp_task_t * new_task, bool serialize_immediate
13541354

13551355
#if OMPT_SUPPORT
13561356
if (ompt_enabled) {
1357-
new_taskdata->ompt_task_info.frame.reenter_runtime_frame = 0;
1357+
new_taskdata->ompt_task_info.frame.reenter_runtime_frame = NULL;
13581358
}
13591359
#endif
13601360

@@ -1419,7 +1419,7 @@ __kmpc_omp_taskwait( ident_t *loc_ref, kmp_int32 gtid )
14191419
my_task_id = taskdata->ompt_task_info.task_id;
14201420
my_parallel_id = team->t.ompt_team_info.parallel_id;
14211421

1422-
taskdata->ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(0);
1422+
taskdata->ompt_task_info.frame.reenter_runtime_frame = __builtin_frame_address(1);
14231423
if (ompt_callbacks.ompt_callback(ompt_event_taskwait_begin)) {
14241424
ompt_callbacks.ompt_callback(ompt_event_taskwait_begin)(
14251425
my_parallel_id, my_task_id);
@@ -1469,7 +1469,7 @@ __kmpc_omp_taskwait( ident_t *loc_ref, kmp_int32 gtid )
14691469
ompt_callbacks.ompt_callback(ompt_event_taskwait_end)(
14701470
my_parallel_id, my_task_id);
14711471
}
1472-
taskdata->ompt_task_info.frame.reenter_runtime_frame = 0;
1472+
taskdata->ompt_task_info.frame.reenter_runtime_frame = NULL;
14731473
}
14741474
#endif
14751475
}

‎openmp/runtime/src/ompt-specific.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
257257
lwt->ompt_team_info.parallel_id = ompt_pid;
258258
lwt->ompt_team_info.microtask = microtask;
259259
lwt->ompt_task_info.task_id = 0;
260-
lwt->ompt_task_info.frame.reenter_runtime_frame = 0;
261-
lwt->ompt_task_info.frame.exit_runtime_frame = 0;
260+
lwt->ompt_task_info.frame.reenter_runtime_frame = NULL;
261+
lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
262262
lwt->ompt_task_info.function = NULL;
263263
lwt->parent = 0;
264264
}

‎openmp/runtime/test/ompt/parallel/nested.c

+19-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
int main()
88
{
99
omp_set_nested(1);
10+
print_frame(0);
1011

1112
#pragma omp parallel num_threads(4)
1213
{
14+
print_frame(1);
1315
print_ids(0);
1416
print_ids(1);
17+
print_frame(0);
1518
#pragma omp parallel num_threads(4)
1619
{
20+
print_frame(1);
1721
print_ids(0);
1822
print_ids(1);
1923
print_ids(2);
24+
print_frame(0);
25+
#pragma omp barrier
2026
}
2127
}
2228

@@ -40,18 +46,23 @@ int main()
4046
// CHECK: {{^}}[[MASTER_ID]]: ompt_event_parallel_end: parallel_id=[[PARALLEL_ID]], task_id=[[PARENT_TASK_ID]], invoker=[[PARALLEL_INVOKER]]
4147

4248

43-
// THREADS: 0: NULL_POINTER=[[NULL:.*$]]
44-
// THREADS: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter={{0x[0-f]+}}, parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=4, parallel_function=0x{{[0-f]+}}, invoker=[[PARALLEL_INVOKER:.+]]
49+
// THREADS: {{^}}0: NULL_POINTER=[[NULL:.*$]]
50+
// THREADS: {{^}}[[MASTER_ID:[0-9]+]]: __builtin_frame_address(0)=[[MAIN_REENTER:0x[0-f]+]]
51+
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter=[[MAIN_REENTER]], parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=4, parallel_function=0x{{[0-f]+}}, invoker=[[PARALLEL_INVOKER:.+]]
4552

4653
// nested parallel masters
4754
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID:[0-9]+]]
48-
// THREADS: {{^}}[[MASTER_ID]]: level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]]
49-
// THREADS: {{^}}[[MASTER_ID]]: level 1: parallel_id=0, task_id=[[PARENT_TASK_ID]]
50-
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin: parent_task_id=[[IMPLICIT_TASK_ID]], parent_task_frame.exit={{0x[0-f]+}}, parent_task_frame.reenter={{0x[0-f]+}}, parallel_id=[[NESTED_PARALLEL_ID:[0-9]+]], requested_team_size=4, parallel_function=[[NESTED_PARALLEL_FUNCTION:0x[0-f]+]], invoker=[[PARALLEL_INVOKER]]
55+
// THREADS: {{^}}[[MASTER_ID]]: __builtin_frame_address(1)=[[EXIT:0x[0-f]+]]
56+
// THREADS: {{^}}[[MASTER_ID]]: level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=[[NULL]]
57+
// THREADS: {{^}}[[MASTER_ID]]: level 1: parallel_id=0, task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=[[MAIN_REENTER]]
58+
// THREADS: {{^}}[[MASTER_ID]]: __builtin_frame_address(0)=[[REENTER:0x[0-f]+]]
59+
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin: parent_task_id=[[IMPLICIT_TASK_ID]], parent_task_frame.exit=[[EXIT]], parent_task_frame.reenter=[[REENTER]], parallel_id=[[NESTED_PARALLEL_ID:[0-9]+]], requested_team_size=4, parallel_function=[[NESTED_PARALLEL_FUNCTION:0x[0-f]+]], invoker=[[PARALLEL_INVOKER]]
5160
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[NESTED_PARALLEL_ID]], task_id=[[NESTED_IMPLICIT_TASK_ID:[0-9]+]]
52-
// THREADS: {{^}}[[MASTER_ID]]: level 0: parallel_id=[[NESTED_PARALLEL_ID]], task_id=[[NESTED_IMPLICIT_TASK_ID]]
53-
// THREADS: {{^}}[[MASTER_ID]]: level 1: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]]
54-
// THREADS: {{^}}[[MASTER_ID]]: level 2: parallel_id=0, task_id=[[PARENT_TASK_ID]]
61+
// THREADS: {{^}}[[MASTER_ID]]: __builtin_frame_address(1)=[[NESTED_EXIT:0x[0-f]+]]
62+
// THREADS: {{^}}[[MASTER_ID]]: level 0: parallel_id=[[NESTED_PARALLEL_ID]], task_id=[[NESTED_IMPLICIT_TASK_ID]], exit_frame=[[NESTED_EXIT]], reenter_frame=[[NULL]]
63+
// THREADS: {{^}}[[MASTER_ID]]: level 1: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=[[REENTER]]
64+
// THREADS: {{^}}[[MASTER_ID]]: level 2: parallel_id=0, task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=[[MAIN_REENTER]]
65+
// THREADS: {{^}}[[MASTER_ID]]: __builtin_frame_address(0)=[[NESTED_REENTER:0x[0-f]+]]
5566
// THREADS-NOT: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end
5667
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_begin: parallel_id=[[NESTED_PARALLEL_ID]], task_id=[[NESTED_IMPLICIT_TASK_ID]]
5768
// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_end: parallel_id=[[NESTED_PARALLEL_ID]], task_id=[[NESTED_IMPLICIT_TASK_ID]]

0 commit comments

Comments
 (0)
Please sign in to comment.