LLVM OpenMP 20.0.0git
Macros | Typedefs | Functions | Variables
ompt-tsan.cpp File Reference
#include <algorithm>
#include <atomic>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <dlfcn.h>
#include <inttypes.h>
#include <iostream>
#include <list>
#include <mutex>
#include <sstream>
#include <string>
#include <sys/resource.h>
#include <unistd.h>
#include <unordered_map>
#include <vector>
#include "omp-tools.h"

Go to the source code of this file.

Macros

#define __STDC_FORMAT_MACROS
 
#define KMP_FALLTHROUGH()   ((void)0)
 
#define DECLARE_TSAN_FUNCTION(name, ...)    static void (*name)(__VA_ARGS__) = __ompt_tsan_func<__VA_ARGS__>;
 
#define TsanHappensBefore(cv)   AnnotateHappensBefore(__FILE__, __LINE__, cv)
 
#define TsanHappensAfter(cv)   AnnotateHappensAfter(__FILE__, __LINE__, cv)
 
#define TsanIgnoreWritesBegin()   AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
 
#define TsanIgnoreWritesEnd()   AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
 
#define TsanDeleteClock(cv)
 
#define TsanNewMemory(addr, size)    AnnotateNewMemory(__FILE__, __LINE__, addr, size)
 
#define TsanFreeMemory(addr, size)    AnnotateNewMemory(__FILE__, __LINE__, addr, size)
 
#define TsanFuncEntry(pc)   __tsan_func_entry(pc)
 
#define TsanFuncExit()   __tsan_func_exit()
 
#define SET_OPTIONAL_CALLBACK_T(event, type, result, level)
 
#define SET_CALLBACK_T(event, type)
 
#define SET_CALLBACK(event)   SET_CALLBACK_T(event, event)
 
#define findTsanFunction(f, fSig)
 
#define findTsanFunctionSilent(f, fSig)   f = fSig dlsym(RTLD_DEFAULT, #f)
 

Typedefs

typedef char ompt_tsan_clockid
 

Functions

