qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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,
	drjones@redhat.com, bsd@redhat.com, hutao@cn.fujitsu.com,
	y-goto@jp.fujitsu.com, pbonzini@redhat.com, afaerber@suse.de,
	gaowanlong@cn.fujitsu.com
Subject: [Qemu-devel] [PATCH V12 10/13] NUMA: add qmp command set-mem-policy to set memory policy for NUMA node
Date: Wed, 4 Sep 2013 17:03:39 +0800	[thread overview]
Message-ID: <1378285422-7361-11-git-send-email-gaowanlong@cn.fujitsu.com> (raw)
In-Reply-To: <1378285422-7361-1-git-send-email-gaowanlong@cn.fujitsu.com>

This QMP command allows user set guest node's memory policy
through the QMP protocol. The qmp-shell command is like:
    set-mem-policy nodeid=0 policy=membind relative=true host-nodes=0-1

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
---
 numa.c           | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json | 21 ++++++++++++++++++
 qmp-commands.hx  | 41 +++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+)

diff --git a/numa.c b/numa.c
index 915a67a..19ee7f7 100644
--- a/numa.c
+++ b/numa.c
@@ -28,6 +28,7 @@
 #include "qapi/opts-visitor.h"
 #include "qapi/dealloc-visitor.h"
 #include "exec/memory.h"
+#include "qmp-commands.h"
 
 #ifdef __linux__
 #include <sys/syscall.h>
@@ -327,3 +328,68 @@ void set_numa_modes(void)
         }
     }
 }
+
+void qmp_set_mem_policy(uint16_t nodeid, bool has_policy, NumaNodePolicy policy,
+                        bool has_relative, bool relative,
+                        bool has_host_nodes, uint16List *host_nodes,
+                        Error **errp)
+{
+    NumaNodePolicy old_policy;
+    bool old_relative;
+    DECLARE_BITMAP(host_mem, MAX_NODES);
+    uint16List *nodes;
+
+    if (nodeid >= nb_numa_nodes) {
+        error_setg(errp, "Only has '%d' NUMA nodes", nb_numa_nodes);
+        return;
+    }
+
+    bitmap_copy(host_mem, numa_info[nodeid].host_mem, MAX_NODES);
+    old_policy = numa_info[nodeid].policy;
+    old_relative = numa_info[nodeid].relative;
+
+    numa_info[nodeid].policy = NUMA_NODE_POLICY_DEFAULT;
+    numa_info[nodeid].relative = false;
+    bitmap_zero(numa_info[nodeid].host_mem, MAX_NODES);
+
+    if (!has_policy) {
+        if (set_node_mem_policy(nodeid) == -1) {
+            error_setg(errp, "Failed to set memory policy for node%" PRIu16,
+                       nodeid);
+            goto error;
+        }
+        return;
+    }
+
+    numa_info[nodeid].policy = policy;
+
+    if (has_relative) {
+        numa_info[nodeid].relative = relative;
+    }
+
+    if (!has_host_nodes) {
+        bitmap_empty(numa_info[nodeid].host_mem, MAX_NODES);
+        bitmap_set(numa_info[nodeid].host_mem, 0, 1);
+    }
+
+    for (nodes = host_nodes; nodes; nodes = nodes->next) {
+        if (nodes->value > MAX_NODES) {
+            continue;
+        }
+        bitmap_set(numa_info[nodeid].host_mem, nodes->value, 1);
+    }
+
+    if (set_node_mem_policy(nodeid) == -1) {
+        error_setg(errp, "Failed to set memory policy for node%" PRIu16,
+                   nodeid);
+        goto error;
+    }
+
+    return;
+
+error:
+    bitmap_copy(numa_info[nodeid].host_mem, host_mem, MAX_NODES);
+    numa_info[nodeid].policy = old_policy;
+    numa_info[nodeid].relative = old_relative;
+    return;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index 2fba592..7a8cf6a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3849,3 +3849,24 @@
    '*policy':     'NumaNodePolicy',
    '*relative':   'bool',
    '*host-nodes': ['uint16'] }}
