qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH V13 11/13] NUMA: add hmp command set-mem-policy


From: Wanlong Gao
Subject: [Qemu-devel] [PATCH V13 11/13] NUMA: add hmp command set-mem-policy
Date: Tue, 17 Sep 2013 11:16:23 +0800

Add hmp command set-mem-policy to set host memory policy for a guest
NUMA node. Then we can also set node's memory policy using
the monitor command like:
    (qemu) set-mem-policy 0 policy=membind,relative=false,host-nodes=0-1

Signed-off-by: Wanlong Gao <address@hidden>
---
 hmp-commands.hx | 28 +++++++++++++++++++++++++
 hmp.c           | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 3 files changed, 94 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 65b7f60..3cf1d5c 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1587,6 +1587,34 @@ Executes a qemu-io command on the given block device.
 ETEXI
 
     {
+        .name       = "set-mem-policy",
+        .args_type  = "nodeid:i,args:s?",
+        .params     = "nodeid [args]",
+        .help       = "set host memory policy for a guest NUMA node",
+        .mhandler.cmd = hmp_set_mem_policy,
+    },
+
+STEXI
address@hidden set-mem-policy @var{nodeid} @var{args}
address@hidden set-mem-policy
+
+Set host memory policy for a guest NUMA node
+
address@hidden is optional. If not set, the policy of @var{nodeid} will
+be set to @var{default}. Its syntax is:
address@hidden,address@hidden,address@hidden,
+Here @var{policy} can be @var{default}, @var{membind}, @var{perferred} or
address@hidden, @var{relative} is a bool value, @var{host-nodes} is a
+set of host node ids. For example:
+
address@hidden
+(qemu) set-mem-policy 0 policy=membind,relative=yes,host-nodes=0-1
address@hidden example
+
+
+ETEXI
+
+    {
         .name       = "info",
         .args_type  = "item:s?",
         .params     = "[subcommand]",
diff --git a/hmp.c b/hmp.c
index b4a6422..84990d7 100644
--- a/hmp.c
+++ b/hmp.c
@@ -24,6 +24,9 @@
 #include "ui/console.h"
 #include "block/qapi.h"
 #include "qemu-io.h"
+#include "qapi-visit.h"
+#include "qapi/opts-visitor.h"
+#include "qapi/dealloc-visitor.h"
 
 static void hmp_handle_error(Monitor *mon, Error **errp)
 {
@@ -1544,3 +1547,65 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
 
     hmp_handle_error(mon, &err);
 }
+
+void hmp_set_mem_policy(Monitor *mon, const QDict *qdict)
+{
+    Error *local_err = NULL;
+    bool has_policy = true;
+    bool has_relative = true;
+    bool has_host_nodes = true;
+    QemuOpts *opts;
+    NumaMemOptions *object = NULL;
+    NumaNodePolicy policy = NUMA_NODE_POLICY_DEFAULT;
+    bool relative = false;
+    uint16List *host_nodes = NULL;
+
+    uint64_t nodeid = qdict_get_int(qdict, "nodeid");
+    const char *args = qdict_get_try_str(qdict, "args");
+
+    if (args == NULL) {
+        has_policy = false;
+        has_relative = false;
+        has_host_nodes = false;
+    } else {
+        opts = qemu_opts_parse(qemu_find_opts("numa"), args, 1);
+        if (opts == NULL) {
+            monitor_printf(mon, "Parsing memory policy args failed\n");
+            return;
+        } else {
+            OptsVisitor *ov = opts_visitor_new(opts);
+            visit_type_NumaMemOptions(opts_get_visitor(ov), &object, NULL,
+                                      &local_err);
+            opts_visitor_cleanup(ov);
+
+            if (error_is_set(&local_err)) {
+                goto out;
+            }
+
+            has_policy = object->has_policy;
+            if (has_policy) {
+                policy = object->policy;
+            }
+            has_relative = object->has_relative;
+            if (has_relative) {
+                relative = object->relative;
+            }
+            has_host_nodes = object->has_host_nodes;
+            if (has_host_nodes) {
+                host_nodes = object->host_nodes;
+            }
+        }
+    }
+
+    qmp_set_mem_policy(nodeid, has_policy, policy, has_relative, relative,
+                       has_host_nodes, host_nodes, &local_err);
+out:
+    if (object) {
+        QapiDeallocVisitor *dv = qapi_dealloc_visitor_new();
+        visit_type_NumaMemOptions(qapi_dealloc_get_visitor(dv),
+                                  &object, NULL, NULL);
+        qapi_dealloc_visitor_cleanup(dv);
+    }
+
+    hmp_handle_error(mon, &local_err);
+}
diff --git a/hmp.h b/hmp.h
index 6c3bdcd..ae09525 100644
--- a/hmp.h
+++ b/hmp.h
@@ -87,5 +87,6 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
 void hmp_chardev_add(Monitor *mon, const QDict *qdict);
 void hmp_chardev_remove(Monitor *mon, const QDict *qdict);
 void hmp_qemu_io(Monitor *mon, const QDict *qdict);
+void hmp_set_mem_policy(Monitor *mon, const QDict *qdict);
 
 #endif
-- 
1.8.4.99.gd2dbd39




reply via email to

[Prev in Thread] Current Thread [Next in Thread]