Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 1fa010c in mainline


Ignore:
Timestamp:
2010-10-19T20:12:14Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
12c38f5
Parents:
525df28
Message:

Implement simple deadlock detection for fibril mutexes.

The mechanism could be extended to rwlocks for the writer and first reader
cases. The current implementation will only build on ia32. In order to fix it,
we need a generic way to tell the frame pointer given fibril's ctx.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/fibril_synch.c

    r525df28 r1fa010c  
    4242#include <errno.h>
    4343#include <assert.h>
     44#include <stacktrace.h>
     45#include <stdlib.h>
    4446
    4547static void optimize_execution_power(void)
     
    5658}
    5759
     60static bool check_for_deadlock(fibril_owner_info_t *oi)
     61{
     62        while (oi && oi->owned_by) {
     63                if (oi->owned_by == (fibril_t *) fibril_get_id())
     64                        return true;
     65                oi = oi->owned_by->waits_for;
     66        }
     67
     68        return false;
     69}
     70
     71static void print_deadlock(fibril_owner_info_t *oi)
     72{
     73        fibril_t *f = (fibril_t *) fibril_get_id();
     74
     75        printf("Deadlock detected: ");
     76
     77        printf("Fibril %p waits for primitive %p.\n", f, oi);
     78        stacktrace_print();
     79
     80        while (oi && oi->owned_by) {
     81                printf(". ");
     82                printf("Primitive %p is owned by fibril %p.\n",
     83                    oi, oi->owned_by);
     84                stacktrace_print_fp_pc(oi->owned_by->ctx.ebp,
     85                    oi->owned_by->ctx.pc);
     86                if (oi->owned_by == f)
     87                        break;
     88                printf("Fibril %p waits for primitive %p.\n",
     89                     oi->owned_by, oi->owned_by->waits_for);
     90                oi = oi->owned_by->waits_for;
     91        }
     92
     93        abort();
     94}
     95
    5896void fibril_mutex_initialize(fibril_mutex_t *fm)
    5997{
     
    77115                list_append(&wdata.wu_event.link, &fm->waiters);
    78116
     117                if (check_for_deadlock(&fm->oi))
     118                        print_deadlock(&fm->oi);
    79119                f->waits_for = &fm->oi;
    80120
Note: See TracChangeset for help on using the changeset viewer.