From: Paolo Bonzini <pbonzini@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>, qemu-devel@nongnu.org
Cc: "Igor Mammedov" <imammedo@redhat.com>,
"Jiri Denemark" <jdenemar@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH 3/6] target-i386: Register QOM properties for feature flags
Date: Wed, 08 Apr 2015 10:30:52 +0200 [thread overview]
Message-ID: <5524E73C.3020708@redhat.com> (raw)
In-Reply-To: <1428439603-8549-4-git-send-email-ehabkost@redhat.com>
On 07/04/2015 22:46, Eduardo Habkost wrote:
> This uses the feature name arrays to register "feat-*" QOM properties
> for feature flags. This simply adds the properties so they can be
> configured using -global, but doesn't change x86_cpu_parse_featurestr()
> to use them yet.
Out of curiosity, why the prefix? (Also, perhaps a prefix such as
"cpuid-*" would be better since the property often only affects the
cpuid leaves, rather than the availability of the feature itself).
Paolo
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> target-i386/cpu.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 98 insertions(+)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 099ed03..f29e55e 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2883,12 +2883,103 @@ out:
> }
> }
>
> +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.
> + * The same property name can be registered multiple times to make it affect
> + * multiple bits in the same FeatureWord.
> + */
> +static void x86_cpu_register_feature_prop(X86CPU *cpu,
> + const char *prop_name,
> + FeatureWord w,
> + uint32_t mask)
> +{
> + FeatureProperty *fp;
> + ObjectProperty *op;
> + op = object_property_find(OBJECT(cpu), prop_name, NULL);
> + if (op) {
> + fp = op->opaque;
> + assert(fp->word == w);
> + fp->mask |= mask;
> + } else {
> + fp = g_new0(FeatureProperty, 1);
> + fp->word = w;
> + fp->mask = mask;
> + object_property_add(OBJECT(cpu), prop_name, "bool",
> + x86_cpu_get_feature_prop,
> + x86_cpu_set_feature_prop,
> + NULL, fp, &error_abort);
> + }
> +}
> +
> +static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
> + FeatureWord w,
> + int bit)
> +{
> + int i;
> + char **names;
> + FeatureWordInfo *fi = &feature_word_info[w];
> +
> + if (!fi->feat_names) {
> + return;
> + }
> + if (!fi->feat_names[bit]) {
> + return;
> + }
> +
> + names = g_strsplit(fi->feat_names[bit], "|", 0);
> + for (i = 0; names[i]; i++) {
> + char *feat_name = names[i];
> + char *prop_name = g_strdup_printf("feat-%s", feat_name);
> + x86_cpu_register_feature_prop(cpu, prop_name, w, (1UL << bit));
> + g_free(prop_name);
> + }
> + 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;
> @@ -2935,6 +3026,13 @@ static void x86_cpu_initfn(Object *obj)
> cpu->apic_id = -1;
> #endif
>
> + for (w = 0; w < FEATURE_WORDS; w++) {
> + int bit;
> + for (bit = 0; bit < 32; bit++) {
> + x86_cpu_register_feature_bit_props(cpu, w, bit);
> + }
> + }
> +
> x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
>
> /* init various static tables used in TCG mode */
>
next prev parent reply other threads:[~2015-04-08 8:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-07 20:46 [Qemu-devel] [PATCH 0/6] target-i386: Feature properties, sample script for -global/-readconfig Eduardo Habkost
2015-04-07 20:46 ` [Qemu-devel] [PATCH 1/6] target-i386: Move error handling to end of x86_cpu_parse_featurestr() Eduardo Habkost
2015-04-08 8:31 ` Paolo Bonzini
2015-04-07 20:46 ` [Qemu-devel] [PATCH 2/6] target-i386: Remove underscores from feature names Eduardo Habkost
2015-04-07 20:46 ` [Qemu-devel] [PATCH 3/6] target-i386: Register QOM properties for feature flags Eduardo Habkost
2015-04-08 8:30 ` Paolo Bonzini [this message]
2015-04-08 11:06 ` Eduardo Habkost
2015-04-08 12:53 ` Andreas Färber
2015-04-08 11:36 ` Igor Mammedov
2015-04-08 12:20 ` Eduardo Habkost
2015-04-08 12:24 ` Paolo Bonzini
2015-04-08 14:09 ` Igor Mammedov
2015-04-08 15:01 ` Eduardo Habkost
2015-04-08 15:36 ` Igor Mammedov
2015-04-07 20:46 ` [Qemu-devel] [PATCH 4/6] target-i386: Make "level" and "xlevel" properties static Eduardo Habkost
2015-04-07 20:46 ` [Qemu-devel] [PATCH 5/6] target-i386: X86CPU::xlevel2 QOM property Eduardo Habkost
2015-04-08 8:31 ` Paolo Bonzini
2015-04-07 20:46 ` [Qemu-devel] [PATCH 6/6] scripts: x86-cpu-model-dump script 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=5524E73C.3020708@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=jdenemar@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).