From b9c3d051c036d05c0db7bf46fb8903e5a7d27ef3 Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Fri, 24 Nov 2023 16:51:26 +0100 Subject: [PATCH] feat(profiler): added option to cmake build to configure NUM_WORKERS --- docs/Manual_Quickstart/Manual_Setup.md | 3 +++ rtlib/CMakeLists.txt | 7 +++++++ rtlib/iFunctions.cpp | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/docs/Manual_Quickstart/Manual_Setup.md b/docs/Manual_Quickstart/Manual_Setup.md index 07f4cbe1b..dabdfa2fd 100644 --- a/docs/Manual_Quickstart/Manual_Setup.md +++ b/docs/Manual_Quickstart/Manual_Setup.md @@ -45,8 +45,11 @@ If you have installed LLVM using the package manager, specifying this var Note: In case you want to use a specific Version of LLVM, it is possible to specify the `-DUSE_LLVM_VERSION=` flag. Note: In case your application uses PThreads, please specify `-DDP_PTHREAD_COMPATIBILITY_MODE=1`. Note, however, that this can influence the runtime of the profiling. + Note: In case you require a more verbose output of the runtime library, specify the `-DDP_RTLIB_VERBOSE=1` flag. +Note: In case you want to specify the number of Workers available for the profiling step, specify the `-DDP_NUM_WORKERS=` flag. + Once the configuration process is successfully finished, compile the DiscoPoP libraries using `make`. All created shared objects will be stored in the build directory and can be found inside a folder named `libi/`. make diff --git a/rtlib/CMakeLists.txt b/rtlib/CMakeLists.txt index 46fcbe7ab..5f1880b1f 100644 --- a/rtlib/CMakeLists.txt +++ b/rtlib/CMakeLists.txt @@ -39,6 +39,13 @@ if(DEFINED DP_RTLIB_VERBOSE) target_compile_definitions(DiscoPoP_RT PUBLIC DP_RTLIB_VERBOSE=${DP_RTLIB_VERBOSE}) endif() endif() + +if(DEFINED DP_NUM_WORKERS) + if(NOT ${DP_NUM_WORKERS} EQUAL 0) + target_compile_definitions(DiscoPoP_RT PUBLIC DP_NUM_WORKERS=${DP_NUM_WORKERS}) + endif() +endif() + # end of compiler flags install(TARGETS DiscoPoP_RT ARCHIVE DESTINATION lib) diff --git a/rtlib/iFunctions.cpp b/rtlib/iFunctions.cpp index 6f4f2b485..600df66d8 100755 --- a/rtlib/iFunctions.cpp +++ b/rtlib/iFunctions.cpp @@ -91,7 +91,14 @@ namespace __dp { pthread_mutex_t allDepsLock; pthread_t *workers = nullptr; // worker threads +#define XSTR(x) STR(x) +#define STR(x) #x +#ifdef DP_NUM_WORKERS +#pragma message "Profiler: set NUM_WORKERS to " XSTR(DP_NUM_WORKERS) + int32_t NUM_WORKERS = DP_NUM_WORKERS; +#else int32_t NUM_WORKERS = 3; // default number of worker threads (multiple workers can potentially lead to non-deterministic results) +#endif int32_t CHUNK_SIZE = 500; // default number of addresses in each chunk queue *chunks = nullptr; // one queue of access info chunks for each worker thread bool *addrChunkPresent = nullptr; // addrChunkPresent[thread_id] denotes whether or not a new chunk is available for the corresponding thread