From: Avi Kivity <avi@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>,
Ryan Harper <ryanh@us.ibm.com>,
qemu-devel qemu-devel <qemu-devel@nongnu.org>,
KVM list <kvm@vger.kernel.org>
Subject: Re: [Qemu-devel] [PATCH v2 1/3] KVM: Add new -cpu best
Date: Mon, 02 Jul 2012 17:25:50 +0300 [thread overview]
Message-ID: <4FF1AF6E.7070100@redhat.com> (raw)
In-Reply-To: <1340728795-4379-1-git-send-email-agraf@suse.de>
On 06/26/2012 07:39 PM, Alexander Graf wrote:
> During discussions on whether to make -cpu host the default in SLE, I found
> myself disagreeing to the thought, because it potentially opens a big can
> of worms for potential bugs. But if I already am so opposed to it for SLE, how
> can it possibly be reasonable to default to -cpu host in upstream QEMU? And
> what would a sane default look like?
>
> So I had this idea of looping through all available CPU definitions. We can
> pretty well tell if our host is able to execute any of them by checking the
> respective flags and seeing if our host has all features the CPU definition
> requires. With that, we can create a -cpu type that would fall back to the
> "best known CPU definition" that our host can fulfill. On my Phenom II
> system for example, that would be -cpu phenom.
>
> With this approach we can test and verify that CPU types actually work at
> any random user setup, because we can always verify that all the -cpu types
> we ship actually work. And we only default to some clever mechanism that
> chooses from one of these.
>
>
> +/* Are all guest feature bits present on the host? */
> +static bool cpu_x86_feature_subset(uint32_t host, uint32_t guest)
> +{
> + int i;
> +
> + for (i = 0; i < 32; i++) {
> + uint32_t mask = 1 << i;
> + if ((guest & mask) && !(host & mask)) {
> + return false;
> + }
> + }
> +
> + return true;
return !(guest & ~host);
> +}
> +
> +
> +
> +static void cpu_x86_fill_best(x86_def_t *x86_cpu_def)
> +{
> + x86_def_t *def;
> +
> + x86_cpu_def->family = 0;
> + x86_cpu_def->model = 0;
> + for (def = x86_defs; def; def = def->next) {
> + if (cpu_x86_fits_host(def) && cpu_x86_fits_higher(def, x86_cpu_def)) {
> + memcpy(x86_cpu_def, def, sizeof(*def));
> + }
*x86_cpu_def = *def;
> + }
> +
> + if (!x86_cpu_def->family && !x86_cpu_def->model) {
> + fprintf(stderr, "No fitting CPU model found!\n");
> + exit(1);
> + }
> +}
> +
> static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)
> {
> int i;
> @@ -878,6 +957,8 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
> break;
> if (kvm_enabled() && name && strcmp(name, "host") == 0) {
> cpu_x86_fill_host(x86_cpu_def);
> + } else if (kvm_enabled() && name && strcmp(name, "best") == 0) {
> + cpu_x86_fill_best(x86_cpu_def);
> } else if (!def) {
> goto error;
> } else {
>
Should we copy the cache size etc. from the host?
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2012-07-02 14:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1340728795-4379-1-git-send-email-agraf@suse.de>
2012-07-02 14:02 ` [Qemu-devel] [PATCH v2 1/3] KVM: Add new -cpu best Alexander Graf
2012-07-02 14:24 ` Andreas Färber
2012-07-02 14:25 ` Avi Kivity [this message]
2012-07-09 11:57 ` Alexander Graf
[not found] ` <1340728795-4379-2-git-send-email-agraf@suse.de>
2012-07-02 14:27 ` [Qemu-devel] [PATCH v2 2/3] KVM: Use -cpu best as default on x86 Avi Kivity
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=4FF1AF6E.7070100@redhat.com \
--to=avi@redhat.com \
--cc=agraf@suse.de \
--cc=anthony@codemonkey.ws \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=ryanh@us.ibm.com \
/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).