diff mbox series

[13/24] i386: Register most CPU properties as class properties

Message ID 20200921221045.699690-14-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show
Series qom: Convert some properties to class properties | expand

Commit Message

Eduardo Habkost Sept. 21, 2020, 10:10 p.m. UTC
Class properties make QOM introspection simpler and easier, as
they don't require an object to be instantiated.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 target/i386/cpu.c | 66 ++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 32 deletions(-)

Comments

Igor Mammedov Sept. 22, 2020, 6:41 a.m. UTC | #1
On Mon, 21 Sep 2020 18:10:34 -0400
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Class properties make QOM introspection simpler and easier, as
> they don't require an object to be instantiated.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  target/i386/cpu.c | 66 ++++++++++++++++++++++++-----------------------
>  1 file changed, 34 insertions(+), 32 deletions(-)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 1c58f764dcb..66792f28ba7 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -6922,44 +6922,12 @@ static void x86_cpu_initfn(Object *obj)
>      env->nr_dies = 1;
>      cpu_set_cpustate_pointers(cpu);
>  
> -    object_property_add(obj, "family", "int",
> -                        x86_cpuid_version_get_family,
> -                        x86_cpuid_version_set_family, NULL, NULL);
> -    object_property_add(obj, "model", "int",
> -                        x86_cpuid_version_get_model,
> -                        x86_cpuid_version_set_model, NULL, NULL);
> -    object_property_add(obj, "stepping", "int",
> -                        x86_cpuid_version_get_stepping,
> -                        x86_cpuid_version_set_stepping, NULL, NULL);
> -    object_property_add_str(obj, "vendor",
> -                            x86_cpuid_get_vendor,
> -                            x86_cpuid_set_vendor);
> -    object_property_add_str(obj, "model-id",
> -                            x86_cpuid_get_model_id,
> -                            x86_cpuid_set_model_id);
> -    object_property_add(obj, "tsc-frequency", "int",
> -                        x86_cpuid_get_tsc_freq,
> -                        x86_cpuid_set_tsc_freq, NULL, NULL);


>      object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo",
>                          x86_cpu_get_feature_words,
>                          NULL, NULL, (void *)env->features);
>      object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo",
>                          x86_cpu_get_feature_words,
>                          NULL, NULL, (void *)cpu->filtered_features);

I'm just curious why these weren't moved as well?

