qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>
Cc: qemu-devel@nongnu.org, Jiri Denemark <jdenemar@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH 1/4] target/i386: Use simple static property for "model-id"
Date: Mon, 17 Jul 2017 14:18:27 -0300	[thread overview]
Message-ID: <20170717171827.GR6020@localhost.localdomain> (raw)
In-Reply-To: <20170717140343.0026e05d@nial.brq.redhat.com>

On Mon, Jul 17, 2017 at 02:03:43PM +0200, Igor Mammedov wrote:
> On Wed, 12 Jul 2017 13:20:55 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > Instead of storing the raw CPUID data in CPUX86State and having
> > to convert the data back and forth on the QOM getter/setter, use
> > a simple static string property, and calculate CPUID data inside
> > cpu_x86_cpuid().
> wouldn't this slow down 'cpuid' instruction execution,
> especially in tcg mode?

It may add a few additional CPU cycles, but I really doubt we can
find a workload where CPUID speed has measurable impact.  See,
for example, how expensive the kernel KVM CPUID code
(kvm_cpuid(), kvm_find_cpuid_entry()) is.

Richard, what do you think?


> 
> Why do you need this patch except of nice code reduction it gives?

It's just for code reduction, and it is not needed for this
series, if I recall correctly.  It can be included later, if
necessary.

