[tip:x86/cache] x86/intel_rdt: Add basic resctrl filesystem support

2016-10-30 Thread tip-bot for Fenghua Yu
Commit-ID:  5ff193fbde20df5d80fec367cea3e7856c057320
Gitweb: http://git.kernel.org/tip/5ff193fbde20df5d80fec367cea3e7856c057320
Author: Fenghua Yu 
AuthorDate: Fri, 28 Oct 2016 15:04:42 -0700
Committer:  Thomas Gleixner 
CommitDate: Sun, 30 Oct 2016 19:10:14 -0600

x86/intel_rdt: Add basic resctrl filesystem support

Use kernfs as basis for our user interface filesystem. This patch
supports mount/umount, and one mount parameter "cdp" to enable code/data
prioritization (though all we do at this point is ensure that the system
can support CDP).  The file system is not populated yet in this patch.

[ tglx: Fixed up a few nits and added cdp handling in case of error ]

Signed-off-by: Fenghua Yu 
Cc: "Ravi V Shankar" 
Cc: "Tony Luck" 
Cc: "Shaohua Li" 
Cc: "Sai Prakhya" 
Cc: "Peter Zijlstra" 
Cc: "Stephane Eranian" 
Cc: "Dave Hansen" 
Cc: "David Carrillo-Cisneros" 
Cc: "Nilay Vaish" 
Cc: "Vikas Shivappa" 
Cc: "Ingo Molnar" 
Cc: "Borislav Petkov" 
Cc: "H. Peter Anvin" 
Link: 
http://lkml.kernel.org/r/1477692289-37412-4-git-send-email-fenghua...@intel.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/include/asm/intel_rdt.h |  26 +++
 arch/x86/kernel/cpu/Makefile |   2 +-
 arch/x86/kernel/cpu/intel_rdt.c  |   8 +-
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 271 +++
 include/uapi/linux/magic.h   |   1 +
 5 files changed, 306 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/intel_rdt.h b/arch/x86/include/asm/intel_rdt.h
index c0d0a6e..09d00e6 100644
--- a/arch/x86/include/asm/intel_rdt.h
+++ b/arch/x86/include/asm/intel_rdt.h
@@ -1,9 +1,31 @@
 #ifndef _ASM_X86_INTEL_RDT_H
 #define _ASM_X86_INTEL_RDT_H
 
+#include 
+
+#define IA32_L3_QOS_CFG0xc81
 #define IA32_L3_CBM_BASE   0xc90
 #define IA32_L2_CBM_BASE   0xd10
 