> -    /*
> -     * The "unavailable-features" property has the same semantics as
> -     * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions"
> -     * QMP command: they list the features that would have prevented the
> -     * CPU from running if the "enforce" flag was set.
> -     */
> -    object_property_add(obj, "unavailable-features", "strList",
> -                        x86_cpu_get_unavailable_features,
> -                        NULL, NULL, NULL);
> -
> -#if !defined(CONFIG_USER_ONLY)
> -    object_property_add(obj, "crash-information", "GuestPanicInformation",
> -                        x86_cpu_get_crash_info_qom, NULL, NULL, NULL);
> -#endif
>  
>      for (w = 0; w < FEATURE_WORDS; w++) {
>          int bitnr;
> @@ -7308,6 +7276,40 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
>      cc->disas_set_info = x86_disas_set_info;
>  
>      dc->user_creatable = true;
> +
> +    object_class_property_add(oc, "family", "int",
> +                              x86_cpuid_version_get_family,
> +                              x86_cpuid_version_set_family, NULL, NULL);
> +    object_class_property_add(oc, "model", "int",
> +                              x86_cpuid_version_get_model,
> +                              x86_cpuid_version_set_model, NULL, NULL);
> +    object_class_property_add(oc, "stepping", "int",
> +                              x86_cpuid_version_get_stepping,
> +                              x86_cpuid_version_set_stepping, NULL, NULL);
> +    object_class_property_add_str(oc, "vendor",
> +                                  x86_cpuid_get_vendor,
> +                                  x86_cpuid_set_vendor);
> +    object_class_property_add_str(oc, "model-id",
> +                                  x86_cpuid_get_model_id,
> +                                  x86_cpuid_set_model_id);
> +    object_class_property_add(oc, "tsc-frequency", "int",
> +                              x86_cpuid_get_tsc_freq,
> +                              x86_cpuid_set_tsc_freq, NULL, NULL);
> +    /*
> +     * The "unavailable-features" property has the same semantics as
> +     * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions"
> +     * QMP command: they list the features that would have prevented the
> +     * CPU from running if the "enforce" flag was set.
> +     */
> +    object_class_property_add(oc, "unavailable-features", "strList",
> +                              x86_cpu_get_unavailable_features,
> +                              NULL, NULL, NULL);
> +
> +#if !defined(CONFIG_USER_ONLY)
> +    object_class_property_add(oc, "crash-information", "GuestPanicInformation",
> +                              x86_cpu_get_crash_info_qom, NULL, NULL, NULL);
> +#endif
> +
>  }
>  
>  static const TypeInfo x86_cpu_type_info = {
Eduardo Habkost Sept. 22, 2020, 12:44 p.m. UTC | #2
On Tue, Sep 22, 2020 at 08:41:49AM +0200, Igor Mammedov wrote:
> On Mon, 21 Sep 2020 18:10:34 -0400
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > Class properties make QOM introspection simpler and easier, as
> > they don't require an object to be instantiated.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: Richard Henderson <rth@twiddle.net>
> > Cc: Eduardo Habkost <ehabkost@redhat.com>
> > Cc: qemu-devel@nongnu.org
> > ---
> >  target/i386/cpu.c | 66 ++++++++++++++++++++++++-----------------------
> >  1 file changed, 34 insertions(+), 32 deletions(-)
> > 
> > diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> > index 1c58f764dcb..66792f28ba7 100644
> > --- a/target/i386/cpu.c
> > +++ b/target/i386/cpu.c
> > @@ -6922,44 +6922,12 @@ static void x86_cpu_initfn(Object *obj)
> >      env->nr_dies = 1;
> >      cpu_set_cpustate_pointers(cpu);
> >  
> > -    object_property_add(obj, "family", "int",
> > -                        x86_cpuid_version_get_family,
> > -                        x86_cpuid_version_set_family, NULL, NULL);
> > -    object_property_add(obj, "model", "int",
> > -                        x86_cpuid_version_get_model,
> > -                        x86_cpuid_version_set_model, NULL, NULL);
> > -    object_property_add(obj, "stepping", "int",
> > -                        x86_cpuid_version_get_stepping,
> > -                        x86_cpuid_version_set_stepping, NULL, NULL);
> > -    object_property_add_str(obj, "vendor",
> > -                            x86_cpuid_get_vendor,
> > -                            x86_cpuid_set_vendor);
> > -    object_property_add_str(obj, "model-id",
> > -                            x86_cpuid_get_model_id,
> > -                            x86_cpuid_set_model_id);
> > -    object_property_add(obj, "tsc-frequency", "int",
> > -                        x86_cpuid_get_tsc_freq,
> > -                        x86_cpuid_set_tsc_freq, NULL, NULL);
> 
> 
> >      object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo",
> >                          x86_cpu_get_feature_words,
> >                          NULL, NULL, (void *)env->features);
> >      object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo",
> >                          x86_cpu_get_feature_words,
> >                          NULL, NULL, (void *)cpu->filtered_features);
> 
> I'm just curious why these weren't moved as well?

