Changeset 60898b6 in mainline for uspace/lib/c


Ignore:
Timestamp:
2010-11-05T16:17:48Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
08042bd
Parents:
a63ff7d (diff), a66e2993 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/lib/c
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/arch/abs32le/include/fibril.h

    ra63ff7d r60898b6  
    4444                (ctx)->pc = (uintptr_t) (_pc); \
    4545                (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
     46                (ctx)->fp = 0; \
    4647                (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \
    4748        } while (0)
     
    5354typedef struct {
    5455        uintptr_t sp;
     56        uintptr_t fp;
    5557        uintptr_t pc;
    5658        uintptr_t tls;
    5759} context_t;
     60
     61static inline uintptr_t context_get_fp(context_t *ctx)
     62{
     63        /* On real hardware, this function returns the frame pointer. */
     64        return ctx->fp;
     65}
    5866
    5967#endif
  • uspace/lib/c/arch/abs32le/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_abs32le__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * On real hardware this stores the registers which
    43  * need to be preserved during interupts.
    44  */
    45 typedef struct istate {
    46         uintptr_t ip;
    47         uintptr_t fp;
    48         uint32_t stack[];
    49 } istate_t;
    50 
    51 static inline uintptr_t istate_get_pc(istate_t *istate)
    52 {
    53         return istate->ip;
    54 }
    55 
    56 static inline uintptr_t istate_get_fp(istate_t *istate)
    57 {
    58         return istate->fp;
    59 }
     38#include <arch/istate.h>
    6039
    6140#endif
  • uspace/lib/c/arch/amd64/include/fibril.h

    ra63ff7d r60898b6  
    5656 */
    5757typedef struct {
    58     uint64_t sp;
    59     uint64_t pc;
    60    
    61     uint64_t rbx;
    62     uint64_t rbp;
     58        uint64_t sp;
     59        uint64_t pc;
    6360
    64     uint64_t r12;
    65     uint64_t r13;
    66     uint64_t r14;
    67     uint64_t r15;
     61        uint64_t rbx;
     62        uint64_t rbp;
    6863
    69     uint64_t tls;
     64        uint64_t r12;
     65        uint64_t r13;
     66        uint64_t r14;
     67        uint64_t r15;
     68
     69        uint64_t tls;
    7070} context_t;
     71
     72static inline uintptr_t context_get_fp(context_t *ctx)
     73{
     74        return ctx->rbp;
     75}
    7176
    7277#endif
  • uspace/lib/c/arch/amd64/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_amd64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint64_t rax;
    46         uint64_t rcx;
    47         uint64_t rdx;
    48         uint64_t rsi;
    49         uint64_t rdi;
    50         uint64_t r8;
    51         uint64_t r9;
    52         uint64_t r10;
    53         uint64_t r11;
    54         uint64_t rbp;
    55         uint64_t error_word;
    56         uint64_t rip;
    57         uint64_t cs;
    58         uint64_t rflags;
    59         uint64_t stack[]; /* Additional data on stack */
    60 } istate_t;
    61 
    62 static inline uintptr_t istate_get_pc(istate_t *istate)
    63 {
    64         return istate->rip;
    65 }
    66 
    67 static inline uintptr_t istate_get_fp(istate_t *istate)
    68 {
    69         return istate->rbp;
    70 }
     38#include <arch/istate.h>
    7139
    7240#endif
  • uspace/lib/c/arch/amd64/src/entry.s

    ra63ff7d r60898b6  
    4242        #
    4343        pushq $0
    44         mov %rsp, %rbp
     44        movq %rsp, %rbp
    4545       
    4646        # %rdi was deliberately chosen as the first argument is also in %rdi
  • uspace/lib/c/arch/amd64/src/fibril.S

    ra63ff7d r60898b6  
    4949        movq %rax, OFFSET_TLS(%rdi)
    5050               
    51         xorq %rax,%rax          # context_save returns 1
    52         incq %rax
     51        xorl %eax, %eax         # context_save returns 1
     52        incl %eax
    5353        ret
    5454
     
    6767        # Set thread local storage
    6868        movq OFFSET_TLS(%rdi), %rdi   # Set arg1 to TLS addr
    69         movq $1, %rax           # SYS_TLS_SET
     69        movl $1, %eax           # SYS_TLS_SET
    7070        syscall
    7171
    72         xorq %rax,%rax          # context_restore returns 0
     72        xorl %eax, %eax         # context_restore returns 0
    7373        ret
  • uspace/lib/c/arch/arm32/include/fibril.h

    ra63ff7d r60898b6  
    8686} context_t;
    8787
     88static inline uintptr_t context_get_fp(context_t *ctx)
     89{
     90        return ctx->fp;
     91}
     92
    8893
    8994#endif
  • uspace/lib/c/arch/arm32/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_arm32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t spsr;
    46         uint32_t sp;
    47         uint32_t lr;
    48 
    49         uint32_t r0;
    50         uint32_t r1;
    51         uint32_t r2;
    52         uint32_t r3;
    53         uint32_t r4;
    54         uint32_t r5;
    55         uint32_t r6;
    56         uint32_t r7;
    57         uint32_t r8;
    58         uint32_t r9;
    59         uint32_t r10;
    60         uint32_t fp;
    61         uint32_t r12;
    62 
    63         uint32_t pc;
    64 } istate_t;
    65 
    66 static inline uintptr_t istate_get_pc(istate_t *istate)
    67 {
    68         return istate->pc;
    69 }
    70 
    71 static inline uintptr_t istate_get_fp(istate_t *istate)
    72 {
    73         return istate->fp;
    74 }
     38#include <arch/istate.h>
    7539
    7640#endif
  • uspace/lib/c/arch/ia32/include/fibril.h

    ra63ff7d r60898b6  
    6767} context_t;
    6868
     69static inline uintptr_t context_get_fp(context_t *ctx)
     70{
     71        return ctx->ebp;
     72}
     73
    6974#endif
    7075
  • uspace/lib/c/arch/ia32/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_ia32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t eax;
    46         uint32_t ecx;
    47         uint32_t edx;
    48         uint32_t ebp;
    49 
    50         uint32_t gs;
    51         uint32_t fs;
    52         uint32_t es;
    53         uint32_t ds;
    54 
    55         uint32_t error_word;
    56         uint32_t eip;
    57         uint32_t cs;
    58         uint32_t eflags;
    59         uint32_t stack[];
    60 } istate_t;
    61 
    62 static inline uintptr_t istate_get_pc(istate_t *istate)
    63 {
    64         return istate->eip;
    65 }
    66 
    67 static inline uintptr_t istate_get_fp(istate_t *istate)
    68 {
    69         return istate->ebp;
    70 }
     38#include <arch/istate.h>
    7139
    7240#endif
  • uspace/lib/c/arch/ia64/include/fibril.h

    ra63ff7d r60898b6  
    130130} context_t;
    131131
     132static inline uintptr_t context_get_fp(context_t *ctx)
     133{
     134        return 0;       /* FIXME */
     135}
     136
    132137#endif
    133138
  • uspace/lib/c/arch/ia64/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_ia64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
    47 
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
    53 
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     38#include <arch/istate.h>
    5939
    6040#endif
  • uspace/lib/c/arch/mips32/include/fibril.h

    ra63ff7d r60898b6  
    8585} context_t;
    8686
     87static inline uintptr_t context_get_fp(context_t *ctx)
     88{
     89        return ctx->sp;
     90}
     91
    8792#endif
    8893
  • uspace/lib/c/arch/mips32/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_mips32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t at;
    46         uint32_t v0;
    47         uint32_t v1;
    48         uint32_t a0;
    49         uint32_t a1;
    50         uint32_t a2;
    51         uint32_t a3;
    52         uint32_t t0;
    53         uint32_t t1;
    54         uint32_t t2;
    55         uint32_t t3;
    56         uint32_t t4;
    57         uint32_t t5;
    58         uint32_t t6;
    59         uint32_t t7;
    60         uint32_t t8;
    61         uint32_t t9;
    62         uint32_t gp;
    63         uint32_t sp;
    64         uint32_t ra;
    65 
    66         uint32_t lo;
    67         uint32_t hi;
    68 
    69         uint32_t status; /* cp0_status */
    70         uint32_t epc; /* cp0_epc */
    71         uint32_t k1; /* We use it as thread-local pointer */
    72 } istate_t;
    73 
    74 static inline uintptr_t istate_get_pc(istate_t *istate)
    75 {
    76         return istate->epc;
    77 }
    78 
    79 static inline uintptr_t istate_get_fp(istate_t *istate)
    80 {
    81         /* TODO */
    82         return 0;
    83 }
     38#include <arch/istate.h>
    8439
    8540#endif
  • uspace/lib/c/arch/ppc32/include/fibril.h

    ra63ff7d r60898b6  
    7878} __attribute__ ((packed)) context_t;
    7979
     80static inline uintptr_t context_get_fp(context_t *ctx)
     81{
     82        return ctx->sp;
     83}
     84
    8085#endif
    8186
  • uspace/lib/c/arch/sparc64/include/fibril.h

    ra63ff7d r60898b6  
    7777} context_t;
    7878
     79static inline uintptr_t context_get_fp(context_t *ctx)
     80{
     81        return ctx->sp + STACK_BIAS;
     82}
     83
    7984#endif
    8085
  • uspace/lib/c/arch/sparc64/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_sparc64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
    47 
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
    53 
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     38#include <arch/istate.h>
    5939
    6040#endif
  • uspace/lib/c/generic/fibril.c

    ra63ff7d r60898b6  
    275275        fibril->func = func;
    276276        fibril->arg = arg;
     277
     278        fibril->waits_for = NULL;
    277279       
    278280        context_save(&fibril->ctx);
  • uspace/lib/c/generic/fibril_synch.c

    ra63ff7d r60898b6  
    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 void print_deadlock(fibril_owner_info_t *oi)
     61{
     62        fibril_t *f = (fibril_t *) fibril_get_id();
     63
     64        printf("Deadlock detected.\n");
     65        stacktrace_print();
     66
     67        printf("Fibril %p waits for primitive %p.\n", f, oi);
     68
     69        while (oi && oi->owned_by) {
     70                printf("Primitive %p is owned by fibril %p.\n",
     71                    oi, oi->owned_by);
     72                if (oi->owned_by == f)
     73                        break;
     74                stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx),
     75                    oi->owned_by->ctx.pc);
     76                printf("Fibril %p waits for primitive %p.\n",
     77                     oi->owned_by, oi->owned_by->waits_for);
     78                oi = oi->owned_by->waits_for;
     79        }
     80}
     81
     82
     83static void check_for_deadlock(fibril_owner_info_t *oi)
     84{
     85        while (oi && oi->owned_by) {
     86                if (oi->owned_by == (fibril_t *) fibril_get_id()) {
     87                        print_deadlock(oi);
     88                        abort();
     89                }
     90                oi = oi->owned_by->waits_for;
     91        }
     92}
     93
     94
    5895void fibril_mutex_initialize(fibril_mutex_t *fm)
    5996{
     97        fm->oi.owned_by = NULL;
    6098        fm->counter = 1;
    6199        list_initialize(&fm->waiters);
     
    64102void fibril_mutex_lock(fibril_mutex_t *fm)
    65103{
     104        fibril_t *f = (fibril_t *) fibril_get_id();
     105
    66106        futex_down(&async_futex);
    67107        if (fm->counter-- <= 0) {
     
    73113                link_initialize(&wdata.wu_event.link);
    74114                list_append(&wdata.wu_event.link, &fm->waiters);
     115                check_for_deadlock(&fm->oi);
     116                f->waits_for = &fm->oi;
    75117                fibril_switch(FIBRIL_TO_MANAGER);
    76118        } else {
     119                fm->oi.owned_by = f;
    77120                futex_up(&async_futex);
    78121        }
     
    86129        if (fm->counter > 0) {
    87130                fm->counter--;
     131                fm->oi.owned_by = (fibril_t *) fibril_get_id();
    88132                locked = true;
    89133        }
     
    99143                link_t *tmp;
    100144                awaiter_t *wdp;
     145                fibril_t *f;
    101146       
    102147                assert(!list_empty(&fm->waiters));
     
    105150                wdp->active = true;
    106151                wdp->wu_event.inlist = false;
     152
     153                f = (fibril_t *) wdp->fid;
     154                fm->oi.owned_by = f;
     155                f->waits_for = NULL;
     156
    107157                list_remove(&wdp->wu_event.link);
    108158                fibril_add_ready(wdp->fid);
    109159                optimize_execution_power();
     160        } else {
     161                fm->oi.owned_by = NULL;
    110162        }
    111163}
     
    120172void fibril_rwlock_initialize(fibril_rwlock_t *frw)
    121173{
     174        frw->oi.owned_by = NULL;
    122175        frw->writers = 0;
    123176        frw->readers = 0;
     
    138191                f->flags &= ~FIBRIL_WRITER;
    139192                list_append(&wdata.wu_event.link, &frw->waiters);
     193                check_for_deadlock(&frw->oi);
     194                f->waits_for = &frw->oi;
    140195                fibril_switch(FIBRIL_TO_MANAGER);
    141196        } else {
     
    147202void fibril_rwlock_write_lock(fibril_rwlock_t *frw)
    148203{
     204        fibril_t *f = (fibril_t *) fibril_get_id();
     205       
    149206        futex_down(&async_futex);
    150207        if (frw->writers || frw->readers) {
    151                 fibril_t *f = (fibril_t *) fibril_get_id();
    152208                awaiter_t wdata;
    153209
     
    158214                f->flags |= FIBRIL_WRITER;
    159215                list_append(&wdata.wu_event.link, &frw->waiters);
     216                check_for_deadlock(&frw->oi);
     217                f->waits_for = &frw->oi;
    160218                fibril_switch(FIBRIL_TO_MANAGER);
    161219        } else {
     220                frw->oi.owned_by = f;
    162221                frw->writers++;
    163222                futex_up(&async_futex);
     
    177236       
    178237        assert(!frw->readers && !frw->writers);
     238       
     239        frw->oi.owned_by = NULL;
    179240       
    180241        while (!list_empty(&frw->waiters)) {
     
    185246                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    186247                f = (fibril_t *) wdp->fid;
     248               
     249                f->waits_for = NULL;
    187250               
    188251                if (f->flags & FIBRIL_WRITER) {
     
    194257                        fibril_add_ready(wdp->fid);
    195258                        frw->writers++;
     259                        frw->oi.owned_by = f;
    196260                        optimize_execution_power();
    197261                        break;
  • uspace/lib/c/include/fibril.h

    ra63ff7d r60898b6  
    4848#define FIBRIL_WRITER      2
    4949
     50struct fibril;
     51
     52typedef struct {
     53        struct fibril *owned_by;
     54} fibril_owner_info_t;
     55
    5056typedef enum {
    5157        FIBRIL_PREEMPT,
     
    6874        int retval;
    6975        int flags;
     76
     77        fibril_owner_info_t *waits_for;
    7078} fibril_t;
    7179
  • uspace/lib/c/include/fibril_synch.h

    ra63ff7d r60898b6  
    4343
    4444typedef struct {
     45        fibril_owner_info_t oi;         /* Keep this the first thing. */
    4546        int counter;
    4647        link_t waiters;
     
    4950#define FIBRIL_MUTEX_INITIALIZER(name) \
    5051        { \
     52                .oi = { \
     53                        .owned_by = NULL \
     54                }, \
    5155                .counter = 1, \
    5256                .waiters = { \
     
    6064
    6165typedef struct {
     66        fibril_owner_info_t oi; /* Keep this the first thing. */
    6267        unsigned writers;
    6368        unsigned readers;
     
    6772#define FIBRIL_RWLOCK_INITIALIZER(name) \
    6873        { \
     74                .oi = { \
     75                        .owned_by = NULL \
     76                }, \
    6977                .readers = 0, \
    7078                .writers = 0, \
Note: See TracChangeset for help on using the changeset viewer.