Displaying a thread as blocked

  • Alexander Neundorf


    I'm trying to use TimeDoctor to visualize the behaviour of threads for our students lab.
    I don't find a way to get the right results.
    Scenario is this: At t=0 thread 1 locks mutex m1 and unlocks it again at t=5.
    At t=1 thread 2 locks m1 but is blocked because m1 is already locked. So m2 gets running at t=5 when t1 unlocks m1.

    With the following "code" I get two completely independent tasks, nothing's blocked:
    STA 0 101  0
    STO 0 101 50
    STA 0 102 20
    STO 0 102 30

    With this code I get some kind of "blocking", but as soon as thread 102 starts running it preempts thread 101, so 101 is blocked until time 30. I'd like to have thread 102 appear blocked from 20 to 30.
    STA 0 101  0
    STA 0 102 20
    STO 0 102 30
    STO 0 101 50

    Is there a way to get this behaviour ? The documentation I found is quite terse (tags.html, overview.html and the slides from CELF 2007), so that didn't help me in this regard.


    • CPeplinski

      CPeplinski - 2007-11-19

      From your description, I don't see so much of a TimeDoctor problem as a question about how the OS works.  Or are you saying that TimeDoctor reports something that seems to conflict with your knowledge of how the system is actually working?

      You don't mention what platform you are running on.  I suspect you are running on Linux.  Is that correct?  When running on the Nexperia platform, this stuff works well.  I am very familiar how it works on Nexperia.  I would like to learn more about how it works on Linux.


    • Alexander Neundorf

      The platform doesn't really matter in my case, I'm just trying to use TimeDoctor as a visualization tool for custom created tdi files.
      Right now I'm just trying manually to create a tdi file where you can see that one thread is blocked by some reason (because it is waiting for something, e.g. a mutex).

      Yes, this is on Linux but doesn't have anything to do with the kernel or anything.
      I'd like to create a library with C functions which can be called from a user application which will write a tdi file, in order to visualize the behaviour of a multithreaded application (without having to modify the kernel or libpthread).
      The idea is that if somebody calls e.g. pthread_cond_wait() he puts a tdi_task(id, BLOCKED) before that call, and if he comes back from that call something like tdi_task(id, RUNNING), which should then create a nice tdi file where you can easily see at which times threads where idle/running/blocked.

      I hope this makes it a bit more clear what I want to do.


    • Alexander Neundorf

      We'd also like to display things like deadlines in the task views. How are the chances that patches would be accepted ?


    • Martijn Rutten

      Martijn Rutten - 2008-01-13

      Hi Alex,

      I guess you either moved on to something else or found a way to resolve your problem. As far as I remember, the .tdi syntax assumes all traces increase monotonously in time. TimeDoctor assumes that a STA for a task on the same CPU means that the task interrupts the current running task (basically because it has a higher priority). So for your example, a correct trace would be:

      STA 0 101 0
      STO 0 101 50
      STA 0 102 50
      STO 0 102 .....

      which shows that task 101 only yields to 102 at time 50. Obviously this does not help you to show that task 102 was actually locked on the mutex...
      TimeDoctor allows you to show the locking of the semaphores (counting semaphores to be precise), which may help you to visualize the issue.

      As an alternative, TimeDoctor allows you to add colors to events (e.g. tasks) that you can use to visualize some specific event, for instance something like this (from the top of my head, not tested):

      NAM 0 123 MyMutex      # the name of a description ID 123
      DNM 0 123 Status       # TO ensure that mouse hover prints as "Status=Locked" for example
      STA 0 101 0            # start task 101
      STA 0 102 20           # start task 102, not really it is blocked
      DSC 3 456 5            # color the previous STA sample with color 5 to indicate it was blocked
      DSC 0 123 Blocked      # and add a descriptive text to the event "Locked" when the mouse hovers over it
      STO 0 102 30
      DSC 0 123 Unblocked
      STO 0 101 50
      STA 0 102 50
      DSC 3 456 0            # reset coloring

      You could show deadlines of tasks as 'events' using the OCC tags, e.g. (again, not tested, sorry):

      NAM 7 123 Deadlines
      DNM 0 123 Deadline
      STA 0 101 0   # start task 101
      STO 0 101 50  # staop task 101
      OCC 7 123 60  # deadline task 101
      DSC 0 123 Task101

      Hope this helps...


Log in to post a comment.