[libvirt] [PATCHv2 5/9] libvirt.h.in: Add new cpumap macro VIR_CPU_USED

Viktor Mihajlovski mihajlov at linux.vnet.ibm.com
Tue Oct 16 14:05:12 UTC 2012


New macro VIR_CPU_USED added to facilitate the interpretation of
cpu maps.
Further, hardened the other cpumap macros against invocations
like VIR_CPU_USE(cpumap + 1, cpu)

Signed-off-by: Viktor Mihajlovski <mihajlov at linux.vnet.ibm.com>
---
 include/libvirt/libvirt.h.in |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 6b72159..3e8e4f8 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1954,7 +1954,7 @@ int                     virDomainGetEmulatorPinInfo (virDomainPtr domain,
  * USE_CPU macro set the bit (CPU usable) of the related cpu in cpumap.
  */
 
-#define VIR_USE_CPU(cpumap,cpu) (cpumap[(cpu)/8] |= (1<<((cpu)%8)))
+#define VIR_USE_CPU(cpumap,cpu)   ((cpumap)[(cpu)/8] |= (1<<((cpu)%8)))
 
 /**
  * VIR_UNUSE_CPU:
@@ -1965,7 +1965,19 @@ int                     virDomainGetEmulatorPinInfo (virDomainPtr domain,
  * USE_CPU macro reset the bit (CPU not usable) of the related cpu in cpumap.
  */
 
-#define VIR_UNUSE_CPU(cpumap,cpu)       (cpumap[(cpu)/8] &= ~(1<<((cpu)%8)))
+#define VIR_UNUSE_CPU(cpumap,cpu) ((cpumap)[(cpu)/8] &= ~(1<<((cpu)%8)))
+
+/**
+ * VIR_CPU_USED:
+ * @cpumap: pointer to a bit map of real CPUs (in 8-bit bytes) (IN)
+ * @cpu: the physical CPU number
+ *
+ * This macro can be used in conjunction with virNodeGetCPUMapFlags() API.
+ * VIR_CPU_USED returns true if the bit of the related CPU is set.
+ *
+ */
+
+#define VIR_CPU_USED(cpumap,cpu)  ((cpumap)[(cpu)/8] & (1<<((cpu)%8)))
 
 /**
  * VIR_CPU_MAPLEN:
@@ -1976,7 +1988,7 @@ int                     virDomainGetEmulatorPinInfo (virDomainPtr domain,
  * CPU map between a single virtual & all physical CPUs of a domain.
  */
 
-#define VIR_CPU_MAPLEN(cpu)      (((cpu)+7)/8)
+#define VIR_CPU_MAPLEN(cpu)       (((cpu)+7)/8)
 
 
 int                     virDomainGetVcpus       (virDomainPtr domain,
@@ -1998,7 +2010,7 @@ int                     virDomainGetVcpus       (virDomainPtr domain,
  */
 
 #define VIR_CPU_USABLE(cpumaps,maplen,vcpu,cpu) \
-        (cpumaps[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))
+    ((cpumaps)[((vcpu)*(maplen))+((cpu)/8)] & (1<<((cpu)%8)))
 
 /**
  * VIR_COPY_CPUMAP:
-- 
1.7.0.4




More information about the libvir-list mailing list