* [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags
@ 2015-04-14 15:28 Eduardo Habkost
2015-04-15 7:47 ` Igor Mammedov
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Eduardo Habkost @ 2015-04-14 15:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber, Igor Mammedov
This uses the feature name arrays to register QOM properties for feature
flags. This simply adds properties that can be configured using -global,
but doesn't change x86_cpu_parse_featurestr() to use them yet.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Use "cpuid-" prefix instead of "feat-"
* Register release function for property
* Convert '_' to '-' on feature name before registering property
* Add dev->realized check to property setter
Changes v2 -> v3:
* Register alias properties for feature name aliases
* Patch is based on x86 tree, at:
https://github.com/ehabkost/qemu.git x86
Changes v3 -> v4:
* Remove "cpuid-" prefix altogether
Changes v4 -> v5:
* Coding style changes (mostly blank lines after variable declarations)
* Change feature property registration to be a generic "bit property"
registration function
* Check for visitor errors on bit property setter
* Rename "bit" variables to "bitnr"
* Get bitnr as argument to bit property registration function, instead
of mask
---
target-i386/cpu.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 3305e09..9b11208 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2841,12 +2841,125 @@ out:
}
}
+typedef struct BitProperty {
+ uint32_t *ptr;
+ uint32_t mask;
+} BitProperty;
+
+static void x86_cpu_get_bit_prop(Object *obj,
+ struct Visitor *v,
+ void *opaque,
+ const char *name,
+ Error **errp)
+{
+ BitProperty *fp = opaque;
+ bool value = (*fp->ptr & fp->mask) == fp->mask;
+ visit_type_bool(v, &value, name, errp);
+}
+
+static void x86_cpu_set_bit_prop(Object *obj,
+ struct Visitor *v,
+ void *opaque,
+ const char *name,
+ Error **errp)
+{
+ DeviceState *dev = DEVICE(obj);
+ BitProperty *fp = opaque;
+ Error *local_err = NULL;
+ bool value;
+
+ if (dev->realized) {
+ qdev_prop_set_after_realize(dev, name, errp);
+ return;
+ }
+
+ visit_type_bool(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ if (value) {
+ *fp->ptr |= fp->mask;
+ } else {
+ *fp->ptr &= ~fp->mask;
+ }
+}
+
+static void x86_cpu_release_bit_prop(Object *obj, const char *name,
+ void *opaque)
+{
+ BitProperty *prop = opaque;
+ g_free(prop);
+}
+
+/* Register a boolean property to get/set a single bit in a uint32_t field.
+ *
+ * The same property name can be registered multiple times to make it affect
+ * multiple bits in the same FeatureWord. In that case, the getter will return
+ * true only if all bits are set.
+ */
+static void x86_cpu_register_bit_prop(X86CPU *cpu,
+ const char *prop_name,
+ uint32_t *field,
+ int bitnr)
+{
+ BitProperty *fp;
+ ObjectProperty *op;
+ uint32_t mask = (1UL << bitnr);
+
+ op = object_property_find(OBJECT(cpu), prop_name, NULL);
+ if (op) {
+ fp = op->opaque;
+ assert(fp->ptr == field);
+ fp->mask |= mask;
+ } else {
+ fp = g_new0(BitProperty, 1);
+ fp->ptr = field;
+ fp->mask = mask;
+ object_property_add(OBJECT(cpu), prop_name, "bool",
+ x86_cpu_get_bit_prop,
+ x86_cpu_set_bit_prop,
+ x86_cpu_release_bit_prop, fp, &error_abort);
+ }
+}
+
+static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
+ FeatureWord w,
+ int bitnr)
+{
+ Object *obj = OBJECT(cpu);
+ int i;
+ char **names;
+ FeatureWordInfo *fi = &feature_word_info[w];
+
+ if (!fi->feat_names) {
+ return;
+ }
+ if (!fi->feat_names[bitnr]) {
+ return;
+ }
+
+ names = g_strsplit(fi->feat_names[bitnr], "|", 0);
+
+ feat2prop(names[0]);
+ x86_cpu_register_bit_prop(cpu, names[0], &cpu->env.features[w], bitnr);
+
+ for (i = 1; names[i]; i++) {
+ feat2prop(names[i]);
+ object_property_add_alias(obj, names[i], obj, names[0], &error_abort);
+ }
+
+ g_strfreev(names);
+}
+
static void x86_cpu_initfn(Object *obj)
{
CPUState *cs = CPU(obj);
X86CPU *cpu = X86_CPU(obj);
X86CPUClass *xcc = X86_CPU_GET_CLASS(obj);
CPUX86State *env = &cpu->env;
+ FeatureWord w;
static int inited;
cs->env_ptr = env;
@@ -2887,6 +3000,14 @@ static void x86_cpu_initfn(Object *obj)
cpu->apic_id = -1;
#endif
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ int bitnr;
+
+ for (bitnr = 0; bitnr < 32; bitnr++) {
+ x86_cpu_register_feature_bit_props(cpu, w, bitnr);
+ }
+ }
+
x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
/* init various static tables used in TCG mode */
--
2.1.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags
2015-04-14 15:28 [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags Eduardo Habkost
@ 2015-04-15 7:47 ` Igor Mammedov
2015-05-22 19:13 ` Eduardo Habkost
2015-07-09 14:15 ` Paolo Bonzini
2 siblings, 0 replies; 5+ messages in thread
From: Igor Mammedov @ 2015-04-15 7:47 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: Paolo Bonzini, qemu-devel, Andreas Färber
On Tue, 14 Apr 2015 12:28:24 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:
> This uses the feature name arrays to register QOM properties for feature
> flags. This simply adds properties that can be configured using -global,
> but doesn't change x86_cpu_parse_featurestr() to use them yet.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
> * Use "cpuid-" prefix instead of "feat-"
> * Register release function for property
> * Convert '_' to '-' on feature name before registering property
> * Add dev->realized check to property setter
>
> Changes v2 -> v3:
> * Register alias properties for feature name aliases
> * Patch is based on x86 tree, at:
> https://github.com/ehabkost/qemu.git x86
>
> Changes v3 -> v4:
> * Remove "cpuid-" prefix altogether
>
> Changes v4 -> v5:
> * Coding style changes (mostly blank lines after variable declarations)
> * Change feature property registration to be a generic "bit property"
> registration function
> * Check for visitor errors on bit property setter
> * Rename "bit" variables to "bitnr"
> * Get bitnr as argument to bit property registration function, instead
> of mask
> ---
> target-i386/cpu.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 121 insertions(+)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 3305e09..9b11208 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2841,12 +2841,125 @@ out:
> }
> }
>
> +typedef struct BitProperty {
> + uint32_t *ptr;
> + uint32_t mask;
> +} BitProperty;
> +
> +static void x86_cpu_get_bit_prop(Object *obj,
> + struct Visitor *v,
> + void *opaque,
> + const char *name,
> + Error **errp)
> +{
> + BitProperty *fp = opaque;
> + bool value = (*fp->ptr & fp->mask) == fp->mask;
> + visit_type_bool(v, &value, name, errp);
> +}
> +
> +static void x86_cpu_set_bit_prop(Object *obj,
> + struct Visitor *v,
> + void *opaque,
> + const char *name,
> + Error **errp)
> +{
> + DeviceState *dev = DEVICE(obj);
> + BitProperty *fp = opaque;
> + Error *local_err = NULL;
> + bool value;
> +
> + if (dev->realized) {
> + qdev_prop_set_after_realize(dev, name, errp);
> + return;
> + }
> +
> + visit_type_bool(v, &value, name, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
> +
> + if (value) {
> + *fp->ptr |= fp->mask;
> + } else {
> + *fp->ptr &= ~fp->mask;
> + }
> +}
> +
> +static void x86_cpu_release_bit_prop(Object *obj, const char *name,
> + void *opaque)
indent went astray ^^^
> +{
> + BitProperty *prop = opaque;
> + g_free(prop);
> +}
> +
> +/* Register a boolean property to get/set a single bit in a uint32_t field.
> + *
> + * The same property name can be registered multiple times to make it affect
> + * multiple bits in the same FeatureWord. In that case, the getter will return
> + * true only if all bits are set.
> + */
> +static void x86_cpu_register_bit_prop(X86CPU *cpu,
> + const char *prop_name,
> + uint32_t *field,
> + int bitnr)
> +{
> + BitProperty *fp;
> + ObjectProperty *op;
> + uint32_t mask = (1UL << bitnr);
> +
> + op = object_property_find(OBJECT(cpu), prop_name, NULL);
> + if (op) {
> + fp = op->opaque;
> + assert(fp->ptr == field);
> + fp->mask |= mask;
> + } else {
> + fp = g_new0(BitProperty, 1);
> + fp->ptr = field;
> + fp->mask = mask;
> + object_property_add(OBJECT(cpu), prop_name, "bool",
> + x86_cpu_get_bit_prop,
> + x86_cpu_set_bit_prop,
> + x86_cpu_release_bit_prop, fp, &error_abort);
> + }
> +}
> +
> +static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
> + FeatureWord w,
> + int bitnr)
> +{
> + Object *obj = OBJECT(cpu);
> + int i;
> + char **names;
> + FeatureWordInfo *fi = &feature_word_info[w];
> +
> + if (!fi->feat_names) {
> + return;
> + }
> + if (!fi->feat_names[bitnr]) {
> + return;
> + }
> +
> + names = g_strsplit(fi->feat_names[bitnr], "|", 0);
> +
> + feat2prop(names[0]);
> + x86_cpu_register_bit_prop(cpu, names[0], &cpu->env.features[w], bitnr);
> +
> + for (i = 1; names[i]; i++) {
> + feat2prop(names[i]);
> + object_property_add_alias(obj, names[i], obj, names[0], &error_abort);
> + }
> +
> + g_strfreev(names);
> +}
> +
> static void x86_cpu_initfn(Object *obj)
> {
> CPUState *cs = CPU(obj);
> X86CPU *cpu = X86_CPU(obj);
> X86CPUClass *xcc = X86_CPU_GET_CLASS(obj);
> CPUX86State *env = &cpu->env;
> + FeatureWord w;
> static int inited;
>
> cs->env_ptr = env;
> @@ -2887,6 +3000,14 @@ static void x86_cpu_initfn(Object *obj)
> cpu->apic_id = -1;
> #endif
>
> + for (w = 0; w < FEATURE_WORDS; w++) {
> + int bitnr;
> +
> + for (bitnr = 0; bitnr < 32; bitnr++) {
> + x86_cpu_register_feature_bit_props(cpu, w, bitnr);
> + }
> + }
> +
> x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
>
> /* init various static tables used in TCG mode */
With comment above fixed,
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags
2015-04-14 15:28 [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags Eduardo Habkost
2015-04-15 7:47 ` Igor Mammedov
@ 2015-05-22 19:13 ` Eduardo Habkost
2015-07-09 14:15 ` Paolo Bonzini
2 siblings, 0 replies; 5+ messages in thread
From: Eduardo Habkost @ 2015-05-22 19:13 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber, Igor Mammedov
On Tue, Apr 14, 2015 at 12:28:24PM -0300, Eduardo Habkost wrote:
> This uses the feature name arrays to register QOM properties for feature
> flags. This simply adds properties that can be configured using -global,
> but doesn't change x86_cpu_parse_featurestr() to use them yet.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This is being applied to x86 tree with the following change, because the
object_property_add_alias() strdup() fix wasn't merged yet.
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b2cf128..7042117 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2947,7 +2947,8 @@ static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
for (i = 1; names[i]; i++) {
feat2prop(names[i]);
- object_property_add_alias(obj, names[i], obj, names[0], &error_abort);
+ object_property_add_alias(obj, names[i], obj, g_strdup(names[0]),
+ &error_abort);
}
g_strfreev(names);
The g_strdup() call will be removed after the
object_property_add_alias() fix is applied.
--
Eduardo
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags
2015-04-14 15:28 [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags Eduardo Habkost
2015-04-15 7:47 ` Igor Mammedov
2015-05-22 19:13 ` Eduardo Habkost
@ 2015-07-09 14:15 ` Paolo Bonzini
2015-07-09 14:51 ` Eduardo Habkost
2 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2015-07-09 14:15 UTC (permalink / raw)
To: Eduardo Habkost, qemu-devel; +Cc: Igor Mammedov, Andreas Färber
On 14/04/2015 17:28, Eduardo Habkost wrote:
> + for (i = 1; names[i]; i++) {
> + feat2prop(names[i]);
> + object_property_add_alias(obj, names[i], obj, names[0], &error_abort);
The version you committed has a strdup(names[0]) here, but
object_property_add_alias already does a strdup.
Paolo
> + }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags
2015-07-09 14:15 ` Paolo Bonzini
@ 2015-07-09 14:51 ` Eduardo Habkost
0 siblings, 0 replies; 5+ messages in thread
From: Eduardo Habkost @ 2015-07-09 14:51 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Igor Mammedov, qemu-devel, Andreas Färber
On Thu, Jul 09, 2015 at 04:15:19PM +0200, Paolo Bonzini wrote:
>
>
> On 14/04/2015 17:28, Eduardo Habkost wrote:
> > + for (i = 1; names[i]; i++) {
> > + feat2prop(names[i]);
> > + object_property_add_alias(obj, names[i], obj, names[0], &error_abort);
>
> The version you committed has a strdup(names[0]) here, but
> object_property_add_alias already does a strdup.
object_property_add_alias() didn't have a strdup() on June 2. I sent a
note about it at:
Date: Fri, 22 May 2015 16:13:55 -0300
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Message-ID: <20150522191355.GG28075@thinpad.lan.raisama.net>
Subject: Re: [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags
Now that the object_property_add_alias() patch was merged, we can remove
hte g_strdup() call.
--
Eduardo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-07-09 14:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-14 15:28 [Qemu-devel] [PATCH v5] target-i386: Register QOM properties for feature flags Eduardo Habkost
2015-04-15 7:47 ` Igor Mammedov
2015-05-22 19:13 ` Eduardo Habkost
2015-07-09 14:15 ` Paolo Bonzini
2015-07-09 14:51 ` Eduardo Habkost
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).