From nobody Wed Nov 5 10:58:06 2025 Return-Path: qemu-devel-bounces+famz=redhat.com@nongnu.org Received: from zmta01.collab.prod.int.phx2.redhat.com (LHLO zmta01.collab.prod.int.phx2.redhat.com) (10.5.81.8) by zmail26.collab.prod.int.phx2.redhat.com with LMTP; Mon, 4 Sep 2017 10:01:49 -0400 (EDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by zmta01.collab.prod.int.phx2.redhat.com (Postfix) with ESMTP id 539B4185F00 for ; Mon, 4 Sep 2017 10:01:49 -0400 (EDT) Received: by smtp.corp.redhat.com (Postfix) id 4FA879AD2F; Mon, 4 Sep 2017 14:01:49 +0000 (UTC) Delivered-To: famz@redhat.com Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4840C9AD2E for ; Mon, 4 Sep 2017 14:01:47 +0000 (UTC) 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 mx1.redhat.com (Postfix) with ESMTPS id 6B17AC010D65 for ; Mon, 4 Sep 2017 14:01:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6B17AC010D65 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=qemu-devel-bounces+famz=redhat.com@nongnu.org DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6B17AC010D65 Received: from localhost ([::1]:44649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dorwa-0003g5-LQ for famz@redhat.com; Mon, 04 Sep 2017 10:01:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dorwC-0003fH-MF for qemu-devel@nongnu.org; Mon, 04 Sep 2017 10:01:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dorw2-0003nE-Sc for qemu-devel@nongnu.org; Mon, 04 Sep 2017 10:01:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32844) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dorw2-0003mY-KL for qemu-devel@nongnu.org; Mon, 04 Sep 2017 10:01:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91F74A963F; Mon, 4 Sep 2017 14:01:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91F74A963F Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 9177066829; Mon, 4 Sep 2017 14:01:04 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 4 Sep 2017 16:00:57 +0200 Message-Id: <1504533662-198084-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1504533662-198084-1-git-send-email-imammedo@redhat.com> References: <1504533662-198084-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 04 Sep 2017 14:01:05 +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 1/6] 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: , Cc: Andrew Jones , Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+famz=redhat.com@nongnu.org Sender: "Qemu-devel" X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 205 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 04 Sep 2017 14:01:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 04 Sep 2017 14:01:41 +0000 (UTC) for IP:'208.118.235.17' DOMAIN:'lists.gnu.org' HELO:'lists.gnu.org' FROM:'redhat.com@nongnu.org' RCPT:'' X-RedHat-Spam-Score: -5.02 (HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS) 208.118.235.17 lists.gnu.org 208.118.235.17 lists.gnu.org X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Content-Length: 3529 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=C3=A9 --- 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 b7ac949..a92a7d2 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -633,6 +633,27 @@ void cpu_reset(CPUState *cpu); ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model= ); =20 /** + * 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_features: + * @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_features(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 deb8880..d715890 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -53,13 +53,26 @@ bool cpu_exists(int64_t id) return !!cpu_by_arch_id(id); } =20 -CPUState *cpu_generic_init(const char *typename, const char *cpu_model) +CPUState *cpu_create(const char *typename) +{ + Error *err =3D NULL; + CPUState *cpu =3D CPU(object_new(typename)); + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + if (err !=3D NULL) { + error_report_err(err); + object_unref(OBJECT(cpu)); + return NULL; + } + return cpu; +} + +const char *cpu_parse_features(const char *typename, const char *cpu_model) { - CPUState *cpu =3D NULL; ObjectClass *oc; CPUClass *cc; Error *err =3D NULL; gchar **model_pieces; + const char *cpu_type; =20 model_pieces =3D g_strsplit(cpu_model, ",", 2); =20 @@ -69,27 +82,28 @@ CPUState *cpu_generic_init(const char *typename, const = char *cpu_model) return NULL; } =20 + cpu_type =3D object_class_get_name(oc); cc =3D 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 !=3D NULL) { - goto out; - } - - cpu =3D CPU(object_new(object_class_get_name(oc))); - object_property_set_bool(OBJECT(cpu), true, "realized", &err); - -out: - if (err !=3D NULL) { error_report_err(err); - object_unref(OBJECT(cpu)); return NULL; } + return cpu_type; +} =20 - 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_ini= t(). + */ + const char *cpu_type =3D cpu_parse_features(typename, cpu_model); + + if (cpu_type) { + return cpu_create(cpu_type); + } + return NULL; } =20 bool cpu_paging_enabled(const CPUState *cpu) --=20 2.7.4