CCTLib
Calling-context and data-object attribution library for Intel Pin
omp_datarace_client.cpp File Reference
#include <stdio.h>
#include <atomic>
#include <stdlib.h>
#include <map>
#include <list>
#include <stdint.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <locale>
#include <unistd.h>
#include <sys/syscall.h>
#include <assert.h>
#include <sys/mman.h>
#include <exception>
#include <sys/time.h>
#include <signal.h>
#include <string.h>
#include <setjmp.h>
#include <sstream>
#include <pthread.h>
#include "pin.H"
#include "pin_isa_compat.H"
#include "cctlib.H"
#include "shadow_memory.H"
+ Include dependency graph for omp_datarace_client.cpp:

Go to the source code of this file.

Classes

struct  LabelSegment
 
class  Label
 
class  LabelIterator
 
class  ThreadData_t
 

Macros

#define MAX_FILE_PATH   (200)
 
#define ENTER_RANK(phase)   (((phase) + 1) & 0xfffffffffffffffe)
 
#define EXIT_RANK(phase)   ((phase)&0xfffffffffffffffe)
 
#define MAX_REGIONS   (1 << 20)
 
#define OMP_RUMTIMR_LIB_NAME   "/home/xl10/support/gcc-4.7-install/lib64/libgomp.so.1"
 
#define LINUX_LD_NAME   "/lib64/ld-linux-x86-64.so.2"
 
#define MAX_SKIP_IMAGES   (2)
 
#define MASTER_BEGIN_FN_NAME   "gomp_datarace_master_begin_dynamic_work"
 
#define DYNAMIC_BEGIN_FN_NAME   "gomp_datarace_begin_dynamic_work"
 
#define DYNAMIC_END_FN_NAME   "gomp_datarace_master_end_dynamic_work"
 
#define ORDERED_ENTER_FN_NAME   "gomp_datarace_begin_ordered_section"
 
#define ORDERED_EXIT_FN_NAME   "gomp_datarace_end_ordered_section"
 
#define CRITICAL_ENTER_FN_NAME   "gomp_datarace_begin_critical"
 
#define CRITICAL_EXIT_FN_NAME   "gomp_datarace_end_critical"
 

Typedefs

