From: Wanlong Gao <gaowanlong@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, ehabkost@redhat.com, lersek@redhat.com,
peter.huangpeng@huawei.com, lcapitulino@redhat.com,
bsd@redhat.com, y-goto@jp.fujitsu.com, pbonzini@redhat.com,
afaerber@suse.de, gaowanlong@cn.fujitsu.com
Subject: [Qemu-devel] [PATCH V5 06/12] NUMA: parse guest numa nodes memory policy
Date: Wed, 17 Jul 2013 17:29:27 +0800 [thread overview]
Message-ID: <1374053373-30499-7-git-send-email-gaowanlong@cn.fujitsu.com> (raw)
In-Reply-To: <1374053373-30499-1-git-send-email-gaowanlong@cn.fujitsu.com>
The memory policy setting format is like:
policy={membind|interleave|preferred},host-node=[+|!]{all|N-N}
And we are adding this setting as a suboption of "-numa mem,",
the memory policy then can be set like following:
-numa node,nodeid=0,cpus=0 \
-numa node,nodeid=1,cpus=1 \
-numa mem,nodeid=0,size=1G,policy=membind,host-nodes=0-1 \
-numa mem,nodeid=1,size=1G,policy=interleave,host-nodes=!1
Reviewed-by: Bandan Das <bsd@redhat.com>
Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
---
include/sysemu/sysemu.h | 8 +++++
numa.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
qapi-schema.json | 8 ++++-
vl.c | 2 ++
4 files changed, 100 insertions(+), 1 deletion(-)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 28fe305..af17c02 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -130,10 +130,18 @@ extern QEMUClock *rtc_clock;
#define MAX_NODES 64
#define MAX_CPUMASK_BITS 255
+#define NODE_HOST_NONE 0x00
+#define NODE_HOST_BIND 0x01
+#define NODE_HOST_INTERLEAVE 0x02
+#define NODE_HOST_PREFERRED 0x03
+#define NODE_HOST_POLICY_MASK 0x03
+#define NODE_HOST_RELATIVE 0x04
extern int nb_numa_nodes;
typedef struct node_info {
uint64_t node_mem;
DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
+ DECLARE_BITMAP(host_mem, MAX_CPUMASK_BITS);
+ unsigned int flags;
} NodeInfo;
extern NodeInfo numa_info[MAX_NODES];
extern QemuOptsList qemu_numa_opts;
diff --git a/numa.c b/numa.c
index 766e111..a2eceb1 100644
--- a/numa.c
+++ b/numa.c
@@ -96,6 +96,79 @@ static int numa_node_parse(NumaNodeOptions *opts)
return numa_node_parse_cpus(nodenr, cpus);
}
+static int numa_mem_parse_policy(int nodenr, const char *policy)
+{
+ if (!strcmp(policy, "interleave")) {
+ numa_info[nodenr].flags |= NODE_HOST_INTERLEAVE;
+ } else if (!strcmp(policy, "preferred")) {
+ numa_info[nodenr].flags |= NODE_HOST_PREFERRED;
+ } else if (!strcmp(policy, "membind")) {
+ numa_info[nodenr].flags |= NODE_HOST_BIND;
+ } else {
+ fprintf(stderr, "qemu: Invalid memory policy: %s\n", policy);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int numa_mem_parse_hostnodes(int nodenr, const char *hostnodes)
+{
+ unsigned long long value, endvalue;
+ char *endptr;
+ bool clear = false;
+ unsigned long *bm = numa_info[nodenr].host_mem;
+
+ if (hostnodes[0] == '!') {
+ clear = true;
+ bitmap_fill(bm, MAX_CPUMASK_BITS);
+ hostnodes++;
+ }
+ if (hostnodes[0] == '+') {
+ numa_info[nodenr].flags |= NODE_HOST_RELATIVE;
+ hostnodes++;
+ }
+
+ if (!strcmp(hostnodes, "all")) {
+ bitmap_fill(bm, MAX_CPUMASK_BITS);
+ return 0;
+ }
+
+ if (parse_uint(hostnodes, &value, &endptr, 10) < 0)
+ goto error;
+ if (*endptr == '-') {
+ if (parse_uint_full(endptr + 1, &endvalue, 10) < 0) {
+ goto error;
+ }
+ } else if (*endptr == '\0') {
+ endvalue = value;
+ } else {
+ goto error;
+ }
+
+ if (endvalue >= MAX_CPUMASK_BITS) {
+ endvalue = MAX_CPUMASK_BITS - 1;
+ fprintf(stderr,
+ "qemu: NUMA: A max of %d host nodes are supported\n",
+ MAX_CPUMASK_BITS);
+ }
+
+ if (endvalue < value) {
+ goto error;
+ }
+
+ if (clear)
+ bitmap_clear(bm, value, endvalue - value + 1);
+ else
+ bitmap_set(bm, value, endvalue - value + 1);
+
+ return 0;
+
+error:
+ fprintf(stderr, "qemu: Invalid host NUMA nodes range: %s\n", hostnodes);
+ return -1;
+}
+
static int numa_mem_parse(NumaMemOptions *opts)
{
uint64_t nodenr, mem_size;
@@ -110,6 +183,16 @@ static int numa_mem_parse(NumaMemOptions *opts)
mem_size = opts->size;
numa_info[nodenr].node_mem = mem_size;
+ const char *policy = opts->policy;
+ if (numa_mem_parse_policy(nodenr, policy) == -1) {
+ return -1;
+ }
+
+ const char *hostnodes = opts->host_nodes;
+ if (numa_mem_parse_hostnodes(nodenr, hostnodes) == -1) {
+ return -1;
+ }
+
return 0;
}
diff --git a/qapi-schema.json b/qapi-schema.json
index f753a35..49eac70 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3717,9 +3717,15 @@
#
# @size: #optional memory size of this node
#
+# @policy: #optional memory policy of this node
+#
+# @host-nodes: #optional host nodes for its memory policy
+#
# Since 1.6
##
{ 'type': 'NumaMemOptions',
'data': {
'*nodeid': 'int',
- '*size': 'size' }}
+ '*size': 'size',
+ '*policy': 'str',
+ '*host-nodes': 'str' }}
diff --git a/vl.c b/vl.c
index 5fdba97..dc8131c 100644
--- a/vl.c
+++ b/vl.c
@@ -2887,6 +2887,8 @@ int main(int argc, char **argv, char **envp)
for (i = 0; i < MAX_NODES; i++) {
numa_info[i].node_mem = 0;
bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
+ bitmap_zero(numa_info[i].host_mem, MAX_CPUMASK_BITS);
+ numa_info[i].flags = NODE_HOST_NONE;
}
nb_numa_nodes = 0;
--
1.8.3.2.634.g7a3187e
next prev parent reply other threads:[~2013-07-17 9:31 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 9:29 [Qemu-devel] [PATCH V5 00/12] Add support for binding guest numa nodes to host numa nodes Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 01/12] NUMA: add NumaOptions, NumaNodeOptions and NumaMemOptions Wanlong Gao
2013-07-17 10:35 ` Laszlo Ersek
2013-07-17 11:11 ` Paolo Bonzini
2013-07-17 13:16 ` Wanlong Gao
2013-07-17 12:24 ` Eric Blake
2013-07-17 13:57 ` Laszlo Ersek
2013-07-17 14:20 ` Paolo Bonzini
2013-07-17 14:33 ` Laszlo Ersek
2013-07-17 14:44 ` Paolo Bonzini
2013-07-17 15:24 ` Laszlo Ersek
2013-07-17 15:26 ` Paolo Bonzini
2013-07-17 15:45 ` Laszlo Ersek
2013-07-17 15:54 ` Paolo Bonzini
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 02/12] NUMA: split -numa option Wanlong Gao
2013-07-17 11:00 ` Laszlo Ersek
2013-07-17 11:14 ` Paolo Bonzini
2013-07-17 11:13 ` Paolo Bonzini
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 03/12] NUMA: move numa related code to numa.c Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 04/12] NUMA: Add numa_info structure to contain numa nodes info Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 05/12] NUMA: Add Linux libnuma detection Wanlong Gao
2013-07-17 9:29 ` Wanlong Gao [this message]
2013-07-17 12:31 ` [Qemu-devel] [PATCH V5 06/12] NUMA: parse guest numa nodes memory policy Eric Blake
2013-07-17 13:12 ` Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 07/12] NUMA: split out the common range parser Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 08/12] NUMA: set guest numa nodes memory policy Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 09/12] NUMA: add qmp command set-mem-policy to set memory policy for NUMA node Wanlong Gao
2013-07-17 12:36 ` Eric Blake
2013-07-17 13:22 ` Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 10/12] NUMA: add hmp command set-mem-policy Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 11/12] NUMA: add qmp command query-numa Wanlong Gao
2013-07-17 12:41 ` Eric Blake
2013-07-17 13:24 ` Wanlong Gao
2013-07-17 9:29 ` [Qemu-devel] [PATCH V5 12/12] NUMA: convert hmp command info_numa to use qmp command query_numa Wanlong Gao
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=1374053373-30499-7-git-send-email-gaowanlong@cn.fujitsu.com \
--to=gaowanlong@cn.fujitsu.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=bsd@redhat.com \
--cc=ehabkost@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=lersek@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=y-goto@jp.fujitsu.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).