+#define L3_QOS_CDP_ENABLE  0x01ULL
+
+/**
+ * struct rdtgroup - store rdtgroup's data in resctrl file system.
+ * @kn:kernfs node
+ * @rdtgroup_list: linked list for all rdtgroups
+ * @closid:closid for this rdtgroup
+ */
+struct rdtgroup {
+   struct kernfs_node  *kn;
+   struct list_headrdtgroup_list;
+   int closid;
+};
+
+/* List of all resource groups */
+extern struct list_head rdt_all_groups;
+
+int __init rdtgroup_init(void);
+
 /**
  * struct rdt_resource - attributes of an RDT resource
  * @enabled:   Is this feature enabled on this machine
@@ -68,6 +90,10 @@ struct msr_param {
 extern struct mutex rdtgroup_mutex;
 
 extern struct rdt_resource rdt_resources_all[];
+extern struct rdtgroup rdtgroup_default;
+DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
+
+int __init rdtgroup_init(void);
 
 enum {
RDT_RESOURCE_L3,
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index cf4bfd0..b4334e8 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -34,7 +34,7 @@ obj-$(CONFIG_CPU_SUP_CENTAUR) += centaur.o
 obj-$(CONFIG_CPU_SUP_TRANSMETA_32) += transmeta.o
 obj-$(CONFIG_CPU_SUP_UMC_32)   += umc.o
 
-obj-$(CONFIG_INTEL_RDT_A)  += intel_rdt.o
+obj-$(CONFIG_INTEL_RDT_A)  += intel_rdt.o intel_rdt_rdtgroup.o
 
 obj-$(CONFIG_X86_MCE)  += mcheck/
 obj-$(CONFIG_MTRR) += mtrr/
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index 3d4b397..9d95414 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -361,7 +361,7 @@ static int intel_rdt_offline_cpu(unsigned int cpu)
 static int __init intel_rdt_late_init(void)
 {
struct rdt_resource *r;
-   int state;
+   int state, ret;
 
if (!get_rdt_resources())
return -ENODEV;
@@ -372,6 +372,12 @@ static int __init intel_rdt_late_init(void)
if (state < 0)
return state;
 
+   ret = rdtgroup_init();
+   if (ret) {
+   cpuhp_remove_state(state);
+   return ret;
+   }
+
for_each_capable_rdt_resource(r)
pr_info("Intel RDT %s allocation detected\n", r->name);
 
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c 
b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
new file mode 100644
index 000..106e4ce
--- /dev/null
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -0,0 +1,271 @@
+/*
+ * User interface for Resource Alloction in Resource Director Technology(RDT)
+ *
+ * Copyright (C) 2016 Intel Corporation
+ *
+ * Author: Fenghua Yu 
+ *
+ * This program is free 

[tip:x86/cache] x86/intel_rdt: Add basic resctrl filesystem support

2016-10-30 Thread tip-bot for Fenghua Yu
Commit-ID:  5ff193fbde20df5d80fec367cea3e7856c057320
Gitweb: http://git.kernel.org/tip/5ff193fbde20df5d80fec367cea3e7856c057320
Author: Fenghua Yu 
AuthorDate: Fri, 28 Oct 2016 15:04:42 -0700
Committer:  Thomas Gleixner 
CommitDate: Sun, 30 Oct 2016 19:10:14 -0600

x86/intel_rdt: Add basic resctrl filesystem support

Use kernfs as basis for our user interface filesystem. This patch
supports mount/umount, and one mount parameter "cdp" to enable code/data
prioritization (though all we do at this point is ensure that the system
can support CDP).  The file system is not populated yet in this patch.

[ tglx: Fixed up a few nits and added cdp handling in case of error ]

Signed-off-by: Fenghua Yu 
Cc: "Ravi V Shankar" 
Cc: "Tony Luck" 
Cc: "Shaohua Li" 
Cc: "Sai Prakhya" 
Cc: "Peter Zijlstra" 
Cc: "Stephane Eranian" 
Cc: "Dave Hansen" 
Cc: "David Carrillo-Cisneros" 
Cc: "Nilay Vaish" 
Cc: "Vikas Shivappa" 
Cc: "Ingo Molnar" 
Cc: "Borislav Petkov" 
Cc: "H. Peter Anvin" 
Link: 
http://lkml.kernel.org/r/1477692289-37412-4-git-send-email-fenghua...@intel.com
Signed-off-by: Thomas Gleixner 

---
 arch/x86/include/asm/intel_rdt.h |  26 +++
 arch/x86/kernel/cpu/Makefile |   2 +-
 arch/x86/kernel/cpu/intel_rdt.c  |   8 +-
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 271 +++
 include/uapi/linux/magic.h   |   1 +
 5 files changed, 306 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/intel_rdt.h b/arch/x86/include/asm/intel_rdt.h
index c0d0a6e..09d00e6 100644
--- a/arch/x86/include/asm/intel_rdt.h
+++ b/arch/x86/include/asm/intel_rdt.h
@@ -1,9 +1,31 @@
 #ifndef _ASM_X86_INTEL_RDT_H
 #define _ASM_X86_INTEL_RDT_H
 
+#include 
+
+#define IA32_L3_QOS_CFG0xc81
 #define IA32_L3_CBM_BASE   0xc90
 #define IA32_L2_CBM_BASE   0xd10
 
+#define L3_QOS_CDP_ENABLE  0x01ULL
+
+/**
+ * struct rdtgroup - store rdtgroup's data in resctrl file system.
+ * @kn:kernfs node
+ * @rdtgroup_list: linked list for all rdtgroups
+ * @closid:closid for this rdtgroup
+ */
+struct rdtgroup {
+   struct kernfs_node  *kn;
+   struct list_headrdtgroup_list;
+   int closid;
+};
+
+/* List of all resource groups */
+extern struct list_head rdt_all_groups;
+
+int __init rdtgroup_init(void);
+
 /**
  * struct rdt_resource - attributes of an RDT resource
  * @enabled:   Is this feature enabled on this machine
@@ -68,6 +90,10 @@ struct msr_param {
 extern struct mutex rdtgroup_mutex;
 
 extern struct rdt_resource rdt_resources_all[];
+extern struct rdtgroup rdtgroup_default;
+DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
+
+int __init rdtgroup_init(void);
 
 enum {
RDT_RESOURCE_L3,
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index cf4bfd0..b4334e8 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -34,7 +34,7 @@ obj-$(CONFIG_CPU_SUP_CENTAUR) += centaur.o
 obj-$(CONFIG_CPU_SUP_TRANSMETA_32) += transmeta.o
 obj-$(CONFIG_CPU_SUP_UMC_32)   += umc.o
 
-obj-$(CONFIG_INTEL_RDT_A)  += intel_rdt.o
+obj-$(CONFIG_INTEL_RDT_A)  += intel_rdt.o intel_rdt_rdtgroup.o
 
 obj-$(CONFIG_X86_MCE)  += mcheck/
 obj-$(CONFIG_MTRR) += mtrr/
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index 3d4b397..9d95414 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -361,7 +361,7 @@ static int intel_rdt_offline_cpu(unsigned int cpu)
 static int __init intel_rdt_late_init(void)
 {
struct rdt_resource *r;
-   int state;
+   int state, ret;
 
if (!get_rdt_resources())
return -ENODEV;
@@ -372,6 +372,12 @@ static int __init intel_rdt_late_init(void)
if (state < 0)
return state;
 
+   ret = rdtgroup_init();
+   if (ret) {
+   cpuhp_remove_state(state);
+   return ret;
+   }
+
for_each_capable_rdt_resource(r)
pr_info("Intel RDT %s allocation detected\n", r->name);
 
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c 
b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
new file mode 100644
index 000..106e4ce
--- /dev/null
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -0,0 +1,271 @@
+/*
+ * User interface for Resource Alloction in Resource Director Technology(RDT)
+ *
+ * Copyright (C) 2016 Intel Corporation
+ *
+ * Author: Fenghua Yu 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General