OSThreads in the RTS

Cristian Perfumo cperfumo at gmail.com
Sat Sep 22 11:18:19 EDT 2007

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.

Cristian Perfumo

workerStart(Task *task)
    Capability *cap;

    // See startWorkerTask().
    cap = task->cap;

    // set the thread-local pointer to the 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20070922/ed495f19/attachment.htm

More information about the Glasgow-haskell-users mailing list