From: Heiko Carstens <heiko.carstens@de.ibm.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
john stultz <johnstul@us.ibm.com>,
Roman Zippel <zippel@linux-m68k.org>,
Christian Borntraeger <cborntra@de.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [patch] timer/hrtimer: take per cpu locks in sane order
Date: Fri, 2 Mar 2007 15:23:08 +0100 [thread overview]
Message-ID: <20070302142308.GB8226@osiris.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20070302130433.GA4391@elte.hu>
On Fri, Mar 02, 2007 at 02:04:33PM +0100, Ingo Molnar wrote:
>
> * Heiko Carstens <heiko.carstens@de.ibm.com> wrote:
>
> > - spin_lock(&new_base->lock);
> > - spin_lock(&old_base->lock);
> > + /*
> > + * If we take a lock from a different cpu, make sure we have always
> > + * the same locking order. That is the lock that belongs to the cpu
> > + * with the lowest number is taken first.
> > + */
> > + lock1 = smp_processor_id() < cpu ? &new_base->lock : &old_base->lock;
> > + lock2 = smp_processor_id() < cpu ? &old_base->lock : &new_base->lock;
> > + spin_lock(lock1);
> > + spin_lock(lock2);
>
> looks good to me. Wouldnt this be cleaner via double_lock_timer() -
> similar to how double_rq_lock() works in kernel/sched.c - instead of
> open-coding it?
Something like the stuff below? Exploits the knowledge that the two
tvec_base_t's are in a per_cpu array. Otherwise I would end up passing
a lot of redundant stuff. But still I think that isn't a good solution
but rather a hack...?
I'd go for the patch above.
---
Index: linux-2.6/kernel/timer.c
===================================================================
--- linux-2.6.orig/kernel/timer.c
+++ linux-2.6/kernel/timer.c
@@ -1640,6 +1640,28 @@ static void migrate_timer_list(tvec_base
}
}
+static void __devinit double_tvec_lock(tvec_base_t *base1, tvec_base_t *base2)
+{
+ if (base1 < base2) {
+ spin_lock(&base1->lock);
+ spin_lock(&base2->lock);
+ } else {
+ spin_lock(&base2->lock);
+ spin_lock(&base1->lock);
+ }
+}
+
+static void __devinit double_tvec_unlock(tvec_base_t *base1, tvec_base_t *base2)
+{
+ if (base1 < base2) {
+ spin_unlock(&base1->lock);
+ spin_unlock(&base2->lock);
+ } else {
+ spin_unlock(&base2->lock);
+ spin_unlock(&base1->lock);
+ }
+}
+
static void __devinit migrate_timers(int cpu)
{
tvec_base_t *old_base;
@@ -1651,8 +1673,7 @@ static void __devinit migrate_timers(int
new_base = get_cpu_var(tvec_bases);
local_irq_disable();
- spin_lock(&new_base->lock);
- spin_lock(&old_base->lock);
+ double_tvec_lock(new_base, old_base);
BUG_ON(old_base->running_timer);
@@ -1665,8 +1686,7 @@ static void __devinit migrate_timers(int
migrate_timer_list(new_base, old_base->tv5.vec + i);
}
- spin_unlock(&old_base->lock);
- spin_unlock(&new_base->lock);
+ double_tvec_unlock(new_base, old_base);
local_irq_enable();
put_cpu_var(tvec_bases);
}
next prev parent reply other threads:[~2007-03-02 14:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-27 15:30 timer/hrtimer & cpu hotplug lockdep complaints Heiko Carstens
2007-03-02 12:58 ` [patch] timer/hrtimer: take per cpu locks in sane order Heiko Carstens
2007-03-02 13:04 ` Ingo Molnar
2007-03-02 14:23 ` Heiko Carstens [this message]
2007-03-02 16:48 ` Andrew Morton
2007-03-02 19:08 ` Heiko Carstens
2007-03-02 19:45 ` Andrew Morton
2007-03-02 21:39 ` Heiko Carstens
2007-03-02 22:47 ` Heiko Carstens
2007-03-04 23:24 ` Matt Mackall
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=20070302142308.GB8226@osiris.boeblingen.de.ibm.com \
--to=heiko.carstens@de.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=cborntra@de.ibm.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=schwidefsky@de.ibm.com \
--cc=tglx@linutronix.de \
--cc=zippel@linux-m68k.org \
/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®