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.
This commit is contained in:
Eric Blake 2012-11-01 17:55:43 -06:00
parent ba804d9fd1
commit 3d0130cbcc
5 changed files with 13 additions and 7 deletions

View 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;

View File

@ -1277,6 +1277,9 @@ nodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
virCheckFlags(0, -1);
if (!cpumap && !online)
return nodeGetCPUCount();
if (!(cpus = nodeGetCPUBitmap(&maxpresent)))
goto cleanup;

View 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));

View 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;
};

View 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 {