* [Qemu-devel] [PATCH 1/3] i386: improve alignment of CPU model listing
2018-06-06 16:55 [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument Daniel P. Berrangé
@ 2018-06-06 16:55 ` Daniel P. Berrangé
2018-06-06 16:55 ` [Qemu-devel] [PATCH 2/3] i386: improve sorting of CPU model names Daniel P. Berrangé
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Daniel P. Berrangé @ 2018-06-06 16:55 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Eduardo Habkost, Richard Henderson,
Daniel P. Berrangé
Since the addition of the -IBRS CPU model variants, the descriptions
shown by '-cpu help' are not well aligned, as several model names
overflow the space allowed. Right aligning the CPU model names is also
not attractive, because it obscures the common name prefixes of many
models. The CPU model name field needs to be 4 characters larger, and
be left aligned instead.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
target/i386/cpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 94260412e2..aa4d9949b4 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3206,7 +3206,7 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data)
desc = cc->cpu_def->model_id;
}
- (*s->cpu_fprintf)(s->file, "x86 %16s %-48s\n",
+ (*s->cpu_fprintf)(s->file, "x86 %-20s %-48s\n",
name, desc);
g_free(name);
}
--
2.17.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/3] i386: improve sorting of CPU model names
2018-06-06 16:55 [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument Daniel P. Berrangé
2018-06-06 16:55 ` [Qemu-devel] [PATCH 1/3] i386: improve alignment of CPU model listing Daniel P. Berrangé
@ 2018-06-06 16:55 ` Daniel P. Berrangé
2018-06-06 16:55 ` [Qemu-devel] [PATCH 3/3] i386: display known CPUID features linewrapped, in alphabetical order Daniel P. Berrangé
2018-06-11 21:23 ` [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument Eduardo Habkost
3 siblings, 0 replies; 6+ messages in thread
From: Daniel P. Berrangé @ 2018-06-06 16:55 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Eduardo Habkost, Richard Henderson,
Daniel P. Berrangé
The current list of CPU model names output by "-cpu help" is sorted
alphabetically based on the internal QOM class name. The text that is
displayed, however, uses the CPU model name, which is equivalent to the
QOM class name, minus a suffix. Unfortunately that suffix has an effect
on the sort ordering, for example, causing the various Broadwell
variants to appear reversed:
x86 486
x86 Broadwell-IBRS Intel Core Processor (Broadwell, IBRS)
x86 Broadwell-noTSX-IBRS Intel Core Processor (Broadwell, no TSX, IBRS
x86 Broadwell-noTSX Intel Core Processor (Broadwell, no TSX)
x86 Broadwell Intel Core Processor (Broadwell)
x86 Conroe Intel Celeron_4x0 (Conroe/Merom Class Core 2)
By sorting on the actual CPU model name text that is displayed, the
result is
x86 486
x86 Broadwell Intel Core Processor (Broadwell)
x86 Broadwell-IBRS Intel Core Processor (Broadwell, IBRS)
x86 Broadwell-noTSX Intel Core Processor (Broadwell, no TSX)
x86 Broadwell-noTSX-IBRS Intel Core Processor (Broadwell, no TSX, IBRS)
x86 Conroe Intel Celeron_4x0 (Conroe/Merom Class Core 2)
This requires extra string allocations during sorting, but this is not a
concern given the usage scenario and the number of CPU models that exist.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
target/i386/cpu.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index aa4d9949b4..cb074082b3 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3177,15 +3177,19 @@ static gint x86_cpu_list_compare(gconstpointer a, gconstpointer b)
ObjectClass *class_b = (ObjectClass *)b;
X86CPUClass *cc_a = X86_CPU_CLASS(class_a);
X86CPUClass *cc_b = X86_CPU_CLASS(class_b);
- const char *name_a, *name_b;
+ char *name_a, *name_b;
+ int ret;
if (cc_a->ordering != cc_b->ordering) {
- return cc_a->ordering - cc_b->ordering;
+ ret = cc_a->ordering - cc_b->ordering;
} else {
- name_a = object_class_get_name(class_a);
- name_b = object_class_get_name(class_b);
- return strcmp(name_a, name_b);
+ name_a = x86_cpu_class_get_model_name(cc_a);
+ name_b = x86_cpu_class_get_model_name(cc_b);
+ ret = strcmp(name_a, name_b);
+ g_free(name_a);
+ g_free(name_b);
}
+ return ret;
}
static GSList *get_sorted_cpu_model_list(void)
--
2.17.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/3] i386: display known CPUID features linewrapped, in alphabetical order
2018-06-06 16:55 [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument Daniel P. Berrangé
2018-06-06 16:55 ` [Qemu-devel] [PATCH 1/3] i386: improve alignment of CPU model listing Daniel P. Berrangé
2018-06-06 16:55 ` [Qemu-devel] [PATCH 2/3] i386: improve sorting of CPU model names Daniel P. Berrangé
@ 2018-06-06 16:55 ` Daniel P. Berrangé
2018-06-11 21:22 ` Eduardo Habkost
2018-06-11 21:23 ` [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument Eduardo Habkost
3 siblings, 1 reply; 6+ messages in thread
From: Daniel P. Berrangé @ 2018-06-06 16:55 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Eduardo Habkost, Richard Henderson,
Daniel P. Berrangé
When using '-cpu help' the list of CPUID features is grouped according
to the internal low level CPUID grouping. The data printed results in
very long lines too.
This combines to make it hard for users to read the output and identify
if QEMU knows about the feature they wish to use.
This change gets rid of the grouping of features and treats all flags as
single list. The list is sorted into alphabetical order and the printing
with line wrapping at the 77th column.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
target/i386/cpu.c | 41 +++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index cb074082b3..8043e41be8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3157,17 +3157,21 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
/* Print all cpuid feature names in featureset
*/
-static void listflags(FILE *f, fprintf_function print, const char **featureset)
+static void listflags(FILE *f, fprintf_function print, GList *features)
{
- int bit;
- bool first = true;
-
- for (bit = 0; bit < 32; bit++) {
- if (featureset[bit]) {
- print(f, "%s%s", first ? "" : " ", featureset[bit]);
- first = false;
+ size_t len = 0;
+ GList *tmp;
+
+ for (tmp = features; tmp; tmp = tmp->next) {
+ const char *name = tmp->data;
+ if ((len + strlen(name) + 1) >= 75) {
+ print(f, "\n");
+ len = 0;
}
+ print(f, "%s%s", len == 0 ? " " : " ", name);
+ len += strlen(name) + 1;
}
+ print(f, "\n");
}
/* Sort alphabetically by type name, respecting X86CPUClass::ordering. */
@@ -3218,26 +3222,35 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data)
/* list available CPU models and flags */
void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
{
- int i;
+ int i, j;
CPUListState s = {
.file = f,
.cpu_fprintf = cpu_fprintf,
};
GSList *list;
+ GList *names = NULL;
(*cpu_fprintf)(f, "Available CPUs:\n");
list = get_sorted_cpu_model_list();
g_slist_foreach(list, x86_cpu_list_entry, &s);
g_slist_free(list);
- (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
+ names = NULL;
for (i = 0; i < ARRAY_SIZE(feature_word_info); i++) {
FeatureWordInfo *fw = &feature_word_info[i];
-
- (*cpu_fprintf)(f, " ");
- listflags(f, cpu_fprintf, fw->feat_names);
- (*cpu_fprintf)(f, "\n");
+ for (j = 0; j < 32; j++) {
+ if (fw->feat_names[j]) {
+ names = g_list_append(names, (gpointer)fw->feat_names[j]);
+ }
+ }
}
+
+ names = g_list_sort(names, (GCompareFunc)strcmp);
+
+ (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
+ listflags(f, cpu_fprintf, names);
+ (*cpu_fprintf)(f, "\n");
+ g_list_free(names);
}
static void x86_cpu_definition_entry(gpointer data, gpointer user_data)
--
2.17.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 3/3] i386: display known CPUID features linewrapped, in alphabetical order
2018-06-06 16:55 ` [Qemu-devel] [PATCH 3/3] i386: display known CPUID features linewrapped, in alphabetical order Daniel P. Berrangé
@ 2018-06-11 21:22 ` Eduardo Habkost
0 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2018-06-11 21:22 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Wed, Jun 06, 2018 at 05:55:27PM +0100, Daniel P. Berrangé wrote:
[...]
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index cb074082b3..8043e41be8 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -3157,17 +3157,21 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
>
> /* Print all cpuid feature names in featureset
> */
> -static void listflags(FILE *f, fprintf_function print, const char **featureset)
> +static void listflags(FILE *f, fprintf_function print, GList *features)
> {
> - int bit;
> - bool first = true;
> -
> - for (bit = 0; bit < 32; bit++) {
> - if (featureset[bit]) {
> - print(f, "%s%s", first ? "" : " ", featureset[bit]);
> - first = false;
> + size_t len = 0;
> + GList *tmp;
> +
> + for (tmp = features; tmp; tmp = tmp->next) {
> + const char *name = tmp->data;
> + if ((len + strlen(name) + 1) >= 75) {
> + print(f, "\n");
> + len = 0;
> }
> + print(f, "%s%s", len == 0 ? " " : " ", name);
> + len += strlen(name) + 1;
> }
> + print(f, "\n");
I'd love to have generic helper functions to format text like
this, but that's not a reason to block this patch from being
included. I will queue the series on x86-next. Thanks!
--
Eduardo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument
2018-06-06 16:55 [Qemu-devel] [PATCH 0/3] i386: improve output from "-cpu help" argument Daniel P. Berrangé
` (2 preceding siblings ...)
2018-06-06 16:55 ` [Qemu-devel] [PATCH 3/3] i386: display known CPUID features linewrapped, in alphabetical order Daniel P. Berrangé
@ 2018-06-11 21:23 ` Eduardo Habkost
3 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2018-06-11 21:23 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Wed, Jun 06, 2018 at 05:55:24PM +0100, Daniel P. Berrangé wrote:
> This short series is a set of improvements to the "-cpu help" output for
> the x86 emulator. The patches describe what's change in each step, but
> it is best visualized by looking at before/after state.
[...]
Queue on x86-next, thanks!
--
Eduardo
^ permalink raw reply [flat|nested] 6+ messages in thread