[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/21] target-i386: Make plus_features/minus_features
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL 05/21] target-i386: Make plus_features/minus_features QOM-based |
Date: |
Mon, 17 Oct 2016 15:51:22 -0200 |
Instead of using custom feature name lookup code for
plus_features/minus_features, save the property names used in
"[+-]feature" and use object_property_set_bool() to set them.
We don't need a feat2prop() call because we now have alias
properties for the old names containing underscores.
Signed-off-by: Eduardo Habkost <address@hidden>
---
target-i386/cpu.c | 106 +++++++++++-------------------------------------------
1 file changed, 20 insertions(+), 86 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index fe62ae1..c5c767b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -650,85 +650,6 @@ void host_cpuid(uint32_t function, uint32_t count,
*edx = vec[3];
}
-#define iswhite(c) ((c) && ((c) <= ' ' || '~' < (c)))
-
-/* general substring compare of *[s1..e1) and *[s2..e2). sx is start of
- * a substring. ex if !NULL points to the first char after a substring,
- * otherwise the string is assumed to sized by a terminating nul.
- * Return lexical ordering of *s1:*s2.
- */
-static int sstrcmp(const char *s1, const char *e1,
- const char *s2, const char *e2)
-{
- for (;;) {
- if (!*s1 || !*s2 || *s1 != *s2)
- return (*s1 - *s2);
- ++s1, ++s2;
- if (s1 == e1 && s2 == e2)
- return (0);
- else if (s1 == e1)
- return (*s2);
- else if (s2 == e2)
- return (*s1);
- }
-}
-
-/* compare *[s..e) to *altstr. *altstr may be a simple string or multiple
- * '|' delimited (possibly empty) strings in which case search for a match
- * within the alternatives proceeds left to right. Return 0 for success,
- * non-zero otherwise.
- */
-static int altcmp(const char *s, const char *e, const char *altstr)
-{
- const char *p, *q;
-
- for (q = p = altstr; ; ) {
- while (*p && *p != '|')
- ++p;
- if ((q == p && !*s) || (q != p && !sstrcmp(s, e, q, p)))
- return (0);
- if (!*p)
- return (1);
- else
- q = ++p;
- }
-}
-
-/* search featureset for flag *[s..e), if found set corresponding bit in
- * *pval and return true, otherwise return false
- */
-static bool lookup_feature(uint32_t *pval, const char *s, const char *e,
- const char **featureset)
-{
- uint32_t mask;
- const char **ppc;
- bool found = false;
-
- for (mask = 1, ppc = featureset; mask; mask <<= 1, ++ppc) {
- if (*ppc && !altcmp(s, e, *ppc)) {
- *pval |= mask;
- found = true;
- }
- }
- return found;
-}
-
-static void add_flagname_to_bitmaps(const char *flagname,
- FeatureWordArray words,
- Error **errp)
-{
- FeatureWord w;
- for (w = 0; w < FEATURE_WORDS; w++) {
- FeatureWordInfo *wi = &feature_word_info[w];
- if (lookup_feature(&words[w], flagname, NULL, wi->feat_names)) {
- break;
- }
- }
- if (w == FEATURE_WORDS) {
- error_setg(errp, "CPU feature %s not found", flagname);
- }
-}
-
/* CPU class name definitions: */
#define X86_CPU_TYPE_SUFFIX "-" TYPE_X86_CPU
@@ -2015,8 +1936,7 @@ static inline void feat2prop(char *s)
* feat=on|feat even if the later is parsed after +-feat
* (i.e. "-x2apic,x2apic=on" will result in x2apic disabled)
*/
-static FeatureWordArray plus_features = { 0 };
-static FeatureWordArray minus_features = { 0 };
+static GList *plus_features, *minus_features;
/* Parse "+feature,-feature,feature=foo" CPU feature string
*/
@@ -2047,10 +1967,12 @@ static void x86_cpu_parse_featurestr(const char
*typename, char *features,
/* Compatibility syntax: */
if (featurestr[0] == '+') {
- add_flagname_to_bitmaps(featurestr + 1, plus_features, &local_err);
+ plus_features = g_list_append(plus_features,
+ g_strdup(featurestr + 1));
continue;
} else if (featurestr[0] == '-') {
- add_flagname_to_bitmaps(featurestr + 1, minus_features,
&local_err);
+ minus_features = g_list_append(minus_features,
+ g_strdup(featurestr + 1));
continue;
}
@@ -3066,6 +2988,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error
**errp)
Error *local_err = NULL;
static bool ht_warned;
FeatureWord w;
+ GList *l;
if (xcc->kvm_required && !kvm_enabled()) {
char *name = x86_cpu_class_get_model_name(xcc);
@@ -3091,9 +3014,20 @@ static void x86_cpu_realizefn(DeviceState *dev, Error
**errp)
}
}
- for (w = 0; w < FEATURE_WORDS; w++) {
- cpu->env.features[w] |= plus_features[w];
- cpu->env.features[w] &= ~minus_features[w];
+ for (l = plus_features; l; l = l->next) {
+ const char *prop = l->data;
+ object_property_set_bool(OBJECT(cpu), true, prop, &local_err);
+ if (local_err) {
+ goto out;
+ }
+ }
+
+ for (l = minus_features; l; l = l->next) {
+ const char *prop = l->data;
+ object_property_set_bool(OBJECT(cpu), false, prop, &local_err);
+ if (local_err) {
+ goto out;
+ }
}
if (!kvm_enabled() || !cpu->expose_kvm) {
--
2.7.4
- [Qemu-devel] [PULL 00/21] x86 queue, 2016-10-17, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 01/21] tests: Add test case for x86 feature parsing compatibility, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 02/21] target-i386: List CPU models using subclass list, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 03/21] target-i386: Disable VME by default with TCG, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 04/21] target-i386: Register aliases for feature names with underscores, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 06/21] target-i386: Remove underscores from feat_names arrays, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 07/21] target-i386: Register properties for feature aliases manually, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 05/21] target-i386: Make plus_features/minus_features QOM-based,
Eduardo Habkost <=
- [Qemu-devel] [PULL 08/21] target-i386: xsave: Add FP and SSE bits to x86_ext_save_areas, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 09/21] qmp: Add runnability information to query-cpu-definitions, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 11/21] apic: add global apic_get_class(), Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 10/21] target-i386: Move warning code outside x86_cpu_filter_features(), Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 12/21] apic: add send_msi() to APICCommonClass, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 13/21] intel_iommu: pass whole remapped addresses to apic, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 14/21] intel_iommu: redo configuraton check in realize, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 15/21] intel_iommu: add OnOffAuto intr_eim as "eim" property, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 16/21] intel_iommu: reject broken EIM, Eduardo Habkost, 2016/10/17
- [Qemu-devel] [PULL 18/21] target-i386: Unset cannot_destroy_with_object_finalize_yet, Eduardo Habkost, 2016/10/17