template<typename... Args>
static void __ompt_tsan_func (Args...)
 
 DECLARE_TSAN_FUNCTION (AnnotateHappensAfter, const char *, int, const volatile void *) DECLARE_TSAN_FUNCTION(AnnotateHappensBefore
 
const char const volatile voidDECLARE_TSAN_FUNCTION (AnnotateNewMemory, const char *, int, const volatile void *, size_t) static int(*RunningOnValgrind)(void)
 
static uint64_t my_next_id ()
 
static TaskData * ToTaskData (ompt_data_t *task_data)
 
static void ompt_tsan_thread_begin (ompt_thread_t thread_type, ompt_data_t *thread_data)
 
static void ompt_tsan_thread_end (ompt_data_t *thread_data)
 
static void ompt_tsan_parallel_begin (ompt_data_t *parent_task_data, const ompt_frame_t *parent_task_frame, ompt_data_t *parallel_data, uint32_t requested_team_size, int flag, const void *codeptr_ra)
 OMPT event callbacks for handling parallel regions.
 
static void ompt_tsan_parallel_end (ompt_data_t *parallel_data, ompt_data_t *task_data, int flag, const void *codeptr_ra)
 
static void ompt_tsan_implicit_task (ompt_scope_endpoint_t endpoint, ompt_data_t *parallel_data, ompt_data_t *task_data, unsigned int team_size, unsigned int thread_num, int type)
 
static void ompt_tsan_sync_region (ompt_sync_region_t kind, ompt_scope_endpoint_t endpoint, ompt_data_t *parallel_data, ompt_data_t *task_data, const void *codeptr_ra)
 
static void ompt_tsan_reduction (ompt_sync_region_t kind, ompt_scope_endpoint_t endpoint, ompt_data_t *parallel_data, ompt_data_t *task_data, const void *codeptr_ra)
 
static void ompt_tsan_task_create (ompt_data_t *parent_task_data, const ompt_frame_t *parent_frame, ompt_data_t *new_task_data, int type, int has_dependences, const void *codeptr_ra)
 OMPT event callbacks for handling tasks.
 
static void freeTask (TaskData *task)
 
static void releaseDependencies (TaskData *task)
 
static void acquireDependencies (TaskData *task)
 
static void completeTask (TaskData *FromTask)
 
static void suspendTask (TaskData *FromTask)
 
static void switchTasks (TaskData *FromTask, TaskData *ToTask)
 
static void endTask (TaskData *FromTask)
 
static void startTask (TaskData *ToTask)
 
static void ompt_tsan_task_schedule (ompt_data_t *first_task_data, ompt_task_status_t prior_task_status, ompt_data_t *second_task_data)
 
static void ompt_tsan_dependences (ompt_data_t *task_data, const ompt_dependence_t *deps, int ndeps)
 
static void ompt_tsan_mutex_acquired (ompt_mutex_t kind, ompt_wait_id_t wait_id, const void *codeptr_ra)
 OMPT event callbacks for handling locking.
 
static void ompt_tsan_mutex_released (ompt_mutex_t kind, ompt_wait_id_t wait_id, const void *codeptr_ra)
 
static int ompt_tsan_initialize (ompt_function_lookup_t lookup, int device_num, ompt_data_t *tool_data)
 
static void ompt_tsan_finalize (ompt_data_t *tool_data)
 
ompt_start_tool_result_tompt_start_tool (unsigned int omp_version, const char *runtime_version)
 

Variables

static int hasReductionCallback
 
static ArcherFlags * archer_flags
 
const char int
 
static ompt_get_parallel_info_t ompt_get_parallel_info
 Required OMPT inquiry functions.
 
static ompt_get_thread_data_t ompt_get_thread_data
 
static int pagesize {0}
 
static std::unordered_map< ompt_wait_id_t, std::mutex > Locks
 Store a mutex for each wait_id to resolve race condition with callbacks.
 
static std::mutex LocksMutex
 

Macro Definition Documentation

◆ __STDC_FORMAT_MACROS

#define __STDC_FORMAT_MACROS

Definition at line 14 of file ompt-tsan.cpp.

◆ DECLARE_TSAN_FUNCTION

#define DECLARE_TSAN_FUNCTION (   name,
  ... 
)     static void (*name)(__VA_ARGS__) = __ompt_tsan_func<__VA_ARGS__>;

Definition at line 152 of file ompt-tsan.cpp.

◆ findTsanFunction

#define findTsanFunction (   f,
  fSig 
)
Value:
do { \
void *fp = dlsym(RTLD_DEFAULT, #f); \
if (fp) \
f = fSig fp; \
else \
printf("Unable to find TSan function " #f ".\n"); \
} while (0)

Definition at line 1153 of file ompt-tsan.cpp.

◆ findTsanFunctionSilent

#define findTsanFunctionSilent (   f,
  fSig 
)    f = fSig dlsym(RTLD_DEFAULT, #f)

Definition at line 1162 of file ompt-tsan.cpp.

◆ KMP_FALLTHROUGH

#define KMP_FALLTHROUGH ( )    ((void)0)

Definition at line 50 of file ompt-tsan.cpp.

◆ SET_CALLBACK

#define SET_CALLBACK (   event)    SET_CALLBACK_T(event, event)

Definition at line 1151 of file ompt-tsan.cpp.

◆ SET_CALLBACK_T

#define SET_CALLBACK_T (   event,
  type 
)
Value:
do { \
int res; \
SET_OPTIONAL_CALLBACK_T(event, type, res, ompt_set_always); \
} while (0)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d __itt_event event
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
#define res

Definition at line 1145 of file ompt-tsan.cpp.

◆ SET_OPTIONAL_CALLBACK_T

#define SET_OPTIONAL_CALLBACK_T (   event,
  type,
  result,
  level 
)
Value:
do { \
ompt_callback_##type##_t tsan_##event = &ompt_tsan_##event; \
result = ompt_set_callback(ompt_callback_##event, \
(ompt_callback_t)tsan_##event); \
if (result < level) \
printf("Registered callback '" #event "' is not supported at " #level \
" (%i)\n", \
result); \
} while (0)
static ompt_set_callback_t ompt_set_callback
Definition: callback.h:132
int result[2]

Definition at line 1134 of file ompt-tsan.cpp.

◆ TsanDeleteClock

#define TsanDeleteClock (   cv)

Definition at line 189 of file ompt-tsan.cpp.

◆ TsanFreeMemory

#define TsanFreeMemory (   addr,
  size 
)     AnnotateNewMemory(__FILE__, __LINE__, addr, size)

