qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: "Marcel Apfelbaum" <marcel.a@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	"Don Slutz" <dslutz@verizon.com>,
	qemu-devel@nongnu.org, "Igor Mammedov" <imammedo@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature
Date: Sat, 16 Aug 2014 23:03:07 +0200	[thread overview]
Message-ID: <20140816210307.GA14045@redhat.com> (raw)
In-Reply-To: <20140814235917.GN3011@thinpad.lan.raisama.net>

On Thu, Aug 14, 2014 at 08:59:17PM -0300, Eduardo Habkost wrote:
> On Thu, Aug 14, 2014 at 11:08:30PM +0200, Michael S. Tsirkin wrote:
> > On Thu, Aug 14, 2014 at 04:25:56PM -0300, Eduardo Habkost wrote:
> > > The "kvmclock" feature is special because it affects two bits in the KVM
> > > CPUID leaf, so it has to be handled differently from the other feature
> > > properties that will be added.
> > > 
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > >  target-i386/cpu.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 61 insertions(+)
> > > 
> > > diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> > > index b005b0d..0eb401b 100644
> > > --- a/target-i386/cpu.c
> > > +++ b/target-i386/cpu.c
> > > @@ -2774,6 +2774,61 @@ uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
> > >      }
> > >  }
> > >  
> > > +typedef struct FeatureProperty {
> > > +    FeatureWord word;
> > > +    uint32_t mask;
> > > +} FeatureProperty;
> > > +
> > > +
> > > +static void x86_cpu_get_feature_prop(Object *obj,
> > > +                                     struct Visitor *v,
> > > +                                     void *opaque,
> > > +                                     const char *name,
> > > +                                     Error **errp)
> > > +{
> > > +    X86CPU *cpu = X86_CPU(obj);
> > > +    CPUX86State *env = &cpu->env;
> > > +    FeatureProperty *fp = opaque;
> > > +    bool value = (env->features[fp->word] & fp->mask) == fp->mask;
> > > +    visit_type_bool(v, &value, name, errp);
> > > +}
> > > +
> > > +static void x86_cpu_set_feature_prop(Object *obj,
> > > +                                     struct Visitor *v,
> > > +                                     void *opaque,
> > > +                                     const char *name,
> > > +                                     Error **errp)
> > > +{
> > > +    X86CPU *cpu = X86_CPU(obj);
> > > +    CPUX86State *env = &cpu->env;
> > > +    FeatureProperty *fp = opaque;
> > > +    bool value;
> > > +    visit_type_bool(v, &value, name, errp);
> > > +    if (value) {
> > > +        env->features[fp->word] |= fp->mask;
> > > +    } else {
> > > +        env->features[fp->word] &= ~fp->mask;
> > > +    }
> > > +}
> > > +
> > > +/* Register a boolean feature-bits property.
> > > + * If mask has multiple bits, all must be set for the property to return true.
> > > + */
> > > +static void x86_cpu_register_feature_prop(X86CPU *cpu,
> > > +                                          const char *prop_name,
> > > +                                          FeatureWord w,
> > > +                                          uint32_t mask)
> > > +{
> > > +    FeatureProperty *fp;
> > > +    fp = g_new0(FeatureProperty, 1);
> > > +    fp->word = w;
> > > +    fp->mask = mask;
> > > +    object_property_add(OBJECT(cpu), prop_name, "bool",
> > > +                        x86_cpu_set_feature_prop,
> > > +                        x86_cpu_get_feature_prop,
> > > +                        NULL, fp, &error_abort);
> > > +}
> > > +
> > 
> > This looks similar to what what DEFINE_PROP_BIT does.
> > Can't this be reused in some way?
> 
> DEFINE_PROP_BIT is from the static property system, and I understand we
> are preferring using object_property_add*() instead (and in the X86CPU
> features case, registering the properties dynamically using the feature
> name arrays saves us a lot of work).
> 
> I will take a look at the DEFINE_PROP_BIT code to see if anything from
> that code can be reused, but I doubt so. It seems to be tightly coupled
> to the static property system.

Main point is, can't we find a way to reduce code duplication?
It doesn't seem reasonable that we basically open-code
each property from scratch.

