Re: [PATCH] lock assertion macros for 2.5.28

From: Robert Love (rml@tech9.net)
Date: Fri Jul 26 2002 - 14:38:37 EST


On Fri, 2002-07-26 at 10:42, Jesse Barnes wrote:

> Well, I had that in one version of the patch, but people didn't think
> it would be useful. Maybe you'd like to check out Oliver's comments
> at http://marc.theaimsgroup.com/?l=linux-kernel&m=102644431806734&w=2
> and respond? If there's demand for MUST_NOT_HOLD, I'd be happy to add
> it since it should be easy. But if you're using it to enforce lock
> ordering as Oliver suggests, then there are probably more robust
> solutions.

Two other suggestions you could implement are CAN_SLEEP and
CANNOT_SLEEP. You can implement them via the preempt_count.

Even if CONFIG_PREEMPT is not set, you will get preempt_count values
representing whether or not you are in an interrupt or softirq (and thus
atomic and cannot sleep). If CONFIG_PREEMPT is set, you get a counter
that represents exactly the atomicity of the code including locks held.

E.g.,

        #define CAN_SLEEP do { \
                assert(unlikely(!preempt_count())); \
        } while (0)

        #define CANNOT_SLEEP do { \
                assert(unlikely(preempt_count())); \
        } while (0)

This works great because after the IRQ changes in 2.5.28, preempt_count
is a universal "are we atomic" count.

        Robert Love

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



This archive was generated by hypermail 2b29 : Tue Jul 30 2002 - 14:00:24 EST