From patchwork Wed Feb 19 07:53:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 321771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 213442C02FB for ; Wed, 19 Feb 2014 19:00:06 +1100 (EST) Received: from localhost ([::1]:57009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG24a-0004yD-6g for incoming@patchwork.ozlabs.org; Wed, 19 Feb 2014 03:00:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG20u-0007Rq-Qw for qemu-devel@nongnu.org; Wed, 19 Feb 2014 02:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WG20l-0003VQ-Ud for qemu-devel@nongnu.org; Wed, 19 Feb 2014 02:56:16 -0500 Received: from [222.73.24.84] (port=23891 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WG20l-0003T0-1U for qemu-devel@nongnu.org; Wed, 19 Feb 2014 02:56:07 -0500 X-IronPort-AV: E=Sophos;i="4.97,504,1389715200"; d="scan'208";a="9558771" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 19 Feb 2014 15:52: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 s1J7trHE012639; Wed, 19 Feb 2014 15:55:53 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com ([10.167.226.102]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014021915534225-35699 ; Wed, 19 Feb 2014 15:53:42 +0800 From: Hu Tao To: qemu-devel@nongnu.org Date: Wed, 19 Feb 2014 15:53:55 +0800 Message-Id: X-Mailer: git-send-email 1.8.5.2.229.g4448466 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/19 15:53:42, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/02/19 15:53:45, Serialize complete at 2014/02/19 15:53:45 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: pbonzini@redhat.com, lersek@redhat.com, Wanlong Gao , imammedo@redhat.com Subject: [Qemu-devel] [PATCH v18 04/14] NUMA: convert -numa option to use OptsVisitor 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 From: Wanlong Gao Signed-off-by: Wanlong Gao Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao --- include/sysemu/sysemu.h | 3 +- numa.c | 148 +++++++++++++++++++++++------------------------- qapi-schema.json | 30 ++++++++++ vl.c | 11 +++- 4 files changed, 114 insertions(+), 78 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index d873b42..20b05a3 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -140,9 +140,10 @@ typedef struct node_info { DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); } NodeInfo; extern NodeInfo numa_info[MAX_NODES]; -void numa_add(const char *optarg); void set_numa_nodes(void); void set_numa_modes(void); +extern QemuOptsList qemu_numa_opts; +int numa_init_func(QemuOpts *opts, void *opaque); #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { diff --git a/numa.c b/numa.c index 1f413a0..827c76f 100644 --- a/numa.c +++ b/numa.c @@ -24,101 +24,97 @@ */ #include "sysemu/sysemu.h" - -static void numa_node_parse_cpus(int nodenr, const char *cpus) +#include "qapi-visit.h" +#include "qapi/opts-visitor.h" +#include "qapi/dealloc-visitor.h" +QemuOptsList qemu_numa_opts = { + .name = "numa", + .implied_opt_name = "type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_numa_opts.head), + .desc = { { 0 } } /* validated with OptsVisitor */ +}; + +static int numa_node_parse(NumaNodeOptions *opts) { - char *endptr; - unsigned long long value, endvalue; - - /* Empty CPU range strings will be considered valid, they will simply - * not set any bit in the CPU bitmap. - */ - if (!*cpus) { - return; - } + uint16_t nodenr; + uint16List *cpus = NULL; - if (parse_uint(cpus, &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; + if (opts->has_nodeid) { + nodenr = opts->nodeid; } else { - goto error; + nodenr = nb_numa_nodes; } - if (endvalue >= MAX_CPUMASK_BITS) { - endvalue = MAX_CPUMASK_BITS - 1; - fprintf(stderr, - "qemu: NUMA: A max of %d VCPUs are supported\n", - MAX_CPUMASK_BITS); + if (nodenr >= MAX_NODES) { + fprintf(stderr, "qemu: Max number of NUMA nodes reached: %" + PRIu16 "\n", nodenr); + return -1; } - if (endvalue < value) { - goto error; + for (cpus = opts->cpus; cpus; cpus = cpus->next) { + if (cpus->value > MAX_CPUMASK_BITS) { + fprintf(stderr, "qemu: cpu number %" PRIu16 " is bigger than %d", + cpus->value, MAX_CPUMASK_BITS); + continue; + } + bitmap_set(numa_info[nodenr].node_cpu, cpus->value, 1); } - bitmap_set(numa_info[nodenr].node_cpu, value, endvalue-value+1); - return; + if (opts->has_mem) { + int64_t mem_size; + char *endptr; + mem_size = strtosz(opts->mem, &endptr); + if (mem_size < 0 || *endptr) { + fprintf(stderr, "qemu: invalid numa mem size: %s\n", opts->mem); + return -1; + } + numa_info[nodenr].node_mem = mem_size; + } -error: - fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus); - exit(1); + return 0; } -void numa_add(const char *optarg) +int numa_init_func(QemuOpts *opts, void *opaque) { - char option[128]; - char *endptr; - unsigned long long nodenr; - - optarg = get_opt_name(option, 128, optarg, ','); - if (*optarg == ',') { - optarg++; + NumaOptions *object = NULL; + Error *err = NULL; + int ret = 0; + + { + OptsVisitor *ov = opts_visitor_new(opts); + visit_type_NumaOptions(opts_get_visitor(ov), &object, NULL, &err); + opts_visitor_cleanup(ov); } - if (!strcmp(option, "node")) { - - if (nb_numa_nodes >= MAX_NODES) { - fprintf(stderr, "qemu: too many NUMA nodes\n"); - exit(1); - } - if (get_param_value(option, 128, "nodeid", optarg) == 0) { - nodenr = nb_numa_nodes; - } else { - if (parse_uint_full(option, &nodenr, 10) < 0) { - fprintf(stderr, "qemu: Invalid NUMA nodeid: %s\n", option); - exit(1); - } - } - - if (nodenr >= MAX_NODES) { - fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr); - exit(1); - } + if (error_is_set(&err)) { + fprintf(stderr, "qemu: %s\n", error_get_pretty(err)); + error_free(err); + ret = -1; + goto error; + } - if (get_param_value(option, 128, "mem", optarg) == 0) { - numa_info[nodenr].node_mem = 0; - } else { - int64_t sval; - sval = strtosz(option, &endptr); - if (sval < 0 || *endptr) { - fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); - exit(1); - } - numa_info[nodenr].node_mem = sval; - } - if (get_param_value(option, 128, "cpus", optarg) != 0) { - numa_node_parse_cpus(nodenr, option); + switch (object->kind) { + case NUMA_OPTIONS_KIND_NODE: + ret = numa_node_parse(object->node); + if (ret) { + goto error; } nb_numa_nodes++; - } else { - fprintf(stderr, "Invalid -numa option: %s\n", option); - exit(1); + break; + default: + fprintf(stderr, "qemu: Invalid NUMA options type.\n"); + ret = -1; } + +error: + if (object) { + QapiDeallocVisitor *dv = qapi_dealloc_visitor_new(); + visit_type_NumaOptions(qapi_dealloc_get_visitor(dv), + &object, NULL, NULL); + qapi_dealloc_visitor_cleanup(dv); + } + + return ret; } void set_numa_nodes(void) diff --git a/qapi-schema.json b/qapi-schema.json index 7cfb5e5..a2839b8 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4420,3 +4420,33 @@ # Since: 1.7 ## { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } } + +## +# @NumaOptions +# +# A discriminated record of NUMA options. (for OptsVisitor) +# +# Since 2.0 +## +{ 'union': 'NumaOptions', + 'data': { + 'node': 'NumaNodeOptions' }} + +## +# @NumaNodeOptions +# +# Create a guest NUMA node. (for OptsVisitor) +# +# @nodeid: #optional NUMA node ID +# +# @cpus: #optional VCPUs belong to this node +# +# @mem: #optional memory size of this node +# +# Since: 2.0 +## +{ 'type': 'NumaNodeOptions', + 'data': { + '*nodeid': 'uint16', + '*cpus': ['uint16'], + '*mem': 'str' }} diff --git a/vl.c b/vl.c index 915f8b7..e070649 100644 --- a/vl.c +++ b/vl.c @@ -2765,6 +2765,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_tpmdev_opts); qemu_add_opts(&qemu_realtime_opts); qemu_add_opts(&qemu_msg_opts); + qemu_add_opts(&qemu_numa_opts); runstate_init(); @@ -2952,7 +2953,10 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_numa: - numa_add(optarg); + opts = qemu_opts_parse(qemu_find_opts("numa"), optarg, 1); + if (!opts) { + exit(1); + } break; case QEMU_OPTION_display: display_type = select_display(optarg); @@ -4042,6 +4046,11 @@ int main(int argc, char **argv, char **envp) register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL); + if (qemu_opts_foreach(qemu_find_opts("numa"), numa_init_func, + NULL, 1) != 0) { + exit(1); + } + set_numa_nodes(); if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) {