qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/4] target/i386: Use simple static property for


From: Igor Mammedov
Subject: Re: [Qemu-devel] [PATCH 1/4] target/i386: Use simple static property for "model-id"
Date: Tue, 18 Jul 2017 13:29:55 +0200

On Mon, 17 Jul 2017 14:18:27 -0300
Eduardo Habkost <address@hidden> wrote:

> On Mon, Jul 17, 2017 at 02:03:43PM +0200, Igor Mammedov wrote:
> > On Wed, 12 Jul 2017 13:20:55 -0300
> > Eduardo Habkost <address@hidden> 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.
I don't expect that it would affect KVM, but for TCG any instruction
execution is 'fast' path, so I'd leave current cpu_x86_cpuid()
not to loose those few cycles, it's not worth sacrifice for the sake of cleanup.

> 
> 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 <address@hidden>
> > > ---
> > >  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),  
> >   
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]