[libvirt] [PATCHv7 16/18] qemu: refactor qemuDomainGetStatsCpu

Wang Huaqiang posted 18 patches 7 years, 3 months ago
There is a newer version of this series
[libvirt] [PATCHv7 16/18] qemu: refactor qemuDomainGetStatsCpu
Posted by Wang Huaqiang 7 years, 3 months ago
Refactoring qemuDomainGetStatsCpu, make it possible to add
more CPU statistics.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
---
 src/qemu/qemu_driver.c | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a52e249..12a5f8f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19711,30 +19711,29 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
     unsigned long long sys_time = 0;
     int err = 0;
 
-    if (!priv->cgroup)
-        return 0;
-
-    err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
-    if (!err && virTypedParamsAddULLong(&record->params,
-                                        &record->nparams,
-                                        maxparams,
-                                        "cpu.time",
-                                        cpu_time) < 0)
-        return -1;
+    if (priv->cgroup) {
+        err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
+        if (!err && virTypedParamsAddULLong(&record->params,
+                                            &record->nparams,
+                                            maxparams,
+                                            "cpu.time",
+                                            cpu_time) < 0)
+            return -1;
 
-    err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
-    if (!err && virTypedParamsAddULLong(&record->params,
-                                        &record->nparams,
-                                        maxparams,
-                                        "cpu.user",
-                                        user_time) < 0)
-        return -1;
-    if (!err && virTypedParamsAddULLong(&record->params,
-                                        &record->nparams,
-                                        maxparams,
-                                        "cpu.system",
-                                        sys_time) < 0)
-        return -1;
+        err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
+        if (!err && virTypedParamsAddULLong(&record->params,
+                                            &record->nparams,
+                                            maxparams,
+                                            "cpu.user",
+                                            user_time) < 0)
+            return -1;
+        if (!err && virTypedParamsAddULLong(&record->params,
+                                            &record->nparams,
+                                            maxparams,
+                                            "cpu.system",
+                                            sys_time) < 0)
+            return -1;
+    }
 
     return 0;
 }
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv7 16/18] qemu: refactor qemuDomainGetStatsCpu
Posted by John Ferlan 7 years, 3 months ago

On 10/22/18 4:01 AM, Wang Huaqiang wrote:
> Refactoring qemuDomainGetStatsCpu, make it possible to add
> more CPU statistics.
> 
> Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
> ---
>  src/qemu/qemu_driver.c | 45 ++++++++++++++++++++++-----------------------
>  1 file changed, 22 insertions(+), 23 deletions(-)
> 

Maybe instead of inverting the logic, let's create a cgroup helper...

qemuDomainGetStatsCpuCgroup(dom, record, *maxparams)
{
    logic as is now
}


static int
qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                      virDomainObjPtr dom,
                      virDomainStatsRecordPtr record,
                      int *maxparams,
                      unsigned int privflags ATTRIBUTE_UNUSED)
{
    return qemuDomainGetStatsCpuCgroup(dom, record, maxparams);
}


Then the subsequent patch would alter the above check and add the new call.

John

> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index a52e249..12a5f8f 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -19711,30 +19711,29 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
>      unsigned long long sys_time = 0;
>      int err = 0;
>  
> -    if (!priv->cgroup)
> -        return 0;
> -
> -    err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
> -    if (!err && virTypedParamsAddULLong(&record->params,
> -                                        &record->nparams,
> -                                        maxparams,
> -                                        "cpu.time",
> -                                        cpu_time) < 0)
> -        return -1;
> +    if (priv->cgroup) {
> +        err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
> +        if (!err && virTypedParamsAddULLong(&record->params,
> +                                            &record->nparams,
> +                                            maxparams,
> +                                            "cpu.time",
> +                                            cpu_time) < 0)
> +            return -1;
>  
> -    err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
> -    if (!err && virTypedParamsAddULLong(&record->params,
> -                                        &record->nparams,
> -                                        maxparams,
> -                                        "cpu.user",
> -                                        user_time) < 0)
> -        return -1;
> -    if (!err && virTypedParamsAddULLong(&record->params,
> -                                        &record->nparams,
> -                                        maxparams,
> -                                        "cpu.system",
> -                                        sys_time) < 0)
> -        return -1;
> +        err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
> +        if (!err && virTypedParamsAddULLong(&record->params,
> +                                            &record->nparams,
> +                                            maxparams,
> +                                            "cpu.user",
> +                                            user_time) < 0)
> +            return -1;
> +        if (!err && virTypedParamsAddULLong(&record->params,
> +                                            &record->nparams,
> +                                            maxparams,
> +                                            "cpu.system",
> +                                            sys_time) < 0)
> +            return -1;
> +    }
>  
>      return 0;
>  }
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv7 16/18] qemu: refactor qemuDomainGetStatsCpu
Posted by Wang, Huaqiang 7 years, 2 months ago

