From patchwork Wed Jul 31 06:42:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanlong Gao X-Patchwork-Id: 263600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 172F02C00BC for ; Wed, 31 Jul 2013 16:46:20 +1000 (EST) Received: from localhost ([::1]:35299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4QAq-0007YN-1O for incoming@patchwork.ozlabs.org; Wed, 31 Jul 2013 02:46:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4Q73-0002Yt-Kk for qemu-devel@nongnu.org; Wed, 31 Jul 2013 02:42:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4Q6y-0002NW-6b for qemu-devel@nongnu.org; Wed, 31 Jul 2013 02:42:21 -0400 Received: from [222.73.24.84] (port=40916 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4Q6x-0002Jh-Iu for qemu-devel@nongnu.org; Wed, 31 Jul 2013 02:42:16 -0400 X-IronPort-AV: E=Sophos;i="4.89,785,1367942400"; d="scan'208";a="8074956" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 31 Jul 2013 14:39:04 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r6V6g2gl009397; Wed, 31 Jul 2013 14:42:04 +0800 Received: from G08FNSTD121251.fnst.cn.fujitsu.com ([10.167.226.75]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013073114395008-281720 ; Wed, 31 Jul 2013 14:39:50 +0800 From: Wanlong Gao To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2013 14:42:13 +0800 Message-Id: <1375252936-28496-9-git-send-email-gaowanlong@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.rc0.11.g35f5eaa In-Reply-To: <1375252936-28496-1-git-send-email-gaowanlong@cn.fujitsu.com> References: <1375252936-28496-1-git-send-email-gaowanlong@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/31 14:39:50, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/31 14:39:52, Serialize complete at 2013/07/31 14:39:52 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: aliguori@us.ibm.com, ehabkost@redhat.com, lersek@redhat.com, peter.huangpeng@huawei.com, lcapitulino@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 V7 08/11] NUMA: add qmp command set-mem-policy to set memory policy for NUMA node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- numa.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 21 +++++++++++++++++++ qmp-commands.hx | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) diff --git a/numa.c b/numa.c index b2c0048..c260d73 100644 --- a/numa.c +++ b/numa.c @@ -29,6 +29,7 @@ #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h" #include "exec/memory.h" +#include "qmp-commands.h" #ifdef CONFIG_NUMA #include @@ -311,3 +312,64 @@ 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_CPUMASK_BITS); + 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_CPUMASK_BITS); + 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_CPUMASK_BITS); + + 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_fill(numa_info[nodeid].host_mem, MAX_CPUMASK_BITS); + } + + for (nodes = host_nodes; nodes; nodes = nodes->next) { + 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_CPUMASK_BITS); + numa_info[nodeid].policy = old_policy; + numa_info[nodeid].relative = old_relative; + return; +} diff --git a/qapi-schema.json b/qapi-schema.json index a34350c..a1e0d36 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3847,3 +3847,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 2e59b0d..c8356c5 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3051,6 +3051,7 @@ Example: <- { "return": {} } EQMP + { .name = "query-rx-filter", .args_type = "name:s?", @@ -3114,3 +3115,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 all available host nodes. + +EQMP