The lock was needed to serialize writing to log file.
However, due to data races the lock can cause deadlock as well:
#0 0x00007f6f86cf2f25 in spinlock_lock (l=0x7f6f86f2bf08 <pmsg_lock>) at /home/la5/git/hpctoolkit/BUILD/../src/lib/prof-lean/spinlock.h:115
#1 0x00007f6f86cf34f7 in hpcrun_write_msg_to_log (echo_stderr=false, add_thread_id=true, tag=0x7f6f86d0efad "LINUX_PERF", fmt=0x7f6f86d0efe0 "buffer header t: %d, s: %d, head: %d, tail: %d",
box=0x7ffe9514a5e0) at ../../../../src/tool/hpcrun/messages/messages-async.c:238
#2 0x00007f6f86cf30d5 in hpcrun_pmsg (tag=0x7f6f86d0efad "LINUX_PERF", fmt=0x7f6f86d0efe0 "buffer header t: %d, s: %d, head: %d, tail: %d")
at ../../../../src/tool/hpcrun/messages/messages-async.c:154
#3 0x00007f6f86ce949e in read_perf_buffer (current=0x7f6f845d1050, mmap_info=0x7ffe9514a760) at ../../../../src/tool/hpcrun/sample-sources/perf/perf_mmap.c:298
#4 0x00007f6f86ce8c94 in perf_event_handler (sig=29, siginfo=0x7ffe9514aab0, context=0x7ffe9514a980) at ../../../../src/tool/hpcrun/sample-sources/perf/linux_perf.c:1269
#5 0x00007f6f86ab23dd in monitor_signal_handler (sig=29, info=0x7ffe9514aab0, context=0x7ffe9514a980) at ../../libmonitor/src/signal.c:213
#6
#7 0x00007f6f8636681d in nanosleep () from /lib64/libc.so.6
#8 0x00007f6f86398534 in usleep () from /lib64/libc.so.6
#9 0x00007f6f86ab9a8a in monitor_thread_shootdown () at ../../libmonitor/src/pthread.c:603
#10 0x00007f6f86ab9079 in monitor_end_process_fcn (how=1) at ../../libmonitor/src/main.c:298
#11 0x00007f6f86ab930d in monitor_main (argc=, argv=0x7ffe9514b2b8, envp=0x7ffe9514b2c8) at ../../libmonitor/src/main.c:503
#12 0x00007f6f862ba401 in __libc_start_main () from /lib64/libc.so.6
#13 0x00007f6f86ab899e in __libc_start_main (main=, argc=1, argv=0x7ffe9514b2b8, init=0x400960 <__libc_csu_init>, fini=0x4009d0 <__libc_csu_fini>,
rtld_fini=0x7f6f86f48e50 <_dl_fini>, stack_end=0x7ffe9514b2a8) at ../../libmonitor/src/main.c:539
#14 0x000000000040074a in _start ()
There is no need to have lock in writing a file. If the writing is not in ordered, that's fine. We should add loop around async write of log messages instead:
spinlock_lock(&pmsg_lock);
// use write to logfile file descriptor, instead of fprintf stuff
//
write(messages_logfile_fd(), buf, strlen(buf));
msgs_out++;
spinlock_unlock(&pmsg_lock);
The lock was needed to serialize writing to log file.
However, due to data races the lock can cause deadlock as well:
#0 0x00007f6f86cf2f25 in spinlock_lock (l=0x7f6f86f2bf08 <pmsg_lock>) at /home/la5/git/hpctoolkit/BUILD/../src/lib/prof-lean/spinlock.h:115
#1 0x00007f6f86cf34f7 in hpcrun_write_msg_to_log (echo_stderr=false, add_thread_id=true, tag=0x7f6f86d0efad "LINUX_PERF", fmt=0x7f6f86d0efe0 "buffer header t: %d, s: %d, head: %d, tail: %d",
box=0x7ffe9514a5e0) at ../../../../src/tool/hpcrun/messages/messages-async.c:238
#2 0x00007f6f86cf30d5 in hpcrun_pmsg (tag=0x7f6f86d0efad "LINUX_PERF", fmt=0x7f6f86d0efe0 "buffer header t: %d, s: %d, head: %d, tail: %d")
at ../../../../src/tool/hpcrun/messages/messages-async.c:154
#3 0x00007f6f86ce949e in read_perf_buffer (current=0x7f6f845d1050, mmap_info=0x7ffe9514a760) at ../../../../src/tool/hpcrun/sample-sources/perf/perf_mmap.c:298
#4 0x00007f6f86ce8c94 in perf_event_handler (sig=29, siginfo=0x7ffe9514aab0, context=0x7ffe9514a980) at ../../../../src/tool/hpcrun/sample-sources/perf/linux_perf.c:1269
#5 0x00007f6f86ab23dd in monitor_signal_handler (sig=29, info=0x7ffe9514aab0, context=0x7ffe9514a980) at ../../libmonitor/src/signal.c:213
#6
#7 0x00007f6f8636681d in nanosleep () from /lib64/libc.so.6
#8 0x00007f6f86398534 in usleep () from /lib64/libc.so.6
#9 0x00007f6f86ab9a8a in monitor_thread_shootdown () at ../../libmonitor/src/pthread.c:603
#10 0x00007f6f86ab9079 in monitor_end_process_fcn (how=1) at ../../libmonitor/src/main.c:298
#11 0x00007f6f86ab930d in monitor_main (argc=, argv=0x7ffe9514b2b8, envp=0x7ffe9514b2c8) at ../../libmonitor/src/main.c:503
#12 0x00007f6f862ba401 in __libc_start_main () from /lib64/libc.so.6
#13 0x00007f6f86ab899e in __libc_start_main (main=, argc=1, argv=0x7ffe9514b2b8, init=0x400960 <__libc_csu_init>, fini=0x4009d0 <__libc_csu_fini>,
rtld_fini=0x7f6f86f48e50 <_dl_fini>, stack_end=0x7ffe9514b2a8) at ../../libmonitor/src/main.c:539
#14 0x000000000040074a in _start ()
There is no need to have lock in writing a file. If the writing is not in ordered, that's fine. We should add loop around async write of log messages instead:
spinlock_lock(&pmsg_lock);
// use write to logfile file descriptor, instead of fprintf stuff
//
write(messages_logfile_fd(), buf, strlen(buf));
msgs_out++;
spinlock_unlock(&pmsg_lock);