From nobody Mon Apr 29 13:04:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501095299979868.3872823092751; Wed, 26 Jul 2017 11:54:59 -0700 (PDT) Received: from localhost ([::1]:39624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daRSU-00079b-Oo for importer@patchew.org; Wed, 26 Jul 2017 14:54:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daRQm-0005Gj-0C for qemu-devel@nongnu.org; Wed, 26 Jul 2017 14:53:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1daRQk-0006fI-W0 for qemu-devel@nongnu.org; Wed, 26 Jul 2017 14:53:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1daRQk-0006eb-Pc for qemu-devel@nongnu.org; Wed, 26 Jul 2017 14:53:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5423CC00D886; Wed, 26 Jul 2017 18:53:09 +0000 (UTC) Received: from localhost (ovpn-116-63.gru2.redhat.com [10.97.116.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3AAF60C14; Wed, 26 Jul 2017 18:53:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5423CC00D886 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=fail smtp.mailfrom=ehabkost@redhat.com Date: Wed, 26 Jul 2017 15:53:05 -0300 From: Eduardo Habkost To: Yi Wang Message-ID: <20170726185305.GG5167@localhost.localdomain> References: <1501049917-4701-1-git-send-email-wang.yi59@zte.com.cn> <1501049917-4701-3-git-send-email-wang.yi59@zte.com.cn> <20170726173638.GG20793@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170726173638.GG20793@localhost.localdomain> X-Fnord: you can see the fnord User-Agent: Mutt/1.8.0 (2017-02-23) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 26 Jul 2017 18:53:09 +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] cpu: cpu_by_arch_id() helper 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: qemu-devel@nongnu.org, liu.yunh@zte.com.cn, armbru@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, Liu.Jianjun3@zte.com.cn, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The helper can be used for CPU object lookup using the CPU's arch-specific ID (the one returned by CPUClass::get_arch_id()). Signed-off-by: Eduardo Habkost [Yi Wang: Added documentation comments] Signed-off-by: Yi Wang Signed-off-by: Yun Liu [ehabkost: extracted cpu_by_arch_id() to a separate patch] Signed-off-by: Eduardo Habkost --- On Wed, Jul 26, 2017 at 02:36:38PM -0300, Eduardo Habkost wrote: > I suggest sending cpu_by_arch_id() in a separate patch, to let > maintainers cherry-pick and revert individual patches more > easily. But there's no need to send v3 just because of that, I > can split it while committing. This is the patch I am queueing for 2.11 on my x86-next branch. --- include/qom/cpu.h | 10 ++++++++++ qom/cpu.c | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 25eefea..b7ac949 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -755,6 +755,16 @@ CPUState *qemu_get_cpu(int index); bool cpu_exists(int64_t id); =20 /** + * cpu_by_arch_id: + * @id: Guest-exposed CPU ID of the CPU to obtain. + * + * Get a CPU with matching @id. + * + * Returns: The CPU or %NULL if there is no matching CPU. + */ +CPUState *cpu_by_arch_id(int64_t id); + +/** * cpu_throttle_set: * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99. * diff --git a/qom/cpu.c b/qom/cpu.c index 4f38db0..e6210d5 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -34,7 +34,7 @@ =20 CPUInterruptHandler cpu_interrupt_handler; =20 -bool cpu_exists(int64_t id) +CPUState *cpu_by_arch_id(int64_t id) { CPUState *cpu; =20 @@ -42,10 +42,15 @@ bool cpu_exists(int64_t id) CPUClass *cc =3D CPU_GET_CLASS(cpu); =20 if (cc->get_arch_id(cpu) =3D=3D id) { - return true; + return cpu; } } - return false; + return NULL; +} + +bool cpu_exists(int64_t id) +{ + return !!cpu_by_arch_id(id); } =20 CPUState *cpu_generic_init(const char *typename, const char *cpu_model) --=20 2.9.4