From patchwork Mon Jun 24 07:12:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanlong Gao X-Patchwork-Id: 253699 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 E38A22C009A for ; Mon, 24 Jun 2013 17:50:17 +1000 (EST) Received: from localhost ([::1]:45597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur12A-0004GM-1b for incoming@patchwork.ozlabs.org; Mon, 24 Jun 2013 03:17:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur0zT-0008Lr-7o for qemu-devel@nongnu.org; Mon, 24 Jun 2013 03:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ur0zP-0001jf-2T for qemu-devel@nongnu.org; Mon, 24 Jun 2013 03:15:07 -0400 Received: from [222.73.24.84] (port=50912 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur0zO-0001bE-JF for qemu-devel@nongnu.org; Mon, 24 Jun 2013 03:15:02 -0400 X-IronPort-AV: E=Sophos;i="4.87,927,1363104000"; d="scan'208";a="7658038" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 24 Jun 2013 15:11:57 +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 r5O7EljO017636; Mon, 24 Jun 2013 15:14:50 +0800 Received: from G08FNSTD121251.fnst.cn.fujitsu.com ([10.167.233.84]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013062415133787-2413538 ; Mon, 24 Jun 2013 15:13:37 +0800 From: Wanlong Gao To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2013 15:12:06 +0800 Message-Id: <1372057928-20248-9-git-send-email-gaowanlong@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1.448.gfb7dfaa In-Reply-To: <1372057928-20248-1-git-send-email-gaowanlong@cn.fujitsu.com> References: <1372057928-20248-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/06/24 15:13:37, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/24 15:13:39, Serialize complete at 2013/06/24 15:13:39 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, bsd@redhat.com, pbonzini@redhat.com, y-goto@jp.fujitsu.com, afaerber@suse.de, gaowanlong@cn.fujitsu.com Subject: [Qemu-devel] [PATCH V3 08/10] NUMA: add qmp command set-mpol 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 The QMP command let it be able to set node's memory policy through the QMP protocol. The qmp-shell command is like: set-mpol nodeid=0 mem-policy=membind mem-hostnode=0-1 Signed-off-by: Wanlong Gao --- cpus.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/cpus.c b/cpus.c index 677ee15..9c2706c 100644 --- a/cpus.c +++ b/cpus.c @@ -1432,3 +1432,57 @@ void qmp_inject_nmi(Error **errp) error_set(errp, QERR_UNSUPPORTED); #endif } + +void qmp_set_mpol(int64_t nodeid, bool has_mpol, const char *mpol, + bool has_hostnode, const char *hostnode, Error **errp) +{ + unsigned int flags; + DECLARE_BITMAP(host_mem, MAX_CPUMASK_BITS); + + 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); + flags = numa_info[nodeid].flags; + + numa_info[nodeid].flags = NODE_HOST_NONE; + bitmap_zero(numa_info[nodeid].host_mem, MAX_CPUMASK_BITS); + + if (!has_mpol) { + if (set_node_mpol(nodeid) == -1) { + error_setg(errp, "Failed to set memory policy for node%lu", nodeid); + goto error; + } + return; + } + + numa_node_parse_mpol(nodeid, mpol, errp); + if (error_is_set(errp)) { + goto error; + } + + if (!has_hostnode) { + bitmap_fill(numa_info[nodeid].host_mem, MAX_CPUMASK_BITS); + } + + if (hostnode) { + numa_node_parse_hostnode(nodeid, hostnode, errp); + if (error_is_set(errp)) { + goto error; + } + } + + if (set_node_mpol(nodeid) == -1) { + error_setg(errp, "Failed to set memory policy for node%lu", nodeid); + goto error; + } + + return; + +error: + bitmap_copy(numa_info[nodeid].host_mem, host_mem, MAX_CPUMASK_BITS); + numa_info[nodeid].flags = flags; + return; +} diff --git a/qapi-schema.json b/qapi-schema.json index a80ee40..cedcbe1 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3608,3 +3608,18 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +# @set-mpol: +# +# Set the host memory binding policy for guest NUMA node. +# +# @nodeid: The node ID of guest NUMA node to set memory policy to. +# +# @mem-policy: The memory policy string to set. +# +# @mem-hostnode: The host node or node range for memory policy. +# +# Since: 1.6.0 +## +{ 'command': 'set-mpol', 'data': {'nodeid': 'int', '*mem-policy': 'str', + '*mem-hostnode': 'str'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index 8cea5e5..7bb5038 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2997,3 +2997,38 @@ Example: <- { "return": {} } EQMP + + { + .name = "set-mpol", + .args_type = "nodeid:i,mem-policy:s?,mem-hostnode:s?", + .help = "Set the host memory binding policy for guest NUMA node", + .mhandler.cmd_new = qmp_marshal_input_set_mpol, + }, + +SQMP +set-mpol +------ + +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) +- "mem-policy": The memory policy string to set. + (json-string, optional) +- "mem-hostnode": The host nodes contained to mpol. + (json-string, optional) + +Example: + +-> { "execute": "set-mpol", "arguments": { "nodeid": 0, "mem-policy": "membind", + "mem-hostnode": "0-1" }} +<- { "return": {} } + +Notes: + 1. If "mem-policy" is not set, the memory policy of this "nodeid" will be set + to "default". + 2. If "mem-hostnode" is not set, the node mask of this "mpol" will be set + to "all". +EQMP