[libvirt] [RFC] RFC: Reimplement cache allocation for a VM

Eli Qiao posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1491902899-38727-1-git-send-email-liyong.qiao@intel.com
There is a newer version of this series
src/util/virresctrl.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
src/util/virresctrl.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 167 insertions(+)
create mode 100644 src/util/virresctrl.c
create mode 100644 src/util/virresctrl.h
[libvirt] [RFC] RFC: Reimplement cache allocation for a VM
Posted by Eli Qiao 7 years ago
This is a RFC patch for the reimplement of `support cache tune(CAT) in
libvirt`[1].

There are already patch sets[2] to address it, and functional
works, but people doesn't like it cause it has global variable, and
missing unit test case for new added capabilites, etc.

Martin has proposed a test infra to do vircaps2xmltest, and I extened it
on top of it to extend resctrl control[3], this is kinds of new desiged
apart from [2], so I propose this RFC patch to do some rework on it.

[] https://www.redhat.com/archives/libvir-list/2017-January/msg00683.html
[] https://www.redhat.com/archives/libvir-list/2017-March/msg00181.html
[] https://www.redhat.com/archives/libvir-list/2017-April/msg00516.html
---
 src/util/virresctrl.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virresctrl.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 167 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 0000000..f555eb8
--- /dev/null
+++ b/src/util/virresctrl.c
@@ -0,0 +1,81 @@
+/*
+ * virresctrl.c: methods for managing resource control
+ *
+ * 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
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Eli Qiao <liyong.qiao@intel.com>
+ */
+
+#include <config.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "virresctrl.h"
+#include "viralloc.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virhostcpu.h"
+#include "virlog.h"
+#include "virstring.h"
+#include "virarch.h"
+
+VIR_LOG_INIT("util.resctrl");
+
+#define VIR_FROM_THIS VIR_FROM_RESCTRL
+
+VIR_ENUM_IMPL(virResctrl, VIR_RESCTRL_TYPE_LAST,
+              "L3",
+              "L3CODE",
+              "L3DATA",
+              "L2")
+
+/**
+ * a virResctrlDomain represents a resource control group, it's a directory
+ * under /sys/fs/resctrl.
+ * eg: /sys/fs/resctrl/CG1
+ * |-- cpus
+ * |-- schemata
+ * `-- tasks
+ * # cat schemata
+ * L3DATA:0=fffff;1=fffff
+ * L3CODE:0=fffff;1=fffff
+ *
+ * Besides, it can also represent the default resource control group of the
+ * host.
+ */
+
+typedef struct _virResctrlGroup virResctrlGroup;
+typedef virResctrlGroup *virResctrlGroupPtr;
+struct _virResctrlGroup {
+    char *name; /* resource group name, eg: CG1. If it represent host's
+                   default resource group name, should be a NULL pointer */
+    size_t n_tasks; /* number of task assigned to the resource group */
+    char **tasks; /* task list which contains task id eg: 77454 */
+
+    size_t n_schematas; /* number of schemata the resource group contains,
+                         eg: 2 */
+    virResctrlSchemataPtr *schematas; /* scheamta list */
+};
+
+/* All resource control groups on this host, including default resource group */
+typedef struct _virResCtrlDomain virResCtrlDomain;
+typedef virResCtrlDomain *virResCtrlDomainPtr;
+struct _virResCtrlDomain {
+    size_t n_groups; /* number of resource control group */
+    virResctrlGroupPtr groups; /* list of resource control group */
+};
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
new file mode 100644
index 0000000..da89542
--- /dev/null
+++ b/src/util/virresctrl.h
@@ -0,0 +1,86 @@
+/*
+ * virresctrl.h: header for managing resctrl control
+ *
+ * Copyright (C) 2016 Intel, Inc.
+ *
+ * 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
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Eli Qiao <liyong.qiao@intel.com>
+ */
+
+#ifndef __VIR_RESCTRL_H__
+# define __VIR_RESCTRL_H__
+
+typedef enum {
+    VIR_RESCTRL_TYPE_L3,
+    VIR_RESCTRL_TYPE_L3_CODE,
+    VIR_RESCTRL_TYPE_L3_DATA,
+    VIR_RESCTRL_TYPE_L2,
+
+    VIR_RESCTRL_TYPE_LAST
+} virResctrlType;
+
+VIR_ENUM_DECL(virResctrl);
+
+/*
+ * a virResctrlSchemataItem represents one of schemata object in a
+ * resource control group.
+ * eg: 0=f
+ */
+typedef struct _virResCtrlSchemataItem virResctrlSchemataItem;
+typedef virResctrlSchemataItem *virResctrlSchemataItemPtr;
+struct _virResctrlSchemataItem {
+    unsigned int cache_id; /* cache resource id, eg: 0 */
+    unsigned int continuous_schemata; /* schemata, should be a continuous bits,
+                                         eg: f, this schemata can be persisted
+                                         to sysfs */
+    unsigned int schemata; /* schemata eg: f0f, a schemata which is calculated
+                              at running time */
+    unsigned long long size; /* the cache size schemata represented in B,
+                              eg: (min * bits of continuous_schemata) */
+};
+
+/*
+ * a virResctrlSchemata represents schemata objects of specific type of
+ * resource in a resource control group.
+ * eg: L3:0=f,1=ff
+ */
+typedef struct _virResctrlSchemata virResctrlSchemata;
+typedef virResctrlSchemata *virResctrlSchemataPtr;
+struct _virResctrlSchemata {
+    virResctrlType type; /* resource control type, eg: L3 */
+    size_t n_schemata_items; /* number of schemata item, eg: 2 */
+    virResctrlSchemataItemPtr *schemata_items; /* pointer list of schemata item */
+};
+
+/* Get free cache of the host, result saved in schemata */
+int virResctrlGetFreeCache(virResctrlType type,
+                           virResctrlSchemataPtr *schemata);
+
+/* Get free cache of specific cache id of the host, result saved in
+   schemataitem */
+int virResctrlGetFreeCacheByCacheId(virResctrlType type,
+                                    virResctrlSchemataItemPtr *schemataitem);
+
+/* Set cache allocation for a VM domain */
+int virResctrlSetCacheBanks(virDomainCachetunePtr cachetune,
+                            unsigned char *group_name,
+                            size_t n_pids,
+                            pid_t *pids);
+
+/* remove cache allocation for a VM domain */
+int virResctrlRemoveCacheBanks(unsigned char *group_name);
+#endif
-- 
1.9.1

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