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);
}