From patchwork Tue Jun 18 08:09:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanlong Gao X-Patchwork-Id: 252128 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 346C52C0087 for ; Tue, 18 Jun 2013 18:16:06 +1000 (EST) Received: from localhost ([::1]:42536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uor5A-0003JB-1P for incoming@patchwork.ozlabs.org; Tue, 18 Jun 2013 04:16:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uor1s-0006qg-T7 for qemu-devel@nongnu.org; Tue, 18 Jun 2013 04:12:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uor1p-0001Tx-KY for qemu-devel@nongnu.org; Tue, 18 Jun 2013 04:12:40 -0400 Received: from [222.73.24.84] (port=50853 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uor1p-0001Sv-90 for qemu-devel@nongnu.org; Tue, 18 Jun 2013 04:12:37 -0400 X-IronPort-AV: E=Sophos;i="4.87,887,1363104000"; d="scan'208";a="7587535" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 18 Jun 2013 16:09:11 +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 r5I8C2pR003331; Tue, 18 Jun 2013 16:12:02 +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 2013061816095985-2230903 ; Tue, 18 Jun 2013 16:09:59 +0800 From: Wanlong Gao To: qemu-devel@nongnu.org Date: Tue, 18 Jun 2013 16:09:47 +0800 Message-Id: <1371542991-15911-4-git-send-email-gaowanlong@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.rc2.10.g0c2b1cf In-Reply-To: <1371542991-15911-1-git-send-email-gaowanlong@cn.fujitsu.com> References: <1371542991-15911-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/18 16:10:00, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/18 16:10:02, Serialize complete at 2013/06/18 16:10:02 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: andre.przywara@amd.com, aliguori@us.ibm.com, ehabkost@redhat.com, pbonzini@redhat.com, y-goto@jp.fujitsu.com, afaerber@suse.de, gaowanlong@cn.fujitsu.com Subject: [Qemu-devel] [PATCH 3/7] NUMA: parse guest numa nodes memory policy 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 memory policy setting format is like: {membind|interleave|preferred}=[+|!]{all|N-N} And we are adding this setting as a suboption of "-numa", the memory policy then can be set like following: -numa node,nodeid=0,mem=1024,cpus=0,membind=0-1 -numa node,nodeid=1,mem=1024,cpus=1,interleave=1 Signed-off-by: Andre Przywara Signed-off-by: Wanlong Gao --- include/sysemu/sysemu.h | 8 ++++++ vl.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 70fd2ed..993b8e0 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; struct node_info { uint64_t node_mem; DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); + DECLARE_BITMAP(host_mem, MAX_CPUMASK_BITS); + unsigned int flags; }; extern struct node_info numa_info[MAX_NODES]; diff --git a/vl.c b/vl.c index 42dec5e..ada9fb2 100644 --- a/vl.c +++ b/vl.c @@ -1348,11 +1348,68 @@ error: exit(1); } +static unsigned int numa_node_parse_mpol(const char *str, unsigned long *bm) +{ + unsigned long long value, endvalue; + char *endptr; + unsigned int flags = 0; + + if (str[0] == '!') { + flags |= 2; + bitmap_fill(bm, MAX_CPUMASK_BITS); + str++; + } + if (str[0] == '+') { + flags |= 1; + str++; + } + + if (!strcmp(str, "all")) { + bitmap_fill(bm, MAX_CPUMASK_BITS); + return flags; + } + + if (parse_uint(str, &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 (flags & 2) + bitmap_clear(bm, value, endvalue - value + 1); + else + bitmap_set(bm, value, endvalue - value + 1); + + return flags; + +error: + fprintf(stderr, "qemu: Invalid host NUMA nodes range: %s\n", str); + return 4; +} + static void numa_add(const char *optarg) { char option[128]; char *endptr; unsigned long long nodenr; + unsigned int ret; optarg = get_opt_name(option, 128, optarg, ','); if (*optarg == ',') { @@ -1393,6 +1450,23 @@ static void numa_add(const char *optarg) if (get_param_value(option, 128, "cpus", optarg) != 0) { numa_node_parse_cpus(nodenr, option); } + + option[0] = 0; + if (get_param_value(option, 128, "interleave", optarg) != 0) + numa_info[nodenr].flags |= NODE_HOST_INTERLEAVE; + else if (get_param_value(option, 128, "preferred", optarg) != 0) + numa_info[nodenr].flags |= NODE_HOST_PREFERRED; + else if (get_param_value(option, 128, "membind", optarg) != 0) + numa_info[nodenr].flags |= NODE_HOST_BIND; + if (option[0] != 0) { + ret = numa_node_parse_mpol(option, numa_info[nodenr].host_mem); + if (ret == 4) { + exit(1); + } else if (ret & 1) { + numa_info[nodenr].flags |= NODE_HOST_RELATIVE; + } + } + nb_numa_nodes++; } else { fprintf(stderr, "Invalid -numa option: %s\n", option); @@ -2922,6 +2996,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;