qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Yi Wang <wang.yi59@zte.com.cn>
Cc: liu.yunh@zte.com.cn, armbru@redhat.com, qemu-devel@nongnu.org,
	dgilbert@redhat.com, imammedo@redhat.com, pbonzini@redhat.com,
	Liu.Jianjun3@zte.com.cn, rth@twiddle.net
Subject: [Qemu-devel] [PATCH] cpu: cpu_by_arch_id() helper
Date: Wed, 26 Jul 2017 15:53:05 -0300	[thread overview]
Message-ID: <20170726185305.GG5167@localhost.localdomain> (raw)
In-Reply-To: <20170726173638.GG20793@localhost.localdomain>

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 <ehabkost@redhat.com>
[Yi Wang: Added documentation comments]
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Signed-off-by: Yun Liu <liu.yunh@zte.com.cn>
[ehabkost: extracted cpu_by_arch_id() to a separate patch]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
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);
 
 /**
+ * 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 @@
 
 CPUInterruptHandler cpu_interrupt_handler;
 
-bool cpu_exists(int64_t id)
+CPUState *cpu_by_arch_id(int64_t id)
 {
     CPUState *cpu;
 
@@ -42,10 +42,15 @@ bool cpu_exists(int64_t id)
         CPUClass *cc = CPU_GET_CLASS(cpu);
 
         if (cc->get_arch_id(cpu) == id) {
-            return true;
+            return cpu;
         }
     }
-    return false;
+    return NULL;
+}
+
+bool cpu_exists(int64_t id)
+{
+    return !!cpu_by_arch_id(id);
 }
 
 CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
-- 
2.9.4

  reply	other threads:[~2017-07-26 18:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26  6:18 [Qemu-devel] [PATCH v2 0/2] hmp: support querying lapic through apic-id for 'info lapic' Yi Wang
2017-07-26  6:18 ` no-reply
2017-07-26  6:18 ` [Qemu-devel] [PATCH v2 1/2] hmp: dump ids including socket-id, core-id and so on for 'info registers' Yi Wang
2017-07-26 14:01   ` Eduardo Habkost
2017-07-26 14:27     ` Igor Mammedov
2017-07-26 17:50       ` Eduardo Habkost
2017-07-27 15:12         ` Igor Mammedov
2017-07-27 16:46           ` Eduardo Habkost
2017-07-26 14:29   ` Igor Mammedov
2017-07-26  6:18 ` [Qemu-devel] [PATCH v2 2/2] hmp: allow apic-id for "info lapic" Yi Wang
2017-07-26 17:36   ` Eduardo Habkost
2017-07-26 18:53     ` Eduardo Habkost [this message]
2017-07-26 18:53   ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170726185305.GG5167@localhost.localdomain \
    --to=ehabkost@redhat.com \
    --cc=Liu.Jianjun3@zte.com.cn \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=liu.yunh@zte.com.cn \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=wang.yi59@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).