On 11/6/2018 3:27 AM, John Ferlan wrote:
> On 10/22/18 4:01 AM, Wang Huaqiang wrote:
>> Refactoring qemuDomainGetStatsCpu, make it possible to add
>> more CPU statistics.
>>
>> Signed-off-by: Wang Huaqiang<huaqiang.wang@intel.com>
>> ---
>>   src/qemu/qemu_driver.c | 45 ++++++++++++++++++++++-----------------------
>>   1 file changed, 22 insertions(+), 23 deletions(-)
>>
> Maybe instead of inverting the logic, let's create a cgroup helper...
>
> qemuDomainGetStatsCpuCgroup(dom, record, *maxparams)
> {
>      logic as is now
> }
>
>
> static int
> qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
>                        virDomainObjPtr dom,
>                        virDomainStatsRecordPtr record,
>                        int *maxparams,
>                        unsigned int privflags ATTRIBUTE_UNUSED)
> {
>      return qemuDomainGetStatsCpuCgroup(dom, record, maxparams);
> }
>
>
> Then the subsequent patch would alter the above check and add the new call.
>
> John

Thanks for advice. Will be done in next series.
Huaqiang

>> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>> index a52e249..12a5f8f 100644
>> --- a/src/qemu/qemu_driver.c
>> +++ b/src/qemu/qemu_driver.c
>> @@ -19711,30 +19711,29 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
>>       unsigned long long sys_time = 0;
>>       int err = 0;
>>   
>> -    if (!priv->cgroup)
>> -        return 0;
>> -
>> -    err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
>> -    if (!err && virTypedParamsAddULLong(&record->params,
>> -                                        &record->nparams,
>> -                                        maxparams,
>> -                                        "cpu.time",
>> -                                        cpu_time) < 0)
>> -        return -1;
>> +    if (priv->cgroup) {
>> +        err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time);
>> +        if (!err && virTypedParamsAddULLong(&record->params,
>> +                                            &record->nparams,
>> +                                            maxparams,
>> +                                            "cpu.time",
>> +                                            cpu_time) < 0)
>> +            return -1;
>>   
>> -    err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
>> -    if (!err && virTypedParamsAddULLong(&record->params,
>> -                                        &record->nparams,
>> -                                        maxparams,
>> -                                        "cpu.user",
>> -                                        user_time) < 0)
>> -        return -1;
>> -    if (!err && virTypedParamsAddULLong(&record->params,
>> -                                        &record->nparams,
>> -                                        maxparams,
>> -                                        "cpu.system",
>> -                                        sys_time) < 0)
>> -        return -1;
>> +        err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time);
>> +        if (!err && virTypedParamsAddULLong(&record->params,
>> +                                            &record->nparams,
>> +                                            maxparams,
>> +                                            "cpu.user",
>> +                                            user_time) < 0)
>> +            return -1;
>> +        if (!err && virTypedParamsAddULLong(&record->params,
>> +                                            &record->nparams,
>> +                                            maxparams,
>> +                                            "cpu.system",
>> +                                            sys_time) < 0)
>> +            return -1;
>> +    }
>>   
>>       return 0;
>>   }
>>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list