On Wed, 2017-06-21 at 19:17 +0000, Mike Lui wrote:
> I posted this on the valgrind-dev mailing list a while back but didn't
> receive a response. Hopefully some users have some input.
> 
> 
> I'm working on a project that leverages Callgrind to generate VEX IR
> traces. I'm using Valgrind 3.12.0.
> I also use Callgrind's infrastructure to detect when Valgrind switches
> thread contexts, however I'm getting unexpected behavior.
> 
> 
> It looks like the best place to detect a thread context switch
> in Callgrind is in CLG_(setup_bbcc) in bbcc.c  (line 561):
> 
> 
>   /* This is needed because thread switches can not reliable be
> tracked
>    * with callback CLG_(run_thread) only: we have otherwise no way to
> get
>    * the thread ID after a signal handler returns.
>    * This could be removed again if that bug is fixed in Valgrind.
>    * This is in the hot path but hopefully not to costly.
>    */
>   tid = VG_(get_running_tid)();
> #if 1
>   /* CLG_(switch_thread) is a no-op when tid is equal to
> CLG_(current_tid).
>    * As this is on the hot path, we only call CLG_(switch_thread)(tid)
>    * if tid differs from the CLG_(current_tid).
>    */
>   if (UNLIKELY(tid != CLG_(current_tid)))
>      CLG_(switch_thread)(tid);
> 
> 
> The above is called every instrumented basic block.
> I've noticed strange behavior, where a thread switch would not always
> be detected.
> I detected the unexpected behavior with the following modifications:
> 
> 
> To investigate further, I modified the above:
> - if (UNLIKELY(tid != CLG_(current_tid)))
> 
> + if (UNLIKELY(tid != CLG_(current_tid))) {
>      CLG_(switch_thread)(tid);
> +    VG_(printf)("Thread switched to: %d\n", tid);
> + }
> 
Adding --trace-sched=yes might help to understand what happens.
Also, --trace-signals=yes might be useful if the problem is signal
related.

Philippe




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to