qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH 2/3] target-i386: introduce x86_cpu_nr_apic_ids
Date: Wed,  5 Nov 2014 22:53:32 +0100	[thread overview]
Message-ID: <1415224413-13972-3-git-send-email-rkrcmar@redhat.com> (raw)
In-Reply-To: <1415224413-13972-1-git-send-email-rkrcmar@redhat.com>

The number of available APIC IDs depends on chosen topology, because
core/smt choices different from a power of two waste some IDs.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 target-i386/cpu.c | 16 ++++++++++++++++
 target-i386/cpu.h |  1 +
 2 files changed, 17 insertions(+)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e194601..c77ec76 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2815,6 +2815,22 @@ uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
     }
 }
 
+/* The number of useable APIC IDs based on current topology.
+ *
+ * id_limit is the highest possible APIC ID + 1.
+ */
+unsigned x86_cpu_nr_apic_ids(unsigned id_limit)
+{
+    unsigned package_width;
+
+    if (compat_apic_id_mode)
+        return id_limit;
+
+    package_width = apicid_pkg_width(smp_cores, smp_threads, id_limit);
+
+    return MIN(id_limit, (1 << package_width) * smp_cores * smp_threads);
+}
+
 static void x86_cpu_initfn(Object *obj)
 {
     CPUState *cs = CPU(obj);
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 9f01831..367968d 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1372,6 +1372,7 @@ void x86_cpu_compat_disable_kvm_features(FeatureWord w, uint32_t features);
 const char *get_register_name_32(unsigned int reg);
 
 uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index);
+unsigned x86_cpu_nr_apic_ids(unsigned id_limit);
 void enable_compat_apic_id_mode(void);
 
 #define APIC_DEFAULT_ADDRESS 0xfee00000
-- 
2.1.0

  parent reply	other threads:[~2014-11-05 21:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05 21:53 [Qemu-devel] [PATCH 0/3] Improve error message on invalid CPU topologies Radim Krčmář
2014-11-05 21:53 ` [Qemu-devel] [PATCH 1/3] target-i386: add apicid_pkg_width to topology.h Radim Krčmář
2014-11-05 21:53 ` Radim Krčmář [this message]
2014-11-05 21:53 ` [Qemu-devel] [PATCH 3/3] pc: improve error message on invalid topologies Radim Krčmář

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=1415224413-13972-3-git-send-email-rkrcmar@redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=afaerber@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).