[PATCH] target/ppc/cpu_init: make cpu listing determnistic

Pierrick Bouvier posted 1 patch 4 days, 14 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260720192403.66694-1-pierrick.bouvier@oss.qualcomm.com
Maintainers: Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Glenn Miles <milesg@linux.ibm.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>
target/ppc/cpu_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] target/ppc/cpu_init: make cpu listing determnistic
Posted by Pierrick Bouvier 4 days, 14 hours ago
The existing compare function only make sure that we list cpus with PVR
order. However, we never compare cpu names.
As a result, while cpus are grouped per PVR, the order within a group is
non deterministic. Depending on QOM type initialization order, we get
different results for -cpu help.

For instance, previous output could be:
Available CPUs:
  755_v1.0         PVR 00083100
  745_v1.0         PVR 00083100
  755_v1.1         PVR 00083101
  745_v1.1         PVR 00083101

While a sorted output should be:
Available CPUs:
  745_v1.0         PVR 00083100
  755_v1.0         PVR 00083100
  745_v1.1         PVR 00083101
  755_v1.1         PVR 00083101

Fix it by comparing cpu names to have a stable result.
This allows us to record and compare various command line results across
versions to make sure we didn't break anything while working on
single-binary.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
---
 target/ppc/cpu_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index f404c7e549d..3443dbeeb01 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7130,7 +7130,7 @@ static gint ppc_cpu_list_compare(gconstpointer a, gconstpointer b, gpointer d)
         } else if (pcc_a->pvr > pcc_b->pvr) {
             return 1;
         } else {
-            return 0;
+            return strcmp(name_a, name_b);
         }
     }
 }
-- 
2.43.0
Re: [PATCH] target/ppc/cpu_init: make cpu listing determnistic
Posted by Pierrick Bouvier 2 days, 17 hours ago
On 7/20/2026 12:24 PM, Pierrick Bouvier wrote:
> The existing compare function only make sure that we list cpus with PVR
> order. However, we never compare cpu names.
> As a result, while cpus are grouped per PVR, the order within a group is
> non deterministic. Depending on QOM type initialization order, we get
> different results for -cpu help.
> 
> For instance, previous output could be:
> Available CPUs:
>   755_v1.0         PVR 00083100
>   745_v1.0         PVR 00083100
>   755_v1.1         PVR 00083101
>   745_v1.1         PVR 00083101
> 
> While a sorted output should be:
> Available CPUs:
>   745_v1.0         PVR 00083100
>   755_v1.0         PVR 00083100
>   745_v1.1         PVR 00083101
>   755_v1.1         PVR 00083101
> 
> Fix it by comparing cpu names to have a stable result.
> This allows us to record and compare various command line results across
> versions to make sure we didn't break anything while working on
> single-binary.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
>  target/ppc/cpu_init.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index f404c7e549d..3443dbeeb01 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -7130,7 +7130,7 @@ static gint ppc_cpu_list_compare(gconstpointer a, gconstpointer b, gpointer d)
>          } else if (pcc_a->pvr > pcc_b->pvr) {
>              return 1;
>          } else {
> -            return 0;
> +            return strcmp(name_a, name_b);
>          }
>      }
>  }

Any chance one of ppc maintainer could send this for the upcoming release?
This would help us to compare command lines across QEMU versions to make
sure there is no regression.

Regards,
Pierrick
Re: [PATCH] target/ppc/cpu_init: make cpu listing determnistic
Posted by Philippe Mathieu-Daudé 4 days, 13 hours ago
On 20/7/26 21:24, Pierrick Bouvier wrote:
> The existing compare function only make sure that we list cpus with PVR
> order. However, we never compare cpu names.
> As a result, while cpus are grouped per PVR, the order within a group is
> non deterministic. Depending on QOM type initialization order, we get
> different results for -cpu help.
> 
> For instance, previous output could be:
> Available CPUs:
>    755_v1.0         PVR 00083100
>    745_v1.0         PVR 00083100
>    755_v1.1         PVR 00083101
>    745_v1.1         PVR 00083101
> 
> While a sorted output should be:
> Available CPUs:
>    745_v1.0         PVR 00083100
>    755_v1.0         PVR 00083100
>    745_v1.1         PVR 00083101
>    755_v1.1         PVR 00083101
> 
> Fix it by comparing cpu names to have a stable result.
> This allows us to record and compare various command line results across
> versions to make sure we didn't break anything while working on
> single-binary.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
> ---
>   target/ppc/cpu_init.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Tested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>