lkml.org 
[lkml]   [2012]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 1/2] lkdtm: use atomic_t to replace count_lock
Date
On Thursday 02 February 2012, Cong Wang wrote:
> On 02/02/2012 09:44 PM, Arnd Bergmann wrote:
> > 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);

^^^^^^^
I guess I meant "new = cmpxchg(...)" here, sorry.

> >>> } 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.
> >
>
> The cmpxchg loop is for comparing and assigning to 'count', but still
> there is a printk() above that needs to read 'count'. Combining these
> two operations means we have to use a spinlock, correct? Because there
> is a chance that another process could change 'count' in between.

No, you can just print the value of "old" in the above example,
which was atomically read.

Arnd


\
 
 \ /
  Last update: 2012-02-02 15:57    [W:0.130 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site