Re: [libvirt] [PATCH 10/16] util: Add virSysfsGetCPUCache* functions
On Friday, 31 March 2017 at 7:39 PM, Martin Kletzander wrote: > On Fri, Mar 31, 2017 at 05:32:16PM +0800, Eli Qiao wrote: > > > > > > On Thursday, 30 March 2017 at 10:03 PM, Martin Kletzander wrote: > > > > > Signed-off-by: Martin Kletzander > > (mailto:mklet...@redhat.com)> > > > --- > > > src/libvirt_private.syms | 5 +++ > > > src/util/virsysfs.c | 102 +++ > > > src/util/virsysfs.h | 34 > > > 3 files changed, 141 insertions(+) > > > > > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > > > index bcd2506ef7c9..0b3b41516fe6 100644 > > > --- a/src/libvirt_private.syms > > > +++ b/src/libvirt_private.syms > > > @@ -2623,6 +2623,11 @@ virVasprintfInternal; > > > # util/virsysfs.h > > > virSysfsCpuDirOpen; > > > virSysfsDirOpen; > > > +virSysfsGetCpuCacheValueBitmap; > > > +virSysfsGetCpuCacheValueInt; > > > +virSysfsGetCpuCacheValueScaledInt; > > > +virSysfsGetCpuCacheValueString; > > > +virSysfsGetCpuCacheValueUint; > > > virSysfsGetCpuValueBitmap; > > > virSysfsGetCpuValueInt; > > > virSysfsGetCpuValueString; > > > diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c > > > index a8550bbfbc26..2a64be4f5f73 100644 > > > --- a/src/util/virsysfs.c > > > +++ b/src/util/virsysfs.c > > > @@ -221,6 +221,108 @@ virSysfsCpuDirOpen(unsigned int cpu, > > > } > > > > > > > > > +/* > > > + * Per-CPU/cache getters > > > + */ > > > +int > > > +virSysfsGetCpuCacheValueInt(unsigned int cpu, > > > + const char *cache, > > > + const char *file, > > > + int *value) > > > > > > > > > > > It will be helpful that we describe what cache, file looks like > > even it’s straight enough to reading code. > > > > > What do you mean? The files look just like they look in the system. > It's a copy of what actually is under /sys/devices/system. The > description is in the kernel. > Okay, never mind. > > > > +{ > > > + char *path = NULL; > > > + int ret = -1; > > > + > > > + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", > > > > > > > > > > > cpu/cpu0/cache/index3/size > > ??? > ignore this. > > > > + sysfs_system_path, cpu, cache, file) < 0) > > > + return -1; > > > + > > > + ret = virFileReadValueInt(path, value); > > > + > > > + VIR_FREE(path); > > > + return ret; > > > +} > > > + > > > + > > > +int > > > +virSysfsGetCpuCacheValueUint(unsigned int cpu, > > > + const char *cache, > > > + const char *file, > > > + unsigned int *value) > > > +{ > > > + char *path = NULL; > > > + int ret = -1; > > > + > > > + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", > > > + sysfs_system_path, cpu, cache, file) < 0) > > > + return -1; > > > + > > > + ret = virFileReadValueUint(path, value); > > > + > > > + VIR_FREE(path); > > > + return ret; > > > +} > > > + > > > +int > > > +virSysfsGetCpuCacheValueScaledInt(unsigned int cpu, > > > + const char *cache, > > > + const char *file, > > > + unsigned long long *value) > > > > > > > > > > > Can we add notes here to tell the value is in unite KiB ? > > Well what if you want to use this for another file in the future? This > function will be able to read it even if the file has "1M" in it. Or > did you mean something else? > > My mistake, it’s should B (not KiB), It’s okay. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 10/16] util: Add virSysfsGetCPUCache* functions
On Fri, Mar 31, 2017 at 05:32:16PM +0800, Eli Qiao wrote: On Thursday, 30 March 2017 at 10:03 PM, Martin Kletzander wrote: Signed-off-by: Martin Kletzander mailto:mklet...@redhat.com)> --- src/libvirt_private.syms | 5 +++ src/util/virsysfs.c | 102 +++ src/util/virsysfs.h | 34 3 files changed, 141 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bcd2506ef7c9..0b3b41516fe6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2623,6 +2623,11 @@ virVasprintfInternal; # util/virsysfs.h virSysfsCpuDirOpen; virSysfsDirOpen; +virSysfsGetCpuCacheValueBitmap; +virSysfsGetCpuCacheValueInt; +virSysfsGetCpuCacheValueScaledInt; +virSysfsGetCpuCacheValueString; +virSysfsGetCpuCacheValueUint; virSysfsGetCpuValueBitmap; virSysfsGetCpuValueInt; virSysfsGetCpuValueString; diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c index a8550bbfbc26..2a64be4f5f73 100644 --- a/src/util/virsysfs.c +++ b/src/util/virsysfs.c @@ -221,6 +221,108 @@ virSysfsCpuDirOpen(unsigned int cpu, } +/* + * Per-CPU/cache getters + */ +int +virSysfsGetCpuCacheValueInt(unsigned int cpu, + const char *cache, + const char *file, + int *value) It will be helpful that we describe what cache, file looks like even it’s straight enough to reading code. What do you mean? The files look just like they look in the system. It's a copy of what actually is under /sys/devices/system. The description is in the kernel. +{ + char *path = NULL; + int ret = -1; + + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", cpu/cpu0/cache/index3/size ??? + sysfs_system_path, cpu, cache, file) < 0) + return -1; + + ret = virFileReadValueInt(path, value); + + VIR_FREE(path); + return ret; +} + + +int +virSysfsGetCpuCacheValueUint(unsigned int cpu, + const char *cache, + const char *file, + unsigned int *value) +{ + char *path = NULL; + int ret = -1; + + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", + sysfs_system_path, cpu, cache, file) < 0) + return -1; + + ret = virFileReadValueUint(path, value); + + VIR_FREE(path); + return ret; +} + +int +virSysfsGetCpuCacheValueScaledInt(unsigned int cpu, + const char *cache, + const char *file, + unsigned long long *value) Can we add notes here to tell the value is in unite KiB ? Well what if you want to use this for another file in the future? This function will be able to read it even if the file has "1M" in it. Or did you mean something else? signature.asc Description: Digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 10/16] util: Add virSysfsGetCPUCache* functions
On Thursday, 30 March 2017 at 10:03 PM, Martin Kletzander wrote: > Signed-off-by: Martin Kletzander (mailto:mklet...@redhat.com)> > --- > src/libvirt_private.syms | 5 +++ > src/util/virsysfs.c | 102 +++ > src/util/virsysfs.h | 34 > 3 files changed, 141 insertions(+) > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms > index bcd2506ef7c9..0b3b41516fe6 100644 > --- a/src/libvirt_private.syms > +++ b/src/libvirt_private.syms > @@ -2623,6 +2623,11 @@ virVasprintfInternal; > # util/virsysfs.h > virSysfsCpuDirOpen; > virSysfsDirOpen; > +virSysfsGetCpuCacheValueBitmap; > +virSysfsGetCpuCacheValueInt; > +virSysfsGetCpuCacheValueScaledInt; > +virSysfsGetCpuCacheValueString; > +virSysfsGetCpuCacheValueUint; > virSysfsGetCpuValueBitmap; > virSysfsGetCpuValueInt; > virSysfsGetCpuValueString; > diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c > index a8550bbfbc26..2a64be4f5f73 100644 > --- a/src/util/virsysfs.c > +++ b/src/util/virsysfs.c > @@ -221,6 +221,108 @@ virSysfsCpuDirOpen(unsigned int cpu, > } > > > +/* > + * Per-CPU/cache getters > + */ > +int > +virSysfsGetCpuCacheValueInt(unsigned int cpu, > + const char *cache, > + const char *file, > + int *value) > > It will be helpful that we describe what cache, file looks like even it’s straight enough to reading code. > +{ > + char *path = NULL; > + int ret = -1; > + > + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", > > cpu/cpu0/cache/index3/size > + sysfs_system_path, cpu, cache, file) < 0) > + return -1; > + > + ret = virFileReadValueInt(path, value); > + > + VIR_FREE(path); > + return ret; > +} > + > + > +int > +virSysfsGetCpuCacheValueUint(unsigned int cpu, > + const char *cache, > + const char *file, > + unsigned int *value) > +{ > + char *path = NULL; > + int ret = -1; > + > + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", > + sysfs_system_path, cpu, cache, file) < 0) > + return -1; > + > + ret = virFileReadValueUint(path, value); > + > + VIR_FREE(path); > + return ret; > +} > + > +int > +virSysfsGetCpuCacheValueScaledInt(unsigned int cpu, > + const char *cache, > + const char *file, > + unsigned long long *value) > > Can we add notes here to tell the value is in unite KiB ? > +{ > + char *path = NULL; > + int ret = -1; > + > + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", > + sysfs_system_path, cpu, cache, file) < 0) > + return -1; > + > + ret = virFileReadValueScaledInt(path, value); > + > + VIR_FREE(path); > + return ret; > +} > + > + > +int > +virSysfsGetCpuCacheValueString(unsigned int cpu, > + const char *cache, > + const char *file, > + char **value) > +{ > + char *path = NULL; > + int ret = -1; > + > + if (virAsprintf(&path, "cpu/cpu%u/cache/%s/%s", cpu, cache, file) < 0) > + return -1; > + > + ret = virSysfsGetValueString(path, value); > + > + VIR_FREE(path); > + return ret; > +} > + > +int > +virSysfsGetCpuCacheValueBitmap(unsigned int cpu, > + const char *cache, > + const char *file, > + virBitmapPtr *value) > +{ > + char *path = NULL; > + int ret = -1; > + > + if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", > + sysfs_system_path, cpu, cache, file) < 0) > + return -1; > + > + ret = virFileReadValueBitmap(path, VIR_SYSFS_VALUE_MAXLEN, value); > + VIR_FREE(path); > + return ret; > +} > + > + > +/* > + * Per-NUMA node getters > + */ > int > virSysfsGetNodeValueString(unsigned int node, > const char *file, > diff --git a/src/util/virsysfs.h b/src/util/virsysfs.h > index 25bd100ea9cb..92f9111b069f 100644 > --- a/src/util/virsysfs.h > +++ b/src/util/virsysfs.h > @@ -77,6 +77,40 @@ virSysfsCpuDirOpen(unsigned int cpu, > > > /* > + * Per-CPU/cache getters > + */ > +int > +virSysfsGetCpuCacheValueInt(unsigned int cpu, > + const char *cache, > + const char *file, > + int *value); > + > +int > +virSysfsGetCpuCacheValueUint(unsigned int cpu, > + const char *cache, > + const char *file, > + unsigned int *value); > + > +int > +virSysfsGetCpuCacheValueScaledInt(unsigned int cpu, > + const char *cache, > + const char *file, > + unsigned long long *value); > + > +int > +virSysfsGetCpuCacheValueString(unsigned int cpu, > + const char *cache, > + const char *file, > + char **value); > + > +int > +virSysfsGetCpuCacheValueBitmap(unsigned int cpu, > + const char *cache, > + const char *file, > + virBitmapPtr *value); > + > + > +/* > * Per-NUMA node getters > */ > int > -- > 2.12.2 > > -- > libvir-list mailing list > libvir-list@redhat.com (mailto:libvir-list@redhat.com) > https://www.redhat.com/mailman/listinfo/libvir-list > > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 10/16] util: Add virSysfsGetCPUCache* functions
Signed-off-by: Martin Kletzander --- src/libvirt_private.syms | 5 +++ src/util/virsysfs.c | 102 +++ src/util/virsysfs.h | 34 3 files changed, 141 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bcd2506ef7c9..0b3b41516fe6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2623,6 +2623,11 @@ virVasprintfInternal; # util/virsysfs.h virSysfsCpuDirOpen; virSysfsDirOpen; +virSysfsGetCpuCacheValueBitmap; +virSysfsGetCpuCacheValueInt; +virSysfsGetCpuCacheValueScaledInt; +virSysfsGetCpuCacheValueString; +virSysfsGetCpuCacheValueUint; virSysfsGetCpuValueBitmap; virSysfsGetCpuValueInt; virSysfsGetCpuValueString; diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c index a8550bbfbc26..2a64be4f5f73 100644 --- a/src/util/virsysfs.c +++ b/src/util/virsysfs.c @@ -221,6 +221,108 @@ virSysfsCpuDirOpen(unsigned int cpu, } +/* + * Per-CPU/cache getters + */ +int +virSysfsGetCpuCacheValueInt(unsigned int cpu, +const char *cache, +const char *file, +int *value) +{ +char *path = NULL; +int ret = -1; + +if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", +sysfs_system_path, cpu, cache, file) < 0) +return -1; + +ret = virFileReadValueInt(path, value); + +VIR_FREE(path); +return ret; +} + + +int +virSysfsGetCpuCacheValueUint(unsigned int cpu, + const char *cache, + const char *file, + unsigned int *value) +{ +char *path = NULL; +int ret = -1; + +if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", +sysfs_system_path, cpu, cache, file) < 0) +return -1; + +ret = virFileReadValueUint(path, value); + +VIR_FREE(path); +return ret; +} + +int +virSysfsGetCpuCacheValueScaledInt(unsigned int cpu, + const char *cache, + const char *file, + unsigned long long *value) +{ +char *path = NULL; +int ret = -1; + +if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", +sysfs_system_path, cpu, cache, file) < 0) +return -1; + +ret = virFileReadValueScaledInt(path, value); + +VIR_FREE(path); +return ret; +} + + +int +virSysfsGetCpuCacheValueString(unsigned int cpu, + const char *cache, + const char *file, + char **value) +{ +char *path = NULL; +int ret = -1; + +if (virAsprintf(&path, "cpu/cpu%u/cache/%s/%s", cpu, cache, file) < 0) +return -1; + +ret = virSysfsGetValueString(path, value); + +VIR_FREE(path); +return ret; +} + +int +virSysfsGetCpuCacheValueBitmap(unsigned int cpu, + const char *cache, + const char *file, + virBitmapPtr *value) +{ +char *path = NULL; +int ret = -1; + +if (virAsprintf(&path, "%s/cpu/cpu%u/cache/%s/%s", +sysfs_system_path, cpu, cache, file) < 0) +return -1; + +ret = virFileReadValueBitmap(path, VIR_SYSFS_VALUE_MAXLEN, value); +VIR_FREE(path); +return ret; +} + + +/* + * Per-NUMA node getters + */ int virSysfsGetNodeValueString(unsigned int node, const char *file, diff --git a/src/util/virsysfs.h b/src/util/virsysfs.h index 25bd100ea9cb..92f9111b069f 100644 --- a/src/util/virsysfs.h +++ b/src/util/virsysfs.h @@ -77,6 +77,40 @@ virSysfsCpuDirOpen(unsigned int cpu, /* + * Per-CPU/cache getters + */ +int +virSysfsGetCpuCacheValueInt(unsigned int cpu, +const char *cache, +const char *file, +int *value); + +int +virSysfsGetCpuCacheValueUint(unsigned int cpu, + const char *cache, + const char *file, + unsigned int *value); + +int +virSysfsGetCpuCacheValueScaledInt(unsigned int cpu, + const char *cache, + const char *file, + unsigned long long *value); + +int +virSysfsGetCpuCacheValueString(unsigned int cpu, + const char *cache, + const char *file, + char **value); + +int +virSysfsGetCpuCacheValueBitmap(unsigned int cpu, + const char *cache, + const char *file, + virBitmapPtr *value); + + +/* * Per-NUMA node getters */ int -- 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list