https://bugzilla.redhat.com/show_bug.cgi?id=1135491
$ virsh iothread --help
NAME
iothreadpin - control or query domain IOThread affinity
SYNOPSIS
iothreadpin <domain> <iothread> [--cpulist <string>] [--config]
[--live] [--current]
DESCRIPTION
Pin domain IOThreads to host physical CPUs.
OPTIONS
[--domain] <string> domain name, id or uuid
[--iothread] <number> IOThread ID number
--cpulist <string> host cpu number(s) to set, or omit option to query
--config affect next boot
--live affect running domain
--current affect current domain
Unlike the iothreadsinfo, allow the get of CPU pin information for a
single IOThread as well as adding support to change the pinned CPUs
$ virsh iothreadpin $dom 3
IOThread ID CPU Affinity
---------------------------------------------------
3 0-1
$ virsh iothreadpin $dom 3 0-2
Then view the change
$ virsh iothreadpin $dom 1
IOThread ID CPU Affinity
---------------------------------------------------
3 0-2
If an invalid value is supplied, an error will be displayed
$ virsh iothreads f18iothr 4 3
error: invalid argument: iothread value out of range 4 > 3
$
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
tools/virsh-domain.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 26 +++++++++++
2 files changed, 148 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0cce57b..dcd7a26 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6878,6 +6878,122 @@ cmdIOThreadsInfo(vshControl *ctl, const vshCmd *cmd)
}
/*
+ * "iothreadpin" command
+ */
+static const vshCmdInfo info_iothreadpin[] = {
+ {.name = "help",
+ .data = N_("control or query domain IOThread affinity")
+ },
+ {.name = "desc",
+ .data = N_("Pin domain IOThreads to host physical CPUs.")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_iothreadpin[] = {
+ {.name = "domain",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("domain name, id or uuid")
+ },
+ {.name = "iothread",
+ .type = VSH_OT_INT,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("IOThread ID number")
+ },
+ {.name = "cpulist",
+ .type = VSH_OT_STRING,
+ .flags = VSH_OFLAG_EMPTY_OK,
+ .help = N_("host cpu number(s) to set, or omit option to query")
+ },
+ {.name = "config",
+ .type = VSH_OT_BOOL,
+ .help = N_("affect next boot")
+ },
+ {.name = "live",
+ .type = VSH_OT_BOOL,
+ .help = N_("affect running domain")
+ },
+ {.name = "current",
+ .type = VSH_OT_BOOL,
+ .help = N_("affect current domain")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ const char *cpulist = NULL;
+ bool config = vshCommandOptBool(cmd, "config");
+ bool live = vshCommandOptBool(cmd, "live");
+ bool current = vshCommandOptBool(cmd, "current");
+ unsigned int iothread_id = 0;
+ int maxcpu;
+ bool ret = false;
+ unsigned char *cpumap = NULL;
+ size_t cpumaplen;
+ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+
+ VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
+ VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+
+ if (config)
+ flags |= VIR_DOMAIN_AFFECT_CONFIG;
+ if (live)
+ flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0)
+ return false;
+
+ if (!cpulist)
+ VSH_EXCLUSIVE_OPTIONS_VAR(live, config);
+
+ if (vshCommandOptUInt(cmd, "iothread", &iothread_id) < 0) {
+ vshError(ctl, "%s", _("iothreadpin: Invalid IOThread
number."));
+ goto cleanup;
+ }
+
+ if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
+ goto cleanup;
+ cpumaplen = VIR_CPU_MAPLEN(maxcpu);
+
+ /* Query mode: show CPU affinity information then exit. */
+ if (!cpulist) {
+ cpumap = vshMalloc(ctl, cpumaplen);
+ if (virDomainGetIOThreadPin(dom, iothread_id,
+ cpumap, cpumaplen, flags) < 0)
+ goto cleanup;
+
+ vshPrintExtra(ctl, " %-15s %-15s\n",
+ _("IOThread ID"), _("CPU Affinity"));
+ vshPrintExtra(ctl,
"---------------------------------------------------\n");
+ vshPrint(ctl, " %-15u ", iothread_id);
+ ignore_value(vshPrintPinInfo(cpumap, cpumaplen, maxcpu, 0));
+ vshPrint(ctl, "\n");
+ } else {
+ /* Pin mode: pinning specified vcpu to specified physical cpus*/
+ if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
+ goto cleanup;
+
+ if (virDomainPinIOThread(dom, iothread_id,
+ cpumap, cpumaplen, flags) != 0)
+ goto cleanup;
+
+ }
+ ret = true;
+
+ cleanup:
+ VIR_FREE(cpumap);
+ virDomainFree(dom);
+ return ret;
+}
+
+/*
* "cpu-compare" command
*/
static const vshCmdInfo info_cpu_compare[] = {
@@ -12796,6 +12912,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_iothreads,
.flags = 0
},
+ {.name = "iothreadpin",
+ .handler = cmdIOThreadPin,
+ .opts = opts_iothreadpin,
+ .info = info_iothreadpin,
+ .flags = 0
+ },
{.name = "send-key",
.handler = cmdSendKey,
.opts = opts_send_key,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index f19601e..9289895 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1373,6 +1373,32 @@ a persistent guest.
If I<--current> is specified or I<--live> and I<--config> are not
specified,
then get the IOThread data based on the current guest state.
+=item B<iothreadpin> I<domain> I<iothread> [I<cpulist>]
+[[I<--live>] [I<--config>] | [I<--current>]]
+
+Query or change the pinning of a domain IOThread to host physical CPUs. To
+pin an I<iothread>, specify I<cpulist>; otherwise, specify just the
+I<iothread> to query a specific IOThread. In order to retrieve a list
+of all IOThreads, use B<iothreadsinfo>.
+
+I<cpulist> is a list of physical CPU numbers. Its syntax is a comma
+separated list and a special markup using '-' and '^' (ex. '0-4',
'0-3,^2') can
+also be allowed. The '-' denotes the range and the '^' denotes
exclusive.
+If you want to reset iothreadpin setting, that is, to pin an I<iothread>
+to all physical cpus, simply specify 'r' as a cpulist.
+
+If I<--live> is specified, affect a running guest. If the guest is not running,
+an error is returned.
+If I<--config> is specified, affect the next boot of a persistent guest.
+If I<--current> is specified or I<--live> and I<--config> are not
specified,
+affect the current guest state.
+Both I<--live> and I<--config> flags may be given if I<cpulist> is
present,
+but I<--current> is exclusive.
+If no flag is specified, behavior is different depending on hypervisor.
+
+B<Note>: The expression is sequentially evaluated, so "0-15,^8" is
+identical to "9-14,0-7,15" but not identical to "^8,0-15".
+
=item B<managedsave> I<domain> [I<--bypass-cache>]
[{I<--running> | I<--paused>}] [I<--verbose>]
--
2.1.0