]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs/resctrl: Add boiler plate for external resctrl code
authorJames Morse <james.morse@arm.com>
Thu, 15 May 2025 16:58:45 +0000 (16:58 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Fri, 16 May 2025 09:05:40 +0000 (11:05 +0200)
Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL
for the common parts of the resctrl interface and make X86_CPU_RESCTRL
select this.

Adding an include of asm/resctrl.h to linux/resctrl.h allows the
/fs/resctrl files to switch over to using this header instead.

Co-developed-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: Dave Martin <Dave.Martin@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Tested-by: Fenghua Yu <fenghuay@nvidia.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64
Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64
Tested-by: Babu Moger <babu.moger@amd.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/20250515165855.31452-16-james.morse@arm.com
19 files changed:
MAINTAINERS
arch/Kconfig
arch/x86/Kconfig
arch/x86/kernel/cpu/resctrl/internal.h
arch/x86/kernel/cpu/resctrl/monitor.c
arch/x86/kernel/cpu/resctrl/pseudo_lock.c
arch/x86/kernel/cpu/resctrl/rdtgroup.c
fs/Kconfig
fs/Makefile
fs/resctrl/Kconfig [new file with mode: 0644]
fs/resctrl/Makefile [new file with mode: 0644]
fs/resctrl/ctrlmondata.c [new file with mode: 0644]
fs/resctrl/internal.h [new file with mode: 0644]
fs/resctrl/monitor.c [new file with mode: 0644]
fs/resctrl/monitor_trace.h [new file with mode: 0644]
fs/resctrl/pseudo_lock.c [new file with mode: 0644]
fs/resctrl/pseudo_lock_trace.h [new file with mode: 0644]
fs/resctrl/rdtgroup.c [new file with mode: 0644]
include/linux/resctrl.h

index f21f1dabb5fe1d31fca1a558473d92b90027088c..ed96cc7ad66258ef541b5252287e5afc33072035 100644 (file)
@@ -20427,6 +20427,7 @@ S:      Supported
 F:     Documentation/arch/x86/resctrl*
 F:     arch/x86/include/asm/resctrl.h
 F:     arch/x86/kernel/cpu/resctrl/
+F:     fs/resctrl/
 F:     include/linux/resctrl*.h
 F:     tools/testing/selftests/resctrl/
 
index b0adb665041f17c89187ec4bbc76482309facb93..a3308a220f86413085cdd101611b689078b998be 100644 (file)
@@ -1518,6 +1518,14 @@ config STRICT_MODULE_RWX
 config ARCH_HAS_PHYS_TO_DMA
        bool
 
+config ARCH_HAS_CPU_RESCTRL
+       bool
+       help
+         An architecture selects this option to indicate that the necessary
+         hooks are provided to support the common memory system usage
+         monitoring and control interfaces provided by the 'resctrl'
+         filesystem (see RESCTRL_FS).
+
 config HAVE_ARCH_COMPILER_H
        bool
        help
index 5873c9e39919cb7b588f803287511e3ff7c57f75..52cfb69c343f103f7608fe3f46a16a9f3d5834c1 100644 (file)
@@ -507,8 +507,9 @@ config X86_MPPARSE
 config X86_CPU_RESCTRL
        bool "x86 CPU resource control support"
        depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
-       select KERNFS
-       select PROC_CPU_RESCTRL         if PROC_FS
+       depends on MISC_FILESYSTEMS
+       select ARCH_HAS_CPU_RESCTRL
+       select RESCTRL_FS
        select RESCTRL_FS_PSEUDO_LOCK
        help
          Enable x86 CPU resource control support.
@@ -526,12 +527,6 @@ config X86_CPU_RESCTRL
 
          Say N if unsure.
 
-config RESCTRL_FS_PSEUDO_LOCK
-       bool
-       help
-         Software mechanism to pin data in a cache portion using
-         micro-architecture specific knowledge.
-
 config X86_FRED
        bool "Flexible Return and Event Delivery"
        depends on X86_64
index 01cb0ff89c8557a0f7bc6a7a0460796e7c22bccf..348895d3b4b8b9e5452a44e7368efe0df6b599b8 100644 (file)
@@ -9,8 +9,6 @@
 #include <linux/jump_label.h>
 #include <linux/tick.h>
 
-#include <asm/resctrl.h>
-
 #define L3_QOS_CDP_ENABLE              0x01ULL
 
 #define L2_QOS_CDP_ENABLE              0x01ULL
index ac1cec61829c2bfc18d5041406219d33d5944df3..8847c23e9ac164950c6f030e590af4b2c671cda4 100644 (file)
 
 #include <linux/cpu.h>
 #include <linux/module.h>
+#include <linux/resctrl.h>
 #include <linux/sizes.h>
 #include <linux/slab.h>
 
 #include <asm/cpu_device_id.h>
-#include <asm/resctrl.h>
 
 #include "internal.h"
 
index f7bb586a83f9e8c960f0dfa9baf03ce3f25213f2..db0b75b45fe4b19f80f11062bbbe8a349d706343 100644 (file)
 #include <linux/mman.h>
 #include <linux/perf_event.h>
 #include <linux/pm_qos.h>
+#include <linux/resctrl.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 
 #include <asm/cacheflush.h>
 #include <asm/cpu_device_id.h>
-#include <asm/resctrl.h>
 #include <asm/perf_event.h>
 
 #include "../../events/perf_event.h" /* For X86_CONFIG() */
index d48078410d771649ca4b6f92eb847d5f7cbcbe6b..3a4a0bb70f6a5e3e2ad3ac0250feb340513e35be 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/fs_parser.h>
 #include <linux/sysfs.h>
 #include <linux/kernfs.h>
+#include <linux/resctrl.h>
 #include <linux/seq_buf.h>
 #include <linux/seq_file.h>
 #include <linux/sched/signal.h>
@@ -28,7 +29,6 @@
 
 #include <uapi/linux/magic.h>
 
-#include <asm/resctrl.h>
 #include "internal.h"
 
 DEFINE_STATIC_KEY_FALSE(rdt_enable_key);
index 5b4847bd2fbb57d1a07e60fc0a01519fa2390120..44b6cdd36dc168409ee4b76187140aeb21f60c33 100644 (file)
@@ -335,6 +335,7 @@ source "fs/omfs/Kconfig"
 source "fs/hpfs/Kconfig"
 source "fs/qnx4/Kconfig"
 source "fs/qnx6/Kconfig"
+source "fs/resctrl/Kconfig"
 source "fs/romfs/Kconfig"
 source "fs/pstore/Kconfig"
 source "fs/ufs/Kconfig"
index 77fd7f7b5d02478621f06304e447cc4a387a7167..79c08b914c4748d4be50f6ce91504a749008c10e 100644 (file)
@@ -128,3 +128,4 @@ obj-$(CONFIG_EROFS_FS)              += erofs/
 obj-$(CONFIG_VBOXSF_FS)                += vboxsf/
 obj-$(CONFIG_ZONEFS_FS)                += zonefs/
 obj-$(CONFIG_BPF_LSM)          += bpf_fs_kfuncs.o
+obj-$(CONFIG_RESCTRL_FS)       += resctrl/
diff --git a/fs/resctrl/Kconfig b/fs/resctrl/Kconfig
new file mode 100644 (file)
index 0000000..478a8e2
--- /dev/null
@@ -0,0 +1,39 @@
+config RESCTRL_FS
+       bool "CPU Resource Control Filesystem (resctrl)"
+       depends on ARCH_HAS_CPU_RESCTRL
+       select KERNFS
+       select PROC_CPU_RESCTRL if PROC_FS
+       help
+         Some architectures provide hardware facilities to group tasks and
+         monitor and control their usage of memory system resources such as
+         caches and memory bandwidth.  Examples of such facilities include
+         Intel's Resource Director Technology (Intel(R) RDT) and AMD's
+         Platform Quality of Service (AMD QoS).
+
+         If your system has the necessary support and you want to be able to
+         assign tasks to groups and manipulate the associated resource
+         monitors and controls from userspace, say Y here to get a mountable
+         'resctrl' filesystem that lets you do just that.
+
+         If nothing mounts or prods the 'resctrl' filesystem, resource
+         controls and monitors are left in a quiescent, permissive state.
+
+         On architectures where this can be disabled independently, it is
+         safe to say N.
+
+         See <file:Documentation/arch/x86/resctrl.rst> for more information.
+
+config RESCTRL_FS_PSEUDO_LOCK
+       bool
+       depends on RESCTRL_FS
+       help
+         Software mechanism to pin data in a cache portion using
+         micro-architecture specific knowledge.
+
+config RESCTRL_RMID_DEPENDS_ON_CLOSID
+       bool
+       depends on RESCTRL_FS
+       help
+         Enabled by the architecture when the RMID values depend on the CLOSID.
+         This causes the CLOSID allocator to search for CLOSID with clean
+         RMID.
diff --git a/fs/resctrl/Makefile b/fs/resctrl/Makefile
new file mode 100644 (file)
index 0000000..e67f34d
--- /dev/null
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_RESCTRL_FS)               += rdtgroup.o ctrlmondata.o monitor.o
+obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK)   += pseudo_lock.o
+
+# To allow define_trace.h's recursive include:
+CFLAGS_monitor.o = -I$(src)
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fs/resctrl/monitor_trace.h b/fs/resctrl/monitor_trace.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fs/resctrl/pseudo_lock_trace.h b/fs/resctrl/pseudo_lock_trace.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
new file mode 100644 (file)
index 0000000..e69de29
index b8f8240050b42df1d0aa1d366b883eff5a05313e..5c7c8bf2c47f9e11047a6a553043d25a29d8c64f 100644 (file)
@@ -8,6 +8,10 @@
 #include <linux/pid.h>
 #include <linux/resctrl_types.h>
 
+#ifdef CONFIG_ARCH_HAS_CPU_RESCTRL
+#include <asm/resctrl.h>
+#endif
+
 /* CLOSID, RMID value used by the default control group */
 #define RESCTRL_RESERVED_CLOSID                0
 #define RESCTRL_RESERVED_RMID          0