Re: [PATCH] Detect and warn on atomic_inc/atomic_dec wrapping around

Ingo Molnar
2009-04-30T08:24:31Z

* Nikanth Karthikesan <knikanth@novell.com> 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@suse.de>

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