Re: [PATCH 1/2] lkdtm: use atomic_t to replace count_lock

From: Arnd Bergmann
Date: Thu Feb 02 2012 - 08:52:31 EST


On Thursday 02 February 2012, Cong Wang wrote:
> > In order to have an atomic here, you have to use a loop around
> > atomic_cmpxchg, like
> >
> >
> > int old, new;
> > old = atomic_read(&count);
> > do {
> > new = old ? old - 1 : cpoint_count;
> > old = cmpxchg(&count, old, new);
> > } while (old != new);
> >
> > I suppose you could also just keep the spinlock and move lkdtm_do_action()
> > outside of it?
>
> If we still need spinlock, I think we don't need to bother atomic_t at all.

Yes, it's one or the other: If you use the cmpxchg loop, you don't need a
spinlock and vice versa.

Arnd
--
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/