+
+##
+# @set-mem-policy:
+#
+# Set the host memory binding policy for guest NUMA node.
+#
+# @nodeid: The node ID of guest NUMA node to set memory policy to.
+#
+# @policy: #optional The memory policy to be set (default 'default').
+#
+# @relative: #optional If the specified nodes are relative (default 'false')
+#
+# @host-nodes: #optional The host nodes range for memory policy.
+#
+# Returns: Nothing on success
+#
+# Since: 1.7
+##
+{ 'command': 'set-mem-policy',
+  'data': {'nodeid': 'uint16', '*policy': 'NumaNodePolicy',
+           '*relative': 'bool', '*host-nodes': ['uint16'] } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8a8f342..67a9dd2 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3061,6 +3061,7 @@ Example:
 <- { "return": {} }
 
 EQMP
+
     {
         .name       = "query-rx-filter",
         .args_type  = "name:s?",
@@ -3124,3 +3125,43 @@ Example:
    }
 
 EQMP
+
+    {
+        .name      = "set-mem-policy",
+        .args_type = "nodeid:i,policy:s?,relative:b?,host-nodes:q?",
+        .help      = "Set the host memory binding policy for guest NUMA node",
+        .mhandler.cmd_new = qmp_marshal_input_set_mem_policy,
+    },
+
+SQMP
+set-mem-policy
+------
+
+Set the host memory binding policy for guest NUMA node
+
+Arguments:
+
+- "nodeid": The nodeid of guest NUMA node to set memory policy to.
+            (json-int)
+- "policy": The memory policy to set.
+            (json-string, optional)
+- "relative": If the specified nodes are relative.
+              (json-bool, optional)
+- "host-nodes": The host nodes contained to this memory policy.
+                (a json-array of int, optional)
+
+Example:
+
+-> { "execute": "set-mem-policy", "arguments": { "nodeid": 0,
+                                                 "policy": "membind",
+                                                 "relative": true,
+                                                 "host-nodes": [0, 1] } }
+<- { "return": {} }
+
+Notes:
+    1. If "policy" is not set, the memory policy of this "nodeid" will be set
+       to "default".
+    2. If "host-nodes" is not set, the node mask of this "policy" will be set
+       to host node 0.
+
+EQMP
-- 
1.8.4.21.g992c386

  parent reply	other threads:[~2013-09-04  9:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-04  9:03 [Qemu-devel] [PATCH V12 00/13] Add support for binding guest numa nodes to host numa nodes Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 01/13] NUMA: move numa related code to new file numa.c Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 02/13] NUMA: check if the total numa memory size is equal to ram_size Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 03/13] NUMA: Add numa_info structure to contain numa nodes info Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 04/13] NUMA: convert -numa option to use OptsVisitor Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 05/13] NUMA: introduce NumaMemOptions Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 06/13] NUMA: add "-numa mem," options Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 07/13] NUMA: expand MAX_NODES from 64 to 128 Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 08/13] NUMA: parse guest numa nodes memory policy Wanlong Gao
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 09/13] NUMA: set " Wanlong Gao
2013-09-04  9:03 ` Wanlong Gao [this message]
2013-09-09 21:02   ` [Qemu-devel] [PATCH V12 10/13] NUMA: add qmp command set-mem-policy to set memory policy for NUMA node Luiz Capitulino
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 11/13] NUMA: add hmp command set-mem-policy Wanlong Gao
2013-09-10 13:36   ` Luiz Capitulino
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 12/13] NUMA: add qmp command query-numa Wanlong Gao
2013-09-10 13:50   ` Luiz Capitulino
2013-09-04  9:03 ` [Qemu-devel] [PATCH V12 13/13] NUMA: convert hmp command info_numa to use qmp command query_numa Wanlong Gao
2013-09-10 14:03   ` Luiz Capitulino
2013-09-09  6:59 ` [Qemu-devel] [PATCH V12 00/13] Add support for binding guest numa nodes to host numa nodes 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=1378285422-7361-11-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=drjones@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=hutao@cn.fujitsu.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).