Hello

I was looking at extending my Basic Block Vector generating plugin so that
it can handle multi-threaded apps.

To do this properly, it would be nice if it were possible to be notified
whenever a thread-change happened.  That way the statistics from the
various threads could be kept separately.

I looked through the code, and it didn't look like functionality existed
for this already.

I've attached a patch that implements registering a thread callback, but
I'm not sure if this is the best way to accomplish this.  Also, it does
make some intrusive changes to the core so I wanted to see what opinions
people have on if this is useful or not.

Thanks,

Vince


--- ./include/pub_tool_tooliface.h.orig 2008-02-20 17:22:26.000000000 -0500
+++ ./include/pub_tool_tooliface.h      2008-02-20 17:40:22.000000000 -0500
@@ -446,6 +446,8 @@
    function here. */
 extern void VG_(needs_final_IR_tidy_pass) ( IRSB*(*final_tidy)(IRSB*) );

+extern void VG_(needs_thread_callback) (void(*thread_switch) (ThreadId));
+

 /* ------------------------------------------------------------------ */
 /* Core events to track */
--- ./coregrind/m_scheduler/scheduler.c.orig    2008-02-20 17:29:34.000000000 
-0500
+++ ./coregrind/m_scheduler/scheduler.c 2008-02-20 17:47:42.000000000 -0500
@@ -945,6 +945,9 @@
         VG_(message)(Vg_DebugMsg, "thread %d: running for %d bbs",
                      tid, VG_(dispatch_ctr) - 1 );

+      if (VG_(needs).thread_callback)
+       (VG_(tdict).tool_thread_callback) ( tid );
+
       trc = run_thread_for_a_while ( tid );

       if (VG_(clo_trace_sched) && VG_(clo_verbosity) > 2) {
--- ./coregrind/m_tooliface.c.orig      2008-02-20 16:33:45.000000000 -0500
+++ ./coregrind/m_tooliface.c   2008-02-20 17:37:08.000000000 -0500
@@ -94,7 +94,8 @@
    .data_syms           = False,
    .malloc_replacement   = False,
    .xml_output           = False,
-   .final_IR_tidy_pass   = False
+   .final_IR_tidy_pass   = False,
+   .thread_callback      = False,
 };

 /* static */
@@ -217,6 +218,14 @@
    VG_(tdict).tool_handle_client_request = handle;
 }

+void VG_(needs_thread_callback)(
+   void(*thread_switch) (ThreadID)
+)
+{
+   VG_(needs).thread_callback = True;
+   VG_(tdict).tool_thread_callback=thread_switch;
+}
+
 void VG_(needs_syscall_wrapper)(
    void(*pre) (ThreadId, UInt),
    void(*post)(ThreadId, UInt, SysRes res)
--- ./coregrind/pub_core_tooliface.h.orig       2008-02-20 17:08:00.000000000 
-0500
+++ ./coregrind/pub_core_tooliface.h    2008-02-20 17:39:47.000000000 -0500
@@ -92,6 +92,7 @@
       Bool malloc_replacement;
       Bool xml_output;
       Bool final_IR_tidy_pass;
+      Bool thread_callback;
    }
    VgNeeds;

@@ -160,6 +161,9 @@
    // VG_(needs).final_IR_tidy_pass
    IRSB* (*tool_final_IR_tidy_pass)  (IRSB*);

+   // VG_(needs).thread_callback
+   void (*tool_thread_callback) (ThreadId);
+
    // -- Event tracking functions ------------------------------------
    void (*track_new_mem_startup)     (Addr, SizeT, Bool, Bool, Bool);
    void (*track_new_mem_stack_signal)(Addr, SizeT);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to