Re: [libvirt] [v7 01/10] Resctrl: Add some utils functions

2017-02-21 Thread Eli Qiao


--  
Best regards  
Eli

天涯无处不重逢
a leaf duckweed belongs to the sea, where not to meet in life  

Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Friday, 17 February 2017 at 8:47 PM, Martin Kletzander wrote:

> On Thu, Feb 16, 2017 at 06:03:50PM +0100, Martin Kletzander wrote:
> > On Thu, Feb 16, 2017 at 05:35:12PM +0800, Eli Qiao wrote:
> > > This patch adds some utils struct and functions to expose resctrl
> > > information.
> > >  
> >  
> >  
> > One tiny nitpick, but it might actually help you as well. You can use
> > -v7 parameter to git send-email or git format-patch to automatically add
> > 'v7' to the subject-prefix keeping the "PATCH" in there. Not only could
> > this be easier for you, but people like me, who filter patches and other
> > mails on the list to different folders, would have these properly
> > categorized.
> >  
> > Anyway, for the review now.
> >  
> > > virResCtrlAvailable: If resctrl interface exist on host
> > > virResCtrlGet: get specify type resource contral information
> > >  
> >  
> >  
> > "get specific resource control information" ???
> >  
> > > virResCtrlInit: initialize resctrl struct from the host's sys fs.
> > > resctrlall[]: an array to maintain resource control information.
> > >  
> > > Signed-off-by: Eli Qiao  > > (mailto:liyong.q...@intel.com)>
> > > ---
> > > include/libvirt/virterror.h | 1 +
> > > po/POTFILES.in (http://POTFILES.in) | 1 +
> > > src/Makefile.am (http://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/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 
> > >  
> >  
> >  
> > What do you need syscall.h for?
> >  
> > > +#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"
> > > +
> > >  
> >  
> >  
> > If you need SYSFS_..._PATH for anything, it probably could be split into
> > other src/util/ files. Example below.
> >  
> > > +#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;
> > > + char *tmp;
> > > + char *path;
> > > +
> > > + if (virAsprintf(, "%s/%s/%s", RESCTRL_INFO_DIR, 
> > > resctrlall[type].name, item) < 0)
> > > + return -1;
> > > + if (virFileReadAll(path, 10, str) < 0) {
> > > + ret = -1;
> > > + goto cleanup;
> > > + }
> > > +
> > > + if ((tmp = strchr(*str, '\n'))) *tmp = '\0';
> > > +
> > > + cleanup:
> > > + VIR_FREE(path);
> > > + return ret;
> > > +}
> > > +
> > > +
> > > +static int 

Re: [libvirt] [v7 01/10] Resctrl: Add some utils functions

2017-02-21 Thread Eli Qiao


--  
Best regards  
Eli

天涯无处不重逢
a leaf duckweed belongs to the sea, where not to meet in life  

Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Friday, 17 February 2017 at 1:03 AM, Martin Kletzander wrote:

> On Thu, Feb 16, 2017 at 05:35:12PM +0800, Eli Qiao wrote:
> > This patch adds some utils struct and functions to expose resctrl
> > information.
> >  
>  
>  
> One tiny nitpick, but it might actually help you as well. You can use
> -v7 parameter to git send-email or git format-patch to automatically add
> 'v7' to the subject-prefix keeping the "PATCH" in there. Not only could
> this be easier for you, but people like me, who filter patches and other
> mails on the list to different folders, would have these properly
> categorized.
>  
> Anyway, for the review now.

Thx  
>  
> > virResCtrlAvailable: If resctrl interface exist on host
> > virResCtrlGet: get specify type resource contral information
> >  
>  
>  
> "get specific resource control information" ???

Yep  
>  
> > virResCtrlInit: initialize resctrl struct from the host's sys fs.
> > resctrlall[]: an array to maintain resource control information.
> >  
> > Signed-off-by: Eli Qiao  > (mailto:liyong.q...@intel.com)>
> > ---
> > include/libvirt/virterror.h | 1 +
> > po/POTFILES.in (http://POTFILES.in) | 1 +
> > src/Makefile.am (http://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/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 
> >  
>  
>  
> What do you need syscall.h for?
Removed
  
>  
> > +#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"
> > +
> >  
>  
>  
> If you need SYSFS_..._PATH for anything, it probably could be split into
> other src/util/ files. Example below.
>  
> > +#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;
> > + char *tmp;
> > + char *path;
> > +
> > + if (virAsprintf(, "%s/%s/%s", RESCTRL_INFO_DIR, 
> > resctrlall[type].name, item) < 0)
> > + return -1;
> > + if (virFileReadAll(path, 10, str) < 0) {
> > + ret = -1;
> > + goto cleanup;
> > + }
> > +
> > + if ((tmp = strchr(*str, '\n'))) *tmp = '\0';
> > +
> > + cleanup:
> > + VIR_FREE(path);
> > + return ret;
> > +}
> > +
> > +
> > +static int virResCtrlGetCPUValue(const char *path, char **value)
> >  
>  
>  
> It would be more consistent if you reused parts of virHostCPUGetValue(),
> put them in a function, and use that one in both this one an the
> original one. It chould be also put in the virhostcpu.c since that's
> about the host cpu.
>  
Done  
> > +static int 

Re: [libvirt] [v7 01/10] Resctrl: Add some utils functions

2017-02-17 Thread Martin Kletzander

On Thu, Feb 16, 2017 at 06:03:50PM +0100, Martin Kletzander wrote:

On Thu, Feb 16, 2017 at 05:35:12PM +0800, Eli Qiao wrote:

This patch adds some utils struct and functions to expose resctrl
information.



One tiny nitpick, but it might actually help you as well.  You can use
-v7 parameter to git send-email or git format-patch to automatically add
'v7' to the subject-prefix keeping the "PATCH" in there.  Not only could
this be easier for you, but people like me, who filter patches and other
mails on the list to different folders, would have these properly
categorized.

Anyway, for the review now.


virResCtrlAvailable: If resctrl interface exist on host
virResCtrlGet: get specify type resource contral information


"get specific resource control 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/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 


What do you need syscall.h for?


+#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"
+


If you need SYSFS_..._PATH for anything, it probably could be split into
other src/util/ files.  Example below.


+#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;
+char *tmp;
+char *path;
+
+if (virAsprintf(, "%s/%s/%s", RESCTRL_INFO_DIR, resctrlall[type].name, 
item) < 0)
+return -1;
+if (virFileReadAll(path, 10, str) < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if ((tmp = strchr(*str, '\n'))) *tmp = '\0';
+
+ cleanup:
+VIR_FREE(path);
+return ret;
+}
+
+
+static int virResCtrlGetCPUValue(const char *path, char **value)


It would be more consistent if you reused parts of virHostCPUGetValue(),
put them in a function, and use that one in both this one an the
original one.  It chould be also put in the virhostcpu.c since that's
about the host cpu.


+static int virResctrlGetCPUSocketID(const size_t cpu, int *socket_id)


No need for this function, just use virHostCPUParseSocket()


+static int virResCtrlGetCPUCache(const size_t cpu, int type, int *cache)


So we have some places in the code that get info from sysfs.  I
understand that cache is controlled in the resctrl, but one doesn't have
to have resctrl to get some cache info, so I would move this function
into virhostcpu.c and keep here only the stuff strictly related to
resource control.


+{
+int ret = -1;
+char *cache_dir = NULL;
+char *cache_str = NULL;
+char *tmp;
+int carry = -1;
+
+if (virAsprintf(_dir,
+"%s/cpu/cpu%zu/cache/index%d/size",
+

Re: [libvirt] [v7 01/10] Resctrl: Add some utils functions

2017-02-16 Thread Martin Kletzander

On Thu, Feb 16, 2017 at 05:35:12PM +0800, Eli Qiao wrote:

This patch adds some utils struct and functions to expose resctrl
information.



One tiny nitpick, but it might actually help you as well.  You can use
-v7 parameter to git send-email or git format-patch to automatically add
'v7' to the subject-prefix keeping the "PATCH" in there.  Not only could
this be easier for you, but people like me, who filter patches and other
mails on the list to different folders, would have these properly
categorized.

Anyway, for the review now.


virResCtrlAvailable: If resctrl interface exist on host
virResCtrlGet: get specify type resource contral information


"get specific resource control 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/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 


What do you need syscall.h for?


+#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"
+


If you need SYSFS_..._PATH for anything, it probably could be split into
other src/util/ files.  Example below.


+#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;
+char *tmp;
+char *path;
+
+if (virAsprintf(, "%s/%s/%s", RESCTRL_INFO_DIR, resctrlall[type].name, 
item) < 0)
+return -1;
+if (virFileReadAll(path, 10, str) < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if ((tmp = strchr(*str, '\n'))) *tmp = '\0';
+
+ cleanup:
+VIR_FREE(path);
+return ret;
+}
+
+
+static int virResCtrlGetCPUValue(const char *path, char **value)


It would be more consistent if you reused parts of virHostCPUGetValue(),
put them in a function, and use that one in both this one an the
original one.  It chould be also put in the virhostcpu.c since that's
about the host cpu.


+static int virResctrlGetCPUSocketID(const size_t cpu, int *socket_id)


No need for this function, just use virHostCPUParseSocket()


+static int virResCtrlGetCPUCache(const size_t cpu, int type, int *cache)


So we have some places in the code that get info from sysfs.  I
understand that cache is controlled in the resctrl, but one doesn't have
to have resctrl to get some cache info, so I would move this function
into virhostcpu.c and keep here only the stuff strictly related to
resource control.


+{
+int ret = -1;
+char *cache_dir = NULL;
+char *cache_str = NULL;
+char *tmp;
+int carry = -1;
+
+if (virAsprintf(_dir,
+"%s/cpu/cpu%zu/cache/index%d/size",
+SYSFS_SYSTEM_PATH, cpu, type) < 0)
+return -1;
+
+if 

[libvirt] [v7 01/10] Resctrl: Add some utils functions

2017-02-16 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..0ba15e6 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",
+  "Resouce 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,