> 
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  target/i386/cpu.h |  2 +-
> >  target/i386/cpu.c | 62 ++++++++++++++++---------------------------------------
> >  2 files changed, 19 insertions(+), 45 deletions(-)
> > 
> > diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> > index 7a228af..f56a3ea 100644
> > --- a/target/i386/cpu.h
> > +++ b/target/i386/cpu.h
> > @@ -1151,7 +1151,7 @@ typedef struct CPUX86State {
> >      FeatureWordArray features;
> >      /* Features that were explicitly enabled/disabled */
> >      FeatureWordArray user_features;
> > -    uint32_t cpuid_model[12];
> > +    char *model_id;
> >  
> >      /* MTRRs */
> >      uint64_t mtrr_fixed[11];
> > diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> > index c571772..30b704c 100644
> > --- a/target/i386/cpu.c
> > +++ b/target/i386/cpu.c
> > @@ -1828,43 +1828,6 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,
> >      }
> >  }
> >  
> > -static char *x86_cpuid_get_model_id(Object *obj, Error **errp)
> > -{
> > -    X86CPU *cpu = X86_CPU(obj);
> > -    CPUX86State *env = &cpu->env;
> > -    char *value;
> > -    int i;
> > -
> > -    value = g_malloc(48 + 1);
> > -    for (i = 0; i < 48; i++) {
> > -        value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3));
> > -    }
> > -    value[48] = '\0';
> > -    return value;
> > -}
> > -
> > -static void x86_cpuid_set_model_id(Object *obj, const char *model_id,
> > -                                   Error **errp)
> > -{
> > -    X86CPU *cpu = X86_CPU(obj);
> > -    CPUX86State *env = &cpu->env;
> > -    int c, len, i;
> > -
> > -    if (model_id == NULL) {
> > -        model_id = "";
> > -    }
> > -    len = strlen(model_id);
> > -    memset(env->cpuid_model, 0, 48);
> > -    for (i = 0; i < 48; i++) {
> > -        if (i >= len) {
> > -            c = '\0';
> > -        } else {
> > -            c = (uint8_t)model_id[i];
> > -        }
> > -        env->cpuid_model[i >> 2] |= c << (8 * (i & 3));
> > -    }
> > -}
> > -
> >  static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, const char *name,
> >                                     void *opaque, Error **errp)
> >  {
> > @@ -2899,10 +2862,23 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
> >      case 0x80000002:
> >      case 0x80000003:
> >      case 0x80000004:
> > -        *eax = env->cpuid_model[(index - 0x80000002) * 4 + 0];
> > -        *ebx = env->cpuid_model[(index - 0x80000002) * 4 + 1];
> > -        *ecx = env->cpuid_model[(index - 0x80000002) * 4 + 2];
> > -        *edx = env->cpuid_model[(index - 0x80000002) * 4 + 3];
> > +        {
> > +            int i;
> > +            int len = strlen(env->model_id);
> > +            uint32_t model[4] = { 0, 0, 0, 0 };
> > +
> > +            for (i = 0; i < 16; i++) {
> > +                int p = (index - 0x80000002) * 16 + i;
> > +                if (p >= len) {
> > +                    continue;
> > +                }
> > +                model[i >> 2] |= ((uint8_t)env->model_id[p]) << (8 * (i & 3));
> > +            }
> > +            *eax = model[0];
> > +            *ebx = model[1];
> > +            *ecx = model[2];
> > +            *edx = model[3];
> > +        }
> >          break;
> >      case 0x80000005:
> >          /* cache info (L1 cache) */
> > @@ -3868,9 +3844,6 @@ static void x86_cpu_initfn(Object *obj)
> >      object_property_add_str(obj, "vendor",
> >                              x86_cpuid_get_vendor,
> >                              x86_cpuid_set_vendor, NULL);
> > -    object_property_add_str(obj, "model-id",
> > -                            x86_cpuid_get_model_id,
> > -                            x86_cpuid_set_model_id, NULL);
> >      object_property_add(obj, "tsc-frequency", "int",
> >                          x86_cpuid_get_tsc_freq,
> >                          x86_cpuid_set_tsc_freq, NULL, NULL, NULL);
> > @@ -4004,6 +3977,7 @@ static Property x86_cpu_properties[] = {
> >      DEFINE_PROP_UINT32("phys-bits", X86CPU, phys_bits, 0),
> >      DEFINE_PROP_BOOL("host-phys-bits", X86CPU, host_phys_bits, false),
> >      DEFINE_PROP_BOOL("fill-mtrr-mask", X86CPU, fill_mtrr_mask, true),
> > +    DEFINE_PROP_STRING("model-id", X86CPU, env.model_id),
> >      DEFINE_PROP_UINT32("level", X86CPU, env.cpuid_level, UINT32_MAX),
> >      DEFINE_PROP_UINT32("xlevel", X86CPU, env.cpuid_xlevel, UINT32_MAX),
> >      DEFINE_PROP_UINT32("xlevel2", X86CPU, env.cpuid_xlevel2, UINT32_MAX),
> 

-- 
Eduardo

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

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12 16:20 [Qemu-devel] [PATCH 0/4] Fix SVM and KVM features reported on "max" CPU model Eduardo Habkost
2017-07-12 16:20 ` [Qemu-devel] [PATCH 1/4] target/i386: Use simple static property for "model-id" Eduardo Habkost
2017-07-17 12:03   ` Igor Mammedov
2017-07-17 17:18     ` Eduardo Habkost [this message]
2017-07-18 11:29       ` Igor Mammedov
2017-07-24 21:11         ` Paolo Bonzini
2017-07-24 23:04           ` Eduardo Habkost
2017-07-12 16:20 ` [Qemu-devel] [PATCH 2/4] target/i386: Use host_vendor_fms() in max_x86_cpu_initfn() Eduardo Habkost
2017-07-18 11:48   ` Igor Mammedov
2017-07-12 16:20 ` [Qemu-devel] [PATCH 3/4] target/i386: Define CPUID_MODEL_ID_SZ macro Eduardo Habkost
2017-07-12 16:20 ` [Qemu-devel] [PATCH 4/4] target/i386: Don't use x86_cpu_load_def() on "max" CPU model Eduardo Habkost
2017-07-18 13:27   ` Igor Mammedov
2017-07-19  0:02     ` Eduardo Habkost
2017-07-19  7:23       ` Igor Mammedov

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=20170717171827.GR6020@localhost.localdomain \
    --to=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jdenemar@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).