Definition at line 194 of file ompt-tsan.cpp.

◆ TsanFuncEntry

#define TsanFuncEntry (   pc)    __tsan_func_entry(pc)

Definition at line 199 of file ompt-tsan.cpp.

◆ TsanFuncExit

#define TsanFuncExit ( )    __tsan_func_exit()

Definition at line 200 of file ompt-tsan.cpp.

◆ TsanHappensAfter

#define TsanHappensAfter (   cv)    AnnotateHappensAfter(__FILE__, __LINE__, cv)

Definition at line 180 of file ompt-tsan.cpp.

◆ TsanHappensBefore

#define TsanHappensBefore (   cv)    AnnotateHappensBefore(__FILE__, __LINE__, cv)

Definition at line 177 of file ompt-tsan.cpp.

◆ TsanIgnoreWritesBegin

#define TsanIgnoreWritesBegin ( )    AnnotateIgnoreWritesBegin(__FILE__, __LINE__)

Definition at line 183 of file ompt-tsan.cpp.

◆ TsanIgnoreWritesEnd

#define TsanIgnoreWritesEnd ( )    AnnotateIgnoreWritesEnd(__FILE__, __LINE__)

Definition at line 186 of file ompt-tsan.cpp.

◆ TsanNewMemory

#define TsanNewMemory (   addr,
  size 
)     AnnotateNewMemory(__FILE__, __LINE__, addr, size)

Definition at line 192 of file ompt-tsan.cpp.

Typedef Documentation

◆ ompt_tsan_clockid

Definition at line 206 of file ompt-tsan.cpp.

Function Documentation

◆ __ompt_tsan_func()

template<typename... Args>
static void __ompt_tsan_func ( Args...  )
static

Definition at line 150 of file ompt-tsan.cpp.

◆ acquireDependencies()

static void acquireDependencies ( TaskData *  task)
static

Definition at line 903 of file ompt-tsan.cpp.

References archer_flags, i, and TsanHappensAfter.

Referenced by ompt_tsan_task_schedule(), and startTask().

◆ completeTask()

static void completeTask ( TaskData *  FromTask)
static

Definition at line 915 of file ompt-tsan.cpp.

References releaseDependencies(), TsanHappensAfter, and TsanHappensBefore.

Referenced by ompt_tsan_task_schedule().

◆ DECLARE_TSAN_FUNCTION() [1/2]

DECLARE_TSAN_FUNCTION ( AnnotateHappensAfter  ,
const char ,
int  ,
const volatile void  
)

◆ DECLARE_TSAN_FUNCTION() [2/2]

const char const volatile void * DECLARE_TSAN_FUNCTION ( AnnotateNewMemory  ,
const char ,
int  ,
const volatile void ,
size_t   
)

◆ endTask()

static void endTask ( TaskData *  FromTask)
static

Definition at line 970 of file ompt-tsan.cpp.

Referenced by ompt_tsan_task_schedule().

◆ freeTask()

static void freeTask ( TaskData *  task)
static

Definition at line 878 of file ompt-tsan.cpp.

Referenced by ompt_tsan_task_schedule().

