
Hi all, I am diving into the RTS, trying to identify where an OSThread is created and where it is destroyed (join). The idea is to read some hardware counters when it is just created and read them again when it is about to be destroyed (for the time being let's ignore, for the sake of understanding, the possibility of thread migration and context switches). Does anyone know where to place these reads? As shown in the code below, I tried "printfing" within "workerStart" (in the places where I thought I should read the counters), but it doesn't seem to print the same throughout several executions. I mean, running with -N2 and forking 2 Haskell threads (plus the main one), sometimes I get three "Scheduling" and two "Unscheduling" and sometimes I get only one "Unscheduling" which discourages me about reading the counters there. Any clue about the reason? Probably "workerStart" is not the place to put it, I don't know. Any light thrown on it or any documentation to read would be welcome. Cheers Cristian Perfumo void workerStart(Task *task) { Capability *cap; // See startWorkerTask(). ACQUIRE_LOCK(&task->lock); cap = task->cap; RELEASE_LOCK(&task->lock); // set the thread-local pointer to the Task: taskEnter(task); printf ("Scheduling %p\n", task); // schedule() runs without a lock. cap = schedule(cap,task); printf ("Unscheduling %p\n", task); // On exit from schedule(), we have a Capability. releaseCapability(cap); workerTaskStop(task); }

Cristian Perfumo wrote:
I am diving into the RTS, trying to identify where an OSThread is created and where it is destroyed (join). The idea is to read some hardware counters when it is just created and read them again when it is about to be destroyed (for the time being let's ignore, for the sake of understanding, the possibility of thread migration and context switches). Does anyone know where to place these reads?
You might want to look at the PAPI stuff we have in GHC 6.8/HEAD, it's designed to measure hardware counters using the PAPI library. See rts/Papi.c, for example. We used this to get the measurements for our ICFP'07 paper on pointer tagging. Unfortunately it doesn't currently work with multiple threads, which sounds like what you want. But I bet it wouldn't be too hard to make it work. You probably want to hook into at least startWorkerTask/workerTaskStop, these are the entry/exit points for a "worker" OS thread (created and managed by the RTS). The other type of OS thread is a "bound" OS thread, created outside the RTS but making calls into Haskell code. The entry/exit points in this case are newBoundTask and boundTaskExiting. Cheers, Simon
participants (2)
-
Cristian Perfumo
-
Simon Marlow