From patchwork Wed Sep 13 16:04:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 813524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xsn1K23Grz9s72 for ; Thu, 14 Sep 2017 02:19:33 +1000 (AEST) Received: from localhost ([::1]:43428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsANv-00012G-7b for incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 12:19:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsA9z-0002PX-4C for qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:05:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsA9t-0006YQ-Bo for qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:05:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsA9t-0006Xm-3R for qemu-devel@nongnu.org; Wed, 13 Sep 2017 12:05:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36B6C356C0 for ; Wed, 13 Sep 2017 16:05:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 36B6C356C0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE5075D963 for ; Wed, 13 Sep 2017 16:04:59 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 18:04:53 +0200 Message-Id: <1505318697-77161-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1505318697-77161-1-git-send-email-imammedo@redhat.com> References: <1505318697-77161-1-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 13 Sep 2017 16:05:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/5] qom: cpus: split cpu_generic_init() on feature parsing and cpu creation parts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" it would allow to reuse feature parsing part in various machines that have CPU features instead of re-implementing the same feature parsing each time. Signed-off-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daudé --- v2: - squash in "cpu: rename cpu_parse_features() to cpu_parse_cpu_model()" --- include/qom/cpu.h | 21 +++++++++++++++++++++ qom/cpu.c | 46 ++++++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 995a7be..885276c 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -645,6 +645,27 @@ void cpu_reset(CPUState *cpu); ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model); /** + * cpu_create: + * @typename: The CPU type. + * + * Instantiates a CPU and realizes the CPU. + * + * Returns: A #CPUState or %NULL if an error occurred. + */ +CPUState *cpu_create(const char *typename); + +/** + * cpu_parse_cpu_model: + * @typename: The CPU base type or CPU type. + * @cpu_model: The model string including optional parameters. + * + * processes optional parameters and registers them as global properties + * + * Returns: type of CPU to create or %NULL if an error occurred. + */ +const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model); + +/** * cpu_generic_init: * @typename: The CPU base type. * @cpu_model: The model string including optional parameters. diff --git a/qom/cpu.c b/qom/cpu.c index dc5392d..483f26a 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -54,13 +54,26 @@ bool cpu_exists(int64_t id) return !!cpu_by_arch_id(id); } -CPUState *cpu_generic_init(const char *typename, const char *cpu_model) +CPUState *cpu_create(const char *typename) +{ + Error *err = NULL; + CPUState *cpu = CPU(object_new(typename)); + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + if (err != NULL) { + error_report_err(err); + object_unref(OBJECT(cpu)); + return NULL; + } + return cpu; +} + +const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model) { - CPUState *cpu = NULL; ObjectClass *oc; CPUClass *cc; Error *err = NULL; gchar **model_pieces; + const char *cpu_type; model_pieces = g_strsplit(cpu_model, ",", 2); @@ -70,27 +83,28 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) return NULL; } + cpu_type = object_class_get_name(oc); cc = CPU_CLASS(oc); - /* TODO: all callers of cpu_generic_init() need to be converted to - * call parse_features() only once, before calling cpu_generic_init(). - */ - cc->parse_features(object_class_get_name(oc), model_pieces[1], &err); + cc->parse_features(cpu_type, model_pieces[1], &err); g_strfreev(model_pieces); if (err != NULL) { - goto out; - } - - cpu = CPU(object_new(object_class_get_name(oc))); - object_property_set_bool(OBJECT(cpu), true, "realized", &err); - -out: - if (err != NULL) { error_report_err(err); - object_unref(OBJECT(cpu)); return NULL; } + return cpu_type; +} - return cpu; +CPUState *cpu_generic_init(const char *typename, const char *cpu_model) +{ + /* TODO: all callers of cpu_generic_init() need to be converted to + * call cpu_parse_features() only once, before calling cpu_generic_init(). + */ + const char *cpu_type = cpu_parse_cpu_model(typename, cpu_model); + + if (cpu_type) { + return cpu_create(cpu_type); + } + return NULL; } bool cpu_paging_enabled(const CPUState *cpu)