◆ my_next_id()

static uint64_t my_next_id ( )
static

Definition at line 208 of file ompt-tsan.cpp.

References ret.

Referenced by ompt_tsan_thread_begin().

◆ ompt_start_tool()

ompt_start_tool_result_t * ompt_start_tool ( unsigned int  omp_version,
const char runtime_version 
)

◆ ompt_tsan_dependences()

static void ompt_tsan_dependences ( ompt_data_t *  task_data,
const ompt_dependence_t *  deps,
int  ndeps 
)
static

Definition at line 1063 of file ompt-tsan.cpp.

References archer_flags, d, i, ret, ToTaskData(), and TsanHappensBefore.

◆ ompt_tsan_finalize()

static void ompt_tsan_finalize ( ompt_data_t *  tool_data)
static

Definition at line 1224 of file ompt-tsan.cpp.

References archer_flags, end, and TsanIgnoreWritesEnd.

Referenced by ompt_start_tool().

◆ ompt_tsan_implicit_task()

static void ompt_tsan_implicit_task ( ompt_scope_endpoint_t  endpoint,
ompt_data_t *  parallel_data,
ompt_data_t *  task_data,
unsigned int  team_size,
unsigned int  thread_num,
int  type 
)
static

Definition at line 667 of file ompt-tsan.cpp.

References ToTaskData(), TsanFuncEntry, TsanFuncExit, TsanHappensAfter, and type.

◆ ompt_tsan_initialize()

static int ompt_tsan_initialize ( ompt_function_lookup_t  lookup,
int  device_num,
ompt_data_t *  tool_data 
)
static

◆ ompt_tsan_mutex_acquired()

static void ompt_tsan_mutex_acquired ( ompt_mutex_t  kind,
ompt_wait_id_t  wait_id,
const void codeptr_ra 
)
static

OMPT event callbacks for handling locking.

Definition at line 1109 of file ompt-tsan.cpp.

References Locks, LocksMutex, and TsanHappensAfter.

◆ ompt_tsan_mutex_released()

static void ompt_tsan_mutex_released ( ompt_mutex_t  kind,
ompt_wait_id_t  wait_id,
const void codeptr_ra 
)
static

Definition at line 1123 of file ompt-tsan.cpp.

References Locks, LocksMutex, and TsanHappensBefore.

◆ ompt_tsan_parallel_begin()

static void ompt_tsan_parallel_begin ( ompt_data_t *  parent_task_data,
const ompt_frame_t *  parent_task_frame,
ompt_data_t *  parallel_data,
uint32_t  requested_team_size,
int  flag,
const void codeptr_ra 
)
static

OMPT event callbacks for handling parallel regions.

Definition at line 635 of file ompt-tsan.cpp.

References archer_flags, ToTaskData(), TsanHappensBefore, and TsanIgnoreWritesEnd.

◆ ompt_tsan_parallel_end()

static void ompt_tsan_parallel_end ( ompt_data_t *  parallel_data,
ompt_data_t *  task_data,
int  flag,
const void codeptr_ra 
)
static

Definition at line 648 of file ompt-tsan.cpp.

References archer_flags, ToTaskData(), TsanHappensAfter, and TsanIgnoreWritesBegin.

◆ ompt_tsan_reduction()

static void ompt_tsan_reduction ( ompt_sync_region_t  kind,
ompt_scope_endpoint_t  endpoint,
ompt_data_t *  parallel_data,
ompt_data_t *  task_data,
const void codeptr_ra 
)
static

Definition at line 810 of file ompt-tsan.cpp.

References TsanIgnoreWritesBegin, and TsanIgnoreWritesEnd.

◆ ompt_tsan_sync_region()

static void ompt_tsan_sync_region ( ompt_sync_region_t  kind,
ompt_scope_endpoint_t  endpoint,
ompt_data_t *  parallel_data,
ompt_data_t *  task_data,
const void codeptr_ra 
)
static

