aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Luck <tony.luck@intel.com>2023-09-06 15:44:57 -0700
committerTony Luck <tony.luck@intel.com>2023-09-12 13:27:23 -0700
commit58ab1450e4ed6c385cfc36cc46b6b282e9b6a558 (patch)
tree2ec6318e1b0b38958af2e6521560480675b90ee4
parent5ff625811e6f91ddc82283afe404647895164000 (diff)
downloadlinux-58ab1450e4ed6c385cfc36cc46b6b282e9b6a558.tar.gz
resctrl2: Add resource register()/unregister()
Export functions from core code so that modules can register and unregister themcelves. Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r--fs/resctrl2/Makefile1
-rw-r--r--fs/resctrl2/internal.h1
-rw-r--r--fs/resctrl2/resources.c32
-rw-r--r--include/linux/resctrl.h16
4 files changed, 50 insertions, 0 deletions
diff --git a/fs/resctrl2/Makefile b/fs/resctrl2/Makefile
index 6d514173570de8..98d6c94f0aec43 100644
--- a/fs/resctrl2/Makefile
+++ b/fs/resctrl2/Makefile
@@ -5,6 +5,7 @@ ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE=RESCTRL
ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE=RESCTRL
obj-$(CONFIG_RESCTRL2_FS) += locking.o
+obj-$(CONFIG_RESCTRL2_FS) += resources.o
obj-$(CONFIG_RESCTRL2_FS) += root.o
obj-$(CONFIG_X86_CPU_RESCTRL2) += arch/x86/
diff --git a/fs/resctrl2/internal.h b/fs/resctrl2/internal.h
index a62228cb385148..c8a85d1668a8ee 100644
--- a/fs/resctrl2/internal.h
+++ b/fs/resctrl2/internal.h
@@ -3,6 +3,7 @@
#include <linux/cpu.h>
#include <linux/kernfs.h>
+#include <linux/resctrl.h>
struct resctrl_node_info {
struct kernfs_node *kn;
diff --git a/fs/resctrl2/resources.c b/fs/resctrl2/resources.c
new file mode 100644
index 00000000000000..d056d9a6d0312b
--- /dev/null
+++ b/fs/resctrl2/resources.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright(c) 2023 Intel Corporation. */
+
+#include "internal.h"
+
+LIST_HEAD(resctrl_all_resources);
+
+int resctrl_register_resource(struct resctrl_resource *r)
+{
+ cpus_read_lock();
+ mutex_lock(&resctrl_mutex);
+
+ list_add(&r->list, &resctrl_all_resources);
+
+ mutex_unlock(&resctrl_mutex);
+ cpus_read_unlock();
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(resctrl_register_resource);
+
+void resctrl_unregister_resource(struct resctrl_resource *r)
+{
+ cpus_read_lock();
+ mutex_lock(&resctrl_mutex);
+
+ list_del(&r->list);
+
+ mutex_unlock(&resctrl_mutex);
+ cpus_read_unlock();
+}
+EXPORT_SYMBOL_GPL(resctrl_unregister_resource);
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 8334eeacfec525..1fd62fa1665cef 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -2,6 +2,8 @@
#ifndef _RESCTRL_H
#define _RESCTRL_H
+#ifdef CONFIG_X86_CPU_RESCTRL
+
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/pid.h>
@@ -264,4 +266,18 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain *d);
extern unsigned int resctrl_rmid_realloc_threshold;
extern unsigned int resctrl_rmid_realloc_limit;
+#endif /* CONFIG_X86_CPU_RESCTRL */
+
+#ifdef CONFIG_RESCTRL2_FS
+
+struct resctrl_resource {
+ char *name;
+ struct list_head list;
+};
+
+int resctrl_register_resource(struct resctrl_resource *r);
+void resctrl_unregister_resource(struct resctrl_resource *r);
+
+#endif /* CONFIG_RESCTRL2_FS */
+
#endif /* _RESCTRL_H */