linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
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, 02 Feb 2012 22:27:34 +0800	[thread overview]
Message-ID: <4F2A9D56.3080102@gmail.com> (raw)
In-Reply-To: <201202021344.19455.arnd@arndb.de>

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);
>>>        } 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.

Thanks.

  reply	other threads:[~2012-02-02 14:27 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 [this message]
2012-02-02 14:55         ` Arnd Bergmann

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=4F2A9D56.3080102@gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=dyoung@redhat.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prarit@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).