Skip to contentSkip to conversation

Help with 2.6.10 concurrency issue

DISCUSSION martin rogers 1 participant 1 message Feb 9, 2006

lore
Share & tools
lore
#0 lore raw

All,
I need help with a concurrency issue on 2.6.10. CONFIG_PREEMPT not set, but my code must run on both uni and SMP systems.

I have a function, that runs from a tastlet:

void readlist(unsigned long arg)
{
int flags;
my_type *entry, *n;

if (list_empty(&mylist.list)) return; list_for_each_entry_safe(entry, n, &mylist.list, list)

 {
       spin_lock_irqsave(&mylock, flags); // protect against intr
       list_del(&entry->list);
       spin_unlock_irqrestore(&mylock, flags);
       INIT_LIST_HEAD(&entry->list);
       do_stuff(entry);

}
}

And the func that puts things on the list:

void writeList(my_type *record)
{
spin_lock(&mylock);
list_add_tail(&record->list, &mylist.list);
spin_unlock(&mylock);
tasklet_schedule(&mytasklet.tlet);
}

Problem is, the function writeList can be called from a H/W intr, and a workqueue (and that intr could of course happen while either the workqueue or the tasklet is running, right?).

If I use spin_lock_irqsave in writeList, it protects against the intr but not the tasklet. If I use spin_lock_bh, I don't get protection from the intr I think; plus, I get :

Badness in local_bh_enable at kernel/softirq.c:142

when the intr runs (what does this mean?).

So, how can I protect my data (my list) from both intrs (calling writeList) and the tasklet (calling readList) while the workqueue is inside of writeList? Combination of spin_lock_irqsave and local_bh_disable inside writeList ?

Thanks to all,
Martin Rogers
Wind River