[libvirt] [RFC v3 1/8] Resctrl: Add some utils functions

2017-02-08 Thread Eli Qiao
This patch adds some utils struct and functions to expose resctrl
information.

virResCtrlAvailable: If resctrl interface exist on host
virResCtrlGet: get specify type resource contral information
virResCtrlInit: initialize resctrl struct from the host's sys fs.
resctrlall[]: an array to maintain resource control information.

Signed-off-by: Eli Qiao 
---
 include/libvirt/virterror.h |   1 +
 po/POTFILES.in  |   1 +
 src/Makefile.am |   1 +
 src/libvirt_private.syms|   4 +
 src/util/virerror.c |   1 +
 src/util/virresctrl.c   | 343 
 src/util/virresctrl.h   |  80 +++
 7 files changed, 431 insertions(+)
 create mode 100644 src/util/virresctrl.c
 create mode 100644 src/util/virresctrl.h

diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 2efee8f..3dd2d08 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -132,6 +132,7 @@ typedef enum {
 
 VIR_FROM_PERF = 65, /* Error from perf */
 VIR_FROM_LIBSSH = 66,   /* Error from libssh connection transport */
+VIR_FROM_RESCTRL = 67,  /* Error from resource control */
 
 # ifdef VIR_ENUM_SENTINELS
 VIR_ERR_DOMAIN_LAST
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 365ea66..f7fda98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -240,6 +240,7 @@ src/util/virportallocator.c
 src/util/virprocess.c
 src/util/virqemu.c
 src/util/virrandom.c
+src/util/virresctrl.c
 src/util/virrotatingfile.c
 src/util/virscsi.c
 src/util/virscsivhost.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f32d41..b626f29 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -162,6 +162,7 @@ UTIL_SOURCES =  
\
util/virprocess.c util/virprocess.h \
util/virqemu.c util/virqemu.h   \
util/virrandom.h util/virrandom.c   \
+   util/virresctrl.h util/virresctrl.c \
util/virrotatingfile.h util/virrotatingfile.c   \
util/virscsi.c util/virscsi.h   \
util/virscsivhost.c util/virscsivhost.h \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8e994c7..743e5ac 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2313,6 +2313,10 @@ virRandomGenerateWWN;
 virRandomInt;
 
 
+# util/virresctrl.h
+virResCtrlAvailable;
+virResCtrlInit;
+
 # util/virrotatingfile.h
 virRotatingFileReaderConsume;
 virRotatingFileReaderFree;
diff --git a/src/util/virerror.c b/src/util/virerror.c
index ef17fb5..93dfd4f 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -139,6 +139,7 @@ VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST,
 
   "Perf", /* 65 */
   "Libssh transport layer",
+  "Rescouce Control",
 )
 
 
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
new file mode 100644
index 000..80481bc
--- /dev/null
+++ b/src/util/virresctrl.c
@@ -0,0 +1,343 @@
+/*
+ * virresctrl.c: methods for managing resource contral
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ *
+ * Authors:
+ *  Eli Qiao 
+ */
+#include 
+
+#include 
+#if defined HAVE_SYS_SYSCALL_H
+# include 
+#endif
+#include 
+#include 
+#include 
+
+#include "virresctrl.h"
+#include "viralloc.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virhostcpu.h"
+#include "virlog.h"
+#include "virstring.h"
+#include "nodeinfo.h"
+
+VIR_LOG_INIT("util.resctrl");
+
+#define VIR_FROM_THIS VIR_FROM_RESCTRL
+
+#define RESCTRL_DIR "/sys/fs/resctrl"
+#define RESCTRL_INFO_DIR "/sys/fs/resctrl/info"
+#define SYSFS_SYSTEM_PATH "/sys/devices/system"
+
+#define MAX_CPU_SOCKET_NUM 8
+#define MAX_CBM_BIT_LEN 32
+#define MAX_SCHEMATA_LEN 1024
+#define MAX_FILE_LEN ( 10 * 1024 * 1024)
+
+
+static unsigned int host_id;
+
+static virResCtrl resctrlall[] = {
+{
+.name = "L3",
+.cache_level = "l3",
+},
+{
+.name = "L3DATA",
+.cache_level = "l3",
+},
+{
+.name = "L3CODE",
+.cache_level = "l3",
+},
+{
+.name = "L2",
+.cache_level = "l2",
+},
+};
+
+static int virResCtrlGetInfoStr(const int type, const char *item, char **str)
+{
+int ret = 0;

Re: [libvirt] [RFC v3 1/8] Resctrl: Add some utils functions

2017-02-10 Thread Marcelo Tosatti
On Thu, Feb 09, 2017 at 03:43:02PM +0800, Eli Qiao wrote:
> This patch adds some utils struct and functions to expose resctrl
> information.
> 
> virResCtrlAvailable: If resctrl interface exist on host
> virResCtrlGet: get specify type resource contral information
> virResCtrlInit: initialize resctrl struct from the host's sys fs.
> resctrlall[]: an array to maintain resource control information.
> 
> Signed-off-by: Eli Qiao 
> ---
>  include/libvirt/virterror.h |   1 +
>  po/POTFILES.in  |   1 +
>  src/Makefile.am |   1 +
>  src/libvirt_private.syms|   4 +
>  src/util/virerror.c |   1 +
>  src/util/virresctrl.c   | 343 
> 
>  src/util/virresctrl.h   |  80 +++
>  7 files changed, 431 insertions(+)
>  create mode 100644 src/util/virresctrl.c
>  create mode 100644 src/util/virresctrl.h
> 
> diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
> index 2efee8f..3dd2d08 100644
> --- a/include/libvirt/virterror.h
> +++ b/include/libvirt/virterror.h
> @@ -132,6 +132,7 @@ typedef enum {
>  
>  VIR_FROM_PERF = 65, /* Error from perf */
>  VIR_FROM_LIBSSH = 66,   /* Error from libssh connection transport */
> +VIR_FROM_RESCTRL = 67,  /* Error from resource control */
>  
>  # ifdef VIR_ENUM_SENTINELS
>  VIR_ERR_DOMAIN_LAST
> diff --git a/po/POTFILES.in b/po/POTFILES.in
> index 365ea66..f7fda98 100644
> --- a/po/POTFILES.in
> +++ b/po/POTFILES.in
> @@ -240,6 +240,7 @@ src/util/virportallocator.c
>  src/util/virprocess.c
>  src/util/virqemu.c
>  src/util/virrandom.c
> +src/util/virresctrl.c
>  src/util/virrotatingfile.c
>  src/util/virscsi.c
>  src/util/virscsivhost.c
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 2f32d41..b626f29 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -162,6 +162,7 @@ UTIL_SOURCES =
> \
>   util/virprocess.c util/virprocess.h \
>   util/virqemu.c util/virqemu.h   \
>   util/virrandom.h util/virrandom.c   \
> + util/virresctrl.h util/virresctrl.c \
>   util/virrotatingfile.h util/virrotatingfile.c   \
>   util/virscsi.c util/virscsi.h   \
>   util/virscsivhost.c util/virscsivhost.h \
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 8e994c7..743e5ac 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -2313,6 +2313,10 @@ virRandomGenerateWWN;
>  virRandomInt;
>  
>  
> +# util/virresctrl.h
> +virResCtrlAvailable;
> +virResCtrlInit;
> +
>  # util/virrotatingfile.h
>  virRotatingFileReaderConsume;
>  virRotatingFileReaderFree;
> diff --git a/src/util/virerror.c b/src/util/virerror.c
> index ef17fb5..93dfd4f 100644
> --- a/src/util/virerror.c
> +++ b/src/util/virerror.c
> @@ -139,6 +139,7 @@ VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST,
>  
>"Perf", /* 65 */
>"Libssh transport layer",
> +  "Rescouce Control",

Typo: Resource Control

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