Re: [PATCH] Detect and warn on atomic_inc/atomic_dec wrappingaround
From: Ingo Molnar
Date: Thu Apr 30 2009 - 04:24:32 EST
* Nikanth Karthikesan <knikanth@xxxxxxxxxx> wrote:
> Add a debug option to detect and warn when the 32-bit atomic_t
> wraps around during atomic_inc and atomic_dec.
>
> Signed-off-by: Nikanth Karthikesan <knikanth@xxxxxxx>
hm, what's the motivation?
As a generic debug helper this is not appropriate i think - counts
can easily have a meaning when going negative as well. (we have no
signed-atomic primitives)
> static inline void atomic_inc(atomic_t *v)
> {
> +#if defined(CONFIG_ENABLE_WARN_ATOMIC_INC_WRAP)
> + WARN_ON(atomic_add_unless(v, 1, INT_MAX) == 0);
> +#else
> asm volatile(LOCK_PREFIX "incl %0"
> : "+m" (v->counter));
> +#endif
> }
also looks a bit ugly - this ugly #ifdef would spread into every
architecture.
If we want to restrict atomic_t value ranges like that then the
clean solution would be to add generic wrappers doing the debug
(once, in generic code), and renaming the arch primitives to
raw_atomic_inc() (etc), doing the lowlevel bits cleanly.
Do we really want this?
Ingo
--
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/