◆ ompt_tsan_task_create()

static void ompt_tsan_task_create ( ompt_data_t *  parent_task_data,
const ompt_frame_t *  parent_frame,
ompt_data_t *  new_task_data,
int  type,
int  has_dependences,
const void codeptr_ra 
)
static

OMPT event callbacks for handling tasks.

Definition at line 844 of file ompt-tsan.cpp.

References ompt_get_parallel_info, ToTaskData(), TsanHappensBefore, and type.

◆ ompt_tsan_task_schedule()

static void ompt_tsan_task_schedule ( ompt_data_t *  first_task_data,
ompt_task_status_t  prior_task_status,
ompt_data_t *  second_task_data 
)
static

◆ ompt_tsan_thread_begin()

static void ompt_tsan_thread_begin ( ompt_thread_t  thread_type,
ompt_data_t *  thread_data 
)
static

Definition at line 607 of file ompt-tsan.cpp.

References my_next_id(), and TsanNewMemory.

◆ ompt_tsan_thread_end()

static void ompt_tsan_thread_end ( ompt_data_t *  thread_data)
static

Definition at line 624 of file ompt-tsan.cpp.

References TsanIgnoreWritesBegin, and TsanIgnoreWritesEnd.

◆ releaseDependencies()

static void releaseDependencies ( TaskData *  task)
static

Definition at line 890 of file ompt-tsan.cpp.

References archer_flags, i, and TsanHappensBefore.

Referenced by completeTask().

◆ startTask()

static void startTask ( TaskData *  ToTask)
static

Definition at line 975 of file ompt-tsan.cpp.

References acquireDependencies(), and TsanHappensAfter.

Referenced by ompt_tsan_task_schedule().

◆ suspendTask()

static void suspendTask ( TaskData *  FromTask)
static

Definition at line 942 of file ompt-tsan.cpp.

References TsanHappensBefore.

Referenced by ompt_tsan_task_schedule().

◆ switchTasks()

static void switchTasks ( TaskData *  FromTask,
TaskData *  ToTask 
)
static

Definition at line 949 of file ompt-tsan.cpp.

References hasReductionCallback, TsanIgnoreWritesBegin, and TsanIgnoreWritesEnd.

Referenced by ompt_tsan_task_schedule().

◆ ToTaskData()

static TaskData * ToTaskData ( ompt_data_t *  task_data)
inlinestatic

Variable Documentation

◆ archer_flags

ArcherFlags* archer_flags
static

◆ hasReductionCallback

int hasReductionCallback
static

Definition at line 53 of file ompt-tsan.cpp.

Referenced by ompt_tsan_initialize(), ompt_tsan_sync_region(), and switchTasks().

◆ int

const char int

Definition at line 161 of file ompt-tsan.cpp.

◆ Locks

std::unordered_map<ompt_wait_id_t, std::mutex> Locks
static

Store a mutex for each wait_id to resolve race condition with callbacks.

Definition at line 604 of file ompt-tsan.cpp.

Referenced by ompt_tsan_mutex_acquired(), and ompt_tsan_mutex_released().

◆ LocksMutex

std::mutex LocksMutex
static

Definition at line 605 of file ompt-tsan.cpp.

Referenced by ompt_tsan_mutex_acquired(), and ompt_tsan_mutex_released().

◆ ompt_get_parallel_info

ompt_get_parallel_info_t ompt_get_parallel_info
static

Required OMPT inquiry functions.

Definition at line 203 of file ompt-tsan.cpp.

Referenced by ompt_tsan_initialize(), and ompt_tsan_task_create().

◆ ompt_get_thread_data

ompt_get_thread_data_t ompt_get_thread_data ( void  )
static

Definition at line 204 of file ompt-tsan.cpp.

Referenced by ompt_tsan_initialize().

◆ pagesize

int pagesize {0}
static

Definition at line 214 of file ompt-tsan.cpp.

Referenced by ompt_start_tool().