[PATCH v2 3/5] virDomainFormatSchedDef: factor out subset code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The code within the function is too specific for priority attribute of
RT schedulers. To allow addition of schedulers that group by different
properties, we factor out the logic to calculate cpu subset. Instead
of comparing by priority, the new code accepts comparator for the 2
sched structs.
---
 src/conf/domain_conf.c | 66 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2dd5e6f..fe5a754 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23065,6 +23065,44 @@ virDomainDefHasCapabilitiesFeatures(virDomainDefPtr def)
     return false;
 }
 
+static bool
+virDomainSchedPriorityComparator(virDomainThreadSchedParamPtr baseSched,
+                                 virDomainThreadSchedParamPtr sched)
+{
+    return (baseSched->priority == sched->priority);
+}
+
+static virDomainThreadSchedParamPtr
+virDomainSchedSubsetCharacteristic(virDomainDefPtr def,
+                                   virBitmapPtr schedMap,
+                                   virBitmapPtr prioMap,
+                                   virDomainThreadSchedParamPtr (*func)(virDomainDefPtr, unsigned int),
+                                   bool (*comparator)(virDomainThreadSchedParamPtr,
+                                                      virDomainThreadSchedParamPtr))
+{
+    ssize_t nextprio;
+    virDomainThreadSchedParamPtr sched;
+    virDomainThreadSchedParamPtr baseSched = NULL;
+
+    virBitmapClearAll(prioMap);
+
+    /* we need to find a subset of vCPUs with the given scheduler
+        * that share the priority */
+    nextprio = virBitmapNextSetBit(schedMap, -1);
+    if (!(sched = func(def, nextprio)))
+        return NULL;
+
+    baseSched = sched;
+    ignore_value(virBitmapSetBit(prioMap, nextprio));
+
+    while ((nextprio = virBitmapNextSetBit(schedMap, nextprio)) > -1) {
+        sched = func(def, nextprio);
+        if (sched && comparator(baseSched, sched))
+            ignore_value(virBitmapSetBit(prioMap, nextprio));
+    }
+
+    return baseSched;
+}
 
 /**
  * virDomainFormatSchedDef:
@@ -23091,6 +23129,7 @@ virDomainFormatSchedDef(virDomainDefPtr def,
     virBitmapPtr schedMap = NULL;
     virBitmapPtr prioMap = NULL;
     virDomainThreadSchedParamPtr sched;
+    virDomainThreadSchedParamPtr baseSched;
     char *tmp = NULL;
     ssize_t next;
     size_t i;
@@ -23124,9 +23163,8 @@ virDomainFormatSchedDef(virDomainDefPtr def,
          * have them */
         while (!virBitmapIsAllClear(schedMap)) {
             virBitmapPtr currentMap = NULL;
-            ssize_t nextprio;
             bool hasPriority = false;
-            int priority = 0;
+            baseSched = NULL;
 
             switch ((virProcessSchedPolicy) i) {
             case VIR_PROC_POLICY_NONE:
@@ -23139,24 +23177,16 @@ virDomainFormatSchedDef(virDomainDefPtr def,
 
             case VIR_PROC_POLICY_FIFO:
             case VIR_PROC_POLICY_RR:
-                virBitmapClearAll(prioMap);
                 hasPriority = true;
 
-                /* we need to find a subset of vCPUs with the given scheduler
-                 * that share the priority */
-                nextprio = virBitmapNextSetBit(schedMap, -1);
-                if (!(sched = func(def, nextprio)))
+                baseSched = virDomainSchedSubsetCharacteristic(def,
+                                                               schedMap,
+                                                               prioMap,
+                                                               func,
+                                                               virDomainSchedPriorityComparator);
+                if (baseSched == NULL)
                     goto cleanup;
 
-                priority = sched->priority;
-                ignore_value(virBitmapSetBit(prioMap, nextprio));
-
-                while ((nextprio = virBitmapNextSetBit(schedMap, nextprio)) > -1) {
-                    sched = func(def, nextprio);
-                    if (sched && sched->priority == priority)
-                        ignore_value(virBitmapSetBit(prioMap, nextprio));
-                }
-
                 currentMap = prioMap;
                 break;
             }
@@ -23171,8 +23201,8 @@ virDomainFormatSchedDef(virDomainDefPtr def,
                               virProcessSchedPolicyTypeToString(i));
             VIR_FREE(tmp);
 
-            if (hasPriority)
-                virBufferAsprintf(buf, " priority='%d'", priority);
+            if (hasPriority && baseSched != NULL)
+                virBufferAsprintf(buf, " priority='%d'", baseSched->priority);
 
             virBufferAddLit(buf, "/>\n");
 
-- 
2.8.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux