- Rename the event to 'thread_runstate'.
- Add arguments: pass also a boolean indicating whether the thread
is running or stopping, and a 64-bit int showing how many blocks
overall have run, so tools can make a rough estimate of workload.
The boolean allows tools to see threads starting and stopping.
Prior to this, de-schedule events were invisible to tools.
- Call the callback (hand the event to tools) just before client
code is run, and again immediately after it stops running. This
should give correct sequencing w.r.t posting of thread creation/
destruction events.
In order to make callgrind work without complex changes, I added a
simple impedance-matching function 'clg_thread_runstate_callback'
which hands thread-run events onwards to CLG_(thread_run).
Use this new 'thread_runstate' with care: it will be called before
and after every translation, which means it will be called ~500k
times in a startup of firefox. So the callback needs to be fast.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6413
/*--- Setup ---*/
/*--------------------------------------------------------------------*/
+static void clg_thread_runstate_callback ( ThreadId tid,
+ Bool is_running,
+ ULong blocks_done )
+{
+ if (0)
+ VG_(printf)("%d %c %llu\n",
+ (Int)tid, is_running ? 'R' : 's', blocks_done);
+ /* Simply call onwards to CLG_(run_thread). Maybe this can be
+ simplified later? */
+ if (is_running)
+ CLG_(run_thread)( tid );
+}
+
static
void CLG_(post_clo_init)(void)
{
VG_(needs_syscall_wrapper)(CLG_(pre_syscalltime),
CLG_(post_syscalltime));
- VG_(track_thread_run) ( & CLG_(run_thread) );
+ VG_(track_thread_runstate) ( & clg_thread_runstate_callback );
VG_(track_pre_deliver_signal) ( & CLG_(pre_signal) );
VG_(track_post_deliver_signal) ( & CLG_(post_signal) );
VG_(sprintf)(buf, " acquired lock (%s)", who);
print_sched_event(tid, buf);
}
-
- // While thre modeling is disable, issue thread_run events here
- // VG_(tm_thread_switchto)(tid);
- VG_TRACK( thread_run, tid );
}
/*
VG_(printf)("\n");
}
+ // Tell the tool this thread is about to run client code
+ VG_TRACK( thread_runstate, tid, True, bbs_done );
+
vg_assert(VG_(in_generated_code) == False);
VG_(in_generated_code) = True;
vg_assert(done_this_time >= 0);
bbs_done += (ULong)done_this_time;
+ // Tell the tool this thread has stopped running client code
+ VG_TRACK( thread_runstate, tid, False, bbs_done );
+
return trc;
}
volatile Int jumped;
volatile ThreadState* tst;
volatile UWord argblock[4];
+ volatile UInt retval;
/* Paranoia */
vg_assert(VG_(is_valid_tid)(tid));
argblock[2] = 0; /* next guest IP is written here */
argblock[3] = 0; /* guest state ptr afterwards is written here */
+ // Tell the tool this thread is about to run client code
+ VG_TRACK( thread_runstate, tid, True, bbs_done );
+
vg_assert(VG_(in_generated_code) == False);
VG_(in_generated_code) = True;
vg_assert(argblock[2] == 0); /* next guest IP was not written */
vg_assert(argblock[3] == 0); /* trc was not written */
block_signals(tid);
- return VG_TRC_FAULT_SIGNAL;
+ retval = VG_TRC_FAULT_SIGNAL;
} else {
/* store away the guest program counter */
VG_(set_IP)( tid, argblock[2] );
if (argblock[3] == argblock[1])
/* the guest state pointer afterwards was unchanged */
- return VG_TRC_BORING;
+ retval = VG_TRC_BORING;
else
- return (UInt)argblock[3];
+ retval = (UInt)argblock[3];
}
+
+ bbs_done++;
+
+ // Tell the tool this thread has stopped running client code
+ VG_TRACK( thread_runstate, tid, False, bbs_done );
+
+ return retval;
}
DEF(track_post_reg_write_clientcall_return, ThreadId, OffT, SizeT, Addr)
-DEF(track_thread_run, ThreadId)
+DEF(track_thread_runstate, ThreadId, Bool, ULong)
DEF(track_post_thread_create, ThreadId, ThreadId)
DEF(track_post_thread_join, ThreadId, ThreadId)
void (*track_post_reg_write)(CorePart, ThreadId, OffT, SizeT);
void (*track_post_reg_write_clientcall_return)(ThreadId, OffT, SizeT, Addr);
- void (*track_thread_run)(ThreadId);
+ void (*track_thread_runstate)(ThreadId, Bool, ULong);
void (*track_post_thread_create)(ThreadId, ThreadId);
void (*track_post_thread_join) (ThreadId, ThreadId);
/* Scheduler events (not exhaustive) */
-void VG_(track_thread_run)(void(*f)(ThreadId tid));
+
+/* Called when 'tid' starts or stops running client code blocks.
+ Gives the total dispatched block count at that event. Note, this
+ is not the same as 'tid' holding the BigLock: a thread can hold the
+ lock for other purposes (making translations, etc) yet not be
+ running client blocks. Obviously though, a thread must hold the
+ lock in order to run client code blocks, so the times bracketed by
+ thread_runstate(tid, True, ..) .. thread_runstate(tid, False, ..)
+ are a subset of the times when 'tid' holds the cpu lock.
+*/
+void VG_(track_thread_runstate)(
+ void(*f)(ThreadId tid, Bool running, ULong blocks_dispatched)
+ );
/* Thread events (not exhaustive)