using VersionInfo_t = struct VersionInfo_t { union { volatile atomic< uint64_t > readStart
 
using DataraceInfo_t = struct DataraceInfo_t { VersionInfo_t versionInfo
 
using ExtendedDataraceInfo_t = struct ExtendedDataraceInfo_t { DataraceInfo_t *shadowAddress
 
using FP_MASTER = void(*)(uint64_t, long)
 
using FP_WORKER = void(*)(uint64_t, long, long)
 
using FP_WORKER_END = void(*)()
 
using FP_ORDERED_ENTER = void(*)(uint64_t)
 
using FP_ORDERED_EXIT = void(*)(uint64_t)
 
using FP_CRITICAL_ENTER = void(*)(void *)
 
using FP_CRITICAL_EXIT = void(*)(void *)
 

Enumerations

enum  LabelCreationType {
  CREATE_FIRST , CREATE_AFTER_FORK , CREATE_AFTER_JOIN , CREATE_AFTER_BARRIER ,
  CREATE_AFTER_ENTERING_ORDERED_SECTION , CREATE_AFTER_EXITING_ORDERED_SECTION
}
 
enum  AccessType { READ_ACCESS = 0 , WRITE_ACCESS = 1 , READ_ACCESS = 0 , WRITE_ACCESS = 1 }
 

Functions

ThreadData_tGetTLS (THREADID threadid)
 
static uint64_t GetReadStartForLoc (const DataraceInfo_t *const shadowAddress)
 
static uint64_t GetReadEndForLoc (const DataraceInfo_t *const shadowAddress)
 
static uint64_t GetWriteStartForLoc (const DataraceInfo_t *const shadowAddress)
 
static uint64_t GetWriteEndForLoc (const DataraceInfo_t *const shadowAddress)
 
static volatile atomic< uint64_t > * GetWriteStartAddressForLoc (DataraceInfo_t *const shadowAddress)
 
static void UpdateShadowDataAtShadowAddress (DataraceInfo_t *shadowAddress, const DataraceInfo_t &info)
 
static void ReadShadowData (DataraceInfo_t *info, DataraceInfo_t *shadowAddress)
 
static bool IsConsistentSpapshot (const DataraceInfo_t *const info)
 
void ReadShadowMemory (DataraceInfo_t *shadowAddress, DataraceInfo_t *info)
 
static bool TryWriteShadowMemory (DataraceInfo_t *shadowAddress, const DataraceInfo_t &info)
 
static LabelGetMyLabel (THREADID threadId)
 
static void SetMyLabel (THREADID threadId, Label *label)
 
static void UpdateLabel (Label **oldLabel, Label *newLabel)
 
static void UpdateContext (ContextHandle_t *oldCtxt, ContextHandle_t ctxt)
 
static void CommitChangesToShadowMemory (Label *oldLabel, Label *newLabel)
 
static bool HappensBefore (const Label *const oldLabel, const Label *const newLabel)
 
static bool IsLeftOf (const Label *const newLabel, const Label *const oldLabel)
 
static bool MaximizesExitRank (const Label *const newLabel, const Label *const oldLabel)
 
static void DumpRaceInfo (ContextHandle_t oldCtxt, Label *oldLbl, ContextHandle_t newCtxt, Label *newLbl)
 
static void CheckRead (DataraceInfo_t *shadowAddress, Label *myLabel, uint32_t opaqueHandle, THREADID threadId)
 
static void CheckWrite (DataraceInfo_t *shadowAddress, Label *myLabel, uint32_t opaqueHandle, THREADID threadId)
 
static void ExecuteOffsetSpanPhaseProtocol (DataraceInfo_t *status, Label *myLabel, bool accessType, uint32_t opaqueHandle, THREADID threadId)
 
static VOID CheckRace (VOID *addr, uint32_t accessLen, bool accessType, uint32_t opaqueHandle, THREADID threadId)
 
static bool IsIgnorableIns (INS ins)
 
void new_MASTER_BEGIN_FN_NAME (uint64_t region_id, long span, THREADID threadid)
 
void new_DYNAMIC_BEGIN_FN_NAME (uint64_t region_id, long span, long iter, THREADID threadid)
 
void new_DYNAMIC_END_FN_NAME (THREADID threadId)
 
void new_ORDERED_ENTER_FN_NAME (uint64_t region_id, THREADID threadId)
 
void new_ORDERED_EXIT_FN_NAME (uint64_t region_id, THREADID threadId)
 
void new_CRITICAL_ENTER_FN_NAME (void *name, THREADID threadid)
 
void new_CRITICAL_EXIT_FN_NAME (void *name, THREADID threadid)
 
VOID Overrides (IMG img, VOID *v)
 
static VOID InstrumentInsCallback (INS ins, VOID *v, const uint32_t opaqueHandle)
 
static INT32 Usage ()
 
VOID ThreadStart (THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
 
static VOID InstrumentImageLoad (IMG img, VOID *v)
 
void InitDataRaceSpy (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Variables

static const LabelSegment defaultExtension = {}
 
static FILE * gTraceFile
 
static const char * HW_LOCK = "HW_LOCK"
 
static Label ** gRegionIdToMasterLabelMap
 
static TLS_KEY tls_key
 
static ADDRINT gSkipImageAddressRanges [MAX_SKIP_IMAGES][2]
 
static int gNumCurSkipImages
 
static string skipImages [] = {OMP_RUMTIMR_LIB_NAME, LINUX_LD_NAME}
 
volatile atomic< uint64_t > writeEnd
 
union {
   volatile atomic< uint64_t >   writeStart
 
   volatile atomic< uint64_t >   readEnd
 
}; 
 
Labelread1
 
ContextHandle_t read1Context
 
Labelread2
 
ContextHandle_t read2Context
 
Labelwrite1
 
ContextHandle_t write1Context
 
ConcurrentShadowMemory< DataraceInfo_tsm
 
DataraceInfo_t data
 

Macro Definition Documentation

◆ CRITICAL_ENTER_FN_NAME

#define CRITICAL_ENTER_FN_NAME   "gomp_datarace_begin_critical"

Definition at line 736 of file omp_datarace_client.cpp.

◆ CRITICAL_EXIT_FN_NAME

#define CRITICAL_EXIT_FN_NAME   "gomp_datarace_end_critical"

Definition at line 737 of file omp_datarace_client.cpp.

◆ DYNAMIC_BEGIN_FN_NAME

#define DYNAMIC_BEGIN_FN_NAME   "gomp_datarace_begin_dynamic_work"

Definition at line 732 of file omp_datarace_client.cpp.

◆ DYNAMIC_END_FN_NAME

#define DYNAMIC_END_FN_NAME   "gomp_datarace_master_end_dynamic_work"

Definition at line 733 of file omp_datarace_client.cpp.

◆ ENTER_RANK

#define ENTER_RANK (   phase)    (((phase) + 1) & 0xfffffffffffffffe)

Definition at line 44 of file omp_datarace_client.cpp.

◆ EXIT_RANK

#define EXIT_RANK (   phase)    ((phase)&0xfffffffffffffffe)

Definition at line 48 of file omp_datarace_client.cpp.

◆ LINUX_LD_NAME

#define LINUX_LD_NAME   "/lib64/ld-linux-x86-64.so.2"

Definition at line 89 of file omp_datarace_client.cpp.

◆ MASTER_BEGIN_FN_NAME

#define MASTER_BEGIN_FN_NAME   "gomp_datarace_master_begin_dynamic_work"

Definition at line 731 of file omp_datarace_client.cpp.

◆ MAX_FILE_PATH

#define MAX_FILE_PATH   (200)

Definition at line 40 of file omp_datarace_client.cpp.

◆ MAX_REGIONS

#define MAX_REGIONS   (1 << 20)

Definition at line 50 of file omp_datarace_client.cpp.

◆ MAX_SKIP_IMAGES

#define MAX_SKIP_IMAGES   (2)

Definition at line 90 of file omp_datarace_client.cpp.

◆ OMP_RUMTIMR_LIB_NAME

#define OMP_RUMTIMR_LIB_NAME   "/home/xl10/support/gcc-4.7-install/lib64/libgomp.so.1"

Definition at line 88 of file omp_datarace_client.cpp.

◆ ORDERED_ENTER_FN_NAME

#define ORDERED_ENTER_FN_NAME   "gomp_datarace_begin_ordered_section"

Definition at line 734 of file omp_datarace_client.cpp.

◆ ORDERED_EXIT_FN_NAME

#define ORDERED_EXIT_FN_NAME   "gomp_datarace_end_ordered_section"

Definition at line 735 of file omp_datarace_client.cpp.

Typedef Documentation

◆ DataraceInfo_t

using DataraceInfo_t = struct DataraceInfo_t { VersionInfo_t versionInfo

Definition at line 118 of file omp_datarace_client.cpp.

◆ ExtendedDataraceInfo_t

Definition at line 143 of file omp_datarace_client.cpp.

◆ FP_CRITICAL_ENTER

using FP_CRITICAL_ENTER = void (*)(void*)

Definition at line 749 of file omp_datarace_client.cpp.

◆ FP_CRITICAL_EXIT

using FP_CRITICAL_EXIT = void (*)(void*)

Definition at line 750 of file omp_datarace_client.cpp.

◆ FP_MASTER

using FP_MASTER = void (*)(uint64_t, long)

Definition at line 744 of file omp_datarace_client.cpp.

◆ FP_ORDERED_ENTER

using FP_ORDERED_ENTER = void (*)(uint64_t)

Definition at line 747 of file omp_datarace_client.cpp.

◆ FP_ORDERED_EXIT

using FP_ORDERED_EXIT = void (*)(uint64_t)

Definition at line 748 of file omp_datarace_client.cpp.

◆ FP_WORKER

using FP_WORKER = void (*)(uint64_t, long, long)

Definition at line 745 of file omp_datarace_client.cpp.

◆ FP_WORKER_END

using FP_WORKER_END = void (*)()

Definition at line 746 of file omp_datarace_client.cpp.

◆ VersionInfo_t

using VersionInfo_t = struct VersionInfo_t { union { volatile atomic<uint64_t> readStart

Definition at line 102 of file omp_datarace_client.cpp.

Enumeration Type Documentation

◆ AccessType

enum AccessType
Enumerator
READ_ACCESS 
WRITE_ACCESS 
READ_ACCESS 
WRITE_ACCESS 

Definition at line 63 of file omp_datarace_client.cpp.

◆ LabelCreationType

Enumerator
CREATE_FIRST 
CREATE_AFTER_FORK 
CREATE_AFTER_JOIN 
CREATE_AFTER_BARRIER 
CREATE_AFTER_ENTERING_ORDERED_SECTION 
CREATE_AFTER_EXITING_ORDERED_SECTION 

Definition at line 54 of file omp_datarace_client.cpp.

Function Documentation

◆ CheckRace()

static VOID CheckRace ( VOID *  addr,
uint32_t  accessLen,
bool  accessType,
uint32_t  opaqueHandle,
THREADID  threadId 
)
inlinestatic

◆ CheckRead()

static void CheckRead ( DataraceInfo_t shadowAddress,
Label myLabel,
uint32_t  opaqueHandle,
THREADID  threadId 
)
inlinestatic

◆ CheckWrite()

static void CheckWrite ( DataraceInfo_t shadowAddress,
Label myLabel,
uint32_t  opaqueHandle,
THREADID  threadId 
)
inlinestatic

◆ CommitChangesToShadowMemory()

static void CommitChangesToShadowMemory ( Label oldLabel,
Label newLabel 
)
inlinestatic

Definition at line 430 of file omp_datarace_client.cpp.

References Label::DecrementRef(), and Label::IncrementRef().

Referenced by CheckRead(), and CheckWrite().

◆ DumpRaceInfo()

static void DumpRaceInfo ( ContextHandle_t  oldCtxt,
Label oldLbl,
ContextHandle_t  newCtxt,
Label newLbl 
)
inlinestatic

◆ ExecuteOffsetSpanPhaseProtocol()

static void ExecuteOffsetSpanPhaseProtocol ( DataraceInfo_t status,
Label myLabel,
bool  accessType,
uint32_t  opaqueHandle,
THREADID  threadId 
)
inlinestatic

Definition at line 668 of file omp_datarace_client.cpp.

References CheckRead(), CheckWrite(), PinCCTLib::status, and WRITE_ACCESS.

Referenced by CheckRace().

◆ GetMyLabel()

static Label* GetMyLabel ( THREADID  threadId)
inlinestatic

◆ GetReadEndForLoc()

static uint64_t GetReadEndForLoc ( const DataraceInfo_t *const  shadowAddress)
inlinestatic

Definition at line 326 of file omp_datarace_client.cpp.

Referenced by ReadShadowMemory().

◆ GetReadStartForLoc()

static uint64_t GetReadStartForLoc ( const DataraceInfo_t *const  shadowAddress)
inlinestatic

Definition at line 321 of file omp_datarace_client.cpp.

Referenced by ReadShadowMemory().

◆ GetTLS()

ThreadData_t* GetTLS ( THREADID  threadid)

Definition at line 314 of file omp_datarace_client.cpp.

References tls_key.

Referenced by GetMyLabel(), and SetMyLabel().

◆ GetWriteEndForLoc()

static uint64_t GetWriteEndForLoc ( const DataraceInfo_t *const  shadowAddress)
inlinestatic

Definition at line 336 of file omp_datarace_client.cpp.

◆ GetWriteStartAddressForLoc()

static volatile atomic<uint64_t>* GetWriteStartAddressForLoc ( DataraceInfo_t *const  shadowAddress)
inlinestatic

Definition at line 340 of file omp_datarace_client.cpp.

Referenced by TryWriteShadowMemory().

◆ GetWriteStartForLoc()

static uint64_t GetWriteStartForLoc ( const DataraceInfo_t *const  shadowAddress)
inlinestatic

Definition at line 331 of file omp_datarace_client.cpp.

◆ HappensBefore()

static bool HappensBefore ( const Label *const  oldLabel,
const Label *const  newLabel 
)
inlinestatic

◆ InitDataRaceSpy()

void InitDataRaceSpy ( int  argc,
char *  argv[] 
)

◆ InstrumentImageLoad()

static VOID InstrumentImageLoad ( IMG  img,
VOID *  v 
)
inlinestatic

◆ InstrumentInsCallback()

static VOID InstrumentInsCallback ( INS  ins,
VOID *  v,
const uint32_t  opaqueHandle 
)
static

◆ IsConsistentSpapshot()

static bool IsConsistentSpapshot ( const DataraceInfo_t *const  info)
inlinestatic

Definition at line 368 of file omp_datarace_client.cpp.

Referenced by ReadShadowMemory().

◆ IsIgnorableIns()

static bool IsIgnorableIns ( INS  ins)
inlinestatic

Definition at line 711 of file omp_datarace_client.cpp.

References gNumCurSkipImages, and gSkipImageAddressRanges.

Referenced by InstrumentInsCallback().

◆ IsLeftOf()

static bool IsLeftOf ( const Label *const  newLabel,
const Label *const  oldLabel 
)
inlinestatic

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ MaximizesExitRank()

static bool MaximizesExitRank ( const Label *const  newLabel,
const Label *const  oldLabel 
)
inlinestatic

◆ new_CRITICAL_ENTER_FN_NAME()

void new_CRITICAL_ENTER_FN_NAME ( void *  name,
THREADID  threadid 
)

Definition at line 809 of file omp_datarace_client.cpp.

Referenced by InstrumentInsCallback(), and Overrides().

◆ new_CRITICAL_EXIT_FN_NAME()

void new_CRITICAL_EXIT_FN_NAME ( void *  name,
THREADID  threadid 
)

Definition at line 817 of file omp_datarace_client.cpp.

Referenced by InstrumentInsCallback(), and Overrides().

◆ new_DYNAMIC_BEGIN_FN_NAME()

void new_DYNAMIC_BEGIN_FN_NAME ( uint64_t  region_id,
long  span,
long  iter,
THREADID  threadid 
)

◆ new_DYNAMIC_END_FN_NAME()

void new_DYNAMIC_END_FN_NAME ( THREADID  threadId)

Definition at line 784 of file omp_datarace_client.cpp.

References CREATE_AFTER_JOIN, GetMyLabel(), and SetMyLabel().

Referenced by Overrides().

◆ new_MASTER_BEGIN_FN_NAME()

void new_MASTER_BEGIN_FN_NAME ( uint64_t  region_id,
long  span,
THREADID  threadid 
)

Definition at line 753 of file omp_datarace_client.cpp.

References GetMyLabel(), gRegionIdToMasterLabelMap, MAX_REGIONS, and SetMyLabel().

Referenced by Overrides().

◆ new_ORDERED_ENTER_FN_NAME()

void new_ORDERED_ENTER_FN_NAME ( uint64_t  region_id,
THREADID  threadId 
)

Definition at line 793 of file omp_datarace_client.cpp.

References CREATE_AFTER_ENTERING_ORDERED_SECTION, GetMyLabel(), and SetMyLabel().

Referenced by Overrides().

◆ new_ORDERED_EXIT_FN_NAME()

void new_ORDERED_EXIT_FN_NAME ( uint64_t  region_id,
THREADID  threadId 
)

Definition at line 801 of file omp_datarace_client.cpp.

References CREATE_AFTER_EXITING_ORDERED_SECTION, GetMyLabel(), and SetMyLabel().

Referenced by Overrides().

◆ Overrides()

◆ ReadShadowData()

static void ReadShadowData ( DataraceInfo_t info,
DataraceInfo_t shadowAddress 
)
inlinestatic

Definition at line 358 of file omp_datarace_client.cpp.

Referenced by ReadShadowMemory().

◆ ReadShadowMemory()

void ReadShadowMemory ( DataraceInfo_t shadowAddress,
DataraceInfo_t info 
)
inline

◆ SetMyLabel()

static void SetMyLabel ( THREADID  threadId,
Label label 
)
inlinestatic

◆ ThreadStart()

VOID ThreadStart ( THREADID  threadid,
CONTEXT *  ctxt,
INT32  flags,
VOID *  v 
)

Definition at line 964 of file omp_datarace_client.cpp.

References tls_key.

Referenced by InitDataRaceSpy().

◆ TryWriteShadowMemory()

static bool TryWriteShadowMemory ( DataraceInfo_t shadowAddress,
const DataraceInfo_t info 
)
inlinestatic

◆ UpdateContext()

static void UpdateContext ( ContextHandle_t oldCtxt,
ContextHandle_t  ctxt 
)
inlinestatic

Definition at line 426 of file omp_datarace_client.cpp.

Referenced by CheckRead(), and CheckWrite().

◆ UpdateLabel()

static void UpdateLabel ( Label **  oldLabel,
Label newLabel 
)
inlinestatic

Definition at line 422 of file omp_datarace_client.cpp.

Referenced by CheckRead(), and CheckWrite().

◆ UpdateShadowDataAtShadowAddress()

static void UpdateShadowDataAtShadowAddress ( DataraceInfo_t shadowAddress,
const DataraceInfo_t info 
)
inlinestatic

Definition at line 345 of file omp_datarace_client.cpp.

Referenced by TryWriteShadowMemory().

◆ Usage()

static INT32 Usage ( )
static

Definition at line 959 of file omp_datarace_client.cpp.

Referenced by main().

Variable Documentation

◆ 

union { ... }

◆ data

◆ defaultExtension

const LabelSegment defaultExtension = {}
static

Definition at line 81 of file omp_datarace_client.cpp.

◆ gNumCurSkipImages

int gNumCurSkipImages
static

Definition at line 92 of file omp_datarace_client.cpp.

Referenced by InstrumentImageLoad(), and IsIgnorableIns().

◆ gRegionIdToMasterLabelMap

Label** gRegionIdToMasterLabelMap
static

◆ gSkipImageAddressRanges

ADDRINT gSkipImageAddressRanges[MAX_SKIP_IMAGES][2]
static

Definition at line 91 of file omp_datarace_client.cpp.

Referenced by InstrumentImageLoad(), and IsIgnorableIns().

◆ gTraceFile

FILE* gTraceFile
static

Definition at line 82 of file omp_datarace_client.cpp.

Referenced by DumpRaceInfo(), InitDataRaceSpy(), main(), and Label::PrintLabel().

◆ HW_LOCK

const char* HW_LOCK = "HW_LOCK"
static

Definition at line 83 of file omp_datarace_client.cpp.

Referenced by InstrumentInsCallback().

◆ read1

Label* read1

Definition at line 123 of file omp_datarace_client.cpp.

◆ read1Context

ContextHandle_t read1Context

Definition at line 125 of file omp_datarace_client.cpp.

◆ read2

Label* read2

Definition at line 128 of file omp_datarace_client.cpp.

◆ read2Context

ContextHandle_t read2Context

Definition at line 130 of file omp_datarace_client.cpp.

◆ readEnd

volatile atomic<uint64_t> readEnd

Definition at line 109 of file omp_datarace_client.cpp.

◆ skipImages

string skipImages[] = {OMP_RUMTIMR_LIB_NAME, LINUX_LD_NAME}
static

Definition at line 93 of file omp_datarace_client.cpp.

Referenced by InstrumentImageLoad().

◆ sm

Definition at line 138 of file omp_datarace_client.cpp.

Referenced by CheckRace().

◆ tls_key

TLS_KEY tls_key
static

Definition at line 86 of file omp_datarace_client.cpp.

Referenced by GetTLS(), InitDataRaceSpy(), and ThreadStart().

◆ write1

Label* write1

Definition at line 133 of file omp_datarace_client.cpp.

◆ write1Context

ContextHandle_t write1Context

Definition at line 135 of file omp_datarace_client.cpp.

◆ writeEnd

volatile atomic<uint64_t> writeEnd

Definition at line 105 of file omp_datarace_client.cpp.

◆ writeStart

volatile atomic<uint64_t> writeStart

Definition at line 108 of file omp_datarace_client.cpp.