> > 
> > 
> > >  static void x86_cpu_initfn(Object *obj)
> > >  {
> > >      CPUState *cs = CPU(obj);
> > > @@ -2819,6 +2874,12 @@ static void x86_cpu_initfn(Object *obj)
> > >                          x86_cpu_get_feature_words,
> > >                          NULL, NULL, (void *)cpu->filtered_features, NULL);
> > >  
> > > +    /* "feat-kvmclock" will affect both kvmclock feature bits */
> > > +    x86_cpu_register_feature_prop(cpu, "feat-kvmclock", FEAT_KVM,
> > > +                                  (1UL << KVM_FEATURE_CLOCKSOURCE) |
> > > +                                  (1UL << KVM_FEATURE_CLOCKSOURCE2));
> > > +
> > > +
> > >      cpu->hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
> > >      env->cpuid_apic_id = x86_cpu_apic_id_from_index(cs->cpu_index);
> > >  
> > > -- 
> > > 1.9.3
> 
> -- 
> Eduardo

  reply	other threads:[~2014-08-16 21:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-14 19:25 [Qemu-devel] [PATCH v4 00/33] Convert PC machine-types to QOM classes Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 01/33] pc: Replace tabs with spaces on pc.h Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 02/33] vl.c: Use qdev_prop_register_global() for single globals Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 03/33] pc: Eliminate has_pci_info global variable Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 04/33] piix: Add kvmclock_enabled, pci_enabled globals Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 05/33] piix: Eliminate pc_init_pci() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 06/33] piix: Move pc-0.14 qxl compat properties to PC_COMPAT_0_14 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 07/33] piix: Move pc-0.13 virtio-9p-pci compat to PC_COMPAT_0_13 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 08/33] piix: Move pc-0.1[23] rombar compat props " Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 09/33] piix: Move pc-0.11 drive version compat props to PC_COMPAT_0_11 Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 10/33] machine: Make compat_props a linked list Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 11/33] pc: Register machine classes directly instead of using QEMUMachine Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 12/33] pc: Eliminate pc_common_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 13/33] pc: Eliminate pc_default_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 14/33] piix: Eliminate pc_i440fx_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 15/33] q35: Eliminate pc_q35_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 16/33] q35: Eliminate pc_q35_1_4_machine_options() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 17/33] pc: Eliminate all *_machine_options() functions Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 18/33] machine: Eliminate QEMUMachine.compat_props Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 19/33] pc: Rename pc_machine variable to pcms Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 20/33] pc: Pass PCMachineState argument to pc_cpus_init() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 21/33] machine: Add MachineClass.default_cpu_model field Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 22/33] pc: Move globals to PCMachineClass Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 23/33] pc: Move option_rom_has_mr/rom_file_has_mr to MachineClass Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 24/33] pc: Add PCMachineClass.compat_apic_id_mode field Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 25/33] target-i386: Move error handling to end of x86_cpu_parse_featurestr() Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 26/33] target-i386: Renove underscores from feature names Eduardo Habkost
2014-08-14 19:31   ` Michael S. Tsirkin
2014-08-14 19:32     ` Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 27/33] target-i386: Register X86CPU "feat-kvmclock" feature Eduardo Habkost
2014-08-14 21:08   ` Michael S. Tsirkin
2014-08-14 23:59     ` Eduardo Habkost
2014-08-16 21:03       ` Michael S. Tsirkin [this message]
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 28/33] target-i386: set [+-]feature using QOM properties Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 29/33] pc: Use compat_props for CPUID compat bits Eduardo Habkost
2014-08-14 19:25 ` [Qemu-devel] [PATCH v4 30/33] target-i386: Move some declarations to hw/i386/cpu.h Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 31/33] pc: Add default KVM features fields to PCMachineClass Eduardo Habkost
2014-08-14 21:09   ` Michael S. Tsirkin
2014-08-15  0:04     ` Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 32/33] pc: Eliminate pc_compat_*() functions Eduardo Habkost
2014-08-14 19:26 ` [Qemu-devel] [PATCH v4 33/33] piix: Move pc_xen_hvm_init() closer to xenfv_machine_class_init() Eduardo Habkost
2014-08-14 20:03   ` Michael S. Tsirkin
2014-08-15  0:03     ` 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=20140816210307.GA14045@redhat.com \
    --to=mst@redhat.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=dslutz@verizon.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).