[libvirt] [PATCH v4 5/9] Implement public API for getting/setting specific IOThread pinning

John Ferlan jferlan at redhat.com
Fri Mar 6 02:03:02 UTC 2015


Add virDomainGetIOThreadPin to fetch the pinned CPU affinity map
for one IOThread.

Add virDomainPinIOThread to allow setting the CPU affinity for a
specific IOThread.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 include/libvirt/libvirt-domain.h |  10 +++
 src/driver-hypervisor.h          |  16 +++++
 src/libvirt-domain.c             | 152 +++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |   2 +
 4 files changed, 180 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 9487b80..fc35cd2 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1609,6 +1609,16 @@ void                 virDomainIOThreadsInfoFree(virDomainIOThreadInfoPtr info);
 int                  virDomainGetIOThreadsInfo(virDomainPtr domain,
                                                virDomainIOThreadInfoPtr **info,
                                                unsigned int flags);
+int                  virDomainGetIOThreadPin (virDomainPtr domain,
+                                              unsigned int iothread_id,
+                                              unsigned char *cpumap,
+                                              int maplen,
+                                              unsigned int flags);
+int                  virDomainPinIOThread(virDomainPtr domain,
+                                          unsigned int iothread_id,
+                                          unsigned char *cpumap,
+                                          int maplen,
+                                          unsigned int flags);
 
 /**
  * VIR_USE_CPU:
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index c2b4cd8..d62ce4b 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -386,6 +386,20 @@ typedef int
                                 unsigned int flags);
 
 typedef int
+(*virDrvDomainGetIOThreadPin)(virDomainPtr domain,
+                              unsigned int iothread_id,
+                              unsigned char *cpumap,
+                              int maplen,
+                              unsigned int flags);
+
+typedef int
+(*virDrvDomainPinIOThread)(virDomainPtr domain,
+                           unsigned int iothread_id,
+                           unsigned char *cpumap,
+                           int maplen,
+                           unsigned int flags);
+
+typedef int
 (*virDrvDomainGetSecurityLabel)(virDomainPtr domain,
                                 virSecurityLabelPtr seclabel);
 
@@ -1260,6 +1274,8 @@ struct _virHypervisorDriver {
     virDrvDomainGetVcpus domainGetVcpus;
     virDrvDomainGetMaxVcpus domainGetMaxVcpus;
     virDrvDomainGetIOThreadsInfo domainGetIOThreadsInfo;
+    virDrvDomainGetIOThreadPin domainGetIOThreadPin;
+    virDrvDomainPinIOThread domainPinIOThread;
     virDrvDomainGetSecurityLabel domainGetSecurityLabel;
     virDrvDomainGetSecurityLabelList domainGetSecurityLabelList;
     virDrvNodeGetSecurityModel nodeGetSecurityModel;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 27f6abe..ee3659a 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -7964,6 +7964,158 @@ virDomainIOThreadsInfoFree(virDomainIOThreadInfoPtr info)
 
 
 /**
+ * virDomainGetIOThreadPin:
+ * @domain: pointer to domain object, or NULL for Domain0
+ * @iothread_id: An IOThread ID of which to get the pin information
+ * @cpumap: pointer to a bit map of real CPUs for the IOThread of this
+ *     domain (in 8-bit bytes) (OUT)
+ *     The memory allocated to cpumap must be maplen bytes
+ *     Must not be NULL.
+ * @maplen: the number of bytes in the cpumap, from 1 up to size of CPU map.
+ *     Must be positive.
+ * @flags: bitwise-OR of virDomainModificationImpact
+ *     Must not be VIR_DOMAIN_AFFECT_LIVE and
+ *     VIR_DOMAIN_AFFECT_CONFIG concurrently.
+ *
+ * Query the CPU affinity setting of an IOThread ID of the domain, store
+ * it in cpumap.
+ *
+ * Returns 1 in case of success,
+ * 0 in case of no IOThread threads are pinned to pcpus,
+ * -1 in case of failure.
+ */
+int
+virDomainGetIOThreadPin(virDomainPtr domain,
+                        unsigned int iothread_id,
+                        unsigned char *cpumap,
+                        int maplen,
+                        unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "iothread_id=%u cpumap=%p, maplen=%d, flags=%x",
+                     iothread_id, cpumap, maplen, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    if ((unsigned short) iothread_id != iothread_id) {
+        virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"),
+                       iothread_id);
+        goto error;
+    }
+    virCheckPositiveArgGoto(iothread_id, error);
+    virCheckNonNullArgGoto(cpumap, error);
+    virCheckPositiveArgGoto(maplen, error);
+
+    /* At most one of these two flags should be set.  */
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
+        (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        virReportInvalidArg(flags,
+                            _("flags 'affect live' and 'affect config' in %s "
+                              "are mutually exclusive"),
+                            __FUNCTION__);
+        goto error;
+    }
+    conn = domain->conn;
+
+    if (conn->driver->domainGetIOThreadPin) {
+        int ret;
+        ret = conn->driver->domainGetIOThreadPin(domain, iothread_id,
+                                                 cpumap, maplen, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
+/**
+ * virDomainPinIOThread:
+ * @domain: a domain object
+ * @iothread_id: either the thread_id to modify or a count of IOThreads
+ *      to be added or removed from the domain depending on the @flags setting
+ * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
+ *      Each bit set to 1 means that corresponding CPU is usable.
+ *      Bytes are stored in little-endian order: CPU0-7, 8-15...
+ *      In each byte, lowest CPU number is least significant bit.
+ * @maplen: number of bytes in cpumap, from 1 up to size of CPU map in
+ *      underlying virtualization system (Xen...).
+ *      If maplen < size, missing bytes are set to zero.
+ *      If maplen > size, failure code is returned.
+ * @flags: bitwise-OR of virDomainModificationImpact
+ *
+ * Dynamically change the real CPUs which can be allocated to an IOThread.
+ * This function may require privileged access to the hypervisor.
+ *
+ * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
+ * Both flags may be set.
+ * If VIR_DOMAIN_AFFECT_LIVE is set, the change affects a running domain
+ * and may fail if domain is not alive.
+ * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
+ * and will fail for transient domains. If neither flag is specified (that is,
+ * @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain modifies
+ * persistent setup, while an active domain is hypervisor-dependent on whether
+ * just live or both live and persistent state is changed.
+ * Not all hypervisors can support all flag combinations.
+ *
+ * See also virDomainGetIOThreadsInfo for querying this information.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainPinIOThread(virDomainPtr domain,
+                     unsigned int iothread_id,
+                     unsigned char *cpumap,
+                     int maplen,
+                     unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "iothread_id=%u, cpumap=%p, maplen=%d",
+                     iothread_id, cpumap, maplen);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
+    if ((unsigned short) iothread_id != iothread_id) {
+        virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"),
+                       iothread_id);
+        goto error;
+    }
+    virCheckPositiveArgGoto(iothread_id, error);
+    virCheckNonNullArgGoto(cpumap, error);
+    virCheckPositiveArgGoto(maplen, error);
+
+    if (conn->driver->domainPinIOThread) {
+        int ret;
+        ret = conn->driver->domainPinIOThread(domain, iothread_id,
+                                              cpumap, maplen, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
+/**
  * virDomainGetSecurityLabel:
  * @domain: a domain object
  * @seclabel: pointer to a virSecurityLabel structure
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 34852c1..e966bdd 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -699,6 +699,8 @@ LIBVIRT_1.2.14 {
     global:
         virDomainIOThreadsInfoFree;
         virDomainGetIOThreadsInfo;
+        virDomainGetIOThreadPin;
+        virDomainPinIOThread;
 } LIBVIRT_1.2.12;
 
 # .... define new API here using predicted next version number ....
-- 
2.1.0




More information about the libvir-list mailing list