X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=contrib%2Ffsm_checker%2FLOCK_CHECK%2Flockclass.c;fp=contrib%2Ffsm_checker%2FLOCK_CHECK%2Flockclass.c;h=28e693cf566bba20706796bc79304322d71c5db1;hb=e09e518ebf18d490dbeb72c6358968af7d05d675;hp=0000000000000000000000000000000000000000;hpb=58f53b56557577b64911d0e7a2bba3fbb521d71d;p=lttv.git diff --git a/contrib/fsm_checker/LOCK_CHECK/lockclass.c b/contrib/fsm_checker/LOCK_CHECK/lockclass.c new file mode 100755 index 00000000..28e693cf --- /dev/null +++ b/contrib/fsm_checker/LOCK_CHECK/lockclass.c @@ -0,0 +1,84 @@ +#include "lockclass.h" + + + +struct lockclass * lockclass_Init(int CPU){ + struct lockclass *this = (struct lockclass *) g_malloc(sizeof(struct lockclass)); + lockclassContext_Init(&this->_fsm, this); + this->cpu = CPU; + this->local_stack = g_array_new(FALSE, FALSE, sizeof(struct lockstruct *)); + return this; +} + +struct lockstruct * lockstruct_Init(guint32 address){ + struct lockstruct *this = (struct lockstruct *) g_malloc(sizeof(struct lockstruct)); + this->lock_add = address; + this->taken_irqs_off=0; + this->taken_irqs_on=0; + this->hardirq_context=0; + return this; +} +int irq_check(struct lockclass *fsm, void *lock, int hardirqs_off, int hardirq_context){ + struct lockstruct *lock_check = (struct lockstruct *)lock; + if(hardirq_context) + lock_check->hardirq_context=hardirq_context; + if(hardirq_context && lock_check->taken_irqs_on) + return 1; + else if(lock_check->hardirq_context && !hardirqs_off) + return 1; + + return 0; +} +int empty_stack(struct lockclass *fsm){ + return fsm->local_stack->len; +} +int lock_held(struct lockclass *fsm, struct lockstruct *lock){ + //loop through stack & return 1 if found, 0 otherwise + int i, len=fsm->local_stack->len; + for(i=0; ilocal_stack, struct lockstruct *, i); + if(temp==lock) + return 1; + } + return 0; +} +int lock_held_on_behalf(struct lockclass *fsm, guint32 pid){ + //loop through stack & return 1 if a lock is being held on behalf of pid + int i, len=fsm->local_stack->len; + for(i=0; ilocal_stack, struct lockstruct *, i); + if(temp->pid==pid){ + return 1; + + } + } + return 0; +} +void lockclass_test(){ + //the smc compiler didn't generate the right code since no action was specified. (only a guard) + return; +} +void lockclass_warning(struct lockclass *fsm, char *msg, struct lockstruct *lock){ + printf("WARNING: %s\n", msg); + if(lock!=NULL) + printf("Lock 0x%x: taken_hard_irqs_on: %d, taken_hard_irqs_off %d, hardirq_context %d\n ", + lock->lock_add, lock->taken_irqs_on, lock->taken_irqs_off, lock->hardirq_context); +} +void lockclass_pushlock(struct lockclass *fsm, struct lockstruct *lock){ + g_array_append_val(fsm->local_stack, lock); +} + +void lockclass_poplock(struct lockclass *fsm, struct lockstruct *lock){ + int i; + struct lockstruct *temp; + for(i=fsm->local_stack->len-1; i>=0; i--){ + temp=g_array_index(fsm->local_stack, struct lockstruct *, i); + if(temp==lock){ + g_array_remove_index(fsm->local_stack, i); + break; + } + } +} +