x86/resctrl: Move the resctrl filesystem code to /fs/resctrl
Subsystems (4)
James Morse
reviewerv8 cover x86/resctrl: Move the resctrl filesystem code to /fs/resctrl
Changes since v7:
* Switched to Tony's alternative for having a structure behind struct mon_data.
Changes otherwise noted on each patch.
N.B, the disk in my machine recently died - so I've re-done the feedback changes multiple times. Appologies if I missed something on the second pass!
---
Patch 1 has been posted as a fix that should get picked up independently.
Patches X-Y should be squashed together when merged - they are posted like this to allow folk to re-generate patch N, then review the differences on top. Not squashing them together would expose a ftrace build warning during bisect. (but who does that!)
That would look like this:git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/move_to_fs/v8_final
This series is based on rc1, and can be retrieved from:git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/move_to_fs/v8
This series renames functions and moves code around. With the exception of invalid configurations for the configurable-events, there should be no changes in behaviour caused by this series. It is now possible for throttle_mode to report 'undefined', but no known platform will do this.
The driving pattern is to make things like struct rdtgroup private to resctrl. Features like pseudo-lock aren't going to work on arm64, the ability to disable it at compile time is added.
After this, I can start posting the MPAM driver to make use of resctrl on arm64. (What's MPAM? See the cover letter of the first series. [1])
As ever - bugs welcome,
Thanks,
James
[v7] https://lore.kernel.org/all/[email protected]/
[v6] https://lore.kernel.org/lkml/[email protected]/
[v5] https://lore.kernel.org/r/[email protected]
[v4] https://lore.kernel.org/all/[email protected]/
[v3] https://lore.kernel.org/r/[email protected]
[v2] https://lore.kernel.org/r/[email protected]
[v1] https://lore.kernel.org/r/[email protected]
[1] https://lore.kernel.org/lkml/[email protected]/
Amit Singh Tomar (1):
x86/resctrl: Remove the limit on the number of CLOSID
Dave Martin (3):
x86/resctrl: Squelch whitespace anomalies in resctrl core code x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context() x86/resctrl: Relax some asm #includes
James Morse (17):
x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use of kernfs_node::name x86/resctrl: Rename resctrl_sched_in() to begin with "resctrl_arch_" x86/resctrl: resctrl_exit() teardown resctrl but leave the mount point x86/resctrl: Drop __init/__exit on assorted symbols x86/resctrl: Move is_mba_sc() out of core.c
x86/resctrl: Add end-marker to the resctrl_event_id enum x86/resctrl: Expand the width of dom_id by replacing mon_data_bits x86/resctrl: Remove a newline to avoid confusing the code move script x86/resctrl: Split trace.h
fs/resctrl: Add boiler plate for external resctrl code x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl x86/resctrl: Always initialise rid field in rdt_resources_all[] x86,fs/resctrl: Move the resctrl filesystem code to live in
/fs/resctrl
x86,fs/resctrl: Remove duplicated trace header files fs/resctrl: Remove unnecessary includes
fs/resctrl: Change internal.h's header guard macros x86,fs/resctrl: Move resctrl.rst to live under
Documentation/filesystems
Documentation/arch/x86/index.rst | 1 -
Documentation/filesystems/index.rst | 1 +
.../{arch/x86 => filesystems}/resctrl.rst | 0
MAINTAINERS | 3 +-
arch/Kconfig | 8 +
arch/x86/Kconfig | 11 +-
arch/x86/include/asm/resctrl.h | 7 +-
arch/x86/kernel/cpu/resctrl/Makefile | 3 +
arch/x86/kernel/cpu/resctrl/core.c | 31 +-
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 635 ---
arch/x86/kernel/cpu/resctrl/internal.h | 397 +-
arch/x86/kernel/cpu/resctrl/monitor.c | 909 +---
arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1092 +---
.../resctrl/{trace.h => pseudo_lock_trace.h} | 26 +-
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4426 +----------------
arch/x86/kernel/process_32.c | 2 +-
arch/x86/kernel/process_64.c | 2 +-
fs/Kconfig | 1 +
fs/Makefile | 1 +
fs/resctrl/Kconfig | 39 +
fs/resctrl/Makefile | 6 +
fs/resctrl/ctrlmondata.c | 660 +++
fs/resctrl/internal.h | 440 ++
fs/resctrl/monitor.c | 929 ++++
fs/resctrl/monitor_trace.h | 33 +
fs/resctrl/pseudo_lock.c | 1105 ++++
fs/resctrl/rdtgroup.c | 4311 ++++++++++++++++
include/linux/resctrl.h | 10 +-
include/linux/resctrl_types.h | 5 +
29 files changed, 7731 insertions(+), 7363 deletions(-)
rename Documentation/{arch/x86 => filesystems}/resctrl.rst (100%)
rename arch/x86/kernel/cpu/resctrl/{trace.h => pseudo_lock_trace.h} (56%)
create mode 100644 fs/resctrl/Kconfig
create mode 100644 fs/resctrl/Makefile
create mode 100644 fs/resctrl/ctrlmondata.c
create mode 100644 fs/resctrl/internal.h
create mode 100644 fs/resctrl/monitor.c
create mode 100644 fs/resctrl/monitor_trace.h
create mode 100644 fs/resctrl/pseudo_lock.c
create mode 100644 fs/resctrl/rdtgroup.cSignature · 1 line
2.20.1
James Morse
reviewerPATCH v8 1/21 x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use of kernfs_node::name
Since commit 741c10b096bc ("kernfs: Use RCU to access kernfs_node::name."), a helper rdt_kn_name() that checks that rdtgroup_mutex is held has been used for all accesses to the kernfs node name.
rdtgroup_mkdir() uses the name to determine if a valid monitor group is being created by checking the parent name is "mon_groups". This is done without holding rdtgroup_mutex, and now triggers the following warning:
| WARNING: suspicious RCU usage | 6.15.0-rc1 #4465 Tainted: G E | ----------------------------- | arch/x86/kernel/cpu/resctrl/internal.h:408 suspicious rcu_dereference_check() usage! [...] | Call Trace: | <TASK> | dump_stack_lvl+0x6c/0xa0 | lockdep_rcu_suspicious.cold+0x4e/0x96 | is_mon_groups+0xba/0xd0 | rdtgroup_mkdir+0x118/0x1970 | kernfs_iop_mkdir+0xfa/0x1a0 | vfs_mkdir+0x456/0x760 | do_mkdirat+0x257/0x310 | __x64_sys_mkdir+0xd4/0x120 | do_syscall_64+0x6d/0x150 | entry_SYSCALL_64_after_hwframe+0x76/0x7e
Creating a control or monitor group calls mkdir_rdt_prepare(), which uses rdtgroup_kn_lock_live() to take the rdtgroup_mutex.
To avoid taking and dropping the lock, move the check for the monitor group name and position into mkdir_rdt_prepare() so that it occurs under rdtgroup_mutex. Hoist is_mon_groups() earlier in the file.
---
Changes since v1:
* Add a word to a comment.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 48 +++++++++++++++----------- 1 file changed, 27 insertions(+), 21 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +27 -21
@@ -3553,6 +3553,22 @@ static void mkdir_rdt_prepare_rmid_free(struct rdtgroup *rgrp)free_rmid (rgrp->closid, rgrp->mon.rmid); } +/* +* We allow creating mon groups only with in a directory called "mon_groups" +* which is present in every ctrl_mon group. Check if this is a valid +* "mon_groups" directory. +* +* 1. The directory should be named "mon_groups". +* 2. The mon group itself should "not" be named "mon_groups". +* This makes sure "mon_groups" directory always has a ctrl_mon group +* as parent. +*/ +static bool is_mon_groups (struct kernfs_node *kn,const char *name) +{ +return (!strcmp (rdt_kn_name (kn),"mon_groups" ) && +strcmp (name,"mon_groups" )); +} +static int mkdir_rdt_prepare (struct kernfs_node *parent_kn,const char *name,umode_t mode,enum rdt_group_type rtype,struct rdtgroup **r)
@@ -3568,6 +3584,15 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, goto out_unlock; } +/* +* Check that the parent directory for a monitor group is a +* "mon_groups" directory. +*/ +if (rtype ==RDTMON_GROUP && !is_mon_groups (parent_kn, name)) { + ret = -EPERM ; + goto out_unlock; + } +if (rtype ==RDTMON_GROUP && (prdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP || prdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED )) {
@@ -3751,22 +3776,6 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,return ret; } -/* -* We allow creating mon groups only with in a directory called "mon_groups" -* which is present in every ctrl_mon group. Check if this is a valid -* "mon_groups" directory. -* -* 1. The directory should be named "mon_groups". -* 2. The mon group itself should "not" be named "mon_groups". -* This makes sure "mon_groups" directory always has a ctrl_mon group -* as parent. -*/ -static bool is_mon_groups (struct kernfs_node *kn,const char *name) -{ -return (!strcmp (rdt_kn_name (kn),"mon_groups" ) && -strcmp (name,"mon_groups" )); -} -static int rdtgroup_mkdir (struct kernfs_node *parent_kn,const char *name,umode_t mode) {
@@ -3782,11 +3791,8 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,if (resctrl_arch_alloc_capable () && parent_kn == rdtgroup_default.kn)return rdtgroup_mkdir_ctrl_mon (parent_kn, name, mode); -/* -* If RDT monitoring is supported and the parent directory is a valid -* "mon_groups" directory, add a monitoring subdirectory. -*/ -if (resctrl_arch_mon_capable () &&is_mon_groups (parent_kn, name)) +/* Else, attempt to add a monitoring subdirectory. */ +if (resctrl_arch_mon_capable ())return rdtgroup_mkdir_mon (parent_kn, name, mode);return -EPERM ;
Signature · 1 line
2.20.1
Re: [PATCH v8 01/21] x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use of kernfs_node::name
Hi, James,
Quoted 73 lines · James Morse
Since commit
741c10b096bc("kernfs: Use RCU to accesskernfs_node::name."), a helperrdt_kn_name()that checks thatrdtgroup_mutexis held has been used for all accesses to the kernfs node name.
rdtgroup_mkdir()uses the name to determine if a valid monitor group is being created by checking the parent name is "mon_groups". This is done without holdingrdtgroup_mutex, and now triggers the following warning:| WARNING: suspicious RCU usage | 6.15.0-rc1 #4465 Tainted: G E | ----------------------------- | arch/x86/kernel/cpu/resctrl/internal.h:408 suspicious rcu_dereference_check() usage! [...] | Call Trace: | <TASK> | dump_stack_lvl+0x6c/0xa0 | lockdep_rcu_suspicious.cold+0x4e/0x96 | is_mon_groups+0xba/0xd0 | rdtgroup_mkdir+0x118/0x1970 | kernfs_iop_mkdir+0xfa/0x1a0 | vfs_mkdir+0x456/0x760 | do_mkdirat+0x257/0x310 | __x64_sys_mkdir+0xd4/0x120 | do_syscall_64+0x6d/0x150 | entry_SYSCALL_64_after_hwframe+0x76/0x7eCreating a control or monitor group calls
mkdir_rdt_prepare(), which usesrdtgroup_kn_lock_live()to take therdtgroup_mutex.To avoid taking and dropping the lock, move the check for the monitor group name and position into
mkdir_rdt_prepare()so that it occurs underrdtgroup_mutex. Hoistis_mon_groups()earlier in the file.CC Sebastian Andrzej Siewior <[email protected]>Fixes 741c10b096bc ("kernfs: Use RCU to access kernfs_node::name.")Signed-off-by James Morse <[email protected]>Acked-by Ingo Molnar <[email protected]>Reviewed-by Reinette Chatre <[email protected]>---
Changes since v1:
* Add a word to a comment.--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 48 +++++++++++++++----------- 1 file changed, 27 insertions(+), 21 deletions(-)arch/x86/kernel/cpu/resctrl/rdtgroup.c +16
-0@@ -3553,6 +3553,22 @@ static void mkdir_rdt_prepare_rmid_free(struct rdtgroup *rgrp)free_rmid (rgrp->closid, rgrp->mon.rmid); } +/* +* We allow creating mon groups only with in a directory called "mon_groups" +* which is present in every ctrl_mon group. Check if this is a valid +* "mon_groups" directory. +* +* 1. The directory should be named "mon_groups". +* 2. The mon group itself should "not" be named "mon_groups". +* This makes sure "mon_groups" directory always has a ctrl_mon group +* as parent. +*/ +static bool is_mon_groups (struct kernfs_node *kn,const char *name) +{ +return (!strcmp (rdt_kn_name (kn),"mon_groups" ) && +strcmp (name,"mon_groups" )); +} +static int mkdir_rdt_prepare (struct kernfs_node *parent_kn,const char *name,umode_t mode,enum rdt_group_type rtype,struct rdtgroup **r)
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, · line 3589
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0@@ -3568,6 +3584,15 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn, goto out_unlock; } +/* +* Check that the parent directory for a monitor group is a +* "mon_groups" directory.
This patch is in upstream now after 6.15-rc1. But the commit in upstream is slightly different from this patch:
+ * Check that the parent directory for a monitor group is a "mon_groups" + * directory.
This slight difference causes patch #17 merge conflict.
You may drop this patch and also fix patch #17 to fix the conflict? Please see my comment in patch #17.
Quoted 36 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-16+*/ +if (rtype ==RDTMON_GROUP && !is_mon_groups (parent_kn, name)) { + ret = -EPERM ; + goto out_unlock; + } +if (rtype ==RDTMON_GROUP && (prdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP || prdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED )) {@@ -3751,22 +3776,6 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,return ret; } -/* -* We allow creating mon groups only with in a directory called "mon_groups" -* which is present in every ctrl_mon group. Check if this is a valid -* "mon_groups" directory. -* -* 1. The directory should be named "mon_groups". -* 2. The mon group itself should "not" be named "mon_groups". -* This makes sure "mon_groups" directory always has a ctrl_mon group -* as parent. -*/ -static bool is_mon_groups (struct kernfs_node *kn,const char *name) -{ -return (!strcmp (rdt_kn_name (kn),"mon_groups" ) && -strcmp (name,"mon_groups" )); -} -static int rdtgroup_mkdir (struct kernfs_node *parent_kn,const char *name,umode_t mode) {@@ -3782,11 +3791,8 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,if (resctrl_arch_alloc_capable () && parent_kn == rdtgroup_default.kn)return rdtgroup_mkdir_ctrl_mon (parent_kn, name, mode);
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, · line 3798
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-5-/* -* If RDT monitoring is supported and the parent directory is a valid -* "mon_groups" directory, add a monitoring subdirectory. -*/ -if (resctrl_arch_mon_capable () &&is_mon_groups (parent_kn, name)) +/* Else, attempt to add a monitoring subdirectory. */ +if (resctrl_arch_mon_capable ())return rdtgroup_mkdir_mon (parent_kn, name, mode);return -EPERM ;
Thanks.
-Fenghua
James Morse
reviewerPATCH v8 2/21 x86/resctrl: Remove the limit on the number of CLOSID
In reply to James MorseFrom: Amit Singh Tomar <[email protected]>
Resctrl allocates and finds free CLOSID values using the bits of a u32. This restricts the number of control groups that can be created by user-space.
MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could be extended beyond 32 values. There is at least one MPAM platform which supports more than 32 CLOSID values.
Replace the fixed size bitmap with calls to the bitmap API to allocate an array of a sufficient size.
ffs() returns '1' for bit 0, hence the existing code subtracts 1 from the index to get the CLOSID value. find_first_bit() returns the bit number which does not need adjusting.
[ morse: fixed the off-by-one in the allocator and the wrong
not-found value. Removed the limit. Rephrase the commit message. ]
---
Changes since v7:
* Moved closid_exit() earlier in rdt_kill_sb() to match what rdt_get_tree() does.
Changes since v6:
* Set variable to NULL after kfree()ing it.
* Call closid_exit() from rdt_kill_sb() to prevent a memory leak.
Changes since v5:
* This patch got pulled into this series.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 47 +++++++++++++++++--------- 1 file changed, 31 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +31 -16
@@ -130,8 +130,8 @@ static bool resctrl_is_mbm_event(int e) }/* -* Trivial allocator for CLOSIDs. Since h/w only supports a small number, -* we can keep a bitmap of free CLOSIDs in a single integer. +* Trivial allocator for CLOSIDs. Use BITMAP APIs to manipulate a bitmap +* of free CLOSIDs. * * Using a global CLOSID across all resources has some advantages and * some drawbacks:
@@ -144,7 +144,7 @@ static bool resctrl_is_mbm_event(int e)* - Our choices on how to configure each resource become progressively more * limited as the number of resources grows. */ -static unsigned long closid_free_map; +static unsigned long *closid_free_map;static int closid_free_map_len;int closids_supported (void )
@@ -152,20 +152,31 @@ int closids_supported(void)return closid_free_map_len; } -static void closid_init (void ) +static int closid_init (void ) {struct resctrl_schema *s; -u32 rdt_min_closid =32 ; +u32 rdt_min_closid = ~0 ;/* Compute rdt_min_closid across all resources */ list_for_each_entry (s, &resctrl_schema_all, list) rdt_min_closid =min (rdt_min_closid, s->num_closid); - closid_free_map =BIT_MASK (rdt_min_closid) -1 ; + closid_free_map =bitmap_alloc (rdt_min_closid,GFP_KERNEL ); +if (!closid_free_map) +return -ENOMEM ; +bitmap_fill (closid_free_map, rdt_min_closid);/* RESCTRL_RESERVED_CLOSID is always reserved for the default group */ -__clear_bit (RESCTRL_RESERVED_CLOSID , &closid_free_map); +__clear_bit (RESCTRL_RESERVED_CLOSID , closid_free_map); closid_free_map_len = rdt_min_closid; + +return 0 ; +} + +static void closid_exit (void ) +{ +bitmap_free (closid_free_map); + closid_free_map =NULL ; }static int closid_alloc (void )
@@ -182,12 +193,11 @@ static int closid_alloc(void)return cleanest_closid; closid = cleanest_closid; }else { - closid =ffs (closid_free_map); -if (closid ==0 ) + closid =find_first_bit (closid_free_map, closid_free_map_len); +if (closid == closid_free_map_len)return -ENOSPC ; - closid--; } -__clear_bit (closid, &closid_free_map); +__clear_bit (closid, closid_free_map);return closid; }
@@ -196,7 +206,7 @@ void closid_free(int closid) {lockdep_assert_held (&rdtgroup_mutex); -__set_bit (closid, &closid_free_map); +__set_bit (closid, closid_free_map); }/**
@@ -210,7 +220,7 @@ bool closid_allocated(unsigned int closid) {lockdep_assert_held (&rdtgroup_mutex); -return !test_bit (closid, &closid_free_map); +return !test_bit (closid, closid_free_map); }/**
@@ -2765,20 +2775,22 @@ static int rdt_get_tree(struct fs_context *fc) goto out_ctx; } -closid_init (); + ret =closid_init (); +if (ret) + goto out_schemata_free;if (resctrl_arch_mon_capable ()) flags |=RFTYPE_MON ; ret =rdtgroup_add_files (rdtgroup_default.kn, flags);if (ret) - goto out_schemata_free; + goto out_closid_exit;kernfs_activate (rdtgroup_default.kn); ret =rdtgroup_create_info_dir (rdtgroup_default.kn);if (ret <0 ) - goto out_schemata_free; + goto out_closid_exit;if (resctrl_arch_mon_capable ()) { ret = mongroup_create_dir(rdtgroup_default.kn,
@@ -2829,6 +2841,8 @@ static int rdt_get_tree(struct fs_context *fc)kernfs_remove (kn_mongrp); out_info:kernfs_remove (kn_info); +out_closid_exit: +closid_exit (); out_schemata_free:schemata_list_destroy (); out_ctx:
@@ -3076,6 +3090,7 @@ static void rdt_kill_sb(struct super_block *sb)rmdir_all_sub ();rdt_pseudo_lock_release (); rdtgroup_default.mode =RDT_MODE_SHAREABLE ; +closid_exit ();schemata_list_destroy ();rdtgroup_destroy_root ();if (resctrl_arch_alloc_capable ())
Signature · 1 line
2.20.1
Re: [PATCH v8 02/21] x86/resctrl: Remove the limit on the number of CLOSID
Hi James,
Quoted 20 lines · James Morse
From: Amit Singh Tomar <[email protected]>
Resctrl allocates and finds free CLOSID values using the bits of a u32. This restricts the number of control groups that can be created by user-space.
MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could be extended beyond 32 values. There is at least one MPAM platform which supports more than 32 CLOSID values.
Replace the fixed size bitmap with calls to the bitmap API to allocate an array of a sufficient size.
ffs()returns '1' for bit 0, hence the existing code subtracts 1 from the index to get the CLOSID value.find_first_bit()returns the bit number which does not need adjusting.Signed-off-by Amit Singh Tomar <[email protected]>[ morse: fixed the off-by-one in the allocator and the wrong
not-found value. Removed the limit. Rephrase the commit message. ]
Quoted 8 lines
Signed-off-by James Morse <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>Tested-by Babu Moger <[email protected]>Reviewed-by Fenghua Yu <[email protected]>---
Thank you.
Reinette
James Morse
reviewerRe: [PATCH v8 02/21] x86/resctrl: Remove the limit on the number of CLOSID
In reply to James MorseHello!
Quoted 26 lines · James Morse
From: Amit Singh Tomar <[email protected]>
Resctrl allocates and finds free CLOSID values using the bits of a u32. This restricts the number of control groups that can be created by user-space.
MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could be extended beyond 32 values. There is at least one MPAM platform which supports more than 32 CLOSID values.
Replace the fixed size bitmap with calls to the bitmap API to allocate an array of a sufficient size.
ffs()returns '1' for bit 0, hence the existing code subtracts 1 from the index to get the CLOSID value.find_first_bit()returns the bit number which does not need adjusting.arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -152,20 +152,31 @@ int closids_supported(void)return closid_free_map_len; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c int closids_supported(void) · line 162
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-2-static void closid_init (void ) +static int closid_init (void ) {struct resctrl_schema *s; -u32 rdt_min_closid =32 ; +u32 rdt_min_closid = ~0 ;/* Compute rdt_min_closid across all resources */ list_for_each_entry (s, &resctrl_schema_all, list) rdt_min_closid =min (rdt_min_closid, s->num_closid);
Platforms that don't have any controls - only monitors - will still call closid_init(). Previously this initialised the fixed-sized bitmap, which was harmless as helpers like closid_alloc() are never called.
With this change, rdt_min_closid keeps its dummy initialisation value of ~0, meaning this:
arch/x86/kernel/cpu/resctrl/rdtgroup.c int closids_supported(void) · line 164
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1- closid_free_map =BIT_MASK (rdt_min_closid) -1 ; + closid_free_map =bitmap_alloc (rdt_min_closid,GFP_KERNEL );
Blows up with a greater than 'max order' error.
I've added a list_empty() check to the top of the function:
| /* Monitor only platforms still call closid_init() */ | if (list_empty(&resctrl_schema_all)) | return 0;
(list-empty as its clearer what goes wrong without the check). I reckon this is minor, so I'll keep the existing tags.
I'm not aware of anyone building a monitor-only MPAM platform - I configured one by accident with one of the software models!
Thanks,
James
Reinette Chatre
maintainerRe: [PATCH v8 02/21] x86/resctrl: Remove the limit on the number of CLOSID
Hi James,
Quoted 56 lines · James Morse
Hello!
Quoted 26 lines · James Morse
From: Amit Singh Tomar <[email protected]>
Resctrl allocates and finds free CLOSID values using the bits of a u32. This restricts the number of control groups that can be created by user-space.
MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could be extended beyond 32 values. There is at least one MPAM platform which supports more than 32 CLOSID values.
Replace the fixed size bitmap with calls to the bitmap API to allocate an array of a sufficient size.
ffs()returns '1' for bit 0, hence the existing code subtracts 1 from the index to get the CLOSID value.find_first_bit()returns the bit number which does not need adjusting.arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -152,20 +152,31 @@ int closids_supported(void)return closid_free_map_len; }arch/x86/kernel/cpu/resctrl/rdtgroup.c int closids_supported(void) · line 162
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-2-static void closid_init (void ) +static int closid_init (void ) {struct resctrl_schema *s; -u32 rdt_min_closid =32 ; +u32 rdt_min_closid = ~0 ;/* Compute rdt_min_closid across all resources */ list_for_each_entry (s, &resctrl_schema_all, list) rdt_min_closid =min (rdt_min_closid, s->num_closid);Platforms that don't have any controls - only monitors - will still call
closid_init(). Previously this initialised the fixed-sized bitmap, which was harmless as helpers likeclosid_alloc()are never called.With this change,
rdt_min_closidkeeps its dummy initialisation value of ~0, meaning this:arch/x86/kernel/cpu/resctrl/rdtgroup.c int closids_supported(void) · line 164
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-1- closid_free_map =BIT_MASK (rdt_min_closid) -1 ; + closid_free_map =bitmap_alloc (rdt_min_closid,GFP_KERNEL );Blows up with a greater than 'max order' error.
I've added a
list_empty()check to the top of the function:| /* Monitor only platforms still call closid_init() */ | if (list_empty(&resctrl_schema_all)) | return 0;
Quoted 7 lines
(list-empty as its clearer what goes wrong without the check). I reckon this is minor, so I'll keep the existing tags.
I'm not aware of anyone building a monitor-only MPAM platform - I configured one by accident with one of the software models!
Thank you very much for catching this.
Reinette
RE: [PATCH v8 02/21] x86/resctrl: Remove the limit on the number of CLOSID
In reply to James MorseHello James, Reinette,
Quoted 139 lines
From: Amit Singh Tomar <[email protected]>
Resctrl allocates and finds free CLOSID values using the bits of a u32. This restricts the number of control groups that can be created by user-space.
MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could be extended beyond 32 values. There is at least one MPAM platform which supports more than 32 CLOSID values.
Replace the fixed size bitmap with calls to the bitmap API to allocate an array of a sufficient size.
ffs()returns '1' for bit 0, hence the existing code subtracts 1 from the index to get the CLOSID value.find_first_bit()returns the bit number which does not need adjusting.Signed-off-by Amit Singh Tomar <[email protected]> [ morse: fixedthe off-by-one in the allocator and the wrong not-found value. Removed the limit. Rephrase the commit message. ]
Signed-off-by James Morse <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>Tested-by Babu Moger <[email protected]>Reviewed-by Fenghua Yu <[email protected]>---
Changes since v7:
* Movedclosid_exit()earlier inrdt_kill_sb()to match whatrdt_get_tree()does.Changes since v6:
* Set variable to NULL after kfree()ing it.
* Callclosid_exit()fromrdt_kill_sb()to prevent a memory leak.Changes since v5:
* This patch got pulled into this series.--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 47 +++++++++++++++++--------- 1 file changed, 31 insertions(+), 16 deletions(-)arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-2@@ -130,8 +130,8 @@ static bool resctrl_is_mbm_event(int e) }/* -* Trivial allocator for CLOSIDs. Since h/w only supports a small number, -* we can keep a bitmap of free CLOSIDs in a single integer. +* Trivial allocator for CLOSIDs. Use BITMAP APIs to manipulate a +bitmap +* of free CLOSIDs. * * Using a global CLOSID across all resources has some advantages and * some drawbacks: @@ -144,7 +144,7 @@ static bool resctrl_is_mbm_event(int e)* - Our choices on how to configure each resource become progressively more
* limited as the number of resources grows.
*/arch/x86/kernel/cpu/resctrl/rdtgroup.c +7
-4-static unsigned long closid_free_map; +static unsigned long *closid_free_map;static int closid_free_map_len;int closids_supported (void )@@ -152,20 +152,31 @@ int closids_supported(void)return closid_free_map_len; } -static void closid_init (void ) +static int closid_init (void ) {struct resctrl_schema *s; -u32 rdt_min_closid =32 ; +u32 rdt_min_closid = ~0 ;/* Compute rdt_min_closid across all resources */ list_for_each_entry (s, &resctrl_schema_all, list) rdt_min_closid =min (rdt_min_closid, s->num_closid); - closid_free_map =BIT_MASK (rdt_min_closid) -1 ; + closid_free_map =bitmap_alloc (rdt_min_closid,GFP_KERNEL ); +if (!closid_free_map) +return -ENOMEM ; +bitmap_fill (closid_free_map, rdt_min_closid);/* RESCTRL_RESERVED_CLOSID is always reserved for the default group */
arch/x86/kernel/cpu/resctrl/rdtgroup.c +12
-5-__clear_bit (RESCTRL_RESERVED_CLOSID , &closid_free_map); +__clear_bit (RESCTRL_RESERVED_CLOSID , closid_free_map); closid_free_map_len = rdt_min_closid; + +return 0 ; +} + +static void closid_exit (void ) +{ +bitmap_free (closid_free_map); + closid_free_map =NULL ; }static int closid_alloc (void )@@ -182,12 +193,11 @@ static int closid_alloc(void)return cleanest_closid; closid = cleanest_closid; }else { - closid =ffs (closid_free_map); -if (closid ==0 ) + closid =find_first_bit (closid_free_map, closid_free_map_len); +if (closid == closid_free_map_len)return -ENOSPC ; - closid--; } -__clear_bit (closid, &closid_free_map); +__clear_bit (closid, closid_free_map);return closid;}
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-2@@ -196,7 +206,7 @@ void closid_free(int closid) {lockdep_assert_held (&rdtgroup_mutex); -__set_bit (closid, &closid_free_map); +__set_bit (closid, closid_free_map); }/** @@ -210,7 +220,7 @@ bool closid_allocated(unsigned int closid) {lockdep_assert_held (&rdtgroup_mutex); -return !test_bit (closid, &closid_free_map); +return !test_bit (closid, closid_free_map); }/**
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_get_tree(struct fs_context *fc) · line 2776
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -2765,20 +2775,22 @@ static int rdt_get_tree(struct fs_context *fc) goto out_ctx; }
Not relevant to this patch, but some of the code around here needs improvement. Maybe consider fixing it together?
ret = schemata_list_create();
if (ret) {
- schemata_list_destroy();
- goto out_ctx;
+ goto out_schemata_free;
}Best regards,
Shaopeng TAN
Quoted 41 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8
-4-closid_init (); + ret =closid_init (); +if (ret) + goto out_schemata_free;if (resctrl_arch_mon_capable ()) flags |=RFTYPE_MON ; ret =rdtgroup_add_files (rdtgroup_default.kn, flags);if (ret) - goto out_schemata_free; + goto out_closid_exit;kernfs_activate (rdtgroup_default.kn); ret =rdtgroup_create_info_dir (rdtgroup_default.kn);if (ret <0 ) - goto out_schemata_free; + goto out_closid_exit;if (resctrl_arch_mon_capable ()) { ret = mongroup_create_dir(rdtgroup_default.kn,@@ -2829,6 +2841,8 @@ static int rdt_get_tree(struct fs_context *fc)kernfs_remove (kn_mongrp); out_info:kernfs_remove (kn_info); +out_closid_exit: +closid_exit (); out_schemata_free:schemata_list_destroy (); out_ctx:@@ -3076,6 +3090,7 @@ static void rdt_kill_sb(struct super_block *sb)rmdir_all_sub ();rdt_pseudo_lock_release (); rdtgroup_default.mode =RDT_MODE_SHAREABLE ; +closid_exit ();schemata_list_destroy ();rdtgroup_destroy_root ();if (resctrl_arch_alloc_capable ()) --2.20.1
James Morse
reviewerRe: [PATCH v8 02/21] x86/resctrl: Remove the limit on the number of CLOSID
Hi Shaopeng Tan,
Quoted 30 lines · Shaopeng Tan (Fujitsu)
Quoted 23 lines
From: Amit Singh Tomar <[email protected]>
Resctrl allocates and finds free CLOSID values using the bits of a u32. This restricts the number of control groups that can be created by user-space.
MPAM has an architectural limit of 2^16 CLOSID values, Intel x86 could be extended beyond 32 values. There is at least one MPAM platform which supports more than 32 CLOSID values.
Replace the fixed size bitmap with calls to the bitmap API to allocate an array of a sufficient size.
ffs()returns '1' for bit 0, hence the existing code subtracts 1 from the index to get the CLOSID value.find_first_bit()returns the bit number which does not need adjusting.arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdt_get_tree(struct fs_context *fc) · line 2776
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -2765,20 +2775,22 @@ static int rdt_get_tree(struct fs_context *fc) goto out_ctx; }Not relevant to this patch, but some of the code around here needs improvement. Maybe consider fixing it together?
ret = schemata_list_create(); if (ret) {
Review
Quoted 4 lines
(quoted diff) +1
-2- schemata_list_destroy(); - goto out_ctx; + goto out_schemata_free; }
Hmmm, that doesn't make a difference, but it does save a line. As I'm not changing that code in this series, I don't want to touch it as part of this series. (its already getting too big!)
It got written like that because list_create() doesn't do all the cleanup when it fails, this makes it the odd one out..
If you think this version is better, please send a patch!
Thanks,
James
James Morse
reviewerPATCH v8 3/21 x86/resctrl: Rename resctrl_sched_in() to begin with "resctrl_arch_"
In reply to James Morseresctrl_sched_in() loads the architecture specific CPU MSRs with the CLOSID and RMID values. This function was named before resctrl was split to have architecture specific code, and generic filesystem code.
This function is obviously architecture specific, but does not begin with 'resctrl_arch_', making it the odd one out in the functions an architecture needs to support to enable resctrl.
Rename it for consistency. This is purely cosmetic.
--- arch/x86/include/asm/resctrl.h | 4 ++-- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 ++++++------ arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/include/asm/resctrl.h +2 -2
@@ -175,7 +175,7 @@ static inline bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 ignored,return READ_ONCE (tsk->rmid) == rmid; } -static inline void resctrl_sched_in (struct task_struct *tsk) +static inline void resctrl_arch_sched_in (struct task_struct *tsk) {if (static_branch_likely (&rdt_enable_key))__resctrl_sched_in (tsk);
@@ -212,7 +212,7 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c);#else -static inline void resctrl_sched_in (struct task_struct *tsk) {} +static inline void resctrl_arch_sched_in (struct task_struct *tsk) {}static inline void resctrl_cpu_detect (struct cpuinfo_x86 *c) {}#endif /* CONFIG_X86_CPU_RESCTRL */
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -6
@@ -372,7 +372,7 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of, }/* -* This is safe against resctrl_sched_in() called from __switch_to() +* This is safe against resctrl_arch_sched_in() called from __switch_to() * because __switch_to() is executed with interrupts disabled. A local call * from update_closid_rmid() is protected against __switch_to() because * preemption is disabled.
@@ -391,7 +391,7 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info)* executing task might have its own closid selected. Just reuse * the context switch code. */ -resctrl_sched_in (current); +resctrl_arch_sched_in (current); }/*
@@ -616,7 +616,7 @@ static void _update_task_closid_rmid(void *task)* Otherwise, the MSR is updated when the task is scheduled in. */ if (task == current) -resctrl_sched_in (task); +resctrl_arch_sched_in (task); }static void update_task_closid_rmid (struct task_struct *t)
@@ -674,7 +674,7 @@ static int __rdtgroup_move_task(struct task_struct *tsk,* Ensure the task's closid and rmid are written before determining if * the task is current that will decide if it will be interrupted. * This pairs with the full barrier between the rq->curr update and -* resctrl_sched_in() during context switch. +* resctrl_arch_sched_in() during context switch. */ smp_mb ();
@@ -2990,8 +2990,8 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to,/* * Order the closid/rmid stores above before the loads * in task_curr(). This pairs with the full barrier -* between the rq->curr update and resctrl_sched_in() -* during context switch. +* between the rq->curr update and +* resctrl_arch_sched_in() during context switch. */ smp_mb ();
arch/x86/kernel/process_32.c +1 -1
@@ -211,7 +211,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)switch_fpu_finish (next_p);/* Load the Intel cache allocation PQR MSR. */ -resctrl_sched_in (next_p); +resctrl_arch_sched_in (next_p);return prev_p; }
arch/x86/kernel/process_64.c +1 -1
@@ -707,7 +707,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) }/* Load the Intel cache allocation PQR MSR. */ -resctrl_sched_in (next_p); +resctrl_arch_sched_in (next_p);return prev_p; }
Signature · 1 line
2.20.1
Reinette Chatre
maintainerRe: [PATCH v8 03/21] x86/resctrl: Rename resctrl_sched_in() to begin with "resctrl_arch_"
Hi James,
Quoted 8 lines · James Morse
resctrl_sched_in()loads the architecture specific CPU MSRs with the CLOSID and RMID values. This function was named before resctrl was split to have architecture specific code, and generic filesystem code.This function is obviously architecture specific, but does not begin with '
resctrl_arch_', making it the odd one out in the functions an architecture needs to support to enable resctrl.
Quoted 7 lines
Rename it for consistency. This is purely cosmetic.
Signed-off-by James Morse <[email protected]>Tested-by Carl Worth <[email protected]> # arm64Tested-by Shaopeng Tan <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>
This is a duplicate "Tested-by" tag for Shaopeng.
Reinette
James Morse
reviewerRe: [PATCH v8 03/21] x86/resctrl: Rename resctrl_sched_in() to begin with "resctrl_arch_"
Hi Reinette,
Quoted 11 lines · Reinette Chatre
Quoted 10 lines · James Morse
resctrl_sched_in()loads the architecture specific CPU MSRs with the CLOSID and RMID values. This function was named before resctrl was split to have architecture specific code, and generic filesystem code.This function is obviously architecture specific, but does not begin with '
resctrl_arch_', making it the odd one out in the functions an architecture needs to support to enable resctrl.Rename it for consistency. This is purely cosmetic.
Quoted 7 lines
Quoted 5 lines
Signed-off-by James Morse <[email protected]>Tested-by Carl Worth <[email protected]> # arm64Tested-by Shaopeng Tan <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>This is a duplicate "Tested-by" tag for Shaopeng.
Fixed,
Thanks,
James
James Morse
reviewerPATCH v8 4/21 x86/resctrl: resctrl_exit() teardown resctrl but leave the mount point
In reply to James Morseresctrl_exit() was intended for use when the 'resctrl' module was unloaded. resctrl can't be built as a module, and the kernfs helpers are not exported so this is unlikely to change. MPAM has an error interrupt which indicates the MPAM driver has gone haywire. Should this occur tasks could run with the wrong control values, leading to bad performance for important tasks. In this scenario the MPAM driver will reset the hardware, but it needs a way to tell resctrl that no further configuration should be attempted.
In particular, moving tasks between control or monitor groups does not interact with the architecture code, so there is no opportunity for the arch code to indicate that the hardware is no-longer functioning.
Using resctrl_exit() for this leaves the system in a funny state as resctrl is still mounted, but cannot be un-mounted because the sysfs directory that is typically used has been removed. Dave Martin suggests this may cause systemd trouble in the future as not all filesystems can be unmounted.
Add calls to remove all the files and directories in resctrl, and remove the sysfs_remove_mount_point() call that leaves the system in a funny state. When triggered, this causes all the resctrl files to disappear. resctrl can be unmounted, but not mounted again.
---
Changes since v7:
* Moved kernfs cleanup functions to resctrl_fs_teardown(), and call this from rescrl_exit().
* Added description of MPAM resetting the hardware to the commit message.
Changes since v6:
* Added kdoc and comment to resctrl_exit().
Changes since v5:
* Serialise rdtgroup_destroy_root() against umount().
* Check rdtgroup_default.kn to protect against duplicate calls.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 42 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +35 -7
@@ -3074,6 +3074,22 @@ static void rmdir_all_sub(void)kernfs_remove (kn_mondata); } +static void resctrl_fs_teardown (void ) +{ +lockdep_assert_held (&rdtgroup_mutex); + +/* Cleared by rdtgroup_destroy_root() */ +if (!rdtgroup_default.kn) +return ; + +rmdir_all_sub (); +rdt_pseudo_lock_release (); + rdtgroup_default.mode =RDT_MODE_SHAREABLE ; +closid_exit (); +schemata_list_destroy (); +rdtgroup_destroy_root (); +} +static void rdt_kill_sb (struct super_block *sb) {struct rdt_resource *r;
@@ -3087,12 +3103,7 @@ static void rdt_kill_sb(struct super_block *sb)for_each_alloc_capable_rdt_resource (r)resctrl_arch_reset_all_ctrls (r); -rmdir_all_sub (); -rdt_pseudo_lock_release (); - rdtgroup_default.mode =RDT_MODE_SHAREABLE ; -closid_exit (); -schemata_list_destroy (); -rdtgroup_destroy_root (); +resctrl_fs_teardown ();if (resctrl_arch_alloc_capable ())resctrl_arch_disable_alloc ();if (resctrl_arch_mon_capable ())
@@ -4123,6 +4134,8 @@ static int rdtgroup_setup_root(struct rdt_fs_context *ctx)static void rdtgroup_destroy_root (void ) { +lockdep_assert_held (&rdtgroup_mutex); +kernfs_destroy_root (rdt_root); rdtgroup_default.kn =NULL ; }
@@ -4416,11 +4429,26 @@ int __init resctrl_init(void)return ret; } +/** +* resctrl_exit() - Remove the resctrl filesystem and free resources. +* +* Called by the architecture code in response to a fatal error. +* Resctrl files and structures are removed from kernfs to prevent further +* configuration. +*/ void __exit resctrl_exit(void) { +mutex_lock (&rdtgroup_mutex); +resctrl_fs_teardown (); +mutex_unlock (&rdtgroup_mutex); +debugfs_remove_recursive (debugfs_resctrl);unregister_filesystem (&rdt_fs_type); -sysfs_remove_mount_point (fs_kobj,"resctrl" ); + +/* +* The sysfs mount point added by resctrl_init() is not removed so that +* it can be used to umount resctrl. +*/ resctrl_mon_resource_exit (); }
Signature · 1 line
2.20.1
Reinette Chatre
maintainerRe: [PATCH v8 04/21] x86/resctrl: resctrl_exit() teardown resctrl but leave the mount point
Hi James,
Quoted 18 lines · James Morse
resctrl_exit()was intended for use when the 'resctrl' module was unloaded. resctrl can't be built as a module, and the kernfs helpers are not exported so this is unlikely to change. MPAM has an error interrupt which indicates the MPAM driver has gone haywire. Should this occur tasks could run with the wrong control values, leading to bad performance for important tasks. In this scenario the MPAM driver will reset the hardware, but it needs a way to tell resctrl that no further configuration should be attempted.In particular, moving tasks between control or monitor groups does not interact with the architecture code, so there is no opportunity for the arch code to indicate that the hardware is no-longer functioning.
Using
resctrl_exit()for this leaves the system in a funny state as resctrl is still mounted, but cannot be un-mounted because the sysfs directory that is typically used has been removed. Dave Martin suggests this may cause systemd trouble in the future as not all filesystems can be unmounted.
Quoted 5 lines
Add calls to remove all the files and directories in resctrl, and remove the
sysfs_remove_mount_point()call that leaves the system in a funny state. When triggered, this causes all the resctrl files to disappear. resctrl can be unmounted, but not mounted again.
The caveat here is that resctrl pretends to be mounted (resctrl_mounted == true) but there is nothing there. The undocumented part of this is that for this to work resctrl fs depends (a lot) on the architecture's callbacks to know if they are being called after a resctrl_exit() call so that they return data that will direct resctrl fs behavior to safest exit for those resctrl fs flows that are still possible after a resctrl_exit(). Not ideal layering.
I understand from a previous comment [1] that one of the Arm "tricks" is to offline all domains. This seems to be a good "catch all" to ensure that at least current flows of concern are not running anymore. Considering this, what if there is a new resctrl_error_exit() that does something like below?
void resctrl_error_exit(void)
{
mutex_lock(&rdtgroup_mutex);
WARN_ON_ONCE(resctrl_new_function_returns_true_if_any_resource_has_a_control_or_monitor_domain());
resctrl_fs_teardown();
mutex_unlock(&rdtgroup_mutex);
resctrl_exit();
}I do not see this as requiring anything new from architecture but instead making what Arm already does a requirement and keeping existing behavior?
This leaves proc_resctrl_show() that relies on resctrl_mounted but as I see the resctrl_fs_cleanup() will remove all resource groups that should result in the output being as it will be if resctrl is not mounted. No dependence on architecture callbacks returning resctrl_exit() aware data here.
Quoted 10 lines
Signed-off-by James Morse <[email protected]>Tested-by Carl Worth <[email protected]> # arm64Tested-by Shaopeng Tan <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Babu Moger <[email protected]>Reviewed-by Shaopeng Tan <[email protected]>Reviewed-by Tony Luck <[email protected]>---
...
Quoted 55 lines
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 42 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-)arch/x86/kernel/cpu/resctrl/rdtgroup.c +19
-6@@ -3074,6 +3074,22 @@ static void rmdir_all_sub(void)kernfs_remove (kn_mondata); } +static void resctrl_fs_teardown (void ) +{ +lockdep_assert_held (&rdtgroup_mutex); + +/* Cleared by rdtgroup_destroy_root() */ +if (!rdtgroup_default.kn) +return ; + +rmdir_all_sub (); +rdt_pseudo_lock_release (); + rdtgroup_default.mode =RDT_MODE_SHAREABLE ; +closid_exit (); +schemata_list_destroy (); +rdtgroup_destroy_root (); +} +static void rdt_kill_sb (struct super_block *sb) {struct rdt_resource *r;@@ -3087,12 +3103,7 @@ static void rdt_kill_sb(struct super_block *sb)for_each_alloc_capable_rdt_resource (r)resctrl_arch_reset_all_ctrls (r); -rmdir_all_sub (); -rdt_pseudo_lock_release (); - rdtgroup_default.mode =RDT_MODE_SHAREABLE ; -closid_exit (); -schemata_list_destroy (); -rdtgroup_destroy_root (); +resctrl_fs_teardown ();if (resctrl_arch_alloc_capable ())resctrl_arch_disable_alloc ();if (resctrl_arch_mon_capable ())@@ -4123,6 +4134,8 @@ static int rdtgroup_setup_root(struct rdt_fs_context *ctx)static void rdtgroup_destroy_root (void ) { +lockdep_assert_held (&rdtgroup_mutex); +kernfs_destroy_root (rdt_root); rdtgroup_default.kn =NULL ; }
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4437
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-0@@ -4416,11 +4429,26 @@ int __init resctrl_init(void)return ret; } +/** +* resctrl_exit() - Remove the resctrl filesystem and free resources. +* +* Called by the architecture code in response to a fatal error. +* Resctrl files and structures are removed from kernfs to prevent further +* configuration.
Please write with imperative tone. For example, "Remove resctrl files and structures ..."
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4445
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-0+*/ void __exit resctrl_exit(void) { +mutex_lock (&rdtgroup_mutex); +resctrl_fs_teardown (); +mutex_unlock (&rdtgroup_mutex); +debugfs_remove_recursive (debugfs_resctrl);
Is it possible for the fatal error handling to trigger multiple calls here? To protect against multiple calls causing issues debugfs_resctrl can be set to NULL here.
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4446
Quoted 1 line
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0unregister_filesystem (&rdt_fs_type);
unregister_filesystem() seems to handle an already-unregistered filesystem.
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4451
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-1-sysfs_remove_mount_point (fs_kobj,"resctrl" ); + +/* +* The sysfs mount point added by resctrl_init() is not removed so that +* it can be used to umount resctrl. +*/
(needs imperative)
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4454
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0resctrl_mon_resource_exit (); }
Reinette
James Morse
reviewerRe: [PATCH v8 04/21] x86/resctrl: resctrl_exit() teardown resctrl but leave the mount point
Hi Reinette,
Quoted 25 lines · Reinette Chatre
Quoted 18 lines · James Morse
resctrl_exit()was intended for use when the 'resctrl' module was unloaded. resctrl can't be built as a module, and the kernfs helpers are not exported so this is unlikely to change. MPAM has an error interrupt which indicates the MPAM driver has gone haywire. Should this occur tasks could run with the wrong control values, leading to bad performance for important tasks. In this scenario the MPAM driver will reset the hardware, but it needs a way to tell resctrl that no further configuration should be attempted.In particular, moving tasks between control or monitor groups does not interact with the architecture code, so there is no opportunity for the arch code to indicate that the hardware is no-longer functioning.
Using
resctrl_exit()for this leaves the system in a funny state as resctrl is still mounted, but cannot be un-mounted because the sysfs directory that is typically used has been removed. Dave Martin suggests this may cause systemd trouble in the future as not all filesystems can be unmounted.Quoted 4 lines
Add calls to remove all the files and directories in resctrl, and remove the
sysfs_remove_mount_point()call that leaves the system in a funny state. When triggered, this causes all the resctrl files to disappear. resctrl can be unmounted, but not mounted again.
Quoted 7 lines
The caveat here is that resctrl pretends to be mounted (
resctrl_mounted== true) but there is nothing there. The undocumented part of this is that for this to work resctrl fs depends (a lot) on the architecture's callbacks to know if they are being called after aresctrl_exit()call so that they return data that will direct resctrl fs behavior to safest exit for those resctrl fs flows that are still possible after aresctrl_exit(). Not ideal layering.
It was the arch code that called resctrl_exit() - there is no other path into it. I don't think its a problem for the arch code to also know to return an error. I haven't found anything where which error is returned actually matter - so there is no 'direction', only errors.
I agree the documentation can be improved.
Quoted 3 lines
I understand from a previous comment [1] that one of the Arm "tricks" is to offline all domains. This seems to be a good "catch all" to ensure that at least current flows of concern are not running anymore.
Yup, that is necessary to stop the limbo and overflow workers for trying to read the counters - which is a waste of time.
Quoted 11 lines
Considering this,
what if there is a newresctrl_error_exit()that does something like below?void resctrl_error_exit(void) { mutex_lock(&rdtgroup_mutex); WARN_ON_ONCE(resctrl_new_function_returns_true_if_any_resource_has_a_control_or_monitor_domain()); resctrl_fs_teardown(); mutex_unlock(&rdtgroup_mutex); resctrl_exit(); }
Makes sense - the alternative would be to dig around to cancel the limbo/overflow work, and a subsequent CPU-online might start them again.
Quoted 2 lines
I do not see this as requiring anything new from architecture but instead making what Arm already does a requirement and keeping existing behavior?
I agree.
Quoted 4 lines
This leaves
proc_resctrl_show()that relies onresctrl_mountedbut as I see theresctrl_fs_cleanup()will remove all resource groups that should result in the output being as it will be if resctrl is not mounted. No dependence on architecture callbacks returningresctrl_exit()aware data here.
Great - I'd missed that one,
Quoted 18 lines
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4437
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-0@@ -4416,11 +4429,26 @@ int __init resctrl_init(void)return ret; } +/** +* resctrl_exit() - Remove the resctrl filesystem and free resources. +* +* Called by the architecture code in response to a fatal error. +* Resctrl files and structures are removed from kernfs to prevent further +* configuration. Please write with imperative tone. For example, "Remove resctrl files and structures ..."
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4445
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-0+*/ void __exit resctrl_exit(void) { +mutex_lock (&rdtgroup_mutex); +resctrl_fs_teardown (); +mutex_unlock (&rdtgroup_mutex); +debugfs_remove_recursive (debugfs_resctrl);Is it possible for the fatal error handling to trigger multiple calls here? To protect against multiple calls causing issues
debugfs_resctrlcan be set to NULL here.
It's not, the driver keeps track of whether resctrl_init() had been called, and only calls resctrl_exit() once. But I agree it would be better to make it robust to this.
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4446
Quoted 1 line
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0unregister_filesystem (&rdt_fs_type);
unregister_filesystem()seems to handle an already-unregistered filesystem.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4451
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-1-sysfs_remove_mount_point (fs_kobj,"resctrl" ); + +/* +* The sysfs mount point added by resctrl_init() is not removed so that +* it can be used to umount resctrl. +*/ (needs imperative)
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0resctrl_mon_resource_exit (); }
Thanks,
James
James Morse
reviewerPATCH v8 5/21 x86/resctrl: Drop __init/__exit on assorted symbols
In reply to James MorseBecause ARM's MPAM controls are probed using MMIO, resctrl can't be initialised until enough CPUs are online to have determined the system-wide supported num_closid. Arm64 also supports 'late onlined secondaries', where only a subset of CPUs are online during boot.
These two combine to mean the MPAM driver may not be able to initialise resctrl until user-space has brought 'enough' CPUs online.
To allow MPAM to initialise resctrl after __init text has been free'd, remove all the __init markings from resctrl.
The existing __exit markings cause these functions to be removed by the linker as it has never been possible to build resctrl as a module. MPAM has an error interrupt which causes the driver to reset and disable itself. Remove the __exit markings to allow the MPAM driver to tear down resctrl when an error occurs.
---
Changes since v4:
* Earlier __init marker removal migrated here.
--- arch/x86/kernel/cpu/resctrl/core.c | 6 +++--- arch/x86/kernel/cpu/resctrl/internal.h | 4 ++-- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 6 +++--- include/linux/resctrl.h | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +3 -3
@@ -737,7 +737,7 @@ struct rdt_options {bool force_off, force_on; }; -static struct rdt_options rdt_options[]__initdata = { +static struct rdt_options rdt_options[]__ro_after_init = {RDT_OPT (RDT_FLAG_CMT ,"cmt" ,X86_FEATURE_CQM_OCCUP_LLC ),RDT_OPT (RDT_FLAG_MBM_TOTAL ,"mbmtotal" ,X86_FEATURE_CQM_MBM_TOTAL ),RDT_OPT (RDT_FLAG_MBM_LOCAL ,"mbmlocal" ,X86_FEATURE_CQM_MBM_LOCAL ),
@@ -777,7 +777,7 @@ static int __init set_rdt_options(char *str) }__setup ("rdt" , set_rdt_options); -bool __init rdt_cpu_has (int flag) +bool rdt_cpu_has (int flag) {bool ret =boot_cpu_has (flag);struct rdt_options *o;
@@ -797,7 +797,7 @@ bool __init rdt_cpu_has(int flag)return ret; } -__init bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt) +bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt) {if (!rdt_cpu_has (X86_FEATURE_BMEC ))return false;
arch/x86/kernel/cpu/resctrl/internal.h +2 -2
@@ -486,13 +486,13 @@ int alloc_rmid(u32 closid);void free_rmid (u32 closid,u32 rmid);int rdt_get_mon_l3_config (struct rdt_resource *r);void resctrl_mon_resource_exit (void ); -bool __init rdt_cpu_has (int flag); +bool rdt_cpu_has (int flag);void mon_event_count (void *info);int rdtgroup_mondata_show (struct seq_file *m,void *arg);void mon_event_read (struct rmid_read *rr,struct rdt_resource *r,struct rdt_mon_domain *d,struct rdtgroup *rdtgrp,cpumask_t *cpumask,int evtid,int first); -int __init resctrl_mon_resource_init (void ); +int resctrl_mon_resource_init (void );void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms,int exclude_cpu);
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -1204,7 +1204,7 @@ static __init int snc_get_config(void)* * Returns 0 for success, or -ENOMEM. */ -int __init resctrl_mon_resource_init (void ) +int resctrl_mon_resource_init (void ) {struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 );int ret;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
@@ -4140,7 +4140,7 @@ static void rdtgroup_destroy_root(void) rdtgroup_default.kn =NULL ; } -static void __init rdtgroup_setup_default (void ) +static void rdtgroup_setup_default (void ) {mutex_lock (&rdtgroup_mutex);
@@ -4372,7 +4372,7 @@ void resctrl_offline_cpu(unsigned int cpu)* * Return: 0 on success or -errno */ -int __init resctrl_init (void ) +int resctrl_init (void ) {int ret =0 ;
@@ -4436,7 +4436,7 @@ int __init resctrl_init(void)* Resctrl files and structures are removed from kernfs to prevent further * configuration. */ -void __exit resctrl_exit(void) +void resctrl_exit (void ) {mutex_lock (&rdtgroup_mutex);resctrl_fs_teardown ();
include/linux/resctrl.h +3 -3
@@ -358,7 +358,7 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r);u32 resctrl_arch_system_num_rmid_idx (void );int resctrl_arch_update_domains (struct rdt_resource *r,u32 closid); -__init bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt); +bool resctrl_arch_is_evt_configurable (enum resctrl_event_id evt);/** * resctrl_arch_mon_event_config_write() - Write the config for an event.
@@ -514,7 +514,7 @@ void resctrl_arch_reset_all_ctrls(struct rdt_resource *r);extern unsigned int resctrl_rmid_realloc_threshold;extern unsigned int resctrl_rmid_realloc_limit; -int __init resctrl_init (void ); -void __exit resctrl_exit(void); +int resctrl_init (void ); +void resctrl_exit (void );#endif /* _RESCTRL_H */
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 6/21 x86/resctrl: Move is_mba_sc() out of core.c
In reply to James Morseis_mba_sc() is defined in core.c, but has no callers there. It does not access any architecture private structures.
Move this to rdtgroup.c where the majority of callers are. This makes the move of the filesystem code to /fs/ cleaner.
---
Changes since v2:
* This patch is new.
--- arch/x86/kernel/cpu/resctrl/core.c | 15 --------------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +0 -15
@@ -164,21 +164,6 @@ static inline void cache_alloc_hsw_probe(void) rdt_alloc_capable = true; } -bool is_mba_sc (struct rdt_resource *r) -{ -if (!r) - r =resctrl_arch_get_resource (RDT_RESOURCE_MBA ); - -/* -* The software controller support is only applicable to MBA resource. -* Make sure to check for resource type. -*/ -if (r->rid !=RDT_RESOURCE_MBA ) -return false; - -return r->membw.mba_sc; -} -/* * rdt_get_mb_table() - get a mapping of bandwidth(b/w) percentage values * exposed to user interface and the h/w understandable delay values.
arch/x86/kernel/cpu/resctrl/rdtgroup.c +15 -0
@@ -1531,6 +1531,21 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,return size; } +bool is_mba_sc (struct rdt_resource *r) +{ +if (!r) + r =resctrl_arch_get_resource (RDT_RESOURCE_MBA ); + +/* +* The software controller support is only applicable to MBA resource. +* Make sure to check for resource type. +*/ +if (r->rid !=RDT_RESOURCE_MBA ) +return false; + +return r->membw.mba_sc; +} +/* * rdtgroup_size_show - Display size in bytes of allocated regions *
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 7/21 x86/resctrl: Add end-marker to the resctrl_event_id enum
In reply to James MorseThe resctrl_event_id enum gives names to the counter event numbers on x86. These are used directly by resctrl.
To allow the MPAM driver to keep an array of these the size of the enum needs to be known.
Add a 'num_events' define which can be used to size an array. This isn't a member of the enum to avoid updating switch statements that would otherwise be missing a case.
--- include/linux/resctrl_types.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/resctrl_types.h +2 -0
@@ -51,4 +51,6 @@ enum resctrl_event_id { QOS_L3_MBM_LOCAL_EVENT_ID = 0x03, }; +#define QOS_NUM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID + 1) +#endif /* __LINUX_RESCTRL_TYPES_H */
Signature · 1 line
2.20.1
Luck, Tony
maintainerRe: [PATCH v8 07/21] x86/resctrl: Add end-marker to the resctrl_event_id enum
Quoted 9 lines · James Morse
The
resctrl_event_idenum gives names to the counter event numbers on x86. These are used directly by resctrl.To allow the MPAM driver to keep an array of these the size of the enum needs to be known.
Add a '
num_events' define which can be used to size an array. This isn't a member of the enum to avoid updating switch statements that would otherwise be missing a case.
I'm adding more events in this series:
https://lore.kernel.org/all/[email protected]/
Any switches in existing code would need to have a "default:" case added because the new events are in the same "enum" but totally unrelated to the existing events. Other code changes in that series deleted many of the switches anyway.
Patch 23 in that series changes QOS_NUM_EVENTS from a #define to the last element in the enum without any issues.
Quoted 28 lines
Signed-off-by James Morse <[email protected]>Tested-by Carl Worth <[email protected]> # arm64Tested-by Shaopeng Tan <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Babu Moger <[email protected]>Reviewed-by Shaopeng Tan <[email protected]>Reviewed-by Tony Luck <[email protected]>Reviewed-by Reinette Chatre <[email protected]>Reviewed-by Fenghua Yu <[email protected]>--- include/linux/resctrl_types.h | 2 ++ 1 file changed, 2 insertions(+)include/linux/resctrl_types.h +2
-0@@ -51,4 +51,6 @@ enum resctrl_event_id { QOS_L3_MBM_LOCAL_EVENT_ID = 0x03, }; +#define QOS_NUM_EVENTS (QOS_L3_MBM_LOCAL_EVENT_ID + 1) +#endif /* __LINUX_RESCTRL_TYPES_H */ Signature · 1 line
2.20.1
-Tony
James Morse
reviewerRe: [PATCH v8 07/21] x86/resctrl: Add end-marker to the resctrl_event_id enum
Hi Tony,
Quoted 11 lines · Tony
Quoted 9 lines · James Morse
The
resctrl_event_idenum gives names to the counter event numbers on x86. These are used directly by resctrl.To allow the MPAM driver to keep an array of these the size of the enum needs to be known.
Add a '
num_events' define which can be used to size an array. This isn't a member of the enum to avoid updating switch statements that would otherwise be missing a case.
Quoted 5 lines
I'm adding more events in this series:
https://lore.kernel.org/all/[email protected]/
Any switches in existing code would need to have a "default:" case
Boo. I much prefer the no-default case as it forces someone adding a new enum entry to inspect every switch statement. But I'll change it.
Quoted 3 lines
added because the new events are in the same "enum" but totally unrelated to the existing events. Other code changes in that series deleted many of the switches anyway.
Cool!
Quoted 2 lines
Patch 23 in that series changes
QOS_NUM_EVENTSfrom a #define to the last element in the enum without any issues.
I'll do that here and add the defaults in this patch to reduce conflicts.
Thanks,
James
James Morse
reviewerPATCH v8 8/21 x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
In reply to James MorseMPAM platforms retrieve the cache-id property from the ACPI PPTT table. The cache-id field is 32 bits wide. Under resctrl, the cache-id becomes the domain-id, and is packed into the mon_data_bits union bitfield. The width of cache-id in this field is 14 bits.
Expanding the union would break 32bit x86 platforms as this union is stored as the kernfs kn->priv pointer. This saved allocating memory for the priv data storage.
The firmware on MPAM platforms have used the PPTT cache-id field to expose the interconnect's id for the cache, which is sparse and uses more than 14 bits. Use of this id is to enable PCIe direct cache injection hints. Using this feature with VFIO means the value provided by the ACPI table should be exposed to user-space.
To support cache-id values greater than 14 bits, convert the mon_data_bits union to a structure. These are shared between control and monitor groups, and are allocated on first use. The list of allocated struct mon_data is free'd when the filesystem is umount()ed.
---
Previously the MPAM tree repainted the cache-id to compact them, argue-ing there was no other user. With VFIO use of this PCIe feature, this is no longer an option.
Changes since v7:
* Replaced with Tony Luck's list based version.
Changes since v6:
* Added the get/put helpers.
* Special case the creation of the mondata files for the default control group.
* Removed wording about files living longer than expected, the corresponding error handling is wrapped in WARN_ON_ONCE() as this indicates a bug.
--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 ++++-- arch/x86/kernel/cpu/resctrl/internal.h | 39 ++++++------ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 78 +++++++++++++++++++++-- 3 files changed, 102 insertions(+), 34 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +12 -7
@@ -667,7 +667,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r; -union mon_data_bits md; +struct mon_data *md;int ret =0 ; rdtgrp =rdtgroup_kn_lock_live (of->kn);
@@ -676,17 +676,22 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } - md.priv = of->kn->priv; - resid = md.u.rid; - domid = md.u.domid; - evtid = md.u.evtid; + md = of->kn->priv; +if (WARN_ON_ONCE (!md)) { + ret = -EIO ; + goto out; + } + + resid = md->rid; + domid = md->domid; + evtid = md->evtid; r =resctrl_arch_get_resource (resid); -if (md.u.sum) { +if (md->sum) {/* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the -* mon_data_bits union. Search all domains in the resource for +* struct mon_data. Search all domains in the resource for * one that matches this cache id. */ list_for_each_entry (d, &r->mon_domains, hdr.list) {
arch/x86/kernel/cpu/resctrl/internal.h +19 -20
@@ -103,27 +103,26 @@ struct mon_evt { };/** -* union mon_data_bits - Monitoring details for each event file. -* @priv: Used to store monitoring event data in @u -* as kernfs private data. -* @u.rid: Resource id associated with the event file. -* @u.evtid: Event id associated with the event file. -* @u.sum: Set when event must be summed across multiple -* domains. -* @u.domid: When @u.sum is zero this is the domain to which -* the event file belongs. When @sum is one this -* is the id of the L3 cache that all domains to be -* summed share. -* @u: Name of the bit fields struct. +* struct mon_data - Monitoring details for each event file. +* @list: Member of list of all allocated structures. +* @rid: Resource id associated with the event file. +* @evtid: Event id associated with the event file. +* @sum: Set when event must be summed across multiple +* domains. +* @domid: When @sum is zero this is the domain to which +* the event file belongs. When @sum is one this +* is the id of the L3 cache that all domains to be +* summed share. +* +* Stored in the kernfs kn->priv field, readers and writers must hold +* rdtgroup_mutex. */ -union mon_data_bits { -void *priv; -struct { -unsigned int rid :10 ; -enum resctrl_event_id evtid :7 ; -unsigned int sum :1 ; -unsigned int domid :14 ; - } u; +struct mon_data { +struct list_head list; +unsigned int rid; +enum resctrl_event_id evtid; +unsigned int sum; +unsigned int domid; };/**
arch/x86/kernel/cpu/resctrl/rdtgroup.c +71 -7
108 lines not on this page · raw message
Signature · 1 line
2.20.1
Reinette Chatre
maintainerRe: [PATCH v8 08/21] x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
Hi James,
There is no occurence of "dom_id" in patch other than subject.
Quoted 63 lines · James Morse
MPAM platforms retrieve the cache-id property from the ACPI PPTT table. The cache-id field is 32 bits wide. Under resctrl, the cache-id becomes the domain-id, and is packed into the
mon_data_bitsunion bitfield. The width of cache-id in this field is 14 bits.Expanding the union would break 32bit x86 platforms as this union is stored as the kernfs
kn->privpointer. This saved allocating memory for the priv data storage.The firmware on MPAM platforms have used the PPTT cache-id field to expose the interconnect's id for the cache, which is sparse and uses more than 14 bits. Use of this id is to enable PCIe direct cache injection hints. Using this feature with VFIO means the value provided by the ACPI table should be exposed to user-space.
To support cache-id values greater than 14 bits, convert the
mon_data_bitsunion to a structure. These are shared between control and monitor groups, and are allocated on first use. The list of allocated structmon_datais free'd when the filesystem is umount()ed.Co-developed-by Tony Luck <[email protected]>Signed-off-by Tony Luck <[email protected]>Signed-off-by James Morse <[email protected]>---
Previously the MPAM tree repainted the cache-id to compact them, argue-ing there was no other user. With VFIO use of this PCIe feature, this is no longer an option.Changes since v7:
* Replaced with Tony Luck's list based version.Changes since v6:
* Added the get/put helpers.
* Special case the creation of the mondata files for the default control group.
* Removed wording about files living longer than expected, the corresponding error handling is wrapped inWARN_ON_ONCE()as this indicates a bug.--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 ++++-- arch/x86/kernel/cpu/resctrl/internal.h | 39 ++++++------ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 78 +++++++++++++++++++++-- 3 files changed, 102 insertions(+), 34 deletions(-)arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1
-4@@ -667,7 +667,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r; -union mon_data_bits md; +struct mon_data *md;int ret =0 ; rdtgrp =rdtgroup_kn_lock_live (of->kn);@@ -676,17 +676,22 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } - md.priv = of->kn->priv; - resid = md.u.rid; - domid = md.u.domid;
arch/x86/kernel/cpu/resctrl/ctrlmondata.c int rdtgroup_mondata_show(struct seq_file *m, void *arg) · line 687
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +9
-1- evtid = md.u.evtid; + md = of->kn->priv; +if (WARN_ON_ONCE (!md)) { + ret = -EIO ; + goto out; + } + + resid = md->rid; + domid = md->domid; + evtid = md->evtid;
What is not visible in this hunk is the types of these variables, which is:
u32 resid, evtid, domid;
These types support the previously used bitfields well but now that the data is provided via a struct it should be possible to use appropriate types and avoid this unnecessary switch between types (more below).
Quoted 24 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2
-2r =resctrl_arch_get_resource (resid); -if (md.u.sum) { +if (md->sum) {/* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the -* mon_data_bits union. Search all domains in the resource for +* struct mon_data. Search all domains in the resource for * one that matches this cache id. */ list_for_each_entry (d, &r->mon_domains, hdr.list) {arch/x86/kernel/cpu/resctrl/internal.h +0
-4@@ -103,27 +103,26 @@ struct mon_evt { };/** -* union mon_data_bits - Monitoring details for each event file. -* @priv: Used to store monitoring event data in @u -* as kernfs private data. -* @u.rid: Resource id associated with the event file.
arch/x86/kernel/cpu/resctrl/internal.h struct mon_evt { · line 107
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-8-* @u.evtid: Event id associated with the event file. -* @u.sum: Set when event must be summed across multiple -* domains. -* @u.domid: When @u.sum is zero this is the domain to which -* the event file belongs. When @sum is one this -* is the id of the L3 cache that all domains to be -* summed share. -* @u: Name of the bit fields struct. +* struct mon_data - Monitoring details for each event file. +* @list: Member of list of all allocated structures.
To help readers this can mention the name of the list. Can simply be
@list: Entry in @listname.
arch/x86/kernel/cpu/resctrl/internal.h struct mon_evt { · line 118
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/internal.h +11
-0+* @rid: Resource id associated with the event file. +* @evtid: Event id associated with the event file. +* @sum: Set when event must be summed across multiple +* domains. +* @domid: When @sum is zero this is the domain to which +* the event file belongs. When @sum is one this +* is the id of the L3 cache that all domains to be +* summed share. +* +* Stored in the kernfs kn->priv field, readers and writers must hold +* rdtgroup_mutex.
"Stored in the kernfs kn->priv field" can be made more specific with, for example, "Pointed to by kernfs kn->priv field of monitoring event file"
Quoted 6 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-5*/ -union mon_data_bits { -void *priv; -struct { -unsigned int rid :10 ; -enum resctrl_event_id evtid :7 ;
arch/x86/kernel/cpu/resctrl/internal.h struct mon_evt { · line 126
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/internal.h +6
-3- unsigned int sum : 1; - unsigned int domid : 14; - } u; +struct mon_data { +struct list_head list; +unsigned int rid; +enum resctrl_event_id evtid; +unsigned int sum; +unsigned int domid; };
The usage of the unsigned int was in support for the bitfield, but now the most appropriate types can be used instead? rid can be int, or even enum resctrl_res_level, domid can be int, and sum can be bool.
Also, every struct in this file follows the custom as documented in maintainer-tip.rst: "Struct declarations should align the struct member names in a tabular fashion". This struct should follow custom.
arch/x86/kernel/cpu/resctrl/rdtgroup.c LIST_HEAD(rdt_all_groups); · line 49
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/internal.h +0
-0/** arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0@@ -45,6 +45,12 @@ LIST_HEAD(rdt_all_groups);/* list of entries for the schemata file */ LIST_HEAD (resctrl_schema_all); +/* +* List of struct mon_data 'priv' structures for rdtgroup_mondata_show().
"struct mon_data 'priv' structures" seems redundant use of struct/structures?
How about:
"List of struct mon_data containing private data of event files for use by rdtgroup_mondata_show()."
arch/x86/kernel/cpu/resctrl/rdtgroup.c LIST_HEAD(rdt_all_groups); · line 52
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0+* Protected by rdtgroup_mutex. +*/ +static LIST_HEAD (kn_priv_list);
Considering all the different "kn" involved in resctrl I find this name very generic for a global variable. I am not sure if something like "mon_data_kn_priv_list" would be considered too long? Open to recommendations.
arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 3101
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5
-0+/* The filesystem can only be mounted once. */ bool resctrl_mounted;@@ -3089,6 +3095,62 @@ static void rmdir_all_sub(void)kernfs_remove (kn_mondata); } +/** +* mon_get_kn_priv() - Get the mon_data priv data for this event. +* +* The same values are used in multiple directories. Keep a list
"The same values are used in multiple directories." is vague. How about "The same values are used across the mon_data directories of all control and monitor groups." Please feel free to improve.
arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 3103
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0+* of allocated structures and re-use an existing one with the same +* list of values for rid, domain, etc.
"list of values" -> "values"?
Also, if using "rid", which is parameter name, why use "domain" instead of "domid"? If using parameter names the kernel-doc "@" can be used for highlighting.
With the many usages of "event type being created" below the above description will be helpful if it could define what is meant with an "event type".
Quoted 79 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +53
-6+* +* @rid: The resource id for the event type being created. +* @domid: The domain id for the event type being created. +* @mevt: The event type being created. +* @do_sum: Whether SNC summing monitors are being created. +*/ +static struct mon_data *mon_get_kn_priv (int rid,int domid, +struct mon_evt *mevt, +bool do_sum) +{ +struct mon_data *priv; + +lockdep_assert_held (&rdtgroup_mutex); + +list_for_each_entry (priv, &kn_priv_list, list) { +if (priv->rid == rid && priv->domid == domid && + priv->sum == do_sum && priv->evtid == mevt->evtid) +return priv; + } + + priv =kzalloc (sizeof (*priv),GFP_KERNEL ); +if (!priv) +return NULL ; + + priv->rid = rid; + priv->domid = domid; + priv->sum = do_sum; + priv->evtid = mevt->evtid; +list_add_tail (&priv->list, &kn_priv_list); + +return priv; +} + +/** +* mon_put_kn_priv() - Free all allocated mon_data structures. +* +* Called when resctrl file system is unmounted. +*/ +static void mon_put_kn_priv (void ) +{ +struct mon_data *priv, *tmp; + +lockdep_assert_held (&rdtgroup_mutex); + +list_for_each_entry_safe (priv, tmp, &kn_priv_list, list) { +list_del (&priv->list); +kfree (priv); + } +} +static void resctrl_fs_teardown (void ) {lockdep_assert_held (&rdtgroup_mutex);@@ -3098,6 +3160,7 @@ static void resctrl_fs_teardown(void)return ;rmdir_all_sub (); +mon_put_kn_priv ();rdt_pseudo_lock_release (); rdtgroup_default.mode =RDT_MODE_SHAREABLE ;closid_exit ();@@ -3204,19 +3267,20 @@ static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain *d, bool do_sum) {struct rmid_read rr = {0 }; -union mon_data_bits priv; +struct mon_data *priv;struct mon_evt *mevt; -int ret; +int ret, domid;if (WARN_ON (list_empty (&r->evt_list)))return -EPERM ; - priv.u.rid = r->rid; - priv.u.domid = do_sum ? d->ci->id : d->hdr.id; - priv.u.sum = do_sum;list_for_each_entry (mevt, &r->evt_list, list) { - priv.u.evtid = mevt->evtid;
arch/x86/kernel/cpu/resctrl/rdtgroup.c static int mon_add_all_files(struct kernfs_node *kn, struct rdt_mon_domain *d, · line 3286
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-1- ret =mon_addfile (kn, mevt->name, priv.priv); + domid = do_sum ? d->ci->id : d->hdr.id; + priv =mon_get_kn_priv (r->rid, domid, mevt, do_sum); +if (WARN_ON_ONCE (!priv)) +return -EINVAL ; + + ret =mon_addfile (kn, mevt->name, priv);if (ret)return ret;
Reinette
James Morse
reviewerRe: [PATCH v8 08/21] x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
Hi Reinette,
Quoted 1 line · Reinette Chatre
There is no occurence of "
dom_id" in patch other than subject.
Fixed.
Quoted 44 lines · James Morse
Quoted 31 lines
MPAM platforms retrieve the cache-id property from the ACPI PPTT table. The cache-id field is 32 bits wide. Under resctrl, the cache-id becomes the domain-id, and is packed into the
mon_data_bitsunion bitfield. The width of cache-id in this field is 14 bits.Expanding the union would break 32bit x86 platforms as this union is stored as the kernfs
kn->privpointer. This saved allocating memory for the priv data storage.The firmware on MPAM platforms have used the PPTT cache-id field to expose the interconnect's id for the cache, which is sparse and uses more than 14 bits. Use of this id is to enable PCIe direct cache injection hints. Using this feature with VFIO means the value provided by the ACPI table should be exposed to user-space.
To support cache-id values greater than 14 bits, convert the
mon_data_bitsunion to a structure. These are shared between control and monitor groups, and are allocated on first use. The list of allocated structmon_datais free'd when the filesystem is umount()ed.arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0
-3@@ -676,17 +676,22 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } - md.priv = of->kn->priv; - resid = md.u.rid; - domid = md.u.domid;arch/x86/kernel/cpu/resctrl/ctrlmondata.c int rdtgroup_mondata_show(struct seq_file *m, void *arg) · line 687
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +9
-1- evtid = md.u.evtid; + md = of->kn->priv; +if (WARN_ON_ONCE (!md)) { + ret = -EIO ; + goto out; + } + + resid = md->rid; + domid = md->domid; + evtid = md->evtid;What is not visible in this hunk is the types of these variables, which is:
Quoted 5 lines
u32 resid, evtid, domid;These types support the previously used bitfields well but now that the data is provided via a struct it should be possible to use appropriate types and avoid this unnecessary switch between types (more below).
Sure, I left them alone as they were already mismatched...
Quoted 29 lines
Quoted 29 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +2
-2r =resctrl_arch_get_resource (resid); -if (md.u.sum) { +if (md->sum) {/* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the -* mon_data_bits union. Search all domains in the resource for +* struct mon_data. Search all domains in the resource for * one that matches this cache id. */ list_for_each_entry (d, &r->mon_domains, hdr.list) {arch/x86/kernel/cpu/resctrl/internal.h +0
-9@@ -103,27 +103,26 @@ struct mon_evt { };/** -* union mon_data_bits - Monitoring details for each event file. -* @priv: Used to store monitoring event data in @u -* as kernfs private data. -* @u.rid: Resource id associated with the event file. -* @u.evtid: Event id associated with the event file. -* @u.sum: Set when event must be summed across multiple -* domains. -* @u.domid: When @u.sum is zero this is the domain to which -* the event file belongs. When @sum is one this
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/internal.h struct mon_evt { · line 107
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/internal.h +2
-3-* is the id of the L3 cache that all domains to be -* summed share. -* @u: Name of the bit fields struct. +* struct mon_data - Monitoring details for each event file. +* @list: Member of list of all allocated structures. To help readers this can mention the name of the list. Can simply be
@list: Entry in @listname.
Sure,
| Member of the global @mon_data_kn_priv_list list.
I was curious how kernel-doc would resolves references like that - turns out its just formatting.
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/internal.h struct mon_evt { · line 118
Quoted 11 lines
arch/x86/kernel/cpu/resctrl/internal.h +11
-0+* @rid: Resource id associated with the event file. +* @evtid: Event id associated with the event file. +* @sum: Set when event must be summed across multiple +* domains. +* @domid: When @sum is zero this is the domain to which +* the event file belongs. When @sum is one this +* is the id of the L3 cache that all domains to be +* summed share. +* +* Stored in the kernfs kn->priv field, readers and writers must hold +* rdtgroup_mutex.
Quoted 2 lines
"Stored in the kernfs
kn->privfield" can be made more specific with, for example, "Pointed to by kernfskn->privfield of monitoring event file"
Sure,
Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/internal.h +3
-8*/ -union mon_data_bits { -void *priv; -struct { -unsigned int rid :10 ; -enum resctrl_event_id evtid :7 ; -unsigned int sum :1 ; -unsigned int domid :14 ; - } u; +struct mon_data { +struct list_head list; +unsigned int rid;
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/internal.h struct mon_evt { · line 126
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/internal.h +3
-0+enum resctrl_event_id evtid; +unsigned int sum; +unsigned int domid; };The usage of the unsigned int was in support for the bitfield, but now the most appropriate types can be used instead? rid can be int, or even enum
resctrl_res_level, domid can be int, and sum can be bool.
Yup. This was just left as is as its the existing behaviour.
Quoted 3 lines
Also, every struct in this file follows the custom as documented in
maintainer-tip.rst: "Struct declarations should align the struct member names in a tabular fashion". This struct should follow custom.
Fixed.
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0@@ -45,6 +45,12 @@ LIST_HEAD(rdt_all_groups);/* list of entries for the schemata file */ LIST_HEAD (resctrl_schema_all);
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c LIST_HEAD(rdt_all_groups); · line 49
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0+/* +* List of struct mon_data 'priv' structures for rdtgroup_mondata_show(). "struct
mon_data'priv' structures" seems redundant use of struct/structures?
Heh, this is because I go back and add 'struct' before structure names as a second pass.
Quoted 2 lines
How about:
"List of structmon_datacontaining private data of event files for use byrdtgroup_mondata_show()."
Done!
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c LIST_HEAD(rdt_all_groups); · line 52
Quoted 3 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3
-0+* Protected by rdtgroup_mutex. +*/ +static LIST_HEAD (kn_priv_list);Considering all the different "kn" involved in resctrl I find this name very generic for a global variable. I am not sure if something like "
mon_data_kn_priv_list" would be considered too long? Open to recommendations.
Its suitably descriptive and doesn't cause a line length problems. Done.
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-0+/* The filesystem can only be mounted once. */ bool resctrl_mounted;@@ -3089,6 +3095,62 @@ static void rmdir_all_sub(void)kernfs_remove (kn_mondata); }
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 3101
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4
-0+/** +* mon_get_kn_priv() - Get the mon_data priv data for this event. +* +* The same values are used in multiple directories. Keep a list "The same values are used in multiple directories." is vague. How about "The same values are used across the
mon_datadirectories of all control and monitor groups." Please feel free to improve.
I've tacked "for the same event in the same domain" on the end, otherwise it reads like there is a single set of values.
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 3103
Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2
-0+* of allocated structures and re-use an existing one with the same +* list of values for rid, domain, etc. "list of values" -> "values"?
Fixed,
Quoted 3 lines
Also, if using "rid", which is parameter name, why use "domain" instead of "domid"? If using parameter names the kernel-doc "@" can be used for highlighting.
Done,
Quoted 2 lines
With the many usages of "event type being created" below the above description will be helpful if it could define what is meant with an "event type".
I'll change these to 'event file', which at least matches the earlier comments.
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 3112
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9
-0+* +* @rid: The resource id for the event type being created. +* @domid: The domain id for the event type being created. +* @mevt: The event type being created. +* @do_sum: Whether SNC summing monitors are being created. +*/ +static struct mon_data *mon_get_kn_priv (int rid,int domid, +struct mon_evt *mevt, +bool do_sum)
Thanks,
James
Re: [PATCH v8 08/21] x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
In reply to James MorseHi James,
Quoted 141 lines · James Morse
MPAM platforms retrieve the cache-id property from the ACPI PPTT table. The cache-id field is 32 bits wide. Under resctrl, the cache-id becomes the domain-id, and is packed into the
mon_data_bitsunion bitfield. The width of cache-id in this field is 14 bits.Expanding the union would break 32bit x86 platforms as this union is stored as the kernfs
kn->privpointer. This saved allocating memory for the priv data storage.The firmware on MPAM platforms have used the PPTT cache-id field to expose the interconnect's id for the cache, which is sparse and uses more than 14 bits. Use of this id is to enable PCIe direct cache injection hints. Using this feature with VFIO means the value provided by the ACPI table should be exposed to user-space.
To support cache-id values greater than 14 bits, convert the
mon_data_bitsunion to a structure. These are shared between control and monitor groups, and are allocated on first use. The list of allocated structmon_datais free'd when the filesystem is umount()ed.Co-developed-by Tony Luck <[email protected]>Signed-off-by Tony Luck <[email protected]>Signed-off-by James Morse <[email protected]>---
Previously the MPAM tree repainted the cache-id to compact them, argue-ing there was no other user. With VFIO use of this PCIe feature, this is no longer an option.Changes since v7:
* Replaced with Tony Luck's list based version.Changes since v6:
* Added the get/put helpers.
* Special case the creation of the mondata files for the default control group.
* Removed wording about files living longer than expected, the corresponding error handling is wrapped inWARN_ON_ONCE()as this indicates a bug.--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 ++++-- arch/x86/kernel/cpu/resctrl/internal.h | 39 ++++++------ arch/x86/kernel/cpu/resctrl/rdtgroup.c | 78 +++++++++++++++++++++-- 3 files changed, 102 insertions(+), 34 deletions(-)arch/x86/kernel/cpu/resctrl/ctrlmondata.c +12
-7@@ -667,7 +667,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)u32 resid, evtid, domid;struct rdtgroup *rdtgrp;struct rdt_resource *r; -union mon_data_bits md; +struct mon_data *md;int ret =0 ; rdtgrp =rdtgroup_kn_lock_live (of->kn);@@ -676,17 +676,22 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg) goto out; } - md.priv = of->kn->priv; - resid = md.u.rid; - domid = md.u.domid; - evtid = md.u.evtid; + md = of->kn->priv; +if (WARN_ON_ONCE (!md)) { + ret = -EIO ; + goto out; + } + + resid = md->rid; + domid = md->domid; + evtid = md->evtid; r =resctrl_arch_get_resource (resid); -if (md.u.sum) { +if (md->sum) {/* * This file requires summing across all domains that share * the L3 cache id that was provided in the "domid" field of the -* mon_data_bits union. Search all domains in the resource for +* struct mon_data. Search all domains in the resource for * one that matches this cache id. */ list_for_each_entry (d, &r->mon_domains, hdr.list) {arch/x86/kernel/cpu/resctrl/internal.h +19
-20@@ -103,27 +103,26 @@ struct mon_evt { };/** -* union mon_data_bits - Monitoring details for each event file. -* @priv: Used to store monitoring event data in @u -* as kernfs private data. -* @u.rid: Resource id associated with the event file. -* @u.evtid: Event id associated with the event file. -* @u.sum: Set when event must be summed across multiple -* domains. -* @u.domid: When @u.sum is zero this is the domain to which -* the event file belongs. When @sum is one this -* is the id of the L3 cache that all domains to be -* summed share. -* @u: Name of the bit fields struct. +* struct mon_data - Monitoring details for each event file. +* @list: Member of list of all allocated structures. +* @rid: Resource id associated with the event file. +* @evtid: Event id associated with the event file. +* @sum: Set when event must be summed across multiple +* domains. +* @domid: When @sum is zero this is the domain to which +* the event file belongs. When @sum is one this +* is the id of the L3 cache that all domains to be +* summed share. +* +* Stored in the kernfs kn->priv field, readers and writers must hold +* rdtgroup_mutex. */ -union mon_data_bits { -void *priv; -struct { -unsigned int rid :10 ; -enum resctrl_event_id evtid :7 ; -unsigned int sum :1 ; -unsigned int domid :14 ; - } u; +struct mon_data { +struct list_head list; +unsigned int rid; +enum resctrl_event_id evtid; +unsigned int sum; +unsigned int domid; };/** arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0
arch/x86/kernel/cpu/resctrl/rdtgroup.c LIST_HEAD(rdt_all_groups); · line 53
Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6
-0@@ -45,6 +45,12 @@ LIST_HEAD(rdt_all_groups);/* list of entries for the schemata file */ LIST_HEAD (resctrl_schema_all); +/* +* List of struct mon_data 'priv' structures for rdtgroup_mondata_show(). +* Protected by rdtgroup_mutex. +*/ +static LIST_HEAD (kn_priv_list); +
Do we really need to maintain a separate list for all the private pointers?
Here's my understanding of the patch—please correct me if I’m missing anything:
Patch Requirements:
1. Expand dom_id.
2. Pack all necessary data (dom_id, event_id, resid) into the of->kn->priv pointer when creating event files in the mon_data directory for each domain.
3. Dynamically allocate the priv structure during event file creation for each domain.
4. Free the priv structure when the mon_data directory is deleted in each domain.
From what I can see, the global list "kn_priv_list" seems relevant only for step 4.
Wouldn’t it be possible to handle this directly in rdtgroup_rmdir_mon() and rdtgroup_rmdir_ctrl()?
We could retrieve the kernfs_node for each file using kernfs_find_and_get().
Thanks,
Babu
Luck, Tony
maintainerRE: [PATCH v8 08/21] x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
Quoted 5 lines
Do we really need to maintain a separate list for all the private pointers?
Here's my understanding of the patch—please correct me if I’m missing anything:
Quoted 7 lines
Patch Requirements:
1. Expand
dom_id.2. Pack all necessary data (
dom_id,event_id, resid) into theof->kn->privpointer when creating event files in themon_datadirectory for each domain.
This step includes searching the list of previously created priv structures to find a matching one that can be shared. This happens all the time because the same set of values is re-used over and over. Essentially we only allocate anything while creating the mon_data directory in the root directory of resctrl. James' original implementation made use of this by special case allocation for the default group, and then doing kernfs lookups while creating new groups to find the matching one and linking to the same ->priv pointer.
-Tony
Re: RE: [PATCH v8 08/21] x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
Hi Tony,
Quoted 13 lines · Tony
Quoted 5 lines
Do we really need to maintain a separate list for all the private pointers?
Here's my understanding of the patch—please correct me if I’m missing anything:
Quoted 7 lines
Patch Requirements:
1. Expand
dom_id.2. Pack all necessary data (
dom_id,event_id, resid) into theof->kn->privpointer when creating event files in themon_datadirectory for each domain.
Quoted 9 lines
This step includes searching the list of previously created priv structures to find a matching one that can be shared. This happens all the time because the same set of values is re-used over and over. Essentially we only allocate anything while creating the
mon_datadirectory in the root directory of resctrl. James' original implementation made use of this by special case allocation for the default group, and then doing kernfs lookups while creating new groups to find the matching one and linking to the same ->priv pointer.
oh ok.
I went back and looked at the history.
https://lore.kernel.org/all/[email protected]/
So you are saying, kernfs lookup method is much more complex. So, having the global list is easy to traverse and efficient?
Thanks
Babu
Luck, Tony
maintainerRE: RE: [PATCH v8 08/21] x86/resctrl: Expand the width of dom_id by replacing mon_data_bits
Quoted 11 lines
Quoted 3 lines
kernfs lookups while creating new groups to find the matching one and linking to the same ->priv pointer.
oh ok.
I went back and looked at the history.
https://lore.kernel.org/all/[email protected]/So you are saying, kernfs lookup method is much more complex. So, having the global list is easy to traverse and efficient?
Complexity in the code to construct the path and do kernfs lookups to walk that path (since kernfs doesn't provide a routine to do the path walk, just individual directory lookups). There was some doubt whether James' code got things right for the SNC case which has an extra sub-level of directories.
The latest version is far simpler to review and decide it is doing the right thing in all configurations.
-Tony
James Morse
reviewerPATCH v8 9/21 x86/resctrl: Remove a newline to avoid confusing the code move script
In reply to James MorseThe resctrl filesystem code will shortly be moved to /fs/. This involves splitting all the existing files, with some functions remaining under arch/x86, and others moving to fs/resctrl.
To make this reproducible, a python script does the heavy lif^W copy-and-paste. This involves some clunky parsing of C code.
The parser gets confused by the newline after this #ifdef. Just remove it.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
@@ -899,7 +899,6 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of, }#ifdef CONFIG_PROC_CPU_RESCTRL -/* * A task can only be part of one resctrl control group and of one monitor * group which is associated to that control group.
Signature · 1 line
2.20.1
RE: [PATCH v8 09/21] x86/resctrl: Remove a newline to avoid confusing the code move script
Hello
Quoted 6 lines
The resctrl filesystem code will shortly be moved to /fs/. This involves splitting all the existing files, with some functions remaining under
arch/x86, and others moving to fs/resctrl.To make this reproducible, a python script does the heavy lif^W copy-and-paste. This involves some clunky parsing of C code.
Is "lif^W" a typo?
Best regards,
Shaopeng TAN
Quoted 33 lines
The parser gets confused by the newline after this #ifdef. Just remove it.
Signed-off-by James Morse <[email protected]>Tested-by Carl Worth <[email protected]> # arm64Tested-by Shaopeng Tan <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Babu Moger <[email protected]>Reviewed-by Shaopeng Tan <[email protected]>Reviewed-by Tony Luck <[email protected]>Reviewed-by Reinette Chatre <[email protected]>Reviewed-by Fenghua Yu <[email protected]>--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 1 - 1 file changed, 1 deletion(-)arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-2@@ -899,7 +899,6 @@ static int rdtgroup_rmid_show(struct kernfs_open_file *of, }#ifdef CONFIG_PROC_CPU_RESCTRL -/* * A task can only be part of one resctrl control group and of one monitor * group which is associated to that control group. -- 2.20.1
James Morse
reviewerRe: [PATCH v8 09/21] x86/resctrl: Remove a newline to avoid confusing the code move script
Hello!
Quoted 9 lines · Shaopeng Tan (Fujitsu)
Hello
Quoted 6 lines
The resctrl filesystem code will shortly be moved to /fs/. This involves splitting all the existing files, with some functions remaining under
arch/x86, and others moving to fs/resctrl.To make this reproducible, a python script does the heavy lif^W copy-and-paste. This involves some clunky parsing of C code.
Is "lif^W" a typo?
No - its a bad joke.
Control-W will delete the previous word on the prompt. I'm suggesting the python script is doing some real work - when it reality its a glorified copy-and-paste.
I'll move this patch later in the series so it can be easily squashed into the move - there is no need to preserve this kind of history.
Thanks!
James
James Morse
reviewerPATCH v8 10/21 x86/resctrl: Split trace.h
In reply to James Morsetrace.h contains all the tracepoints. After the move to /fs/resctrl, some of these will be left behind. All the pseudo_lock tracepoints remain part of the architecture. The lone tracepoint in monitor.c moves to /fs/resctrl.
Split trace.h so that each C file includes a different trace header file. This means the trace header files are not modified when they are moved.
---
arch/x86/kernel/cpu/resctrl/Makefile | 3 ++
arch/x86/kernel/cpu/resctrl/monitor.c | 4 ++-
arch/x86/kernel/cpu/resctrl/monitor_trace.h | 31 +++++++++++++++++++
arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +-
.../resctrl/{trace.h => pseudo_lock_trace.h} | 24 +++-----------
5 files changed, 42 insertions(+), 22 deletions(-)
create mode 100644 arch/x86/kernel/cpu/resctrl/monitor_trace.h
rename arch/x86/kernel/cpu/resctrl/{trace.h => pseudo_lock_trace.h} (56%)arch/x86/kernel/cpu/resctrl/Makefile +3 -0
@@ -2,4 +2,7 @@ obj-$(CONFIG_X86_CPU_RESCTRL) += core.o rdtgroup.o monitor.o obj-$(CONFIG_X86_CPU_RESCTRL) += ctrlmondata.o obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK) += pseudo_lock.o + +# To allow define_trace.h's recursive include: CFLAGS_pseudo_lock.o = -I$(src) +CFLAGS_monitor.o = -I$(src)
arch/x86/kernel/cpu/resctrl/monitor.c +3 -1
@@ -26,7 +26,9 @@#include <asm/resctrl.h> #include "internal.h" -#include "trace.h" + +#define CREATE_TRACE_POINTS +#include "monitor_trace.h" /** * struct rmid_entry - dirty tracking for all RMID.
arch/x86/kernel/cpu/resctrl/monitor_trace.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM resctrl + +#if !defined(_FS_RESCTRL_MONITOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _FS_RESCTRL_MONITOR_TRACE_H + +#include <linux/tracepoint.h> + +TRACE_EVENT (mon_llc_occupancy_limbo, + TP_PROTO(u32 ctrl_hw_id, u32 mon_hw_id, int domain_id, u64 llc_occupancy_bytes), +TP_ARGS (ctrl_hw_id, mon_hw_id, domain_id, llc_occupancy_bytes), + TP_STRUCT__entry(__field(u32, ctrl_hw_id) + __field(u32, mon_hw_id) + __field(int, domain_id) +__field (u64, llc_occupancy_bytes)), + TP_fast_assign(__entry->ctrl_hw_id = ctrl_hw_id; + __entry->mon_hw_id = mon_hw_id; + __entry->domain_id = domain_id; + __entry->llc_occupancy_bytes = llc_occupancy_bytes;), +TP_printk ("ctrl_hw_id=%u mon_hw_id=%u domain_id=%d llc_occupancy_bytes=%llu" , + __entry->ctrl_hw_id, __entry->mon_hw_id, __entry->domain_id, + __entry->llc_occupancy_bytes) + ); + +#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_FILE monitor_trace +#include <trace/define_trace.h>
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
@@ -30,7 +30,7 @@#include "internal.h" #define CREATE_TRACE_POINTS -#include "trace.h" +#include "pseudo_lock_trace.h" /* * The bits needed to disable hardware prefetching varies based on the
arch/x86/kernel/cpu/resctrl/pseudo_lock_trace.h renamed from arch/x86/kernel/cpu/resctrl/trace.h +4 -20
@@ -2,8 +2,8 @@#undef TRACE_SYSTEM#define TRACE_SYSTEM resctrl -#if !defined(_TRACE_RESCTRL_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _TRACE_RESCTRL_H +#if !defined(_X86_RESCTRL_PSEUDO_LOCK_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _X86_RESCTRL_PSEUDO_LOCK_TRACE_H#include <linux/tracepoint.h>
@@ -35,25 +35,9 @@ TRACE_EVENT(pseudo_lock_l3,TP_printk ("hits=%llu miss=%llu" , __entry->l3_hits, __entry->l3_miss)); -TRACE_EVENT (mon_llc_occupancy_limbo, - TP_PROTO(u32 ctrl_hw_id, u32 mon_hw_id, int domain_id, u64 llc_occupancy_bytes), -TP_ARGS (ctrl_hw_id, mon_hw_id, domain_id, llc_occupancy_bytes), - TP_STRUCT__entry(__field(u32, ctrl_hw_id) - __field(u32, mon_hw_id) - __field(int, domain_id) -__field (u64, llc_occupancy_bytes)), - TP_fast_assign(__entry->ctrl_hw_id = ctrl_hw_id; - __entry->mon_hw_id = mon_hw_id; - __entry->domain_id = domain_id; - __entry->llc_occupancy_bytes = llc_occupancy_bytes;), -TP_printk ("ctrl_hw_id=%u mon_hw_id=%u domain_id=%d llc_occupancy_bytes=%llu" , - __entry->ctrl_hw_id, __entry->mon_hw_id, __entry->domain_id, - __entry->llc_occupancy_bytes) - ); - -#endif /* _TRACE_RESCTRL_H */ +#endif /* _X86_RESCTRL_PSEUDO_LOCK_TRACE_H */ #undef TRACE_INCLUDE_PATH#define TRACE_INCLUDE_PATH . -#define TRACE_INCLUDE_FILE trace +#define TRACE_INCLUDE_FILE pseudo_lock_trace#include <trace/define_trace.h>
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 11/21 fs/resctrl: Add boiler plate for external resctrl code
In reply to James MorseAdd 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.
---
Changes since v6:
* Added 'depends on RESCTRL_FS' to the hidden kconfig options.
Changes since v5:
* Removed double include.
* Removed duplicate pseudo lock Kconfig define
* Grammar fix and closid capitalisation change.
Changes since v4:
* Tweaking of the commit message.
Changes since v3:
* Reworded 'if unsure say N' from the Kconfig text, the user doesn't have the choice anyway at this point.
* Added PWD to monitor.o's CFLAGS for the ftrace rube-goldberg build machine.
* Added split trace files.
Changes since v2:
* Dropped KERNFS dependency from arch side Kconfig.
* Added empty trace.h file.
* Merged asm->linux includes from Dave's patch to decouple those patches from this series.
Changes since v1:
* Rename new file psuedo_lock.c to pseudo_lock.c, to match the name of the original file (and to be less surprising).
* [Whitespace only] Under RESCTRL_FS in fs/resctrl/Kconfig, delete alignment space in orphaned select ... if (which has nothing to line up with any more).
* [Whitespace only] Reflow and re-tab Kconfig additions.
--- MAINTAINERS | 1 + arch/Kconfig | 8 +++++ arch/x86/Kconfig | 11 ++----- arch/x86/kernel/cpu/resctrl/internal.h | 2 -- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- fs/Kconfig | 1 + fs/Makefile | 1 + fs/resctrl/Kconfig | 39 +++++++++++++++++++++++ fs/resctrl/Makefile | 6 ++++ fs/resctrl/ctrlmondata.c | 0 fs/resctrl/internal.h | 0 fs/resctrl/monitor.c | 0 fs/resctrl/monitor_trace.h | 0 fs/resctrl/pseudo_lock.c | 0 fs/resctrl/pseudo_lock_trace.h | 0 fs/resctrl/rdtgroup.c | 0 include/linux/resctrl.h | 4 +++ 19 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 fs/resctrl/Kconfig create mode 100644 fs/resctrl/Makefile create mode 100644 fs/resctrl/ctrlmondata.c create mode 100644 fs/resctrl/internal.h create mode 100644 fs/resctrl/monitor.c create mode 100644 fs/resctrl/monitor_trace.h create mode 100644 fs/resctrl/pseudo_lock.c create mode 100644 fs/resctrl/pseudo_lock_trace.h create mode 100644 fs/resctrl/rdtgroup.c
MAINTAINERS +1 -0
@@ -20284,6 +20284,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/
arch/Kconfig +8 -0
@@ -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
arch/x86/Kconfig +3 -8
@@ -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
arch/x86/kernel/cpu/resctrl/internal.h +0 -2
@@ -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
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -19,11 +19,11 @@#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"
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1
@@ -18,12 +18,12 @@#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() */
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -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);
fs/Kconfig +1 -0
@@ -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"
fs/Makefile +1 -0
@@ -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/
fs/resctrl/Kconfig new file +39 -0
@@ -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.
fs/resctrl/Makefile new file +6 -0
@@ -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)
fs/resctrl/ctrlmondata.c new file +0 -0
fs/resctrl/internal.h new file +0 -0
fs/resctrl/monitor.c new file +0 -0
fs/resctrl/monitor_trace.h new file +0 -0
fs/resctrl/pseudo_lock.c new file +0 -0
fs/resctrl/pseudo_lock_trace.h new file +0 -0
fs/resctrl/rdtgroup.c new file +0 -0
include/linux/resctrl.h +4 -0
@@ -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
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 12/21 x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl
In reply to James MorseOnce the filesystem parts of resctrl move to fs/resctrl, it cannot rely on definitions in x86's internal.h.
Move definitions in internal.h that need to be shared between the filesystem and architecture code to header files that fs/resctrl can include.
Doing this separately means the filesystem code only moves between files of the same name, instead of having these changes mixed in too.
---
Changes since v6:
* Moved resctrl_arch_set_cdp_enabled() to rdtgroup.c instead of core.c
Changes since v3:
* Changed the number of hyphens at the end of the commit message.
Changes since v2:
* Dropped the rfflags and some other defines from being moved.
Changes since v1:
* Revert apparently unintentional duplication of a couple of variable declarations in <linux/resctrl.h>.
No functional change.
--- arch/x86/include/asm/resctrl.h | 3 +++ arch/x86/kernel/cpu/resctrl/internal.h | 9 --------- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 +++++ include/linux/resctrl_types.h | 3 +++ 4 files changed, 11 insertions(+), 9 deletions(-)
arch/x86/include/asm/resctrl.h +3 -0
@@ -210,6 +210,9 @@ int resctrl_arch_measure_l2_residency(void *_plr);int resctrl_arch_measure_l3_residency (void *_plr);void resctrl_cpu_detect (struct cpuinfo_x86 *c); +bool resctrl_arch_get_cdp_enabled (enum resctrl_res_level l); +int resctrl_arch_set_cdp_enabled (enum resctrl_res_level l,bool enable); +#else static inline void resctrl_arch_sched_in (struct task_struct *tsk) {}
arch/x86/kernel/cpu/resctrl/internal.h +0 -9
@@ -16,8 +16,6 @@#define CQM_LIMBOCHECK_INTERVAL 1000#define MBM_CNTR_WIDTH_BASE 24 -#define MBM_OVERFLOW_INTERVAL 1000 -#define MAX_MBA_BW 100u#define MBA_IS_LINEAR 0x4#define MBM_CNTR_WIDTH_OFFSET_AMD 20
@@ -410,13 +408,6 @@ extern struct rdtgroup rdtgroup_default;extern struct dentry *debugfs_resctrl;extern enum resctrl_event_id mba_mbps_default_event; -static inline bool resctrl_arch_get_cdp_enabled (enum resctrl_res_level l) -{ -return rdt_resources_all[l].cdp_enabled; -} - -int resctrl_arch_set_cdp_enabled (enum resctrl_res_level l,bool enable); -void arch_mon_domain_online (struct rdt_resource *r,struct rdt_mon_domain *d);/* CPUID.(EAX=10H, ECX=ResID=1).EAX */
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -0
@@ -2536,6 +2536,11 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable)return 0 ; } +bool resctrl_arch_get_cdp_enabled (enum resctrl_res_level l) +{ +return rdt_resources_all[l].cdp_enabled; +} +/* * We don't allow rdtgroup directories to be created anywhere * except the root directory. Thus when looking for the rdtgroup
include/linux/resctrl_types.h +3 -0
@@ -7,6 +7,9 @@#ifndef __LINUX_RESCTRL_TYPES_H#define __LINUX_RESCTRL_TYPES_H +#define MAX_MBA_BW 100u +#define MBM_OVERFLOW_INTERVAL 1000 +/* Reads to Local DRAM Memory */ #define READS_TO_LOCAL_MEM BIT(0)
Signature · 1 line
2.20.1
Reinette Chatre
maintainerRe: [PATCH v8 12/21] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl
Hi James,
arch/x86/include/asm/resctrl.h int resctrl_arch_measure_l2_residency(void *_plr); · line 216
Quoted 12 lines
arch/x86/include/asm/resctrl.h +3
-0@@ -210,6 +210,9 @@ int resctrl_arch_measure_l2_residency(void *_plr);int resctrl_arch_measure_l3_residency (void *_plr);void resctrl_cpu_detect (struct cpuinfo_x86 *c); +bool resctrl_arch_get_cdp_enabled (enum resctrl_res_level l); +int resctrl_arch_set_cdp_enabled (enum resctrl_res_level l,bool enable); +#else
I noticed this while reading through the telemetry work ... the custom appears to be for all arch helpers to be declared in include/linux/resctrl.h making these two stand out. What motivated their inclusion into arch/x86/include/asm/resctrl.h?
If they move to include/linux/resctrl.h it looks like enum resctrl_res_level is no longer required to be in include/linux/resctrl_types.h.
Looking further, from commit f16adbaf9272 ("x86/resctrl: Move resctrl types to a separate header") the motivation for including enum resctrl_event_id is to support resctrl_arch_mon_ctx_alloc() and resctrl_arch_mon_ctx_free(), but looking
at their definitions in arch/x86/include/asm/resctrl.h they are using "int evtid" instead of enum resctrl_event_id. Looks like their definitions need to
change?
I assume the pseudo-locking arch helpers are placed in arch/x86/include/asm/resctrl.h with the implicit knowledge that only x86 will set CONFIG_RESCTRL_FS_PSEUDO_LOCK so avoiding that extra handling in include/linux/resctrl.h?
Reinette
James Morse
reviewerRe: [PATCH v8 12/21] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl
Hi Reinette,
Quoted 8 lines · Reinette Chatre
Quoted 8 lines
arch/x86/include/asm/resctrl.h +0
-0@@ -210,6 +210,9 @@ int resctrl_arch_measure_l2_residency(void *_plr);int resctrl_arch_measure_l3_residency (void *_plr);void resctrl_cpu_detect (struct cpuinfo_x86 *c);
Quoted 7 lines
arch/x86/include/asm/resctrl.h int resctrl_arch_measure_l2_residency(void *_plr); · line 214
Quoted 2 lines
arch/x86/include/asm/resctrl.h +2
-0+bool resctrl_arch_get_cdp_enabled (enum resctrl_res_level l); +int resctrl_arch_set_cdp_enabled (enum resctrl_res_level l,bool enable);I noticed this while reading through the telemetry work ... the custom appears to be for all arch helpers to be declared in
include/linux/resctrl.hmaking these two stand out. What motivated their inclusion intoarch/x86/include/asm/resctrl.h?
Doing some archaeology ... it looks like this dates from the era when MPAM had stub versions of these because it didn't support/emulate CDP. Having these in the arch code's header meant the static-inline stubs could be inlined into resctrl. x86 has an inline version before this patch, but I moved it out of line to avoid exposing the array of all resources. (which in turn would suggest changing the name, which isn't worth the churn)
I was assuming only x86 would ever support CDP, but since then, emulating CDP using the separate I/D PARTID values MPAM has proved feasible.
I'll move them.
Quoted 2 lines
If they move to
include/linux/resctrl.hit looks like enumresctrl_res_levelis no longer required to be ininclude/linux/resctrl_types.h.
Yes. I'll add a patch move it, but it feels like churn.
Quoted 6 lines
Looking further, from commit
f16adbaf9272("x86/resctrl: Move resctrl types to a separate header") the motivation for including enumresctrl_event_idis to supportresctrl_arch_mon_ctx_alloc()andresctrl_arch_mon_ctx_free(), but looking
at their definitions inarch/x86/include/asm/resctrl.hthey are using "int evtid" instead of enumresctrl_event_id. Looks like their definitions need to
change?
Bother. The MPAM definition of those has the enum type, I'd missed that the x86 stub swallowed the type. I'll fix that.
Quoted 3 lines
I assume the pseudo-locking arch helpers are placed in
arch/x86/include/asm/resctrl.hwith the implicit knowledge that only x86 will setCONFIG_RESCTRL_FS_PSEUDO_LOCKso avoiding that extra handling ininclude/linux/resctrl.h?
Given how specific that is to x86, I think it will only ever be enabled there. For arm, things like the prefetcher can't be disabled by linux. I would assume risc-v is structurally the same.
Those definitions went into the arch header so that some architectures could inline the stubs to let the compiler remove code that will never run.
I guess these could be defined both ways round in linux/resctrl.h depending on the Kconfig symbol. At this point its churn, but this saves a third architecture having to define the same list of stubs. (I reckon that is likely for risc-v).
Thanks,
James
James Morse
reviewerPATCH v8 13/21 x86/resctrl: Squelch whitespace anomalies in resctrl core code
In reply to James MorseFrom: Dave Martin <[email protected]>
checkpatch.pl complains about some whitespace anomalies in the resctrl core code.
This doesn't matter, but since this code is about to be factored out and made generic, this is a good opportunity to fix these issues and so reduce future checkpatch fuzz.
Fix them.
No functional change.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -7
@@ -1019,7 +1019,7 @@ static int rdt_num_closids_show(struct kernfs_open_file *of, }static int rdt_default_ctrl_show (struct kernfs_open_file *of, -struct seq_file *seq,void *v) +struct seq_file *seq,void *v) {struct resctrl_schema *s =rdt_kn_parent_priv (of->kn);struct rdt_resource *r = s->res;
@@ -1029,7 +1029,7 @@ static int rdt_default_ctrl_show(struct kernfs_open_file *of, }static int rdt_min_cbm_bits_show (struct kernfs_open_file *of, -struct seq_file *seq,void *v) +struct seq_file *seq,void *v) {struct resctrl_schema *s =rdt_kn_parent_priv (of->kn);struct rdt_resource *r = s->res;
@@ -1145,7 +1145,7 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of, }static int rdt_min_bw_show (struct kernfs_open_file *of, -struct seq_file *seq,void *v) +struct seq_file *seq,void *v) {struct resctrl_schema *s =rdt_kn_parent_priv (of->kn);struct rdt_resource *r = s->res;
@@ -1180,7 +1180,7 @@ static int rdt_mon_features_show(struct kernfs_open_file *of, }static int rdt_bw_gran_show (struct kernfs_open_file *of, -struct seq_file *seq,void *v) +struct seq_file *seq,void *v) {struct resctrl_schema *s =rdt_kn_parent_priv (of->kn);struct rdt_resource *r = s->res;
@@ -1190,7 +1190,7 @@ static int rdt_bw_gran_show(struct kernfs_open_file *of, }static int rdt_delay_linear_show (struct kernfs_open_file *of, -struct seq_file *seq,void *v) +struct seq_file *seq,void *v) {struct resctrl_schema *s =rdt_kn_parent_priv (of->kn);struct rdt_resource *r = s->res;
@@ -2063,7 +2063,6 @@ static struct rftype res_common_files[] = { .seq_show = rdtgroup_closid_show, .fflags = RFTYPE_CTRL_BASE | RFTYPE_DEBUG, }, - };static int rdtgroup_add_files (struct kernfs_node *kn,unsigned long fflags)
@@ -3622,7 +3621,6 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)rdt_last_cmd_puts ("Failed to initialize allocations\n" ); goto out; } - } rdtgrp->mode =RDT_MODE_SHAREABLE ;
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 14/21 x86/resctrl: Prefer alloc(sizeof(*foo)) idiom in rdt_init_fs_context()
In reply to James MorseFrom: Dave Martin <[email protected]>
rdt_init_fs_context() sizes a typed allocation using an explicit sizeof(type) expression, which checkpatch.pl complains about.
Since this code is about to be factored out and made generic, this is a good opportunity to fix the code to size the allocation based on the target pointer instead, to reduce the chance of future mis- maintenance.
Fix it.
No functional change.
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -2946,7 +2946,7 @@ static int rdt_init_fs_context(struct fs_context *fc) {struct rdt_fs_context *ctx; - ctx =kzalloc (sizeof (struct rdt_fs_context ),GFP_KERNEL ); + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL );if (!ctx)return -ENOMEM ;
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 15/21 x86/resctrl: Relax some asm #includes
In reply to James MorseFrom: Dave Martin <[email protected]>
checkpatch.pl identifies some direct #includes of asm headers that can be satisfied by including the corresponding <linux/...> header instead.
Fix them.
No intentional functional change.
---
Changes since v2:
* asm->linux for resctrl.h moved into an earlier patch.
--- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +2 -1
@@ -11,6 +11,8 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/cacheflush.h> +#include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/cpumask.h> #include <linux/debugfs.h>
@@ -22,7 +24,6 @@#include <linux/slab.h> #include <linux/uaccess.h> -#include <asm/cacheflush.h> #include <asm/cpu_device_id.h> #include <asm/perf_event.h>
Signature · 1 line
2.20.1
Re: [PATCH v8 15/21] x86/resctrl: Relax some asm #includes
Hi James,
Quoted 10 lines · James Morse
From: Dave Martin <[email protected]>
checkpatch.pl identifies some direct #includes of asm headers that can be satisfied by including the corresponding <linux/...> header instead.
Fix them.
No intentional functional change.
Quoted 8 lines
Signed-off-by Dave Martin <[email protected]>Signed-off-by James Morse <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>Tested-by Babu Moger <[email protected]>---
Reinette
James Morse
reviewerPATCH v8 16/21 x86/resctrl: Always initialise rid field in rdt_resources_all[]
In reply to James Morsex86 has an array, rdt_resources_all[], of all possible resources. The for-each-resource walkers depend on the rid field of all resources being initialised.
If the array ever grows due to another architecture adding a resource type that is not defined on x86, the for-each-resources walkers will loop forever.
Initialise all the rid values in resctrl_arch_late_init() before any for-each-resource walker can be called.
---
Changes since v7:
* Split out of a previous patch due to a botched merged conflict.
--- arch/x86/kernel/cpu/resctrl/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +5 -5
@@ -60,7 +60,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_L3] = { .r_resctrl = { - .rid = RDT_RESOURCE_L3, .name = "L3", .ctrl_scope = RESCTRL_L3_CACHE, .mon_scope = RESCTRL_L3_CACHE,
@@ -74,7 +73,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_L2] = { .r_resctrl = { - .rid = RDT_RESOURCE_L2, .name = "L2", .ctrl_scope = RESCTRL_L2_CACHE, .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L2),
@@ -86,7 +84,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_MBA] = { .r_resctrl = { - .rid = RDT_RESOURCE_MBA, .name = "MB", .ctrl_scope = RESCTRL_L3_CACHE, .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_MBA),
@@ -96,7 +93,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_SMBA] = { .r_resctrl = { - .rid = RDT_RESOURCE_SMBA, .name = "SMBA", .ctrl_scope = RESCTRL_L3_CACHE, .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_SMBA),
@@ -996,7 +992,11 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)static int __init resctrl_arch_late_init (void ) {struct rdt_resource *r; -int state, ret; +int state, ret, i; + +/* Initialise all rid values for_each_rdt_resource() */ +for (i =0 ; i <RDT_NUM_RESOURCES ; i++) + rdt_resources_all[i].r_resctrl.rid = i;/* * Initialize functions(or definitions) that are different
Signature · 1 line
2.20.1
Luck, Tony
maintainerRe: [PATCH v8 16/21] x86/resctrl: Always initialise rid field in rdt_resources_all[]
Quoted 7 lines · James Morse
x86 has an array, rdt_resources_all[], of all possible resources. The for-each-resource walkers depend on the rid field of all resources being initialised.
If the array ever grows due to another architecture adding a resource type that is not defined on x86, the for-each-resources walkers will loop forever.
This feels a bit weird. Having rdt_resources_all[] be a "swiss cheese" array full of holes where other architectures defined events that aren't supported by x86.
But it does work, so it can go in like this. But someday I may revisit some experimental patches I did a while back that:
1) Split the rdt_resource structure into separate "ctrl" and "mon" pieces.
2) Replaced this array with a pair of lists, one each for enabled ctrl and mon resources.
3) Changed the resource walkers to use list_for_each*() macros.
Quoted 64 lines
Initialise all the rid values in
resctrl_arch_late_init()before any for-each-resource walker can be called.Signed-off-by James Morse <[email protected]>---
Changes since v7:
* Split out of a previous patch due to a botched merged conflict.--- arch/x86/kernel/cpu/resctrl/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/x86/kernel/cpu/resctrl/core.c +5
-5@@ -60,7 +60,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_L3] = { .r_resctrl = { - .rid = RDT_RESOURCE_L3, .name = "L3", .ctrl_scope = RESCTRL_L3_CACHE, .mon_scope = RESCTRL_L3_CACHE,@@ -74,7 +73,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_L2] = { .r_resctrl = { - .rid = RDT_RESOURCE_L2, .name = "L2", .ctrl_scope = RESCTRL_L2_CACHE, .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_L2),@@ -86,7 +84,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_MBA] = { .r_resctrl = { - .rid = RDT_RESOURCE_MBA, .name = "MB", .ctrl_scope = RESCTRL_L3_CACHE, .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_MBA),@@ -96,7 +93,6 @@ struct rdt_hw_resource rdt_resources_all[RDT_NUM_RESOURCES] = { [RDT_RESOURCE_SMBA] = { .r_resctrl = { - .rid = RDT_RESOURCE_SMBA, .name = "SMBA", .ctrl_scope = RESCTRL_L3_CACHE, .ctrl_domains = ctrl_domain_init(RDT_RESOURCE_SMBA),@@ -996,7 +992,11 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)static int __init resctrl_arch_late_init (void ) {struct rdt_resource *r; -int state, ret; +int state, ret, i; + +/* Initialise all rid values for_each_rdt_resource() */ +for (i =0 ; i <RDT_NUM_RESOURCES ; i++) + rdt_resources_all[i].r_resctrl.rid = i;/* * Initialize functions(or definitions) that are different Signature · 1 line
2.20.1
-Tony
James Morse
reviewerRe: [PATCH v8 16/21] x86/resctrl: Always initialise rid field in rdt_resources_all[]
Hi Tony,
Quoted 5 lines · Tony
Quoted 4 lines · James Morse
x86 has an array, rdt_resources_all[], of all possible resources. The for-each-resource walkers depend on the rid field of all resources being initialised.
Quoted 7 lines
Quoted 3 lines
If the array ever grows due to another architecture adding a resource type that is not defined on x86, the for-each-resources walkers will loop forever.
This feels a bit weird. Having rdt_resources_all[] be a "swiss cheese" array full of holes where other architectures defined events that aren't supported by x86.
Today, there are none of those for x86. The MPAM driver has to do this, but so far the array is small. I agree if the array becomes large, and no architecture implements everything then some other structure would be better.
Quoted 7 lines
But it does work, so it can go in like this. But someday I may revisit some experimental patches I did a while back that:
1) Split therdt_resourcestructure into separate "ctrl" and "mon" pieces.
2) Replaced this array with a pair of lists, one each for enabled ctrl and mon resources.
3) Changed the resource walkers to use list_for_each*() macros.
Sounds good - this matches what the schema list has become.
The only oddity is the newly proposed "resctrl_online_domains_exist()" that would sanity-check a resctrl_exit() call - but I don't see a problem walking one list after the other there.
Thanks,
James
Reinette Chatre
maintainerRe: [PATCH v8 16/21] x86/resctrl: Always initialise rid field in rdt_resources_all[]
In reply to James MorseHi James,
arch/x86/kernel/cpu/resctrl/core.c void resctrl_cpu_detect(struct cpuinfo_x86 *c) · line 997
Quoted 8 lines · James Morse
arch/x86/kernel/cpu/resctrl/core.c +3
-1@@ -996,7 +992,11 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)static int __init resctrl_arch_late_init (void ) {struct rdt_resource *r; -int state, ret; +int state, ret, i; + +/* Initialise all rid values for_each_rdt_resource() */
I find the above difficult to parse. How about:
/* for_each_rdt_resource() requires all rid to be initialised. */
arch/x86/kernel/cpu/resctrl/core.c void resctrl_cpu_detect(struct cpuinfo_x86 *c) · line 1002
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+for (i =0 ; i <RDT_NUM_RESOURCES ; i++) + rdt_resources_all[i].r_resctrl.rid = i;/* * Initialize functions(or definitions) that are different
Reinette
James Morse
reviewerRe: [PATCH v8 16/21] x86/resctrl: Always initialise rid field in rdt_resources_all[]
Hi Reinette,
Quoted 12 lines · Reinette Chatre
arch/x86/kernel/cpu/resctrl/core.c void resctrl_cpu_detect(struct cpuinfo_x86 *c) · line 997
Quoted 8 lines · James Morse
arch/x86/kernel/cpu/resctrl/core.c +3
-1@@ -996,7 +992,11 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)static int __init resctrl_arch_late_init (void ) {struct rdt_resource *r; -int state, ret; +int state, ret, i; + +/* Initialise all rid values for_each_rdt_resource() */ I find the above difficult to parse. How about:
Quoted 7 lines
/* for_each_rdt_resource() requires all rid to be initialised. */arch/x86/kernel/cpu/resctrl/core.c void resctrl_cpu_detect(struct cpuinfo_x86 *c) · line 1002
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/core.c +2
-0+for (i =0 ; i <RDT_NUM_RESOURCES ; i++) + rdt_resources_all[i].r_resctrl.rid = i;/* * Initialize functions(or definitions) that are different
Thanks that's better. I think I removed a 'for' as 'for for_each...' looked like a duplicate word...
Thanks,
James
James Morse
reviewerPATCH v8 17/21 x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
In reply to James MorseResctrl is a filesystem interface to hardware that provides cache allocation policy and bandwidth control for groups of tasks or CPUs.
To support more than one architecture, resctrl needs to live in /fs/.
Move the code that is concerned with the filesystem interface to /fs/resctrl.
---
Changes since *:
* This patch is generated by a script.
--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +---------------- fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++ 14 files changed, 7668 insertions(+), 7418 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0 -636
@@ -23,270 +23,6 @@#include "internal.h" -struct rdt_parse_data { -struct rdtgroup *rdtgrp; -char *buf; -}; - -typedef int (ctrlval_parser_t )(struct rdt_parse_data *data, -struct resctrl_schema *s, -struct rdt_ctrl_domain *d); - -/* -* Check whether MBA bandwidth percentage value is correct. The value is -* checked against the minimum and max bandwidth values specified by the -* hardware. The allocated bandwidth percentage is rounded to the next -* control step available on the hardware. -*/ -static bool bw_validate (char *buf,u32 *data,struct rdt_resource *r) -{ -int ret; -u32 bw; - -/* -* Only linear delay values is supported for current Intel SKUs. -*/ -if (!r->membw.delay_linear && r->membw.arch_needs_linear) { -rdt_last_cmd_puts ("No support for non-linear MB domains\n" ); -return false; - } - - ret =kstrtou32 (buf,10 , &bw); -if (ret) { -rdt_last_cmd_printf ("Invalid MB value %s\n" , buf); -return false; - } - -/* Nothing else to do if software controller is enabled. */ -if (is_mba_sc (r)) { - *data = bw; -return true; - } - -if (bw < r->membw.min_bw || bw > r->membw.max_bw) { -rdt_last_cmd_printf ("MB value %u out of range [%d,%d]\n" , - bw, r->membw.min_bw, r->membw.max_bw); -return false; - } - - *data =roundup (bw, (unsigned long )r->membw.bw_gran); -return true; -} - -static int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_ctrl_domain *d) -{ -struct resctrl_staged_config *cfg; -u32 closid = data->rdtgrp->closid; -struct rdt_resource *r = s->res; -u32 bw_val; - - cfg = &d->staged_config[s->conf_type]; -if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id); -return -EINVAL ; - } - -if (!bw_validate (data->buf, &bw_val, r)) -return -EINVAL ; - -if (is_mba_sc (r)) { - d->mbps_val[closid] = bw_val; -return 0 ; - } - - cfg->new_ctrl = bw_val; - cfg->have_new_ctrl = true; - -return 0 ; -} - -/* -* Check whether a cache bit mask is valid. -* On Intel CPUs, non-contiguous 1s value support is indicated by CPUID: -* - CPUID.0x10.1:ECX[3]: L3 non-contiguous 1s value supported if 1 -* - CPUID.0x10.2:ECX[3]: L2 non-contiguous 1s value supported if 1 -* -* Haswell does not support a non-contiguous 1s value and additionally -* requires at least two bits set. -* AMD allows non-contiguous bitmasks. -*/ -static bool cbm_validate (char *buf,u32 *data,struct rdt_resource *r) -{ -u32 supported_bits =BIT_MASK (r->cache.cbm_len) -1 ; -unsigned int cbm_len = r->cache.cbm_len; -unsigned long first_bit, zero_bit, val; -int ret; - - ret =kstrtoul (buf,16 , &val); -if (ret) { -rdt_last_cmd_printf ("Non-hex character in the mask %s\n" , buf); -return false; - } - -if ((r->cache.min_cbm_bits >0 && val ==0 ) || val > supported_bits) { -rdt_last_cmd_puts ("Mask out of range\n" ); -return false; - } - - first_bit =find_first_bit (&val, cbm_len); - zero_bit =find_next_zero_bit (&val, cbm_len, first_bit); - -/* Are non-contiguous bitmasks allowed? */ -if (!r->cache.arch_has_sparse_bitmasks && - (find_next_bit (&val, cbm_len, zero_bit) < cbm_len)) { -rdt_last_cmd_printf ("The mask %lx has non-consecutive 1-bits\n" , val); -return false; - } - -if ((zero_bit - first_bit) < r->cache.min_cbm_bits) { -rdt_last_cmd_printf ("Need at least %d bits in the mask\n" , - r->cache.min_cbm_bits); -return false; - } - - *data = val; -return true; -} - -/* -* Read one cache bit mask (hex). Check that it is valid for the current -* resource type. -*/ -static int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_ctrl_domain *d) -{ -struct rdtgroup *rdtgrp = data->rdtgrp; -struct resctrl_staged_config *cfg; -struct rdt_resource *r = s->res; -u32 cbm_val; - - cfg = &d->staged_config[s->conf_type]; -if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id); -return -EINVAL ; - } - -/* -* Cannot set up more than one pseudo-locked region in a cache -* hierarchy. -*/ -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP && -rdtgroup_pseudo_locked_in_hierarchy (d)) { -rdt_last_cmd_puts ("Pseudo-locked region in hierarchy\n" ); -return -EINVAL ; - } - -if (!cbm_validate (data->buf, &cbm_val, r)) -return -EINVAL ; - -if ((rdtgrp->mode ==RDT_MODE_EXCLUSIVE || - rdtgrp->mode ==RDT_MODE_SHAREABLE ) && -rdtgroup_cbm_overlaps_pseudo_locked (d, cbm_val)) { -rdt_last_cmd_puts ("CBM overlaps with pseudo-locked region\n" ); -return -EINVAL ; - } - -/* -* The CBM may not overlap with the CBM of another closid if -* either is exclusive. -*/ -if (rdtgroup_cbm_overlaps (s, d, cbm_val, rdtgrp->closid, true)) { -rdt_last_cmd_puts ("Overlaps with exclusive group\n" ); -return -EINVAL ; - } - -if (rdtgroup_cbm_overlaps (s, d, cbm_val, rdtgrp->closid, false)) { -if (rdtgrp->mode ==RDT_MODE_EXCLUSIVE || - rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -rdt_last_cmd_puts ("Overlaps with other group\n" ); -return -EINVAL ; - } - } - - cfg->new_ctrl = cbm_val; - cfg->have_new_ctrl = true; - -return 0 ; -} - -/* -* For each domain in this resource we expect to find a series of: -* id=mask -* separated by ";". The "id" is in decimal, and must match one of -* the "id"s for this resource. -*/ -static int parse_line (char *line,struct resctrl_schema *s, -struct rdtgroup *rdtgrp) -{ -enum resctrl_conf_type t = s->conf_type; -ctrlval_parser_t *parse_ctrlval =NULL ; -struct resctrl_staged_config *cfg; -struct rdt_resource *r = s->res; -struct rdt_parse_data data; -struct rdt_ctrl_domain *d; -char *dom =NULL , *id; -unsigned long dom_id; - -/* Walking r->domains, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -switch (r->schema_fmt) { -case RESCTRL_SCHEMA_BITMAP : - parse_ctrlval = &parse_cbm; -break ; -case RESCTRL_SCHEMA_RANGE : - parse_ctrlval = &parse_bw; -break ; - } - -if (WARN_ON_ONCE (!parse_ctrlval)) -return -EINVAL ; - -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP && - (r->rid ==RDT_RESOURCE_MBA || r->rid ==RDT_RESOURCE_SMBA )) { -rdt_last_cmd_puts ("Cannot pseudo-lock MBA resource\n" ); -return -EINVAL ; - } - -next: -if (!line || line[0 ] =='\0' ) -return 0 ; - dom =strsep (&line,";" ); - id =strsep (&dom,"=" ); -if (!dom ||kstrtoul (id,10 , &dom_id)) { -rdt_last_cmd_puts ("Missing '=' or non-numeric domain\n" ); -return -EINVAL ; - } - dom =strim (dom); -list_for_each_entry (d, &r->ctrl_domains, hdr.list) { -if (d->hdr.id == dom_id) { - data.buf = dom; - data.rdtgrp = rdtgrp; -if (parse_ctrlval (&data, s, d)) -return -EINVAL ; -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { - cfg = &d->staged_config[t]; -/* -* In pseudo-locking setup mode and just -* parsed a valid CBM that should be -* pseudo-locked. Only one locked region per -* resource group and domain so just do -* the required initialization for single -* region and return. -*/ - rdtgrp->plr->s = s; - rdtgrp->plr->d = d; - rdtgrp->plr->cbm = cfg->new_ctrl; - d->plr = rdtgrp->plr; -return 0 ; - } - goto next; - } - } -return -EINVAL ; -} -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) {
@@ -351,100 +87,6 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return 0 ; } -static int rdtgroup_parse_resource (char *resname,char *tok, -struct rdtgroup *rdtgrp) -{ -struct resctrl_schema *s; - -list_for_each_entry (s, &resctrl_schema_all, list) { -if (!strcmp (resname, s->name) && rdtgrp->closid < s->num_closid) -return parse_line (tok, s, rdtgrp); - } -rdt_last_cmd_printf ("Unknown or unsupported resource name '%s'\n" , resname); -return -EINVAL ; -} - -ssize_t rdtgroup_schemata_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off) -{ -struct resctrl_schema *s; -struct rdtgroup *rdtgrp; -struct rdt_resource *r; -char *tok, *resname; -int ret =0 ; - -/* Valid input requires a trailing newline */ -if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) -return -EINVAL ; - buf[nbytes -1 ] ='\0' ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (!rdtgrp) { -rdtgroup_kn_unlock (of->kn); -return -ENOENT ; - } -rdt_last_cmd_clear (); - -/* -* No changes to pseudo-locked region allowed. It has to be removed -* and re-created instead. -*/ -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED ) { - ret = -EINVAL ; -rdt_last_cmd_puts ("Resource group is pseudo-locked\n" ); - goto out; - } - -rdt_staged_configs_clear (); - -while ((tok =strsep (&buf,"\n" )) !=NULL ) { - resname =strim (strsep (&tok,":" )); -if (!tok) { -rdt_last_cmd_puts ("Missing ':'\n" ); - ret = -EINVAL ; - goto out; - } -if (tok[0 ] =='\0' ) { -rdt_last_cmd_printf ("Missing '%s' value\n" , resname); - ret = -EINVAL ; - goto out; - } - ret =rdtgroup_parse_resource (resname, tok, rdtgrp); -if (ret) - goto out; - } - -list_for_each_entry (s, &resctrl_schema_all, list) { - r = s->res; - -/* -* Writes to mba_sc resources update the software controller, -* not the control MSR. -*/ -if (is_mba_sc (r)) -continue ; - - ret =resctrl_arch_update_domains (r, rdtgrp->closid); -if (ret) - goto out; - } - -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -/* -* If pseudo-locking fails we keep the resource group in -* mode RDT_MODE_PSEUDO_LOCKSETUP with its class of service -* active and updated for just the domain the pseudo-locked -* region was requested for. -*/ - ret =rdtgroup_pseudo_lock_create (rdtgrp); - } - -out: -rdt_staged_configs_clear (); -rdtgroup_kn_unlock (of->kn); -return ret ?: nbytes; -} -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) {
@@ -453,281 +95,3 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,return hw_dom->ctrl_val[idx]; } - -static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) -{ -struct rdt_resource *r = schema->res; -struct rdt_ctrl_domain *dom; -bool sep = false; -u32 ctrl_val; - -/* Walking r->domains, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->ctrl_domains, hdr.list) { -if (sep) -seq_puts (s,";" ); - -if (is_mba_sc (r)) - ctrl_val = dom->mbps_val[closid]; -else - ctrl_val =resctrl_arch_get_config (r, dom, closid, - schema->conf_type); - -seq_printf (s, schema->fmt_str, dom->hdr.id, ctrl_val); - sep = true; - } -seq_puts (s,"\n" ); -} - -int rdtgroup_schemata_show (struct kernfs_open_file *of, -struct seq_file *s,void *v) -{ -struct resctrl_schema *schema; -struct rdtgroup *rdtgrp; -int ret =0 ; -u32 closid; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (rdtgrp) { -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -list_for_each_entry (schema, &resctrl_schema_all, list) { -seq_printf (s,"%s:uninitialized\n" , schema->name); - } - }else if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED ) { -if (!rdtgrp->plr->d) { -rdt_last_cmd_clear (); -rdt_last_cmd_puts ("Cache domain offline\n" ); - ret = -ENODEV ; - }else { -seq_printf (s,"%s:%d=%x\n" , - rdtgrp->plr->s->res->name, - rdtgrp->plr->d->hdr.id, - rdtgrp->plr->cbm); - } - }else { - closid = rdtgrp->closid; -list_for_each_entry (schema, &resctrl_schema_all, list) { -if (closid < schema->num_closid) -show_doms (s, schema, closid); - } - } - }else { - ret = -ENOENT ; - } -rdtgroup_kn_unlock (of->kn); -return ret; -} - -static int smp_mon_event_count (void *arg) -{ -mon_event_count (arg); - -return 0 ; -} - -ssize_t rdtgroup_mba_mbps_event_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off) -{ -struct rdtgroup *rdtgrp; -int ret =0 ; - -/* Valid input requires a trailing newline */ -if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) -return -EINVAL ; - buf[nbytes -1 ] ='\0' ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (!rdtgrp) { -rdtgroup_kn_unlock (of->kn); -return -ENOENT ; - } -rdt_last_cmd_clear (); - -if (!strcmp (buf,"mbm_local_bytes" )) { -if (resctrl_arch_is_mbm_local_enabled ()) - rdtgrp->mba_mbps_event =QOS_L3_MBM_LOCAL_EVENT_ID ; -else - ret = -EINVAL ; - }else if (!strcmp (buf,"mbm_total_bytes" )) { -if (resctrl_arch_is_mbm_total_enabled ()) - rdtgrp->mba_mbps_event =QOS_L3_MBM_TOTAL_EVENT_ID ; -else - ret = -EINVAL ; - }else { - ret = -EINVAL ; - } - -if (ret) -rdt_last_cmd_printf ("Unsupported event id '%s'\n" , buf); - -rdtgroup_kn_unlock (of->kn); - -return ret ?: nbytes; -} - -int rdtgroup_mba_mbps_event_show (struct kernfs_open_file *of, -struct seq_file *s,void *v) -{ -struct rdtgroup *rdtgrp; -int ret =0 ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); - -if (rdtgrp) { -switch (rdtgrp->mba_mbps_event) { -case QOS_L3_MBM_LOCAL_EVENT_ID : -seq_puts (s,"mbm_local_bytes\n" ); -break ; -case QOS_L3_MBM_TOTAL_EVENT_ID : -seq_puts (s,"mbm_total_bytes\n" ); -break ; -default : -pr_warn_once ("Bad event %d\n" , rdtgrp->mba_mbps_event); - ret = -EINVAL ; -break ; - } - }else { - ret = -ENOENT ; - } - -rdtgroup_kn_unlock (of->kn); - -return ret; -} - -struct rdt_domain_hdr *resctrl_find_domain (struct list_head *h,int id, -struct list_head **pos) -{ -struct rdt_domain_hdr *d; -struct list_head *l; - -list_for_each (l, h) { - d = list_entry(l, struct rdt_domain_hdr, list); -/* When id is found, return its domain. */ -if (id == d->id) -return d; -/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) -break ; - } - -if (pos) - *pos = l; - -return NULL ; -} - -void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_mon_domain *d,struct rdtgroup *rdtgrp, -cpumask_t *cpumask,int evtid,int first) -{ -int cpu; - -/* When picking a CPU from cpu_mask, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -/* -* Setup the parameters to pass to mon_event_count() to read the data. -*/ - rr->rgrp = rdtgrp; - rr->evtid = evtid; - rr->r = r; - rr->d = d; - rr->first = first; - rr->arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r, evtid); -if (IS_ERR (rr->arch_mon_ctx)) { - rr->err = -EINVAL ; -return ; - } - - cpu =cpumask_any_housekeeping (cpumask,RESCTRL_PICK_ANY_CPU ); - -/* -* cpumask_any_housekeeping() prefers housekeeping CPUs, but -* are all the CPUs nohz_full? If yes, pick a CPU to IPI. -* MPAM's resctrl_arch_rmid_read() is unable to read the -* counters on some platforms if its called in IRQ context. -*/ -if (tick_nohz_full_cpu (cpu)) -smp_call_function_any (cpumask, mon_event_count, rr,1 ); -else -smp_call_on_cpu (cpu, smp_mon_event_count, rr, false); - -resctrl_arch_mon_ctx_free (r, evtid, rr->arch_mon_ctx); -} - -int rdtgroup_mondata_show (struct seq_file *m,void *arg) -{ -struct kernfs_open_file *of = m->private; -struct rdt_domain_hdr *hdr; -struct rmid_read rr = {0 }; -struct rdt_mon_domain *d; -u32 resid, evtid, domid; -struct rdtgroup *rdtgrp; -struct rdt_resource *r; -struct mon_data *md; -int ret =0 ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (!rdtgrp) { - ret = -ENOENT ; - goto out; - } - - md = of->kn->priv; -if (WARN_ON_ONCE (!md)) { - ret = -EIO ; - goto out; - } - - resid = md->rid; - domid = md->domid; - evtid = md->evtid; - r =resctrl_arch_get_resource (resid); - -if (md->sum) { -/* -* This file requires summing across all domains that share -* the L3 cache id that was provided in the "domid" field of the -* struct mon_data. Search all domains in the resource for -* one that matches this cache id. -*/ -list_for_each_entry (d, &r->mon_domains, hdr.list) { -if (d->ci->id == domid) { - rr.ci = d->ci; -mon_event_read (&rr, r,NULL , rdtgrp, - &d->ci->shared_cpu_map, evtid, false); - goto checkresult; - } - } - ret = -ENOENT ; - goto out; - }else { -/* -* This file provides data from a single domain. Search -* the resource to find the domain with "domid". -*/ - hdr =resctrl_find_domain (&r->mon_domains, domid,NULL ); -if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { - ret = -ENOENT ; - goto out; - } - d = container_of(hdr, struct rdt_mon_domain, hdr); -mon_event_read (&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); - } - -checkresult: - -if (rr.err == -EIO ) -seq_puts (m,"Error\n" ); -else if (rr.err == -EINVAL ) -seq_puts (m,"Unavailable\n" ); -else -seq_printf (m,"%llu\n" , rr.val); - -out: -rdtgroup_kn_unlock (of->kn); -return ret; -}
arch/x86/kernel/cpu/resctrl/internal.h +8 -372
415 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/monitor.c +2 -900
945 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/monitor_trace.h +2 -16
@@ -7,25 +7,11 @@#include <linux/tracepoint.h> -TRACE_EVENT (mon_llc_occupancy_limbo, - TP_PROTO(u32 ctrl_hw_id, u32 mon_hw_id, int domain_id, u64 llc_occupancy_bytes), -TP_ARGS (ctrl_hw_id, mon_hw_id, domain_id, llc_occupancy_bytes), - TP_STRUCT__entry(__field(u32, ctrl_hw_id) - __field(u32, mon_hw_id) - __field(int, domain_id) -__field (u64, llc_occupancy_bytes)), - TP_fast_assign(__entry->ctrl_hw_id = ctrl_hw_id; - __entry->mon_hw_id = mon_hw_id; - __entry->domain_id = domain_id; - __entry->llc_occupancy_bytes = llc_occupancy_bytes;), -TP_printk ("ctrl_hw_id=%u mon_hw_id=%u domain_id=%d llc_occupancy_bytes=%llu" , - __entry->ctrl_hw_id, __entry->mon_hw_id, __entry->domain_id, - __entry->llc_occupancy_bytes) - ); -#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ #undef TRACE_INCLUDE_PATH#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_FILE monitor_trace +#include <trace/define_trace.h>
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1 -1079
962 lines not on this page · raw message
arch/x86/kernel/cpu/resctrl/pseudo_lock_trace.h +2 -0
Lines of this file are not shown. View the raw message.
arch/x86/kernel/cpu/resctrl/rdtgroup.c +141 -4415
4,556 lines not on this page · raw message
fs/resctrl/ctrlmondata.c +660 -0
660 lines not on this page · raw message
fs/resctrl/internal.h +442 -0
442 lines not on this page · raw message
fs/resctrl/monitor.c +932 -0
932 lines not on this page · raw message
fs/resctrl/pseudo_lock.c +1115 -0
1,115 lines not on this page · raw message
fs/resctrl/rdtgroup.c +4313 -0
4,313 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.20.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
Hi, James,
arch/x86/kernel/cpu/resctrl/rdtgroup.c
Quoted 7,036 lines · James Morse
Resctrl is a filesystem interface to hardware that provides cache allocation policy and bandwidth control for groups of tasks or CPUs.
To support more than one architecture, resctrl needs to live in /fs/.
Move the code that is concerned with the filesystem interface to /fs/resctrl.
Signed-off-by James Morse <[email protected]>---
Changes since *:
* This patch is generated by a script.--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +---------------- fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++ 14 files changed, 7668 insertions(+), 7418 deletions(-)arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0
-636@@ -23,270 +23,6 @@#include "internal.h" -struct rdt_parse_data { -struct rdtgroup *rdtgrp; -char *buf; -}; - -typedef int (ctrlval_parser_t )(struct rdt_parse_data *data, -struct resctrl_schema *s, -struct rdt_ctrl_domain *d); - -/* -* Check whether MBA bandwidth percentage value is correct. The value is -* checked against the minimum and max bandwidth values specified by the -* hardware. The allocated bandwidth percentage is rounded to the next -* control step available on the hardware. -*/ -static bool bw_validate (char *buf,u32 *data,struct rdt_resource *r) -{ -int ret; -u32 bw; - -/* -* Only linear delay values is supported for current Intel SKUs. -*/ -if (!r->membw.delay_linear && r->membw.arch_needs_linear) { -rdt_last_cmd_puts ("No support for non-linear MB domains\n" ); -return false; - } - - ret =kstrtou32 (buf,10 , &bw); -if (ret) { -rdt_last_cmd_printf ("Invalid MB value %s\n" , buf); -return false; - } - -/* Nothing else to do if software controller is enabled. */ -if (is_mba_sc (r)) { - *data = bw; -return true; - } - -if (bw < r->membw.min_bw || bw > r->membw.max_bw) { -rdt_last_cmd_printf ("MB value %u out of range [%d,%d]\n" , - bw, r->membw.min_bw, r->membw.max_bw); -return false; - } - - *data =roundup (bw, (unsigned long )r->membw.bw_gran); -return true; -} - -static int parse_bw (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_ctrl_domain *d) -{ -struct resctrl_staged_config *cfg; -u32 closid = data->rdtgrp->closid; -struct rdt_resource *r = s->res; -u32 bw_val; - - cfg = &d->staged_config[s->conf_type]; -if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id); -return -EINVAL ; - } - -if (!bw_validate (data->buf, &bw_val, r)) -return -EINVAL ; - -if (is_mba_sc (r)) { - d->mbps_val[closid] = bw_val; -return 0 ; - } - - cfg->new_ctrl = bw_val; - cfg->have_new_ctrl = true; - -return 0 ; -} - -/* -* Check whether a cache bit mask is valid. -* On Intel CPUs, non-contiguous 1s value support is indicated by CPUID: -* - CPUID.0x10.1:ECX[3]: L3 non-contiguous 1s value supported if 1 -* - CPUID.0x10.2:ECX[3]: L2 non-contiguous 1s value supported if 1 -* -* Haswell does not support a non-contiguous 1s value and additionally -* requires at least two bits set. -* AMD allows non-contiguous bitmasks. -*/ -static bool cbm_validate (char *buf,u32 *data,struct rdt_resource *r) -{ -u32 supported_bits =BIT_MASK (r->cache.cbm_len) -1 ; -unsigned int cbm_len = r->cache.cbm_len; -unsigned long first_bit, zero_bit, val; -int ret; - - ret =kstrtoul (buf,16 , &val); -if (ret) { -rdt_last_cmd_printf ("Non-hex character in the mask %s\n" , buf); -return false; - } - -if ((r->cache.min_cbm_bits >0 && val ==0 ) || val > supported_bits) { -rdt_last_cmd_puts ("Mask out of range\n" ); -return false; - } - - first_bit =find_first_bit (&val, cbm_len); - zero_bit =find_next_zero_bit (&val, cbm_len, first_bit); - -/* Are non-contiguous bitmasks allowed? */ -if (!r->cache.arch_has_sparse_bitmasks && - (find_next_bit (&val, cbm_len, zero_bit) < cbm_len)) { -rdt_last_cmd_printf ("The mask %lx has non-consecutive 1-bits\n" , val); -return false; - } - -if ((zero_bit - first_bit) < r->cache.min_cbm_bits) { -rdt_last_cmd_printf ("Need at least %d bits in the mask\n" , - r->cache.min_cbm_bits); -return false; - } - - *data = val; -return true; -} - -/* -* Read one cache bit mask (hex). Check that it is valid for the current -* resource type. -*/ -static int parse_cbm (struct rdt_parse_data *data,struct resctrl_schema *s, -struct rdt_ctrl_domain *d) -{ -struct rdtgroup *rdtgrp = data->rdtgrp; -struct resctrl_staged_config *cfg; -struct rdt_resource *r = s->res; -u32 cbm_val; - - cfg = &d->staged_config[s->conf_type]; -if (cfg->have_new_ctrl) { -rdt_last_cmd_printf ("Duplicate domain %d\n" , d->hdr.id); -return -EINVAL ; - } - -/* -* Cannot set up more than one pseudo-locked region in a cache -* hierarchy. -*/ -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP && -rdtgroup_pseudo_locked_in_hierarchy (d)) { -rdt_last_cmd_puts ("Pseudo-locked region in hierarchy\n" ); -return -EINVAL ; - } - -if (!cbm_validate (data->buf, &cbm_val, r)) -return -EINVAL ; - -if ((rdtgrp->mode ==RDT_MODE_EXCLUSIVE || - rdtgrp->mode ==RDT_MODE_SHAREABLE ) && -rdtgroup_cbm_overlaps_pseudo_locked (d, cbm_val)) { -rdt_last_cmd_puts ("CBM overlaps with pseudo-locked region\n" ); -return -EINVAL ; - } - -/* -* The CBM may not overlap with the CBM of another closid if -* either is exclusive. -*/ -if (rdtgroup_cbm_overlaps (s, d, cbm_val, rdtgrp->closid, true)) { -rdt_last_cmd_puts ("Overlaps with exclusive group\n" ); -return -EINVAL ; - } - -if (rdtgroup_cbm_overlaps (s, d, cbm_val, rdtgrp->closid, false)) { -if (rdtgrp->mode ==RDT_MODE_EXCLUSIVE || - rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -rdt_last_cmd_puts ("Overlaps with other group\n" ); -return -EINVAL ; - } - } - - cfg->new_ctrl = cbm_val; - cfg->have_new_ctrl = true; - -return 0 ; -} - -/* -* For each domain in this resource we expect to find a series of: -* id=mask -* separated by ";". The "id" is in decimal, and must match one of -* the "id"s for this resource. -*/ -static int parse_line (char *line,struct resctrl_schema *s, -struct rdtgroup *rdtgrp) -{ -enum resctrl_conf_type t = s->conf_type; -ctrlval_parser_t *parse_ctrlval =NULL ; -struct resctrl_staged_config *cfg; -struct rdt_resource *r = s->res; -struct rdt_parse_data data; -struct rdt_ctrl_domain *d; -char *dom =NULL , *id; -unsigned long dom_id; - -/* Walking r->domains, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -switch (r->schema_fmt) { -case RESCTRL_SCHEMA_BITMAP : - parse_ctrlval = &parse_cbm; -break ; -case RESCTRL_SCHEMA_RANGE : - parse_ctrlval = &parse_bw; -break ; - } - -if (WARN_ON_ONCE (!parse_ctrlval)) -return -EINVAL ; - -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP && - (r->rid ==RDT_RESOURCE_MBA || r->rid ==RDT_RESOURCE_SMBA )) { -rdt_last_cmd_puts ("Cannot pseudo-lock MBA resource\n" ); -return -EINVAL ; - } - -next: -if (!line || line[0 ] =='\0' ) -return 0 ; - dom =strsep (&line,";" ); - id =strsep (&dom,"=" ); -if (!dom ||kstrtoul (id,10 , &dom_id)) { -rdt_last_cmd_puts ("Missing '=' or non-numeric domain\n" ); -return -EINVAL ; - } - dom =strim (dom); -list_for_each_entry (d, &r->ctrl_domains, hdr.list) { -if (d->hdr.id == dom_id) { - data.buf = dom; - data.rdtgrp = rdtgrp; -if (parse_ctrlval (&data, s, d)) -return -EINVAL ; -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { - cfg = &d->staged_config[t]; -/* -* In pseudo-locking setup mode and just -* parsed a valid CBM that should be -* pseudo-locked. Only one locked region per -* resource group and domain so just do -* the required initialization for single -* region and return. -*/ - rdtgrp->plr->s = s; - rdtgrp->plr->d = d; - rdtgrp->plr->cbm = cfg->new_ctrl; - d->plr = rdtgrp->plr; -return 0 ; - } - goto next; - } - } -return -EINVAL ; -} -int resctrl_arch_update_one (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type t,u32 cfg_val) {@@ -351,100 +87,6 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)return 0 ; } -static int rdtgroup_parse_resource (char *resname,char *tok, -struct rdtgroup *rdtgrp) -{ -struct resctrl_schema *s; - -list_for_each_entry (s, &resctrl_schema_all, list) { -if (!strcmp (resname, s->name) && rdtgrp->closid < s->num_closid) -return parse_line (tok, s, rdtgrp); - } -rdt_last_cmd_printf ("Unknown or unsupported resource name '%s'\n" , resname); -return -EINVAL ; -} - -ssize_t rdtgroup_schemata_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off) -{ -struct resctrl_schema *s; -struct rdtgroup *rdtgrp; -struct rdt_resource *r; -char *tok, *resname; -int ret =0 ; - -/* Valid input requires a trailing newline */ -if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) -return -EINVAL ; - buf[nbytes -1 ] ='\0' ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (!rdtgrp) { -rdtgroup_kn_unlock (of->kn); -return -ENOENT ; - } -rdt_last_cmd_clear (); - -/* -* No changes to pseudo-locked region allowed. It has to be removed -* and re-created instead. -*/ -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED ) { - ret = -EINVAL ; -rdt_last_cmd_puts ("Resource group is pseudo-locked\n" ); - goto out; - } - -rdt_staged_configs_clear (); - -while ((tok =strsep (&buf,"\n" )) !=NULL ) { - resname =strim (strsep (&tok,":" )); -if (!tok) { -rdt_last_cmd_puts ("Missing ':'\n" ); - ret = -EINVAL ; - goto out; - } -if (tok[0 ] =='\0' ) { -rdt_last_cmd_printf ("Missing '%s' value\n" , resname); - ret = -EINVAL ; - goto out; - } - ret =rdtgroup_parse_resource (resname, tok, rdtgrp); -if (ret) - goto out; - } - -list_for_each_entry (s, &resctrl_schema_all, list) { - r = s->res; - -/* -* Writes to mba_sc resources update the software controller, -* not the control MSR. -*/ -if (is_mba_sc (r)) -continue ; - - ret =resctrl_arch_update_domains (r, rdtgrp->closid); -if (ret) - goto out; - } - -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -/* -* If pseudo-locking fails we keep the resource group in -* mode RDT_MODE_PSEUDO_LOCKSETUP with its class of service -* active and updated for just the domain the pseudo-locked -* region was requested for. -*/ - ret =rdtgroup_pseudo_lock_create (rdtgrp); - } - -out: -rdt_staged_configs_clear (); -rdtgroup_kn_unlock (of->kn); -return ret ?: nbytes; -} -u32 resctrl_arch_get_config (struct rdt_resource *r,struct rdt_ctrl_domain *d,u32 closid,enum resctrl_conf_type type) {@@ -453,281 +95,3 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,return hw_dom->ctrl_val[idx]; } - -static void show_doms (struct seq_file *s,struct resctrl_schema *schema,int closid) -{ -struct rdt_resource *r = schema->res; -struct rdt_ctrl_domain *dom; -bool sep = false; -u32 ctrl_val; - -/* Walking r->domains, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -seq_printf (s,"%*s:" , max_name_width, schema->name); -list_for_each_entry (dom, &r->ctrl_domains, hdr.list) { -if (sep) -seq_puts (s,";" ); - -if (is_mba_sc (r)) - ctrl_val = dom->mbps_val[closid]; -else - ctrl_val =resctrl_arch_get_config (r, dom, closid, - schema->conf_type); - -seq_printf (s, schema->fmt_str, dom->hdr.id, ctrl_val); - sep = true; - } -seq_puts (s,"\n" ); -} - -int rdtgroup_schemata_show (struct kernfs_open_file *of, -struct seq_file *s,void *v) -{ -struct resctrl_schema *schema; -struct rdtgroup *rdtgrp; -int ret =0 ; -u32 closid; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (rdtgrp) { -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -list_for_each_entry (schema, &resctrl_schema_all, list) { -seq_printf (s,"%s:uninitialized\n" , schema->name); - } - }else if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED ) { -if (!rdtgrp->plr->d) { -rdt_last_cmd_clear (); -rdt_last_cmd_puts ("Cache domain offline\n" ); - ret = -ENODEV ; - }else { -seq_printf (s,"%s:%d=%x\n" , - rdtgrp->plr->s->res->name, - rdtgrp->plr->d->hdr.id, - rdtgrp->plr->cbm); - } - }else { - closid = rdtgrp->closid; -list_for_each_entry (schema, &resctrl_schema_all, list) { -if (closid < schema->num_closid) -show_doms (s, schema, closid); - } - } - }else { - ret = -ENOENT ; - } -rdtgroup_kn_unlock (of->kn); -return ret; -} - -static int smp_mon_event_count (void *arg) -{ -mon_event_count (arg); - -return 0 ; -} - -ssize_t rdtgroup_mba_mbps_event_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off) -{ -struct rdtgroup *rdtgrp; -int ret =0 ; - -/* Valid input requires a trailing newline */ -if (nbytes ==0 || buf[nbytes -1 ] !='\n' ) -return -EINVAL ; - buf[nbytes -1 ] ='\0' ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (!rdtgrp) { -rdtgroup_kn_unlock (of->kn); -return -ENOENT ; - } -rdt_last_cmd_clear (); - -if (!strcmp (buf,"mbm_local_bytes" )) { -if (resctrl_arch_is_mbm_local_enabled ()) - rdtgrp->mba_mbps_event =QOS_L3_MBM_LOCAL_EVENT_ID ; -else - ret = -EINVAL ; - }else if (!strcmp (buf,"mbm_total_bytes" )) { -if (resctrl_arch_is_mbm_total_enabled ()) - rdtgrp->mba_mbps_event =QOS_L3_MBM_TOTAL_EVENT_ID ; -else - ret = -EINVAL ; - }else { - ret = -EINVAL ; - } - -if (ret) -rdt_last_cmd_printf ("Unsupported event id '%s'\n" , buf); - -rdtgroup_kn_unlock (of->kn); - -return ret ?: nbytes; -} - -int rdtgroup_mba_mbps_event_show (struct kernfs_open_file *of, -struct seq_file *s,void *v) -{ -struct rdtgroup *rdtgrp; -int ret =0 ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); - -if (rdtgrp) { -switch (rdtgrp->mba_mbps_event) { -case QOS_L3_MBM_LOCAL_EVENT_ID : -seq_puts (s,"mbm_local_bytes\n" ); -break ; -case QOS_L3_MBM_TOTAL_EVENT_ID : -seq_puts (s,"mbm_total_bytes\n" ); -break ; -default : -pr_warn_once ("Bad event %d\n" , rdtgrp->mba_mbps_event); - ret = -EINVAL ; -break ; - } - }else { - ret = -ENOENT ; - } - -rdtgroup_kn_unlock (of->kn); - -return ret; -} - -struct rdt_domain_hdr *resctrl_find_domain (struct list_head *h,int id, -struct list_head **pos) -{ -struct rdt_domain_hdr *d; -struct list_head *l; - -list_for_each (l, h) { - d = list_entry(l, struct rdt_domain_hdr, list); -/* When id is found, return its domain. */ -if (id == d->id) -return d; -/* Stop searching when finding id's position in sorted list. */ -if (id < d->id) -break ; - } - -if (pos) - *pos = l; - -return NULL ; -} - -void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_mon_domain *d,struct rdtgroup *rdtgrp, -cpumask_t *cpumask,int evtid,int first) -{ -int cpu; - -/* When picking a CPU from cpu_mask, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -/* -* Setup the parameters to pass to mon_event_count() to read the data. -*/ - rr->rgrp = rdtgrp; - rr->evtid = evtid; - rr->r = r; - rr->d = d; - rr->first = first; - rr->arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r, evtid); -if (IS_ERR (rr->arch_mon_ctx)) { - rr->err = -EINVAL ; -return ; - } - - cpu =cpumask_any_housekeeping (cpumask,RESCTRL_PICK_ANY_CPU ); - -/* -* cpumask_any_housekeeping() prefers housekeeping CPUs, but -* are all the CPUs nohz_full? If yes, pick a CPU to IPI. -* MPAM's resctrl_arch_rmid_read() is unable to read the -* counters on some platforms if its called in IRQ context. -*/ -if (tick_nohz_full_cpu (cpu)) -smp_call_function_any (cpumask, mon_event_count, rr,1 ); -else -smp_call_on_cpu (cpu, smp_mon_event_count, rr, false); - -resctrl_arch_mon_ctx_free (r, evtid, rr->arch_mon_ctx); -} - -int rdtgroup_mondata_show (struct seq_file *m,void *arg) -{ -struct kernfs_open_file *of = m->private; -struct rdt_domain_hdr *hdr; -struct rmid_read rr = {0 }; -struct rdt_mon_domain *d; -u32 resid, evtid, domid; -struct rdtgroup *rdtgrp; -struct rdt_resource *r; -struct mon_data *md; -int ret =0 ; - - rdtgrp =rdtgroup_kn_lock_live (of->kn); -if (!rdtgrp) { - ret = -ENOENT ; - goto out; - } - - md = of->kn->priv; -if (WARN_ON_ONCE (!md)) { - ret = -EIO ; - goto out; - } - - resid = md->rid; - domid = md->domid; - evtid = md->evtid; - r =resctrl_arch_get_resource (resid); - -if (md->sum) { -/* -* This file requires summing across all domains that share -* the L3 cache id that was provided in the "domid" field of the -* struct mon_data. Search all domains in the resource for -* one that matches this cache id. -*/ -list_for_each_entry (d, &r->mon_domains, hdr.list) { -if (d->ci->id == domid) { - rr.ci = d->ci; -mon_event_read (&rr, r,NULL , rdtgrp, - &d->ci->shared_cpu_map, evtid, false); - goto checkresult; - } - } - ret = -ENOENT ; - goto out; - }else { -/* -* This file provides data from a single domain. Search -* the resource to find the domain with "domid". -*/ - hdr =resctrl_find_domain (&r->mon_domains, domid,NULL ); -if (!hdr ||WARN_ON_ONCE (hdr->type !=RESCTRL_MON_DOMAIN )) { - ret = -ENOENT ; - goto out; - } - d = container_of(hdr, struct rdt_mon_domain, hdr); -mon_event_read (&rr, r, d, rdtgrp, &d->hdr.cpu_mask, evtid, false); - } - -checkresult: - -if (rr.err == -EIO ) -seq_puts (m,"Error\n" ); -else if (rr.err == -EINVAL ) -seq_puts (m,"Unavailable\n" ); -else -seq_printf (m,"%llu\n" , rr.val); - -out: -rdtgroup_kn_unlock (of->kn); -return ret; -}arch/x86/kernel/cpu/resctrl/internal.h +8
-372@@ -13,14 +13,16 @@#define L2_QOS_CDP_ENABLE 0x01ULL -#define CQM_LIMBOCHECK_INTERVAL 1000 -#define MBM_CNTR_WIDTH_BASE 24 +#define MBA_IS_LINEAR 0x4 +#define MBM_CNTR_WIDTH_OFFSET_AMD 20#define RMID_VAL_ERROR BIT_ULL(63) +#define RMID_VAL_UNAVAIL BIT_ULL(62) +/* * With the above fields in use 62 bits remain in MSR_IA32_QM_CTR for * data to be returned. The counter width is discovered from the hardware @@ -28,277 +30,6 @@*/ #define MBM_CNTR_WIDTH_OFFSET_MAX (62 - MBM_CNTR_WIDTH_BASE) -/** -* cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that -* aren't marked nohz_full -* @mask: The mask to pick a CPU from. -* @exclude_cpu:The CPU to avoid picking. -* -* Returns a CPU from @mask, but not @exclude_cpu. If there are housekeeping -* CPUs that don't use nohz_full, these are preferred. Pass -* RESCTRL_PICK_ANY_CPU to avoid excluding any CPUs. -* -* When a CPU is excluded, returns >= nr_cpu_ids if no CPUs are available. -*/ -static inline unsigned int -cpumask_any_housekeeping (const struct cpumask *mask,int exclude_cpu) -{ -unsigned int cpu, hk_cpu; - -if (exclude_cpu ==RESCTRL_PICK_ANY_CPU ) - cpu =cpumask_any (mask); -else - cpu =cpumask_any_but (mask, exclude_cpu); - -/* Only continue if tick_nohz_full_mask has been initialized. */ -if (!tick_nohz_full_enabled ()) -return cpu; - -/* If the CPU picked isn't marked nohz_full nothing more needs doing. */ -if (cpu < nr_cpu_ids && !tick_nohz_full_cpu (cpu)) -return cpu; - -/* Try to find a CPU that isn't nohz_full to use in preference */ - hk_cpu =cpumask_nth_andnot (0 , mask, tick_nohz_full_mask); -if (hk_cpu == exclude_cpu) - hk_cpu =cpumask_nth_andnot (1 , mask, tick_nohz_full_mask); - -if (hk_cpu < nr_cpu_ids) - cpu = hk_cpu; - -return cpu; -} - -struct rdt_fs_context { -struct kernfs_fs_context kfc; -bool enable_cdpl2; -bool enable_cdpl3; -bool enable_mba_mbps; -bool enable_debug; -}; - -static inline struct rdt_fs_context *rdt_fc2context (struct fs_context *fc) -{ -struct kernfs_fs_context *kfc = fc->fs_private; - - return container_of(kfc, struct rdt_fs_context, kfc); -} - -/** -* struct mon_evt - Entry in the event list of a resource -* @evtid: event id -* @name: name of the event -* @configurable: true if the event is configurable -* @list: entry in &rdt_resource->evt_list -*/ -struct mon_evt { -enum resctrl_event_id evtid; -char *name; -bool configurable; -struct list_head list; -}; - -/** -* struct mon_data - Monitoring details for each event file. -* @list: Member of list of all allocated structures. -* @rid: Resource id associated with the event file. -* @evtid: Event id associated with the event file. -* @sum: Set when event must be summed across multiple -* domains. -* @domid: When @sum is zero this is the domain to which -* the event file belongs. When @sum is one this -* is the id of the L3 cache that all domains to be -* summed share. -* -* Stored in the kernfs kn->priv field, readers and writers must hold -* rdtgroup_mutex. -*/ -struct mon_data { -struct list_head list; -unsigned int rid; -enum resctrl_event_id evtid; -unsigned int sum; -unsigned int domid; -}; - -/** -* struct rmid_read - Data passed across smp_call*() to read event count. -* @rgrp: Resource group for which the counter is being read. If it is a parent -* resource group then its event count is summed with the count from all -* its child resource groups. -* @r: Resource describing the properties of the event being read. -* @d: Domain that the counter should be read from. If NULL then sum all -* domains in @r sharing L3 @ci.id -* @evtid: Which monitor event to read. -* @first: Initialize MBM counter when true. -* @ci: Cacheinfo for L3. Only set when @d is NULL. Used when summing domains. -* @err: Error encountered when reading counter. -* @val: Returned value of event counter. If @rgrp is a parent resource group, -* @val includes the sum of event counts from its child resource groups. -* If @d is NULL, @val includes the sum of all domains in @r sharing @ci.id, -* (summed across child resource groups if @rgrp is a parent resource group). -* @arch_mon_ctx: Hardware monitor allocated for this read request (MPAM only). -*/ -struct rmid_read { -struct rdtgroup *rgrp; -struct rdt_resource *r; -struct rdt_mon_domain *d; -enum resctrl_event_id evtid; -bool first; -struct cacheinfo *ci; -int err; -u64 val; -void *arch_mon_ctx; -}; - -extern struct list_head resctrl_schema_all; -extern bool resctrl_mounted; - -enum rdt_group_type { -RDTCTRL_GROUP =0 , -RDTMON_GROUP , -RDT_NUM_GROUP , -}; - -/** -* enum rdtgrp_mode - Mode of a RDT resource group -* @RDT_MODE_SHAREABLE: This resource group allows sharing of its allocations -* @RDT_MODE_EXCLUSIVE: No sharing of this resource group's allocations allowed -* @RDT_MODE_PSEUDO_LOCKSETUP: Resource group will be used for Pseudo-Locking -* @RDT_MODE_PSEUDO_LOCKED: No sharing of this resource group's allocations -* allowed AND the allocations are Cache Pseudo-Locked -* @RDT_NUM_MODES: Total number of modes -* -* The mode of a resource group enables control over the allowed overlap -* between allocations associated with different resource groups (classes -* of service). User is able to modify the mode of a resource group by -* writing to the "mode" resctrl file associated with the resource group. -* -* The "shareable", "exclusive", and "pseudo-locksetup" modes are set by -* writing the appropriate text to the "mode" file. A resource group enters -* "pseudo-locked" mode after the schemata is written while the resource -* group is in "pseudo-locksetup" mode. -*/ -enum rdtgrp_mode { -RDT_MODE_SHAREABLE =0 , -RDT_MODE_EXCLUSIVE , -RDT_MODE_PSEUDO_LOCKSETUP , -RDT_MODE_PSEUDO_LOCKED , - -/* Must be last */ -RDT_NUM_MODES , -}; - -/** -* struct mongroup - store mon group's data in resctrl fs. -* @mon_data_kn: kernfs node for the mon_data directory -* @parent: parent rdtgrp -* @crdtgrp_list: child rdtgroup node list -* @rmid: rmid for this rdtgroup -*/ -struct mongroup { -struct kernfs_node *mon_data_kn; -struct rdtgroup *parent; -struct list_head crdtgrp_list; -u32 rmid; -}; - -/** -* 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 -* @cpu_mask: CPUs assigned to this rdtgroup -* @flags: status bits -* @waitcount: how many cpus expect to find this -* group when they acquire rdtgroup_mutex -* @type: indicates type of this rdtgroup - either -* monitor only or ctrl_mon group -* @mon: mongroup related data -* @mode: mode of resource group -* @mba_mbps_event: input monitoring event id when mba_sc is enabled -* @plr: pseudo-locked region -*/ -struct rdtgroup { -struct kernfs_node *kn; -struct list_head rdtgroup_list; -u32 closid; -struct cpumask cpu_mask; -int flags; -atomic_t waitcount; -enum rdt_group_type type; -struct mongroup mon; -enum rdtgrp_mode mode; -enum resctrl_event_id mba_mbps_event; -struct pseudo_lock_region *plr; -}; - -/* rdtgroup.flags */ -#define RDT_DELETED 1 - -/* rftype.flags */ -#define RFTYPE_FLAGS_CPUS_LIST 1 - -/* -* Define the file type flags for base and info directories. -*/ -#define RFTYPE_INFO BIT(0) -#define RFTYPE_BASE BIT(1) -#define RFTYPE_CTRL BIT(4) -#define RFTYPE_MON BIT(5) -#define RFTYPE_TOP BIT(6) -#define RFTYPE_RES_CACHE BIT(8) -#define RFTYPE_RES_MB BIT(9) -#define RFTYPE_DEBUG BIT(10) -#define RFTYPE_CTRL_INFO (RFTYPE_INFO | RFTYPE_CTRL) -#define RFTYPE_MON_INFO (RFTYPE_INFO | RFTYPE_MON) -#define RFTYPE_TOP_INFO (RFTYPE_INFO | RFTYPE_TOP) -#define RFTYPE_CTRL_BASE (RFTYPE_BASE | RFTYPE_CTRL) -#define RFTYPE_MON_BASE (RFTYPE_BASE | RFTYPE_MON) - -/* List of all resource groups */ -extern struct list_head rdt_all_groups; - -extern int max_name_width; - -/** -* struct rftype - describe each file in the resctrl file system -* @name: File name -* @mode: Access mode -* @kf_ops: File operations -* @flags: File specific RFTYPE_FLAGS_* flags -* @fflags: File specific RFTYPE_* flags -* @seq_show: Show content of the file -* @write: Write to the file -*/ -struct rftype { -char *name; -umode_t mode; -const struct kernfs_ops *kf_ops; -unsigned long flags; -unsigned long fflags; - -int (*seq_show)(struct kernfs_open_file *of, -struct seq_file *sf,void *v); -/* -* write() is the generic write callback which maps directly to -* kernfs write operation and overrides all other operations. -* Maximum write size is determined by ->max_write_len. -*/ -ssize_t (*write)(struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off); -}; - -/** -* struct mbm_state - status for each MBM counter in each domain -* @prev_bw_bytes: Previous bytes value read for bandwidth calculation -* @prev_bw: The most recent bandwidth in MBps -*/ -struct mbm_state { -u64 prev_bw_bytes; -u32 prev_bw; -}; -/** * struct arch_mbm_state - values used to compute resctrl_arch_rmid_read()s * return value. @@ -396,17 +127,7 @@ static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r return container_of(r, struct rdt_hw_resource, r_resctrl); } -extern struct mutex rdtgroup_mutex; - -static inline const char *rdt_kn_name (const struct kernfs_node *kn) -{ -return rcu_dereference_check (kn->name,lockdep_is_held (&rdtgroup_mutex)); -} -extern struct rdt_hw_resource rdt_resources_all[]; -extern struct rdtgroup rdtgroup_default; -extern struct dentry *debugfs_resctrl; -extern enum resctrl_event_id mba_mbps_default_event;void arch_mon_domain_online (struct rdt_resource *r,struct rdt_mon_domain *d);@@ -443,99 +164,14 @@ union cpuid_0x10_x_edx { unsigned int full; }; -void rdt_last_cmd_clear (void ); -void rdt_last_cmd_puts (const char *s); -__printf(1, 2) -void rdt_last_cmd_printf (const char *fmt, ...); -void rdt_ctrl_update (void *arg); -struct rdtgroup *rdtgroup_kn_lock_live (struct kernfs_node *kn); -void rdtgroup_kn_unlock (struct kernfs_node *kn); -int rdtgroup_kn_mode_restrict (struct rdtgroup *r,const char *name); -int rdtgroup_kn_mode_restore (struct rdtgroup *r,const char *name, -umode_t mask); -ssize_t rdtgroup_schemata_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off); -int rdtgroup_schemata_show (struct kernfs_open_file *of, -struct seq_file *s,void *v); -ssize_t rdtgroup_mba_mbps_event_write (struct kernfs_open_file *of, -char *buf,size_t nbytes,loff_t off); -int rdtgroup_mba_mbps_event_show (struct kernfs_open_file *of, -struct seq_file *s,void *v); -bool rdtgroup_cbm_overlaps (struct resctrl_schema *s,struct rdt_ctrl_domain *d, -unsigned long cbm,int closid,bool exclusive); -unsigned int rdtgroup_cbm_to_size (struct rdt_resource *r,struct rdt_ctrl_domain *d, -unsigned long cbm); -enum rdtgrp_mode rdtgroup_mode_by_closid (int closid); -int rdtgroup_tasks_assigned (struct rdtgroup *r); -int closids_supported (void ); -void closid_free (int closid); -int alloc_rmid (u32 closid); -void free_rmid (u32 closid,u32 rmid); -int rdt_get_mon_l3_config (struct rdt_resource *r); -void resctrl_mon_resource_exit (void ); -bool rdt_cpu_has (int flag); -void mon_event_count (void *info); -int rdtgroup_mondata_show (struct seq_file *m,void *arg); -void mon_event_read (struct rmid_read *rr,struct rdt_resource *r, -struct rdt_mon_domain *d,struct rdtgroup *rdtgrp, -cpumask_t *cpumask,int evtid,int first); -int resctrl_mon_resource_init (void ); -void mbm_setup_overflow_handler (struct rdt_mon_domain *dom, -unsigned long delay_ms, -int exclude_cpu); -void mbm_handle_overflow (struct work_struct *work); -void __init intel_rdt_mbm_apply_quirk (void ); -bool is_mba_sc (struct rdt_resource *r); -void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms, -int exclude_cpu); -void cqm_handle_limbo (struct work_struct *work); -bool has_busy_rmid (struct rdt_mon_domain *d); -void __check_limbo (struct rdt_mon_domain *d,bool force_free); -void rdt_domain_reconfigure_cdp (struct rdt_resource *r); -void resctrl_file_fflags_init (const char *config,unsigned long fflags); -void rdt_staged_configs_clear (void ); -bool closid_allocated (unsigned int closid); -int resctrl_find_cleanest_closid (void ); - -#ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK -int rdtgroup_locksetup_enter (struct rdtgroup *rdtgrp); -int rdtgroup_locksetup_exit (struct rdtgroup *rdtgrp); -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm); -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d); -int rdt_pseudo_lock_init (void ); -void rdt_pseudo_lock_release (void ); -int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp); -void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp); -#else -static inline int rdtgroup_locksetup_enter (struct rdtgroup *rdtgrp) -{ -return -EOPNOTSUPP ; -} - -static inline int rdtgroup_locksetup_exit (struct rdtgroup *rdtgrp) -{ -return -EOPNOTSUPP ; -} -static inline bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) -{ -return false; -} +int rdt_get_mon_l3_config (struct rdt_resource *r); -static inline bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) -{ -return false; -} +bool rdt_cpu_has (int flag); -static inline int rdt_pseudo_lock_init (void ) {return 0 ; } -static inline void rdt_pseudo_lock_release (void ) { } -static inline int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp) -{ -return -EOPNOTSUPP ; -} +void __init intel_rdt_mbm_apply_quirk (void ); -static inline void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp) { } -#endif /* CONFIG_RESCTRL_FS_PSEUDO_LOCK */ +void rdt_domain_reconfigure_cdp (struct rdt_resource *r);#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ arch/x86/kernel/cpu/resctrl/monitor.c +2
-900@@ -28,54 +28,8 @@#include "internal.h" #define CREATE_TRACE_POINTS -#include "monitor_trace.h" - -/** -* struct rmid_entry - dirty tracking for all RMID. -* @closid: The CLOSID for this entry. -* @rmid: The RMID for this entry. -* @busy: The number of domains with cached data using this RMID. -* @list: Member of the rmid_free_lru list when busy == 0. -* -* Depending on the architecture the correct monitor is accessed using -* both @closid and @rmid, or @rmid only. -* -* Take the rdtgroup_mutex when accessing. -*/ -struct rmid_entry { -u32 closid; -u32 rmid; -int busy; -struct list_head list; -}; -/* -* @rmid_free_lru - A least recently used list of free RMIDs -* These RMIDs are guaranteed to have an occupancy less than the -* threshold occupancy -*/ -static LIST_HEAD (rmid_free_lru); - -/* -* @closid_num_dirty_rmid The number of dirty RMID each CLOSID has. -* Only allocated when CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is defined. -* Indexed by CLOSID. Protected by rdtgroup_mutex. -*/ -static u32 *closid_num_dirty_rmid; - -/* -* @rmid_limbo_count - count of currently unused but (potentially) -* dirty RMIDs. -* This counts RMIDs that no one is currently using but that -* may have a occupancy value > resctrl_rmid_realloc_threshold. User can -* change the threshold occupancy value. -*/ -static unsigned int rmid_limbo_count; - -/* -* @rmid_entry - The entry in the limbo and free lists. -*/ -static struct rmid_entry *rmid_ptrs; +#include "monitor_trace.h" /* * Global boolean for rdt_monitor which is true if any @@ -88,17 +42,6 @@ bool rdt_mon_capable;*/ unsigned int rdt_mon_features; -/* -* This is the threshold cache occupancy in bytes at which we will consider an -* RMID available for re-allocation. -*/ -unsigned int resctrl_rmid_realloc_threshold; - -/* -* This is the maximum value for the reallocation threshold, in bytes. -*/ -unsigned int resctrl_rmid_realloc_limit; -#define CF (cf) ((unsigned long)(1048576 * (cf) + 0.5))static int snc_nodes_per_l3_cache =1 ;@@ -153,6 +96,7 @@ static const struct mbm_correction_factor_table { };static u32 mbm_cf_rmidthreshold__read_mostly =UINT_MAX ; +static u64 mbm_cf__read_mostly ;static inline u64 get_corrected_mbm_count (u32 rmid,unsigned long val)@@ -164,33 +108,6 @@ static inline u64 get_corrected_mbm_count(u32 rmid, unsigned long val)return val; } -/* -* x86 and arm64 differ in their handling of monitoring. -* x86's RMID are independent numbers, there is only one source of traffic -* with an RMID value of '1'. -* arm64's PMG extends the PARTID/CLOSID space, there are multiple sources of -* traffic with a PMG value of '1', one for each CLOSID, meaning the RMID -* value is no longer unique. -* To account for this, resctrl uses an index. On x86 this is just the RMID, -* on arm64 it encodes the CLOSID and RMID. This gives a unique number. -* -* The domain's rmid_busy_llc and rmid_ptrs[] are sized by index. The arch code -* must accept an attempt to read every index. -*/ -static inline struct rmid_entry *__rmid_entry (u32 idx) -{ -struct rmid_entry *entry; -u32 closid, rmid; - - entry = &rmid_ptrs[idx]; -resctrl_arch_rmid_idx_decode (idx, &closid, &rmid); - -WARN_ON_ONCE (entry->closid != closid); -WARN_ON_ONCE (entry->rmid != rmid); - -return entry; -} -/* * When Sub-NUMA Cluster (SNC) mode is not enabled (as indicated by * "snc_nodes_per_l3_cache == 1") no translation of the RMID value is @@ -348,769 +265,6 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,return 0 ; } -static void limbo_release_entry (struct rmid_entry *entry) -{ -lockdep_assert_held (&rdtgroup_mutex); - - rmid_limbo_count--; -list_add_tail (&entry->list, &rmid_free_lru); - -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) - closid_num_dirty_rmid[entry->closid]--; -} - -/* -* Check the RMIDs that are marked as busy for this domain. If the -* reported LLC occupancy is below the threshold clear the busy bit and -* decrement the count. If the busy count gets to zero on an RMID, we -* free the RMID -*/ -void __check_limbo (struct rdt_mon_domain *d,bool force_free) -{ -struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -u32 idx_limit =resctrl_arch_system_num_rmid_idx (); -struct rmid_entry *entry; -u32 idx, cur_idx =1 ; -void *arch_mon_ctx; -bool rmid_dirty; -u64 val =0 ; - - arch_mon_ctx =resctrl_arch_mon_ctx_alloc (r,QOS_L3_OCCUP_EVENT_ID ); -if (IS_ERR (arch_mon_ctx)) { -pr_warn_ratelimited ("Failed to allocate monitor context: %ld" , -PTR_ERR (arch_mon_ctx)); -return ; - } - -/* -* Skip RMID 0 and start from RMID 1 and check all the RMIDs that -* are marked as busy for occupancy < threshold. If the occupancy -* is less than the threshold decrement the busy counter of the -* RMID and move it to the free list when the counter reaches 0. -*/ -for (;;) { - idx =find_next_bit (d->rmid_busy_llc, idx_limit, cur_idx); -if (idx >= idx_limit) -break ; - - entry =__rmid_entry (idx); -if (resctrl_arch_rmid_read (r, d, entry->closid, entry->rmid, -QOS_L3_OCCUP_EVENT_ID , &val, - arch_mon_ctx)) { - rmid_dirty = true; - }else { - rmid_dirty = (val >= resctrl_rmid_realloc_threshold); - -/* -* x86's CLOSID and RMID are independent numbers, so the entry's -* CLOSID is an empty CLOSID (X86_RESCTRL_EMPTY_CLOSID). On Arm the -* RMID (PMG) extends the CLOSID (PARTID) space with bits that aren't -* used to select the configuration. It is thus necessary to track both -* CLOSID and RMID because there may be dependencies between them -* on some architectures. -*/ -trace_mon_llc_occupancy_limbo (entry->closid, entry->rmid, d->hdr.id, val); - } - -if (force_free || !rmid_dirty) { -clear_bit (idx, d->rmid_busy_llc); -if (!--entry->busy) -limbo_release_entry (entry); - } - cur_idx = idx +1 ; - } - -resctrl_arch_mon_ctx_free (r,QOS_L3_OCCUP_EVENT_ID , arch_mon_ctx); -} - -bool has_busy_rmid (struct rdt_mon_domain *d) -{ -u32 idx_limit =resctrl_arch_system_num_rmid_idx (); - -return find_first_bit (d->rmid_busy_llc, idx_limit) != idx_limit; -} - -static struct rmid_entry *resctrl_find_free_rmid (u32 closid) -{ -struct rmid_entry *itr; -u32 itr_idx, cmp_idx; - -if (list_empty (&rmid_free_lru)) -return rmid_limbo_count ?ERR_PTR (-EBUSY ) :ERR_PTR (-ENOSPC ); - -list_for_each_entry (itr, &rmid_free_lru, list) { -/* -* Get the index of this free RMID, and the index it would need -* to be if it were used with this CLOSID. -* If the CLOSID is irrelevant on this architecture, the two -* index values are always the same on every entry and thus the -* very first entry will be returned. -*/ - itr_idx =resctrl_arch_rmid_idx_encode (itr->closid, itr->rmid); - cmp_idx =resctrl_arch_rmid_idx_encode (closid, itr->rmid); - -if (itr_idx == cmp_idx) -return itr; - } - -return ERR_PTR (-ENOSPC ); -} - -/** -* resctrl_find_cleanest_closid() - Find a CLOSID where all the associated -* RMID are clean, or the CLOSID that has -* the most clean RMID. -* -* MPAM's equivalent of RMID are per-CLOSID, meaning a freshly allocated CLOSID -* may not be able to allocate clean RMID. To avoid this the allocator will -* choose the CLOSID with the most clean RMID. -* -* When the CLOSID and RMID are independent numbers, the first free CLOSID will -* be returned. -*/ -int resctrl_find_cleanest_closid (void ) -{ -u32 cleanest_closid = ~0 ; -int i =0 ; - -lockdep_assert_held (&rdtgroup_mutex); - -if (!IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) -return -EIO ; - -for (i =0 ; i <closids_supported (); i++) { -int num_dirty; - -if (closid_allocated (i)) -continue ; - - num_dirty = closid_num_dirty_rmid[i]; -if (num_dirty ==0 ) -return i; - -if (cleanest_closid == ~0 ) - cleanest_closid = i; - -if (num_dirty < closid_num_dirty_rmid[cleanest_closid]) - cleanest_closid = i; - } - -if (cleanest_closid == ~0 ) -return -ENOSPC ; - -return cleanest_closid; -} - -/* -* For MPAM the RMID value is not unique, and has to be considered with -* the CLOSID. The (CLOSID, RMID) pair is allocated on all domains, which -* allows all domains to be managed by a single free list. -* Each domain also has a rmid_busy_llc to reduce the work of the limbo handler. -*/ -int alloc_rmid (u32 closid) -{ -struct rmid_entry *entry; - -lockdep_assert_held (&rdtgroup_mutex); - - entry =resctrl_find_free_rmid (closid); -if (IS_ERR (entry)) -return PTR_ERR (entry); - -list_del (&entry->list); -return entry->rmid; -} - -static void add_rmid_to_limbo (struct rmid_entry *entry) -{ -struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -struct rdt_mon_domain *d; -u32 idx; - -lockdep_assert_held (&rdtgroup_mutex); - -/* Walking r->domains, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - - idx =resctrl_arch_rmid_idx_encode (entry->closid, entry->rmid); - - entry->busy =0 ; -list_for_each_entry (d, &r->mon_domains, hdr.list) { -/* -* For the first limbo RMID in the domain, -* setup up the limbo worker. -*/ -if (!has_busy_rmid (d)) -cqm_setup_limbo_handler (d,CQM_LIMBOCHECK_INTERVAL , -RESCTRL_PICK_ANY_CPU ); -set_bit (idx, d->rmid_busy_llc); - entry->busy++; - } - - rmid_limbo_count++; -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) - closid_num_dirty_rmid[entry->closid]++; -} - -void free_rmid (u32 closid,u32 rmid) -{ -u32 idx =resctrl_arch_rmid_idx_encode (closid, rmid); -struct rmid_entry *entry; - -lockdep_assert_held (&rdtgroup_mutex); - -/* -* Do not allow the default rmid to be free'd. Comparing by index -* allows architectures that ignore the closid parameter to avoid an -* unnecessary check. -*/ -if (!resctrl_arch_mon_capable () || - idx ==resctrl_arch_rmid_idx_encode (RESCTRL_RESERVED_CLOSID , -RESCTRL_RESERVED_RMID )) -return ; - - entry =__rmid_entry (idx); - -if (resctrl_arch_is_llc_occupancy_enabled ()) -add_rmid_to_limbo (entry); -else -list_add_tail (&entry->list, &rmid_free_lru); -} - -static struct mbm_state *get_mbm_state (struct rdt_mon_domain *d,u32 closid, -u32 rmid,enum resctrl_event_id evtid) -{ -u32 idx =resctrl_arch_rmid_idx_encode (closid, rmid); - -switch (evtid) { -case QOS_L3_MBM_TOTAL_EVENT_ID : -return &d->mbm_total[idx]; -case QOS_L3_MBM_LOCAL_EVENT_ID : -return &d->mbm_local[idx]; -default : -return NULL ; - } -} - -static int __mon_event_count (u32 closid,u32 rmid,struct rmid_read *rr) -{ -int cpu =smp_processor_id (); -struct rdt_mon_domain *d; -struct mbm_state *m; -int err, ret; -u64 tval =0 ; - -if (rr->first) { -resctrl_arch_reset_rmid (rr->r, rr->d, closid, rmid, rr->evtid); - m =get_mbm_state (rr->d, closid, rmid, rr->evtid); -if (m) -memset (m,0 ,sizeof (struct mbm_state )); -return 0 ; - } - -if (rr->d) { -/* Reading a single domain, must be on a CPU in that domain. */ -if (!cpumask_test_cpu (cpu, &rr->d->hdr.cpu_mask)) -return -EINVAL ; - rr->err =resctrl_arch_rmid_read (rr->r, rr->d, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); -if (rr->err) -return rr->err; - - rr->val += tval; - -return 0 ; - } - -/* Summing domains that share a cache, must be on a CPU for that cache. */ -if (!cpumask_test_cpu (cpu, &rr->ci->shared_cpu_map)) -return -EINVAL ; - -/* -* Legacy files must report the sum of an event across all -* domains that share the same L3 cache instance. -* Report success if a read from any domain succeeds, -EINVAL -* (translated to "Unavailable" for user space) if reading from -* all domains fail for any reason. -*/ - ret = -EINVAL ; -list_for_each_entry (d, &rr->r->mon_domains, hdr.list) { -if (d->ci->id != rr->ci->id) -continue ; - err =resctrl_arch_rmid_read (rr->r, d, closid, rmid, - rr->evtid, &tval, rr->arch_mon_ctx); -if (!err) { - rr->val += tval; - ret =0 ; - } - } - -if (ret) - rr->err = ret; - -return ret; -} - -/* -* mbm_bw_count() - Update bw count from values previously read by -* __mon_event_count(). -* @closid: The closid used to identify the cached mbm_state. -* @rmid: The rmid used to identify the cached mbm_state. -* @rr: The struct rmid_read populated by __mon_event_count(). -* -* Supporting function to calculate the memory bandwidth -* and delta bandwidth in MBps. The chunks value previously read by -* __mon_event_count() is compared with the chunks value from the previous -* invocation. This must be called once per second to maintain values in MBps. -*/ -static void mbm_bw_count (u32 closid,u32 rmid,struct rmid_read *rr) -{ -u64 cur_bw, bytes, cur_bytes; -struct mbm_state *m; - - m =get_mbm_state (rr->d, closid, rmid, rr->evtid); -if (WARN_ON_ONCE (!m)) -return ; - - cur_bytes = rr->val; - bytes = cur_bytes - m->prev_bw_bytes; - m->prev_bw_bytes = cur_bytes; - - cur_bw = bytes /SZ_1M ; - - m->prev_bw = cur_bw; -} - -/* -* This is scheduled by mon_event_read() to read the CQM/MBM counters -* on a domain. -*/ -void mon_event_count (void *info) -{ -struct rdtgroup *rdtgrp, *entry; -struct rmid_read *rr = info; -struct list_head *head; -int ret; - - rdtgrp = rr->rgrp; - - ret =__mon_event_count (rdtgrp->closid, rdtgrp->mon.rmid, rr); - -/* -* For Ctrl groups read data from child monitor groups and -* add them together. Count events which are read successfully. -* Discard the rmid_read's reporting errors. -*/ - head = &rdtgrp->mon.crdtgrp_list; - -if (rdtgrp->type ==RDTCTRL_GROUP ) { -list_for_each_entry (entry, head, mon.crdtgrp_list) { -if (__mon_event_count (entry->closid, entry->mon.rmid, - rr) ==0 ) - ret =0 ; - } - } - -/* -* __mon_event_count() calls for newly created monitor groups may -* report -EINVAL/Unavailable if the monitor hasn't seen any traffic. -* Discard error if any of the monitor event reads succeeded. -*/ -if (ret ==0 ) - rr->err =0 ; -} - -static struct rdt_ctrl_domain *get_ctrl_domain_from_cpu (int cpu, -struct rdt_resource *r) -{ -struct rdt_ctrl_domain *d; - -lockdep_assert_cpus_held (); - -list_for_each_entry (d, &r->ctrl_domains, hdr.list) { -/* Find the domain that contains this CPU */ -if (cpumask_test_cpu (cpu, &d->hdr.cpu_mask)) -return d; - } - -return NULL ; -} - -/* -* Feedback loop for MBA software controller (mba_sc) -* -* mba_sc is a feedback loop where we periodically read MBM counters and -* adjust the bandwidth percentage values via the IA32_MBA_THRTL_MSRs so -* that: -* -* current bandwidth(cur_bw) < user specified bandwidth(user_bw) -* -* This uses the MBM counters to measure the bandwidth and MBA throttle -* MSRs to control the bandwidth for a particular rdtgrp. It builds on the -* fact that resctrl rdtgroups have both monitoring and control. -* -* The frequency of the checks is 1s and we just tag along the MBM overflow -* timer. Having 1s interval makes the calculation of bandwidth simpler. -* -* Although MBA's goal is to restrict the bandwidth to a maximum, there may -* be a need to increase the bandwidth to avoid unnecessarily restricting -* the L2 <-> L3 traffic. -* -* Since MBA controls the L2 external bandwidth where as MBM measures the -* L3 external bandwidth the following sequence could lead to such a -* situation. -* -* Consider an rdtgroup which had high L3 <-> memory traffic in initial -* phases -> mba_sc kicks in and reduced bandwidth percentage values -> but -* after some time rdtgroup has mostly L2 <-> L3 traffic. -* -* In this case we may restrict the rdtgroup's L2 <-> L3 traffic as its -* throttle MSRs already have low percentage values. To avoid -* unnecessarily restricting such rdtgroups, we also increase the bandwidth. -*/ -static void update_mba_bw (struct rdtgroup *rgrp,struct rdt_mon_domain *dom_mbm) -{ -u32 closid, rmid, cur_msr_val, new_msr_val; -struct mbm_state *pmbm_data, *cmbm_data; -struct rdt_ctrl_domain *dom_mba; -enum resctrl_event_id evt_id; -struct rdt_resource *r_mba; -struct list_head *head; -struct rdtgroup *entry; -u32 cur_bw, user_bw; - - r_mba =resctrl_arch_get_resource (RDT_RESOURCE_MBA ); - evt_id = rgrp->mba_mbps_event; - - closid = rgrp->closid; - rmid = rgrp->mon.rmid; - pmbm_data =get_mbm_state (dom_mbm, closid, rmid, evt_id); -if (WARN_ON_ONCE (!pmbm_data)) -return ; - - dom_mba =get_ctrl_domain_from_cpu (smp_processor_id (), r_mba); -if (!dom_mba) { -pr_warn_once ("Failure to get domain for MBA update\n" ); -return ; - } - - cur_bw = pmbm_data->prev_bw; - user_bw = dom_mba->mbps_val[closid]; - -/* MBA resource doesn't support CDP */ - cur_msr_val =resctrl_arch_get_config (r_mba, dom_mba, closid,CDP_NONE ); - -/* -* For Ctrl groups read data from child monitor groups. -*/ - head = &rgrp->mon.crdtgrp_list; -list_for_each_entry (entry, head, mon.crdtgrp_list) { - cmbm_data =get_mbm_state (dom_mbm, entry->closid, entry->mon.rmid, evt_id); -if (WARN_ON_ONCE (!cmbm_data)) -return ; - cur_bw += cmbm_data->prev_bw; - } - -/* -* Scale up/down the bandwidth linearly for the ctrl group. The -* bandwidth step is the bandwidth granularity specified by the -* hardware. -* Always increase throttling if current bandwidth is above the -* target set by user. -* But avoid thrashing up and down on every poll by checking -* whether a decrease in throttling is likely to push the group -* back over target. E.g. if currently throttling to 30% of bandwidth -* on a system with 10% granularity steps, check whether moving to -* 40% would go past the limit by multiplying current bandwidth by -* "(30 + 10) / 30". -*/ -if (cur_msr_val > r_mba->membw.min_bw && user_bw < cur_bw) { - new_msr_val = cur_msr_val - r_mba->membw.bw_gran; - }else if (cur_msr_val <MAX_MBA_BW && - (user_bw > (cur_bw * (cur_msr_val + r_mba->membw.min_bw) / cur_msr_val))) { - new_msr_val = cur_msr_val + r_mba->membw.bw_gran; - }else { -return ; - } - -resctrl_arch_update_one (r_mba, dom_mba, closid,CDP_NONE , new_msr_val); -} - -static void mbm_update_one_event (struct rdt_resource *r,struct rdt_mon_domain *d, -u32 closid,u32 rmid,enum resctrl_event_id evtid) -{ -struct rmid_read rr = {0 }; - - rr.r = r; - rr.d = d; - rr.evtid = evtid; - rr.arch_mon_ctx =resctrl_arch_mon_ctx_alloc (rr.r, rr.evtid); -if (IS_ERR (rr.arch_mon_ctx)) { -pr_warn_ratelimited ("Failed to allocate monitor context: %ld" , -PTR_ERR (rr.arch_mon_ctx)); -return ; - } - -__mon_event_count (closid, rmid, &rr); - -/* -* If the software controller is enabled, compute the -* bandwidth for this event id. -*/ -if (is_mba_sc (NULL )) -mbm_bw_count (closid, rmid, &rr); - -resctrl_arch_mon_ctx_free (rr.r, rr.evtid, rr.arch_mon_ctx); -} - -static void mbm_update (struct rdt_resource *r,struct rdt_mon_domain *d, -u32 closid,u32 rmid) -{ -/* -* This is protected from concurrent reads from user as both -* the user and overflow handler hold the global mutex. -*/ -if (resctrl_arch_is_mbm_total_enabled ()) -mbm_update_one_event (r, d, closid, rmid,QOS_L3_MBM_TOTAL_EVENT_ID ); - -if (resctrl_arch_is_mbm_local_enabled ()) -mbm_update_one_event (r, d, closid, rmid,QOS_L3_MBM_LOCAL_EVENT_ID ); -} - -/* -* Handler to scan the limbo list and move the RMIDs -* to free list whose occupancy < threshold_occupancy. -*/ -void cqm_handle_limbo (struct work_struct *work) -{ -unsigned long delay =msecs_to_jiffies (CQM_LIMBOCHECK_INTERVAL ); -struct rdt_mon_domain *d; - -cpus_read_lock (); -mutex_lock (&rdtgroup_mutex); - - d = container_of(work, struct rdt_mon_domain, cqm_limbo.work); - -__check_limbo (d, false); - -if (has_busy_rmid (d)) { - d->cqm_work_cpu =cpumask_any_housekeeping (&d->hdr.cpu_mask, -RESCTRL_PICK_ANY_CPU ); -schedule_delayed_work_on (d->cqm_work_cpu, &d->cqm_limbo, - delay); - } - -mutex_unlock (&rdtgroup_mutex); -cpus_read_unlock (); -} - -/** -* cqm_setup_limbo_handler() - Schedule the limbo handler to run for this -* domain. -* @dom: The domain the limbo handler should run for. -* @delay_ms: How far in the future the handler should run. -* @exclude_cpu: Which CPU the handler should not run on, -* RESCTRL_PICK_ANY_CPU to pick any CPU. -*/ -void cqm_setup_limbo_handler (struct rdt_mon_domain *dom,unsigned long delay_ms, -int exclude_cpu) -{ -unsigned long delay =msecs_to_jiffies (delay_ms); -int cpu; - - cpu =cpumask_any_housekeeping (&dom->hdr.cpu_mask, exclude_cpu); - dom->cqm_work_cpu = cpu; - -if (cpu < nr_cpu_ids) -schedule_delayed_work_on (cpu, &dom->cqm_limbo, delay); -} - -void mbm_handle_overflow (struct work_struct *work) -{ -unsigned long delay =msecs_to_jiffies (MBM_OVERFLOW_INTERVAL ); -struct rdtgroup *prgrp, *crgrp; -struct rdt_mon_domain *d; -struct list_head *head; -struct rdt_resource *r; - -cpus_read_lock (); -mutex_lock (&rdtgroup_mutex); - -/* -* If the filesystem has been unmounted this work no longer needs to -* run. -*/ -if (!resctrl_mounted || !resctrl_arch_mon_capable ()) - goto out_unlock; - - r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); - d = container_of(work, struct rdt_mon_domain, mbm_over.work); - -list_for_each_entry (prgrp, &rdt_all_groups, rdtgroup_list) { -mbm_update (r, d, prgrp->closid, prgrp->mon.rmid); - - head = &prgrp->mon.crdtgrp_list; -list_for_each_entry (crgrp, head, mon.crdtgrp_list) -mbm_update (r, d, crgrp->closid, crgrp->mon.rmid); - -if (is_mba_sc (NULL )) -update_mba_bw (prgrp, d); - } - -/* -* Re-check for housekeeping CPUs. This allows the overflow handler to -* move off a nohz_full CPU quickly. -*/ - d->mbm_work_cpu =cpumask_any_housekeeping (&d->hdr.cpu_mask, -RESCTRL_PICK_ANY_CPU ); -schedule_delayed_work_on (d->mbm_work_cpu, &d->mbm_over, delay); - -out_unlock: -mutex_unlock (&rdtgroup_mutex); -cpus_read_unlock (); -} - -/** -* mbm_setup_overflow_handler() - Schedule the overflow handler to run for this -* domain. -* @dom: The domain the overflow handler should run for. -* @delay_ms: How far in the future the handler should run. -* @exclude_cpu: Which CPU the handler should not run on, -* RESCTRL_PICK_ANY_CPU to pick any CPU. -*/ -void mbm_setup_overflow_handler (struct rdt_mon_domain *dom,unsigned long delay_ms, -int exclude_cpu) -{ -unsigned long delay =msecs_to_jiffies (delay_ms); -int cpu; - -/* -* When a domain comes online there is no guarantee the filesystem is -* mounted. If not, there is no need to catch counter overflow. -*/ -if (!resctrl_mounted || !resctrl_arch_mon_capable ()) -return ; - cpu =cpumask_any_housekeeping (&dom->hdr.cpu_mask, exclude_cpu); - dom->mbm_work_cpu = cpu; - -if (cpu < nr_cpu_ids) -schedule_delayed_work_on (cpu, &dom->mbm_over, delay); -} - -static int dom_data_init (struct rdt_resource *r) -{ -u32 idx_limit =resctrl_arch_system_num_rmid_idx (); -u32 num_closid =resctrl_arch_get_num_closid (r); -struct rmid_entry *entry =NULL ; -int err =0 , i; -u32 idx; - -mutex_lock (&rdtgroup_mutex); -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -u32 *tmp; - -/* -* If the architecture hasn't provided a sanitised value here, -* this may result in larger arrays than necessary. Resctrl will -* use a smaller system wide value based on the resources in -* use. -*/ - tmp =kcalloc (num_closid,sizeof (*tmp),GFP_KERNEL ); -if (!tmp) { - err = -ENOMEM ; - goto out_unlock; - } - - closid_num_dirty_rmid = tmp; - } - - rmid_ptrs =kcalloc (idx_limit,sizeof (struct rmid_entry ),GFP_KERNEL ); -if (!rmid_ptrs) { -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } - err = -ENOMEM ; - goto out_unlock; - } - -for (i =0 ; i < idx_limit; i++) { - entry = &rmid_ptrs[i]; -INIT_LIST_HEAD (&entry->list); - -resctrl_arch_rmid_idx_decode (i, &entry->closid, &entry->rmid); -list_add_tail (&entry->list, &rmid_free_lru); - } - -/* -* RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID are special and -* are always allocated. These are used for the rdtgroup_default -* control group, which will be setup later in resctrl_init(). -*/ - idx =resctrl_arch_rmid_idx_encode (RESCTRL_RESERVED_CLOSID , -RESCTRL_RESERVED_RMID ); - entry =__rmid_entry (idx); -list_del (&entry->list); - -out_unlock: -mutex_unlock (&rdtgroup_mutex); - -return err; -} - -static void dom_data_exit (struct rdt_resource *r) -{ -mutex_lock (&rdtgroup_mutex); - -if (!r->mon_capable) - goto out_unlock; - -if (IS_ENABLED (CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID )) { -kfree (closid_num_dirty_rmid); - closid_num_dirty_rmid =NULL ; - } - -kfree (rmid_ptrs); - rmid_ptrs =NULL ; - -out_unlock: -mutex_unlock (&rdtgroup_mutex); -} - -static struct mon_evt llc_occupancy_event = { - .name ="llc_occupancy" , - .evtid =QOS_L3_OCCUP_EVENT_ID , -}; - -static struct mon_evt mbm_total_event = { - .name ="mbm_total_bytes" , - .evtid =QOS_L3_MBM_TOTAL_EVENT_ID , -}; - -static struct mon_evt mbm_local_event = { - .name ="mbm_local_bytes" , - .evtid =QOS_L3_MBM_LOCAL_EVENT_ID , -}; - -/* -* Initialize the event list for the resource. -* -* Note that MBM events are also part of RDT_RESOURCE_L3 resource -* because as per the SDM the total and local memory bandwidth -* are enumerated as part of L3 monitoring. -*/ -static void l3_mon_evt_init (struct rdt_resource *r) -{ -INIT_LIST_HEAD (&r->evt_list); - -if (resctrl_arch_is_llc_occupancy_enabled ()) -list_add_tail (&llc_occupancy_event.list, &r->evt_list); -if (resctrl_arch_is_mbm_total_enabled ()) -list_add_tail (&mbm_total_event.list, &r->evt_list); -if (resctrl_arch_is_mbm_local_enabled ()) -list_add_tail (&mbm_local_event.list, &r->evt_list); -} -/* * The power-on reset value of MSR_RMID_SNC_CONFIG is 0x1 * which indicates that RMIDs are configured in legacy mode. @@ -1194,51 +348,6 @@ static __init int snc_get_config(void)return ret; } -/** -* resctrl_mon_resource_init() - Initialise global monitoring structures. -* -* Allocate and initialise global monitor resources that do not belong to a -* specific domain. i.e. the rmid_ptrs[] used for the limbo and free lists. -* Called once during boot after the struct rdt_resource's have been configured -* but before the filesystem is mounted. -* Resctrl's cpuhp callbacks may be called before this point to bring a domain -* online. -* -* Returns 0 for success, or -ENOMEM. -*/ -int resctrl_mon_resource_init (void ) -{ -struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); -int ret; - -if (!r->mon_capable) -return 0 ; - - ret =dom_data_init (r); -if (ret) -return ret; - -l3_mon_evt_init (r); - -if (resctrl_arch_is_evt_configurable (QOS_L3_MBM_TOTAL_EVENT_ID )) { - mbm_total_event.configurable = true; -resctrl_file_fflags_init ("mbm_total_bytes_config" , -RFTYPE_MON_INFO |RFTYPE_RES_CACHE ); - } -if (resctrl_arch_is_evt_configurable (QOS_L3_MBM_LOCAL_EVENT_ID )) { - mbm_local_event.configurable = true; -resctrl_file_fflags_init ("mbm_local_bytes_config" , -RFTYPE_MON_INFO |RFTYPE_RES_CACHE ); - } - -if (resctrl_arch_is_mbm_local_enabled ()) - mba_mbps_default_event =QOS_L3_MBM_LOCAL_EVENT_ID ; -else if (resctrl_arch_is_mbm_total_enabled ()) - mba_mbps_default_event =QOS_L3_MBM_TOTAL_EVENT_ID ; - -return 0 ; -} -int __init rdt_get_mon_l3_config (struct rdt_resource *r) {unsigned int mbm_offset = boot_cpu_data.x86_cache_mbm_width_offset;@@ -1286,13 +395,6 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)return 0 ; } -void resctrl_mon_resource_exit (void ) -{ -struct rdt_resource *r =resctrl_arch_get_resource (RDT_RESOURCE_L3 ); - -dom_data_exit (r); -} -void __init intel_rdt_mbm_apply_quirk (void ) {int cf_index;arch/x86/kernel/cpu/resctrl/monitor_trace.h +2
-16@@ -7,25 +7,11 @@#include <linux/tracepoint.h> -TRACE_EVENT (mon_llc_occupancy_limbo, - TP_PROTO(u32 ctrl_hw_id, u32 mon_hw_id, int domain_id, u64 llc_occupancy_bytes), -TP_ARGS (ctrl_hw_id, mon_hw_id, domain_id, llc_occupancy_bytes), - TP_STRUCT__entry(__field(u32, ctrl_hw_id) - __field(u32, mon_hw_id) - __field(int, domain_id) -__field (u64, llc_occupancy_bytes)), - TP_fast_assign(__entry->ctrl_hw_id = ctrl_hw_id; - __entry->mon_hw_id = mon_hw_id; - __entry->domain_id = domain_id; - __entry->llc_occupancy_bytes = llc_occupancy_bytes;), -TP_printk ("ctrl_hw_id=%u mon_hw_id=%u domain_id=%d llc_occupancy_bytes=%llu" , - __entry->ctrl_hw_id, __entry->mon_hw_id, __entry->domain_id, - __entry->llc_occupancy_bytes) - ); -#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ #undef TRACE_INCLUDE_PATH#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_FILE monitor_trace +#include <trace/define_trace.h> arch/x86/kernel/cpu/resctrl/pseudo_lock.c +1
-1079@@ -31,6 +31,7 @@#include "internal.h" #define CREATE_TRACE_POINTS +#include "pseudo_lock_trace.h" /* @@ -39,29 +40,6 @@*/ static u64 prefetch_disable_bits; -/* -* Major number assigned to and shared by all devices exposing -* pseudo-locked regions. -*/ -static unsigned int pseudo_lock_major; -static unsigned long pseudo_lock_minor_avail =GENMASK (MINORBITS ,0 ); - -static char *pseudo_lock_devnode (const struct device *dev,umode_t *mode) -{ -const struct rdtgroup *rdtgrp; - - rdtgrp =dev_get_drvdata (dev); -if (mode) - *mode =0600 ; -guard (mutex)(&rdtgroup_mutex); -return kasprintf (GFP_KERNEL ,"pseudo_lock/%s" ,rdt_kn_name (rdtgrp->kn)); -} - -static const struct class pseudo_lock_class = { - .name ="pseudo_lock" , - .devnode = pseudo_lock_devnode, -}; -/** * resctrl_arch_get_prefetch_disable_bits - prefetch disable bits of supported * platforms @@ -122,298 +100,6 @@ u64 resctrl_arch_get_prefetch_disable_bits(void)return prefetch_disable_bits; } -/** -* pseudo_lock_minor_get - Obtain available minor number -* @minor: Pointer to where new minor number will be stored -* -* A bitmask is used to track available minor numbers. Here the next free -* minor number is marked as unavailable and returned. -* -* Return: 0 on success, <0 on failure. -*/ -static int pseudo_lock_minor_get (unsigned int *minor) -{ -unsigned long first_bit; - - first_bit =find_first_bit (&pseudo_lock_minor_avail,MINORBITS ); - -if (first_bit ==MINORBITS ) -return -ENOSPC ; - -__clear_bit (first_bit, &pseudo_lock_minor_avail); - *minor = first_bit; - -return 0 ; -} - -/** -* pseudo_lock_minor_release - Return minor number to available -* @minor: The minor number made available -*/ -static void pseudo_lock_minor_release (unsigned int minor) -{ -__set_bit (minor, &pseudo_lock_minor_avail); -} - -/** -* region_find_by_minor - Locate a pseudo-lock region by inode minor number -* @minor: The minor number of the device representing pseudo-locked region -* -* When the character device is accessed we need to determine which -* pseudo-locked region it belongs to. This is done by matching the minor -* number of the device to the pseudo-locked region it belongs. -* -* Minor numbers are assigned at the time a pseudo-locked region is associated -* with a cache instance. -* -* Return: On success return pointer to resource group owning the pseudo-locked -* region, NULL on failure. -*/ -static struct rdtgroup *region_find_by_minor (unsigned int minor) -{ -struct rdtgroup *rdtgrp, *rdtgrp_match =NULL ; - -list_for_each_entry (rdtgrp, &rdt_all_groups, rdtgroup_list) { -if (rdtgrp->plr && rdtgrp->plr->minor == minor) { - rdtgrp_match = rdtgrp; -break ; - } - } -return rdtgrp_match; -} - -/** -* struct pseudo_lock_pm_req - A power management QoS request list entry -* @list: Entry within the @pm_reqs list for a pseudo-locked region -* @req: PM QoS request -*/ -struct pseudo_lock_pm_req { -struct list_head list; -struct dev_pm_qos_request req; -}; - -static void pseudo_lock_cstates_relax (struct pseudo_lock_region *plr) -{ -struct pseudo_lock_pm_req *pm_req, *next; - -list_for_each_entry_safe (pm_req, next, &plr->pm_reqs, list) { -dev_pm_qos_remove_request (&pm_req->req); -list_del (&pm_req->list); -kfree (pm_req); - } -} - -/** -* pseudo_lock_cstates_constrain - Restrict cores from entering C6 -* @plr: Pseudo-locked region -* -* To prevent the cache from being affected by power management entering -* C6 has to be avoided. This is accomplished by requesting a latency -* requirement lower than lowest C6 exit latency of all supported -* platforms as found in the cpuidle state tables in the intel_idle driver. -* At this time it is possible to do so with a single latency requirement -* for all supported platforms. -* -* Since Goldmont is supported, which is affected by X86_BUG_MONITOR, -* the ACPI latencies need to be considered while keeping in mind that C2 -* may be set to map to deeper sleep states. In this case the latency -* requirement needs to prevent entering C2 also. -* -* Return: 0 on success, <0 on failure -*/ -static int pseudo_lock_cstates_constrain (struct pseudo_lock_region *plr) -{ -struct pseudo_lock_pm_req *pm_req; -int cpu; -int ret; - -for_each_cpu (cpu, &plr->d->hdr.cpu_mask) { - pm_req =kzalloc (sizeof (*pm_req),GFP_KERNEL ); -if (!pm_req) { -rdt_last_cmd_puts ("Failure to allocate memory for PM QoS\n" ); - ret = -ENOMEM ; - goto out_err; - } - ret =dev_pm_qos_add_request (get_cpu_device (cpu), - &pm_req->req, -DEV_PM_QOS_RESUME_LATENCY , -30 ); -if (ret <0 ) { -rdt_last_cmd_printf ("Failed to add latency req CPU%d\n" , - cpu); -kfree (pm_req); - ret =-1 ; - goto out_err; - } -list_add (&pm_req->list, &plr->pm_reqs); - } - -return 0 ; - -out_err: -pseudo_lock_cstates_relax (plr); -return ret; -} - -/** -* pseudo_lock_region_clear - Reset pseudo-lock region data -* @plr: pseudo-lock region -* -* All content of the pseudo-locked region is reset - any memory allocated -* freed. -* -* Return: void -*/ -static void pseudo_lock_region_clear (struct pseudo_lock_region *plr) -{ - plr->size =0 ; - plr->line_size =0 ; -kfree (plr->kmem); - plr->kmem =NULL ; - plr->s =NULL ; -if (plr->d) - plr->d->plr =NULL ; - plr->d =NULL ; - plr->cbm =0 ; - plr->debugfs_dir =NULL ; -} - -/** -* pseudo_lock_region_init - Initialize pseudo-lock region information -* @plr: pseudo-lock region -* -* Called after user provided a schemata to be pseudo-locked. From the -* schemata the &struct pseudo_lock_region is on entry already initialized -* with the resource, domain, and capacity bitmask. Here the information -* required for pseudo-locking is deduced from this data and &struct -* pseudo_lock_region initialized further. This information includes: -* - size in bytes of the region to be pseudo-locked -* - cache line size to know the stride with which data needs to be accessed -* to be pseudo-locked -* - a cpu associated with the cache instance on which the pseudo-locking -* flow can be executed -* -* Return: 0 on success, <0 on failure. Descriptive error will be written -* to last_cmd_status buffer. -*/ -static int pseudo_lock_region_init (struct pseudo_lock_region *plr) -{ -enum resctrl_scope scope = plr->s->res->ctrl_scope; -struct cacheinfo *ci; -int ret; - -if (WARN_ON_ONCE (scope !=RESCTRL_L2_CACHE && scope !=RESCTRL_L3_CACHE )) -return -ENODEV ; - -/* Pick the first cpu we find that is associated with the cache. */ - plr->cpu =cpumask_first (&plr->d->hdr.cpu_mask); - -if (!cpu_online (plr->cpu)) { -rdt_last_cmd_printf ("CPU %u associated with cache not online\n" , - plr->cpu); - ret = -ENODEV ; - goto out_region; - } - - ci =get_cpu_cacheinfo_level (plr->cpu, scope); -if (ci) { - plr->line_size = ci->coherency_line_size; - plr->size =rdtgroup_cbm_to_size (plr->s->res, plr->d, plr->cbm); -return 0 ; - } - - ret =-1 ; -rdt_last_cmd_puts ("Unable to determine cache line size\n" ); -out_region: -pseudo_lock_region_clear (plr); -return ret; -} - -/** -* pseudo_lock_init - Initialize a pseudo-lock region -* @rdtgrp: resource group to which new pseudo-locked region will belong -* -* A pseudo-locked region is associated with a resource group. When this -* association is created the pseudo-locked region is initialized. The -* details of the pseudo-locked region are not known at this time so only -* allocation is done and association established. -* -* Return: 0 on success, <0 on failure -*/ -static int pseudo_lock_init (struct rdtgroup *rdtgrp) -{ -struct pseudo_lock_region *plr; - - plr =kzalloc (sizeof (*plr),GFP_KERNEL ); -if (!plr) -return -ENOMEM ; - -init_waitqueue_head (&plr->lock_thread_wq); -INIT_LIST_HEAD (&plr->pm_reqs); - rdtgrp->plr = plr; -return 0 ; -} - -/** -* pseudo_lock_region_alloc - Allocate kernel memory that will be pseudo-locked -* @plr: pseudo-lock region -* -* Initialize the details required to set up the pseudo-locked region and -* allocate the contiguous memory that will be pseudo-locked to the cache. -* -* Return: 0 on success, <0 on failure. Descriptive error will be written -* to last_cmd_status buffer. -*/ -static int pseudo_lock_region_alloc (struct pseudo_lock_region *plr) -{ -int ret; - - ret =pseudo_lock_region_init (plr); -if (ret <0 ) -return ret; - -/* -* We do not yet support contiguous regions larger than -* KMALLOC_MAX_SIZE. -*/ -if (plr->size >KMALLOC_MAX_SIZE ) { -rdt_last_cmd_puts ("Requested region exceeds maximum size\n" ); - ret = -E2BIG ; - goto out_region; - } - - plr->kmem =kzalloc (plr->size,GFP_KERNEL ); -if (!plr->kmem) { -rdt_last_cmd_puts ("Unable to allocate memory\n" ); - ret = -ENOMEM ; - goto out_region; - } - - ret =0 ; - goto out; -out_region: -pseudo_lock_region_clear (plr); -out: -return ret; -} - -/** -* pseudo_lock_free - Free a pseudo-locked region -* @rdtgrp: resource group to which pseudo-locked region belonged -* -* The pseudo-locked region's resources have already been released, or not -* yet created at this point. Now it can be freed and disassociated from the -* resource group. -* -* Return: void -*/ -static void pseudo_lock_free (struct rdtgroup *rdtgrp) -{ -pseudo_lock_region_clear (rdtgrp->plr); -kfree (rdtgrp->plr); - rdtgrp->plr =NULL ; -} -/** * resctrl_arch_pseudo_lock_fn - Load kernel memory into cache * @_plr: the pseudo-lock region descriptor @@ -543,340 +229,6 @@ int resctrl_arch_pseudo_lock_fn(void *_plr)return 0 ; } -/** -* rdtgroup_monitor_in_progress - Test if monitoring in progress -* @rdtgrp: resource group being queried -* -* Return: 1 if monitor groups have been created for this resource -* group, 0 otherwise. -*/ -static int rdtgroup_monitor_in_progress (struct rdtgroup *rdtgrp) -{ -return !list_empty (&rdtgrp->mon.crdtgrp_list); -} - -/** -* rdtgroup_locksetup_user_restrict - Restrict user access to group -* @rdtgrp: resource group needing access restricted -* -* A resource group used for cache pseudo-locking cannot have cpus or tasks -* assigned to it. This is communicated to the user by restricting access -* to all the files that can be used to make such changes. -* -* Permissions restored with rdtgroup_locksetup_user_restore() -* -* Return: 0 on success, <0 on failure. If a failure occurs during the -* restriction of access an attempt will be made to restore permissions but -* the state of the mode of these files will be uncertain when a failure -* occurs. -*/ -static int rdtgroup_locksetup_user_restrict (struct rdtgroup *rdtgrp) -{ -int ret; - - ret =rdtgroup_kn_mode_restrict (rdtgrp,"tasks" ); -if (ret) -return ret; - - ret =rdtgroup_kn_mode_restrict (rdtgrp,"cpus" ); -if (ret) - goto err_tasks; - - ret =rdtgroup_kn_mode_restrict (rdtgrp,"cpus_list" ); -if (ret) - goto err_cpus; - -if (resctrl_arch_mon_capable ()) { - ret =rdtgroup_kn_mode_restrict (rdtgrp,"mon_groups" ); -if (ret) - goto err_cpus_list; - } - - ret =0 ; - goto out; - -err_cpus_list: -rdtgroup_kn_mode_restore (rdtgrp,"cpus_list" ,0777 ); -err_cpus: -rdtgroup_kn_mode_restore (rdtgrp,"cpus" ,0777 ); -err_tasks: -rdtgroup_kn_mode_restore (rdtgrp,"tasks" ,0777 ); -out: -return ret; -} - -/** -* rdtgroup_locksetup_user_restore - Restore user access to group -* @rdtgrp: resource group needing access restored -* -* Restore all file access previously removed using -* rdtgroup_locksetup_user_restrict() -* -* Return: 0 on success, <0 on failure. If a failure occurs during the -* restoration of access an attempt will be made to restrict permissions -* again but the state of the mode of these files will be uncertain when -* a failure occurs. -*/ -static int rdtgroup_locksetup_user_restore (struct rdtgroup *rdtgrp) -{ -int ret; - - ret =rdtgroup_kn_mode_restore (rdtgrp,"tasks" ,0777 ); -if (ret) -return ret; - - ret =rdtgroup_kn_mode_restore (rdtgrp,"cpus" ,0777 ); -if (ret) - goto err_tasks; - - ret =rdtgroup_kn_mode_restore (rdtgrp,"cpus_list" ,0777 ); -if (ret) - goto err_cpus; - -if (resctrl_arch_mon_capable ()) { - ret =rdtgroup_kn_mode_restore (rdtgrp,"mon_groups" ,0777 ); -if (ret) - goto err_cpus_list; - } - - ret =0 ; - goto out; - -err_cpus_list: -rdtgroup_kn_mode_restrict (rdtgrp,"cpus_list" ); -err_cpus: -rdtgroup_kn_mode_restrict (rdtgrp,"cpus" ); -err_tasks: -rdtgroup_kn_mode_restrict (rdtgrp,"tasks" ); -out: -return ret; -} - -/** -* rdtgroup_locksetup_enter - Resource group enters locksetup mode -* @rdtgrp: resource group requested to enter locksetup mode -* -* A resource group enters locksetup mode to reflect that it would be used -* to represent a pseudo-locked region and is in the process of being set -* up to do so. A resource group used for a pseudo-locked region would -* lose the closid associated with it so we cannot allow it to have any -* tasks or cpus assigned nor permit tasks or cpus to be assigned in the -* future. Monitoring of a pseudo-locked region is not allowed either. -* -* The above and more restrictions on a pseudo-locked region are checked -* for and enforced before the resource group enters the locksetup mode. -* -* Returns: 0 if the resource group successfully entered locksetup mode, <0 -* on failure. On failure the last_cmd_status buffer is updated with text to -* communicate details of failure to the user. -*/ -int rdtgroup_locksetup_enter (struct rdtgroup *rdtgrp) -{ -int ret; - -/* -* The default resource group can neither be removed nor lose the -* default closid associated with it. -*/ -if (rdtgrp == &rdtgroup_default) { -rdt_last_cmd_puts ("Cannot pseudo-lock default group\n" ); -return -EINVAL ; - } - -/* -* Cache Pseudo-locking not supported when CDP is enabled. -* -* Some things to consider if you would like to enable this -* support (using L3 CDP as example): -* - When CDP is enabled two separate resources are exposed, -* L3DATA and L3CODE, but they are actually on the same cache. -* The implication for pseudo-locking is that if a -* pseudo-locked region is created on a domain of one -* resource (eg. L3CODE), then a pseudo-locked region cannot -* be created on that same domain of the other resource -* (eg. L3DATA). This is because the creation of a -* pseudo-locked region involves a call to wbinvd that will -* affect all cache allocations on particular domain. -* - Considering the previous, it may be possible to only -* expose one of the CDP resources to pseudo-locking and -* hide the other. For example, we could consider to only -* expose L3DATA and since the L3 cache is unified it is -* still possible to place instructions there are execute it. -* - If only one region is exposed to pseudo-locking we should -* still keep in mind that availability of a portion of cache -* for pseudo-locking should take into account both resources. -* Similarly, if a pseudo-locked region is created in one -* resource, the portion of cache used by it should be made -* unavailable to all future allocations from both resources. -*/ -if (resctrl_arch_get_cdp_enabled (RDT_RESOURCE_L3 ) || -resctrl_arch_get_cdp_enabled (RDT_RESOURCE_L2 )) { -rdt_last_cmd_puts ("CDP enabled\n" ); -return -EINVAL ; - } - -/* -* Not knowing the bits to disable prefetching implies that this -* platform does not support Cache Pseudo-Locking. -*/ -if (resctrl_arch_get_prefetch_disable_bits () ==0 ) { -rdt_last_cmd_puts ("Pseudo-locking not supported\n" ); -return -EINVAL ; - } - -if (rdtgroup_monitor_in_progress (rdtgrp)) { -rdt_last_cmd_puts ("Monitoring in progress\n" ); -return -EINVAL ; - } - -if (rdtgroup_tasks_assigned (rdtgrp)) { -rdt_last_cmd_puts ("Tasks assigned to resource group\n" ); -return -EINVAL ; - } - -if (!cpumask_empty (&rdtgrp->cpu_mask)) { -rdt_last_cmd_puts ("CPUs assigned to resource group\n" ); -return -EINVAL ; - } - -if (rdtgroup_locksetup_user_restrict (rdtgrp)) { -rdt_last_cmd_puts ("Unable to modify resctrl permissions\n" ); -return -EIO ; - } - - ret =pseudo_lock_init (rdtgrp); -if (ret) { -rdt_last_cmd_puts ("Unable to init pseudo-lock region\n" ); - goto out_release; - } - -/* -* If this system is capable of monitoring a rmid would have been -* allocated when the control group was created. This is not needed -* anymore when this group would be used for pseudo-locking. This -* is safe to call on platforms not capable of monitoring. -*/ -free_rmid (rdtgrp->closid, rdtgrp->mon.rmid); - - ret =0 ; - goto out; - -out_release: -rdtgroup_locksetup_user_restore (rdtgrp); -out: -return ret; -} - -/** -* rdtgroup_locksetup_exit - resource group exist locksetup mode -* @rdtgrp: resource group -* -* When a resource group exits locksetup mode the earlier restrictions are -* lifted. -* -* Return: 0 on success, <0 on failure -*/ -int rdtgroup_locksetup_exit (struct rdtgroup *rdtgrp) -{ -int ret; - -if (resctrl_arch_mon_capable ()) { - ret =alloc_rmid (rdtgrp->closid); -if (ret <0 ) { -rdt_last_cmd_puts ("Out of RMIDs\n" ); -return ret; - } - rdtgrp->mon.rmid = ret; - } - - ret =rdtgroup_locksetup_user_restore (rdtgrp); -if (ret) { -free_rmid (rdtgrp->closid, rdtgrp->mon.rmid); -return ret; - } - -pseudo_lock_free (rdtgrp); -return 0 ; -} - -/** -* rdtgroup_cbm_overlaps_pseudo_locked - Test if CBM or portion is pseudo-locked -* @d: RDT domain -* @cbm: CBM to test -* -* @d represents a cache instance and @cbm a capacity bitmask that is -* considered for it. Determine if @cbm overlaps with any existing -* pseudo-locked region on @d. -* -* @cbm is unsigned long, even if only 32 bits are used, to make the -* bitmap functions work correctly. -* -* Return: true if @cbm overlaps with pseudo-locked region on @d, false -* otherwise. -*/ -bool rdtgroup_cbm_overlaps_pseudo_locked (struct rdt_ctrl_domain *d,unsigned long cbm) -{ -unsigned int cbm_len; -unsigned long cbm_b; - -if (d->plr) { - cbm_len = d->plr->s->res->cache.cbm_len; - cbm_b = d->plr->cbm; -if (bitmap_intersects (&cbm, &cbm_b, cbm_len)) -return true; - } -return false; -} - -/** -* rdtgroup_pseudo_locked_in_hierarchy - Pseudo-locked region in cache hierarchy -* @d: RDT domain under test -* -* The setup of a pseudo-locked region affects all cache instances within -* the hierarchy of the region. It is thus essential to know if any -* pseudo-locked regions exist within a cache hierarchy to prevent any -* attempts to create new pseudo-locked regions in the same hierarchy. -* -* Return: true if a pseudo-locked region exists in the hierarchy of @d or -* if it is not possible to test due to memory allocation issue, -* false otherwise. -*/ -bool rdtgroup_pseudo_locked_in_hierarchy (struct rdt_ctrl_domain *d) -{ -struct rdt_ctrl_domain *d_i; -cpumask_var_t cpu_with_psl; -struct rdt_resource *r; -bool ret = false; - -/* Walking r->domains, ensure it can't race with cpuhp */ -lockdep_assert_cpus_held (); - -if (!zalloc_cpumask_var (&cpu_with_psl,GFP_KERNEL )) -return true; - -/* -* First determine which cpus have pseudo-locked regions -* associated with them. -*/ -for_each_alloc_capable_rdt_resource (r) { -list_for_each_entry (d_i, &r->ctrl_domains, hdr.list) { -if (d_i->plr) -cpumask_or (cpu_with_psl, cpu_with_psl, - &d_i->hdr.cpu_mask); - } - } - -/* -* Next test if new pseudo-locked region would intersect with -* existing region. -*/ -if (cpumask_intersects (&d->hdr.cpu_mask, cpu_with_psl)) - ret = true; - -free_cpumask_var (cpu_with_psl); -return ret; -} -/** * resctrl_arch_measure_cycles_lat_fn - Measure cycle latency to read * pseudo-locked memory @@ -1169,433 +521,3 @@ int resctrl_arch_measure_l3_residency(void *_plr)wake_up_interruptible (&plr->lock_thread_wq);return 0 ; } - -/** -* pseudo_lock_measure_cycles - Trigger latency measure to pseudo-locked region -* @rdtgrp: Resource group to which the pseudo-locked region belongs. -* @sel: Selector of which measurement to perform on a pseudo-locked region. -* -* The measurement of latency to access a pseudo-locked region should be -* done from a cpu that is associated with that pseudo-locked region. -* Determine which cpu is associated with this region and start a thread on -* that cpu to perform the measurement, wait for that thread to complete. -* -* Return: 0 on success, <0 on failure -*/ -static int pseudo_lock_measure_cycles (struct rdtgroup *rdtgrp,int sel) -{ -struct pseudo_lock_region *plr = rdtgrp->plr; -struct task_struct *thread; -unsigned int cpu; -int ret =-1 ; - -cpus_read_lock (); -mutex_lock (&rdtgroup_mutex); - -if (rdtgrp->flags &RDT_DELETED ) { - ret = -ENODEV ; - goto out; - } - -if (!plr->d) { - ret = -ENODEV ; - goto out; - } - - plr->thread_done =0 ; - cpu =cpumask_first (&plr->d->hdr.cpu_mask); -if (!cpu_online (cpu)) { - ret = -ENODEV ; - goto out; - } - - plr->cpu = cpu; - -if (sel ==1 ) - thread =kthread_run_on_cpu (resctrl_arch_measure_cycles_lat_fn, - plr, cpu,"pseudo_lock_measure/%u" ); -else if (sel ==2 ) - thread =kthread_run_on_cpu (resctrl_arch_measure_l2_residency, - plr, cpu,"pseudo_lock_measure/%u" ); -else if (sel ==3 ) - thread =kthread_run_on_cpu (resctrl_arch_measure_l3_residency, - plr, cpu,"pseudo_lock_measure/%u" ); -else - goto out; - -if (IS_ERR (thread)) { - ret =PTR_ERR (thread); - goto out; - } - - ret =wait_event_interruptible (plr->lock_thread_wq, - plr->thread_done ==1 ); -if (ret <0 ) - goto out; - - ret =0 ; - -out: -mutex_unlock (&rdtgroup_mutex); -cpus_read_unlock (); -return ret; -} - -static ssize_t pseudo_lock_measure_trigger (struct file *file, -const char __user *user_buf, -size_t count,loff_t *ppos) -{ -struct rdtgroup *rdtgrp = file->private_data; -size_t buf_size; -char buf[32 ]; -int ret; -int sel; - - buf_size =min (count, (sizeof (buf) -1 )); -if (copy_from_user (buf, user_buf, buf_size)) -return -EFAULT ; - - buf[buf_size] ='\0' ; - ret =kstrtoint (buf,10 , &sel); -if (ret ==0 ) { -if (sel !=1 && sel !=2 && sel !=3 ) -return -EINVAL ; - ret =debugfs_file_get (file->f_path.dentry); -if (ret) -return ret; - ret =pseudo_lock_measure_cycles (rdtgrp, sel); -if (ret ==0 ) - ret = count; -debugfs_file_put (file->f_path.dentry); - } - -return ret; -} - -static const struct file_operations pseudo_measure_fops = { - .write = pseudo_lock_measure_trigger, - .open = simple_open, - .llseek = default_llseek, -}; - -/** -* rdtgroup_pseudo_lock_create - Create a pseudo-locked region -* @rdtgrp: resource group to which pseudo-lock region belongs -* -* Called when a resource group in the pseudo-locksetup mode receives a -* valid schemata that should be pseudo-locked. Since the resource group is -* in pseudo-locksetup mode the &struct pseudo_lock_region has already been -* allocated and initialized with the essential information. If a failure -* occurs the resource group remains in the pseudo-locksetup mode with the -* &struct pseudo_lock_region associated with it, but cleared from all -* information and ready for the user to re-attempt pseudo-locking by -* writing the schemata again. -* -* Return: 0 if the pseudo-locked region was successfully pseudo-locked, <0 -* on failure. Descriptive error will be written to last_cmd_status buffer. -*/ -int rdtgroup_pseudo_lock_create (struct rdtgroup *rdtgrp) -{ -struct pseudo_lock_region *plr = rdtgrp->plr; -struct task_struct *thread; -unsigned int new_minor; -struct device *dev; - char *kn_name __free(kfree) = NULL; -int ret; - - ret =pseudo_lock_region_alloc (plr); -if (ret <0 ) -return ret; - - ret =pseudo_lock_cstates_constrain (plr); -if (ret <0 ) { - ret = -EINVAL ; - goto out_region; - } - kn_name =kstrdup (rdt_kn_name (rdtgrp->kn),GFP_KERNEL ); -if (!kn_name) { - ret = -ENOMEM ; - goto out_cstates; - } - - plr->thread_done =0 ; - - thread =kthread_run_on_cpu (resctrl_arch_pseudo_lock_fn, plr, - plr->cpu,"pseudo_lock/%u" ); -if (IS_ERR (thread)) { - ret =PTR_ERR (thread); -rdt_last_cmd_printf ("Locking thread returned error %d\n" , ret); - goto out_cstates; - } - - ret =wait_event_interruptible (plr->lock_thread_wq, - plr->thread_done ==1 ); -if (ret <0 ) { -/* -* If the thread does not get on the CPU for whatever -* reason and the process which sets up the region is -* interrupted then this will leave the thread in runnable -* state and once it gets on the CPU it will dereference -* the cleared, but not freed, plr struct resulting in an -* empty pseudo-locking loop. -*/ -rdt_last_cmd_puts ("Locking thread interrupted\n" ); - goto out_cstates; - } - - ret =pseudo_lock_minor_get (&new_minor); -if (ret <0 ) { -rdt_last_cmd_puts ("Unable to obtain a new minor number\n" ); - goto out_cstates; - } - -/* -* Unlock access but do not release the reference. The -* pseudo-locked region will still be here on return. -* -* The mutex has to be released temporarily to avoid a potential -* deadlock with the mm->mmap_lock which is obtained in the -* device_create() and debugfs_create_dir() callpath below as well as -* before the mmap() callback is called. -*/ -mutex_unlock (&rdtgroup_mutex); - -if (!IS_ERR_OR_NULL (debugfs_resctrl)) { - plr->debugfs_dir =debugfs_create_dir (kn_name, debugfs_resctrl); -if (!IS_ERR_OR_NULL (plr->debugfs_dir)) -debugfs_create_file ("pseudo_lock_measure" ,0200 , - plr->debugfs_dir, rdtgrp, - &pseudo_measure_fops); - } - - dev =device_create (&pseudo_lock_class,NULL , -MKDEV (pseudo_lock_major, new_minor), - rdtgrp,"%s" , kn_name); - -mutex_lock (&rdtgroup_mutex); - -if (IS_ERR (dev)) { - ret =PTR_ERR (dev); -rdt_last_cmd_printf ("Failed to create character device: %d\n" , - ret); - goto out_debugfs; - } - -/* We released the mutex - check if group was removed while we did so */ -if (rdtgrp->flags &RDT_DELETED ) { - ret = -ENODEV ; - goto out_device; - } - - plr->minor = new_minor; - - rdtgrp->mode =RDT_MODE_PSEUDO_LOCKED ; -closid_free (rdtgrp->closid); -rdtgroup_kn_mode_restore (rdtgrp,"cpus" ,0444 ); -rdtgroup_kn_mode_restore (rdtgrp,"cpus_list" ,0444 ); - - ret =0 ; - goto out; - -out_device: -device_destroy (&pseudo_lock_class,MKDEV (pseudo_lock_major, new_minor)); -out_debugfs: -debugfs_remove_recursive (plr->debugfs_dir); -pseudo_lock_minor_release (new_minor); -out_cstates: -pseudo_lock_cstates_relax (plr); -out_region: -pseudo_lock_region_clear (plr); -out: -return ret; -} - -/** -* rdtgroup_pseudo_lock_remove - Remove a pseudo-locked region -* @rdtgrp: resource group to which the pseudo-locked region belongs -* -* The removal of a pseudo-locked region can be initiated when the resource -* group is removed from user space via a "rmdir" from userspace or the -* unmount of the resctrl filesystem. On removal the resource group does -* not go back to pseudo-locksetup mode before it is removed, instead it is -* removed directly. There is thus asymmetry with the creation where the -* &struct pseudo_lock_region is removed here while it was not created in -* rdtgroup_pseudo_lock_create(). -* -* Return: void -*/ -void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp) -{ -struct pseudo_lock_region *plr = rdtgrp->plr; - -if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP ) { -/* -* Default group cannot be a pseudo-locked region so we can -* free closid here. -*/ -closid_free (rdtgrp->closid); - goto free; - } - -pseudo_lock_cstates_relax (plr); -debugfs_remove_recursive (rdtgrp->plr->debugfs_dir); -device_destroy (&pseudo_lock_class,MKDEV (pseudo_lock_major, plr->minor)); -pseudo_lock_minor_release (plr->minor); - -free: -pseudo_lock_free (rdtgrp); -} - -static int pseudo_lock_dev_open (struct inode *inode,struct file *filp) -{ -struct rdtgroup *rdtgrp; - -mutex_lock (&rdtgroup_mutex); - - rdtgrp =region_find_by_minor (iminor (inode)); -if (!rdtgrp) {Lines of this file are not shown. View the raw message.
arch/x86/kernel/cpu/resctrl/pseudo_lock_trace.h +2
-0Lines of this file are not shown. View the raw message.
arch/x86/kernel/cpu/resctrl/rdtgroup.c +140
-3577Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Due to the slight difference between here and the upstream commit 45c2e30bbd64 ("x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use of kernfs_node::name"), merge conflicts.
You may consider to add the following patch in patch #17 to fix the conflict?
/*
- * Check that the parent directory for a monitor group is a "mon_groups" - * directory.
+ * Check that the parent directory for a monitor group is a + * "mon_groups" directory.
*/
Thanks.
-Fenghua
Quoted 8,387 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1
-838Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Reinette Chatre
maintainerRe: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
Hi Fenghua,
Quoted 7 lines · Fenghua Yu
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +----------------
Quoted 8 lines
Quoted 8 lines
fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++
14 files changed, 7668 insertions(+), 7418 deletions(-)
This patch is huge. Placing a response in the middle of it makes your feedback very hard to find. Please trim your replies.
Reinette
Re: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
Hi, Reinette,
Quoted 19 lines · Reinette Chatre
Hi Fenghua,
Quoted 7 lines · Fenghua Yu
Quoted 7 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +----------------Quoted 8 lines
Quoted 8 lines
fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++ 14 files changed, 7668 insertions(+), 7418 deletions(-)
Quoted 6 lines
This patch is huge. Placing a response in the middle of it makes your feedback very hard to find. Please trim your replies.
Reinette
You are right! I re-sent my comment and remove all irrelevant code. Now hopefully it's easier to see my comment:)
Thanks.
-Fenghua
Reinette Chatre
maintainerRe: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
Hi Fenghua,
Quoted 22 lines · Fenghua Yu
Hi, Reinette,
Quoted 19 lines · Reinette Chatre
Hi Fenghua,
Quoted 15 lines · Fenghua Yu
Quoted 15 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +---------------- fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++
14 files changed, 7668 insertions(+), 7418 deletions(-)
Quoted 8 lines
Quoted 6 lines
This patch is huge. Placing a response in the middle of it makes your feedback very hard to find. Please trim your replies.
Reinette
You are right! I re-sent my comment and remove all irrelevant code. Now hopefully it's easier to see my comment:)
Thank you very much for re-sending the trimmed version. This helps a lot.
Reinette
Re: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
In reply to Fenghua YuHi, James,
This comment was buried in the middle of this huge patch.
To see my previous comment easily, I cut all other irrelevant code.
Quoted 31 lines · Fenghua Yu
Hi, James,
Quoted 28 lines · James Morse
Resctrl is a filesystem interface to hardware that provides cache allocation policy and bandwidth control for groups of tasks or CPUs.
To support more than one architecture, resctrl needs to live in /fs/.
Move the code that is concerned with the filesystem interface to /fs/resctrl.
Signed-off-by James Morse <[email protected]>---
Changes since *:
* This patch is generated by a script.
---
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +---------------- fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++14 files changed, 7668 insertions(+), 7418 deletions(-)
[SNIP]
Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0
[SNIP]
Quoted 10 lines
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-10-static int mkdir_rdt_prepare (struct kernfs_node *parent_kn, - const char *name, umode_t mode, - enum rdt_group_type rtype, struct rdtgroup **r) -{ - struct rdtgroup *prdtgrp, *rdtgrp; - unsigned long files = 0; - struct kernfs_node *kn; - int ret; - - prdtgrp = rdtgroup_kn_lock_live(parent_kn);
Quoted 8 lines
Quoted 8 lines
- if (!prdtgrp) {
- ret =-ENODEV;
- gotoout_unlock;
- }
-
- /*
- * Check that the parent directory for a monitor group is a - * "mon_groups" directory.
The follow is my previous original comment on the merge conflict and the fix:
Quoted 4 lines
Due to the slight difference between here and the upstream commit
45c2e30bbd64("x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use ofkernfs_node::name"), merge conflicts.You may consider to add the following patch in patch #17 to fix the conflict?
Quoted 8 lines
/*
- * Check that the parent directory for a monitor group is a "mon_groups"
- * directory.
+ * Check that the parent directory for a monitor group is a + * "mon_groups" directory.
*/
[SNIP]
Thanks.
-Fenghua
James Morse
reviewerRe: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
Hi Fenghua,
Quoted 3 lines · Fenghua Yu
This comment was buried in the middle of this huge patch.
To see my previous comment easily, I cut all other irrelevant code.
(please do this as a matter of course! Anyone who needs more context can look at the previous message)
Quoted 30 lines · Fenghua Yu
Quoted 14 lines · James Morse
Quoted 13 lines
Resctrl is a filesystem interface to hardware that provides cache allocation policy and bandwidth control for groups of tasks or CPUs.
To support more than one architecture, resctrl needs to live in /fs/.
Move the code that is concerned with the filesystem interface to /fs/resctrl.
arch/x86/kernel/cpu/resctrl/ renamed from arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0
rdtgroup.c
index326b3048d728..c7a7f0ae373a100644arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-0[SNIP]
Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0
-12-static int mkdir_rdt_prepare (struct kernfs_node *parent_kn, - const char *name, umode_t mode, - enum rdt_group_type rtype, struct rdtgroup **r) -{ - struct rdtgroup *prdtgrp, *rdtgrp; - unsigned long files = 0; - struct kernfs_node *kn; - int ret; - - prdtgrp = rdtgroup_kn_lock_live(parent_kn); - if (!prdtgrp) { - ret = -ENODEV;
Quoted 20 lines
Quoted 6 lines
Quoted 6 lines
- goto
out_unlock;
- }
-
- /*
- * Check that the parent directory for a monitor group is a - * "mon_groups" directory.The follow is my previous original comment on the merge conflict and the fix:
Quoted 11 lines
Due to the slight difference between here and the upstream commit
45c2e30bbd64("x86/
resctrl: Fix rdtgroup_mkdir()'s unlocked use ofkernfs_node::name"), merge conflicts.You may consider to add the following patch in patch #17 to fix the conflict?
/*
- * Check that the parent directory for a monitor group is a "mon_groups" - * directory.
+ * Check that the parent directory for a monitor group is a + * "mon_groups" directory.
*/
This patch is generated by the python script that I previously posted - it will make these changes when I rebase over the upstream'd version of patch 1.
Thanks,
James
Re: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
In reply to James MorseHi, James,
Quoted 28 lines · James Morse
Resctrl is a filesystem interface to hardware that provides cache allocation policy and bandwidth control for groups of tasks or CPUs.
To support more than one architecture, resctrl needs to live in /fs/.
Move the code that is concerned with the filesystem interface to /fs/resctrl.
Signed-off-by James Morse <[email protected]>---
Changes since *:
* This patch is generated by a script.--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 636 --- arch/x86/kernel/cpu/resctrl/internal.h | 380 +- arch/x86/kernel/cpu/resctrl/monitor.c | 902 +--- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 18 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1080 +--- .../kernel/cpu/resctrl/pseudo_lock_trace.h | 2 + arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4556 +---------------- fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 442 ++ fs/resctrl/monitor.c | 932 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1115 ++++ fs/resctrl/pseudo_lock_trace.h | 17 + fs/resctrl/rdtgroup.c | 4313 ++++++++++++++++ 14 files changed, 7668 insertions(+), 7418 deletions(-)
[SNIP]
Quoted 40 lines
fs/resctrl/pseudo_lock.c +35
-0@@ -0,0 +1,1115 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Resource Director Technology (RDT) +* +* Pseudo-locking support built on top of Cache Allocation Technology (CAT) +* +* Copyright (C) 2018 Intel Corporation +* +* Author: Reinette Chatre <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/cacheflush.h> +#include <linux/cacheinfo.h> +#include <linux/cpu.h> +#include <linux/cpumask.h> +#include <linux/debugfs.h> +#include <linux/kthread.h> +#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/cpu_device_id.h> +#include <asm/perf_event.h> + +#include "../../events/perf_event.h" /* For X86_CONFIG() */ +#include "internal.h" + +#define CREATE_TRACE_POINTS + +#include "pseudo_lock_trace.h"
[SNIP]
Quoted 13 lines
fs/resctrl/pseudo_lock.c +1
-0+}fs/resctrl/pseudo_lock_trace.h +7
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM resctrl + +#if !defined(_X86_RESCTRL_PSEUDO_LOCK_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _X86_RESCTRL_PSEUDO_LOCK_TRACE_H +
fs/resctrl/pseudo_lock_trace.h line 17
Quoted 10 lines
fs/resctrl/pseudo_lock_trace.h +10
-0+#include <linux/tracepoint.h> + +#endif /* _X86_RESCTRL_PSEUDO_LOCK_TRACE_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#define TRACE_INCLUDE_FILE pseudo_lock_trace + +#include <trace/define_trace.h>
If applying patch 1-17, building the kernel reports this error, which will cause bisect failure:
CC fs/resctrl/pseudo_lock.o
In file included from fs/resctrl/pseudo_lock_trace.h:17,
from fs/resctrl/pseudo_lock.c:35:./include/trace/define_trace.h:110:42: fatal error: ./pseudo_lock_trace.h: No such file or directory 110 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
| ^
compilation terminated.
make[4]: *** [scripts/Makefile.build:203: fs/resctrl/pseudo_lock.o] Error 1
Again combining patch 18 with this patch together makes the error go away.
But you said combining them together may cause the conversion python tool complex: https://lore.kernel.org/lkml/[email protected]/
Is there a better way to resolve this error? Maybe update the tool not to generate or include fs/resctrl/pseudo_lock_trace.h at all?
[SNIP]
Thanks.
-Fenghua
James Morse
reviewerRe: [PATCH v8 17/21] x86,fs/resctrl: Move the resctrl filesystem code to live in /fs/resctrl
Hi Fenghua,
Quoted 45 lines · Fenghua Yu
Quoted 20 lines · James Morse
Resctrl is a filesystem interface to hardware that provides cache allocation policy and bandwidth control for groups of tasks or CPUs.
To support more than one architecture, resctrl needs to live in /fs/.
Move the code that is concerned with the filesystem interface to /fs/resctrl.
fs/resctrl/pseudo_lock_trace.h +7
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM resctrl + +#if !defined(_X86_RESCTRL_PSEUDO_LOCK_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _X86_RESCTRL_PSEUDO_LOCK_TRACE_H +fs/resctrl/pseudo_lock_trace.h line 17
Quoted 10 lines
fs/resctrl/pseudo_lock_trace.h +10
-0+#include <linux/tracepoint.h> + +#endif /* _X86_RESCTRL_PSEUDO_LOCK_TRACE_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#define TRACE_INCLUDE_FILE pseudo_lock_trace + +#include <trace/define_trace.h> If applying patch 1-17, building the kernel reports this error, which will cause bisect failure:
CC
fs/resctrl/pseudo_lock.o
In file included fromfs/resctrl/pseudo_lock_trace.h:17,
fromfs/resctrl/pseudo_lock.c:35:./include/trace/define_trace.h:110:42: fatal error: ./pseudo_lock_trace.h: No such file or directory
110 | #includeTRACE_INCLUDE(TRACE_INCLUDE_FILE)
| ^
compilation terminated.
make[4]: *** [scripts/Makefile.build:203:fs/resctrl/pseudo_lock.o] Error 1
Quoted 7 lines
Again combining patch 18 with this patch together makes the error go away.
But you said combining them together may cause the conversion python tool complex:
https://lore.kernel.org/lkml/[email protected]/Is there a better way to resolve this error? Maybe update the tool not to generate or include
fs/resctrl/pseudo_lock_trace.hat all?
Please see my previous description of this, also described in the cover letter:
| Patches X-Y should be squashed together when merged - they are posted like | this to allow folk to re-generate patch N, then review the differences on | op. Not squashing them together would expose a ftrace build warning | during bisect. (but who does that!) | That would look like this: | git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git mpam/move_to_fs/v8_final
Amusingly, I forgot to fix 'X-Y', that should read as 17-21.
I can post that 'final' version with everything squashed together once patches 18-21 have been reviewed - but doing that before makes it harder to review the deliberate changes separately from the mechanical changes. This patch is just the mechanical changes.
Thanks,
James
James Morse
reviewerPATCH v8 18/21 x86,fs/resctrl: Remove duplicated trace header files
In reply to James MorseThe copy-pasting python script harmlessly creates some empty trace point header files. Remove them.
--- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ---- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 17 ----------------- fs/resctrl/pseudo_lock.c | 4 ---- fs/resctrl/pseudo_lock_trace.h | 17 ----------------- 4 files changed, 42 deletions(-) delete mode 100644 arch/x86/kernel/cpu/resctrl/monitor_trace.h delete mode 100644 fs/resctrl/pseudo_lock_trace.h
arch/x86/kernel/cpu/resctrl/monitor.c +0 -4
@@ -27,10 +27,6 @@#include "internal.h" -#define CREATE_TRACE_POINTS - -#include "monitor_trace.h" -/* * Global boolean for rdt_monitor which is true if any * resource monitoring is enabled.
arch/x86/kernel/cpu/resctrl/monitor_trace.h deleted +0 -17
@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_FS_RESCTRL_MONITOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _FS_RESCTRL_MONITOR_TRACE_H - -#include <linux/tracepoint.h> - -#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ - -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE monitor_trace - -#include <trace/define_trace.h>
fs/resctrl/pseudo_lock.c +0 -4
@@ -30,10 +30,6 @@#include "../../events/perf_event.h" /* For X86_CONFIG() */ #include "internal.h" -#define CREATE_TRACE_POINTS - -#include "pseudo_lock_trace.h" -/* * Major number assigned to and shared by all devices exposing * pseudo-locked regions.
fs/resctrl/pseudo_lock_trace.h deleted +0 -17
@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_X86_RESCTRL_PSEUDO_LOCK_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _X86_RESCTRL_PSEUDO_LOCK_TRACE_H - -#include <linux/tracepoint.h> - -#endif /* _X86_RESCTRL_PSEUDO_LOCK_TRACE_H */ - -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE pseudo_lock_trace - -#include <trace/define_trace.h>
Signature · 1 line
2.20.1
Reinette Chatre
maintainerRe: [PATCH v8 18/21] x86,fs/resctrl: Remove duplicated trace header files
Hi James,
Quoted 46 lines · James Morse
The copy-pasting python script harmlessly creates some empty trace point header files. Remove them.
Signed-off-by James Morse <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>Tested-by Babu Moger <[email protected]>--- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ---- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 17 ----------------- fs/resctrl/pseudo_lock.c | 4 ---- fs/resctrl/pseudo_lock_trace.h | 17 ----------------- 4 files changed, 42 deletions(-) delete mode 100644 arch/x86/kernel/cpu/resctrl/monitor_trace.h delete mode 100644 fs/resctrl/pseudo_lock_trace.harch/x86/kernel/cpu/resctrl/monitor.c +0
-4@@ -27,10 +27,6 @@#include "internal.h" -#define CREATE_TRACE_POINTS - -#include "monitor_trace.h" -/* * Global boolean for rdt_monitor which is true if any * resource monitoring is enabled. arch/x86/kernel/cpu/resctrl/monitor_trace.h deleted +0
-7@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_FS_RESCTRL_MONITOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _FS_RESCTRL_MONITOR_TRACE_H -
arch/x86/kernel/cpu/resctrl/monitor_trace.h line 17
Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor_trace.h deleted +0
-10-#include <linux/tracepoint.h> - -#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ - -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE monitor_trace - -#include <trace/define_trace.h>
Should the "CFLAGS_monitor.o = -I$(src)" be removed from arch/x86/kernel/cpu/resctrl/Makefile as part of the above changes?
Reinette
James Morse
reviewerRe: [PATCH v8 18/21] x86,fs/resctrl: Remove duplicated trace header files
Hi Reinette,
Quoted 22 lines · Reinette Chatre
Quoted 21 lines · James Morse
The copy-pasting python script harmlessly creates some empty trace point header files. Remove them.
arch/x86/kernel/cpu/resctrl/monitor_trace.h deleted +0
-12@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_FS_RESCTRL_MONITOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _FS_RESCTRL_MONITOR_TRACE_H - -#include <linux/tracepoint.h> - -#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ - -#undef TRACE_INCLUDE_PATH
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/monitor_trace.h line 17
Quoted 5 lines
arch/x86/kernel/cpu/resctrl/monitor_trace.h deleted +0
-5-#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE monitor_trace - -#include <trace/define_trace.h> Should the "CFLAGS_monitor.o = -I$(src)" be removed from
arch/x86/kernel/cpu/resctrl/Makefileas part of the above changes?
Yes! It took a while of staring at build errors to work out what those things were about...
I'll also fix the 'harmless' comment in the commit message with Fenghua's description of the ftrace thing.
Thanks,
James
Re: [PATCH v8 18/21] x86,fs/resctrl: Remove duplicated trace header files
In reply to James MorseHi, James,
Quoted 84 lines · James Morse
The copy-pasting python script harmlessly creates some empty trace point header files. Remove them.
Signed-off-by James Morse <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>Tested-by Babu Moger <[email protected]>--- arch/x86/kernel/cpu/resctrl/monitor.c | 4 ---- arch/x86/kernel/cpu/resctrl/monitor_trace.h | 17 ----------------- fs/resctrl/pseudo_lock.c | 4 ---- fs/resctrl/pseudo_lock_trace.h | 17 ----------------- 4 files changed, 42 deletions(-)delete mode 100644
arch/x86/kernel/cpu/resctrl/monitor_trace.hdelete mode 100644fs/resctrl/pseudo_lock_trace.harch/x86/kernel/cpu/resctrl/monitor.c +0
-4@@ -27,10 +27,6 @@#include "internal.h" -#define CREATE_TRACE_POINTS - -#include "monitor_trace.h" -/* * Global boolean for rdt_monitor which is true if any * resource monitoring is enabled. arch/x86/kernel/cpu/resctrl/monitor_trace.h deleted +0
-17@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_FS_RESCTRL_MONITOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _FS_RESCTRL_MONITOR_TRACE_H - -#include <linux/tracepoint.h> - -#endif /* _FS_RESCTRL_MONITOR_TRACE_H */ - -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE monitor_trace - -#include <trace/define_trace.h> fs/resctrl/pseudo_lock.c +0
-4@@ -30,10 +30,6 @@#include "../../events/perf_event.h" /* For X86_CONFIG() */ #include "internal.h" -#define CREATE_TRACE_POINTS - -#include "pseudo_lock_trace.h" -/* * Major number assigned to and shared by all devices exposing * pseudo-locked regions. fs/resctrl/pseudo_lock_trace.h deleted +0
-7@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_X86_RESCTRL_PSEUDO_LOCK_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _X86_RESCTRL_PSEUDO_LOCK_TRACE_H -
fs/resctrl/pseudo_lock_trace.h line 17
Quoted 10 lines
fs/resctrl/pseudo_lock_trace.h deleted +0
-10-#include <linux/tracepoint.h> - -#endif /* _X86_RESCTRL_PSEUDO_LOCK_TRACE_H */ - -#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE pseudo_lock_trace - -#include <trace/define_trace.h>
Will patches 18-21 be merged into patch 17 eventually before they are pushed into upstream?
Thanks.
-Fenghua
James Morse
reviewerRe: [PATCH v8 18/21] x86,fs/resctrl: Remove duplicated trace header files
Hi Fenghua,
Quoted 21 lines · Fenghua Yu
Quoted 20 lines · James Morse
The copy-pasting python script harmlessly creates some empty trace point header files. Remove them.
fs/resctrl/pseudo_lock_trace.h deleted +0
-11@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#undef TRACE_SYSTEM -#define TRACE_SYSTEM resctrl - -#if !defined(_X86_RESCTRL_PSEUDO_LOCK_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) -#define _X86_RESCTRL_PSEUDO_LOCK_TRACE_H - -#include <linux/tracepoint.h> - -#endif /* _X86_RESCTRL_PSEUDO_LOCK_TRACE_H */ -
Quoted 8 lines
fs/resctrl/pseudo_lock_trace.h line 17
Quoted 6 lines
fs/resctrl/pseudo_lock_trace.h deleted +0
-6-#undef TRACE_INCLUDE_PATH -#define TRACE_INCLUDE_PATH . - -#define TRACE_INCLUDE_FILE pseudo_lock_trace - -#include <trace/define_trace.h> Will patches 18-21 be merged into patch 17 eventually before they are pushed into upstream?
Up to the maintainers - but that is the plan I describe in the cover letter. The history of those patches isn't interesting - but they do need to be broken out to be reviewed.
Thanks,
James
James Morse
reviewerPATCH v8 19/21 fs/resctrl: Remove unnecessary includes
In reply to James MorseWhen splitting and moving the resctrl code to live in fs/resctrl and arch/x86, some code was duplicated. This was done to keep the parser in the script that does the moving simple. This results in unnecessary includes in the arch and filesystem code.
Remove them.
---
Changes since v7:
* Expanded the scope, removed many more includes.
--- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 4 ---- arch/x86/kernel/cpu/resctrl/internal.h | 5 ----- arch/x86/kernel/cpu/resctrl/monitor.c | 3 --- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 7 ------- fs/resctrl/internal.h | 2 -- fs/resctrl/monitor.c | 3 --- fs/resctrl/pseudo_lock.c | 6 ------ fs/resctrl/rdtgroup.c | 2 -- 8 files changed, 32 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +0 -4
@@ -16,10 +16,6 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/cpu.h> -#include <linux/kernfs.h> -#include <linux/seq_file.h> -#include <linux/slab.h> -#include <linux/tick.h> #include "internal.h"
arch/x86/kernel/cpu/resctrl/internal.h +0 -5
@@ -3,11 +3,6 @@#define _ASM_X86_RESCTRL_INTERNAL_H#include <linux/resctrl.h> -#include <linux/sched.h> -#include <linux/kernfs.h> -#include <linux/fs_context.h> -#include <linux/jump_label.h> -#include <linux/tick.h> #define L3_QOS_CDP_ENABLE 0x01ULL
arch/x86/kernel/cpu/resctrl/monitor.c +0 -3
@@ -18,10 +18,7 @@#define pr_fmt (fmt) "resctrl: " fmt#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>
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +0 -7
@@ -12,17 +12,10 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/cacheflush.h> -#include <linux/cacheinfo.h> #include <linux/cpu.h> -#include <linux/cpumask.h> -#include <linux/debugfs.h> -#include <linux/kthread.h> -#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/cpu_device_id.h> #include <asm/perf_event.h>
fs/resctrl/internal.h +0 -2
@@ -3,10 +3,8 @@#define _ASM_X86_RESCTRL_INTERNAL_H#include <linux/resctrl.h> -#include <linux/sched.h> #include <linux/kernfs.h> #include <linux/fs_context.h> -#include <linux/jump_label.h> #include <linux/tick.h> #define CQM_LIMBOCHECK_INTERVAL 1000
fs/resctrl/monitor.c +0 -3
@@ -18,13 +18,10 @@#define pr_fmt (fmt) "resctrl: " fmt#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 "internal.h" #define CREATE_TRACE_POINTS
fs/resctrl/pseudo_lock.c +0 -6
@@ -11,23 +11,17 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/cacheflush.h> #include <linux/cacheinfo.h> #include <linux/cpu.h> #include <linux/cpumask.h> #include <linux/debugfs.h> #include <linux/kthread.h> #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/cpu_device_id.h> -#include <asm/perf_event.h> - -#include "../../events/perf_event.h" /* For X86_CONFIG() */ #include "internal.h" /*
fs/resctrl/rdtgroup.c +0 -2
@@ -21,10 +21,8 @@#include <linux/resctrl.h> #include <linux/seq_buf.h> #include <linux/seq_file.h> -#include <linux/sched/signal.h> #include <linux/sched/task.h> #include <linux/slab.h> -#include <linux/task_work.h> #include <linux/user_namespace.h> #include <uapi/linux/magic.h>
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 20/21 fs/resctrl: Change internal.h's header guard macros
In reply to James MorseThe code in internal.h was moved by a script. The script didn't know to change the header guard macros. Do that.
--- fs/resctrl/internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/resctrl/internal.h +3 -3
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_X86_RESCTRL_INTERNAL_H -#define _ASM_X86_RESCTRL_INTERNAL_H +#ifndef _FS_RESCTRL_INTERNAL_H +#define _FS_RESCTRL_INTERNAL_H#include <linux/resctrl.h> #include <linux/kernfs.h>
@@ -437,4 +437,4 @@ static inline int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp)static inline void rdtgroup_pseudo_lock_remove (struct rdtgroup *rdtgrp) { }#endif /* CONFIG_RESCTRL_FS_PSEUDO_LOCK */ -#endif /* _ASM_X86_RESCTRL_INTERNAL_H */ +#endif /* _FS_RESCTRL_INTERNAL_H */
Signature · 1 line
2.20.1
James Morse
reviewerPATCH v8 21/21 x86,fs/resctrl: Move resctrl.rst to live under Documentation/filesystems
In reply to James MorseThe filesystem code has moved from arch/x86 to fs. Move the documentation too.
---
Documentation/arch/x86/index.rst | 1 -
Documentation/filesystems/index.rst | 1 +
Documentation/{arch/x86 => filesystems}/resctrl.rst | 0
MAINTAINERS | 2 +-
arch/x86/kernel/cpu/resctrl/monitor.c | 2 +-
fs/resctrl/Kconfig | 2 +-
6 files changed, 4 insertions(+), 4 deletions(-)
rename Documentation/{arch/x86 => filesystems}/resctrl.rst (100%)Documentation/arch/x86/index.rst +0 -1
@@ -31,7 +31,6 @@ x86-specific Documentation pti mds microcode - resctrl tsx_async_abort buslock usb-legacy-support
Documentation/filesystems/index.rst +1 -0
@@ -113,6 +113,7 @@ Documentation for filesystem implementations. qnx6 ramfs-rootfs-initramfs relay + resctrl romfs smb/index spufs/index
Documentation/filesystems/resctrl.rst renamed from Documentation/arch/x86/resctrl.rst +0 -0
MAINTAINERS +1 -1
@@ -20281,7 +20281,7 @@ M: Tony Luck <[email protected]> M: Reinette Chatre <[email protected]> L: [email protected] S: Supported -F: Documentation/arch/x86/resctrl* +F: Documentation/filesystems/resctrl.rst F: arch/x86/include/asm/resctrl.h F: arch/x86/kernel/cpu/resctrl/ F: fs/resctrl/
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
@@ -40,7 +40,7 @@ unsigned int rdt_mon_features;static int snc_nodes_per_l3_cache =1 ;/* -* The correction factor table is documented in Documentation/arch/x86/resctrl.rst. +* The correction factor table is documented in Documentation/filesystems/resctrl.rst. * If rmid > rmid threshold, MBM total and local values should be multiplied * by the correction factor. *
fs/resctrl/Kconfig +1 -1
@@ -21,7 +21,7 @@ config RESCTRL_FS On architectures where this can be disabled independently, it is safe to say N. - See <file:Documentation/arch/x86/resctrl.rst> for more information. + See <file:Documentation/filesystems/resctrl.rst> for more information. config RESCTRL_FS_PSEUDO_LOCK bool
Signature · 1 line
2.20.1
Reinette Chatre
maintainerRe: [PATCH v8 21/21] x86,fs/resctrl: Move resctrl.rst to live under Documentation/filesystems
Hi James,
Quoted 37 lines · James Morse
The filesystem code has moved from
arch/x86to fs. Move the documentation too.Signed-off-by James Morse <[email protected]>Tested-by Peter Newman <[email protected]>Tested-by Shaopeng Tan <[email protected]>Tested-by Babu Moger <[email protected]>Reviewed-by Fenghua Yu <[email protected]>--- Documentation/arch/x86/index.rst | 1 - Documentation/filesystems/index.rst | 1 + Documentation/{arch/x86 => filesystems}/resctrl.rst | 0 MAINTAINERS | 2 +- arch/x86/kernel/cpu/resctrl/monitor.c | 2 +- fs/resctrl/Kconfig | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename Documentation/{arch/x86 => filesystems}/resctrl.rst (100%)Documentation/arch/x86/index.rst +0
-1@@ -31,7 +31,6 @@ x86-specific Documentation pti mds microcode - resctrl tsx_async_abort buslock usb-legacy-supportDocumentation/filesystems/index.rst +0
-0
Documentation/filesystems/index.rst Documentation for filesystem implementations. · line 119
Quoted 7 lines
Documentation/filesystems/index.rst +1
-0@@ -113,6 +113,7 @@ Documentation for filesystem implementations. qnx6 ramfs-rootfs-initramfs relay + resctrl romfs smb/index spufs/index
I built the htmldocs with this change and the filesystem's index.html is quite big making the resctrl parts not be obvious. The title of the documentation is used as a heading so the resctrl documentation's heading is "User Interface for Resource Control feature" that I think makes a text search hard to use since it may not be obvious to users what to search for.
What do you think of a snippet like below that will include "resctrl" as a term in the title that should make the documentation easier to find?
---8<---
Documentation/filesystems/resctrl.rst +3 -3
@@ -1,9 +1,9 @@ .. SPDX-License-Identifier: GPL-2.0 .. include:: <isonum.txt> -=========================================== -User Interface for Resource Control feature -=========================================== +===================================================== +User Interface for Resource Control feature (resctrl) +===================================================== :Copyright: |copy| 2016 Intel Corporation :Authors: - Fenghua Yu <[email protected]>
---8<---
Quoted 9 lines
Documentation/filesystems/resctrl.rst renamed from Documentation/arch/x86/resctrl.rst +0
-0MAINTAINERS +0
-0
MAINTAINERS M: Tony Luck <[email protected]> · line 20287
Quoted 8 lines
MAINTAINERS +1
-1@@ -20281,7 +20281,7 @@ M: Tony Luck <[email protected]> M: Reinette Chatre <[email protected]> L: [email protected] S: Supported -F: Documentation/arch/x86/resctrl* +F: Documentation/filesystems/resctrl.rst F: arch/x86/include/asm/resctrl.h F: arch/x86/kernel/cpu/resctrl/ F: fs/resctrl/
On the topic of MAINTAINERS file ... if this is ok with you I would like to suggest that you add your name as reviewer to this area with the goal of you being CCed on any patches that touch any of these files so that you could highlight if anything impacts Arm.
Quoted 18 lines
arch/x86/kernel/cpu/resctrl/monitor.c +1
-1@@ -40,7 +40,7 @@ unsigned int rdt_mon_features;static int snc_nodes_per_l3_cache =1 ;/* -* The correction factor table is documented in Documentation/arch/x86/resctrl.rst. +* The correction factor table is documented in Documentation/filesystems/resctrl.rst. * If rmid > rmid threshold, MBM total and local values should be multiplied * by the correction factor. * fs/resctrl/Kconfig +0
-0
fs/resctrl/Kconfig config RESCTRL_FS · line 27
Quoted 8 lines
fs/resctrl/Kconfig +1
-1@@ -21,7 +21,7 @@ config RESCTRL_FS On architectures where this can be disabled independently, it is safe to say N. - See <file:Documentation/arch/x86/resctrl.rst> for more information. + See <file:Documentation/filesystems/resctrl.rst> for more information. config RESCTRL_FS_PSEUDO_LOCK bool
Reinette
James Morse
reviewerRe: [PATCH v8 21/21] x86,fs/resctrl: Move resctrl.rst to live under Documentation/filesystems
Hi Reinette,
Quoted 23 lines · Reinette Chatre
Quoted 8 lines · James Morse
The filesystem code has moved from
arch/x86to fs. Move the documentation too.Documentation/filesystems/index.rst +0
-0Documentation/filesystems/index.rst Documentation for filesystem implementations. · line 119
Quoted 7 lines
Documentation/filesystems/index.rst +1
-0@@ -113,6 +113,7 @@ Documentation for filesystem implementations. qnx6 ramfs-rootfs-initramfs relay + resctrl romfs smb/index spufs/indexI built the htmldocs with this change and the filesystem's index.html is quite big making the resctrl parts not be obvious. The title of the documentation is used as a heading so the resctrl documentation's heading is "User Interface for Resource Control feature" that I think makes a text search hard to use since it may not be obvious to users what to search for.
Quoted 2 lines
What do you think of a snippet like below that will include "resctrl" as a term in the title that should make the documentation easier to find?
Good point - that is the string people are going to use, and the file names might not be something they are looking at.
Quoted 9 lines
---8<---
Documentation/filesystems/resctrl.rst +0
-0@@ -1,9 +1,9 @@ .. SPDX-License-Identifier: GPL-2.0 .. include:: <isonum.txt>
Documentation/filesystems/resctrl.rst
Quoted 10 lines
Documentation/filesystems/resctrl.rst +3
-4-=========================================== -User Interface for Resource Control feature -=========================================== +===================================================== +User Interface for Resource Control feature (resctrl) +===================================================== :Copyright: |copy| 2016 Intel Corporation :Authors: - Fenghua Yu <[email protected]> ---8<---
I'll add this as a patch before 17 as its a little more nuanced that fallout from moving code.
Quoted 14 lines
Quoted 14 lines
Documentation/filesystems/resctrl.rst renamed from Documentation/arch/x86/resctrl.rst +0
-0MAINTAINERS +1
-1@@ -20281,7 +20281,7 @@ M: Tony Luck <[email protected]> M: Reinette Chatre <[email protected]> L: [email protected] S: Supported -F: Documentation/arch/x86/resctrl* +F: Documentation/filesystems/resctrl.rst
Quoted 8 lines
MAINTAINERS M: Tony Luck <[email protected]> · line 20287
Quoted 3 lines
MAINTAINERS +0
-0F: arch/x86/include/asm/resctrl.h F: arch/x86/kernel/cpu/resctrl/ F: fs/resctrl/On the topic of
MAINTAINERSfile ... if this is ok with you I would like to suggest that you add your name as reviewer to this area with the goal of you being CCed on any patches that touch any of these files so that you could highlight if anything impacts Arm.
Yes, that makes sense. I'd like to add Dave Martin too so that one of us is more likely to be available. I've asked him verbally ...
Thanks,
James
Reinette Chatre
maintainerRe: [PATCH v8 21/21] x86,fs/resctrl: Move resctrl.rst to live under Documentation/filesystems
Hi James,
Quoted 49 lines · James Morse
Hi Reinette,
Quoted 23 lines · Reinette Chatre
Quoted 8 lines · James Morse
The filesystem code has moved from
arch/x86to fs. Move the documentation too.Documentation/filesystems/index.rst +0
-0Documentation/filesystems/index.rst Documentation for filesystem implementations. · line 119
Quoted 7 lines
Documentation/filesystems/index.rst +1
-0@@ -113,6 +113,7 @@ Documentation for filesystem implementations. qnx6 ramfs-rootfs-initramfs relay + resctrl romfs smb/index spufs/indexI built the htmldocs with this change and the filesystem's index.html is quite big making the resctrl parts not be obvious. The title of the documentation is used as a heading so the resctrl documentation's heading is "User Interface for Resource Control feature" that I think makes a text search hard to use since it may not be obvious to users what to search for.
Quoted 2 lines
What do you think of a snippet like below that will include "resctrl" as a term in the title that should make the documentation easier to find?
Good point - that is the string people are going to use, and the file names might not be something they are looking at.
Quoted 16 lines
---8<---
Documentation/filesystems/resctrl.rst +3
-3@@ -1,9 +1,9 @@ .. SPDX-License-Identifier: GPL-2.0 .. include:: <isonum.txt> -=========================================== -User Interface for Resource Control feature -=========================================== +===================================================== +User Interface for Resource Control feature (resctrl) +=====================================================
Quoted 5 lines
Documentation/filesystems/resctrl.rst
Quoted 3 lines
Documentation/filesystems/resctrl.rst +0
-1:Copyright: |copy| 2016 Intel Corporation :Authors: - Fenghua Yu <[email protected]> ---8<---I'll add this as a patch before 17 as its a little more nuanced that fallout from moving code.
Thank you for considering this.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
Documentation/filesystems/resctrl.rst renamed from Documentation/arch/x86/resctrl.rst +0
-0MAINTAINERS +1
-1@@ -20281,7 +20281,7 @@ M: Tony Luck <[email protected]> M: Reinette Chatre <[email protected]> L: [email protected] S: Supported -F: Documentation/arch/x86/resctrl* +F: Documentation/filesystems/resctrl.rstQuoted 8 lines
MAINTAINERS M: Tony Luck <[email protected]> · line 20287
Quoted 3 lines
MAINTAINERS +0
-0F: arch/x86/include/asm/resctrl.h F: arch/x86/kernel/cpu/resctrl/ F: fs/resctrl/On the topic of
MAINTAINERSfile ... if this is ok with you I would like to suggest that you add your name as reviewer to this area with the goal of you being CCed on any patches that touch any of these files so that you could highlight if anything impacts Arm.
Quoted 2 lines
Yes, that makes sense. I'd like to add Dave Martin too so that one of us is more likely to be available. I've asked him verbally ...
I'll support this. I find Dave's feedback to be insightful and would appreciate and welcome more of it.
Reinette
Luck, Tony
maintainerQuoted 4 lines · James Morse
Changes since v7:
* Switched to Tony's alternative for having a structure behind structmon_data.
Quoted 8 lines
Changes otherwise noted on each patch.
N.B, the disk in my machine recently died - so I've re-done the feedback changes multiple times. Appologies if I missed something on the second pass!
---
Patch 1 has been posted as a fix that should get picked up independently.Patches X-Y should be squashed together when merged - they are posted like
X=17 (the big move). Y=20 (last of the cleanups from the move)?
Quoted 5 lines
this to allow folk to re-generate patch N, then review the differences on top. Not squashing them together would expose a ftrace build warning during bisect. (but who does that!)
That would look like this:git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.gitmpam/move_to_fs/v8_final
This "final" branch is missing the patch that move resctrl.rst into Documentation/filesystems.
Quoted 7 lines
This series is based on rc1, and can be retrieved from:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.gitmpam/move_to_fs/v8This series renames functions and moves code around. With the exception of invalid configurations for the configurable-events, there should be no changes in behaviour caused by this series. It is now possible for
throttle_modeto report 'undefined', but no known platform will do this.
As far as I can tell x86/Intel systems are still working as before.
Quoted 8 lines
The driving pattern is to make things like struct rdtgroup private to resctrl. Features like pseudo-lock aren't going to work on arm64, the ability to disable it at compile time is added.
After this, I can start posting the MPAM driver to make use of resctrl on arm64. (What's MPAM? See the cover letter of the first series. [1])
As ever - bugs welcome,
Couldn't find any bugs for you.
Quoted 86 lines
Thanks,
James
[v7] https://lore.kernel.org/all/[email protected]/
[v6] https://lore.kernel.org/lkml/[email protected]/
[v5] https://lore.kernel.org/r/[email protected]
[v4] https://lore.kernel.org/all/[email protected]/
[v3] https://lore.kernel.org/r/[email protected]
[v2] https://lore.kernel.org/r/[email protected]
[v1] https://lore.kernel.org/r/[email protected]
[1] https://lore.kernel.org/lkml/[email protected]/Amit Singh Tomar (1):
x86/resctrl: Remove the limit on the number of CLOSIDDave Martin (3):
x86/resctrl: Squelch whitespace anomalies in resctrl core code x86/resctrl: Prefer alloc(sizeof(*foo)) idiom inrdt_init_fs_context()x86/resctrl: Relax some asm #includesJames Morse (17):
x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use ofkernfs_node::namex86/resctrl: Renameresctrl_sched_in()to begin with "resctrl_arch_" x86/resctrl:resctrl_exit()teardown resctrl but leave the mount point x86/resctrl: Drop __init/__exit on assorted symbols x86/resctrl: Moveis_mba_sc()out ofcore.c
x86/resctrl: Add end-marker to theresctrl_event_idenum x86/resctrl: Expand the width ofdom_idby replacingmon_data_bitsx86/resctrl: Remove a newline to avoid confusing the code move script x86/resctrl: Splittrace.h
fs/resctrl: Add boiler plate for external resctrl code x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl x86/resctrl: Always initialise rid field in rdt_resources_all[] x86,fs/resctrl: Move the resctrl filesystem code to live in
/fs/resctrl
x86,fs/resctrl: Remove duplicated trace header files fs/resctrl: Remove unnecessary includes
fs/resctrl: Change internal.h's header guard macros x86,fs/resctrl: Moveresctrl.rstto live under
Documentation/filesystemsDocumentation/arch/x86/index.rst | 1 - Documentation/filesystems/index.rst | 1 + .../{arch/x86 => filesystems}/resctrl.rst | 0 MAINTAINERS | 3 +- arch/Kconfig | 8 + arch/x86/Kconfig | 11 +- arch/x86/include/asm/resctrl.h | 7 +- arch/x86/kernel/cpu/resctrl/Makefile | 3 + arch/x86/kernel/cpu/resctrl/core.c | 31 +- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 635 --- arch/x86/kernel/cpu/resctrl/internal.h | 397 +- arch/x86/kernel/cpu/resctrl/monitor.c | 909 +--- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1092 +--- .../resctrl/{trace.h => pseudo_lock_trace.h} | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4426 +---------------- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- fs/Kconfig | 1 + fs/Makefile | 1 + fs/resctrl/Kconfig | 39 + fs/resctrl/Makefile | 6 + fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 440 ++ fs/resctrl/monitor.c | 929 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1105 ++++ fs/resctrl/rdtgroup.c | 4311 ++++++++++++++++ include/linux/resctrl.h | 10 +- include/linux/resctrl_types.h | 5 + 29 files changed, 7731 insertions(+), 7363 deletions(-) rename Documentation/{arch/x86 => filesystems}/resctrl.rst (100%) rename arch/x86/kernel/cpu/resctrl/{trace.h => pseudo_lock_trace.h} (56%) create mode 100644 fs/resctrl/Kconfig create mode 100644 fs/resctrl/Makefile create mode 100644 fs/resctrl/ctrlmondata.c create mode 100644 fs/resctrl/internal.h create mode 100644 fs/resctrl/monitor.c create mode 100644 fs/resctrl/monitor_trace.h create mode 100644 fs/resctrl/pseudo_lock.c create mode 100644 fs/resctrl/rdtgroup.cSignature · 1 line
2.20.1
James Morse
reviewerHi Tony,
Quoted 7 lines · Tony
Quoted 6 lines · James Morse
Changes since v7:
* Switched to Tony's alternative for having a structure behind structmon_data.Changes otherwise noted on each patch.
Quoted 8 lines
Quoted 6 lines
N.B, the disk in my machine recently died - so I've re-done the feedback changes multiple times. Appologies if I missed something on the second pass!
---
Patch 1 has been posted as a fix that should get picked up independently.Patches X-Y should be squashed together when merged - they are posted like
X=17 (the big move). Y=20 (last of the cleanups from the move)?
Probably 21 as well as that is mechanical changes as part of the move.
Quoted 8 lines
Quoted 5 lines
this to allow folk to re-generate patch N, then review the differences on top. Not squashing them together would expose a ftrace build warning during bisect. (but who does that!)
That would look like this:git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.gitmpam/move_to_fs/v8_finalThis "final" branch is missing the patch that move
resctrl.rstintoDocumentation/filesystems.
Right - sorry I cut it in the wrong place. I've have loads of MPAM driver on top...
Hopefully it illustrates my suggestion for reviewing/merging...
Quoted 14 lines
Quoted 7 lines
This series is based on rc1, and can be retrieved from:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.gitmpam/move_to_fs/v8This series renames functions and moves code around. With the exception of invalid configurations for the configurable-events, there should be no changes in behaviour caused by this series. It is now possible for
throttle_modeto report 'undefined', but no known platform will do this.As far as I can tell x86/Intel systems are still working as before.
Quoted 4 lines
The driving pattern is to make things like struct rdtgroup private to resctrl. Features like pseudo-lock aren't going to work on arm64, the ability to disable it at compile time is added.
Quoted 6 lines
Quoted 4 lines
After this, I can start posting the MPAM driver to make use of resctrl on arm64. (What's MPAM? See the cover letter of the first series. [1])
As ever - bugs welcome,
Couldn't find any bugs for you.
:(
Thanks for taking a look!
James
Hello,
I ran tools/tests/selftests/resctrl with the following patches on AMD EPYC 9454P 48-Core Processor, it looks good.
https://lore.kernel.org/lkml/96d276c11e69cfb1e29d50a12c8043555c06b404.1718144237.git.babu.moger@amd.com/#r
https://lore.kernel.org/lkml/[email protected]/#r
Best regards,
Shaopeng TAN
Quoted 147 lines
-----Original Message-----
From: James Morse <[email protected]>
Sent: Saturday, April 12, 2025 1:42 AM
To: [email protected]; [email protected]
Cc: Reinette Chatre <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Borislav Petkov <[email protected]>; H Peter Anvin <[email protected]>; Babu Moger <[email protected]>; James Morse <[email protected]>; [email protected]; D Scott Phillips OS <[email protected]>; [email protected]; [email protected]; [email protected]; Tan, Shaopeng/譚 紹 鵬 <[email protected]>; [email protected]; Jamie Iles <[email protected]>; Xin Hao <[email protected]>; [email protected]; [email protected]; [email protected]; David Hildenbrand <[email protected]>; Rex Nie <[email protected]>; Dave Martin <[email protected]>; Koba Ko <[email protected]>; Shanker Donthineni <[email protected]>; [email protected]
Subject: [PATCH v8 00/21] x86/resctrl: Move the resctrl filesystem code to /fs/resctrlChanges since v7:
* Switched to Tony's alternative for having a structure behind structmon_data.Changes otherwise noted on each patch.
N.B, the disk in my machine recently died - so I've re-done the feedback changes multiple times. Appologies if I missed something on the second pass!
---
Patch 1 has been posted as a fix that should get picked up independently.Patches X-Y should be squashed together when merged - they are posted like this to allow folk to re-generate patch N, then review the differences on top. Not squashing them together would expose a ftrace build warning during bisect. (but who does that!) That would look like this:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/move_to_fs/v8_finalThis series is based on rc1, and can be retrieved from:
git://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/move_to_fs/v8This series renames functions and moves code around. With the exception of invalid configurations for the configurable-events, there should be no changes in behaviour caused by this series. It is now possible for
throttle_modeto report 'undefined', but no known platform will do this.The driving pattern is to make things like struct rdtgroup private to resctrl. Features like pseudo-lock aren't going to work on arm64, the ability to disable it at compile time is added.
After this, I can start posting the MPAM driver to make use of resctrl on arm64. (What's MPAM? See the cover letter of the first series. [1])
As ever - bugs welcome,
Thanks,James
[v7]
https://lore.kernel.org/all/[email protected]/
[v6]
https://lore.kernel.org/lkml/[email protected]/
[v5]
https://lore.kernel.org/r/[email protected]
[v4]
https://lore.kernel.org/all/[email protected]/
[v3]
https://lore.kernel.org/r/[email protected]
[v2] https://lore.kernel.org/r/[email protected]
[v1]
https://lore.kernel.org/r/[email protected]
[1]
https://lore.kernel.org/lkml/[email protected]
m/Amit Singh Tomar (1):
x86/resctrl: Remove the limit on the number of CLOSIDDave Martin (3):
x86/resctrl: Squelch whitespace anomalies in resctrl core code x86/resctrl: Prefer alloc(sizeof(*foo)) idiom inrdt_init_fs_context()x86/resctrl: Relax some asm #includesJames Morse (17):
x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use ofkernfs_node::namex86/resctrl: Renameresctrl_sched_in()to begin with "resctrl_arch_" x86/resctrl:resctrl_exit()teardown resctrl but leave the mount point x86/resctrl: Drop __init/__exit on assorted symbols x86/resctrl: Moveis_mba_sc()out ofcore.c
x86/resctrl: Add end-marker to theresctrl_event_idenum x86/resctrl: Expand the width ofdom_idby replacingmon_data_bitsx86/resctrl: Remove a newline to avoid confusing the code move script x86/resctrl: Splittrace.h
fs/resctrl: Add boiler plate for external resctrl code x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl x86/resctrl: Always initialise rid field in rdt_resources_all[] x86,fs/resctrl: Move the resctrl filesystem code to live in
/fs/resctrl
x86,fs/resctrl: Remove duplicated trace header files fs/resctrl: Remove unnecessary includes
fs/resctrl: Change internal.h's header guard macros x86,fs/resctrl: Moveresctrl.rstto live under
Documentation/filesystemsDocumentation/arch/x86/index.rst | 1 - Documentation/filesystems/index.rst | 1 + .../{arch/x86 => filesystems}/resctrl.rst | 0 MAINTAINERS | 3 +- arch/Kconfig | 8 + arch/x86/Kconfig | 11 +- arch/x86/include/asm/resctrl.h | 7 +- arch/x86/kernel/cpu/resctrl/Makefile | 3 + arch/x86/kernel/cpu/resctrl/core.c | 31 +- arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 635 --- arch/x86/kernel/cpu/resctrl/internal.h | 397 +- arch/x86/kernel/cpu/resctrl/monitor.c | 909 +--- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1092 +--- .../resctrl/{trace.h => pseudo_lock_trace.h} | 26 +- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4426 +---------------- arch/x86/kernel/process_32.c | 2 +- arch/x86/kernel/process_64.c | 2 +- fs/Kconfig | 1 + fs/Makefile | 1 + fs/resctrl/Kconfig | 39 + fs/resctrl/Makefile | 6 + fs/resctrl/ctrlmondata.c | 660 +++ fs/resctrl/internal.h | 440 ++ fs/resctrl/monitor.c | 929 ++++ fs/resctrl/monitor_trace.h | 33 + fs/resctrl/pseudo_lock.c | 1105 ++++ fs/resctrl/rdtgroup.c | 4311 ++++++++++++++++ include/linux/resctrl.h | 10 +- include/linux/resctrl_types.h | 5 + 29 files changed, 7731 insertions(+), 7363 deletions(-) rename
Documentation/{arch/x86=>filesystems}/resctrl.rst(100%) renamearch/x86/kernel/cpu/resctrl/{trace.h=>pseudo_lock_trace.h} (56%) create mode 100644fs/resctrl/Kconfigcreate mode 100644fs/resctrl/Makefilecreate mode 100644fs/resctrl/ctrlmondata.ccreate mode 100644fs/resctrl/internal.hcreate mode 100644fs/resctrl/monitor.ccreate mode 100644fs/resctrl/monitor_trace.hcreate mode 100644fs/resctrl/pseudo_lock.ccreate mode 100644fs/resctrl/rdtgroup.c--
2.20.1
Reinette Chatre
maintainerHi Shaopeng and Babu,
Quoted 3 lines · Shaopeng Tan (Fujitsu)
Hello,
I ran
tools/tests/selftests/resctrlwith the following patches on AMD EPYC 9454P 48-Core Processor, it looks good.
Thank you!
Quoted 2 lines
It is strange that you needed to add this since it can be found in v6.10 and up.
Quoted 1 line
Babu, is this still something that you want to see upstream?
Reinette
Hi Reinette,
Quoted 10 lines · Reinette Chatre
Hi Shaopeng and Babu,
Quoted 3 lines · Shaopeng Tan (Fujitsu)
Hello,
I ran
tools/tests/selftests/resctrlwith the following patches on AMD EPYC 9454P 48-Core Processor, it looks good.Thank you!
Quoted 1 line
Quoted 8 lines
Quoted 1 line
It is strange that you needed to add this since it can be found in v6.10 and up.
Quoted 1 line
Babu, is this still something that you want to see upstream?
Yes. I need to address few comments in there. Didn't get chance to work on it due to other priorities. I will pick it up later.
Thanks for the reminder.
-Babu