From: Peter Zijlstra <peterz@infradead.org>
To: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>,
mingo@kernel.org, prarit@redhat.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH -tip] fix race between stop_two_cpus and stop_cpus
Date: Fri, 1 Nov 2013 15:24:04 +0100 [thread overview]
Message-ID: <20131101142404.GG19466@laptop.lan> (raw)
In-Reply-To: <20131101134424.GA32685@suse.de>
On Fri, Nov 01, 2013 at 01:44:24PM +0000, Mel Gorman wrote:
> Ok, I see your point now but still wonder if this is too specialised
> for what we are trying to do. Could it have been done with a read-write
> semaphore with the global stop_cpus taking it for write and stop_two_cpus
> taking it for read?
rwsem for read is still global state.. That said it should be fairly
easy to use lglock for this.
Or write it with spinlocks like:
DEFINE_PER_CPU(spinlock_t, local_lock);
DEFINE_PER_CPU(int, have_global);
spinlock_t global_lock;
void local_lock(void)
{
preempt_disable();
spin_lock(this_cpu_ptr(&local_lock));
if (spin_is_locked(&global_lock)) {
spin_unlock(this_cpu_ptr(&local_lock));
spin_lock(&global_lock);
this_cpu_write(have_global, true);
spin_lock(this_cpu_ptr(&local_lock));
}
}
void local_unlock(void)
{
spin_unlock(this_cpu_ptr(&local_lock));
if (this_cpu_read(have_global)) {
this_cpu_write(have_global, false);
spin_unlock(&global_lock);
}
}
void global_lock(void)
{
int cpu;
spin_lock(&global_lock);
for_each_possible_cpu(cpu)
spin_unlock_wait(&per_cpu(local_lock, cpu));
}
void global_unlock(void)
{
spin_unlock(&global_lock);
}
Or possibly make the global_lock a mutex, plenty variants possible.
next prev parent reply other threads:[~2013-11-01 14:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-31 20:31 Rik van Riel
2013-11-01 11:08 ` Mel Gorman
2013-11-01 11:36 ` Rik van Riel
2013-11-01 12:08 ` Prarit Bhargava
2013-11-01 13:44 ` Mel Gorman
2013-11-01 14:24 ` Peter Zijlstra [this message]
2013-11-01 14:27 ` Rik van Riel
2013-11-01 14:41 ` [PATCH -v2 " Rik van Riel
2013-11-01 14:47 ` Mel Gorman
2013-11-01 14:49 ` Prarit Bhargava
2013-11-01 18:24 ` Prarit Bhargava
2013-11-11 17:52 ` [tip:sched/core] stop_machine: Fix race between stop_two_cpus() and stop_cpus() tip-bot for Rik van Riel
2013-11-01 11:39 ` [PATCH -tip] fix race between stop_two_cpus and stop_cpus Prarit Bhargava
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=20131101142404.GG19466@laptop.lan \
--to=peterz@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=prarit@redhat.com \
--cc=riel@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
all inboxes | Powered by JetHome®