[libvirt] [PATCH] virsh nodecpustats returns incorrect stats of cpu on Linux when the number of online cpu exceed 9.

Ján Tomko jtomko at redhat.com
Tue Jan 14 13:30:42 UTC 2014


On 01/13/2014 11:28 AM, mars at linux.vnet.ibm.com wrote:
> From: Bing Bu Cao <mars at linux.vnet.ibm.com>
> 
> To retrieve node cpu statistics on Linux system, the
> linuxNodeGetCPUstats function use STRPREFIX() to match the
> cpuid with the cpuid read from /proc/cpustat, it will cause
> obvious error.
> 
> For example:
> 'virsh nodecpustats 12' will display stats of cpu1 if the latter is online.
> 
> This patch fixes this bug.
> 
> Signed-off-by: Bing Bu Cao <mars at linux.vnet.ibm.com>
> Signed-off-by: Pradipta Kr. Banerjee <bpradip at in.ibm.com>
> ---
>  src/nodeinfo.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> index 05bc038..6d7926c 100644
> --- a/src/nodeinfo.c
> +++ b/src/nodeinfo.c
> @@ -715,8 +715,9 @@ linuxNodeGetCPUStats(FILE *procstat,
>  
>      while (fgets(line, sizeof(line), procstat) != NULL) {
>          char *buf = line;
> +        char **buf_header = virStringSplit(buf, " ", 2);
>  
> -        if (STRPREFIX(buf, cpu_header)) { /* aka logical CPU time */
> +        if (STREQ(buf_header[0], cpu_header)) { /* aka logical CPU time */
>              size_t i;
>  
>              if (sscanf(buf,

I think it would be simpler to just add a space at the end of cpu_header and
keep using STRPREFIX than splitting the string.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140114/96ee3a04/attachment-0001.sig>


More information about the libvir-list mailing list