qemu_monitor_json: Implement logic for setting iothread.thread-pool-{min,max}

When virDomainSetIOThreadParams() API is called, well its QEMU
impl: qemuDomainSetIOThreadParams() then typed params are parsed
by qemuDomainIOThreadParseParams() into this
qemuMonitorIOThreadInfo struct. In the struct we have a <int,
bool> pair for every IOThread attribute we can tune through
monitor. The struct is then passed to
qemuMonitorJSONSetIOThread() which looks at the bool and if set
then the corresponding attribute is set to given value. Each
attribute is thus changed in a separate call. While this works
for attributes independent of each other ("poll-max-ns",
"poll-grow", "poll-shrink"), it does not always work for the
other attributes ("thread-pool-min" and "thread-pool-max").

The limitation here is that the lower boundary (minimum) has to
be lower (or equal to) the upper boundary (maximum) at all times.

This means, that in some cases we might need to set attributes in
reversed order to meet the constraint.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/339
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Michal Privoznik 2022-06-30 13:44:58 +02:00
parent 49a32cd8cb
commit 3547875f3a

View File

@ -7428,6 +7428,7 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
{
g_autofree char *path = NULL;
qemuMonitorJSONObjectProperty prop;
bool setMaxFirst = false;
path = g_strdup_printf("/objects/iothread%u", iothreadInfo->iothread_id);
@ -7443,8 +7444,32 @@ qemuMonitorJSONSetIOThread(qemuMonitor *mon,
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("thread-pool-min", thread_pool_min);
VIR_IOTHREAD_SET_PROP("thread-pool-max", thread_pool_max);
if (iothreadInfo->set_thread_pool_min &&
iothreadInfo->set_thread_pool_max) {
int curr_max = -1;
/* By default, the minimum is set first, followed by the maximum. But
* if the current maximum is below the minimum we want to set we need
* to set the maximum first. Otherwise would get an error because we
* would be attempting to shift minimum above maximum. */
prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT;
if (qemuMonitorJSONGetObjectProperty(mon, path,
"thread-pool-max", &prop) < 0)
return -1;
curr_max = prop.val.iv;
if (curr_max < iothreadInfo->thread_pool_min)
setMaxFirst = true;
}
if (setMaxFirst) {
VIR_IOTHREAD_SET_PROP("thread-pool-max", thread_pool_max);
VIR_IOTHREAD_SET_PROP("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);
}
#undef VIR_IOTHREAD_SET_PROP