From: Arnd Bergmann <arnd@arndb.de>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Prarit Bhargava <prarit@redhat.com>,
"Greg Kroah-Hartman" <greg@kroah.com>,
Dave Young <dyoung@redhat.com>
Subject: Re: [PATCH 1/2] lkdtm: use atomic_t to replace count_lock
Date: Thu, 2 Feb 2012 14:55:38 +0000 [thread overview]
Message-ID: <201202021455.38966.arnd@arndb.de> (raw)
In-Reply-To: <4F2A9D56.3080102@gmail.com>
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
prev parent reply other threads:[~2012-02-02 14:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-01 6:58 [PATCH 1/2] lkdtm: use atomic_t to replace count_lock Cong Wang
2012-02-01 6:58 ` [PATCH 2/2] lkdtm: avoid calling sleeping functions in interrupt context Cong Wang
2012-02-01 15:27 ` [PATCH 1/2] lkdtm: use atomic_t to replace count_lock Arnd Bergmann
2012-02-02 13:33 ` Cong Wang
2012-02-02 13:44 ` Arnd Bergmann
2012-02-02 14:27 ` Cong Wang
2012-02-02 14:55 ` Arnd Bergmann [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201202021455.38966.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=akpm@linux-foundation.org \
--cc=dyoung@redhat.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=prarit@redhat.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.