[PATCH v3 22/25] qemu: Store all iothread's 'poll*' attributes as unsigned long long

Peter Krempa pkrempa at redhat.com
Wed Apr 19 12:04:39 UTC 2023


Convert the internal types to unsigned long long. Luckily we can also
covert the external types too:

 - 'qemuDomainSetIOThreadParams' can accept both _UINT and _ULLONG by
   converting to 'virTypedParamsGetUnsigned'

 - querying is handled via the bulk stats API which is flexible:
    - we use virTypedParamListAddUnsigned to use the bigger type only if
      necessary
    - most users don't even notice because the bindings abstract the
      data types

Apart from the code modifications we also improve the documenataion
which was missing for the setters.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 include/libvirt/libvirt-domain.h |  4 +++-
 src/libvirt-domain.c             | 14 +++++++----
 src/qemu/qemu_driver.c           | 28 +++++++++++-----------
 src/qemu/qemu_monitor.h          |  4 ++--
 src/qemu/qemu_monitor_json.c     | 41 ++++++++++++++++++++------------
 5 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 3ebb2c6642..20862a69f2 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2482,7 +2482,7 @@ int                  virDomainDelIOThread(virDomainPtr domain,
  * poll_grow and poll_shrink parameters provided. A value set too large
  * will cause more CPU time to be allocated the guest. A value set too
  * small will not provide enough cycles for the guest to process data.
- * The polling interval is not available for statistical purposes.
+ * Accepted type is VIR_TYPED_PARAM_ULLONG.
  *
  * Since: 4.10.0
  */
@@ -2495,6 +2495,7 @@ int                  virDomainDelIOThread(virDomainPtr domain,
  * use to grow its polling interval up to the poll_max_ns value. A value
  * of 0 (zero) allows the hypervisor to choose its own value. The algorithm
  * to use for adjustment is hypervisor specific.
+ * Accepted type is VIR_TYPED_PARAM_UINT or since 9.3.0 VIR_TYPED_PARAM_ULLONG.
  *
  * Since: 4.10.0
  */
@@ -2508,6 +2509,7 @@ int                  virDomainDelIOThread(virDomainPtr domain,
  * the poll_max_ns value. A value of 0 (zero) allows the hypervisor to
  * choose its own value. The algorithm to use for adjustment is hypervisor
  * specific.
+ * Accepted type is VIR_TYPED_PARAM_UINT or since 9.3.0 VIR_TYPED_PARAM_ULLONG.
  *
  * Since: 4.10.0
  */
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 63829bb028..ec42bb9a53 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12449,14 +12449,18 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  *     "iothread.<id>.poll-max-ns" - maximum polling time in ns as an unsigned
  *                                   long long. A 0 (zero) means polling is
  *                                   disabled.
- *     "iothread.<id>.poll-grow" - polling time factor as an unsigned int.
+ *     "iothread.<id>.poll-grow" - polling time factor as an unsigned int or
+ *                                 unsigned long long if exceeding range of
+ *                                 unsigned int.
  *                                 A 0 (zero) indicates to allow the underlying
  *                                 hypervisor to choose how to grow the
  *                                 polling time.
- *     "iothread.<id>.poll-shrink" - polling time divisor as an unsigned int.
- *                                 A 0 (zero) indicates to allow the underlying
- *                                 hypervisor to choose how to shrink the
- *                                 polling time.
+ *     "iothread.<id>.poll-shrink" - polling time divisor as an unsigned int or
+ *                                   unsigned long long if exceeding range of
+ *                                   unsigned int.
+ *                                   A 0 (zero) indicates to allow the underlying
+ *                                   hypervisor to choose how to shrink the
+ *                                   polling time.
  *
  * VIR_DOMAIN_STATS_MEMORY:
  *     Return memory bandwidth statistics and the usage information. The typed
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 23646b7289..dafe8af8a6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5189,9 +5189,9 @@ qemuDomainIOThreadParseParams(virTypedParameterPtr params,
                                VIR_DOMAIN_IOTHREAD_POLL_MAX_NS,
                                VIR_TYPED_PARAM_ULLONG,
                                VIR_DOMAIN_IOTHREAD_POLL_GROW,
-                               VIR_TYPED_PARAM_UINT,
+                               VIR_TYPED_PARAM_UNSIGNED,
                                VIR_DOMAIN_IOTHREAD_POLL_SHRINK,
-                               VIR_TYPED_PARAM_UINT,
+                               VIR_TYPED_PARAM_UNSIGNED,
                                VIR_DOMAIN_IOTHREAD_THREAD_POOL_MIN,
                                VIR_TYPED_PARAM_INT,
                                VIR_DOMAIN_IOTHREAD_THREAD_POOL_MAX,
@@ -5206,16 +5206,16 @@ qemuDomainIOThreadParseParams(virTypedParameterPtr params,
     if (rc == 1)
         iothread->set_poll_max_ns = true;

-    if ((rc = virTypedParamsGetUInt(params, nparams,
-                                    VIR_DOMAIN_IOTHREAD_POLL_GROW,
-                                    &iothread->poll_grow)) < 0)
+    if ((rc = virTypedParamsGetUnsigned(params, nparams,
+                                        VIR_DOMAIN_IOTHREAD_POLL_GROW,
+                                        &iothread->poll_grow)) < 0)
         return -1;
     if (rc == 1)
         iothread->set_poll_grow = true;

-    if ((rc = virTypedParamsGetUInt(params, nparams,
-                                    VIR_DOMAIN_IOTHREAD_POLL_SHRINK,
-                                    &iothread->poll_shrink)) < 0)
+    if ((rc = virTypedParamsGetUnsigned(params, nparams,
+                                        VIR_DOMAIN_IOTHREAD_POLL_SHRINK,
+                                        &iothread->poll_shrink)) < 0)
         return -1;
     if (rc == 1)
         iothread->set_poll_shrink = true;
@@ -18048,12 +18048,12 @@ qemuDomainGetStatsIOThread(virQEMUDriver *driver G_GNUC_UNUSED,
             virTypedParamListAddULLong(params, iothreads[i]->poll_max_ns,
                                        "iothread.%u.poll-max-ns",
                                        iothreads[i]->iothread_id);
-            virTypedParamListAddUInt(params, iothreads[i]->poll_grow,
-                                     "iothread.%u.poll-grow",
-                                     iothreads[i]->iothread_id);
-            virTypedParamListAddUInt(params, iothreads[i]->poll_shrink,
-                                     "iothread.%u.poll-shrink",
-                                     iothreads[i]->iothread_id);
+            virTypedParamListAddUnsigned(params, iothreads[i]->poll_grow,
+                                         "iothread.%u.poll-grow",
+                                         iothreads[i]->iothread_id);
+            virTypedParamListAddUnsigned(params, iothreads[i]->poll_shrink,
+                                         "iothread.%u.poll-shrink",
+                                         iothreads[i]->iothread_id);
         }
     }

diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 72db0c0838..09f22f2328 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1254,8 +1254,8 @@ struct _qemuMonitorIOThreadInfo {
     int thread_id;
     bool poll_valid;
     unsigned long long poll_max_ns;
-    unsigned int poll_grow;
-    unsigned int poll_shrink;
+    unsigned long long poll_grow;
+    unsigned long long poll_shrink;
     int thread_pool_min;
     int thread_pool_max;
     bool set_poll_max_ns;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 3454e85e43..745d83e2b6 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7130,10 +7130,10 @@ qemuMonitorJSONGetIOThreads(qemuMonitor *mon,

         if (virJSONValueObjectGetNumberUlong(child, "poll-max-ns",
                                              &info->poll_max_ns) == 0 &&
-            virJSONValueObjectGetNumberUint(child, "poll-grow",
-                                            &info->poll_grow) == 0 &&
-            virJSONValueObjectGetNumberUint(child, "poll-shrink",
-                                            &info->poll_shrink) == 0)
+            virJSONValueObjectGetNumberUlong(child, "poll-grow",
+                                             &info->poll_grow) == 0 &&
+            virJSONValueObjectGetNumberUlong(child, "poll-shrink",
+                                             &info->poll_shrink) == 0)
             info->poll_valid = true;
     }

@@ -7161,18 +7161,20 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,

     path = g_strdup_printf("/objects/iothread%u", iothreadInfo->iothread_id);

-#define VIR_IOTHREAD_SET_PROP(propName, propVal) \
+#define VIR_IOTHREAD_SET_PROP_UL(propName, propVal) \
     if (iothreadInfo->set_##propVal) { \
         memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \
-        prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; \
-        prop.val.iv = iothreadInfo->propVal; \
+        prop.type = QEMU_MONITOR_OBJECT_PROPERTY_ULONG; \
+        prop.val.ul = iothreadInfo->propVal; \
         if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \
             return -1; \
     }

-    VIR_IOTHREAD_SET_PROP("poll-max-ns", poll_max_ns);
-    VIR_IOTHREAD_SET_PROP("poll-grow", poll_grow);
-    VIR_IOTHREAD_SET_PROP("poll-shrink", poll_shrink);
+    VIR_IOTHREAD_SET_PROP_UL("poll-max-ns", poll_max_ns);
+    VIR_IOTHREAD_SET_PROP_UL("poll-grow", poll_grow);
+    VIR_IOTHREAD_SET_PROP_UL("poll-shrink", poll_shrink);
+
+#undef VIR_IOTHREAD_SET_PROP_UL

     if (iothreadInfo->set_thread_pool_min &&
         iothreadInfo->set_thread_pool_max) {
@@ -7192,15 +7194,24 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
             setMaxFirst = true;
     }

+#define VIR_IOTHREAD_SET_PROP_INT(propName, propVal) \
+    if (iothreadInfo->set_##propVal) { \
+        memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty)); \
+        prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT; \
+        prop.val.iv = iothreadInfo->propVal; \
+        if (qemuMonitorJSONSetObjectProperty(mon, path, propName, &prop) < 0) \
+            return -1; \
+    }
+
     if (setMaxFirst) {
-        VIR_IOTHREAD_SET_PROP("thread-pool-max", thread_pool_max);
-        VIR_IOTHREAD_SET_PROP("thread-pool-min", thread_pool_min);
+        VIR_IOTHREAD_SET_PROP_INT("thread-pool-max", thread_pool_max);
+        VIR_IOTHREAD_SET_PROP_INT("thread-pool-min", thread_pool_min);
     } else {
-        VIR_IOTHREAD_SET_PROP("thread-pool-min", thread_pool_min);
-        VIR_IOTHREAD_SET_PROP("thread-pool-max", thread_pool_max);
+        VIR_IOTHREAD_SET_PROP_INT("thread-pool-min", thread_pool_min);
+        VIR_IOTHREAD_SET_PROP_INT("thread-pool-max", thread_pool_max);
     }

-#undef VIR_IOTHREAD_SET_PROP
+#undef VIR_IOTHREAD_SET_PROP_INT

     return 0;
 }
-- 
2.39.2



More information about the libvir-list mailing list