Because of the (void*) arguments that need a pointer to the
instance.
Igor Mammedov Sept. 23, 2020, 8:43 a.m. UTC | #3
On Mon, 21 Sep 2020 18:10:34 -0400
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Class properties make QOM introspection simpler and easier, as
> they don't require an object to be instantiated.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>

Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Eduardo Habkost <ehabkost@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>  target/i386/cpu.c | 66 ++++++++++++++++++++++++-----------------------
>  1 file changed, 34 insertions(+), 32 deletions(-)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 1c58f764dcb..66792f28ba7 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -6922,44 +6922,12 @@ static void x86_cpu_initfn(Object *obj)
>      env->nr_dies = 1;
>      cpu_set_cpustate_pointers(cpu);
>  
> -    object_property_add(obj, "family", "int",
> -                        x86_cpuid_version_get_family,
> -                        x86_cpuid_version_set_family, NULL, NULL);
> -    object_property_add(obj, "model", "int",
> -                        x86_cpuid_version_get_model,
> -                        x86_cpuid_version_set_model, NULL, NULL);
> -    object_property_add(obj, "stepping", "int",
> -                        x86_cpuid_version_get_stepping,
> -                        x86_cpuid_version_set_stepping, NULL, NULL);
> -    object_property_add_str(obj, "vendor",
> -                            x86_cpuid_get_vendor,
> -                            x86_cpuid_set_vendor);
> -    object_property_add_str(obj, "model-id",
> -                            x86_cpuid_get_model_id,
> -                            x86_cpuid_set_model_id);
> -    object_property_add(obj, "tsc-frequency", "int",
> -                        x86_cpuid_get_tsc_freq,
> -                        x86_cpuid_set_tsc_freq, NULL, NULL);
>      object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo",
>                          x86_cpu_get_feature_words,
>                          NULL, NULL, (void *)env->features);
>      object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo",
>                          x86_cpu_get_feature_words,
>                          NULL, NULL, (void *)cpu->filtered_features);
> -    /*
> -     * The "unavailable-features" property has the same semantics as
> -     * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions"
> -     * QMP command: they list the features that would have prevented the
> -     * CPU from running if the "enforce" flag was set.
> -     */
> -    object_property_add(obj, "unavailable-features", "strList",
> -                        x86_cpu_get_unavailable_features,
> -                        NULL, NULL, NULL);
> -
> -#if !defined(CONFIG_USER_ONLY)
> -    object_property_add(obj, "crash-information", "GuestPanicInformation",
> -                        x86_cpu_get_crash_info_qom, NULL, NULL, NULL);
> -#endif
>  
>      for (w = 0; w < FEATURE_WORDS; w++) {
>          int bitnr;
> @@ -7308,6 +7276,40 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
>      cc->disas_set_info = x86_disas_set_info;
>  
>      dc->user_creatable = true;
> +
> +    object_class_property_add(oc, "family", "int",
> +                              x86_cpuid_version_get_family,
> +                              x86_cpuid_version_set_family, NULL, NULL);
> +    object_class_property_add(oc, "model", "int",
> +                              x86_cpuid_version_get_model,
> +                              x86_cpuid_version_set_model, NULL, NULL);
> +    object_class_property_add(oc, "stepping", "int",
> +                              x86_cpuid_version_get_stepping,
> +                              x86_cpuid_version_set_stepping, NULL, NULL);
> +    object_class_property_add_str(oc, "vendor",
> +                                  x86_cpuid_get_vendor,
> +                                  x86_cpuid_set_vendor);
> +    object_class_property_add_str(oc, "model-id",
> +                                  x86_cpuid_get_model_id,
> +                                  x86_cpuid_set_model_id);
> +    object_class_property_add(oc, "tsc-frequency", "int",
> +                              x86_cpuid_get_tsc_freq,
> +                              x86_cpuid_set_tsc_freq, NULL, NULL);
> +    /*
> +     * The "unavailable-features" property has the same semantics as
> +     * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions"
> +     * QMP command: they list the features that would have prevented the
> +     * CPU from running if the "enforce" flag was set.
> +     */
> +    object_class_property_add(oc, "unavailable-features", "strList",
> +                              x86_cpu_get_unavailable_features,
> +                              NULL, NULL, NULL);
> +
> +#if !defined(CONFIG_USER_ONLY)
> +    object_class_property_add(oc, "crash-information", "GuestPanicInformation",
> +                              x86_cpu_get_crash_info_qom, NULL, NULL, NULL);
> +#endif
> +
>  }
>  
>  static const TypeInfo x86_cpu_type_info = {
diff mbox series

Patch

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1c58f764dcb..66792f28ba7 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6922,44 +6922,12 @@  static void x86_cpu_initfn(Object *obj)
     env->nr_dies = 1;
     cpu_set_cpustate_pointers(cpu);
 
-    object_property_add(obj, "family", "int",
-                        x86_cpuid_version_get_family,
-                        x86_cpuid_version_set_family, NULL, NULL);
-    object_property_add(obj, "model", "int",
-                        x86_cpuid_version_get_model,
-                        x86_cpuid_version_set_model, NULL, NULL);
-    object_property_add(obj, "stepping", "int",
-                        x86_cpuid_version_get_stepping,
-                        x86_cpuid_version_set_stepping, NULL, NULL);
-    object_property_add_str(obj, "vendor",
-                            x86_cpuid_get_vendor,
-                            x86_cpuid_set_vendor);
-    object_property_add_str(obj, "model-id",
-                            x86_cpuid_get_model_id,
-                            x86_cpuid_set_model_id);
-    object_property_add(obj, "tsc-frequency", "int",
-                        x86_cpuid_get_tsc_freq,
-                        x86_cpuid_set_tsc_freq, NULL, NULL);
     object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo",
                         x86_cpu_get_feature_words,
                         NULL, NULL, (void *)env->features);
     object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo",
                         x86_cpu_get_feature_words,
                         NULL, NULL, (void *)cpu->filtered_features);
