Minres / SystemC-Components

A SystemC productivity library: https://minres.github.io/SystemC-Components/
https://www.minres.com/#opensource
Apache License 2.0
81 stars 21 forks source link

logging.h is not thread safe #18

Closed staskau closed 3 years ago

staskau commented 3 years ago

After updating the SCC lib to the latest version, ThreadSanitizer complains about data races like this one: https://jenkins.minres.com/blue/organizations/jenkins/Raven-Tests/detail/Raven-Tests/101/pipeline


[2021-06-09T13:09:01.633Z] WARNING: ThreadSanitizer: data race (pid=7968)

[2021-06-09T13:09:01.633Z]   Write of size 4 at 0x55a30515d360 by thread T2:

[2021-06-09T13:09:01.633Z]     #0 CLIParser::CLIParser(int, char**) /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/CLIParser.cpp:103 (dual_hifive_vp_mt+0x26d1d1)

[2021-06-09T13:09:01.633Z]     #1 top(int, char**, bool) /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/dual_hifive_vp_mt.cpp:78 (dual_hifive_vp_mt+0x23de1b)

[2021-06-09T13:09:01.633Z]     #2 sc_main /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/dual_hifive_vp_mt.cpp:190 (dual_hifive_vp_mt+0x23f3ff)

[2021-06-09T13:09:01.633Z]     #3 sc_elab_and_sim /var/jenkins_home/workspace/Raven-Tests@3/Raven/Minres-SystemC/src/sysc/kernel/sc_main_main.cpp:89 (libsystemc.so.2.3+0x3c3078)

[2021-06-09T13:09:01.633Z]     #4 int std::__invoke_impl<int, int (*)(int, char**), int, char**>(std::__invoke_other, int (*&&)(int, char**), int&&, char**&&) <null> (dual_hifive_vp_mt+0x24d1be)

[2021-06-09T13:09:01.633Z]     #5 std::__invoke_result<int (*)(int, char**), int, char**>::type std::__invoke<int (*)(int, char**), int, char**>(int (*&&)(int, char**), int&&, char**&&) <null> (dual_hifive_vp_mt+0x24d016)

[2021-06-09T13:09:01.633Z]     #6 int std::thread::_Invoker<std::tuple<int (*)(int, char**), int, char**> >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) <null> (dual_hifive_vp_mt+0x24ce9e)

[2021-06-09T13:09:01.633Z]     #7 std::thread::_Invoker<std::tuple<int (*)(int, char**), int, char**> >::operator()() <null> (dual_hifive_vp_mt+0x24cdf1)

[2021-06-09T13:09:01.633Z]     #8 std::thread::_State_impl<std::thread::_Invoker<std::tuple<int (*)(int, char**), int, char**> > >::_M_run() <null> (dual_hifive_vp_mt+0x24cc88)

[2021-06-09T13:09:01.633Z]     #9 <null> <null> (libstdc++.so.6+0xd6d83)

[2021-06-09T13:09:01.633Z] 

[2021-06-09T13:09:01.633Z]   Previous write of size 4 at 0x55a30515d360 by thread T1:

[2021-06-09T13:09:01.633Z]     #0 CLIParser::CLIParser(int, char**) /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/CLIParser.cpp:103 (dual_hifive_vp_mt+0x26d1d1)

[2021-06-09T13:09:01.633Z]     #1 top(int, char**, bool) /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/dual_hifive_vp_mt.cpp:78 (dual_hifive_vp_mt+0x23de1b)

[2021-06-09T13:09:01.633Z]     #2 sc_main /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/dual_hifive_vp_mt.cpp:188 (dual_hifive_vp_mt+0x23f397)

[2021-06-09T13:09:01.633Z]     #3 sc_elab_and_sim /var/jenkins_home/workspace/Raven-Tests@3/Raven/Minres-SystemC/src/sysc/kernel/sc_main_main.cpp:89 (libsystemc.so.2.3+0x3c3078)

[2021-06-09T13:09:01.633Z]     #4 int std::__invoke_impl<int, int (*)(int, char**), int, char**>(std::__invoke_other, int (*&&)(int, char**), int&&, char**&&) <null> (dual_hifive_vp_mt+0x24d1be)

[2021-06-09T13:09:01.633Z]     #5 std::__invoke_result<int (*)(int, char**), int, char**>::type std::__invoke<int (*)(int, char**), int, char**>(int (*&&)(int, char**), int&&, char**&&) <null> (dual_hifive_vp_mt+0x24d016)

[2021-06-09T13:09:01.633Z]     #6 int std::thread::_Invoker<std::tuple<int (*)(int, char**), int, char**> >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) <null> (dual_hifive_vp_mt+0x24ce9e)

[2021-06-09T13:09:01.633Z]     #7 std::thread::_Invoker<std::tuple<int (*)(int, char**), int, char**> >::operator()() <null> (dual_hifive_vp_mt+0x24cdf1)

[2021-06-09T13:09:01.633Z]     #8 std::thread::_State_impl<std::thread::_Invoker<std::tuple<int (*)(int, char**), int, char**> > >::_M_run() <null> (dual_hifive_vp_mt+0x24cc88)

[2021-06-09T13:09:01.633Z]     #9 <null> <null> (libstdc++.so.6+0xd6d83)

[2021-06-09T13:09:01.633Z] 

[2021-06-09T13:09:01.633Z]   Location is global 'logging::Log<logging::Output2FILE<logging::DEFAULT> >::reporting_level()::reportingLevel' of size 4 at 0x55a30515d360 (dual_hifive_vp_mt+0x000000731360)

[2021-06-09T13:09:01.633Z] 

[2021-06-09T13:09:01.633Z]   Thread T2 (tid=7972, running) created by main thread at:

[2021-06-09T13:09:01.633Z]     #0 pthread_create <null> (libtsan.so.0+0x5ea99)

[2021-06-09T13:09:01.633Z]     #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xd7048)

[2021-06-09T13:09:01.633Z]     #2 main /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/dual_hifive_vp_mt.cpp:204 (dual_hifive_vp_mt+0x23f53c)

[2021-06-09T13:09:01.633Z] 

[2021-06-09T13:09:01.633Z]   Thread T1 (tid=7971, running) created by main thread at:

[2021-06-09T13:09:01.633Z]     #0 pthread_create <null> (libtsan.so.0+0x5ea99)

[2021-06-09T13:09:01.633Z]     #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xd7048)

[2021-06-09T13:09:01.633Z]     #2 main /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/dual_hifive_vp_mt.cpp:203 (dual_hifive_vp_mt+0x23f521)

[2021-06-09T13:09:01.633Z] 

[2021-06-09T13:09:01.633Z] SUMMARY: ThreadSanitizer: data race /var/jenkins_home/workspace/Raven-Tests@3/RAVEN-Validation/platform/src/CLIParser.cpp:103 in CLIParser::CLIParser(int, char**)
eyck commented 3 years ago

Try with 50f086c

staskau commented 3 years ago

with 50f086c SCC does not compile:

scc/src/common/util/logging.h:122:39: error: use of deleted function ‘std::atomic<_Tp>::atomic(const std::atomic<_Tp>&) [with _Tp = logging::log_level]’
  122 |         static std::atomic<log_level> reportingLevel = WARNING;

the build error can be fixed by initializing reportingLevel as follows: static std::atomic<log_level> reportingLevel{WARNING};

However the data race is still present (see attached log file) raven_xspn_multithread.log