]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpumap: optimize for clients that don't need online count
authorEric Blake <eblake@redhat.com>
Thu, 1 Nov 2012 23:55:43 +0000 (17:55 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 2 Nov 2012 02:36:01 +0000 (20:36 -0600)
It turns out that calling virNodeGetCPUMap(conn, NULL, NULL, 0)
is both useful, and with Viktor's patches, common enough to
optimize.  Since this interface hasn't been released yet, we
can change the RPC call.

A bit more background on the optimization - learning the cpu count
is a single file read (/sys/devices/system/cpu/possible), but
learning the number of online cpus can possibly trigger a file
read per cpu, depending on the age of the kernel, and all wasted
if the caller passed NULL for both arguments.

* src/nodeinfo.c (nodeGetCPUMap): Avoid bitmap when not needed.
* src/remote/remote_protocol.x (remote_node_get_cpu_map_args):
Supply two separate flags for needed arguments.
* src/remote/remote_driver.c (remoteNodeGetCPUMap): Update
caller.
* daemon/remote.c (remoteDispatchNodeGetCPUMap): Likewise.
* src/remote_protocol-structs: Regenerate.

daemon/remote.c
src/nodeinfo.c
src/remote/remote_driver.c
src/remote/remote_protocol.x
src/remote_protocol-structs

index 7a9df60d00f3aaa2c65b713e2213ccc55f858525..340d07de6f90187804bf31ac8827b4e58aa7435d 100644 (file)
@@ -4578,7 +4578,7 @@ remoteDispatchNodeGetCPUMap(virNetServerPtr server ATTRIBUTE_UNUSED,
                             remote_node_get_cpu_map_ret *ret)
 {
     unsigned char *cpumap = NULL;
-    unsigned int online;
+    unsigned int online = 0;
     unsigned int flags;
     int cpunum;
     int rv = -1;
@@ -4592,13 +4592,13 @@ remoteDispatchNodeGetCPUMap(virNetServerPtr server ATTRIBUTE_UNUSED,
 
     flags = args->flags;
 
-    cpunum = virNodeGetCPUMap(priv->conn, args->need_results ? &cpumap : NULL,
-                              &online, flags);
+    cpunum = virNodeGetCPUMap(priv->conn, args->need_map ? &cpumap : NULL,
+                              args->need_online ? &online : NULL, flags);
     if (cpunum < 0)
         goto cleanup;
 
     /* 'serialize' return cpumap */
-    if (args->need_results) {
+    if (args->need_map) {
         ret->cpumap.cpumap_len = VIR_CPU_MAPLEN(cpunum);
         ret->cpumap.cpumap_val = (char *) cpumap;
         cpumap = NULL;
index 35c5f96d374f6f77e72e0f763b640313ea5c36d9..3348ae70910f224e9a3cc6c62c3786e8033f3d78 100644 (file)
@@ -1277,6 +1277,9 @@ nodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     virCheckFlags(0, -1);
 
+    if (!cpumap && !online)
+        return nodeGetCPUCount();
+
     if (!(cpus = nodeGetCPUBitmap(&maxpresent)))
         goto cleanup;
 
index 71218f0c9b6b49371e88ddfbafa02829eb4319b4..5eca0fab19985b1f4b4337a70c652b77bd93462a 100644 (file)
@@ -5793,7 +5793,8 @@ remoteNodeGetCPUMap(virConnectPtr conn,
 
     remoteDriverLock(priv);
 
-    args.need_results = !!cpumap;
+    args.need_map = !!cpumap;
+    args.need_online = !!online;
     args.flags = flags;
 
     memset (&ret, 0, sizeof(ret));
index 765ffcddfc8ea5db21d9e42ecc82d4ebfc8d000d..d6ac3c10ac61b2e4bc34ae04c458d582cbddff97 100644 (file)
@@ -2671,7 +2671,8 @@ struct remote_node_get_memory_parameters_ret {
 };
 
 struct remote_node_get_cpu_map_args {
-    int need_results;
+    int need_map;
+    int need_online;
     unsigned int flags;
 };
 
index 567864a18219966ef0fb9c6dfd266fde3e7a1499..6fe7213665a72d9c12c4d16082fe388ca48618be 100644 (file)
@@ -2127,7 +2127,8 @@ struct remote_node_get_memory_parameters_ret {
         int                        nparams;
 };
 struct remote_node_get_cpu_map_args {
-        int                        need_results;
+        int                        need_map;
+        int                        need_online;
         u_int                      flags;
 };
 struct remote_node_get_cpu_map_ret {