How to detect a thread synchronization in a program in my LLVM pass?

102 views Asked by At

I'm trying to measure how much time a program spends in its synchronized parts e.g. critical sections protected by locks (or any other form of concurrency control).

I'm confused on how to do it and how to detect concurrency control methods in a program that I'm running through my llvm pass.

1

There are 1 answers

0
Brian On BEST ANSWER

I wrote a tool, Contech, to instrument LLVM IR to collect synchronization information (as well as other data). There is also the tool, Harmony, which instruments the LLVM IR to measure similar information.

I will recap the three components that you would require to write your own LLVM Pass.

First, while most synchronization control relies on atomic operations, these operations are in assembly and often sit within other libraries. As you are not tracking the execution of each assembly instruction, you will instead need to fall back on the names of functions, such as pthread_mutex_lock or sem_wait.

Second, having identified the synchronization control operations, the LLVM pass will need to insert the necessary instrumentation to record the vital information about this synchronization operation, such as its identifier (i.e. address) and a timestamp.

Third, the system will need additional code to process the synchronization records, as the instrumentation from the second component is within the critical section. Without this component, the results will be skewed by the instrumentation. There will still be an impact from the instrumentation.