Help with 2.6.10 concurrency issue

From: martin rogers
Date: Thu Feb 09 2006 - 16:06:24 EST


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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/