-    /*
-     * The "unavailable-features" property has the same semantics as
-     * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions"
-     * QMP command: they list the features that would have prevented the
-     * CPU from running if the "enforce" flag was set.
-     */
-    object_property_add(obj, "unavailable-features", "strList",
-                        x86_cpu_get_unavailable_features,
-                        NULL, NULL, NULL);
-
-#if !defined(CONFIG_USER_ONLY)
-    object_property_add(obj, "crash-information", "GuestPanicInformation",
-                        x86_cpu_get_crash_info_qom, NULL, NULL, NULL);
-#endif
 
     for (w = 0; w < FEATURE_WORDS; w++) {
         int bitnr;
@@ -7308,6 +7276,40 @@  static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->disas_set_info = x86_disas_set_info;
 
     dc->user_creatable = true;
+
+    object_class_property_add(oc, "family", "int",
+                              x86_cpuid_version_get_family,
+                              x86_cpuid_version_set_family, NULL, NULL);
+    object_class_property_add(oc, "model", "int",
+                              x86_cpuid_version_get_model,
+                              x86_cpuid_version_set_model, NULL, NULL);
+    object_class_property_add(oc, "stepping", "int",
+                              x86_cpuid_version_get_stepping,
+                              x86_cpuid_version_set_stepping, NULL, NULL);
+    object_class_property_add_str(oc, "vendor",
+                                  x86_cpuid_get_vendor,
+                                  x86_cpuid_set_vendor);
+    object_class_property_add_str(oc, "model-id",
+                                  x86_cpuid_get_model_id,
+                                  x86_cpuid_set_model_id);
+    object_class_property_add(oc, "tsc-frequency", "int",
+                              x86_cpuid_get_tsc_freq,
+                              x86_cpuid_set_tsc_freq, NULL, NULL);
+    /*
+     * The "unavailable-features" property has the same semantics as
+     * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions"
+     * QMP command: they list the features that would have prevented the
+     * CPU from running if the "enforce" flag was set.
+     */
+    object_class_property_add(oc, "unavailable-features", "strList",
+                              x86_cpu_get_unavailable_features,
+                              NULL, NULL, NULL);
+
+#if !defined(CONFIG_USER_ONLY)
+    object_class_property_add(oc, "crash-information", "GuestPanicInformation",
+                              x86_cpu_get_crash_info_qom, NULL, NULL, NULL);
+#endif
+
 }
 
 static const TypeInfo x86_cpu_type_info = {