From: Roger Pau Monne <roger.pau@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH 1/2] smp: convert the cpu maps lock into a rw lock
Date: Thu, 13 Feb 2020 12:32:36 +0100 [thread overview]
Message-ID: <20200213113237.58795-2-roger.pau@citrix.com> (raw)
In-Reply-To: <20200213113237.58795-1-roger.pau@citrix.com>
Most users of the cpu maps just care about the maps not changing while
the lock is being held, but don't actually modify the maps.
Convert the lock into a rw lock, and take the lock in read mode in
get_cpu_maps and in write mode in cpu_hotplug_begin. This will lower
the contention around the lock, since plug and unplug operations that
take the lock in write mode are not that common.
Note that the read lock can be taken recursively (as it's a shared
lock), and hence will keep the same behavior as the previously used
recursive lock. As for the write lock, it's only used by CPU
plug/unplug operations, and the lock is never taken recursively in
that case.
While there also change get_cpu_maps return type to bool.
Reported-by: Julien Grall <julien@xen.org>
Suggested-also-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
xen/common/cpu.c | 22 ++++++++++++++++------
xen/include/xen/cpu.h | 13 +++----------
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/xen/common/cpu.c b/xen/common/cpu.c
index 66c855c5d9..0d7a10878c 100644
--- a/xen/common/cpu.c
+++ b/xen/common/cpu.c
@@ -39,26 +39,36 @@ const unsigned long cpu_bit_bitmap[BITS_PER_LONG+1][BITS_TO_LONGS(NR_CPUS)] = {
#endif
};
-static DEFINE_SPINLOCK(cpu_add_remove_lock);
+static DEFINE_RWLOCK(cpu_add_remove_lock);
-bool_t get_cpu_maps(void)
+bool get_cpu_maps(void)
{
- return spin_trylock_recursive(&cpu_add_remove_lock);
+ return read_trylock(&cpu_add_remove_lock);
}
void put_cpu_maps(void)
{
- spin_unlock_recursive(&cpu_add_remove_lock);
+ read_unlock(&cpu_add_remove_lock);
+}
+
+bool cpu_hotplug_begin(void)
+{
+ return write_trylock(&cpu_add_remove_lock);
+}
+
+void cpu_hotplug_done(void)
+{
+ write_unlock(&cpu_add_remove_lock);
}
static NOTIFIER_HEAD(cpu_chain);
void __init register_cpu_notifier(struct notifier_block *nb)
{
- if ( !spin_trylock(&cpu_add_remove_lock) )
+ if ( !write_trylock(&cpu_add_remove_lock) )
BUG(); /* Should never fail as we are called only during boot. */
notifier_chain_register(&cpu_chain, nb);
- spin_unlock(&cpu_add_remove_lock);
+ write_unlock(&cpu_add_remove_lock);
}
static int cpu_notifier_call_chain(unsigned int cpu, unsigned long action,
diff --git a/xen/include/xen/cpu.h b/xen/include/xen/cpu.h
index 2c87db26f6..e49172f64c 100644
--- a/xen/include/xen/cpu.h
+++ b/xen/include/xen/cpu.h
@@ -6,19 +6,12 @@
#include <xen/notifier.h>
/* Safely access cpu_online_map, cpu_present_map, etc. */
-bool_t get_cpu_maps(void);
+bool get_cpu_maps(void);
void put_cpu_maps(void);
/* Safely perform CPU hotplug and update cpu_online_map, etc. */
-static inline bool cpu_hotplug_begin(void)
-{
- return get_cpu_maps();
-}
-
-static inline void cpu_hotplug_done(void)
-{
- put_cpu_maps();
-}
+bool cpu_hotplug_begin(void);
+void cpu_hotplug_done(void);
/* Receive notification of CPU hotplug events. */
void register_cpu_notifier(struct notifier_block *nb);
--
2.25.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-02-13 11:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 11:32 [Xen-devel] [PATCH 0/2] smp: convert cpu_add_remove_lock int a rw lock Roger Pau Monne
2020-02-13 11:32 ` Roger Pau Monne [this message]
2020-02-19 12:08 ` [Xen-devel] [PATCH 1/2] smp: convert the cpu maps lock into " Julien Grall
2020-02-19 12:56 ` Jan Beulich
2020-02-19 13:19 ` Roger Pau Monné
2020-02-19 13:42 ` Jan Beulich
2020-02-19 14:38 ` Roger Pau Monné
2020-02-20 8:13 ` Jan Beulich
2020-02-20 8:27 ` Jürgen Groß
2020-02-20 8:36 ` Jan Beulich
2020-02-20 8:57 ` Julien Grall
2020-02-20 9:20 ` Roger Pau Monné
2020-02-13 11:32 ` [Xen-devel] [PATCH 2/2] smp: convert cpu_hotplug_begin into a blocking lock acquisition Roger Pau Monne
2020-02-19 12:59 ` Jan Beulich
2020-02-19 13:22 ` Roger Pau Monné
2020-02-19 13:44 ` Jan Beulich
2020-02-19 14:45 ` Roger Pau Monné
2020-02-19 14:57 ` Jan Beulich
2020-02-19 15:07 ` Andrew Cooper
2020-02-19 16:06 ` Jan Beulich
2020-02-19 16:26 ` Roger Pau Monné
2020-02-19 17:06 ` Jan Beulich
2020-02-19 16:54 ` Andrew Cooper
2020-02-19 16:08 ` Roger Pau Monné
2020-02-19 17:03 ` Jan Beulich
2020-02-20 8:16 ` Jan Beulich
2020-02-21 10:23 ` Roger Pau Monné
2020-02-21 13:06 ` Jan Beulich
2020-02-19 14:58 ` Andrew Cooper
2020-02-19 12:22 ` [Xen-devel] [PATCH 0/2] smp: convert cpu_add_remove_lock int a rw lock Andrew Cooper
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=20200213113237.58795-2-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.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 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.