From: Eric Blake Date: Thu, 1 Nov 2012 23:55:43 +0000 (-0600) Subject: cpumap: optimize for clients that don't need online count X-Git-Tag: v1.0.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d0130cbcc7a70e3119dd7f4a1d4a5b484dc2823;p=thirdparty%2Flibvirt.git cpumap: optimize for clients that don't need online count 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. --- diff --git a/daemon/remote.c b/daemon/remote.c index 7a9df60d00..340d07de6f 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -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; diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 35c5f96d37..3348ae7091 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -1277,6 +1277,9 @@ nodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED, virCheckFlags(0, -1); + if (!cpumap && !online) + return nodeGetCPUCount(); + if (!(cpus = nodeGetCPUBitmap(&maxpresent))) goto cleanup; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 71218f0c9b..5eca0fab19 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -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)); diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 765ffcddfc..d6ac3c10ac 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -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; }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 567864a182..6fe7213665 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -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 {