Blame SOURCES/libvirt-cpu_x86-Refactor-feature-list-comparison-in-x86DecodeUseCandidate.patch

49d448
From 3d7a4041d31e403dc9e762b34f7faf36f7f20a28 Mon Sep 17 00:00:00 2001
49d448
Message-Id: <3d7a4041d31e403dc9e762b34f7faf36f7f20a28@dist-git>
49d448
From: Jiri Denemark <jdenemar@redhat.com>
49d448
Date: Tue, 26 Apr 2022 15:02:51 +0200
49d448
Subject: [PATCH] cpu_x86: Refactor feature list comparison in
49d448
 x86DecodeUseCandidate
49d448
49d448
It will become more complicated and so it deserves to be separated into
49d448
a new function.
49d448
49d448
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
49d448
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
49d448
(cherry picked from commit 1d6ca40ac23c039abc4392b668f256d0eda33280)
49d448
49d448
https://bugzilla.redhat.com/show_bug.cgi?id=1851227
49d448
49d448
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
49d448
---
49d448
 src/cpu/cpu_x86.c | 31 ++++++++++++++++++++++---------
49d448
 1 file changed, 22 insertions(+), 9 deletions(-)
49d448
49d448
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
49d448
index f007487824..81c2441b8b 100644
49d448
--- a/src/cpu/cpu_x86.c
49d448
+++ b/src/cpu/cpu_x86.c
49d448
@@ -1970,6 +1970,27 @@ virCPUx86Compare(virCPUDef *host,
49d448
 }
49d448
 
49d448
 
49d448
+static int
49d448
+virCPUx86CompareCandidateFeatureList(virCPUDef *cpuCurrent,
49d448
+                                     virCPUDef *cpuCandidate)
49d448
+{
49d448
+    size_t current = cpuCurrent->nfeatures;
49d448
+    size_t candidate = cpuCandidate->nfeatures;
49d448
+
49d448
+    if (candidate < current) {
49d448
+        VIR_DEBUG("%s is better than %s: %zu < %zu",
49d448
+                  cpuCandidate->model, cpuCurrent->model,
49d448
+                  candidate, current);
49d448
+        return 1;
49d448
+    }
49d448
+
49d448
+    VIR_DEBUG("%s is not better than %s: %zu >= %zu",
49d448
+              cpuCandidate->model, cpuCurrent->model,
49d448
+              candidate, current);
49d448
+    return 0;
49d448
+}
49d448
+
49d448
+
49d448
 /*
49d448
  * Checks whether a candidate model is a better fit for the CPU data than the
49d448
  * current model.
49d448
@@ -2038,15 +2059,7 @@ x86DecodeUseCandidate(virCPUx86Model *current,
49d448
         }
49d448
     }
49d448
 
49d448
-    if (cpuCurrent->nfeatures > cpuCandidate->nfeatures) {
49d448
-        VIR_DEBUG("%s results in shorter feature list than %s",
49d448
-                  cpuCandidate->model, cpuCurrent->model);
49d448
-        return 1;
49d448
-    }
49d448
-
49d448
-    VIR_DEBUG("%s does not result in shorter feature list than %s",
49d448
-              cpuCandidate->model, cpuCurrent->model);
49d448
-    return 0;
49d448
+    return virCPUx86CompareCandidateFeatureList(cpuCurrent, cpuCandidate);
49d448
 }
49d448
 
49d448
 
49d448
-- 
49d448
2.35.1
49d448