Skip to contentSkip to conversation

x86/resctrl: Move the resctrl filesystem code to /fs/resctrl

PATCH Superseded James Morse 10 participants 179 messages Mar 21, 2024 – Jun 14, 2024 Page 1 of 2

Subsystems (3)

v1 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

James Morse

author reviewer
#0 lore raw

cover x86/resctrl: Move the resctrl filesystem code to /fs/resctrl

Hello!

This is the final series that allows other architectures to implement resctrl. The last patch just moves the code, and its a bit of a monster. I don't expect that to get merged as part of this series - we should wait for it to make less impact on other series. It's included here to show what gets moved, and that structures/function-prototypes have the right visibility.

Otherwise 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.

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])

This series is based on Linus' commit 23956900041d and can be retrieved from:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git
mpam/move_to_fs/v1

Sorry for the mid-merge window base, I'm away for a few weeks - this should rebase trivially onto rc1.

As ever - bugs welcome,
Thanks,

James

[1] https://lore.kernel.org/lkml/[email protected]/

James Morse (31):
x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no
monitors
x86/resctrl: Add a helper to avoid reaching into the arch code
resource list
x86/resctrl: Move ctrlval string parsing policy away from the arch
code
x86/resctrl: Add helper for setting CPU default properties x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid() x86/resctrl: Export resctrl fs's init function x86/resctrl: Wrap resctrl_arch_find_domain() around rdt_find_domain() x86/resctrl: Move resctrl types to a separate header x86/resctrl: Add a resctrl helper to reset all the resources x86/resctrl: Move monitor init work to a resctrl init call x86/resctrl: Move monitor exit work to a restrl exit call x86/resctrl: Move max_{name,data}_width into resctrl code x86/resctrl: Stop using the for_each_*_rdt_resource() walkers x86/resctrl: Export the is_mbm_*_enabled() helpers to asm/resctrl.h x86/resctrl: Add resctrl_arch_is_evt_configurable() to abstract BMEC x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers x86/resctrl: Move mbm_cfg_mask to struct rdt_resource x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an
error
x86/resctrl: Add resctrl_arch_ prefix to pseudo lock functions x86/resctrl: Allow an architecture to disable pseudo lock x86/resctrl: Make prefetch_disable_bits belong to the arch code x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr x86/resctrl: Move thread_throttle_mode_init() to be managed by resctrl x86/resctrl: Move get_config_index() to a header x86/resctrl: Claim get_domain_from_cpu() for resctrl x86/resctrl: Describe resctrl's bitmap size assumptions x86/resctrl: Rename resctrl_sched_in() to begin resctrl_arch_ x86/resctrl: Drop __init/__exit on assorted symbols fs/resctrl: Add boiler plate for external resctrl code x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl x86/resctrl: Move the resctrl filesystem code to /fs/resctrl

 MAINTAINERS                               |    2 +
 arch/Kconfig                              |    8 +
 arch/x86/Kconfig                          |    5 +-
 arch/x86/include/asm/resctrl.h            |   45 +-
 arch/x86/kernel/cpu/resctrl/Makefile      |    5 +-
 arch/x86/kernel/cpu/resctrl/core.c        |  119 +-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  506 +--
 arch/x86/kernel/cpu/resctrl/internal.h    |  433 +--
 arch/x86/kernel/cpu/resctrl/monitor.c     |  813 +----
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 1126 +-----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 3929 +-------------------
 arch/x86/kernel/process_32.c              |    2 +-
 arch/x86/kernel/process_64.c              |    2 +-
 fs/Kconfig                                |    1 +
 fs/Makefile                               |    1 +
 fs/resctrl/Kconfig                        |   23 +
 fs/resctrl/Makefile                       |    3 +
 fs/resctrl/ctrlmondata.c                  |  527 +++
 fs/resctrl/internal.h                     |  340 ++
 fs/resctrl/monitor.c                      |  843 +++++
 fs/resctrl/psuedo_lock.c                  | 1122 ++++++
 fs/resctrl/rdtgroup.c                     | 4013 +++++++++++++++++++++
 include/linux/resctrl.h                   |  153 +-
 include/linux/resctrl_types.h             |   98 +
 24 files changed, 7244 insertions(+), 6875 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/psuedo_lock.c
 create mode 100644 fs/resctrl/rdtgroup.c
 create mode 100644 include/linux/resctrl_types.h
Signature · 1 line
2.39.2
author reviewer
#1 lore raw

PATCH 1/31 x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
index 011e17efb1a6..1767c1affa60 100644
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;
Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Hi James,

Quoted 2 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes

Please see section about "Fixes" tags in section "Ordering of commit tags" in Documentation/process/maintainer-tip.rst

Quoted 25 lines

resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 011e17efb1a6..1767c1affa60 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int closid_alloc(void) · line 156

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;

Patch looks good.

Thank you

Reinette

reviewer
#3 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Quoted 8 lines · Reinette Chatre

Hi James,

Quoted 2 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes

Please see section about "Fixes" tags in section "Ordering of commit tags" in Documentation/process/maintainer-tip.rst

Noted for James' attention.

Quoted 37 lines
Quoted 25 lines

resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 011e17efb1a6..1767c1affa60 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int closid_alloc(void) · line 156

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;

Patch looks good.

Quoted 4 lines

Thank you

Reinette

Noted, thanks.

Cheers
---Dave

Reviewed-by on v1 1/31
#4 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

In reply to James Morse
Quoted 10 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

Quoted 7 lines

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

It's weird to not see RESCTRL_RMID_DEPENDS_ON_CLOSID appear in any Kconfig file. I guess it will all make sense once the refactoring is done :)

As Reinette comments, likely we want here:

Fixes 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid")
Quoted 10 lines
---
  arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 011e17efb1a6..1767c1affa60 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int closid_alloc(void) · line 156

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
  	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
  		cleanest_closid = resctrl_find_cleanest_closid();
  		if (cleanest_closid < 0)
  			return cleanest_closid;
Signature · 3 lines
Cheers,

David / dhildenb
maintainer
#5 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Hi David,

(Thank you very much for taking a look at these)

Quoted 15 lines · David Hildenbrand
Quoted 14 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

Quoted 6 lines
Quoted 3 lines

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

It's weird to not see RESCTRL_RMID_DEPENDS_ON_CLOSID appear in any Kconfig file. I guess it will all make sense once the refactoring is done :)

This is done later in this series where patch #29, "fs/resctrl: Add boiler plate for external resctrl code", introduces it to fs/resctrl/Kconfig.

Reinette

#6 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Quoted 2 lines · Reinette Chatre

Hi David,

Hi,

Quoted 1 line

(Thank you very much for taking a look at these)

I'm planning on reviewing more; as most of resctrl is code I haven't really read before, I'm not able to make progress as fast as I normally would in core-MM ... :)

Quoted 21 lines · David Hildenbrand
Quoted 19 lines · James Morse
Quoted 17 lines

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

Quoted 5 lines
Quoted 2 lines

It's weird to not see RESCTRL_RMID_DEPENDS_ON_CLOSID appear in any Kconfig file. I guess it will all make sense once the refactoring is done :)

This is done later in this series where patch #29, "fs/resctrl: Add boiler plate for external resctrl code", introduces it to fs/resctrl/Kconfig.

Oh, already in this series, great!

Signature · 3 lines
Cheers,

David / dhildenb
reviewer
#7 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Quoted 11 lines · David Hildenbrand
Quoted 2 lines · Reinette Chatre

Hi David,

Hi,

Quoted 1 line

(Thank you very much for taking a look at these)

I'm planning on reviewing more; as most of resctrl is code I haven't really read before, I'm not able to make progress as fast as I normally would in core-MM ... :)

[...]

Quoted 4 lines
Signature · 3 lines
Cheers,

David / dhildenb

Thanks, all review is appreciated (I'm somewhat in the same boat myself, but gradually finding my way around...)

Cheers
---Dave

reviewer
#8 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

In reply to David Hildenbrand
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

[...]

Quoted 2 lines

It's weird to not see RESCTRL_RMID_DEPENDS_ON_CLOSID appear in any Kconfig file. I guess it will all make sense once the refactoring is done :)

Agreed; a stub Kconfig item could be added, but since the file layout and naming conventions change after this patch, doing this would probably just create noise in the series though.

Looking at <linux/kconfig.h> (yikes!), IS_ENABLED() is designed to do the right thing for non-existing Kconfigs...

If nobody is too concerned about the temporarily dangling IS_ENABLED()s in this series, I won't propose any change here.

Quoted 3 lines

As Reinette comments, likely we want here:

Fixes 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid")

Noted for James' attention.

Quoted 6 lines
Quoted 6 lines
---
  arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 19 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int closid_alloc(void) · line 154

Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
index 011e17efb1a6..1767c1affa60 100644
@@ -149,7 +149,8 @@ static int closid_alloc(void)
  	lockdep_assert_held(&rdtgroup_mutex);
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
  		cleanest_closid = resctrl_find_cleanest_closid();
  		if (cleanest_closid < 0)
  			return cleanest_closid;
Signature · 3 lines
Cheers,

David / dhildenb

Thanks; noted for James' attention.

Cheers
---Dave

maintainer
#9 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Hi Dave,

Quoted 17 lines · Dave Martin
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

[...]

Quoted 2 lines

It's weird to not see RESCTRL_RMID_DEPENDS_ON_CLOSID appear in any Kconfig file. I guess it will all make sense once the refactoring is done :)

Agreed; a stub Kconfig item could be added, but since the file layout and naming conventions change after this patch, doing this would probably just create noise in the series though.

Quoted 5 lines

Looking at <linux/kconfig.h> (yikes!), IS_ENABLED() is designed to do the right thing for non-existing Kconfigs...

If nobody is too concerned about the temporarily dangling IS_ENABLED()s in this series, I won't propose any change here.

I am not concerned about this. Please note that these IS_ENABLED() checks are not introduced in this series, they were introduced in the previous portion of this MPAM work that can be found in upstream resctrl.

Reinette

reviewer
#10 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Quoted 23 lines · Reinette Chatre

Hi Dave,

Quoted 20 lines · Dave Martin
Quoted 6 lines · David Hildenbrand
Quoted 5 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

[...]

Quoted 2 lines

It's weird to not see RESCTRL_RMID_DEPENDS_ON_CLOSID appear in any Kconfig file. I guess it will all make sense once the refactoring is done :)

Agreed; a stub Kconfig item could be added, but since the file layout and naming conventions change after this patch, doing this would probably just create noise in the series though.

Looking at <linux/kconfig.h> (yikes!), IS_ENABLED() is designed to do the right thing for non-existing Kconfigs...

Quoted 9 lines
Quoted 2 lines

If nobody is too concerned about the temporarily dangling IS_ENABLED()s in this series, I won't propose any change here.

I am not concerned about this. Please note that these IS_ENABLED() checks are not introduced in this series, they were introduced in the previous portion of this MPAM work that can be found in upstream resctrl.

Reinette

Ah, right. Thanks for the explanation.

Cheers
---Dave

reviewer
#11 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

In reply to James Morse
Quoted 2 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes

This is not true. The Kconfig option is never added. It is added later in the series. There is also comment
on this https://lore.kernel.org/lkml/[email protected]/

Shouldn't the Kconfig option added first before doing this change?

Quoted 34 lines

resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
index 011e17efb1a6..1767c1affa60 100644
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;
Signature · 2 lines
Thanks
Babu Moger
reviewer
#12 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Quoted 6 lines · Babu
Quoted 2 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes

Quoted 10 lines

This is not true. The Kconfig option is never added. It is added later in the series. There is also comment
on this https://lore.kernel.org/lkml/[email protected]/

Shouldn't the Kconfig option added first before doing this change?

Quoted 3 lines

resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

See David's comments and previous discussion on this patch.

You're right to point out that the description of the original commit does seem a bit garbled though: CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is not present in Kconfig here, but already referenced by other code.

We seem to have a consensus that it's OK to have a dangling IS_ENABLED() so long as the option is added formally to Kconfig later, but it looks like the commit message here should be reworded.

Does the following make sense?

--8<--

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added logic that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group, if requested by the arch code. This depends on the values read from the llc_occupancy counters. The logic is applicable to architectures where the CLOSID effectively forms part of the monitoring identifier and so do not allow complete freedom to choose an unused monitoring identifier for a given CLOSID.

-->8--

Although it would probably have been better if the Kconfig option had been added upstream, this patch does not create that that situation and the series (taken as a whole) resolves it.

So I am not sure that anything would be solved or improved by changing the body of this patch, but if people still have concerns then I guess we can look at it.

Quoted 23 lines
Quoted 23 lines

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 011e17efb1a6..1767c1affa60 100644
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
Quoted 13 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;
Signature · 2 lines
Thanks
Babu Moger

[...]

Cheers
---Dave

reviewer
#13 lore raw

Re: [PATCH v1 01/31] x86/resctrl: Fix allocation of cleanest CLOSID on platforms with no monitors

Hi Dave,

Quoted 41 lines · Dave Martin
Quoted 6 lines · Babu
Quoted 2 lines · James Morse

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added a Kconfig option that causes

Quoted 10 lines

This is not true. The Kconfig option is never added. It is added later in the series. There is also comment
on this https://lore.kernel.org/lkml/[email protected]/

Shouldn't the Kconfig option added first before doing this change?

Quoted 3 lines

resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group. This depends on the values read from the llc_occupancy counters.

See David's comments and previous discussion on this patch.

You're right to point out that the description of the original commit does seem a bit garbled though: CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID is not present in Kconfig here, but already referenced by other code.

We seem to have a consensus that it's OK to have a dangling IS_ENABLED() so long as the option is added formally to Kconfig later, but it looks like the commit message here should be reworded.

Does the following make sense?

--8<--

commit 6eac36bb9eb0 ("x86/resctrl: Allocate the cleanest CLOSID by searching closid_num_dirty_rmid") added logic that causes resctrl to search for the CLOSID with the fewest dirty cache lines when creating a new control group, if requested by the arch code. This depends on the values read from the llc_occupancy counters. The logic is applicable to architectures where the CLOSID effectively forms part of the monitoring identifier and so do not allow complete freedom to choose an unused monitoring identifier for a given CLOSID.

Quoted 1 line

-->8--

That looks good. Thanks

Quoted 53 lines

Although it would probably have been better if the Kconfig option had been added upstream, this patch does not create that that situation and the series (taken as a whole) resolves it.

So I am not sure that anything would be solved or improved by changing the body of this patch, but if people still have concerns then I guess we can look at it.

Quoted 23 lines
Quoted 23 lines

This support missed that some platforms may not have these counters. This causes a NULL pointer dereference when creating a new control group as the array was not allocated by dom_data_init().

As this feature isn't necessary on platforms that don't have cache occupancy monitors, add this to the check that occurs when a new control group is allocated.

The existing code is not selected by any upstream platform, it makes no sense to backport this patch to stable.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 011e17efb1a6..1767c1affa60 100644
@@ -149,7 +149,8 @@ static int closid_alloc(void)
 
Quoted 13 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
+	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
+	    is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;
Signature · 2 lines
Thanks
Babu Moger

[...]

Cheers
---Dave

Signature · 2 lines
Thanks
Babu Moger
author reviewer
#14 lore raw

PATCH 2/31 x86/resctrl: Add a helper to avoid reaching into the arch code resource list

In reply to James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

---
 arch/x86/kernel/cpu/resctrl/core.c        | 10 +++++++++-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 10 ----------
 arch/x86/kernel/cpu/resctrl/monitor.c     |  8 ++++----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 15 +++++++--------
 include/linux/resctrl.h                   | 17 +++++++++++++++++
 6 files changed, 38 insertions(+), 24 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +9 -1
index 83e40341583e..b773b3bdebe3 100644
@@ -122,6 +122,14 @@ struct rdt_hw_resource rdt_resources_all[] = {
 	},
 };
 
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
+{
+	if (l >= RDT_NUM_RESOURCES)
+		return NULL;
+
+	return &rdt_resources_all[l].r_resctrl;
+}
+
 /*
  * cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs
  * as they do not have CPUID enumeration support for Cache allocation.
@@ -169,7 +177,7 @@ static inline void cache_alloc_hsw_probe(void)
 bool is_mba_sc(struct rdt_resource *r)
 {
 	if (!r)
-		return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.mba_sc;
+		r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
 	/*
 	 * The software controller support is only applicable to MBA resource.
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
index 7997b47743a2..788ac0395645 100644
@@ -599,7 +599,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	domid = md.u.domid;
 	evtid = md.u.evtid;
 
-	r = &rdt_resources_all[resid].r_resctrl;
+	r = resctrl_arch_get_resource(resid);
 	d = rdt_find_domain(r, domid, NULL);
 	if (IS_ERR_OR_NULL(d)) {
 		ret = -ENOENT;
arch/x86/kernel/cpu/resctrl/internal.h +0 -10
index c99f26ebe7a6..65990def6c79 100644
@@ -466,16 +466,6 @@ extern struct rdt_hw_resource rdt_resources_all[];
 extern struct rdtgroup rdtgroup_default;
 extern struct dentry *debugfs_resctrl;
 
-enum resctrl_res_level {
-	RDT_RESOURCE_L3,
-	RDT_RESOURCE_L2,
-	RDT_RESOURCE_MBA,
-	RDT_RESOURCE_SMBA,
-
-	/* Must be the last */
-	RDT_NUM_RESOURCES,
-};
-
 static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(res);
arch/x86/kernel/cpu/resctrl/monitor.c +4 -4
index c34a35ec0f03..06565153ceb2 100644
@@ -321,7 +321,7 @@ static void limbo_release_entry(struct rmid_entry *entry)
  */
 void __check_limbo(struct rdt_domain *d, bool force_free)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	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;
@@ -467,7 +467,7 @@ int alloc_rmid(u32 closid)
 
 static void add_rmid_to_limbo(struct rmid_entry *entry)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	struct rdt_domain *d;
 	u32 idx;
 
@@ -669,7 +669,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 	if (!is_mbm_local_enabled())
 		return;
 
-	r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	r_mba = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
 	closid = rgrp->closid;
 	rmid = rgrp->mon.rmid;
@@ -839,7 +839,7 @@ void mbm_handle_overflow(struct work_struct *work)
 	if (!resctrl_mounted || !resctrl_arch_mon_capable())
 		goto out_unlock;
 
-	r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	d = container_of(work, struct rdt_domain, mbm_over.work);
 
 	list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c +7 -8
index 1767c1affa60..45372b6a6215 100644
@@ -2253,7 +2253,7 @@ static void l2_qos_cfg_update(void *arg)
 
 static inline bool is_mba_linear(void)
 {
-	return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.delay_linear;
+	return resctrl_arch_get_resource(RDT_RESOURCE_MBA)->membw.delay_linear;
 }
 
 static int set_cache_qos_cfg(int level, bool enable)
@@ -2341,7 +2341,7 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
  */
 static bool supports_mba_mbps(void)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
 	return (is_mbm_local_enabled() &&
 		r->alloc_capable && is_mba_linear());
@@ -2353,7 +2353,7 @@ static bool supports_mba_mbps(void)
  */
 static int set_mba_sc(bool mba_sc)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 	u32 num_closid = resctrl_arch_get_num_closid(r);
 	struct rdt_domain *d;
 	int i;
@@ -2625,10 +2625,10 @@ static void schemata_list_destroy(void)
 
 static int rdt_get_tree(struct fs_context *fc)
 {
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	struct rdt_fs_context *ctx = rdt_fc2context(fc);
 	unsigned long flags = RFTYPE_CTRL_BASE;
 	struct rdt_domain *dom;
-	struct rdt_resource *r;
 	int ret;
 
 	cpus_read_lock();
@@ -2701,8 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc)
 		resctrl_mounted = true;
 
 	if (is_mbm_enabled()) {
-		r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-		list_for_each_entry(dom, &r->domains, list)
+		list_for_each_entry(dom, &l3->domains, list)
 			mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
 						   RESCTRL_PICK_ANY_CPU);
 	}
@@ -3878,7 +3877,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
 	if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
 		seq_puts(seq, ",cdpl2");
 
-	if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
+	if (is_mba_sc(resctrl_arch_get_resource(RDT_RESOURCE_MBA)))
 		seq_puts(seq, ",mba_MBps");
 
 	if (resctrl_debug)
@@ -4068,7 +4067,7 @@ static void clear_childcpus(struct rdtgroup *r, unsigned int cpu)
 
 void resctrl_offline_cpu(unsigned int cpu)
 {
-	struct rdt_resource *l3 = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	struct rdtgroup *rdtgrp;
 	struct rdt_domain *d;
 
include/linux/resctrl.h +17 -0
index a365f67131ec..168cc9510069 100644
@@ -36,6 +36,16 @@ enum resctrl_conf_type {
 	CDP_DATA,
 };
 
+enum resctrl_res_level {
+	RDT_RESOURCE_L3,
+	RDT_RESOURCE_L2,
+	RDT_RESOURCE_MBA,
+	RDT_RESOURCE_SMBA,
+
+	/* Must be the last */
+	RDT_NUM_RESOURCES,
+};
+
 #define CDP_NUM_TYPES	(CDP_DATA + 1)
 
 /*
@@ -190,6 +200,13 @@ struct rdt_resource {
 	bool			cdp_capable;
 };
 
+/*
+ * Get the resource that exists at this level. If the level is not supported
+ * a dummy/not-capable resource can be returned. Levels >= RDT_NUM_RESOURCES
+ * will return NULL.
+ */
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
+
 /**
  * struct resctrl_schema - configuration abilities of a resource presented to
  *			   user-space
Signature · 1 line
2.39.2
maintainer
#15 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

Hi James,

Quoted 7 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources.

rdt_hw_resource?

Quoted 6 lines

All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

Quoted 6 lines

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

---

Patch looks good to me.

Reinette

reviewer
#16 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

Quoted 7 lines · Reinette Chatre

Hi James,

Quoted 4 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Quoted 5 lines
Quoted 3 lines

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources.

rdt_hw_resource?

Looks like it. Noted for James' attention.

Quoted 10 lines
Quoted 10 lines

All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

Quoted 7 lines
Quoted 2 lines

---

Patch looks good to me.

Reinette

Noted, thanks.

Cheers
---Dave

Reviewed-by on v1 2/31
#17 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

In reply to James Morse
Quoted 13 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

Quoted 6 lines

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

---

Signature · 3 lines
Cheers,

David / dhildenb
reviewer
#18 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

Quoted 14 lines · David Hildenbrand
Quoted 13 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

Quoted 13 lines
Quoted 6 lines

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

---

Signature · 3 lines
Cheers,

David / dhildenb

Thanks; noted for James' attention.

Cheers
---Dave

Quoted 2 lines
reviewer
#19 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

In reply to James Morse

Hi James/Dave,

Quoted 9 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Quoted 7 lines

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

Nit.
You may want to drop the second half of the statement. We don't have a dummy resource.

Quoted 145 lines
---
 arch/x86/kernel/cpu/resctrl/core.c        | 10 +++++++++-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 10 ----------
 arch/x86/kernel/cpu/resctrl/monitor.c     |  8 ++++----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 15 +++++++--------
 include/linux/resctrl.h                   | 17 +++++++++++++++++
 6 files changed, 38 insertions(+), 24 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +9 -1
index 83e40341583e..b773b3bdebe3 100644
@@ -122,6 +122,14 @@ struct rdt_hw_resource rdt_resources_all[] = {
 	},
 };
 
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)
+{
+	if (l >= RDT_NUM_RESOURCES)
+		return NULL;
+
+	return &rdt_resources_all[l].r_resctrl;
+}
+
 /*
  * cache_alloc_hsw_probe() - Have to probe for Intel haswell server CPUs
  * as they do not have CPUID enumeration support for Cache allocation.
@@ -169,7 +177,7 @@ static inline void cache_alloc_hsw_probe(void)
 bool is_mba_sc(struct rdt_resource *r)
 {
 	if (!r)
-		return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.mba_sc;
+		r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
 	/*
 	 * The software controller support is only applicable to MBA resource.
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
index 7997b47743a2..788ac0395645 100644
@@ -599,7 +599,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	domid = md.u.domid;
 	evtid = md.u.evtid;
 
-	r = &rdt_resources_all[resid].r_resctrl;
+	r = resctrl_arch_get_resource(resid);
 	d = rdt_find_domain(r, domid, NULL);
 	if (IS_ERR_OR_NULL(d)) {
 		ret = -ENOENT;
arch/x86/kernel/cpu/resctrl/internal.h +0 -10
index c99f26ebe7a6..65990def6c79 100644
@@ -466,16 +466,6 @@ extern struct rdt_hw_resource rdt_resources_all[];
 extern struct rdtgroup rdtgroup_default;
 extern struct dentry *debugfs_resctrl;
 
-enum resctrl_res_level {
-	RDT_RESOURCE_L3,
-	RDT_RESOURCE_L2,
-	RDT_RESOURCE_MBA,
-	RDT_RESOURCE_SMBA,
-
-	/* Must be the last */
-	RDT_NUM_RESOURCES,
-};
-
 static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(res);
arch/x86/kernel/cpu/resctrl/monitor.c +4 -4
index c34a35ec0f03..06565153ceb2 100644
@@ -321,7 +321,7 @@ static void limbo_release_entry(struct rmid_entry *entry)
  */
 void __check_limbo(struct rdt_domain *d, bool force_free)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	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;
@@ -467,7 +467,7 @@ int alloc_rmid(u32 closid)
 
 static void add_rmid_to_limbo(struct rmid_entry *entry)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	struct rdt_domain *d;
 	u32 idx;
 
@@ -669,7 +669,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 	if (!is_mbm_local_enabled())
 		return;
 
-	r_mba = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	r_mba = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
 	closid = rgrp->closid;
 	rmid = rgrp->mon.rmid;
@@ -839,7 +839,7 @@ void mbm_handle_overflow(struct work_struct *work)
 	if (!resctrl_mounted || !resctrl_arch_mon_capable())
 		goto out_unlock;
 
-	r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	d = container_of(work, struct rdt_domain, mbm_over.work);
 
 	list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
index 1767c1affa60..45372b6a6215 100644
@@ -2253,7 +2253,7 @@ static void l2_qos_cfg_update(void *arg)
 
 static inline bool is_mba_linear(void)
 {
-	return rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl.membw.delay_linear;
+	return resctrl_arch_get_resource(RDT_RESOURCE_MBA)->membw.delay_linear;
 }
 
 static int set_cache_qos_cfg(int level, bool enable)
@@ -2341,7 +2341,7 @@ static void mba_sc_domain_destroy(struct rdt_resource *r,
  */
 static bool supports_mba_mbps(void)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
 	return (is_mbm_local_enabled() &&
 		r->alloc_capable && is_mba_linear());
@@ -2353,7 +2353,7 @@ static bool supports_mba_mbps(void)
  */
 static int set_mba_sc(bool mba_sc)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl;
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 	u32 num_closid = resctrl_arch_get_num_closid(r);
 	struct rdt_domain *d;
 	int i;

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void schemata_list_destroy(void) · line 2628

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -2625,10 +2625,10 @@ static void schemata_list_destroy(void)
 
 static int rdt_get_tree(struct fs_context *fc)
 {
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Its is probably best to keep the resource name as r here to be consistent with other changes.

Quoted 70 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -5
 	struct rdt_fs_context *ctx = rdt_fc2context(fc);
 	unsigned long flags = RFTYPE_CTRL_BASE;
 	struct rdt_domain *dom;
-	struct rdt_resource *r;
 	int ret;
 
 	cpus_read_lock();
@@ -2701,8 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc)
 		resctrl_mounted = true;
 
 	if (is_mbm_enabled()) {
-		r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-		list_for_each_entry(dom, &r->domains, list)
+		list_for_each_entry(dom, &l3->domains, list)
 			mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
 						   RESCTRL_PICK_ANY_CPU);
 	}
@@ -3878,7 +3877,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
 	if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
 		seq_puts(seq, ",cdpl2");
 
-	if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
+	if (is_mba_sc(resctrl_arch_get_resource(RDT_RESOURCE_MBA)))
 		seq_puts(seq, ",mba_MBps");
 
 	if (resctrl_debug)
@@ -4068,7 +4067,7 @@ static void clear_childcpus(struct rdtgroup *r, unsigned int cpu)
 
 void resctrl_offline_cpu(unsigned int cpu)
 {
-	struct rdt_resource *l3 = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 	struct rdtgroup *rdtgrp;
 	struct rdt_domain *d;
 
include/linux/resctrl.h +17 -0
index a365f67131ec..168cc9510069 100644
@@ -36,6 +36,16 @@ enum resctrl_conf_type {
 	CDP_DATA,
 };
 
+enum resctrl_res_level {
+	RDT_RESOURCE_L3,
+	RDT_RESOURCE_L2,
+	RDT_RESOURCE_MBA,
+	RDT_RESOURCE_SMBA,
+
+	/* Must be the last */
+	RDT_NUM_RESOURCES,
+};
+
 #define CDP_NUM_TYPES	(CDP_DATA + 1)
 
 /*
@@ -190,6 +200,13 @@ struct rdt_resource {
 	bool			cdp_capable;
 };
 
+/*
+ * Get the resource that exists at this level. If the level is not supported
+ * a dummy/not-capable resource can be returned. Levels >= RDT_NUM_RESOURCES
+ * will return NULL.
+ */
+struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l);
+
 /**
  * struct resctrl_schema - configuration abilities of a resource presented to
  *			   user-space
Signature · 2 lines
Thanks
Babu Moger
reviewer
#20 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

Quoted 16 lines · Babu

Hi James/Dave,

Quoted 13 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

Quoted 7 lines
Quoted 3 lines

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

Nit.
You may want to drop the second half of the statement. We don't have a dummy resource.

I guess not, but MPAM will, although I haven't fully understood the logic. See:

https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2

(Search for "dummy".)

In any case, the statement above is part of the definition of the new
interface: the resctrl core code is going to explicitly need to cope with a dummy resource being returned, and the arch code is required to return a pointer to something and not NULL.

So I would say that it is appropriate (or, at the very least, harmless) to keep that statement here?

Quoted 12 lines
Quoted 12 lines
---
 arch/x86/kernel/cpu/resctrl/core.c        | 10 +++++++++-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 10 ----------
 arch/x86/kernel/cpu/resctrl/monitor.c     |  8 ++++----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 15 +++++++--------
 include/linux/resctrl.h                   | 17 +++++++++++++++++
 6 files changed, 38 insertions(+), 24 deletions(-)

[...]

Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 1767c1affa60..45372b6a6215 100644

[...]

Quoted 27 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void schemata_list_destroy(void) · line 2628

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -2625,10 +2625,10 @@ static void schemata_list_destroy(void)
 
 static int rdt_get_tree(struct fs_context *fc)
 {
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Its is probably best to keep the resource name as r here to be consistent with other changes.

Quoted 18 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -3
 	struct rdt_fs_context *ctx = rdt_fc2context(fc);
 	unsigned long flags = RFTYPE_CTRL_BASE;
 	struct rdt_domain *dom;
-	struct rdt_resource *r;
 	int ret;
 
 	cpus_read_lock();
@@ -2701,8 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc)
 		resctrl_mounted = true;
 
 	if (is_mbm_enabled()) {
-		r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-		list_for_each_entry(dom, &r->domains, list)
+		list_for_each_entry(dom, &l3->domains, list)
 			mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
 						   RESCTRL_PICK_ANY_CPU);
 	}
@@ -3878,7 +3877,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)

[...]

Quoted 2 lines

Thanks
Babu Moger

[...]

Yes, this does look a bit odd.

This looks like a no-op change to me -- I think that resctrl_arch_get_resource() is supposed to be without side-effects, so I would have expected this to be a one-line change at the assignment to r, with no particular need for renaming r.

Does that make sense to you, or is there some complexity I'm not noticing here?

Cheers
---Dave

reviewer
#21 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

Hi Dave,

Quoted 33 lines · Dave Martin
Quoted 16 lines · Babu

Hi James/Dave,

Quoted 13 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

Quoted 7 lines
Quoted 3 lines

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

Nit.
You may want to drop the second half of the statement. We don't have a dummy resource.

I guess not, but MPAM will, although I haven't fully understood the logic. See:

https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2

(Search for "dummy".)

Quoted 7 lines

In any case, the statement above is part of the definition of the new
interface: the resctrl core code is going to explicitly need to cope with a dummy resource being returned, and the arch code is required to return a pointer to something and not NULL.

So I would say that it is appropriate (or, at the very least, harmless) to keep that statement here?

Ok. fine.

Quoted 60 lines
Quoted 13 lines
Quoted 13 lines
---
 arch/x86/kernel/cpu/resctrl/core.c        | 10 +++++++++-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 10 ----------
 arch/x86/kernel/cpu/resctrl/monitor.c     |  8 ++++----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 15 +++++++--------
 include/linux/resctrl.h                   | 17 +++++++++++++++++
 6 files changed, 38 insertions(+), 24 deletions(-)

[...]

Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 1767c1affa60..45372b6a6215 100644

[...]

Quoted 27 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void schemata_list_destroy(void) · line 2628

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -2625,10 +2625,10 @@ static void schemata_list_destroy(void)
 
 static int rdt_get_tree(struct fs_context *fc)
 {
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Its is probably best to keep the resource name as r here to be consistent with other changes.

Quoted 18 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -3
 	struct rdt_fs_context *ctx = rdt_fc2context(fc);
 	unsigned long flags = RFTYPE_CTRL_BASE;
 	struct rdt_domain *dom;
-	struct rdt_resource *r;
 	int ret;
 
 	cpus_read_lock();
@@ -2701,8 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc)
 		resctrl_mounted = true;
 
 	if (is_mbm_enabled()) {
-		r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-		list_for_each_entry(dom, &r->domains, list)
+		list_for_each_entry(dom, &l3->domains, list)
 			mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
 						   RESCTRL_PICK_ANY_CPU);
 	}
@@ -3878,7 +3877,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)

[...]

Quoted 2 lines

Thanks
Babu Moger

[...]

Yes, this does look a bit odd.

Quoted 7 lines

This looks like a no-op change to me -- I think that resctrl_arch_get_resource() is supposed to be without side-effects, so I would have expected this to be a one-line change at the assignment to r, with no particular need for renaming r.

Does that make sense to you, or is there some complexity I'm not noticing here?

No other complexity.. Just keep the variable name as r.

struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Signature · 2 lines
Thanks
Babu Moger
reviewer
#22 lore raw

Re: [PATCH v1 02/31] x86/resctrl: Add a helper to avoid reaching into the arch code resource list

Quoted 110 lines · Babu

Hi Dave,

Quoted 33 lines · Dave Martin
Quoted 16 lines · Babu

Hi James/Dave,

Quoted 13 lines · James Morse

Resctrl occasionally wants to know something about a specific resource, in these cases it reaches into the arch code's rdt_resources_all[] array.

Once the filesystem parts of resctrl are moved to /fs/, this means it will need visibility of the architecture specific struct resctrl_hw_resource definition, and the array of all resources. All architectures would also need a r_resctrl member in this struct.

Instead, abstract this via a helper to allow architectures to do different things here. Move the level enum to the resctrl header and add a helper to retrieve the struct rdt_resource by 'rid'.

Quoted 7 lines
Quoted 3 lines

resctrl_arch_get_resource() should not return NULL for any value in the enum, it may instead return a dummy resource that is !alloc_enabled && !mon_enabled.

Nit.
You may want to drop the second half of the statement. We don't have a dummy resource.

I guess not, but MPAM will, although I haven't fully understood the logic. See:

https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2

(Search for "dummy".)

Quoted 7 lines

In any case, the statement above is part of the definition of the new
interface: the resctrl core code is going to explicitly need to cope with a dummy resource being returned, and the arch code is required to return a pointer to something and not NULL.

So I would say that it is appropriate (or, at the very least, harmless) to keep that statement here?

Ok. fine.

Quoted 65 lines
Quoted 13 lines
Quoted 13 lines
---
 arch/x86/kernel/cpu/resctrl/core.c        | 10 +++++++++-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 10 ----------
 arch/x86/kernel/cpu/resctrl/monitor.c     |  8 ++++----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 15 +++++++--------
 include/linux/resctrl.h                   | 17 +++++++++++++++++
 6 files changed, 38 insertions(+), 24 deletions(-)

[...]

Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 1767c1affa60..45372b6a6215 100644

[...]

Quoted 27 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void schemata_list_destroy(void) · line 2628

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -2625,10 +2625,10 @@ static void schemata_list_destroy(void)
 
 static int rdt_get_tree(struct fs_context *fc)
 {
+	struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Its is probably best to keep the resource name as r here to be consistent with other changes.

Quoted 18 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -3
 	struct rdt_fs_context *ctx = rdt_fc2context(fc);
 	unsigned long flags = RFTYPE_CTRL_BASE;
 	struct rdt_domain *dom;
-	struct rdt_resource *r;
 	int ret;
 
 	cpus_read_lock();
@@ -2701,8 +2701,7 @@ static int rdt_get_tree(struct fs_context *fc)
 		resctrl_mounted = true;
 
 	if (is_mbm_enabled()) {
-		r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-		list_for_each_entry(dom, &r->domains, list)
+		list_for_each_entry(dom, &l3->domains, list)
 			mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
 						   RESCTRL_PICK_ANY_CPU);
 	}
@@ -3878,7 +3877,7 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)

[...]

Quoted 2 lines

Thanks
Babu Moger

[...]

Yes, this does look a bit odd.

This looks like a no-op change to me -- I think that resctrl_arch_get_resource() is supposed to be without side-effects, so I would have expected this to be a one-line change at the assignment to r, with no particular need for renaming r.

Quoted 6 lines
Quoted 2 lines

Does that make sense to you, or is there some complexity I'm not noticing here?

No other complexity.. Just keep the variable name as r.

struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);

Ack; I went for the minimum-diffstat option in the end, so kept the declaration and initialiser separate. If you have a strong view on that though, please shout.

Cheers
---Dave

author reviewer
#23 lore raw

PATCH 3/31 x86/resctrl: Move ctrlval string parsing policy away from the arch code

In reply to James Morse

The policy for parsing the configuration values as a string from user-space is specified by a function pointer the arch code specifies.

These strings are part of resctrl's ABI, and the functions and their caller both live in the same file. Exporting the parsing functions and allowing the architecture to choose how a schema is parsed allows an architecture to get this wrong.

Keep this all in the flesystem parts of resctrl. This should prevent any architecture's string-parsing behaviour from varying without core code changes. Use the fflags to spot caches and bandwidth resources, and use the appropriate helper.

---
 arch/x86/kernel/cpu/resctrl/core.c        |  4 ----
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 28 +++++++++++++++++++----
 arch/x86/kernel/cpu/resctrl/internal.h    | 10 --------
 include/linux/resctrl.h                   |  7 ------
 4 files changed, 23 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +0 -4
index b773b3bdebe3..d07eff7d6750 100644
@@ -75,7 +75,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
 			.name			= "L3",
 			.cache_level		= 3,
 			.domains		= domain_init(RDT_RESOURCE_L3),
-			.parse_ctrlval		= parse_cbm,
 			.format_str		= "%d=%0*x",
 			.fflags			= RFTYPE_RES_CACHE,
 		},
@@ -89,7 +88,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
 			.name			= "L2",
 			.cache_level		= 2,
 			.domains		= domain_init(RDT_RESOURCE_L2),
-			.parse_ctrlval		= parse_cbm,
 			.format_str		= "%d=%0*x",
 			.fflags			= RFTYPE_RES_CACHE,
 		},
@@ -103,7 +101,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
 			.name			= "MB",
 			.cache_level		= 3,
 			.domains		= domain_init(RDT_RESOURCE_MBA),
-			.parse_ctrlval		= parse_bw,
 			.format_str		= "%d=%*u",
 			.fflags			= RFTYPE_RES_MB,
 		},
@@ -115,7 +112,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
 			.name			= "SMBA",
 			.cache_level		= 3,
 			.domains		= domain_init(RDT_RESOURCE_SMBA),
-			.parse_ctrlval		= parse_bw,
 			.format_str		= "%d=%*u",
 			.fflags			= RFTYPE_RES_MB,
 		},
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +23 -5
index 788ac0395645..72a651671c68 100644
@@ -23,6 +23,15 @@
 
 #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_domain *d);
+
 /*
  * Check whether MBA bandwidth percentage value is correct. The value is
  * checked against the minimum and max bandwidth values specified by the
@@ -59,8 +68,8 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
 	return true;
 }
 
-int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
-	     struct rdt_domain *d)
+static int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
+		    struct rdt_domain *d)
 {
 	struct resctrl_staged_config *cfg;
 	u32 closid = data->rdtgrp->closid;
@@ -138,8 +147,8 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
  * Read one cache bit mask (hex). Check that it is valid for the current
  * resource type.
  */
-int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
-	      struct rdt_domain *d)
+static int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
+		     struct rdt_domain *d)
 {
 	struct rdtgroup *rdtgrp = data->rdtgrp;
 	struct resctrl_staged_config *cfg;
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}
+
 /*
  * For each domain in this resource we expect to find a series of:
  *	id=mask
@@ -204,6 +221,7 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 static int parse_line(char *line, struct resctrl_schema *s,
 		      struct rdtgroup *rdtgrp)
 {
+	ctrlval_parser_t *parse_ctrlval = get_parser(s->res);
 	enum resctrl_conf_type t = s->conf_type;
 	struct resctrl_staged_config *cfg;
 	struct rdt_resource *r = s->res;
@@ -235,7 +253,7 @@ static int parse_line(char *line, struct resctrl_schema *s,
 		if (d->id == dom_id) {
 			data.buf = dom;
 			data.rdtgrp = rdtgrp;
-			if (r->parse_ctrlval(&data, s, d))
+			if (parse_ctrlval(&data, s, d))
 				return -EINVAL;
 			if (rdtgrp->mode ==  RDT_MODE_PSEUDO_LOCKSETUP) {
 				cfg = &d->staged_config[t];
arch/x86/kernel/cpu/resctrl/internal.h +0 -10
index 65990def6c79..9048bd32e86f 100644
@@ -413,11 +413,6 @@ static inline bool is_mbm_event(int e)
 		e <= QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
-struct rdt_parse_data {
-	struct rdtgroup		*rdtgrp;
-	char			*buf;
-};
-
 /**
  * struct rdt_hw_resource - arch private attributes of a resctrl resource
  * @r_resctrl:		Attributes of the resource used directly by resctrl.
@@ -455,11 +450,6 @@ static inline struct rdt_hw_resource *resctrl_to_arch_res(struct rdt_resource *r
 	return container_of(r, struct rdt_hw_resource, r_resctrl);
 }
 
-int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
-	      struct rdt_domain *d);
-int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
-	     struct rdt_domain *d);
-
 extern struct mutex rdtgroup_mutex;
 
 extern struct rdt_hw_resource rdt_resources_all[];
include/linux/resctrl.h +0 -7
index 168cc9510069..6e87bc95f5ea 100644
@@ -157,9 +157,6 @@ struct resctrl_membw {
 	u32				*mb_map;
 };
 
-struct rdt_parse_data;
-struct resctrl_schema;
-
 /**
  * struct rdt_resource - attributes of a resctrl resource
  * @rid:		The index of the resource
@@ -174,7 +171,6 @@ struct resctrl_schema;
  * @data_width:		Character width of data when displaying
  * @default_ctrl:	Specifies default cache cbm or memory B/W percent.
  * @format_str:		Per resource format string to show domain value
- * @parse_ctrlval:	Per resource function pointer to parse control values
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
  * @cdp_capable:	Is the CDP feature available on this resource
@@ -192,9 +188,6 @@ struct rdt_resource {
 	int			data_width;
 	u32			default_ctrl;
 	const char		*format_str;
-	int			(*parse_ctrlval)(struct rdt_parse_data *data,
-						 struct resctrl_schema *s,
-						 struct rdt_domain *d);
 	struct list_head	evt_list;
 	unsigned long		fflags;
 	bool			cdp_capable;
Signature · 1 line
2.39.2
maintainer
#24 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Hi James,

Quoted 9 lines · James Morse

The policy for parsing the configuration values as a string from user-space is specified by a function pointer the arch code specifies.

These strings are part of resctrl's ABI, and the functions and their caller both live in the same file. Exporting the parsing functions and allowing the architecture to choose how a schema is parsed allows an architecture to get this wrong.

Keep this all in the flesystem parts of resctrl. This should prevent any

flesystem -> filesystem

Quoted 6 lines

architecture's string-parsing behaviour from varying without core code changes. Use the fflags to spot caches and bandwidth resources, and use the appropriate helper.

---

...

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 11 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

This is borderline ... at minimum it expands what fflags means and how it is intended to be used and that needs to be documented because it reads:

* @fflags: flags to choose base and info files

I am curious why you picked fflags instead of an explicit check against rid?

Reinette

reviewer
#25 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

The policy for parsing the configuration values as a string from user-space is specified by a function pointer the arch code specifies.

Quoted 8 lines
Quoted 6 lines

These strings are part of resctrl's ABI, and the functions and their caller both live in the same file. Exporting the parsing functions and allowing the architecture to choose how a schema is parsed allows an architecture to get this wrong.

Keep this all in the flesystem parts of resctrl. This should prevent any

flesystem -> filesystem

Noted, thanks.

Quoted 24 lines
Quoted 6 lines

architecture's string-parsing behaviour from varying without core code changes. Use the fflags to spot caches and bandwidth resources, and use the appropriate helper.

---

..

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 11 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

This is borderline ... at minimum it expands what fflags means and how it is intended to be used and that needs to be documented because it reads:

Quoted 6 lines

* @fflags: flags to choose base and info files

I am curious why you picked fflags instead of an explicit check against rid?

Reinette

Is fflags already somewhat overloaded? There seem to be a mix of things that are independent Boolean flags, while other things seem mutually exclusive or enum-like.

Do we expect RFTYPE_RES_CACHE | RFTYPE_RES_MB ever to make sense, as David points out?

With MPAM, we could in theory have cache population control and egress memory bandwidth controls on a single interconnect component.

If that would always be represented through resctrl as two components with the MB controls considered one level out from the CACHE controls, then I guess these control types remain mutually exclusive from resctrl's point of view.

Allowing a single rdt_resource to sprout multiple control types looks more invasive in the code, even if it logically makes sense in terms of the hardware.

(I'm guessing that may have already been ruled out? Apologies if I seem to be questioning things that were decided already. That's not my intention, and James will already have thought about this in any case...)

Anyway, for this patch, there seem to be a couple of assumptions:

a) get_parser() doesn't get called except for rdt_resources that represent resource controls (so, fflags = RFTYPE_RES_foo for some "foo", with no other flags set), and

b) there are exactly two kinds of "foo", so whatever isn't a CACHE is a BW.

These assumptions seem to hold today (?)

But the semantics of fflags already look a bit complicated, so I can see why it might be best to avoid anything that may add more complexity.

If the main aim is to avoid silly copy-paste errors when coding up resources for a new arch, would it make sense to go for a more low- tech approach and just bundle up related fields in a macro?

E.g., something like:

#define RDT_RESOURCE_MB_DEFAULTS		\
	.format_str	= "%d=%*u",		\
	.fflags		= RFTYPE_RES_MB,	\
	.parse_ctrlval	= parse_bw
#define RDT_RESOURCE_CACHE_DEFAULTS		\
	.format_str	= "%d=%0*x",		\
	.fflags		= RFTYPE_RES_CACHE,	\
	.parse_ctrlval	= parse_cbm

This isn't particularly pretty, but would at least help avoid accidents and reduce the amount of explicit boilerplate in the resource definitions.

Thoughts?

Cheers
---Dave

maintainer
#26 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Hi Dave,

Quoted 53 lines · Dave Martin
Quoted 17 lines · Reinette Chatre

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 11 lines · James Morse
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

This is borderline ... at minimum it expands what fflags means and how it is intended to be used and that needs to be documented because it reads:

Quoted 6 lines

* @fflags: flags to choose base and info files

I am curious why you picked fflags instead of an explicit check against rid?

Reinette

Is fflags already somewhat overloaded? There seem to be a mix of things that are independent Boolean flags, while other things seem mutually exclusive or enum-like.

Do we expect RFTYPE_RES_CACHE | RFTYPE_RES_MB ever to make sense, as David points out?

With MPAM, we could in theory have cache population control and egress memory bandwidth controls on a single interconnect component.

If that would always be represented through resctrl as two components with the MB controls considered one level out from the CACHE controls, then I guess these control types remain mutually exclusive from resctrl's point of view.

Allowing a single rdt_resource to sprout multiple control types looks more invasive in the code, even if it logically makes sense in terms of the hardware.

(I'm guessing that may have already been ruled out? Apologies if I seem to be questioning things that were decided already. That's not my intention, and James will already have thought about this in any case...)

Anyway, for this patch, there seem to be a couple of assumptions:

Quoted 8 lines

a) get_parser() doesn't get called except for rdt_resources that represent resource controls (so, fflags = RFTYPE_RES_foo for some "foo", with no other flags set), and

b) there are exactly two kinds of "foo", so whatever isn't a CACHE is a BW.

These assumptions seem to hold today (?)

(c) the parser for user provided data is based on the resource type.

As I understand (c) may not be true for MPAM that supports different partitioning controls for a single resource. For example, for a cache MPAM supports portion as well as maximum capacity controls that I expect would need different parsers (perhaps mapping to different schemata entries?) from user space but will be used to control the same resource.

I do now know if the goal is to support this MPAM capability via resctrl but do accomplish this I wonder if it may not be more appropriate to associate the parser with the schema entry that is presented to user space.

Quoted 3 lines

But the semantics of fflags already look a bit complicated, so I can see why it might be best to avoid anything that may add more complexity.

ack.

Quoted 3 lines

If the main aim is to avoid silly copy-paste errors when coding up resources for a new arch, would it make sense to go for a more low- tech approach and just bundle up related fields in a macro?

I understand this as more than avoiding copy-paste errors. I understand the goal is to prevent architectures from having architecture specific parsers.

Quoted 13 lines

E.g., something like:

#define RDT_RESOURCE_MB_DEFAULTS		\
	.format_str	= "%d=%*u",		\
	.fflags		= RFTYPE_RES_MB,	\
	.parse_ctrlval	= parse_bw
#define RDT_RESOURCE_CACHE_DEFAULTS		\
	.format_str	= "%d=%0*x",		\
	.fflags		= RFTYPE_RES_CACHE,	\
	.parse_ctrlval	= parse_cbm
Quoted 5 lines

This isn't particularly pretty, but would at least help avoid accidents and reduce the amount of explicit boilerplate in the resource definitions.

Thoughts?

I understand the goal of this patch to make the parser something that the fs code owns. This is done in support of a consistent user interface. It is not clear how turning this into macros prevents arch code from still overriding the parser.

You do highlight another point though, shouldn't the fs code own the format_str also? I do not think we want arch code to control the print format, this is also something that should be consistent between all archs and owned by fs code, again perhaps more appropriate for a schema entry.

Reinette

reviewer
#27 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Quoted 116 lines · Reinette Chatre

Hi Dave,

Quoted 53 lines · Dave Martin
Quoted 17 lines · Reinette Chatre

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 11 lines · James Morse
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

This is borderline ... at minimum it expands what fflags means and how it is intended to be used and that needs to be documented because it reads:

Quoted 6 lines

* @fflags: flags to choose base and info files

I am curious why you picked fflags instead of an explicit check against rid?

Reinette

Is fflags already somewhat overloaded? There seem to be a mix of things that are independent Boolean flags, while other things seem mutually exclusive or enum-like.

Do we expect RFTYPE_RES_CACHE | RFTYPE_RES_MB ever to make sense, as David points out?

With MPAM, we could in theory have cache population control and egress memory bandwidth controls on a single interconnect component.

If that would always be represented through resctrl as two components with the MB controls considered one level out from the CACHE controls, then I guess these control types remain mutually exclusive from resctrl's point of view.

Allowing a single rdt_resource to sprout multiple control types looks more invasive in the code, even if it logically makes sense in terms of the hardware.

(I'm guessing that may have already been ruled out? Apologies if I seem to be questioning things that were decided already. That's not my intention, and James will already have thought about this in any case...)

Anyway, for this patch, there seem to be a couple of assumptions:

Quoted 8 lines

a) get_parser() doesn't get called except for rdt_resources that represent resource controls (so, fflags = RFTYPE_RES_foo for some "foo", with no other flags set), and

b) there are exactly two kinds of "foo", so whatever isn't a CACHE is a BW.

These assumptions seem to hold today (?)

(c) the parser for user provided data is based on the resource type.

As I understand (c) may not be true for MPAM that supports different partitioning controls for a single resource. For example, for a cache MPAM supports portion as well as maximum capacity controls that I expect would need different parsers (perhaps mapping to different schemata entries?) from user space but will be used to control the same resource.

I do now know if the goal is to support this MPAM capability via resctrl but do accomplish this I wonder if it may not be more appropriate to associate the parser with the schema entry that is presented to user space.

Quoted 3 lines

But the semantics of fflags already look a bit complicated, so I can see why it might be best to avoid anything that may add more complexity.

ack.

Quoted 3 lines

If the main aim is to avoid silly copy-paste errors when coding up resources for a new arch, would it make sense to go for a more low- tech approach and just bundle up related fields in a macro?

I understand this as more than avoiding copy-paste errors. I understand the goal is to prevent architectures from having architecture specific parsers.

Quoted 13 lines

E.g., something like:

#define RDT_RESOURCE_MB_DEFAULTS		\
	.format_str	= "%d=%*u",		\
	.fflags		= RFTYPE_RES_MB,	\
	.parse_ctrlval	= parse_bw
#define RDT_RESOURCE_CACHE_DEFAULTS		\
	.format_str	= "%d=%0*x",		\
	.fflags		= RFTYPE_RES_CACHE,	\
	.parse_ctrlval	= parse_cbm
Quoted 5 lines

This isn't particularly pretty, but would at least help avoid accidents and reduce the amount of explicit boilerplate in the resource definitions.

Thoughts?

I understand the goal of this patch to make the parser something that the fs code owns. This is done in support of a consistent user interface. It is not clear how turning this into macros prevents arch code from still overriding the parser.

Quoted 7 lines

You do highlight another point though, shouldn't the fs code own the format_str also? I do not think we want arch code to control the print format, this is also something that should be consistent between all archs and owned by fs code, again perhaps more appropriate for a schema entry.

Reinette

Fair points, I guess.

For the print format, I was presuming that this ought to be consistent with the parse format, so probably a core property too (until/unless someone comes up with a convincing counterexample).

Would something like the following make sense, if you want a less informal approach? (Modulo minor details like naming conventions etc.)

/* In fs/resctrl.c */

struct struct resctrl_ctrl_traits {
	const char		*format_str;
	ctrlval_parser_t	*parse_ctrlval;
};
static const struct resctrl_ctrl_traits resource_traits[]  = {
	[RESTYPE_INVALID] = {},
	[RESTYPE_MB] = {
		.format_str	= "%d=%*u",
		.parse_ctrlval	= parse_bw,
	},
	[RESTYPE_CACHE] = {
		.format_str	= "%d=%0*x",
		.parse_ctrlval	= parse_cbm,
	},
};

static bool is_resource(const struct rdt_resource *r)

{
	return r->fflags & RFTYPE_RES;
}

/* In include/linux/resctrl_types.h */

+#define RFTYPE_RES BIT(8)
-#define RFTYPE_RES_CACHE BIT(8)
-#define RFTYPE_RES_MB BIT(9)

/* For RFTYPE_RES: */
enum resctrl_resource_type {
RRESTYPE_INVALID,
RRESTYPE_MB,
RRESTYPE_CACHE,
};

/* In include/linux/resctrl.h */

struct rdt_resource {
/* ... */

- const char *format_str;
+ enum resctrl_resource_type res_type;

/* ... */
};

(RRESTYPE_INVALID would just be there to catch cases where .res_type is not assigned.)

James might also have other thoughts about this when he gets back...

In any case, it might make sense to detach this change from this series if we're making more significant changes in this area than just splitting the code into core and arch parts.

(Note also, your suggestion about indexing using rid may also work; I tend to assume that the mapping from rid to resource types may not be fixed, but maybe I'm being too strongly influenced by MPAM...)

Cheers
---Dave

maintainer
#28 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Hi Dave

Quoted 143 lines · Dave Martin
Quoted 116 lines · Reinette Chatre

Hi Dave,

Quoted 53 lines · Dave Martin
Quoted 17 lines · Reinette Chatre

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 11 lines · James Morse
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

This is borderline ... at minimum it expands what fflags means and how it is intended to be used and that needs to be documented because it reads:

Quoted 6 lines

* @fflags: flags to choose base and info files

I am curious why you picked fflags instead of an explicit check against rid?

Reinette

Is fflags already somewhat overloaded? There seem to be a mix of things that are independent Boolean flags, while other things seem mutually exclusive or enum-like.

Do we expect RFTYPE_RES_CACHE | RFTYPE_RES_MB ever to make sense, as David points out?

With MPAM, we could in theory have cache population control and egress memory bandwidth controls on a single interconnect component.

If that would always be represented through resctrl as two components with the MB controls considered one level out from the CACHE controls, then I guess these control types remain mutually exclusive from resctrl's point of view.

Allowing a single rdt_resource to sprout multiple control types looks more invasive in the code, even if it logically makes sense in terms of the hardware.

(I'm guessing that may have already been ruled out? Apologies if I seem to be questioning things that were decided already. That's not my intention, and James will already have thought about this in any case...)

Anyway, for this patch, there seem to be a couple of assumptions:

Quoted 8 lines

a) get_parser() doesn't get called except for rdt_resources that represent resource controls (so, fflags = RFTYPE_RES_foo for some "foo", with no other flags set), and

b) there are exactly two kinds of "foo", so whatever isn't a CACHE is a BW.

These assumptions seem to hold today (?)

(c) the parser for user provided data is based on the resource type.

As I understand (c) may not be true for MPAM that supports different partitioning controls for a single resource. For example, for a cache MPAM supports portion as well as maximum capacity controls that I expect would need different parsers (perhaps mapping to different schemata entries?) from user space but will be used to control the same resource.

I do now know if the goal is to support this MPAM capability via resctrl but do accomplish this I wonder if it may not be more appropriate to associate the parser with the schema entry that is presented to user space.

Quoted 3 lines

But the semantics of fflags already look a bit complicated, so I can see why it might be best to avoid anything that may add more complexity.

ack.

Quoted 3 lines

If the main aim is to avoid silly copy-paste errors when coding up resources for a new arch, would it make sense to go for a more low- tech approach and just bundle up related fields in a macro?

I understand this as more than avoiding copy-paste errors. I understand the goal is to prevent architectures from having architecture specific parsers.

Quoted 13 lines

E.g., something like:

#define RDT_RESOURCE_MB_DEFAULTS		\
	.format_str	= "%d=%*u",		\
	.fflags		= RFTYPE_RES_MB,	\
	.parse_ctrlval	= parse_bw
#define RDT_RESOURCE_CACHE_DEFAULTS		\
	.format_str	= "%d=%0*x",		\
	.fflags		= RFTYPE_RES_CACHE,	\
	.parse_ctrlval	= parse_cbm
Quoted 5 lines

This isn't particularly pretty, but would at least help avoid accidents and reduce the amount of explicit boilerplate in the resource definitions.

Thoughts?

I understand the goal of this patch to make the parser something that the fs code owns. This is done in support of a consistent user interface. It is not clear how turning this into macros prevents arch code from still overriding the parser.

Quoted 7 lines

You do highlight another point though, shouldn't the fs code own the format_str also? I do not think we want arch code to control the print format, this is also something that should be consistent between all archs and owned by fs code, again perhaps more appropriate for a schema entry.

Reinette

Fair points, I guess.

For the print format, I was presuming that this ought to be consistent with the parse format, so probably a core property too (until/unless someone comes up with a convincing counterexample).

Would something like the following make sense, if you want a less informal approach? (Modulo minor details like naming conventions etc.)

/* In fs/resctrl.c */

struct struct resctrl_ctrl_traits {
	const char		*format_str;
	ctrlval_parser_t	*parse_ctrlval;
};
Quoted 11 lines
static const struct resctrl_ctrl_traits resource_traits[]  = {
	[RESTYPE_INVALID] = {},
	[RESTYPE_MB] = {
		.format_str	= "%d=%*u",
		.parse_ctrlval	= parse_bw,
	},
	[RESTYPE_CACHE] = {
		.format_str	= "%d=%0*x",
		.parse_ctrlval	= parse_cbm,
	},
};

It is not obvious to me that another layer is needed here. format_str and parse_ctrlval can just be members of struct resctrl_schema?

Quoted 5 lines

static bool is_resource(const struct rdt_resource *r)

{
	return r->fflags & RFTYPE_RES;
}

I do not see the usage of is_resource().

(I think we are now discussing both this patch and patch #30 here)

Here is part relevant to #30:

What I was thinking about was something like below that uses the enum you introduce later and lets the RF flags stay internal to fs code:

rdtgroup_create_info_dir()
{

	...
	list_for_each_entry(s, &resctrl_schema_all, list) {
		r = s->res;
		if (r->res_type == RRESTYPE_CACHE)
			fflags = RFTYPE_RES_CACHE;
		else if (r->res_type == RRESTYPE_MB)
			fflags = RFTYPE_RES_MB;
		else /* fail */
		
		fflags |= RFTYPE_CTRL_INFO;

		...
	}
	/* same idea for monitor info files */

For this patch the resource type can be used to initialize the schema entry.

Review

Quoted 7 lines

/* In include/linux/resctrl_types.h */

(quoted diff) +1 -2
+#define RFTYPE_RES			BIT(8)
-#define RFTYPE_RES_CACHE		BIT(8)
-#define RFTYPE_RES_MB			BIT(9)

The goal is to not have to expose any of the RFTYPE flags internals to the architecture. RFTYPE_RES_CACHE and RFTYPE_RES_MB stays, but is not exposed to arch code. I do not see need for RFTYPE_RES. All the RFTYPE flags can be defined in fs/resctrl/internal.h

Quoted 7 lines

/* For RFTYPE_RES: */
enum resctrl_resource_type {
RRESTYPE_INVALID,
RRESTYPE_MB,
RRESTYPE_CACHE,
};

(I find naming hard ... note the names changed from the beginning of pseudo code to here where RESTYPE changing to RRESTYPE)

Quoted 11 lines

/* In include/linux/resctrl.h */

struct rdt_resource {
/* ... */

(quoted diff) +1 -1
-	const char			*format_str;
+	enum resctrl_resource_type	res_type;

/* ... */
};

Yes. With the above architecture code would only specify if it is cache or memory via enum resctrl_resource_type and need not know the individual file flags and can pick how to format and parse data based on the resource type.

Quoted 8 lines

(RRESTYPE_INVALID would just be there to catch cases where .res_type is not assigned.)

James might also have other thoughts about this when he gets back...

Quoted 7 lines

In any case, it might make sense to detach this change from this series if we're making more significant changes in this area than just splitting the code into core and arch parts.

(Note also, your suggestion about indexing using rid may also work; I tend to assume that the mapping from rid to resource types may not be fixed, but maybe I'm being too strongly influenced by MPAM...)

Reinette

author reviewer
#29 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Hi Reinette, Dave,

Quoted 21 lines · Reinette Chatre
Quoted 20 lines · Dave Martin
Quoted 19 lines · Reinette Chatre
Quoted 18 lines · Dave Martin
Quoted 17 lines · Reinette Chatre

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 11 lines · James Morse
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
 	return 0;
 }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

This is borderline ... at minimum it expands what fflags means and how it is intended to be used and that needs to be documented because it reads:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

* @fflags: flags to choose base and info files

Hmm, true this is used to day to select which groups of files appear.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I am curious why you picked fflags instead of an explicit check against rid?

Simply because it would need to match both L2 and L3 to parse_cbm, I didn't think that would scale if other cache resources get added. However, with an enum of types we can get the compiler to bark if an entry is needed here, which is probably good enough.

more background: {
In the arm world the cache hierarchy isn't something we can reason about. We have funny names for where different things converge, (Point of Coherency, Point of Unification etc), but its up to the platform designer if/where the L2/L3 or even L9 live. The cache topology is fed to the kernel via an ACPI table.

I anticipate a 'System Cache' resource and schema eventually being added to resctrl as it looks to be a popular hardware design. These system-cache live after the L3 (if there is one).
}

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Is fflags already somewhat overloaded? There seem to be a mix of things that are independent Boolean flags, while other things seem mutually exclusive or enum-like.

Do we expect RFTYPE_RES_CACHE | RFTYPE_RES_MB ever to make sense, as David points out?

With MPAM, we could in theory have cache population control and egress memory bandwidth controls on a single interconnect component.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

If that would always be represented through resctrl as two components with the MB controls considered one level out from the CACHE controls, then I guess these control types remain mutually exclusive from resctrl's point of view.

Allowing a single rdt_resource to sprout multiple control types looks more invasive in the code, even if it logically makes sense in terms of the hardware.

MPAM allows this, but it doesn't fit with resctrl. The MPAM drivers resctrl glue code has a load of stuff to present these as separate resources to resctrl, even if they are the same piece of hardware underneath.

So far it looks possible to hide this, I don't think its worth changing resctrl's behaviour to try and cover this.

RFTYPE_RES_CACHE and RFTYPE_RES_MB would remain mutually-exclusive.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Anyway, for this patch, there seem to be a couple of assumptions:

a) get_parser() doesn't get called except for rdt_resources that represent resource controls (so, fflags = RFTYPE_RES_foo for some "foo", with no other flags set), and

b) there are exactly two kinds of "foo", so whatever isn't a CACHE is a BW.

These assumptions seem to hold today (?)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

(c) the parser for user provided data is based on the resource type.

As I understand (c) may not be true for MPAM that supports different partitioning controls for a single resource. For example, for a cache MPAM supports portion as well as maximum capacity controls that I expect would need different parsers (perhaps mapping to different schemata entries?) from user space but will be used to control the same resource.

Exactly - to maintain compatibility with existing software the driver has to present it as a totally new thing. I guess it will look something like this:
| L3:0=0xffff;1=0xffff;
| L3_CAP:0=1048576;1=;1048576

Where existing software knows about 'L3', and should ignore 'L3_CAP'.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I do now know if the goal is to support this MPAM capability via resctrl but do accomplish this I wonder if it may not be more appropriate to associate the parser with the schema entry that is presented to user space.

Even better.

For Tony's resctrl2 I had mused on exposing to user-space whether the controls were a bitmap/percentage/MBps-value/raw-number. As there is a parser for the first two (or three) today I think keying these from something in the schemata makes the most sense.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines

But the semantics of fflags already look a bit complicated, so I can see why it might be best to avoid anything that may add more complexity.

ack.

Quoted 3 lines

If the main aim is to avoid silly copy-paste errors when coding up resources for a new arch, would it make sense to go for a more low- tech approach and just bundle up related fields in a macro?

I understand this as more than avoiding copy-paste errors. I understand the goal is to prevent architectures from having architecture specific parsers.

[...]

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

You do highlight another point though, shouldn't the fs code own the format_str also? I do not think we want arch code to control the print format, this is also something that should be consistent between all archs and owned by fs code, again perhaps more appropriate for a schema entry.

Good point ... I've still got that as a "TODO: kill these properties off as they are derivatives" in the MPAM code.

I agree they should live together. We can also pull in data_width too, as it is calculated based on the format used here.

Moving default_ctrl is tricky as on AMD platforms the {S,}MBA default value is discovered from cpuid. But it only makes sense for an architecture to provides this for MBps controls
- bitmaps and percentages have an obvious maximum/default value. Putting that in struct resctrl_membw as 'max_bw' makes bw_validate()s use of it clearer.

bw_validate() has always caught me out as it doesn't just parse percentages, but AMDs MBps values. I don't think this needs changing, but having MBps as a control type will make this less surprising.

Finally, core.c will end up keeping default_ctrl as an arch-specific thing as its convenient for the init and reset code.

[...]

Quoted 6 lines

What I was thinking about was something like below that uses the enum you introduce later and lets the RF flags stay internal to fs code:

rdtgroup_create_info_dir()
{

Quoted 14 lines
	...
	list_for_each_entry(s, &resctrl_schema_all, list) {
		r = s->res;
		if (r->res_type == RRESTYPE_CACHE)
			fflags = RFTYPE_RES_CACHE;
		else if (r->res_type == RRESTYPE_MB)
			fflags = RFTYPE_RES_MB;
		else /* fail */
		
		fflags |= RFTYPE_CTRL_INFO;

		...
	}
	/* same idea for monitor info files */

Good point, that would let us remove fflags from the arch code too.

Quoted 7 lines

For this patch the resource type can be used to initialize the schema entry.

Quoted 4 lines

/* In include/linux/resctrl_types.h */

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +1 -2
+#define RFTYPE_RES			BIT(8)
-#define RFTYPE_RES_CACHE		BIT(8)
-#define RFTYPE_RES_MB			BIT(9)

The goal is to not have to expose any of the RFTYPE flags internals to the architecture. RFTYPE_RES_CACHE and RFTYPE_RES_MB stays, but is not exposed to arch code. I do not see need for RFTYPE_RES. All the RFTYPE flags can be defined in fs/resctrl/internal.h

Yup, these should stay in internal.h - they got swept up as there are #defines either side that are needed for MPAM to build.

Quoted 9 lines
Quoted 6 lines

/* For RFTYPE_RES: */
enum resctrl_resource_type {
RRESTYPE_INVALID,
RRESTYPE_MB,
RRESTYPE_CACHE,
};

(I find naming hard ... note the names changed from the beginning of pseudo code to here where RESTYPE changing to RRESTYPE)

Before I saw this my attempt has:

| enum resctrl_schema_fmt {
| 	RESCTRL_SCHEMA_BITMAP,
| 	RESCTRL_SCHEMA_PERCENTAGE,
| 	RESCTRL_SCHEMA_MBPS,
| };

Invalid as value '0' would catch the arch code missing this - but means any switch over this enum has to handle it... I'd prefer to leave that out so the compiler can bark about any place that needs updating when a new control scheme is added.

Thanks,

James

#30 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

In reply to James Morse
Quoted 26 lines

/*
* Check whether MBA bandwidth percentage value is correct. The value is
* checked against the minimum and max bandwidth values specified by the

arch/x86/kernel/cpu/resctrl/ctrlmondata.c +4 -4
@@ -59,8 +68,8 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
  	return true;
  }
 
-int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
-	     struct rdt_domain *d)
+static int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
+		    struct rdt_domain *d)
  {
  	struct resctrl_staged_config *cfg;
  	u32 closid = data->rdtgrp->closid;
@@ -138,8 +147,8 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
   * Read one cache bit mask (hex). Check that it is valid for the current
   * resource type.
   */
-int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
-	      struct rdt_domain *d)
+static int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
+		     struct rdt_domain *d)
  {
  	struct rdtgroup *rdtgrp = data->rdtgrp;
  	struct resctrl_staged_config *cfg;

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 213

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
  	return 0;
  }
 
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

Besides what Reinette said, I'd have added here something that would fire in case someone adds something unexpected in the future, like

WARN_ON_ONCE(!(res->fflags & (RFTYPE_RES_CACHE|RFTYPE_RES_MB));

At the beginning of the function.

Apart from that, nothing jumped at me.

Signature · 3 lines
Cheers,

David / dhildenb
reviewer
#31 lore raw

Re: [PATCH v1 03/31] x86/resctrl: Move ctrlval string parsing policy away from the arch code

Hi,

On Tue, Apr 09, 2024 at 05:13:01PM +0200, David Hildenbrand wrote:

[...]

Quoted 14 lines

arch/x86/kernel/cpu/resctrl/ctrlmondata.c int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s, · line 212

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +7 -0
@@ -195,6 +204,14 @@ int parse_cbm(struct rdt_parse_data *data, struct resctrl_schema *s,
  	return 0;
  }
+static ctrlval_parser_t *get_parser(struct rdt_resource *res)
+{
+	if (res->fflags & RFTYPE_RES_CACHE)
+		return &parse_cbm;
+	else
+		return &parse_bw;
+}

Besides what Reinette said, I'd have added here something that would fire in case someone adds something unexpected in the future, like

Quoted 12 lines

WARN_ON_ONCE(!(res->fflags & (RFTYPE_RES_CACHE|RFTYPE_RES_MB));

At the beginning of the function.

Apart from that, nothing jumped at me.

Signature · 3 lines
Cheers,

David / dhildenb

Thanks for that -- I guess that would benefit from discussion; please see my reply to Reinette on this patch.

Cheers
---Dave

author reviewer
#32 lore raw

PATCH 4/31 x86/resctrl: Add helper for setting CPU default properties

In reply to James Morse

rdtgroup_rmdir_ctrl() and rdtgroup_rmdir_mon() set the per-CPU pqr_state for CPUs that were part of the rmdir()'d group.

Another architecture might not have a 'pqr_state', its hardware may need the values in a different format. MPAM's equivalent of RMID values are not unique, and always need the CLOSID to be provided too.

There is only one caller that modifies a single value, (rdtgroup_rmdir_mon()). MPAM always needs both CLOSID and RMID for the hardware value as these are written to the same system register.

As rdtgroup_rmdir_mon() has the CLOSID on hand, only provide a helper to set both values. These values are read by __resctrl_sched_in(), but may be written by a different CPU without any locking, add READ/WRTE_ONCE() to avoid torn values.

---
 arch/x86/include/asm/resctrl.h         | 14 +++++++++++---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 15 ++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)
arch/x86/include/asm/resctrl.h +11 -3
index 12dbd2588ca7..f61382258743 100644
@@ -4,8 +4,9 @@
 
 #ifdef CONFIG_X86_CPU_RESCTRL
 
-#include <linux/sched.h>
 #include <linux/jump_label.h>
+#include <linux/percpu.h>
+#include <linux/sched.h>
 
 /*
  * This value can never be a valid CLOSID, and is used when mapping a
@@ -96,8 +97,8 @@ static inline void resctrl_arch_disable_mon(void)
 static inline void __resctrl_sched_in(struct task_struct *tsk)
 {
 	struct resctrl_pqr_state *state = this_cpu_ptr(&pqr_state);
-	u32 closid = state->default_closid;
-	u32 rmid = state->default_rmid;
+	u32 closid = READ_ONCE(state->default_closid);
+	u32 rmid = READ_ONCE(state->default_rmid);
 	u32 tmp;
 
 	/*
@@ -132,6 +133,13 @@ static inline unsigned int resctrl_arch_round_mon_val(unsigned int val)
 	return val * scale;
 }
 
+static inline void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid,
+							    u32 rmid)
+{
+	WRITE_ONCE(per_cpu(pqr_state.default_closid, cpu), closid);
+	WRITE_ONCE(per_cpu(pqr_state.default_rmid, cpu), rmid);
+}
+
 static inline void resctrl_arch_set_closid_rmid(struct task_struct *tsk,
 						u32 closid, u32 rmid)
 {
arch/x86/kernel/cpu/resctrl/rdtgroup.c +10 -5
index 45372b6a6215..5d2c1ce5b6b1 100644
@@ -3623,14 +3623,18 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
 	struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+	u32 closid, rmid;
 	int cpu;
 
 	/* Give any tasks back to the parent group */
 	rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
 
 	/* Update per cpu rmid of the moved CPUs first */
+	closid = rdtgrp->closid;
+	rmid = prdtgrp->mon.rmid;
 	for_each_cpu(cpu, &rdtgrp->cpu_mask)
-		per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
+
 	/*
 	 * Update the MSR on moved CPUs and CPUs which have moved
 	 * task running on them.
@@ -3663,6 +3667,7 @@ static int rdtgroup_ctrl_remove(struct rdtgroup *rdtgrp)
 
 static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
+	u32 closid, rmid;
 	int cpu;
 
 	/* Give any tasks back to the default group */
@@ -3673,10 +3678,10 @@ static int rdtgroup_rmdir_ctrl(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 		   &rdtgroup_default.cpu_mask, &rdtgrp->cpu_mask);
 
 	/* Update per cpu closid and rmid of the moved CPUs first */
-	for_each_cpu(cpu, &rdtgrp->cpu_mask) {
-		per_cpu(pqr_state.default_closid, cpu) = rdtgroup_default.closid;
-		per_cpu(pqr_state.default_rmid, cpu) = rdtgroup_default.mon.rmid;
-	}
+	closid = rdtgroup_default.closid;
+	rmid = rdtgroup_default.mon.rmid;
+	for_each_cpu(cpu, &rdtgrp->cpu_mask)
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
 
 	/*
 	 * Update the MSR on moved CPUs and CPUs which have moved
Signature · 1 line
2.39.2
maintainer
#33 lore raw

Re: [PATCH v1 04/31] x86/resctrl: Add helper for setting CPU default properties

Hi James,

Quoted 9 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -3623,14 +3623,18 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
 	struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+	u32 closid, rmid;
 	int cpu;
 

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, · line 3637

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
 	/* Give any tasks back to the parent group */
 	rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
 
 	/* Update per cpu rmid of the moved CPUs first */
+	closid = rdtgrp->closid;
+	rmid = prdtgrp->mon.rmid;
 	for_each_cpu(cpu, &rdtgrp->cpu_mask)
-		per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
+

While I understand that the CLOSIDs are the same, I do think it looks unexpected for the CLOSID to be set to the CLOSID of the group being removed. Could this be set to CLOSID of parent group instead?

Reinette

reviewer
#34 lore raw

Re: [PATCH v1 04/31] x86/resctrl: Add helper for setting CPU default properties

Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 9 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -3623,14 +3623,18 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
 	struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+	u32 closid, rmid;
 	int cpu;
 

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, · line 3637

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
 	/* Give any tasks back to the parent group */
 	rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
 
 	/* Update per cpu rmid of the moved CPUs first */
+	closid = rdtgrp->closid;
+	rmid = prdtgrp->mon.rmid;
 	for_each_cpu(cpu, &rdtgrp->cpu_mask)
-		per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
+

While I understand that the CLOSIDs are the same, I do think it looks unexpected for the CLOSID to be set to the CLOSID of the group being removed. Could this be set to CLOSID of parent group instead?

Quoted 1 line

Reinette

That seems reasonable. How about something like this?

- closid = rdtgrp->closid;
+ closid = prdtgrp->closid; /* no change, but the arch code needs it */

Cheers
---Dave

maintainer
#35 lore raw

Re: [PATCH v1 04/31] x86/resctrl: Add helper for setting CPU default properties

Hi Dave,

Quoted 33 lines · Dave Martin
Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 9 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -3623,14 +3623,18 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
 	struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+	u32 closid, rmid;
 	int cpu;
 

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, · line 3637

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
 	/* Give any tasks back to the parent group */
 	rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
 
 	/* Update per cpu rmid of the moved CPUs first */
+	closid = rdtgrp->closid;
+	rmid = prdtgrp->mon.rmid;
 	for_each_cpu(cpu, &rdtgrp->cpu_mask)
-		per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
+

While I understand that the CLOSIDs are the same, I do think it looks unexpected for the CLOSID to be set to the CLOSID of the group being removed. Could this be set to CLOSID of parent group instead?

Quoted 1 line

Reinette

That seems reasonable. How about something like this?

Review

Quoted 2 lines
(quoted diff) +1 -1
-	closid = rdtgrp->closid;
+	closid = prdtgrp->closid; /* no change, but the arch code needs it */

Looks good. If the comment stays, please do replace the tail comment with a freestanding comment (for reference you can search for "No tail comments" in Documentation/process/maintainer-tip.rst).

Thank you

Reinette

reviewer
#36 lore raw

Re: [PATCH v1 04/31] x86/resctrl: Add helper for setting CPU default properties

Quoted 34 lines · Reinette Chatre

Hi Dave,

Quoted 31 lines · Dave Martin
Quoted 29 lines · Reinette Chatre

Hi James,

Quoted 9 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -3623,14 +3623,18 @@ static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
 static int rdtgroup_rmdir_mon(struct rdtgroup *rdtgrp, cpumask_var_t tmpmask)
 {
 	struct rdtgroup *prdtgrp = rdtgrp->mon.parent;
+	u32 closid, rmid;
 	int cpu;
 

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_mkdir(struct kernfs_node *parent_kn, const char *name, · line 3637

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -1
 	/* Give any tasks back to the parent group */
 	rdt_move_group_tasks(rdtgrp, prdtgrp, tmpmask);
 
 	/* Update per cpu rmid of the moved CPUs first */
+	closid = rdtgrp->closid;
+	rmid = prdtgrp->mon.rmid;
 	for_each_cpu(cpu, &rdtgrp->cpu_mask)
-		per_cpu(pqr_state.default_rmid, cpu) = prdtgrp->mon.rmid;
+		resctrl_arch_set_cpu_default_closid_rmid(cpu, closid, rmid);
+

While I understand that the CLOSIDs are the same, I do think it looks unexpected for the CLOSID to be set to the CLOSID of the group being removed. Could this be set to CLOSID of parent group instead?

Reinette

Quoted 8 lines

Review

Quoted 4 lines

That seems reasonable. How about something like this?

(quoted diff) +1 -1
-	closid = rdtgrp->closid;
+	closid = prdtgrp->closid; /* no change, but the arch code needs it */

Looks good. If the comment stays, please do replace the tail comment with a freestanding comment (for reference you can search for "No tail comments" in Documentation/process/maintainer-tip.rst).

Ack, noted.

Cheers
---Dave

author reviewer
#37 lore raw

PATCH 5/31 x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

In reply to James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +15 -4
index 5d2c1ce5b6b1..18f097fce51e 100644
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
 	/*
@@ -362,11 +362,22 @@ static void update_cpu_closid_rmid(void *info)
  * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
  *
  * Per task closids/rmids must have been set up before calling this function.
+ * @r may be NULL.
  */
 static void
 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
 {
-	on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
+	struct resctrl_cpu_sync defaults;
+	struct resctrl_cpu_sync *defaults_p = NULL;
+
+	if (r) {
+		defaults.closid = r->closid;
+		defaults.rmid = r->mon.rmid;
+		defaults_p = &defaults;
+	}
+
+	on_each_cpu_mask(cpu_mask, resctrl_arch_sync_cpu_defaults, defaults_p,
+			 1);
 }
 
 static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
include/linux/resctrl.h +11 -0
index 6e87bc95f5ea..2b79e4159507 100644
@@ -220,6 +220,17 @@ struct resctrl_schema {
 	u32				num_closid;
 };
 
+struct resctrl_cpu_sync {
+	u32 closid;
+	u32 rmid;
+};
+
+/*
+ * Update and re-load this CPUs defaults. Called via IPI, takes a pointer to
+ * struct resctrl_cpu_sync, or NULL.
+ */
+void resctrl_arch_sync_cpu_defaults(void *info);
+
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
Signature · 1 line
2.39.2
maintainer
#38 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Hi James,

Quoted 38 lines · James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
index 5d2c1ce5b6b1..18f097fce51e 100644
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
 	/*
@@ -362,11 +362,22 @@ static void update_cpu_closid_rmid(void *info)
  * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void update_cpu_closid_rmid(void *info) · line 371

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
  *
  * Per task closids/rmids must have been set up before calling this function.
+ * @r may be NULL.
  */
 static void
 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
 {
-	on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
+	struct resctrl_cpu_sync defaults;
+	struct resctrl_cpu_sync *defaults_p = NULL;

Please maintain reverse fir order.

Quoted 17 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9 -0
+
+	if (r) {
+		defaults.closid = r->closid;
+		defaults.rmid = r->mon.rmid;
+		defaults_p = &defaults;
+	}
+
+	on_each_cpu_mask(cpu_mask, resctrl_arch_sync_cpu_defaults, defaults_p,
+			 1);
 }
 
 static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
include/linux/resctrl.h +0 -0
index 6e87bc95f5ea..2b79e4159507 100644

include/linux/resctrl.h struct resctrl_schema { · line 229

Quoted 10 lines
include/linux/resctrl.h +7 -0
@@ -220,6 +220,17 @@ struct resctrl_schema {
 	u32				num_closid;
 };
 
+struct resctrl_cpu_sync {
+	u32 closid;
+	u32 rmid;
+};
+
+/*
+ * Update and re-load this CPUs defaults. Called via IPI, takes a pointer to

"this CPU's defaults"?

include/linux/resctrl.h struct resctrl_schema { · line 231

Quoted 2 lines
include/linux/resctrl.h +2 -0
+ * struct resctrl_cpu_sync, or NULL.
+ */

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

include/linux/resctrl.h struct resctrl_schema { · line 236

Quoted 5 lines
include/linux/resctrl.h +2 -0
+void resctrl_arch_sync_cpu_defaults(void *info);
+
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);

Reinette

reviewer
#39 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Quoted 38 lines · Reinette Chatre

Hi James,

Quoted 35 lines · James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
index 5d2c1ce5b6b1..18f097fce51e 100644
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
Quoted 15 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void update_cpu_closid_rmid(void *info) · line 371

Quoted 13 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
 	/*
@@ -362,11 +362,22 @@ static void update_cpu_closid_rmid(void *info)
  * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
  *
  * Per task closids/rmids must have been set up before calling this function.
+ * @r may be NULL.
  */
 static void
 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
 {
-	on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
+	struct resctrl_cpu_sync defaults;
+	struct resctrl_cpu_sync *defaults_p = NULL;

Please maintain reverse fir order.

Or, more tersely as follows?

	struct resctrl_cpu_sync defaults, *defaults_p = NULL;

"Reverse fir order" seems to be documented as a preference rather than a rule.

The declarations can be swapped, but defaults_p is in some sense a weak pointer to defaults, so it feels a bit strange to declare them backwards.

Alternatively, could we rename defaults_p to p? Given the size of this function I don't think that impacts clarity.

I'll wait for your opinion on this.

Quoted 20 lines
Quoted 20 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +9 -0
+
+	if (r) {
+		defaults.closid = r->closid;
+		defaults.rmid = r->mon.rmid;
+		defaults_p = &defaults;
+	}
+
+	on_each_cpu_mask(cpu_mask, resctrl_arch_sync_cpu_defaults, defaults_p,
+			 1);
 }
 
 static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
include/linux/resctrl.h +0 -0
index 6e87bc95f5ea..2b79e4159507 100644
@@ -220,6 +220,17 @@ struct resctrl_schema {
 	u32				num_closid;
 };
 
Quoted 9 lines

include/linux/resctrl.h struct resctrl_schema { · line 229

Quoted 7 lines
include/linux/resctrl.h +7 -0
+struct resctrl_cpu_sync {
+	u32 closid;
+	u32 rmid;
+};
+
+/*
+ * Update and re-load this CPUs defaults. Called via IPI, takes a pointer to

"this CPU's defaults"?

Ack (also in the commit message).

Quoted 4 lines

include/linux/resctrl.h struct resctrl_schema { · line 231

Quoted 3 lines
include/linux/resctrl.h +2 -0
+ * struct resctrl_cpu_sync, or NULL.
+ */
Quoted 10 lines

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

Quoted 1 line
include/linux/resctrl.h +1 -0
+void resctrl_arch_sync_cpu_defaults(void *info);

That seems reasonable, and follows the original naming and what the code does:

What about:

/**
* resctrl_arch_sync_cpu_defaults() - Refresh the CPU's CLOSID and RMID.
* Call via IPI.
* @info: If non-NULL, a pointer to a struct resctrl_cpu_sync specifying
* the new CLOSID and RMID for tasks in the default resctrl ctrl
* and mon group when running on this CPU. If NULL, the default
* CLOSID and RMID are not changed.
*
* This is how reassignment of CPUs and/or tasks to different resctrl groups
* is propagated when requested by the resctrl fs core code.
*
* This function should typically record the per-cpu defaults specified by
* @info (if any), and then reconfigure the CPU's hardware CLOSID and RMID
* for subsequent execution based on @current, in the same way as during a
* task switch.
*/

...?

Cheers
---Dave

maintainer
#40 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Hi Dave,

Quoted 55 lines · Dave Martin
Quoted 38 lines · Reinette Chatre

Hi James,

Quoted 35 lines · James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
index 5d2c1ce5b6b1..18f097fce51e 100644
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
Quoted 15 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void update_cpu_closid_rmid(void *info) · line 371

Quoted 13 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
 	/*
@@ -362,11 +362,22 @@ static void update_cpu_closid_rmid(void *info)
  * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
  *
  * Per task closids/rmids must have been set up before calling this function.
+ * @r may be NULL.
  */
 static void
 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
 {
-	on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
+	struct resctrl_cpu_sync defaults;
+	struct resctrl_cpu_sync *defaults_p = NULL;

Please maintain reverse fir order.

Quoted 3 lines

Or, more tersely as follows?

	struct resctrl_cpu_sync defaults, *defaults_p = NULL;

Sure.

Quoted 3 lines

"Reverse fir order" seems to be documented as a preference rather than a rule.

This does not seem to be a place that warrants an exception to this preference. Note how this function is not consistent with any other in the file.

Quoted 5 lines

The declarations can be swapped, but defaults_p is in some sense a weak pointer to defaults, so it feels a bit strange to declare them backwards.

Alternatively, could we rename defaults_p to p? Given the size of this function I don't think that impacts clarity.

Do you imply that this would maintain the order in this patch? It does not look to me that it would but I may be looking wrong.

sidenote: the "on_each_cpu_mask()" in update_closid_rmid() can be on one line.

Quoted 4 lines

I'll wait for your opinion on this.

...

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

+ * struct resctrl_cpu_sync, or NULL.
+ */

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

Quoted 1 line

+void resctrl_arch_sync_cpu_defaults(void *info);

Quoted 8 lines

That seems reasonable, and follows the original naming and what the code does:

What about:

/**
* resctrl_arch_sync_cpu_defaults() - Refresh the CPU's CLOSID and RMID.
* Call via IPI.

Did you intend to change function name?

How about "Refresh the CPU's ..." -> "Refresh this CPU's ..." I think it makes it more obvious how this function is called.

Quoted 4 lines

* @info: If non-NULL, a pointer to a struct resctrl_cpu_sync specifying
* the new CLOSID and RMID for tasks in the default resctrl ctrl
* and mon group when running on this CPU. If NULL, the default
* CLOSID and RMID are not changed.

"If NULL, this CPU is not re-assigned to a different group." ?

Quoted 3 lines

*
* This is how reassignment of CPUs and/or tasks to different resctrl groups
* is propagated when requested by the resctrl fs core code.

Could you please use imperative tone here? For example, "Propagates reassignment of CPUs and/or tasks to different resctrl groups."

Quoted 2 lines

*
* This function should typically record the per-cpu defaults specified by

"should" sounds like there may be cases when this is not done? Maybe just "Records the per-CPU defaults specified ..."

Quoted 6 lines

* @info (if any), and then reconfigure the CPU's hardware CLOSID and RMID
* for subsequent execution based on @current, in the same way as during a
* task switch.
*/

...?

Reinette

reviewer
#41 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Quoted 58 lines · Reinette Chatre

Hi Dave,

Quoted 55 lines · Dave Martin
Quoted 53 lines · Reinette Chatre

Hi James,

Quoted 38 lines · James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -3
index 5d2c1ce5b6b1..18f097fce51e 100644
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
 	/*
@@ -362,11 +362,22 @@ static void update_cpu_closid_rmid(void *info)
  * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void update_cpu_closid_rmid(void *info) · line 371

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -1
  *
  * Per task closids/rmids must have been set up before calling this function.
+ * @r may be NULL.
  */
 static void
 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
 {
-	on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
+	struct resctrl_cpu_sync defaults;
+	struct resctrl_cpu_sync *defaults_p = NULL;

Please maintain reverse fir order.

Quoted 5 lines
Quoted 3 lines

Or, more tersely as follows?

	struct resctrl_cpu_sync defaults, *defaults_p = NULL;

Sure.

[*]

Quoted 7 lines
Quoted 3 lines

"Reverse fir order" seems to be documented as a preference rather than a rule.

This does not seem to be a place that warrants an exception to this preference. Note how this function is not consistent with any other in the file.

Ack (just bikeshedding here TBH).

Quoted 6 lines
Quoted 6 lines

The declarations can be swapped, but defaults_p is in some sense a weak pointer to defaults, so it feels a bit strange to declare them backwards.

Alternatively, could we rename defaults_p to p? Given the size of this function I don't think that impacts clarity.

[...]

Quoted 7 lines
Quoted 4 lines

I'll wait for your opinion on this.

Do you imply that this would maintain the order in this patch? It does not look to me that it would but I may be looking wrong.

I'm not sure without looking again, but since this discussion is not a good use of your time I'll just go ahead and implement the change at [*] above, while restoring referse FIR order, if that is good for you.

Quoted 3 lines

sidenote: the "on_each_cpu_mask()" in update_closid_rmid() can be on one line.

I guess that might have been split to stick to the 80-char limit.

Due the the small size of this function, shall I just rename defaults_p to p? Alternatively, there are already a few non-printk lines over 80 chars, so maybe we can tolerate one more here?

Quoted 20 lines

..

Quoted 17 lines
Quoted 13 lines
Quoted 2 lines

+ * struct resctrl_cpu_sync, or NULL.
+ */

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

Quoted 1 line

+void resctrl_arch_sync_cpu_defaults(void *info);

That seems reasonable, and follows the original naming and what the code does:

Quoted 7 lines
Quoted 5 lines

What about:

/**
* resctrl_arch_sync_cpu_defaults() - Refresh the CPU's CLOSID and RMID.
* Call via IPI.

Did you intend to change function name?

Er, yes, I meant to use your suggestion here, so:
resctrl_arch_sync_cpu_closid_rmid().

Also, Babu Moger's suggestion to rename struct resctrl_cpu_sync to resctrl_cpu_defaults seems good, since that accurately describes what is specified in the struct (and what is *not* specified if NULL is passed).

Quoted 3 lines

How about "Refresh the CPU's ..." -> "Refresh this CPU's ..." I think it makes it more obvious how this function is called.

Agreed.

Quoted 7 lines
Quoted 5 lines

* @info: If non-NULL, a pointer to a struct resctrl_cpu_sync specifying
* the new CLOSID and RMID for tasks in the default resctrl ctrl
* and mon group when running on this CPU. If NULL, the default
* CLOSID and RMID are not changed.

"If NULL, this CPU is not re-assigned to a different group." ?

Agreed.

Quoted 6 lines
Quoted 3 lines

*
* This is how reassignment of CPUs and/or tasks to different resctrl groups
* is propagated when requested by the resctrl fs core code.

Could you please use imperative tone here? For example, "Propagates reassignment of CPUs and/or tasks to different resctrl groups."

Yes, that's better (and shorter).

Quoted 6 lines
Quoted 3 lines

*
* This function should typically record the per-cpu defaults specified by

"should" sounds like there may be cases when this is not done? Maybe just "Records the per-CPU defaults specified ..."

I didn't want to pre-judge what implementation-specific cruft the arch code needs here, so I was intentionally vague. But the arch would need to put the CPU defaults into effect somehow or other, so yes, I think your text is better here.

I'll make a note of those changes.

[...]

Cheers
---Dave

maintainer
#42 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Hi Dave,

Quoted 4 lines · Dave Martin
Quoted 3 lines · Reinette Chatre
Quoted 2 lines · Dave Martin
Quoted 1 line · Reinette Chatre

On 3/21/2024 9:50 AM, James Morse wrote:

...

Quoted 8 lines
Quoted 2 lines

Do you imply that this would maintain the order in this patch? It does not look to me that it would but I may be looking wrong.

I'm not sure without looking again, but since this discussion is not a good use of your time I'll just go ahead and implement the change at [*] above, while restoring referse FIR order, if that is good for you.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

sidenote: the "on_each_cpu_mask()" in update_closid_rmid() can be on one line.

I guess that might have been split to stick to the 80-char limit.

Due the the small size of this function, shall I just rename defaults_p to p? Alternatively, there are already a few non-printk lines over 80 chars, so maybe we can tolerate one more here?

80 chars are not enforced so strictly that it impacts readability. You may refer to how update_task_closid_rmid() looks for more confidence in/ motivation for placing this on one line.

Quoted 23 lines
Quoted 23 lines

..

Quoted 19 lines
Quoted 13 lines
Quoted 2 lines

+ * struct resctrl_cpu_sync, or NULL.
+ */

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

Quoted 1 line

+void resctrl_arch_sync_cpu_defaults(void *info);

That seems reasonable, and follows the original naming and what the code does:

What about:

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

/**
* resctrl_arch_sync_cpu_defaults() - Refresh the CPU's CLOSID and RMID.
* Call via IPI.

Did you intend to change function name?

Er, yes, I meant to use your suggestion here, so:
resctrl_arch_sync_cpu_closid_rmid().

I'm a bit confused here when comparing with your response in [1] mentioning a change to another name.

[1] https://lore.kernel.org/lkml/Zh6kgs1%[email protected]/

Quoted 4 lines

Also, Babu Moger's suggestion to rename struct resctrl_cpu_sync to resctrl_cpu_defaults seems good, since that accurately describes what is specified in the struct (and what is *not* specified if NULL is passed).

Sounds good, yes.

Reinette

reviewer
#43 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Quoted 22 lines · Reinette Chatre

Hi Dave,

Quoted 4 lines · Dave Martin
Quoted 3 lines · Reinette Chatre
Quoted 2 lines · Dave Martin
Quoted 1 line · Reinette Chatre

On 3/21/2024 9:50 AM, James Morse wrote:

..

Quoted 13 lines
Quoted 2 lines

Do you imply that this would maintain the order in this patch? It does not look to me that it would but I may be looking wrong.

I'm not sure without looking again, but since this discussion is not a good use of your time I'll just go ahead and implement the change at [*] above, while restoring referse FIR order, if that is good for you.

Quoted 3 lines

sidenote: the "on_each_cpu_mask()" in update_closid_rmid() can be on one line.

I guess that might have been split to stick to the 80-char limit.

Quoted 7 lines
Quoted 3 lines

Due the the small size of this function, shall I just rename defaults_p to p? Alternatively, there are already a few non-printk lines over 80 chars, so maybe we can tolerate one more here?

80 chars are not enforced so strictly that it impacts readability. You may refer to how update_task_closid_rmid() looks for more confidence in/ motivation for placing this on one line.

Agreed.

(I did in fact rename default_p to p in my fixup, which shortens the affected line as a side-effect anyway.)

<aside>

Although probably out of scope for this series, I wonder whether these two paths can be combined?

update_task_closid_rmid() selects the cross_call target by task, where update_closid_rmid() selects the cross_call target(s) by cpu. But the backend work that the arch code needs to do seems basically the same:
possibly update the the CPU default group membership, the reconfigure the MSRs for the running task to ensure that they aren't stale (with a possible optimisation not to bother if we sure that the MSRs are not stale for the task actually running, or if we know they wouldn't be changed by the write).

Even the check to see whether the right task is running seems somewhat
redundant: we already paid the cost of taking the IPI, and we have to cope with spurious, idempotent updates to the MSRs anyway since this is all racy.

Is there a high overhead to writing the MSRs on x86?

For arm64, the relevant system register only affects EL0 (i.e., userspace) execution, so we defer synchronisation of a whole bunch of stuff until the return to userspace.

</aside>

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines

..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

+ * struct resctrl_cpu_sync, or NULL.
+ */

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

Quoted 1 line

+void resctrl_arch_sync_cpu_defaults(void *info);

Quoted 8 lines

That seems reasonable, and follows the original naming and what the code does:

What about:

/**
* resctrl_arch_sync_cpu_defaults() - Refresh the CPU's CLOSID and RMID.
* Call via IPI.

Did you intend to change function name?

Quoted 8 lines
Quoted 3 lines

Er, yes, I meant to use your suggestion here, so:
resctrl_arch_sync_cpu_closid_rmid().

I'm a bit confused here when comparing with your response in [1] mentioning a change to another name.

[1] https://lore.kernel.org/lkml/Zh6kgs1%[email protected]/

My bad (sorry Babu!).

I read that suggestion carelessly and assumed it was aligned with Reinette's.

The most important thing seems to be to transfer the "defaults" from the name of the function to the name of the struct, since the struct is about defaults (and only about defaults), while the function is about defaults and the running task.

To avoid extra busy-work, I'll stick with resctrl_arch_sync_cpu_closid_rmid() for now, but I don't mind changing it if people prefer.

Quoted 9 lines
Quoted 4 lines

Also, Babu Moger's suggestion to rename struct resctrl_cpu_sync to resctrl_cpu_defaults seems good, since that accurately describes what is specified in the struct (and what is *not* specified if NULL is passed).

Sounds good, yes.

Reinette

Cheers
---Dave

maintainer
#44 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Hi Dave,

Quoted 6 lines · Dave Martin
Quoted 5 lines · Reinette Chatre
Quoted 4 lines · Dave Martin
Quoted 3 lines · Reinette Chatre
Quoted 2 lines · Dave Martin
Quoted 1 line · Reinette Chatre

On 3/21/2024 9:50 AM, James Morse wrote:

...

Quoted 14 lines

<aside>

Although probably out of scope for this series, I wonder whether these two paths can be combined?

update_task_closid_rmid() selects the cross_call target by task, where update_closid_rmid() selects the cross_call target(s) by cpu. But the backend work that the arch code needs to do seems basically the same:
possibly update the the CPU default group membership, the reconfigure the MSRs for the running task to ensure that they aren't stale (with a possible optimisation not to bother if we sure that the MSRs are not stale for the task actually running, or if we know they wouldn't be changed by the write).

Quoted 6 lines

Even the check to see whether the right task is running seems somewhat
redundant: we already paid the cost of taking the IPI, and we have to cope with spurious, idempotent updates to the MSRs anyway since this is all racy.

Is there a high overhead to writing the MSRs on x86?

The MSRs do not all have the same overhead. MSR_IA32_PQR_ASSOC is intended to be updated quickly but it is not free and I'd prefer to keep avoiding unnecessary updates where possible.

Quoted 52 lines

For arm64, the relevant system register only affects EL0 (i.e., userspace) execution, so we defer synchronisation of a whole bunch of stuff until the return to userspace.

</aside>

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines

..

Quoted 14 lines
Quoted 13 lines
Quoted 2 lines

+ * struct resctrl_cpu_sync, or NULL.
+ */

Updating the CPU's defaults is not the primary goal of this function and because of that I do not think this should be the focus with the main goal (updating RMID and CLOSID on CPU) ignored. Specifically, this function only updates the defaults if *info is set but it _always_ ensures CPU is running with appropriate CLOSID/RMID (which may or may not be from a CPU default).

I think resctrl_arch_sync_cpu_closid_rmid() may be more appropriate and the comment needs to elaborate what the function does.

Quoted 1 line

+void resctrl_arch_sync_cpu_defaults(void *info);

Quoted 8 lines

That seems reasonable, and follows the original naming and what the code does:

What about:

/**
* resctrl_arch_sync_cpu_defaults() - Refresh the CPU's CLOSID and RMID.
* Call via IPI.

Did you intend to change function name?

Quoted 8 lines
Quoted 3 lines

Er, yes, I meant to use your suggestion here, so:
resctrl_arch_sync_cpu_closid_rmid().

I'm a bit confused here when comparing with your response in [1] mentioning a change to another name.

[1] https://lore.kernel.org/lkml/Zh6kgs1%[email protected]/

My bad (sorry Babu!).

I read that suggestion carelessly and assumed it was aligned with Reinette's.

Quoted 8 lines

The most important thing seems to be to transfer the "defaults" from the name of the function to the name of the struct, since the struct is about defaults (and only about defaults), while the function is about defaults and the running task.

To avoid extra busy-work, I'll stick with resctrl_arch_sync_cpu_closid_rmid() for now, but I don't mind changing it if people prefer.

resctrl_arch_sync_cpu_closid_rmid() sounds good to me.

Reinette

reviewer
#45 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

In reply to James Morse

Hi James/Dave,

Quoted 20 lines · James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 5d2c1ce5b6b1..18f097fce51e 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_cpus_show(struct kernfs_open_file *of, · line 344

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)

How about keeping the name similar to the old name?

resctrl_arch_update_cpu_defaults

Quoted 40 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +14 -3
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
 	/*
@@ -362,11 +362,22 @@ static void update_cpu_closid_rmid(void *info)
  * Update the PGR_ASSOC MSR on all cpus in @cpu_mask,
  *
  * Per task closids/rmids must have been set up before calling this function.
+ * @r may be NULL.
  */
 static void
 update_closid_rmid(const struct cpumask *cpu_mask, struct rdtgroup *r)
 {
-	on_each_cpu_mask(cpu_mask, update_cpu_closid_rmid, r, 1);
+	struct resctrl_cpu_sync defaults;
+	struct resctrl_cpu_sync *defaults_p = NULL;
+
+	if (r) {
+		defaults.closid = r->closid;
+		defaults.rmid = r->mon.rmid;
+		defaults_p = &defaults;
+	}
+
+	on_each_cpu_mask(cpu_mask, resctrl_arch_sync_cpu_defaults, defaults_p,
+			 1);
 }
 
 static int cpus_mon_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
include/linux/resctrl.h +0 -0
index 6e87bc95f5ea..2b79e4159507 100644

include/linux/resctrl.h struct resctrl_schema { · line 223

Quoted 4 lines
include/linux/resctrl.h +1 -0
@@ -220,6 +220,17 @@ struct resctrl_schema {
 	u32				num_closid;
 };
 
+struct resctrl_cpu_sync {

How about changing it to resctrl_cpu_defaults?

Quoted 13 lines
include/linux/resctrl.h +10 -0
+	u32 closid;
+	u32 rmid;
+};
+
+/*
+ * Update and re-load this CPUs defaults. Called via IPI, takes a pointer to
+ * struct resctrl_cpu_sync, or NULL.
+ */
+void resctrl_arch_sync_cpu_defaults(void *info);
+
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
Signature · 2 lines
Thanks
Babu Moger
reviewer
#46 lore raw

Re: [PATCH v1 05/31] x86/resctrl: Remove rdtgroup from update_cpu_closid_rmid()

Quoted 31 lines · Babu

Hi James/Dave,

Quoted 20 lines · James Morse

update_cpu_closid_rmid() takes a struct rdtgroup as an argument, which it uses to update the local CPUs default pqr values. This is a problem once the resctrl parts move out to /fs/, as the arch code cannot poke around inside struct rdtgroup.

Rename update_cpu_closid_rmid() as resctrl_arch_sync_cpus_defaults() to be used as the target of an IPI, and pass the effective CLOSID and RMID in a new struct.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 +++++++++++++++----
 include/linux/resctrl.h                | 11 +++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 5d2c1ce5b6b1..18f097fce51e 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_cpus_show(struct kernfs_open_file *of, · line 344

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -341,13 +341,13 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
  * from update_closid_rmid() is protected against __switch_to() because
  * preemption is disabled.
  */
-static void update_cpu_closid_rmid(void *info)
+void resctrl_arch_sync_cpu_defaults(void *info)

How about keeping the name similar to the old name?

Quoted 1 line

resctrl_arch_update_cpu_defaults

Ack (Reinette made a similar comment.)

Quoted 12 lines
Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -2
 {
-	struct rdtgroup *r = info;
+	struct resctrl_cpu_sync *r = info;
 
 	if (r) {
 		this_cpu_write(pqr_state.default_closid, r->closid);
-		this_cpu_write(pqr_state.default_rmid, r->mon.rmid);
+		this_cpu_write(pqr_state.default_rmid, r->rmid);
 	}
 
 	/*

[...]

Quoted 15 lines

include/linux/resctrl.h struct resctrl_schema { · line 223

Quoted 9 lines
include/linux/resctrl.h +1 -0
index 6e87bc95f5ea..2b79e4159507 100644
@@ -220,6 +220,17 @@ struct resctrl_schema {
 	u32				num_closid;
 };
 
+struct resctrl_cpu_sync {

How about changing it to resctrl_cpu_defaults?

Quoted 3 lines
include/linux/resctrl.h +3 -0
+	u32 closid;
+	u32 rmid;
+};

[...]

Quoted 4 lines
Signature · 2 lines
Thanks
Babu Moger

Yes, your name describes what the struct means, so renaming it as per your suggestion does make sense.

I'll make a note.

Cheers
---Dave

author reviewer
#47 lore raw

PATCH 6/31 x86/resctrl: Export resctrl fs's init function

In reply to James Morse

rdtgroup_init() needs exporting so that arch code can call it once it lives in core code. As this is one of the few functions we export, rename it to have the resctrl in the name. The same goes for the exit call.

x86's arch code init functions for RDT are renamed to have an arch prefix to make it clear these are part of the architecture code.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 12 ++++++------
 arch/x86/kernel/cpu/resctrl/internal.h |  3 ---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  8 ++++----
 include/linux/resctrl.h                |  3 +++
 4 files changed, 13 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +6 -6
index d07eff7d6750..b4e7d655e242 100644
@@ -938,7 +938,7 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
 	}
 }
 
-static int __init resctrl_late_init(void)
+static int __init resctrl_arch_late_init(void)
 {
 	struct rdt_resource *r;
 	int state, ret;
@@ -963,7 +963,7 @@ static int __init resctrl_late_init(void)
 	if (state < 0)
 		return state;
 
-	ret = rdtgroup_init();
+	ret = resctrl_init();
 	if (ret) {
 		cpuhp_remove_state(state);
 		return ret;
@@ -979,18 +979,18 @@ static int __init resctrl_late_init(void)
 	return 0;
 }
 
-late_initcall(resctrl_late_init);
+late_initcall(resctrl_arch_late_init);
 
-static void __exit resctrl_exit(void)
+static void __exit resctrl_arch_exit(void)
 {
 	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 
 	cpuhp_remove_state(rdt_online);
 
-	rdtgroup_exit();
+	resctrl_exit();
 
 	if (r->mon_capable)
 		rdt_put_mon_l3_config();
 }
 
-__exitcall(resctrl_exit);
+__exitcall(resctrl_arch_exit);
arch/x86/kernel/cpu/resctrl/internal.h +0 -3
index 9048bd32e86f..7c073298aabf 100644
@@ -300,9 +300,6 @@ extern struct list_head rdt_all_groups;
 
 extern int max_name_width, max_data_width;
 
-int __init rdtgroup_init(void);
-void __exit rdtgroup_exit(void);
-
 /**
  * struct rftype - describe each file in the resctrl file system
  * @name:	File name
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -4
index 18f097fce51e..1a49c9918f8d 100644
@@ -4116,14 +4116,14 @@ void resctrl_offline_cpu(unsigned int cpu)
 }
 
 /*
- * rdtgroup_init - rdtgroup initialization
+ * resctrl_init - resctrl filesystem initialization
  *
  * Setup resctrl file system including set up root, create mount point,
- * register rdtgroup filesystem, and initialize files under root directory.
+ * register resctrl filesystem, and initialize files under root directory.
  *
  * Return: 0 on success or -errno
  */
-int __init rdtgroup_init(void)
+int __init resctrl_init(void)
 {
 	int ret = 0;
 
@@ -4171,7 +4171,7 @@ int __init rdtgroup_init(void)
 	return ret;
 }
 
-void __exit rdtgroup_exit(void)
+void __exit resctrl_exit(void)
 {
 	debugfs_remove_recursive(debugfs_resctrl);
 	unregister_filesystem(&rdt_fs_type);
include/linux/resctrl.h +3 -0
index 2b79e4159507..f6a4b75f8122 100644
@@ -325,4 +325,7 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain *d);
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 
+int __init resctrl_init(void);
+void __exit resctrl_exit(void);
+
 #endif /* _RESCTRL_H */
Signature · 1 line
2.39.2
#48 lore raw

RE: [PATCH v1 06/31] x86/resctrl: Export resctrl fs's init function

Hello James,

Quoted 7 lines

rdtgroup_init() needs exporting so that arch code can call it once it lives in core code. As this is one of the few functions we export, rename it to have the resctrl in the name. The same goes for the exit call.

x86's arch code init functions for RDT are renamed to have an arch prefix to make it clear these are part of the architecture code.

Quoted 7 lines
---
 arch/x86/kernel/cpu/resctrl/core.c     | 12 ++++++------
 arch/x86/kernel/cpu/resctrl/internal.h |  3 ---
arch/x86/kernel/cpu/resctrl/rdtgroup.c |  8 ++++----
 include/linux/resctrl.h                |  3 +++
 4 files changed, 13 insertions(+), 13 deletions(-)

./fs/resctrl/monitor.c

746          * RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID are special and
747          * are always allocated. These are used for the rdtgroup_default
748          * control group, which will be setup later in rdtgroup_init(). 

"rdtgroup_init()" is still in the comments.

Best regards,
Shaopeng TAN

Quoted 107 lines
arch/x86/kernel/cpu/resctrl/core.c +6 -6
index d07eff7d6750..b4e7d655e242 100644
@@ -938,7 +938,7 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
 	}
 }
 
-static int __init resctrl_late_init(void)
+static int __init resctrl_arch_late_init(void)
 {
 	struct rdt_resource *r;
 	int state, ret;
@@ -963,7 +963,7 @@ static int __init resctrl_late_init(void)
 	if (state < 0)
 		return state;
 
-	ret = rdtgroup_init();
+	ret = resctrl_init();
 	if (ret) {
 		cpuhp_remove_state(state);
 		return ret;
@@ -979,18 +979,18 @@ static int __init resctrl_late_init(void)
 	return 0;
 }
 
-late_initcall(resctrl_late_init);
+late_initcall(resctrl_arch_late_init);
 
-static void __exit resctrl_exit(void)
+static void __exit resctrl_arch_exit(void)
 {
 	struct rdt_resource *r =
 &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
 
 	cpuhp_remove_state(rdt_online);
 
-	rdtgroup_exit();
+	resctrl_exit();
 
 	if (r->mon_capable)
 		rdt_put_mon_l3_config();
 }
 
-__exitcall(resctrl_exit);
+__exitcall(resctrl_arch_exit);
arch/x86/kernel/cpu/resctrl/internal.h +0 -3
index 9048bd32e86f..7c073298aabf 100644
@@ -300,9 +300,6 @@ extern struct list_head rdt_all_groups;
 
 extern int max_name_width, max_data_width;
 
-int __init rdtgroup_init(void);
-void __exit rdtgroup_exit(void);
-
 /**
  * struct rftype - describe each file in the resctrl file system
  * @name:	File name
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -4
index 18f097fce51e..1a49c9918f8d 100644
@@ -4116,14 +4116,14 @@ void resctrl_offline_cpu(unsigned int cpu)  }
 
 /*
- * rdtgroup_init - rdtgroup initialization
+ * resctrl_init - resctrl filesystem initialization
  *
  * Setup resctrl file system including set up root, create mount point,
- * register rdtgroup filesystem, and initialize files under root directory.
+ * register resctrl filesystem, and initialize files under root directory.
  *
  * Return: 0 on success or -errno
  */
-int __init rdtgroup_init(void)
+int __init resctrl_init(void)
 {
 	int ret = 0;
 
@@ -4171,7 +4171,7 @@ int __init rdtgroup_init(void)
 	return ret;
 }
 
-void __exit rdtgroup_exit(void)
+void __exit resctrl_exit(void)
 {
 	debugfs_remove_recursive(debugfs_resctrl);
 	unregister_filesystem(&rdt_fs_type);
include/linux/resctrl.h index renamed from include/linux/resctrl.h +0 -0

2b79e4159507..f6a4b75f8122 100644

include/linux/resctrl.h +3 -1
@@ -325,4 +325,7 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r,
 struct rdt_domain *d);  extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 
+int __init resctrl_init(void);
+void __exit resctrl_exit(void);
+
 #endif /* _RESCTRL_H */
--

2.39.2

reviewer
#49 lore raw

Re: [PATCH v1 06/31] x86/resctrl: Export resctrl fs's init function

Quoted 18 lines · Shaopeng Tan (Fujitsu)

Hello James,

Quoted 7 lines

rdtgroup_init() needs exporting so that arch code can call it once it lives in core code. As this is one of the few functions we export, rename it to have the resctrl in the name. The same goes for the exit call.

x86's arch code init functions for RDT are renamed to have an arch prefix to make it clear these are part of the architecture code.

Quoted 7 lines
---
 arch/x86/kernel/cpu/resctrl/core.c     | 12 ++++++------
 arch/x86/kernel/cpu/resctrl/internal.h |  3 ---
arch/x86/kernel/cpu/resctrl/rdtgroup.c |  8 ++++----
 include/linux/resctrl.h                |  3 +++
 4 files changed, 13 insertions(+), 13 deletions(-)

/fs/resctrl/monitor.c

Quoted 9 lines
746          * RESCTRL_RESERVED_CLOSID and RESCTRL_RESERVED_RMID are special and
747          * are always allocated. These are used for the rdtgroup_default
748          * control group, which will be setup later in rdtgroup_init(). 

"rdtgroup_init()" is still in the comments.

Best regards,
Shaopeng TAN

[...]

Noted for James' attention, thanks.

Cheers
---Dave

maintainer
#50 lore raw

Re: [PATCH v1 06/31] x86/resctrl: Export resctrl fs's init function

In reply to James Morse

Hi James,

Quoted 2 lines · James Morse

rdtgroup_init() needs exporting so that arch code can call it once it lives in core code. As this is one of the few functions we export,

Please do not impersonate code.

Quoted 1 line

rename it to have the resctrl in the name. The same goes for the exit

"to have the resctrl" -> "to have resctrl"

Quoted 7 lines

call.

x86's arch code init functions for RDT are renamed to have an arch prefix to make it clear these are part of the architecture code.

---

Reinette

reviewer
#51 lore raw

Re: [PATCH v1 06/31] x86/resctrl: Export resctrl fs's init function

Quoted 7 lines · Reinette Chatre

Hi James,

Quoted 2 lines · James Morse

rdtgroup_init() needs exporting so that arch code can call it once it lives in core code. As this is one of the few functions we export,

Please do not impersonate code.

Noted. Any objection to rewording this as follows?

"As this is one of the few functions exported from the resctrl common code, [...]"

Quoted 3 lines
Quoted 1 line

rename it to have the resctrl in the name. The same goes for the exit

"to have the resctrl" -> "to have resctrl"

Noted for James' attention.

[...]

Cheers
---Dave

maintainer
#52 lore raw

Re: [PATCH v1 06/31] x86/resctrl: Export resctrl fs's init function

Hi Dave,

Quoted 4 lines · Dave Martin
Quoted 3 lines · Reinette Chatre

Hi James,

On 3/21/2024 9:50 AM, James Morse wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

rdtgroup_init() needs exporting so that arch code can call it once it lives in core code. As this is one of the few functions we export,

Please do not impersonate code.

Noted. Any objection to rewording this as follows?

"As this is one of the few functions exported from the resctrl common code, [...]"

Sounds good. Thank you.

Reinette

author reviewer
#53 lore raw

PATCH 7/31 x86/resctrl: Wrap resctrl_arch_find_domain() around rdt_find_domain()

In reply to James Morse

rdt_find_domain() finds a domain given a resource and a cache-id. It's not quite right for the resctrl arch API as it also returns the position to insert a new domain, which is needed when bringing a domain online in the arch code.

Wrap rdt_find_domain() in a another function resctrl_arch_find_domain() so we avoid the unnecessary argument outside the arch code.

---
 arch/x86/kernel/cpu/resctrl/core.c        | 9 +++++++--
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 2 --
 include/linux/resctrl.h                   | 2 ++
 4 files changed, 10 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +7 -2
index b4e7d655e242..06dc12b08afc 100644
@@ -405,8 +405,8 @@ void rdt_ctrl_update(void *arg)
  * caller, return the first domain whose id is bigger than the input id.
  * The domain list is sorted by id in ascending order.
  */
-struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
-				   struct list_head **pos)
+static struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
+					  struct list_head **pos)
 {
 	struct rdt_domain *d;
 	struct list_head *l;
@@ -430,6 +430,11 @@ struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
 	return NULL;
 }
 
+struct rdt_domain *resctrl_arch_find_domain(struct rdt_resource *r, int id)
+{
+	return rdt_find_domain(r, id, NULL);
+}
+
 static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +1 -1
index 72a651671c68..3603ade95f1d 100644
@@ -618,7 +618,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg)
 	evtid = md.u.evtid;
 
 	r = resctrl_arch_get_resource(resid);
-	d = rdt_find_domain(r, domid, NULL);
+	d = resctrl_arch_find_domain(r, domid);
 	if (IS_ERR_OR_NULL(d)) {
 		ret = -ENOENT;
 		goto out;
arch/x86/kernel/cpu/resctrl/internal.h +0 -2
index 7c073298aabf..32ade929ea1b 100644
@@ -533,8 +533,6 @@ 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);
-struct rdt_domain *rdt_find_domain(struct rdt_resource *r, int id,
-				   struct list_head **pos);
 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,
include/linux/resctrl.h +2 -0
index f6a4b75f8122..c5fcbb524136 100644
@@ -233,6 +233,8 @@ void resctrl_arch_sync_cpu_defaults(void *info);
 
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
+
+struct rdt_domain *resctrl_arch_find_domain(struct rdt_resource *r, int id);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 
 /*
Signature · 1 line
2.39.2
maintainer
#54 lore raw

Re: [PATCH v1 07/31] x86/resctrl: Wrap resctrl_arch_find_domain() around rdt_find_domain()

Hi James,

Quoted 6 lines · James Morse

rdt_find_domain() finds a domain given a resource and a cache-id. It's not quite right for the resctrl arch API as it also returns the position to insert a new domain, which is needed when bringing a domain online in the arch code.

Wrap rdt_find_domain() in a another function resctrl_arch_find_domain()

"in a another" -> "in another"

Quoted 1 line

so we avoid the unnecessary argument outside the arch code.

Please do not impersonate code.

Quoted 3 lines

---

Reinette

reviewer
#55 lore raw

Re: [PATCH v1 07/31] x86/resctrl: Wrap resctrl_arch_find_domain() around rdt_find_domain()

Quoted 11 lines · Reinette Chatre

Hi James,

Quoted 6 lines · James Morse

rdt_find_domain() finds a domain given a resource and a cache-id. It's not quite right for the resctrl arch API as it also returns the position to insert a new domain, which is needed when bringing a domain online in the arch code.

Wrap rdt_find_domain() in a another function resctrl_arch_find_domain()

"in a another" -> "in another"

Noted for James' attention.

Quoted 3 lines
Quoted 1 line

so we avoid the unnecessary argument outside the arch code.

Please do not impersonate code.

[...]

Quoted 1 line

Reinette

Noted.

Cheers
---Dave

author reviewer
#56 lore raw

PATCH 8/31 x86/resctrl: Move resctrl types to a separate header

In reply to James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

---
internal.h lacks a copyright notice so there is nothing to preserve when creating a new file...

---
 MAINTAINERS                            |  1 +
 arch/x86/kernel/cpu/resctrl/internal.h | 24 ---------
 include/linux/resctrl.h                | 35 +------------
 include/linux/resctrl_types.h          | 68 ++++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 58 deletions(-)
 create mode 100644 include/linux/resctrl_types.h
MAINTAINERS +1 -0
index 43b39956694a..5621dd823e79 100644
@@ -18543,6 +18543,7 @@ S:	Supported
 F:	Documentation/arch/x86/resctrl*
 F:	arch/x86/include/asm/resctrl.h
 F:	arch/x86/kernel/cpu/resctrl/
+F:	include/linux/resctrl*.h
 F:	tools/testing/selftests/resctrl/
 
 READ-COPY UPDATE (RCU)
arch/x86/kernel/cpu/resctrl/internal.h +0 -24
index 32ade929ea1b..031948322eab 100644
@@ -32,30 +32,6 @@
  */
 #define MBM_CNTR_WIDTH_OFFSET_MAX (62 - MBM_CNTR_WIDTH_BASE)
 
-/* Reads to Local DRAM Memory */
-#define READS_TO_LOCAL_MEM		BIT(0)
-
-/* Reads to Remote DRAM Memory */
-#define READS_TO_REMOTE_MEM		BIT(1)
-
-/* Non-Temporal Writes to Local Memory */
-#define NON_TEMP_WRITE_TO_LOCAL_MEM	BIT(2)
-
-/* Non-Temporal Writes to Remote Memory */
-#define NON_TEMP_WRITE_TO_REMOTE_MEM	BIT(3)
-
-/* Reads to Local Memory the system identifies as "Slow Memory" */
-#define READS_TO_LOCAL_S_MEM		BIT(4)
-
-/* Reads to Remote Memory the system identifies as "Slow Memory" */
-#define READS_TO_REMOTE_S_MEM		BIT(5)
-
-/* Dirty Victims to All Types of Memory */
-#define DIRTY_VICTIMS_TO_ALL_MEM	BIT(6)
-
-/* Max event bits supported */
-#define MAX_EVT_CONFIG_BITS		GENMASK(6, 0)
-
 /**
  * cpumask_any_housekeeping() - Choose any CPU in @mask, preferring those that
  *			        aren't marked nohz_full
include/linux/resctrl.h +1 -34
index c5fcbb524136..b0ee7256e095 100644
@@ -5,6 +5,7 @@
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/pid.h>
+#include <linux/resctrl_types.h>
 
 /* CLOSID, RMID value used by the default control group */
 #define RESCTRL_RESERVED_CLOSID		0
@@ -24,40 +25,6 @@ int proc_resctrl_show(struct seq_file *m,
 /* max value for struct rdt_domain's mbps_val */
 #define MBA_MAX_MBPS   U32_MAX
 
-/**
- * enum resctrl_conf_type - The type of configuration.
- * @CDP_NONE:	No prioritisation, both code and data are controlled or monitored.
- * @CDP_CODE:	Configuration applies to instruction fetches.
- * @CDP_DATA:	Configuration applies to reads and writes.
- */
-enum resctrl_conf_type {
-	CDP_NONE,
-	CDP_CODE,
-	CDP_DATA,
-};
-
-enum resctrl_res_level {
-	RDT_RESOURCE_L3,
-	RDT_RESOURCE_L2,
-	RDT_RESOURCE_MBA,
-	RDT_RESOURCE_SMBA,
-
-	/* Must be the last */
-	RDT_NUM_RESOURCES,
-};
-
-#define CDP_NUM_TYPES	(CDP_DATA + 1)
-
-/*
- * Event IDs, the values match those used to program IA32_QM_EVTSEL before
- * reading IA32_QM_CTR on RDT systems.
- */
-enum resctrl_event_id {
-	QOS_L3_OCCUP_EVENT_ID		= 0x01,
-	QOS_L3_MBM_TOTAL_EVENT_ID	= 0x02,
-	QOS_L3_MBM_LOCAL_EVENT_ID	= 0x03,
-};
-
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded
include/linux/resctrl_types.h new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer
#57 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Hi James,

Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Quoted 10 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

...

include/linux/resctrl_types.h line 5

Quoted 11 lines
include/linux/resctrl_types.h new file +5 -0
new file mode 100644
index 000000000000..4788bd95dac6
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Arm Ltd.
+ * Based on arch/x86/kernel/cpu/resctrl/internal.h
+ */

Could this header please explain how this file is intended to be used? What is it intended to contain?

Reinette

reviewer
#58 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Quoted 8 lines · Reinette Chatre

Hi James,

Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Maybe just delete the the sticky clause, and leave:

Move the resctrl enums into a separate header.

...since the next paragraph explains the rationale?

Quoted 28 lines
Quoted 10 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

..

include/linux/resctrl_types.h line 5

Quoted 11 lines
include/linux/resctrl_types.h new file +5 -0
new file mode 100644
index 000000000000..4788bd95dac6
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Arm Ltd.
+ * Based on arch/x86/kernel/cpu/resctrl/internal.h
+ */

Could this header please explain how this file is intended to be used? What is it intended to contain?

Quoted 1 line

Reinette

Maybe something like the following?

* Resctrl types and constants needed for inline function definitions in
* the arch-specific <asm/resctrl.h> headers.

(James might have had other things in mind, but this is what it looks like to me...)

Cheers
---Dave

maintainer
#59 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Hi Dave,

Quoted 5 lines · Dave Martin
Quoted 4 lines · Reinette Chatre
Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Quoted 8 lines
Quoted 2 lines

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Maybe just delete the the sticky clause, and leave:

Move the resctrl enums into a separate header.

...since the next paragraph explains the rationale?

In the x86 area changelogs start with a context paragraph to provide reader with foundation to parse the subsequent problem and solution statements (that are also expected to be in separate paragraphs in that order).

Quoted 27 lines
Quoted 27 lines
Quoted 9 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

..

include/linux/resctrl_types.h line 5

Quoted 11 lines
include/linux/resctrl_types.h new file +5 -0
new file mode 100644
index 000000000000..4788bd95dac6
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Arm Ltd.
+ * Based on arch/x86/kernel/cpu/resctrl/internal.h
+ */

Could this header please explain how this file is intended to be used? What is it intended to contain?

Quoted 7 lines
Quoted 1 line

Reinette

Maybe something like the following?

* Resctrl types and constants needed for inline function definitions in
* the arch-specific <asm/resctrl.h> headers.

ok.

Reinette

reviewer
#60 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Quoted 13 lines · Reinette Chatre

Hi Dave,

Quoted 10 lines · Dave Martin
Quoted 6 lines · Reinette Chatre
Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Maybe just delete the the sticky clause, and leave:

Quoted 8 lines
Quoted 3 lines

Move the resctrl enums into a separate header.

...since the next paragraph explains the rationale?

In the x86 area changelogs start with a context paragraph to provide reader with foundation to parse the subsequent problem and solution statements (that are also expected to be in separate paragraphs in that order).

Acknowledged; I was hoping to avoid a rewrite, but ...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

[...]

OK, how about the following:

--8<--

When resctrl is fully factored into core and per-arch code, each arch will need to use some resctrl common definitions in order to define its own specialisations and helpers. Following conventional practice, it would be desirable to put the dependent arch definitions in an <asm/resctrl.h> header that is included by the common <linux/resctrl.h> header. However, this can make it awkward to avoid a circular dependency between <linux/resctrl.h> and the arch header.

To avoid solving this issue via conditional inclusion tricks that are likely to be tricky to maintain, move the affected common types and constants into a new header that does not need to depend on <linux/resctrl.h> or on the arch headers.

The same logic applies to the monitor-configuration defines, move these too.

-->8--

Then:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

The last paragraph looks like it can stand as-is.

Does that look OK?

[...]

Quoted 19 lines
Quoted 19 lines
Quoted 15 lines

include/linux/resctrl_types.h line 5

Quoted 11 lines
include/linux/resctrl_types.h new file +5 -0
new file mode 100644
index 000000000000..4788bd95dac6
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Arm Ltd.
+ * Based on arch/x86/kernel/cpu/resctrl/internal.h
+ */

Could this header please explain how this file is intended to be used? What is it intended to contain?

Quoted 1 line

Reinette

Maybe something like the following?

Quoted 8 lines
Quoted 3 lines

* Resctrl types and constants needed for inline function definitions in
* the arch-specific <asm/resctrl.h> headers.

ok.

Reinette

OK, I'll propose to add that.

Cheers
---Dave

maintainer
#61 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Hi Dave,

Quoted 31 lines · Dave Martin
Quoted 13 lines · Reinette Chatre

Hi Dave,

Quoted 10 lines · Dave Martin
Quoted 6 lines · Reinette Chatre
Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Maybe just delete the the sticky clause, and leave:

Quoted 8 lines
Quoted 3 lines

Move the resctrl enums into a separate header.

...since the next paragraph explains the rationale?

In the x86 area changelogs start with a context paragraph to provide reader with foundation to parse the subsequent problem and solution statements (that are also expected to be in separate paragraphs in that order).

Acknowledged; I was hoping to avoid a rewrite, but ...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

[...]

Quoted 7 lines

OK, how about the following:

--8<--

When resctrl is fully factored into core and per-arch code, each arch will need to use some resctrl common definitions in order to define its own specialisations and helpers. Following conventional practice,

specializations

Quoted 7 lines

it would be desirable to put the dependent arch definitions in an <asm/resctrl.h> header that is included by the common <linux/resctrl.h> header. However, this can make it awkward to avoid a circular dependency between <linux/resctrl.h> and the arch header.

To avoid solving this issue via conditional inclusion tricks that are likely to be tricky to maintain, move the affected common types and

To help with motivation please be specific (somebody may interpret above that it may not be tricky to maintain). So just ... "that are difficult to maintain ...".

Quoted 8 lines

constants into a new header that does not need to depend on <linux/resctrl.h> or on the arch headers.

The same logic applies to the monitor-configuration defines, move these too.

-->8--

This explains the motivation for this file well, but its contents is not obvious to me and after reading [1] I am more weary of including code before use. Not all of these definitions are needed
by the end of this series so there needs to be a good motivation for making things global without any visible user.

I do understand that in the next stage of this work we may need to deal with potentially three subsystems when making changes and there is thus a strong motivation for laying a good foundation now. I do not think this should be an excuse to not be diligent in ensuring the changes are required.

Quoted 7 lines

Then:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

The last paragraph looks like it can stand as-is.

Does that look OK?

Yes.

Reinette

[1] https://lore.kernel.org/lkml/[email protected]/

reviewer
#62 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Quoted 36 lines · Reinette Chatre

Hi Dave,

Quoted 33 lines · Dave Martin
Quoted 13 lines · Reinette Chatre

Hi Dave,

Quoted 10 lines · Dave Martin
Quoted 6 lines · Reinette Chatre
Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Maybe just delete the the sticky clause, and leave:

Quoted 8 lines
Quoted 3 lines

Move the resctrl enums into a separate header.

...since the next paragraph explains the rationale?

In the x86 area changelogs start with a context paragraph to provide reader with foundation to parse the subsequent problem and solution statements (that are also expected to be in separate paragraphs in that order).

Acknowledged; I was hoping to avoid a rewrite, but ...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

[...]

OK, how about the following:

Quoted 7 lines
Quoted 5 lines

--8<--

When resctrl is fully factored into core and per-arch code, each arch will need to use some resctrl common definitions in order to define its own specialisations and helpers. Following conventional practice,

specializations

Debatable, but OK, fine.

Quoted 11 lines
Quoted 7 lines

it would be desirable to put the dependent arch definitions in an <asm/resctrl.h> header that is included by the common <linux/resctrl.h> header. However, this can make it awkward to avoid a circular dependency between <linux/resctrl.h> and the arch header.

To avoid solving this issue via conditional inclusion tricks that are likely to be tricky to maintain, move the affected common types and

To help with motivation please be specific (somebody may interpret above that it may not be tricky to maintain). So just ... "that are difficult to maintain ...".

Rather than the text encouraging questions about whether there are reasonable alternative approaches, perhaps this can just be, simply:

"To avoid such dependencies, move the affected types into a new header [...]"

?

Quoted 7 lines
Quoted 7 lines

constants into a new header that does not need to depend on <linux/resctrl.h> or on the arch headers.

The same logic applies to the monitor-configuration defines, move these too.

Quoted 8 lines
Quoted 2 lines

-->8--

This explains the motivation for this file well, but its contents is not obvious to me and after reading [1] I am more weary of including code before use. Not all of these definitions are needed
by the end of this series so there needs to be a good motivation for making things global without any visible user.

That's fair. I guess we need to review the contents of this header and make sure that everything that's here really should be here.

However, this is not user ABI and there are only 1.5 users of this interface (given that MPAM is not yet merged). So, the penalty for not getting this quite right and fixing it later seems low.

If you agree that adding this header is appropriate, are you OK with some post-merge cleanup, or do you think it's essential to sanitise this fully up-front?

Quoted 18 lines

I do understand that in the next stage of this work we may need to deal with potentially three subsystems when making changes and there is thus a strong motivation for laying a good foundation now. I do not think this should be an excuse to not be diligent in ensuring the changes are required.

Quoted 11 lines

Then:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The maintainers entry for these headers was missed when resctrl.h was created. Add a wildcard entry to match both resctrl.h and resctrl_types.h.

The last paragraph looks like it can stand as-is.

Quoted 8 lines
Quoted 1 line

Does that look OK?

Yes.

Reinette

[1] https://lore.kernel.org/lkml/[email protected]/

Cheers
---Dave

maintainer
#63 lore raw

Re: [PATCH v1 08/31] x86/resctrl: Move resctrl types to a separate header

Hi Dave,

Quoted 38 lines · Dave Martin
Quoted 37 lines · Reinette Chatre
Quoted 36 lines · Dave Martin
Quoted 13 lines · Reinette Chatre
Quoted 12 lines · Dave Martin
Quoted 7 lines · Reinette Chatre
Quoted 2 lines · James Morse

To avoid sticky problems in the mpam glue code, move the resctrl enums into a separate header.

Could you please elaborate so that "sticky problems in the mpam glue code" is specific about what problems are avoided?

Maybe just delete the the sticky clause, and leave:

Quoted 8 lines
Quoted 3 lines

Move the resctrl enums into a separate header.

...since the next paragraph explains the rationale?

In the x86 area changelogs start with a context paragraph to provide reader with foundation to parse the subsequent problem and solution statements (that are also expected to be in separate paragraphs in that order).

Acknowledged; I was hoping to avoid a rewrite, but ...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

This lets the arch code declare prototypes that use these enums without creating a loop via asm<->linux resctrl.h The same logic applies to the monitor-configuration defines, move these too.

[...]

OK, how about the following:

--8<--

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

When resctrl is fully factored into core and per-arch code, each arch will need to use some resctrl common definitions in order to define its own specialisations and helpers. Following conventional practice,

specializations

Debatable, but OK, fine.

ah British spelling, apologies.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

it would be desirable to put the dependent arch definitions in an <asm/resctrl.h> header that is included by the common <linux/resctrl.h> header. However, this can make it awkward to avoid a circular dependency between <linux/resctrl.h> and the arch header.

Quoted 7 lines
Quoted 3 lines

To avoid solving this issue via conditional inclusion tricks that are likely to be tricky to maintain, move the affected common types and

To help with motivation please be specific (somebody may interpret above that it may not be tricky to maintain). So just ... "that are difficult to maintain ...".

Quoted 7 lines

Rather than the text encouraging questions about whether there are reasonable alternative approaches, perhaps this can just be, simply:

"To avoid such dependencies, move the affected types into a new header [...]"

?

Sure.

Quoted 20 lines
Quoted 8 lines
Quoted 8 lines

constants into a new header that does not need to depend on <linux/resctrl.h> or on the arch headers.

The same logic applies to the monitor-configuration defines, move these too.

Quoted 8 lines
Quoted 2 lines

-->8--

This explains the motivation for this file well, but its contents is not obvious to me and after reading [1] I am more weary of including code before use. Not all of these definitions are needed by the end of this series so there needs to be a good motivation for making things global without any visible user.

That's fair. I guess we need to review the contents of this header and make sure that everything that's here really should be here.

Quoted 8 lines

However, this is not user ABI and there are only 1.5 users of this interface (given that MPAM is not yet merged). So, the penalty for not getting this quite right and fixing it later seems low.

If you agree that adding this header is appropriate, are you OK with some post-merge cleanup, or do you think it's essential to sanitise this fully up-front?

I think you may have sent this before your response to patch #17 where you are talking about keeping some definitions x86 specific until their usage is clear.

I understand this is not user ABI and as I also stated previously I recognize that these changes are easier now than later when changes need to cross two subsystems. I do not think the goal should be to have the perfect header file but I would like to understand why each definition in it needs to be global.

Unfortunately, based on learnings during the four year history of this work, I do not have confidence that there will be post-merge cleanup.

Reinette

author reviewer
#64 lore raw

PATCH 9/31 x86/resctrl: Add a resctrl helper to reset all the resources

In reply to James Morse

On umount(), resctrl resets each resource back to its default configuration. It only ever does this for all resources in one go.

reset_all_ctrls() is architecture specific as it works with struct rdt_hw_resource.

Add an architecture helper to reset all resources.

---
 arch/x86/include/asm/resctrl.h         |  2 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
arch/x86/include/asm/resctrl.h +2 -0
index f61382258743..5f6a5375bb4a 100644
@@ -15,6 +15,8 @@
  */
 #define X86_RESCTRL_EMPTY_CLOSID         ((u32)~0)
 
+void resctrl_arch_reset_resources(void);
+
 /**
  * struct resctrl_pqr_state - State cache for the PQR MSR
  * @cur_rmid:		The cached Resource Monitoring ID
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11 -5
index 1a49c9918f8d..13c24cb18d76 100644
@@ -2859,6 +2859,14 @@ static int reset_all_ctrls(struct rdt_resource *r)
 	return 0;
 }
 
+void resctrl_arch_reset_resources(void)
+{
+	struct rdt_resource *r;
+
+	for_each_capable_rdt_resource(r)
+		reset_all_ctrls(r);
+}
+
 /*
  * Move tasks from one to the other group. If @from is NULL, then all tasks
  * in the systems are moved unconditionally (used for teardown).
@@ -2968,16 +2976,14 @@ static void rmdir_all_sub(void)
 
 static void rdt_kill_sb(struct super_block *sb)
 {
-	struct rdt_resource *r;
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_disable_ctx();
 
-	/*Put everything back to default values. */
-	for_each_alloc_capable_rdt_resource(r)
-		reset_all_ctrls(r);
+	/* Put everything back to default values. */
+	resctrl_arch_reset_resources();
+
 	rmdir_all_sub();
 	rdt_pseudo_lock_release();
 	rdtgroup_default.mode = RDT_MODE_SHAREABLE;
Signature · 1 line
2.39.2
#65 lore raw

RE: [PATCH v1 09/31] x86/resctrl: Add a resctrl helper to reset all the resources

Hello James,

Quoted 33 lines

On umount(), resctrl resets each resource back to its default configuration. It only ever does this for all resources in one go.

reset_all_ctrls() is architecture specific as it works with struct rdt_hw_resource.

Add an architecture helper to reset all resources.

---
 arch/x86/include/asm/resctrl.h         |  2 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
arch/x86/include/asm/resctrl.h +2 -0
index f61382258743..5f6a5375bb4a 100644
@@ -15,6 +15,8 @@
  */
 #define X86_RESCTRL_EMPTY_CLOSID         ((u32)~0)
 
+void resctrl_arch_reset_resources(void);
+
 /**
  * struct resctrl_pqr_state - State cache for the PQR MSR
  * @cur_rmid:		The cached Resource Monitoring ID
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 1a49c9918f8d..13c24cb18d76 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int reset_all_ctrls(struct rdt_resource *r) · line 2866

Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -0
@@ -2859,6 +2859,14 @@ static int reset_all_ctrls(struct rdt_resource *r)
 	return 0;
 }
 
+void resctrl_arch_reset_resources(void)
+{
+	struct rdt_resource *r;
+
+	for_each_capable_rdt_resource(r)

Could you explain why not "for_each_alloc_capable_rdt_resource(r)"?

Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
+		reset_all_ctrls(r);
+}
+
 /*
  * Move tasks from one to the other group. If @from is NULL, then all tasks
  * in the systems are moved unconditionally (used for teardown).
@@ -2968,16 +2976,14 @@ static void rmdir_all_sub(void)
 

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 2978

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -4
 static void rdt_kill_sb(struct super_block *sb)  {
-	struct rdt_resource *r;
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_disable_ctx();
 
-	/*Put everything back to default values. */
-	for_each_alloc_capable_rdt_resource(r)

This was "for_each_alloc_capable_rdt_resource(r)".

Best regards,
Shaopeng TAN

Quoted 9 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -2
-		reset_all_ctrls(r);
+	/* Put everything back to default values. */
+	resctrl_arch_reset_resources();
+
 	rmdir_all_sub();
 	rdt_pseudo_lock_release();
 	rdtgroup_default.mode = RDT_MODE_SHAREABLE;
--

2.39.2

reviewer
#66 lore raw

Re: [PATCH v1 09/31] x86/resctrl: Add a resctrl helper to reset all the resources

Quoted 59 lines · Shaopeng Tan (Fujitsu)

Hello James,

Quoted 33 lines

On umount(), resctrl resets each resource back to its default configuration. It only ever does this for all resources in one go.

reset_all_ctrls() is architecture specific as it works with struct rdt_hw_resource.

Add an architecture helper to reset all resources.

---
 arch/x86/include/asm/resctrl.h         |  2 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)
arch/x86/include/asm/resctrl.h +2 -0
index f61382258743..5f6a5375bb4a 100644
@@ -15,6 +15,8 @@
  */
 #define X86_RESCTRL_EMPTY_CLOSID         ((u32)~0)
 
+void resctrl_arch_reset_resources(void);
+
 /**
  * struct resctrl_pqr_state - State cache for the PQR MSR
  * @cur_rmid:		The cached Resource Monitoring ID
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 1a49c9918f8d..13c24cb18d76 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int reset_all_ctrls(struct rdt_resource *r) · line 2866

Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -0
@@ -2859,6 +2859,14 @@ static int reset_all_ctrls(struct rdt_resource *r)
 	return 0;
 }
 
+void resctrl_arch_reset_resources(void)
+{
+	struct rdt_resource *r;
+
+	for_each_capable_rdt_resource(r)

Could you explain why not "for_each_alloc_capable_rdt_resource(r)"?

Quoted 14 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -2
+		reset_all_ctrls(r);
+}
+
 /*
  * Move tasks from one to the other group. If @from is NULL, then all tasks
  * in the systems are moved unconditionally (used for teardown).
@@ -2968,16 +2976,14 @@ static void rmdir_all_sub(void)
 
 static void rdt_kill_sb(struct super_block *sb)  {
-	struct rdt_resource *r;
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
Quoted 8 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static void rmdir_all_sub(void) · line 2979

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -2
 	rdt_disable_ctx();
 
-	/*Put everything back to default values. */
-	for_each_alloc_capable_rdt_resource(r)

This was "for_each_alloc_capable_rdt_resource(r)".

Best regards,
Shaopeng TAN

Noted for James to take a look at, thanks.

If this was intentional, it probably needs more explanation -- it looks quite likely to have been unintentional, though.

Cheers
---Dave

author reviewer
#67 lore raw

PATCH 10/31 x86/resctrl: Move monitor init work to a resctrl init call

In reply to James Morse

rdt_get_mon_l3_config() is called from the architecture's resctrl_arch_late_init(), and initialises both architecture specific fields, such as hw_res->mon_scale and resctrl filesystem fields by calling dom_data_init().

To separate the filesystem and architecture parts of resctrl, this function needs splitting up.

Add resctrl_mon_resource_init() to do the filesystem specific work, and call it from resctrl_init(). This runs later, but is still before the filesystem is mounted and the rmid_ptrs[] array can be used.

---
 arch/x86/kernel/cpu/resctrl/internal.h |  1 +
 arch/x86/kernel/cpu/resctrl/monitor.c  | 24 +++++++++++++++++-------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  4 ++++
 3 files changed, 22 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
index 031948322eab..7a0c74779c53 100644
@@ -540,6 +540,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg);
 void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
 		    struct rdt_domain *d, struct rdtgroup *rdtgrp,
 		    int evtid, int first);
+int resctrl_mon_resource_init(void);
 void mbm_setup_overflow_handler(struct rdt_domain *dom,
 				unsigned long delay_ms,
 				int exclude_cpu);
arch/x86/kernel/cpu/resctrl/monitor.c +17 -7
index 06565153ceb2..929ec1430b45 100644
@@ -1003,12 +1003,28 @@ static void l3_mon_evt_init(struct rdt_resource *r)
 		list_add_tail(&mbm_local_event.list, &r->evt_list);
 }
 
+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);
+
+	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;
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	unsigned int threshold;
-	int ret;
 
 	resctrl_rmid_realloc_limit = boot_cpu_data.x86_cache_size * 1024;
 	hw_res->mon_scale = boot_cpu_data.x86_cache_occ_scale;
@@ -1036,10 +1052,6 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	 */
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(threshold);
 
-	ret = dom_data_init(r);
-	if (ret)
-		return ret;
-
 	if (rdt_cpu_has(X86_FEATURE_BMEC)) {
 		u32 eax, ebx, ecx, edx;
 
@@ -1057,8 +1069,6 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 		}
 	}
 
-	l3_mon_evt_init(r);
-
 	r->mon_capable = true;
 
 	return 0;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -0
index 13c24cb18d76..7a9696f53f2b 100644
@@ -4138,6 +4138,10 @@ int __init resctrl_init(void)
 
 	rdtgroup_setup_default();
 
+	ret = resctrl_mon_resource_init();
+	if (ret)
+		return ret;
+
 	ret = sysfs_create_mount_point(fs_kobj, "resctrl");
 	if (ret)
 		return ret;
Signature · 1 line
2.39.2
maintainer
#68 lore raw

Re: [PATCH v1 10/31] x86/resctrl: Move monitor init work to a resctrl init call

Hi James,

On 3/21/2024 9:50 AM, James Morse wrote:

...

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index 13c24cb18d76..7a9696f53f2b 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c int __init resctrl_init(void) · line 4147

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -0
@@ -4138,6 +4138,10 @@ int __init resctrl_init(void)
 
 	rdtgroup_setup_default();
 
+	ret = resctrl_mon_resource_init();
+	if (ret)
+		return ret;
+
 	ret = sysfs_create_mount_point(fs_kobj, "resctrl");
 	if (ret)
 		return ret;

Should the mon data be cleaned up if sysfs_create_mount_point() fails?

Reinette

#69 lore raw

Re: [PATCH v1 10/31] x86/resctrl: Move monitor init work to a resctrl init call

In reply to James Morse

Hi James,

Quoted 46 lines · James Morse

rdt_get_mon_l3_config() is called from the architecture's resctrl_arch_late_init(), and initialises both architecture specific fields, such as hw_res->mon_scale and resctrl filesystem fields by calling dom_data_init().

To separate the filesystem and architecture parts of resctrl, this function needs splitting up.

Add resctrl_mon_resource_init() to do the filesystem specific work, and call it from resctrl_init(). This runs later, but is still before the filesystem is mounted and the rmid_ptrs[] array can be used.

---
  arch/x86/kernel/cpu/resctrl/internal.h |  1 +
  arch/x86/kernel/cpu/resctrl/monitor.c  | 24 +++++++++++++++++-------
  arch/x86/kernel/cpu/resctrl/rdtgroup.c |  4 ++++
  3 files changed, 22 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
index 031948322eab..7a0c74779c53 100644
@@ -540,6 +540,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg);
  void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
  		    struct rdt_domain *d, struct rdtgroup *rdtgrp,
  		    int evtid, int first);
+int resctrl_mon_resource_init(void);
  void mbm_setup_overflow_handler(struct rdt_domain *dom,
  				unsigned long delay_ms,
  				int exclude_cpu);
arch/x86/kernel/cpu/resctrl/monitor.c +7 -0
index 06565153ceb2..929ec1430b45 100644
@@ -1003,12 +1003,28 @@ static void l3_mon_evt_init(struct rdt_resource *r)
  		list_add_tail(&mbm_local_event.list, &r->evt_list);
  }
 
+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;

arch/x86/kernel/cpu/resctrl/monitor.c static void l3_mon_evt_init(struct rdt_resource *r) · line 1022

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10 -0
+
+	ret = dom_data_init(r);
+	if (ret)
+		return ret;
+
+	l3_mon_evt_init(r);
+
+	return 0;
+}
+

Now x86 platform defaults to all monitoring features on the L3 cache, but some monitoring features may also be on the L2 cache or memory controller according to the MPAM spec. For example, the memory bandwidth monitors could be on the memory controller.

Will resctrl_mon_resource_init() consider this scenario?

Best Regards,
Shawn

reviewer
#70 lore raw

Re: [PATCH v1 10/31] x86/resctrl: Move monitor init work to a resctrl init call

Quoted 61 lines · Shawn Wang

Hi James,

Quoted 45 lines · James Morse

rdt_get_mon_l3_config() is called from the architecture's resctrl_arch_late_init(), and initialises both architecture specific fields, such as hw_res->mon_scale and resctrl filesystem fields by calling dom_data_init().

To separate the filesystem and architecture parts of resctrl, this function needs splitting up.

Add resctrl_mon_resource_init() to do the filesystem specific work, and call it from resctrl_init(). This runs later, but is still before the filesystem is mounted and the rmid_ptrs[] array can be used.

---
  arch/x86/kernel/cpu/resctrl/internal.h |  1 +
  arch/x86/kernel/cpu/resctrl/monitor.c  | 24 +++++++++++++++++-------
  arch/x86/kernel/cpu/resctrl/rdtgroup.c |  4 ++++
  3 files changed, 22 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -0
index 031948322eab..7a0c74779c53 100644
@@ -540,6 +540,7 @@ int rdtgroup_mondata_show(struct seq_file *m, void *arg);
  void mon_event_read(struct rmid_read *rr, struct rdt_resource *r,
  		    struct rdt_domain *d, struct rdtgroup *rdtgrp,
  		    int evtid, int first);
+int resctrl_mon_resource_init(void);
  void mbm_setup_overflow_handler(struct rdt_domain *dom,
  				unsigned long delay_ms,
  				int exclude_cpu);
arch/x86/kernel/cpu/resctrl/monitor.c +7 -0
index 06565153ceb2..929ec1430b45 100644
@@ -1003,12 +1003,28 @@ static void l3_mon_evt_init(struct rdt_resource *r)
  		list_add_tail(&mbm_local_event.list, &r->evt_list);
  }
+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;

arch/x86/kernel/cpu/resctrl/monitor.c static void l3_mon_evt_init(struct rdt_resource *r) · line 1021

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/monitor.c +10 -0
+
+	ret = dom_data_init(r);
+	if (ret)
+		return ret;
+
+	l3_mon_evt_init(r);
+
+	return 0;
+}
+

Now x86 platform defaults to all monitoring features on the L3 cache, but some monitoring features may also be on the L2 cache or memory controller according to the MPAM spec. For example, the memory bandwidth monitors could be on the memory controller.

Quoted 4 lines

Will resctrl_mon_resource_init() consider this scenario?

Best Regards,
Shawn

My understanding is limited here, so this will probably have to wait until James gets back for a full answer.

The resctrl userspace filesystem interface looks like it can describe monitors at multiple levels of the memory system, so my assumption would be that it should be possible to wire it up.

This series focuses on refactoring and does not try to add new functionality, though.

Cheers
---Dave

author reviewer
#71 lore raw

Re: [PATCH v1 10/31] x86/resctrl: Move monitor init work to a resctrl init call

In reply to Shawn Wang

Hi Shawn,

Quoted 14 lines · Shawn Wang
Quoted 11 lines · James Morse

rdt_get_mon_l3_config() is called from the architecture's resctrl_arch_late_init(), and initialises both architecture specific fields, such as hw_res->mon_scale and resctrl filesystem fields by calling dom_data_init().

To separate the filesystem and architecture parts of resctrl, this function needs splitting up.

Add resctrl_mon_resource_init() to do the filesystem specific work, and call it from resctrl_init(). This runs later, but is still before the filesystem is mounted and the rmid_ptrs[] array can be used.

Quoted 5 lines

Now x86 platform defaults to all monitoring features on the L3 cache, but some monitoring features may also be on the L2 cache or memory controller according to the MPAM spec. For example, the memory bandwidth monitors could be on the memory controller.

Will resctrl_mon_resource_init() consider this scenario?

Nope.

The aim here is to get existing user-space software working on machines with MPAM. You can build an MPAM machine with monitors on the L1, L2 and L5 - but resctrl can't expose them, and there is no existing software that makes use of them.

The result is the MPAM driver plays fast and loose with some of this stuff to try and slot the machine into a Xeon shaped hole.

I'd like to support this in the future, but it will need user visible filesystem changes - its not worth discussing now.
I strongly suspect that declaring all monitors platform-specific, and plumbing them out via perf is the best thing for everyone...

Thanks,

James

author reviewer
#72 lore raw

PATCH 11/31 x86/resctrl: Move monitor exit work to a restrl exit call

In reply to James Morse

rdt_put_mon_l3_config() is called via the architecture's resctrl_arch_exit() call, and appears to free the rmid_ptrs[] and closid_num_dirty_rmid[] arrays. In reality this code is marked __exit, and is removed by the linker as resctl can't be built as a module.

MPAM can make use of this code from its error interrupt handler, a later patch drops all the __init/__exit annotations.

To separate the filesystem and architecture parts of resctrl, this free()ing work needs to be triggered by the filesystem, as these structures belong to the filesystem code.

Rename rdt_put_mon_l3_config() resctrl_mon_resource_exit() and call it from resctrl_exit(). The kfree() is currently dependent on r->mon_capable. resctrl_mon_resource_init() takes no arguments, so resctrl_mon_resource_exit() shouldn't take any either. Add the check to dom_data_exit(), making it take the resource as an argument. This makes it more symmetrical with dom_data_init().

---
 arch/x86/kernel/cpu/resctrl/core.c     |  5 -----
 arch/x86/kernel/cpu/resctrl/internal.h |  2 +-
 arch/x86/kernel/cpu/resctrl/monitor.c  | 12 ++++++++----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  2 ++
 4 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +0 -5
index 06dc12b08afc..9a09a64bbb7f 100644
@@ -988,14 +988,9 @@ late_initcall(resctrl_arch_late_init);
 
 static void __exit resctrl_arch_exit(void)
 {
-	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
-
 	cpuhp_remove_state(rdt_online);
 
 	resctrl_exit();
-
-	if (r->mon_capable)
-		rdt_put_mon_l3_config();
 }
 
 __exitcall(resctrl_arch_exit);
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
index 7a0c74779c53..01fcd4ef26ca 100644
@@ -533,7 +533,7 @@ 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 __exit rdt_put_mon_l3_config(void);
+void __exit resctrl_mon_resource_exit(void);
 bool __init rdt_cpu_has(int flag);
 void mon_event_count(void *info);
 int rdtgroup_mondata_show(struct seq_file *m, void *arg);
arch/x86/kernel/cpu/resctrl/monitor.c +8 -4
index 929ec1430b45..2a1cbd4de6ee 100644
@@ -954,10 +954,12 @@ static int dom_data_init(struct rdt_resource *r)
 	return err;
 }
 
-static void __exit dom_data_exit(void)
+static void __exit dom_data_exit(struct rdt_resource *r)
 {
-	mutex_lock(&rdtgroup_mutex);
+	if (!r->mon_capable)
+		return;
 
+	mutex_lock(&rdtgroup_mutex);
 	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID)) {
 		kfree(closid_num_dirty_rmid);
 		closid_num_dirty_rmid = NULL;
@@ -1074,9 +1076,11 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	return 0;
 }
 
-void __exit rdt_put_mon_l3_config(void)
+void __exit resctrl_mon_resource_exit(void)
 {
-	dom_data_exit();
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+
+	dom_data_exit(r);
 }
 
 void __init intel_rdt_mbm_apply_quirk(void)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -0
index 7a9696f53f2b..6cf4ebe9c058 100644
@@ -4186,4 +4186,6 @@ void __exit resctrl_exit(void)
 	debugfs_remove_recursive(debugfs_resctrl);
 	unregister_filesystem(&rdt_fs_type);
 	sysfs_remove_mount_point(fs_kobj, "resctrl");
+
+	resctrl_mon_resource_exit();
 }
Signature · 1 line
2.39.2
maintainer
#73 lore raw

Re: [PATCH v1 11/31] x86/resctrl: Move monitor exit work to a restrl exit call

Hi James,

Quoted 4 lines · James Morse

rdt_put_mon_l3_config() is called via the architecture's resctrl_arch_exit() call, and appears to free the rmid_ptrs[] and closid_num_dirty_rmid[] arrays. In reality this code is marked __exit, and is removed by the linker as resctl can't be built

resctl -> resctrl

Quoted 4 lines

as a module.

MPAM can make use of this code from its error interrupt handler, a later patch drops all the __init/__exit annotations.

Reminder:
https://lore.kernel.org/lkml/[email protected]/

Reinette

reviewer
#74 lore raw

Re: [PATCH v1 11/31] x86/resctrl: Move monitor exit work to a restrl exit call

Quoted 9 lines · Reinette Chatre

Hi James,

Quoted 4 lines · James Morse

rdt_put_mon_l3_config() is called via the architecture's resctrl_arch_exit() call, and appears to free the rmid_ptrs[] and closid_num_dirty_rmid[] arrays. In reality this code is marked __exit, and is removed by the linker as resctl can't be built

resctl -> resctrl

Noted, thanks (also, there is "restrl" in the subject line.)

Quoted 8 lines
Quoted 5 lines

as a module.

MPAM can make use of this code from its error interrupt handler, a later patch drops all the __init/__exit annotations.

Reminder:
https://lore.kernel.org/lkml/[email protected]/

The "Drop __init/__exit on assorted symbols" patch speaks for itself, I guess. I think it's probably sufficient for now to comfirm that this patch is deliberately not changing the annotations for now.

Does the following work?

--8<--

Since there is no immediate need to change them, leave the __exit annotations as-is. This will need to be revisited as and when there is a need to call these functions other than at __exit time.

-->8--

Cheers
---Dave

maintainer
#75 lore raw

Re: [PATCH v1 11/31] x86/resctrl: Move monitor exit work to a restrl exit call

Hi Dave,

Quoted 10 lines · Dave Martin
Quoted 7 lines · Reinette Chatre
Quoted 4 lines · James Morse

rdt_put_mon_l3_config() is called via the architecture's resctrl_arch_exit() call, and appears to free the rmid_ptrs[] and closid_num_dirty_rmid[] arrays. In reality this code is marked __exit, and is removed by the linker as resctl can't be built

resctl -> resctrl

Noted, thanks (also, there is "restrl" in the subject line.)

Thank you for catching that.

Quoted 16 lines
Quoted 9 lines
Quoted 6 lines

as a module.

MPAM can make use of this code from its error interrupt handler, a later patch drops all the __init/__exit annotations.

Reminder:
https://lore.kernel.org/lkml/[email protected]/

The "Drop __init/__exit on assorted symbols" patch speaks for itself, I guess. I think it's probably sufficient for now to comfirm that this patch is deliberately not changing the annotations for now.

Does the following work?

Quoted 7 lines

--8<--

Since there is no immediate need to change them, leave the __exit annotations as-is. This will need to be revisited as and when there is a need to call these functions other than at __exit time.

-->8--

Sounds good. I find a big focus on the __init/__exit annotations distracting. As I understand this has nothing to do with the goal of this patch, which is to move code from architecture side to filesystem side.

Reinette

author reviewer
#76 lore raw

PATCH 12/31 x86/resctrl: Move max_{name,data}_width into resctrl code

In reply to James Morse

max_name_width and max_data_width are used to pad the strings in the resctrl schemata file.

This should be part of the fs code as it influences the user-space interface, but currently max_data_width is generated by the arch init code. max_name_width is already managed by schemata_list_add().

Move the variables and max_data_width's initialisation code to rdtgroup.c. There is no need for an extra rdt_init_padding() helper as the length of the name can be considered when schemata_list_add() creates each schema entry.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 22 ----------------------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 ++++++++++++
 2 files changed, 12 insertions(+), 22 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +0 -22
index 9a09a64bbb7f..9551ca4a6480 100644
@@ -44,12 +44,6 @@ static DEFINE_MUTEX(domain_list_lock);
  */
 DEFINE_PER_CPU(struct resctrl_pqr_state, pqr_state);
 
-/*
- * Used to store the max resource name width and max resource data width
- * to display the schemata in a tabular format
- */
-int max_name_width, max_data_width;
-
 /*
  * Global boolean for rdt_alloc which is true if any
  * resource allocation is enabled.
@@ -648,20 +642,6 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)
 	return 0;
 }
 
-/*
- * Choose a width for the resource name and resource data based on the
- * resource that has widest name and cbm.
- */
-static __init void rdt_init_padding(void)
-{
-	struct rdt_resource *r;
-
-	for_each_alloc_capable_rdt_resource(r) {
-		if (r->data_width > max_data_width)
-			max_data_width = r->data_width;
-	}
-}
-
 enum {
 	RDT_FLAG_CMT,
 	RDT_FLAG_MBM_TOTAL,
@@ -959,8 +939,6 @@ static int __init resctrl_arch_late_init(void)
 	if (!get_rdt_resources())
 		return -ENODEV;
 
-	rdt_init_padding();
-
 	state = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				  "x86/resctrl/cat:online:",
 				  resctrl_arch_online_cpu,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +12 -0
index 6cf4ebe9c058..e736e4d20f63 100644
@@ -58,6 +58,12 @@ static struct kernfs_node *kn_mongrp;
 /* Kernel fs node for "mon_data" directory under root */
 static struct kernfs_node *kn_mondata;
 
+/*
+ * Used to store the max resource name width and max resource data width
+ * to display the schemata in a tabular format
+ */
+int max_name_width, max_data_width;
+
 static struct seq_buf last_cmd_status;
 static char last_cmd_status_buf[512];
 
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.
+	 */
+	max_data_width = max(max_data_width, r->data_width);
+
 	INIT_LIST_HEAD(&s->list);
 	list_add(&s->list, &resctrl_schema_all);
 
Signature · 1 line
2.39.2
maintainer
#77 lore raw

Re: [PATCH v1 12/31] x86/resctrl: Move max_{name,data}_width into resctrl code

Hi James,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2606

Quoted 7 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.

Please check series to ensure upper case is used for acronyms.

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2612

Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
+	 */
+	max_data_width = max(max_data_width, r->data_width);
+
 	INIT_LIST_HEAD(&s->list);
 	list_add(&s->list, &resctrl_schema_all);
 

Reinette

reviewer
#78 lore raw

Re: [PATCH v1 12/31] x86/resctrl: Move max_{name,data}_width into resctrl code

Quoted 12 lines · Reinette Chatre

Hi James,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2606

Quoted 7 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.

Please check series to ensure upper case is used for acronyms.

[...]

Quoted 1 line

Reinette

This patch is just moving existing code around AFAICT. See:
commit de016df88f23 ("x86/intel_rdt: Update schemata read to show data in tabular format")

Since no new usage of any term is being introduced here, can it be left as-is?

There seem to be other uses of "cbm" with this sense in the resctrl code already.

Cheers
---Dave

maintainer
#79 lore raw

Re: [PATCH v1 12/31] x86/resctrl: Move max_{name,data}_width into resctrl code

Hi Dave,

Quoted 18 lines · Dave Martin
Quoted 12 lines · Reinette Chatre

Hi James,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2606

Quoted 7 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.

Please check series to ensure upper case is used for acronyms.

[...]

Quoted 1 line

Reinette

Quoted 8 lines

This patch is just moving existing code around AFAICT. See:
commit de016df88f23 ("x86/intel_rdt: Update schemata read to show data in tabular format")

Since no new usage of any term is being introduced here, can it be left as-is?

There seem to be other uses of "cbm" with this sense in the resctrl code already.

I am not asking to change all existing usages of these terms but in any new changes, please use upper case for acronyms.

Reinette

reviewer
#80 lore raw

Re: [PATCH v1 12/31] x86/resctrl: Move max_{name,data}_width into resctrl code

Hi Reinette,

Quoted 24 lines · Reinette Chatre

Hi Dave,

Quoted 21 lines · Dave Martin
Quoted 12 lines · Reinette Chatre

Hi James,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2606

Quoted 7 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.

Please check series to ensure upper case is used for acronyms.

[...]

Quoted 1 line

Reinette

This patch is just moving existing code around AFAICT. See:
commit de016df88f23 ("x86/intel_rdt: Update schemata read to show data in tabular format")

Quoted 8 lines
Quoted 5 lines

Since no new usage of any term is being introduced here, can it be left as-is?

There seem to be other uses of "cbm" with this sense in the resctrl code already.

I am not asking to change all existing usages of these terms but in any new changes, please use upper case for acronyms.

While there is a general argument to be made here, it sounds from this like you are not requesting a change to this patch; can you confirm?

Cheers
---Dave

maintainer
#81 lore raw

Re: [PATCH v1 12/31] x86/resctrl: Move max_{name,data}_width into resctrl code

Hi Dave,

Quoted 26 lines · Dave Martin
Quoted 25 lines · Reinette Chatre
Quoted 24 lines · Dave Martin
Quoted 12 lines · Reinette Chatre

Hi James,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2606

Quoted 7 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.

Please check series to ensure upper case is used for acronyms.

[...]

Quoted 1 line

Reinette

This patch is just moving existing code around AFAICT. See:
commit de016df88f23 ("x86/intel_rdt: Update schemata read to show data in tabular format")

Since no new usage of any term is being introduced here, can it be left as-is?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

There seem to be other uses of "cbm" with this sense in the resctrl code already.

I am not asking to change all existing usages of these terms but in any new changes, please use upper case for acronyms.

While there is a general argument to be made here, it sounds from this like you are not requesting a change to this patch; can you confirm?

Sorry for confusion. I do think in a small change like this it is a good opportunity to make sure the style is clean. Since this changes the code anyway, it might as well ensure the style is clean. So, yes, could you please use CBM instead of cbm.

The final patch of this series is in a different category altogether and I do not think style changes will be appropriate in it.

Reinette

reviewer
#82 lore raw

Re: [PATCH v1 12/31] x86/resctrl: Move max_{name,data}_width into resctrl code

Quoted 35 lines · Reinette Chatre

Hi Dave,

Quoted 32 lines · Dave Martin
Quoted 30 lines · Reinette Chatre
Quoted 18 lines · Dave Martin
Quoted 12 lines · Reinette Chatre

Hi James,

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type · line 2606

Quoted 7 lines · James Morse
arch/x86/kernel/cpu/resctrl/rdtgroup.c +3 -0
@@ -2595,6 +2601,12 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 	if (cl > max_name_width)
 		max_name_width = cl;
 
+	/*
+	 * Choose a width for the resource data based on the resource that has
+	 * widest name and cbm.

Please check series to ensure upper case is used for acronyms.

[...]

Quoted 1 line

Reinette

Quoted 8 lines

This patch is just moving existing code around AFAICT. See:
commit de016df88f23 ("x86/intel_rdt: Update schemata read to show data in tabular format")

Since no new usage of any term is being introduced here, can it be left as-is?

There seem to be other uses of "cbm" with this sense in the resctrl code already.

I am not asking to change all existing usages of these terms but in any new changes, please use upper case for acronyms.

Quoted 7 lines
Quoted 2 lines

While there is a general argument to be made here, it sounds from this like you are not requesting a change to this patch; can you confirm?

Sorry for confusion. I do think in a small change like this it is a good opportunity to make sure the style is clean. Since this changes the code anyway, it might as well ensure the style is clean. So, yes, could you please use CBM instead of cbm.

OK; I had thought that we might be introducing a new inconsistency here by making such a change, but looking at upstream, "CBM" is prevalent in comments in the preexisting x86 code. I should have checked that before; apologies for the unnecessary back-and-forth on this.

So, sure, it makes sense to change it.

Noted.

Cheers
---Dave

author reviewer
#83 lore raw

PATCH 13/31 x86/resctrl: Stop using the for_each_*_rdt_resource() walkers

In reply to James Morse

The for_each_*_rdt_resource() helpers walk the architectures array of structures, using the resctrl visible part as an iterator. These became over-complex when the structures were split into a filesystem and architecture-specific struct. This approach avoided the need to touch every call site.

Once the filesystem parts of resctrl are moved to /fs/, both the architecture's resource array, and the definition of those structures is no longer accessible. To support resctrl, each architecture would have to provide equally complex macros.

Change the resctrl code that uses these to walk through the resource_level enum and check the mon/alloc capable flags instead. Instances in core.c, and resctrl_arch_reset_resources() remain part of x86's architecture specific code.

---
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |  7 +++++-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 30 +++++++++++++++++++----
 2 files changed, 31 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +6 -1
index 884b88e25141..f2315a50ea4f 100644
@@ -840,6 +840,7 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm
 bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
 {
 	cpumask_var_t cpu_with_psl;
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	struct rdt_domain *d_i;
 	bool ret = false;
@@ -854,7 +855,11 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
 	 * First determine which cpus have pseudo-locked regions
 	 * associated with them.
 	 */
-	for_each_alloc_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->alloc_capable)
+			continue;
+
 		list_for_each_entry(d_i, &r->domains, list) {
 			if (d_i->plr)
 				cpumask_or(cpu_with_psl, cpu_with_psl,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +25 -5
index e736e4d20f63..3f16e7854411 100644
@@ -98,12 +98,17 @@ void rdt_last_cmd_printf(const char *fmt, ...)
 
 void rdt_staged_configs_clear(void)
 {
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	struct rdt_domain *dom;
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	for_each_alloc_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->alloc_capable)
+			continue;
+
 		list_for_each_entry(dom, &r->domains, list)
 			memset(dom->staged_config, 0, sizeof(dom->staged_config));
 	}
@@ -2181,6 +2186,7 @@ static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
 
 static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 {
+	enum resctrl_res_level i;
 	struct resctrl_schema *s;
 	struct rdt_resource *r;
 	unsigned long fflags;
@@ -2205,8 +2211,12 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 			goto out_destroy;
 	}
 
-	for_each_mon_capable_rdt_resource(r) {
-		fflags = r->fflags | RFTYPE_MON_INFO;
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->mon_capable)
+			continue;
+
+		fflags =  r->fflags | RFTYPE_MON_INFO;
 		sprintf(name, "%s_MON", r->name);
 		ret = rdtgroup_mkdir_info_resdir(r, name, fflags);
 		if (ret)
@@ -2615,10 +2625,15 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 
 static int schemata_list_create(void)
 {
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	int ret = 0;
 
-	for_each_alloc_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->alloc_capable)
+			continue;
+
 		if (resctrl_arch_get_cdp_enabled(r->rid)) {
 			ret = schemata_list_add(r, CDP_CODE);
 			if (ret)
@@ -3166,6 +3181,7 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
 			     struct rdtgroup *prgrp,
 			     struct kernfs_node **dest_kn)
 {
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	struct kernfs_node *kn;
 	int ret;
@@ -3184,7 +3200,11 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
 	 * Create the subdirectories for each domain. Note that all events
 	 * in a domain like L3 are grouped into a resource whose domain is L3
 	 */
-	for_each_mon_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->mon_capable)
+			continue;
+
 		ret = mkdir_mondata_subdir_alldom(kn, r, prgrp);
 		if (ret)
 			goto out_destroy;
Signature · 1 line
2.39.2
maintainer
#84 lore raw

Re: [PATCH v1 13/31] x86/resctrl: Stop using the for_each_*_rdt_resource() walkers

Hi James,

Quoted 1 line · James Morse

The for_each_*_rdt_resource() helpers walk the architectures array

architecture's ?

Quoted 79 lines

of structures, using the resctrl visible part as an iterator. These became over-complex when the structures were split into a filesystem and architecture-specific struct. This approach avoided the need to touch every call site.

Once the filesystem parts of resctrl are moved to /fs/, both the architecture's resource array, and the definition of those structures is no longer accessible. To support resctrl, each architecture would have to provide equally complex macros.

Change the resctrl code that uses these to walk through the resource_level enum and check the mon/alloc capable flags instead. Instances in core.c, and resctrl_arch_reset_resources() remain part of x86's architecture specific code.

---
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |  7 +++++-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 30 +++++++++++++++++++----
 2 files changed, 31 insertions(+), 6 deletions(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +6 -1
index 884b88e25141..f2315a50ea4f 100644
@@ -840,6 +840,7 @@ bool rdtgroup_cbm_overlaps_pseudo_locked(struct rdt_domain *d, unsigned long cbm
 bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
 {
 	cpumask_var_t cpu_with_psl;
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	struct rdt_domain *d_i;
 	bool ret = false;
@@ -854,7 +855,11 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
 	 * First determine which cpus have pseudo-locked regions
 	 * associated with them.
 	 */
-	for_each_alloc_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->alloc_capable)
+			continue;
+
 		list_for_each_entry(d_i, &r->domains, list) {
 			if (d_i->plr)
 				cpumask_or(cpu_with_psl, cpu_with_psl,
arch/x86/kernel/cpu/resctrl/rdtgroup.c +7 -1
index e736e4d20f63..3f16e7854411 100644
@@ -98,12 +98,17 @@ void rdt_last_cmd_printf(const char *fmt, ...)
 
 void rdt_staged_configs_clear(void)
 {
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	struct rdt_domain *dom;
 
 	lockdep_assert_held(&rdtgroup_mutex);
 
-	for_each_alloc_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->alloc_capable)
+			continue;
+
 		list_for_each_entry(dom, &r->domains, list)
 			memset(dom->staged_config, 0, sizeof(dom->staged_config));
 	}
@@ -2181,6 +2186,7 @@ static int rdtgroup_mkdir_info_resdir(void *priv, char *name,
 
 static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 {
+	enum resctrl_res_level i;
 	struct resctrl_schema *s;
 	struct rdt_resource *r;
 	unsigned long fflags;
@@ -2205,8 +2211,12 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 			goto out_destroy;

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn) · line 2219

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -2
 	}
 
-	for_each_mon_capable_rdt_resource(r) {
-		fflags = r->fflags | RFTYPE_MON_INFO;
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->mon_capable)
+			continue;
+
+		fflags =  r->fflags | RFTYPE_MON_INFO;

Please check spacing.

Quoted 31 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +7 -1
 		sprintf(name, "%s_MON", r->name);
 		ret = rdtgroup_mkdir_info_resdir(r, name, fflags);
 		if (ret)
@@ -2615,10 +2625,15 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
 
 static int schemata_list_create(void)
 {
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	int ret = 0;
 
-	for_each_alloc_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->alloc_capable)
+			continue;
+
 		if (resctrl_arch_get_cdp_enabled(r->rid)) {
 			ret = schemata_list_add(r, CDP_CODE);
 			if (ret)
@@ -3166,6 +3181,7 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
 			     struct rdtgroup *prgrp,
 			     struct kernfs_node **dest_kn)
 {
+	enum resctrl_res_level i;
 	struct rdt_resource *r;
 	struct kernfs_node *kn;
 	int ret;
@@ -3184,7 +3200,11 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
 	 * Create the subdirectories for each domain. Note that all events
 	 * in a domain like L3 are grouped into a resource whose domain is L3

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int mkdir_mondata_all(struct kernfs_node *parent_kn, · line 3210

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -1
 	 */
-	for_each_mon_capable_rdt_resource(r) {
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->mon_capable)
+			continue;
+
 		ret = mkdir_mondata_subdir_alldom(kn, r, prgrp);
 		if (ret)
 			goto out_destroy;

Reinette

reviewer
#85 lore raw

Re: [PATCH v1 13/31] x86/resctrl: Stop using the for_each_*_rdt_resource() walkers

Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 1 line · James Morse

The for_each_*_rdt_resource() helpers walk the architectures array

architecture's ?

Noted.

Quoted 20 lines
Quoted 20 lines

of structures, using the resctrl visible part as an iterator. These became over-complex when the structures were split into a filesystem and architecture-specific struct. This approach avoided the need to touch every call site.

Once the filesystem parts of resctrl are moved to /fs/, both the architecture's resource array, and the definition of those structures is no longer accessible. To support resctrl, each architecture would have to provide equally complex macros.

Change the resctrl code that uses these to walk through the resource_level enum and check the mon/alloc capable flags instead. Instances in core.c, and resctrl_arch_reset_resources() remain part of x86's architecture specific code.

---
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c |  7 +++++-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    | 30 +++++++++++++++++++----
 2 files changed, 31 insertions(+), 6 deletions(-)

[...]

Quoted 4 lines
Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index e736e4d20f63..3f16e7854411 100644

[...]

Quoted 14 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn) · line 2219

Quoted 12 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -2
@@ -2205,8 +2211,12 @@ static int rdtgroup_create_info_dir(struct kernfs_node *parent_kn)
 			goto out_destroy;
 	}
 
-	for_each_mon_capable_rdt_resource(r) {
-		fflags = r->fflags | RFTYPE_MON_INFO;
+	for (i = 0; i < RDT_NUM_RESOURCES; i++) {
+		r = resctrl_arch_get_resource(i);
+		if (!r->mon_capable)
+			continue;
+
+		fflags =  r->fflags | RFTYPE_MON_INFO;

Please check spacing.

[...]

Quoted 1 line

Reinette

Noted, thanks.

Cheers
---Dave

author reviewer
#86 lore raw

PATCH 14/31 x86/resctrl: Export the is_mbm_*_enabled() helpers to asm/resctrl.h

In reply to James Morse

The architecture specific parts of resctrl have helpers to hide accesses to the rdt_mon_features bitmap.

Once the filesystem parts of resctrl are moved, these can no longer live in internal.h. Once these are exposed to the wider kernel, they should have a 'resctrl_arch_' prefix, to fit the rest of the arch<->fs interface.

Move and rename the helpers that touch rdt_mon_features directly. is_mbm_event() and is_mbm_enabled() are only called from rdtgroup.c, so can be moved into that file.

---
 arch/x86/include/asm/resctrl.h         | 17 +++++++++++
 arch/x86/kernel/cpu/resctrl/core.c     |  4 +--
 arch/x86/kernel/cpu/resctrl/internal.h | 27 -----------------
 arch/x86/kernel/cpu/resctrl/monitor.c  | 18 ++++++------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++---------
 5 files changed, 54 insertions(+), 52 deletions(-)
arch/x86/include/asm/resctrl.h +17 -0
index 5f6a5375bb4a..50407e83d0ca 100644
@@ -7,6 +7,7 @@
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 #include <linux/sched.h>
+#include <linux/resctrl_types.h>
 
 /*
  * This value can never be a valid CLOSID, and is used when mapping a
@@ -43,6 +44,7 @@ DECLARE_PER_CPU(struct resctrl_pqr_state, pqr_state);
 
 extern bool rdt_alloc_capable;
 extern bool rdt_mon_capable;
+extern unsigned int rdt_mon_features;
 
 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
 DECLARE_STATIC_KEY_FALSE(rdt_alloc_enable_key);
@@ -82,6 +84,21 @@ static inline void resctrl_arch_disable_mon(void)
 	static_branch_dec_cpuslocked(&rdt_enable_key);
 }
 
+static inline bool resctrl_arch_is_llc_occupancy_enabled(void)
+{
+	return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
+}
+
+static inline bool resctrl_arch_is_mbm_total_enabled(void)
+{
+	return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID));
+}
+
+static inline bool resctrl_arch_is_mbm_local_enabled(void)
+{
+	return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID));
+}
+
 /*
  * __resctrl_sched_in() - Writes the task's CLOSid/RMID to IA32_PQR_MSR
  *
arch/x86/kernel/cpu/resctrl/core.c +2 -2
index 9551ca4a6480..a4b5ade6e291 100644
@@ -481,13 +481,13 @@ static int arch_domain_mbm_alloc(u32 num_rmid, struct rdt_hw_domain *hw_dom)
 {
 	size_t tsize;
 
-	if (is_mbm_total_enabled()) {
+	if (resctrl_arch_is_mbm_total_enabled()) {
 		tsize = sizeof(*hw_dom->arch_mbm_total);
 		hw_dom->arch_mbm_total = kcalloc(num_rmid, tsize, GFP_KERNEL);
 		if (!hw_dom->arch_mbm_total)
 			return -ENOMEM;
 	}
-	if (is_mbm_local_enabled()) {
+	if (resctrl_arch_is_mbm_local_enabled()) {
 		tsize = sizeof(*hw_dom->arch_mbm_local);
 		hw_dom->arch_mbm_local = kcalloc(num_rmid, tsize, GFP_KERNEL);
 		if (!hw_dom->arch_mbm_local) {
arch/x86/kernel/cpu/resctrl/internal.h +0 -27
index 01fcd4ef26ca..edbccc79246f 100644
@@ -130,7 +130,6 @@ struct rmid_read {
 	void			*arch_mon_ctx;
 };
 
-extern unsigned int rdt_mon_features;
 extern struct list_head resctrl_schema_all;
 extern bool resctrl_mounted;
 
@@ -360,32 +359,6 @@ struct msr_param {
 	u32			high;
 };
 
-static inline bool is_llc_occupancy_enabled(void)
-{
-	return (rdt_mon_features & (1 << QOS_L3_OCCUP_EVENT_ID));
-}
-
-static inline bool is_mbm_total_enabled(void)
-{
-	return (rdt_mon_features & (1 << QOS_L3_MBM_TOTAL_EVENT_ID));
-}
-
-static inline bool is_mbm_local_enabled(void)
-{
-	return (rdt_mon_features & (1 << QOS_L3_MBM_LOCAL_EVENT_ID));
-}
-
-static inline bool is_mbm_enabled(void)
-{
-	return (is_mbm_total_enabled() || is_mbm_local_enabled());
-}
-
-static inline bool is_mbm_event(int e)
-{
-	return (e >= QOS_L3_MBM_TOTAL_EVENT_ID &&
-		e <= QOS_L3_MBM_LOCAL_EVENT_ID);
-}
-
 /**
  * struct rdt_hw_resource - arch private attributes of a resctrl resource
  * @r_resctrl:		Attributes of the resource used directly by resctrl.
arch/x86/kernel/cpu/resctrl/monitor.c +9 -9
index 2a1cbd4de6ee..c9be2d0819c0 100644
@@ -251,11 +251,11 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain *d)
 {
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
 
-	if (is_mbm_total_enabled())
+	if (resctrl_arch_is_mbm_total_enabled())
 		memset(hw_dom->arch_mbm_total, 0,
 		       sizeof(*hw_dom->arch_mbm_total) * r->num_rmid);
 
-	if (is_mbm_local_enabled())
+	if (resctrl_arch_is_mbm_local_enabled())
 		memset(hw_dom->arch_mbm_local, 0,
 		       sizeof(*hw_dom->arch_mbm_local) * r->num_rmid);
 }
@@ -514,7 +514,7 @@ void free_rmid(u32 closid, u32 rmid)
 
 	entry = __rmid_entry(idx);
 
-	if (is_llc_occupancy_enabled())
+	if (resctrl_arch_is_llc_occupancy_enabled())
 		add_rmid_to_limbo(entry);
 	else
 		list_add_tail(&entry->list, &rmid_free_lru);
@@ -666,7 +666,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 	struct list_head *head;
 	struct rdtgroup *entry;
 
-	if (!is_mbm_local_enabled())
+	if (!resctrl_arch_is_mbm_local_enabled())
 		return;
 
 	r_mba = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
@@ -735,7 +735,7 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d,
 	 * This is protected from concurrent reads from user
 	 * as both the user and we hold the global mutex.
 	 */
-	if (is_mbm_total_enabled()) {
+	if (resctrl_arch_is_mbm_total_enabled()) {
 		rr.evtid = QOS_L3_MBM_TOTAL_EVENT_ID;
 		rr.val = 0;
 		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
@@ -749,7 +749,7 @@ static void mbm_update(struct rdt_resource *r, struct rdt_domain *d,
 
 		resctrl_arch_mon_ctx_free(rr.r, rr.evtid, rr.arch_mon_ctx);
 	}
-	if (is_mbm_local_enabled()) {
+	if (resctrl_arch_is_mbm_local_enabled()) {
 		rr.evtid = QOS_L3_MBM_LOCAL_EVENT_ID;
 		rr.val = 0;
 		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, rr.evtid);
@@ -997,11 +997,11 @@ static void l3_mon_evt_init(struct rdt_resource *r)
 {
 	INIT_LIST_HEAD(&r->evt_list);
 
-	if (is_llc_occupancy_enabled())
+	if (resctrl_arch_is_llc_occupancy_enabled())
 		list_add_tail(&llc_occupancy_event.list, &r->evt_list);
-	if (is_mbm_total_enabled())
+	if (resctrl_arch_is_mbm_total_enabled())
 		list_add_tail(&mbm_total_event.list, &r->evt_list);
-	if (is_mbm_local_enabled())
+	if (resctrl_arch_is_mbm_local_enabled())
 		list_add_tail(&mbm_local_event.list, &r->evt_list);
 }
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +26 -14
index 3f16e7854411..8285b916289c 100644
@@ -114,6 +114,18 @@ void rdt_staged_configs_clear(void)
 	}
 }
 
+static bool resctrl_is_mbm_enabled(void)
+{
+	return (resctrl_arch_is_mbm_total_enabled() ||
+		resctrl_arch_is_mbm_local_enabled());
+}
+
+static bool resctrl_is_mbm_event(int e)
+{
+	return (e >= QOS_L3_MBM_TOTAL_EVENT_ID &&
+		e <= QOS_L3_MBM_LOCAL_EVENT_ID);
+}
+
 /*
  * Trivial allocator for CLOSIDs. Since h/w only supports a small number,
  * we can keep a bitmap of free CLOSIDs in a single integer.
@@ -161,7 +173,7 @@ static int closid_alloc(void)
 	lockdep_assert_held(&rdtgroup_mutex);
 
 	if (IS_ENABLED(CONFIG_RESCTRL_RMID_DEPENDS_ON_CLOSID) &&
-	    is_llc_occupancy_enabled()) {
+	    resctrl_arch_is_llc_occupancy_enabled()) {
 		cleanest_closid = resctrl_find_cleanest_closid();
 		if (cleanest_closid < 0)
 			return cleanest_closid;
@@ -2370,7 +2382,7 @@ static bool supports_mba_mbps(void)
 {
 	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 
-	return (is_mbm_local_enabled() &&
+	return (resctrl_arch_is_mbm_local_enabled() &&
 		r->alloc_capable && is_mba_linear());
 }
 
@@ -2738,7 +2750,7 @@ static int rdt_get_tree(struct fs_context *fc)
 	if (resctrl_arch_alloc_capable() || resctrl_arch_mon_capable())
 		resctrl_mounted = true;
 
-	if (is_mbm_enabled()) {
+	if (resctrl_is_mbm_enabled()) {
 		list_for_each_entry(dom, &l3->domains, list)
 			mbm_setup_overflow_handler(dom, MBM_OVERFLOW_INTERVAL,
 						   RESCTRL_PICK_ANY_CPU);
@@ -3107,7 +3119,7 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
 		if (ret)
 			goto out_destroy;
 
-		if (is_mbm_event(mevt->evtid))
+		if (resctrl_is_mbm_event(mevt->evtid))
 			mon_event_read(&rr, r, d, prgrp, mevt->evtid, true);
 	}
 	kernfs_activate(kn);
@@ -4006,9 +4018,9 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (resctrl_mounted && resctrl_arch_mon_capable())
 		rmdir_mondata_subdir_allrdtgrp(r, d->id);
 
-	if (is_mbm_enabled())
+	if (resctrl_is_mbm_enabled())
 		cancel_delayed_work(&d->mbm_over);
-	if (is_llc_occupancy_enabled() && has_busy_rmid(d)) {
+	if (resctrl_arch_is_llc_occupancy_enabled() && has_busy_rmid(d)) {
 		/*
 		 * When a package is going down, forcefully
 		 * decrement rmid->ebusy. There is no way to know
@@ -4032,12 +4044,12 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
 	u32 idx_limit = resctrl_arch_system_num_rmid_idx();
 	size_t tsize;
 
-	if (is_llc_occupancy_enabled()) {
+	if (resctrl_arch_is_llc_occupancy_enabled()) {
 		d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
 		if (!d->rmid_busy_llc)
 			return -ENOMEM;
 	}
-	if (is_mbm_total_enabled()) {
+	if (resctrl_arch_is_mbm_total_enabled()) {
 		tsize = sizeof(*d->mbm_total);
 		d->mbm_total = kcalloc(idx_limit, tsize, GFP_KERNEL);
 		if (!d->mbm_total) {
@@ -4045,7 +4057,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
 			return -ENOMEM;
 		}
 	}
-	if (is_mbm_local_enabled()) {
+	if (resctrl_arch_is_mbm_local_enabled()) {
 		tsize = sizeof(*d->mbm_local);
 		d->mbm_local = kcalloc(idx_limit, tsize, GFP_KERNEL);
 		if (!d->mbm_local) {
@@ -4077,13 +4089,13 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
 	if (err)
 		goto out_unlock;
 
-	if (is_mbm_enabled()) {
+	if (resctrl_is_mbm_enabled()) {
 		INIT_DELAYED_WORK(&d->mbm_over, mbm_handle_overflow);
 		mbm_setup_overflow_handler(d, MBM_OVERFLOW_INTERVAL,
 					   RESCTRL_PICK_ANY_CPU);
 	}
 
-	if (is_llc_occupancy_enabled())
+	if (resctrl_arch_is_llc_occupancy_enabled())
 		INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
 
 	/*
@@ -4138,12 +4150,12 @@ void resctrl_offline_cpu(unsigned int cpu)
 
 	d = get_domain_from_cpu(cpu, l3);
 	if (d) {
-		if (is_mbm_enabled() && cpu == d->mbm_work_cpu) {
+		if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
 			cancel_delayed_work(&d->mbm_over);
 			mbm_setup_overflow_handler(d, 0, cpu);
 		}
-		if (is_llc_occupancy_enabled() && cpu == d->cqm_work_cpu &&
-		    has_busy_rmid(d)) {
+		if (resctrl_arch_is_llc_occupancy_enabled() &&
+		    cpu == d->cqm_work_cpu && has_busy_rmid(d)) {
 			cancel_delayed_work(&d->cqm_limbo);
 			cqm_setup_limbo_handler(d, 0, cpu);
 		}
Signature · 1 line
2.39.2
maintainer
#87 lore raw

Re: [PATCH v1 14/31] x86/resctrl: Export the is_mbm_*_enabled() helpers to asm/resctrl.h

Hi James,

Quoted 25 lines · James Morse

The architecture specific parts of resctrl have helpers to hide accesses to the rdt_mon_features bitmap.

Once the filesystem parts of resctrl are moved, these can no longer live in internal.h. Once these are exposed to the wider kernel, they should have a 'resctrl_arch_' prefix, to fit the rest of the arch<->fs interface.

Move and rename the helpers that touch rdt_mon_features directly. is_mbm_event() and is_mbm_enabled() are only called from rdtgroup.c, so can be moved into that file.

---
 arch/x86/include/asm/resctrl.h         | 17 +++++++++++
 arch/x86/kernel/cpu/resctrl/core.c     |  4 +--
 arch/x86/kernel/cpu/resctrl/internal.h | 27 -----------------
 arch/x86/kernel/cpu/resctrl/monitor.c  | 18 ++++++------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++---------
 5 files changed, 54 insertions(+), 52 deletions(-)
arch/x86/include/asm/resctrl.h +0 -0
index 5f6a5375bb4a..50407e83d0ca 100644

arch/x86/include/asm/resctrl.h line 11

Quoted 5 lines
arch/x86/include/asm/resctrl.h +1 -0
@@ -7,6 +7,7 @@
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 #include <linux/sched.h>
+#include <linux/resctrl_types.h>
 

Can this be alphabetical?

Reinette

reviewer
#88 lore raw

Re: [PATCH v1 14/31] x86/resctrl: Export the is_mbm_*_enabled() helpers to asm/resctrl.h

Quoted 23 lines · Reinette Chatre

Hi James,

Quoted 20 lines · James Morse

The architecture specific parts of resctrl have helpers to hide accesses to the rdt_mon_features bitmap.

Once the filesystem parts of resctrl are moved, these can no longer live in internal.h. Once these are exposed to the wider kernel, they should have a 'resctrl_arch_' prefix, to fit the rest of the arch<->fs interface.

Move and rename the helpers that touch rdt_mon_features directly. is_mbm_event() and is_mbm_enabled() are only called from rdtgroup.c, so can be moved into that file.

---
 arch/x86/include/asm/resctrl.h         | 17 +++++++++++
 arch/x86/kernel/cpu/resctrl/core.c     |  4 +--
 arch/x86/kernel/cpu/resctrl/internal.h | 27 -----------------
 arch/x86/kernel/cpu/resctrl/monitor.c  | 18 ++++++------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 40 +++++++++++++++++---------
 5 files changed, 54 insertions(+), 52 deletions(-)
Quoted 12 lines

arch/x86/include/asm/resctrl.h line 11

Quoted 10 lines
arch/x86/include/asm/resctrl.h +1 -0
index 5f6a5375bb4a..50407e83d0ca 100644
@@ -7,6 +7,7 @@
 #include <linux/jump_label.h>
 #include <linux/percpu.h>
 #include <linux/sched.h>
+#include <linux/resctrl_types.h>
 

Can this be alphabetical?

I'd guess so, looking at it.

Noted.

Cheers
---Dave

author reviewer
#89 lore raw

PATCH 15/31 x86/resctrl: Add resctrl_arch_is_evt_configurable() to abstract BMEC

In reply to James Morse

When BMEC is supported the resctrl event can be configured in a number of ways. This depends on architecture support. rdt_get_mon_l3_config() modifies the struct mon_evt and calls mbm_config_rftype_init() to create the files that allow the configuration.

Splitting this into separate architecture and filesystem parts would require the struct mon_evt and mbm_config_rftype_init() to be exposed.

Instead, add resctrl_arch_is_evt_configurable(), and use this from resctrl_mon_resource_init() to initialise struct mon_evt and call mbm_config_rftype_init(). resctrl_arch_is_evt_configurable() calls rdt_cpu_has() so it doesn't obviously benefit from being inlined. Putting it in core.c will allow rdt_cpu_has() to eventually become static.

resctrl_arch_is_evt_configurable() uses rdt_cpu_has() from resctrl_mon_resource_init(), which isn't marked __init. In addition, MPAM needs to initialise resctrl late. Drop the __init on the relevant functions.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 19 +++++++++++++++++--
 arch/x86/kernel/cpu/resctrl/internal.h |  4 ++--
 arch/x86/kernel/cpu/resctrl/monitor.c  | 18 +++++++++---------
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  2 +-
 include/linux/resctrl.h                |  2 ++
 5 files changed, 31 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +17 -2
index a4b5ade6e291..824a94593e9d 100644
@@ -667,7 +667,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),
@@ -707,7 +707,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;
@@ -727,6 +727,21 @@ bool __init rdt_cpu_has(int flag)
 	return ret;
 }
 
+bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt)
+{
+	if (!rdt_cpu_has(X86_FEATURE_BMEC))
+		return false;
+
+	switch (evt) {
+	case QOS_L3_MBM_TOTAL_EVENT_ID:
+		return rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL);
+	case QOS_L3_MBM_LOCAL_EVENT_ID:
+		return rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL);
+	default:
+		return false;
+	}
+}
+
 static __init bool get_mem_config(void)
 {
 	struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_MBA];
arch/x86/kernel/cpu/resctrl/internal.h +2 -2
index edbccc79246f..46370eafb00f 100644
@@ -507,7 +507,7 @@ int alloc_rmid(u32 closid);
 void free_rmid(u32 closid, u32 rmid);
 int rdt_get_mon_l3_config(struct rdt_resource *r);
 void __exit 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,
@@ -527,7 +527,7 @@ bool has_busy_rmid(struct rdt_domain *d);
 void __check_limbo(struct rdt_domain *d, bool force_free);
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
 void __init thread_throttle_mode_init(void);
-void __init mbm_config_rftype_init(const char *config);
+void mbm_config_rftype_init(const char *config);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
 int resctrl_find_cleanest_closid(void);
arch/x86/kernel/cpu/resctrl/monitor.c +9 -9
index c9be2d0819c0..ccb85c61b43b 100644
@@ -1019,6 +1019,15 @@ int resctrl_mon_resource_init(void)
 
 	l3_mon_evt_init(r);
 
+	if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_TOTAL_EVENT_ID)) {
+		mbm_total_event.configurable = true;
+		mbm_config_rftype_init("mbm_total_bytes_config");
+	}
+	if (resctrl_arch_is_evt_configurable(QOS_L3_MBM_LOCAL_EVENT_ID)) {
+		mbm_local_event.configurable = true;
+		mbm_config_rftype_init("mbm_local_bytes_config");
+	}
+
 	return 0;
 }
 
@@ -1060,15 +1069,6 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
 		hw_res->mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
-
-		if (rdt_cpu_has(X86_FEATURE_CQM_MBM_TOTAL)) {
-			mbm_total_event.configurable = true;
-			mbm_config_rftype_init("mbm_total_bytes_config");
-		}
-		if (rdt_cpu_has(X86_FEATURE_CQM_MBM_LOCAL)) {
-			mbm_local_event.configurable = true;
-			mbm_config_rftype_init("mbm_local_bytes_config");
-		}
 	}
 
 	r->mon_capable = true;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
index 8285b916289c..2d6f4e0d3656 100644
@@ -2068,7 +2068,7 @@ void __init thread_throttle_mode_init(void)
 	rft->fflags = RFTYPE_CTRL_INFO | RFTYPE_RES_MB;
 }
 
-void __init mbm_config_rftype_init(const char *config)
+void mbm_config_rftype_init(const char *config)
 {
 	struct rftype *rft;
 
include/linux/resctrl.h +2 -0
index b0ee7256e095..bfc63e8219e5 100644
@@ -204,6 +204,8 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 struct rdt_domain *resctrl_arch_find_domain(struct rdt_resource *r, int id);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 
+bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
+
 /*
  * Update the ctrl_val and apply this config right now.
  * Must be called on one of the domain's CPUs.
Signature · 1 line
2.39.2
author reviewer
#90 lore raw

PATCH 16/31 x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers

In reply to James Morse

mon_event_config_{read,write}() are called via IPI and access model specific registers to do their work.

To support another architecture, this needs abstracting.

Rename mon_event_config_{read,write}() to have a resctrl_arch_ prefix, and move their struct mon_config_info parameter into the restrl_types header. This allows another architecture to supply an implementation of these.

As struct mon_config_info is now exposed globally, give it a 'resctrl_' prefix. MPAM systems need access to the domain to do this work, add the resource and domain to struct resctrl_mon_config_info.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 34 +++++++++++++-------------
 include/linux/resctrl.h                |  9 +++++++
 2 files changed, 26 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +17 -17
index 2d6f4e0d3656..e76018687117 100644
@@ -1580,11 +1580,6 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 	return ret;
 }
 
-struct mon_config_info {
-	u32 evtid;
-	u32 mon_config;
-};
-
 #define INVALID_CONFIG_INDEX   UINT_MAX
 
 /**
@@ -1609,9 +1604,9 @@ static inline unsigned int mon_event_config_index_get(u32 evtid)
 	}
 }
 
-static void mon_event_config_read(void *info)
+void resctrl_arch_mon_event_config_read(void *info)
 {
-	struct mon_config_info *mon_info = info;
+	struct resctrl_mon_config_info *mon_info = info;
 	unsigned int index;
 	u64 msrval;
 
@@ -1626,14 +1621,15 @@ static void mon_event_config_read(void *info)
 	mon_info->mon_config = msrval & MAX_EVT_CONFIG_BITS;
 }
 
-static void mondata_config_read(struct rdt_domain *d, struct mon_config_info *mon_info)
+static void mondata_config_read(struct resctrl_mon_config_info *mon_info)
 {
-	smp_call_function_any(&d->cpu_mask, mon_event_config_read, mon_info, 1);
+	smp_call_function_any(&mon_info->d->cpu_mask,
+			      resctrl_arch_mon_event_config_read, mon_info, 1);
 }
 
 static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid)
 {
-	struct mon_config_info mon_info = {0};
+	struct resctrl_mon_config_info mon_info = {0};
 	struct rdt_domain *dom;
 	bool sep = false;
 
@@ -1644,9 +1640,11 @@ static int mbm_config_show(struct seq_file *s, struct rdt_resource *r, u32 evtid
 		if (sep)
 			seq_puts(s, ";");
 
-		memset(&mon_info, 0, sizeof(struct mon_config_info));
+		memset(&mon_info, 0, sizeof(struct resctrl_mon_config_info));
+		mon_info.r = r;
+		mon_info.d = dom;
 		mon_info.evtid = evtid;
-		mondata_config_read(dom, &mon_info);
+		mondata_config_read(&mon_info);
 
 		seq_printf(s, "%d=0x%02x", dom->id, mon_info.mon_config);
 		sep = true;
@@ -1679,9 +1677,9 @@ static int mbm_local_bytes_config_show(struct kernfs_open_file *of,
 	return 0;
 }
 
-static void mon_event_config_write(void *info)
+void resctrl_arch_mon_event_config_write(void *info)
 {
-	struct mon_config_info *mon_info = info;
+	struct resctrl_mon_config_info *mon_info = info;
 	unsigned int index;
 
 	index = mon_event_config_index_get(mon_info->evtid);
@@ -1695,14 +1693,16 @@ static void mon_event_config_write(void *info)
 static void mbm_config_write_domain(struct rdt_resource *r,
 				    struct rdt_domain *d, u32 evtid, u32 val)
 {
-	struct mon_config_info mon_info = {0};
+	struct resctrl_mon_config_info mon_info = {0};
 
 	/*
 	 * Read the current config value first. If both are the same then
 	 * no need to write it again.
 	 */
+	mon_info.r = r;
+	mon_info.d = d;
 	mon_info.evtid = evtid;
-	mondata_config_read(d, &mon_info);
+	mondata_config_read(&mon_info);
 	if (mon_info.mon_config == val)
 		return;
 
@@ -1714,7 +1714,7 @@ static void mbm_config_write_domain(struct rdt_resource *r,
 	 * are scoped at the domain level. Writing any of these MSRs
 	 * on one CPU is observed by all the CPUs in the domain.
 	 */
-	smp_call_function_any(&d->cpu_mask, mon_event_config_write,
+	smp_call_function_any(&d->cpu_mask, resctrl_arch_mon_event_config_write,
 			      &mon_info, 1);
 
 	/*
include/linux/resctrl.h +9 -0
index bfc63e8219e5..975b80102fbe 100644
@@ -192,6 +192,13 @@ struct resctrl_cpu_sync {
 	u32 rmid;
 };
 
+struct resctrl_mon_config_info {
+	struct rdt_resource *r;
+	struct rdt_domain   *d;
+	u32                  evtid;
+	u32                  mon_config;
+};
+
 /*
  * Update and re-load this CPUs defaults. Called via IPI, takes a pointer to
  * struct resctrl_cpu_sync, or NULL.
@@ -205,6 +212,8 @@ struct rdt_domain *resctrl_arch_find_domain(struct rdt_resource *r, int id);
 int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
 
 bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
+void resctrl_arch_mon_event_config_write(void *info);
+void resctrl_arch_mon_event_config_read(void *info);
 
 /*
  * Update the ctrl_val and apply this config right now.
Signature · 1 line
2.39.2
maintainer
#91 lore raw

Re: [PATCH v1 16/31] x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers

Hi James,

Quoted 7 lines · James Morse

mon_event_config_{read,write}() are called via IPI and access model specific registers to do their work.

To support another architecture, this needs abstracting.

Rename mon_event_config_{read,write}() to have a resctrl_arch_ prefix, and move their struct mon_config_info parameter into the restrl_types

Looks like this change is actually moving the struct into include/linux/resctrl.h, not resctrl_types.h.

Quoted 8 lines

header. This allows another architecture to supply an implementation of these.

As struct mon_config_info is now exposed globally, give it a 'resctrl_' prefix. MPAM systems need access to the domain to do this work, add the resource and domain to struct resctrl_mon_config_info.

...

Quoted 5 lines
include/linux/resctrl.h +0 -0
index bfc63e8219e5..975b80102fbe 100644

include/linux/resctrl.h struct resctrl_cpu_sync { · line 201

Quoted 10 lines
include/linux/resctrl.h +7 -0
@@ -192,6 +192,13 @@ struct resctrl_cpu_sync {
 	u32 rmid;
 };
 
+struct resctrl_mon_config_info {
+	struct rdt_resource *r;
+	struct rdt_domain   *d;
+	u32                  evtid;
+	u32                  mon_config;
+};
+

Please use tabs consistently in this file.

Reinette

reviewer
#92 lore raw

Re: [PATCH v1 16/31] x86/resctrl: Change mon_event_config_{read,write}() to be arch helpers

Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

mon_event_config_{read,write}() are called via IPI and access model specific registers to do their work.

Quoted 7 lines
Quoted 4 lines

To support another architecture, this needs abstracting.

Rename mon_event_config_{read,write}() to have a resctrl_arch_ prefix, and move their struct mon_config_info parameter into the restrl_types

Looks like this change is actually moving the struct into include/linux/resctrl.h, not resctrl_types.h.

Noted.

Quoted 30 lines
Quoted 9 lines

header. This allows another architecture to supply an implementation of these.

As struct mon_config_info is now exposed globally, give it a 'resctrl_' prefix. MPAM systems need access to the domain to do this work, add the resource and domain to struct resctrl_mon_config_info.

..

Quoted 5 lines
include/linux/resctrl.h +0 -0
index bfc63e8219e5..975b80102fbe 100644

include/linux/resctrl.h struct resctrl_cpu_sync { · line 201

Quoted 10 lines
include/linux/resctrl.h +7 -0
@@ -192,6 +192,13 @@ struct resctrl_cpu_sync {
 	u32 rmid;
 };
 
+struct resctrl_mon_config_info {
+	struct rdt_resource *r;
+	struct rdt_domain   *d;
+	u32                  evtid;
+	u32                  mon_config;
+};
+

Please use tabs consistently in this file.

Quoted 2 lines

Reinette

Noted; I have presumed that you mean tabs-only indentation before the member declarator, and to line up the declarators (including the *), e.g.:

struct resctrl_mon_config_info {
	struct rdt_resource	*r;
	struct rdt_domain	*d;
	u32			evtid;
	u32			mon_config;
};

(But if that's not what you meant, please shout!)

Cheers
---Dave

author reviewer
#93 lore raw

PATCH 17/31 x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

In reply to James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 3 ---
 arch/x86/kernel/cpu/resctrl/monitor.c  | 2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 5 ++---
 include/linux/resctrl.h                | 3 +++
 4 files changed, 6 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +0 -3
index 46370eafb00f..238b81d3f64a 100644
@@ -371,8 +371,6 @@ struct msr_param {
  * @msr_update:		Function pointer to update QOS MSRs
  * @mon_scale:		cqm counter * mon_scale = occupancy in bytes
  * @mbm_width:		Monitor width, to detect and correct for overflow.
- * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
- *			Monitoring Event Configuration (BMEC) is supported.
  * @cdp_enabled:	CDP state of this resource
  *
  * Members of this structure are either private to the architecture
@@ -387,7 +385,6 @@ struct rdt_hw_resource {
 				 struct rdt_resource *r);
 	unsigned int		mon_scale;
 	unsigned int		mbm_width;
-	unsigned int		mbm_cfg_mask;
 	bool			cdp_enabled;
 };
 
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
index ccb85c61b43b..287fb0a5f060 100644
@@ -1068,7 +1068,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 
 		/* Detect list of bandwidth sources that can be tracked */
 		cpuid_count(0x80000020, 3, &eax, &ebx, &ecx, &edx);
-		hw_res->mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
+		r->mbm_cfg_mask = ecx & MAX_EVT_CONFIG_BITS;
 	}
 
 	r->mon_capable = true;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -3
index e76018687117..3d3a839eba6b 100644
@@ -1731,7 +1731,6 @@ static void mbm_config_write_domain(struct rdt_resource *r,
 
 static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
 {
-	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	char *dom_str = NULL, *id_str;
 	unsigned long dom_id, val;
 	struct rdt_domain *d;
@@ -1758,9 +1757,9 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
 	}
 
 	/* Value from user cannot be more than the supported set of events */
-	if ((val & hw_res->mbm_cfg_mask) != val) {
+	if ((val & r->mbm_cfg_mask) != val) {
 		rdt_last_cmd_printf("Invalid event configuration: max valid mask is 0x%02x\n",
-				    hw_res->mbm_cfg_mask);
+				    r->mbm_cfg_mask);
 		return -EINVAL;
 	}
 
include/linux/resctrl.h +3 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.
  * @cdp_capable:	Is the CDP feature available on this resource
  */
 struct rdt_resource {
@@ -157,6 +159,7 @@ struct rdt_resource {
 	const char		*format_str;
 	struct list_head	evt_list;
 	unsigned long		fflags;
+	unsigned int		mbm_cfg_mask;
 	bool			cdp_capable;
 };
 
Signature · 1 line
2.39.2
maintainer
#94 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Hi James,

Quoted 12 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

...

include/linux/resctrl.h struct resctrl_membw { · line 144

Quoted 10 lines
include/linux/resctrl.h +2 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.

BMEC is an AMD term. If MPAM is planning to use this member then this comment should be made generic.

include/linux/resctrl.h struct rdt_resource { · line 165

Quoted 11 lines
include/linux/resctrl.h +1 -0
  * @cdp_capable:	Is the CDP feature available on this resource
  */
 struct rdt_resource {
@@ -157,6 +159,7 @@ struct rdt_resource {
 	const char		*format_str;
 	struct list_head	evt_list;
 	unsigned long		fflags;
+	unsigned int		mbm_cfg_mask;
 	bool			cdp_capable;
 };
 

Reinette

reviewer
#95 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 12 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

..

Quoted 10 lines
include/linux/resctrl.h +2 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.

[...]

Quoted 4 lines

Reinette

BMEC is an AMD term. If MPAM is planning to use this member then this comment should be made generic.

MPAM can (at least) filter reads and/or writes, and it looks like James is expecting to support this.

However, it probably does make sense to keep the comments neutral in a common header.

Would the following work?

* @ mbm_cfg_mask: Arch-specific event configuration flags

I think that's broad enough to cover all bases, but I'll wait for your response.

Cheers
---Dave

maintainer
#96 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Hi Dave,

Quoted 43 lines · Dave Martin
Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 12 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

..

Quoted 10 lines
include/linux/resctrl.h +2 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.

[...]

Quoted 4 lines

Reinette

BMEC is an AMD term. If MPAM is planning to use this member then this comment should be made generic.

MPAM can (at least) filter reads and/or writes, and it looks like James is expecting to support this.

However, it probably does make sense to keep the comments neutral in a common header.

Quoted 8 lines

Would the following work?

* @ mbm_cfg_mask: Arch-specific event configuration flags

I think that's broad enough to cover all bases, but I'll wait for your response.

Since this is exposed to user space, ideally all architectures would use the same bits to mean the same thing. I assumed that is what James intended by placing the existing (AMD BMEC) bits in the global resctrl_types.h.

Reinette

reviewer
#97 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Quoted 52 lines · Reinette Chatre

Hi Dave,

Quoted 49 lines · Dave Martin
Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 12 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

..

Quoted 10 lines
include/linux/resctrl.h +2 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.

[...]

Quoted 4 lines

Reinette

BMEC is an AMD term. If MPAM is planning to use this member then this comment should be made generic.

MPAM can (at least) filter reads and/or writes, and it looks like James is expecting to support this.

However, it probably does make sense to keep the comments neutral in a common header.

Would the following work?

* @ mbm_cfg_mask: Arch-specific event configuration flags

Quoted 8 lines
Quoted 2 lines

I think that's broad enough to cover all bases, but I'll wait for your response.

Since this is exposed to user space, ideally all architectures would use the same bits to mean the same thing. I assumed that is what James intended by placing the existing (AMD BMEC) bits in the global resctrl_types.h.

Reinette

Maybe, but the bits as defined by AMD BMEC look rather architecture and bus specific, and I am suspicious that there is no guaranteed clean mapping between MPAM's config and BMEC's config.

MPAM currently just has "reads" and "writes" (or both), though as for BMEC, the meanings of these are not fully defined. I suppose finer filtering granularity might be supported in future (at least, it is not explicitly ruled out).

James' current approach seems to be to pick a single BMEC flag that's in the right sort of area for each MPAM bit (though not equivalent) and translate that bit across to drive a corresponding the MPAM bit. But I'd say that this is arch-specific configuration masquerading as generic configuration IMHO and not really generic at all.

See "untested: arm_mpam: resctrl: Allow monitors to be configured"
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot/v6.7-rc2&id=db0ac51f60675b6c4a54ccd24fa7198ec321c56d

I guess this needs discussion with James, since there will have been additional thought process behind all this that is not captured; either way, I guess it could be resolved after this series, but it will need a decision before the MPAM support is merged (or at least, before MPAM exposes userspace support for event configuration upstream).

(If this has already been discussed and James' current approach has already been agreed as the least worst option, then I guess I can live with it; I just find it icky, and it looks odd to have AMD specifics in a common header.)

Cheers
---Dave

maintainer
#98 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Hi Dave,

Quoted 86 lines · Dave Martin
Quoted 52 lines · Reinette Chatre

Hi Dave,

Quoted 49 lines · Dave Martin
Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 12 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

..

Quoted 10 lines
include/linux/resctrl.h +2 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.

[...]

Quoted 4 lines

Reinette

BMEC is an AMD term. If MPAM is planning to use this member then this comment should be made generic.

MPAM can (at least) filter reads and/or writes, and it looks like James is expecting to support this.

However, it probably does make sense to keep the comments neutral in a common header.

Would the following work?

* @ mbm_cfg_mask: Arch-specific event configuration flags

Quoted 8 lines
Quoted 2 lines

I think that's broad enough to cover all bases, but I'll wait for your response.

Since this is exposed to user space, ideally all architectures would use the same bits to mean the same thing. I assumed that is what James intended by placing the existing (AMD BMEC) bits in the global resctrl_types.h.

Reinette

Maybe, but the bits as defined by AMD BMEC look rather architecture and bus specific, and I am suspicious that there is no guaranteed clean mapping between MPAM's config and BMEC's config.

MPAM currently just has "reads" and "writes" (or both), though as for BMEC, the meanings of these are not fully defined. I suppose finer filtering granularity might be supported in future (at least, it is not explicitly ruled out).

James' current approach seems to be to pick a single BMEC flag that's in the right sort of area for each MPAM bit (though not equivalent) and translate that bit across to drive a corresponding the MPAM bit. But I'd say that this is arch-specific configuration masquerading as generic configuration IMHO and not really generic at all.

See "untested: arm_mpam: resctrl: Allow monitors to be configured"
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot/v6.7-rc2&id=db0ac51f60675b6c4a54ccd24fa7198ec321c56d

I guess this needs discussion with James, since there will have been additional thought process behind all this that is not captured; either way, I guess it could be resolved after this series, but it will need a decision before the MPAM support is merged (or at least, before MPAM exposes userspace support for event configuration upstream).

Quoted 4 lines

(If this has already been discussed and James' current approach has already been agreed as the least worst option, then I guess I can live with it; I just find it icky, and it looks odd to have AMD specifics in a common header.)

I am not aware of such a discussion.

Sounds like a motivation to delay this portion of the changes in patch #8.

Reinette

reviewer
#99 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Quoted 94 lines · Reinette Chatre

Hi Dave,

Quoted 86 lines · Dave Martin
Quoted 52 lines · Reinette Chatre

Hi Dave,

Quoted 49 lines · Dave Martin
Quoted 28 lines · Reinette Chatre

Hi James,

Quoted 12 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

..

Quoted 10 lines
include/linux/resctrl.h +2 -0
index 975b80102fbe..8a7367d1ce45 100644
@@ -140,6 +140,8 @@ struct resctrl_membw {
  * @format_str:		Per resource format string to show domain value
  * @evt_list:		List of monitoring events
  * @fflags:		flags to choose base and info files
+ * @mbm_cfg_mask:	Bandwidth sources that can be tracked when Bandwidth
+ *			Monitoring Event Configuration (BMEC) is supported.

[...]

Quoted 4 lines

Reinette

BMEC is an AMD term. If MPAM is planning to use this member then this comment should be made generic.

MPAM can (at least) filter reads and/or writes, and it looks like James is expecting to support this.

However, it probably does make sense to keep the comments neutral in a common header.

Would the following work?

* @ mbm_cfg_mask: Arch-specific event configuration flags

Quoted 8 lines
Quoted 2 lines

I think that's broad enough to cover all bases, but I'll wait for your response.

Since this is exposed to user space, ideally all architectures would use the same bits to mean the same thing. I assumed that is what James intended by placing the existing (AMD BMEC) bits in the global resctrl_types.h.

Reinette

Maybe, but the bits as defined by AMD BMEC look rather architecture and bus specific, and I am suspicious that there is no guaranteed clean mapping between MPAM's config and BMEC's config.

MPAM currently just has "reads" and "writes" (or both), though as for BMEC, the meanings of these are not fully defined. I suppose finer filtering granularity might be supported in future (at least, it is not explicitly ruled out).

James' current approach seems to be to pick a single BMEC flag that's in the right sort of area for each MPAM bit (though not equivalent) and translate that bit across to drive a corresponding the MPAM bit. But I'd say that this is arch-specific configuration masquerading as generic configuration IMHO and not really generic at all.

See "untested: arm_mpam: resctrl: Allow monitors to be configured"
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot/v6.7-rc2&id=db0ac51f60675b6c4a54ccd24fa7198ec321c56d

I guess this needs discussion with James, since there will have been additional thought process behind all this that is not captured; either way, I guess it could be resolved after this series, but it will need a decision before the MPAM support is merged (or at least, before MPAM exposes userspace support for event configuration upstream).

Quoted 4 lines

(If this has already been discussed and James' current approach has already been agreed as the least worst option, then I guess I can live with it; I just find it icky, and it looks odd to have AMD specifics in a common header.)

Quoted 5 lines

I am not aware of such a discussion.

Sounds like a motivation to delay this portion of the changes in patch #8.

Reinette

Ack, I'll discuss this with James.

I guess the thing to do will be to keep the affected definitions in the x86 headers for now, and carry the exports in James' MPAM branch until we figure out whether it really makes sense to share them.

Cheers
---Dave

author reviewer
#100 lore raw

Re: [PATCH v1 17/31] x86/resctrl: Move mbm_cfg_mask to struct rdt_resource

Hi guys,

Quoted 50 lines · Dave Martin
Quoted 49 lines · Reinette Chatre
Quoted 39 lines · Dave Martin
Quoted 7 lines · Reinette Chatre
Quoted 6 lines · Dave Martin
Quoted 5 lines · Reinette Chatre
Quoted 4 lines · James Morse

The mbm_cfg_mask field lists the bits that user-space can set when configuring an event. This value is output via the last_cmd_status file.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Once the filesystem parts of resctrl are moved to live in /fs/, the struct rdt_hw_resource is inaccessible to the filesystem code. Because this value is output to user-space, it has to be accessible to the filesystem code.

Move it to struct rdt_resource.

Maybe, but the bits as defined by AMD BMEC look rather architecture and bus specific, and I am suspicious that there is no guaranteed clean mapping between MPAM's config and BMEC's config.

MPAM currently just has "reads" and "writes" (or both), though as for BMEC, the meanings of these are not fully defined. I suppose finer filtering granularity might be supported in future (at least, it is not explicitly ruled out).

James' current approach seems to be to pick a single BMEC flag that's in the right sort of area for each MPAM bit (though not equivalent) and translate that bit across to drive a corresponding the MPAM bit. But I'd say that this is arch-specific configuration masquerading as generic configuration IMHO and not really generic at all.

See "untested: arm_mpam: resctrl: Allow monitors to be configured"
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot/v6.7-rc2&id=db0ac51f60675b6c4a54ccd24fa7198ec321c56d

I guess this needs discussion with James, since there will have been additional thought process behind all this that is not captured; either way, I guess it could be resolved after this series, but it will need a decision before the MPAM support is merged (or at least, before MPAM exposes userspace support for event configuration upstream).

Quoted 4 lines

(If this has already been discussed and James' current approach has already been agreed as the least worst option, then I guess I can live with it; I just find it icky, and it looks odd to have AMD specifics in a common header.)

I am not aware of such a discussion.

Sounds like a motivation to delay this portion of the changes in patch #8.

Quoted 8 lines
Quoted 1 line

Reinette

Ack, I'll discuss this with James.

I guess the thing to do will be to keep the affected definitions in the x86 headers for now, and carry the exports in James' MPAM branch until we figure out whether it really makes sense to share them.

I'm afraid this ship has already sailed. Nothing about the 'mbm_total_bytes_config' section of Documentation/arch/x86/resctrl.rst says that this interface is AMD specific. It just happens not to be supported on Intel parts, meaning no-one can tell the difference today.

Because the documentation doesn't say "AMD only" or "consult the lid of the box for the meaning of the bits" - I expect user-space can expect this to work in the same way on any platform that supports these files. As such, it has become resctrl's interface to this stuff. We certainly don't want two different ways of doing this.

As MPAM can configure the monitors like this, I'm stuck between a rock and a hard place. I can't invent something new - because existing user-space expects BMEC, and making these bits generic is being questioned because its secretly AMD specific.

Mapping the BMEC^Wresctrl bits to what MPAM supports is my best attempt at supporting this. The MPAM driver is all about fitting MPAM into a shape that can be exposed via resctrl, so this is hardly out of keeping. (I could make the same argument about the MBA percentages...)

The same argument holds for X86's event numbers. Some agreement on IDs for events is needed between the arch and fs code - and we may as well stick with the X86 numbers today
- its certainly more convenient for the X86 arch code. Where arm64/MPAM or any other architecture extends this, I'd hope to do it via perf where numbered events are already understood to be platform specific, and there is tooling to support this.

For configurable events on non-AMD architectures? We can kick that into the perf weeds - but we need somewhere to hang the fs/resctrl code that drives these files. I think 'is_AMD()' is detestable, and as these bits are uapi, they should be exposed for all architectures that support resctrl.

Thanks,

James

author reviewer
#101 lore raw

PATCH 18/31 x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

In reply to James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 20 ++++++++++++++++----
 include/linux/resctrl.h                |  1 +
 2 files changed, 17 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +16 -4
index 3d3a839eba6b..56a0bfdc11f7 100644
@@ -1685,13 +1685,16 @@ void resctrl_arch_mon_event_config_write(void *info)
 	index = mon_event_config_index_get(mon_info->evtid);
 	if (index == INVALID_CONFIG_INDEX) {
 		pr_warn_once("Invalid event id %d\n", mon_info->evtid);
+		mon_info->err = -EINVAL;
 		return;
 	}
 	wrmsr(MSR_IA32_EVT_CFG_BASE + index, mon_info->mon_config, 0);
+
+	mon_info->err = 0;
 }
 
-static void mbm_config_write_domain(struct rdt_resource *r,
-				    struct rdt_domain *d, u32 evtid, u32 val)
+static int mbm_config_write_domain(struct rdt_resource *r,
+				   struct rdt_domain *d, u32 evtid, u32 val)
 {
 	struct resctrl_mon_config_info mon_info = {0};
 
@@ -1704,7 +1707,7 @@ static void mbm_config_write_domain(struct rdt_resource *r,
 	mon_info.evtid = evtid;
 	mondata_config_read(&mon_info);
 	if (mon_info.mon_config == val)
-		return;
+		return 0;
 
 	mon_info.mon_config = val;
 
@@ -1716,6 +1719,10 @@ static void mbm_config_write_domain(struct rdt_resource *r,
 	 */
 	smp_call_function_any(&d->cpu_mask, resctrl_arch_mon_event_config_write,
 			      &mon_info, 1);
+	if (mon_info.err) {
+		rdt_last_cmd_puts("Invalid event configuration\n");
+		return mon_info.err;
+	}
 
 	/*
 	 * When an Event Configuration is changed, the bandwidth counters
@@ -1727,6 +1734,8 @@ static void mbm_config_write_domain(struct rdt_resource *r,
 	 * mbm_local and mbm_total counts for all the RMIDs.
 	 */
 	resctrl_arch_reset_rmid_all(r, d);
+
+	return 0;
 }
 
 static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
@@ -1734,6 +1743,7 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
 	char *dom_str = NULL, *id_str;
 	unsigned long dom_id, val;
 	struct rdt_domain *d;
+	int err;
 
 	/* Walking r->domains, ensure it can't race with cpuhp */
 	lockdep_assert_cpus_held();
@@ -1765,7 +1775,9 @@ static int mon_config_write(struct rdt_resource *r, char *tok, u32 evtid)
 
 	list_for_each_entry(d, &r->domains, list) {
 		if (d->id == dom_id) {
-			mbm_config_write_domain(r, d, evtid, val);
+			err = mbm_config_write_domain(r, d, evtid, val);
+			if (err)
+				return err;
 			goto next;
 		}
 	}
include/linux/resctrl.h +1 -0
index 8a7367d1ce45..6705d7960dfd 100644
@@ -200,6 +200,7 @@ struct resctrl_mon_config_info {
 	struct rdt_domain   *d;
 	u32                  evtid;
 	u32                  mon_config;
+	int                  err;
 };
 
 /*
Signature · 1 line
2.39.2
maintainer
#102 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

Hi James,

Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

Quoted 2 lines

---

...

include/linux/resctrl.h struct resctrl_mon_config_info { · line 204

Quoted 10 lines
include/linux/resctrl.h +1 -0
index 8a7367d1ce45..6705d7960dfd 100644
@@ -200,6 +200,7 @@ struct resctrl_mon_config_info {
 	struct rdt_domain   *d;
 	u32                  evtid;
 	u32                  mon_config;
+	int                  err;
 };

Please take care to use consistent spacing.

Reinette

reviewer
#103 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

Quoted 21 lines · Reinette Chatre

Hi James,

Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Quoted 7 lines

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

This sounds plausible.

In a recent snapshot of James' MPAM code, it looks like we could be initialising rdt_resource::mbm_cfg_mask when setting up the rdt_resource struct for resctrl, though in fact this information is captured differently right now. I'm sure why (though James may have a reason). [1]

I don't see an obvious reason though why we couldn't set mbm_cfg_mask and detect bad config values globally in mon_config_write(), the same as for the existing AMD BMEC case.

Nothing in the MPAM architecture stops hardware vendors from randomly implementing different capabilities in different components of the system, but provided that we only expose the globally supported subset of event filtering capabilities to resctrl this approach looks workable. This consistent with the James' MPAM code deals with other feature mismatches across the system today.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2#n730

Quoted 18 lines
Quoted 3 lines

---

..

include/linux/resctrl.h struct resctrl_mon_config_info { · line 204

Quoted 10 lines
include/linux/resctrl.h +1 -0
index 8a7367d1ce45..6705d7960dfd 100644
@@ -200,6 +200,7 @@ struct resctrl_mon_config_info {
 	struct rdt_domain   *d;
 	u32                  evtid;
 	u32                  mon_config;
+	int                  err;
 };

Please take care to use consistent spacing.

Quoted 1 line

Reinette

Noted FWIW (though I guess this code might change or go away).

Cheers
---Dave

maintainer
#104 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

Hi Dave,

Quoted 42 lines · Dave Martin
Quoted 21 lines · Reinette Chatre

Hi James,

Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Quoted 7 lines

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

This sounds plausible.

In a recent snapshot of James' MPAM code, it looks like we could be initialising rdt_resource::mbm_cfg_mask when setting up the rdt_resource struct for resctrl, though in fact this information is captured differently right now. I'm sure why (though James may have a reason). [1]

I don't see an obvious reason though why we couldn't set mbm_cfg_mask and detect bad config values globally in mon_config_write(), the same as for the existing AMD BMEC case.

Quoted 8 lines

Nothing in the MPAM architecture stops hardware vendors from randomly implementing different capabilities in different components of the system, but provided that we only expose the globally supported subset of event filtering capabilities to resctrl this approach looks workable. This consistent with the James' MPAM code deals with other feature mismatches across the system today.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2#n730

My response was based on what I understood from the goal of this change as described by the changelog. The patch does not appear to match with the goals stated in changelog.

As I understand the patch it aims to detect when there is an invalid event id. It is not possible for this scenario to occur because this code is always called with a valid event id.

Reinette

reviewer
#105 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

Hi Rainette,

Quoted 58 lines · Reinette Chatre

Hi Dave,

Quoted 42 lines · Dave Martin
Quoted 21 lines · Reinette Chatre

Hi James,

Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Quoted 7 lines

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

This sounds plausible.

In a recent snapshot of James' MPAM code, it looks like we could be initialising rdt_resource::mbm_cfg_mask when setting up the rdt_resource struct for resctrl, though in fact this information is captured differently right now. I'm sure why (though James may have a reason). [1]

I don't see an obvious reason though why we couldn't set mbm_cfg_mask and detect bad config values globally in mon_config_write(), the same as for the existing AMD BMEC case.

Quoted 8 lines

Nothing in the MPAM architecture stops hardware vendors from randomly implementing different capabilities in different components of the system, but provided that we only expose the globally supported subset of event filtering capabilities to resctrl this approach looks workable. This consistent with the James' MPAM code deals with other feature mismatches across the system today.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2#n730

My response was based on what I understood from the goal of this change as described by the changelog. The patch does not appear to match with the goals stated in changelog.

Quoted 5 lines

As I understand the patch it aims to detect when there is an invalid event id. It is not possible for this scenario to occur because this code is always called with a valid event id.

Reinette

I guess this will need discussion with James. FWIW, my impression was that the real goal of this patch was to allow a bad event config to be detected at cross-call time and reported asynchronously. Changes elsewhere look to be there just to make error reporting consistent for other existing paths too.

Either way, I agree that we really ought be be able to detect and report "bad event config" errors synchronously, unless I'm missing something. I'll discuss with James whether we should be dropping this patch.

(For MPAM, I suppose some componets grouped as a single resctrl resource could support event configuration and some not, but I'd hope that we can just not expose event configurability to resctrl at all in that case. A sane system design should not be affected.)

Cheers
---Dave

Quoted 5 lines
maintainer
#106 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

Hi Dave,

Quoted 65 lines · Dave Martin

Hi Rainette,

Quoted 62 lines · Reinette Chatre

Hi Dave,

Quoted 42 lines · Dave Martin
Quoted 21 lines · Reinette Chatre

Hi James,

Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Quoted 7 lines

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

This sounds plausible.

In a recent snapshot of James' MPAM code, it looks like we could be initialising rdt_resource::mbm_cfg_mask when setting up the rdt_resource struct for resctrl, though in fact this information is captured differently right now. I'm sure why (though James may have a reason). [1]

I don't see an obvious reason though why we couldn't set mbm_cfg_mask and detect bad config values globally in mon_config_write(), the same as for the existing AMD BMEC case.

Quoted 8 lines

Nothing in the MPAM architecture stops hardware vendors from randomly implementing different capabilities in different components of the system, but provided that we only expose the globally supported subset of event filtering capabilities to resctrl this approach looks workable. This consistent with the James' MPAM code deals with other feature mismatches across the system today.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2#n730

My response was based on what I understood from the goal of this change as described by the changelog. The patch does not appear to match with the goals stated in changelog.

As I understand the patch it aims to detect when there is an invalid event id. It is not possible for this scenario to occur because this code is always called with a valid event id.

Quoted 7 lines
Quoted 1 line

Reinette

I guess this will need discussion with James. FWIW, my impression was that the real goal of this patch was to allow a bad event config to be detected at cross-call time and reported asynchronously. Changes elsewhere look to be there just to make error reporting consistent for other existing paths too.

How do you interpret "bad event config"?

As I understand it, this patch only sets an error in one scenario:

	 	index = mon_event_config_index_get(mon_info->evtid);
	 	if (index == INVALID_CONFIG_INDEX) {
 			pr_warn_once("Invalid event id %d\n", mon_info->evtid);
			mon_info->err = -EINVAL;
	 		return;

}

When will mon_info->evtid be anything but QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID?

Reinette

reviewer
#107 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

Quoted 85 lines · Reinette Chatre

Hi Dave,

Quoted 65 lines · Dave Martin

Hi Rainette,

Quoted 62 lines · Reinette Chatre

Hi Dave,

Quoted 42 lines · Dave Martin
Quoted 21 lines · Reinette Chatre

Hi James,

Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Quoted 7 lines

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

This sounds plausible.

In a recent snapshot of James' MPAM code, it looks like we could be initialising rdt_resource::mbm_cfg_mask when setting up the rdt_resource struct for resctrl, though in fact this information is captured differently right now. I'm sure why (though James may have a reason). [1]

I don't see an obvious reason though why we couldn't set mbm_cfg_mask and detect bad config values globally in mon_config_write(), the same as for the existing AMD BMEC case.

Quoted 8 lines

Nothing in the MPAM architecture stops hardware vendors from randomly implementing different capabilities in different components of the system, but provided that we only expose the globally supported subset of event filtering capabilities to resctrl this approach looks workable. This consistent with the James' MPAM code deals with other feature mismatches across the system today.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2#n730

My response was based on what I understood from the goal of this change as described by the changelog. The patch does not appear to match with the goals stated in changelog.

As I understand the patch it aims to detect when there is an invalid event id. It is not possible for this scenario to occur because this code is always called with a valid event id.

Quoted 7 lines
Quoted 1 line

Reinette

I guess this will need discussion with James. FWIW, my impression was that the real goal of this patch was to allow a bad event config to be detected at cross-call time and reported asynchronously. Changes elsewhere look to be there just to make error reporting consistent for other existing paths too.

How do you interpret "bad event config"?

As I understand it, this patch only sets an error in one scenario:

	 	index = mon_event_config_index_get(mon_info->evtid);
	 	if (index == INVALID_CONFIG_INDEX) {
 			pr_warn_once("Invalid event id %d\n", mon_info->evtid);
			mon_info->err = -EINVAL;
	 		return;
Quoted 6 lines

}

When will mon_info->evtid be anything but QOS_L3_MBM_TOTAL_EVENT_ID or QOS_L3_MBM_LOCAL_EVENT_ID?

Reinette

I don't know; my reading of this was that since there was a pr_warn() already, and since James was adding the capability to return an error, he figured that a suitable error ought to be returned in this case.

But the real reason for the error return mechanism seems to be resctrl_arch_mon_event_config_write() in the MPAM code, here:

https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/commit/?h=mpam/snapshot/v6.7-rc2&id=db0ac51f60675b6c4a54ccd24fa7198ec321c56d

I agree though that if we set mbm_cfg_mask in the rdt_resource at probe time, the code in mon_config_write() ought to catch such cases cleanly before making the cross-call. So maybe the new mechanism isn't needed.

I think I need to discuss this with James, to figure out if there's any reason why that wouldn't work.

Cheers
---Dave

author reviewer
#108 lore raw

Re: [PATCH v1 18/31] x86/resctrl: Allow resctrl_arch_mon_event_config_write() to return an error

In reply to Reinette Chatre

Hi Reinette,

Quoted 19 lines · Reinette Chatre
Quoted 11 lines · James Morse

resctrl_arch_mon_event_config_write() writes a bitmap of events provided by user-space into the configuration register for the monitors.

This assumes that all architectures support all the features each bit corresponds to.

MPAM can filter monitors based on read, write, or both, but there are many more options in the existing bitmap. To allow this interface to work for machines with MPAM, allow the architecture helper to return an error if an incompatible bitmap is set.

Quoted 6 lines

When valid values are provided, there is no change in behaviour. If an invalid value is provided, currently it is silently ignored, but last_cmd_status is updated. After this change, the parser will stop at the first invalid value and return an error to user-space. This matches the way changes to the schemata file are made.

Quoted 7 lines

Is this needed? With move of mbm_cfg_mask to rdt_resource I expect MPAM would use it to set what the valid values are. With that done, when user space provides a value, mon_config_write() compares user provided value against mbm_cfg_mask and will already return early (before attempting to write to hardware) with error
if value is not supported. This seems to accomplish the goal of this patch?

Aha, this is done in mon_config_write(), not mbm_config_write_domain(). I'd missed that. I'll drop this patch.

Thanks!

James

author reviewer
#109 lore raw

PATCH 19/31 x86/resctrl: Add resctrl_arch_ prefix to pseudo lock functions

In reply to James Morse

resctrl's pseudo lock has some copy-to-cache and measurement functions that are micro-architecture specific. pseudo_lock_fn() is not at all portable. Label these 'resctrl_arch_' so they stay under /arch/x86.

---
 arch/x86/include/asm/resctrl.h            |  5 ++++
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 36 ++++++++++++-----------
 2 files changed, 24 insertions(+), 17 deletions(-)
arch/x86/include/asm/resctrl.h +5 -0
index 50407e83d0ca..a88af68f9fe2 100644
@@ -211,6 +211,11 @@ static inline void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r, int evtid
 static inline void resctrl_arch_mon_ctx_free(struct rdt_resource *r, int evtid,
 					     void *ctx) { };
 
+u64 resctrl_arch_get_prefetch_disable_bits(void);
+int resctrl_arch_pseudo_lock_fn(void *_rdtgrp);
+int resctrl_arch_measure_cycles_lat_fn(void *_plr);
+int resctrl_arch_measure_l2_residency(void *_plr);
+int resctrl_arch_measure_l3_residency(void *_plr);
 void resctrl_cpu_detect(struct cpuinfo_x86 *c);
 
 #else
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +19 -17
index f2315a50ea4f..856beb6f668b 100644
@@ -62,7 +62,8 @@ static const struct class pseudo_lock_class = {
 };
 
 /**
- * get_prefetch_disable_bits - prefetch disable bits of supported platforms
+ * resctrl_arch_get_prefetch_disable_bits - prefetch disable bits of supported
+ *                                          platforms
  * @void: It takes no parameters.
  *
  * Capture the list of platforms that have been validated to support
@@ -76,13 +77,13 @@ static const struct class pseudo_lock_class = {
  * in the SDM.
  *
  * When adding a platform here also add support for its cache events to
- * measure_cycles_perf_fn()
+ * resctrl_arch_measure_l*_residency()
  *
  * Return:
  * If platform is supported, the bits to disable hardware prefetchers, 0
  * if platform is not supported.
  */
-static u64 get_prefetch_disable_bits(void)
+u64 resctrl_arch_get_prefetch_disable_bits(void)
 {
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
 	    boot_cpu_data.x86 != 6)
@@ -410,7 +411,7 @@ static void pseudo_lock_free(struct rdtgroup *rdtgrp)
 }
 
 /**
- * pseudo_lock_fn - Load kernel memory into cache
+ * resctrl_arch_pseudo_lock_fn - Load kernel memory into cache
  * @_rdtgrp: resource group to which pseudo-lock region belongs
  *
  * This is the core pseudo-locking flow.
@@ -428,7 +429,7 @@ static void pseudo_lock_free(struct rdtgroup *rdtgrp)
  *
  * Return: 0. Waiter on waitqueue will be woken on completion.
  */
-static int pseudo_lock_fn(void *_rdtgrp)
+int resctrl_arch_pseudo_lock_fn(void *_rdtgrp)
 {
 	struct rdtgroup *rdtgrp = _rdtgrp;
 	struct pseudo_lock_region *plr = rdtgrp->plr;
@@ -714,7 +715,7 @@ int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp)
 	 * Not knowing the bits to disable prefetching implies that this
 	 * platform does not support Cache Pseudo-Locking.
 	 */
-	prefetch_disable_bits = get_prefetch_disable_bits();
+	prefetch_disable_bits = resctrl_arch_get_prefetch_disable_bits();
 	if (prefetch_disable_bits == 0) {
 		rdt_last_cmd_puts("Pseudo-locking not supported\n");
 		return -EINVAL;
@@ -879,7 +880,8 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
 }
 
 /**
- * measure_cycles_lat_fn - Measure cycle latency to read pseudo-locked memory
+ * resctrl_arch_measure_cycles_lat_fn - Measure cycle latency to read
+ *                                      pseudo-locked memory
  * @_plr: pseudo-lock region to measure
  *
  * There is no deterministic way to test if a memory region is cached. One
@@ -892,7 +894,7 @@ bool rdtgroup_pseudo_locked_in_hierarchy(struct rdt_domain *d)
  *
  * Return: 0. Waiter on waitqueue will be woken on completion.
  */
-static int measure_cycles_lat_fn(void *_plr)
+int resctrl_arch_measure_cycles_lat_fn(void *_plr)
 {
 	struct pseudo_lock_region *plr = _plr;
 	u32 saved_low, saved_high;
@@ -1076,7 +1078,7 @@ static int measure_residency_fn(struct perf_event_attr *miss_attr,
 	return 0;
 }
 
-static int measure_l2_residency(void *_plr)
+int resctrl_arch_measure_l2_residency(void *_plr)
 {
 	struct pseudo_lock_region *plr = _plr;
 	struct residency_counts counts = {0};
@@ -1114,7 +1116,7 @@ static int measure_l2_residency(void *_plr)
 	return 0;
 }
 
-static int measure_l3_residency(void *_plr)
+int resctrl_arch_measure_l3_residency(void *_plr)
 {
 	struct pseudo_lock_region *plr = _plr;
 	struct residency_counts counts = {0};
@@ -1212,18 +1214,18 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel)
 	plr->cpu = cpu;
 
 	if (sel == 1)
-		thread = kthread_create_on_node(measure_cycles_lat_fn, plr,
-						cpu_to_node(cpu),
+		thread = kthread_create_on_node(resctrl_arch_measure_cycles_lat_fn,
+						plr, cpu_to_node(cpu),
 						"pseudo_lock_measure/%u",
 						cpu);
 	else if (sel == 2)
-		thread = kthread_create_on_node(measure_l2_residency, plr,
-						cpu_to_node(cpu),
+		thread = kthread_create_on_node(resctrl_arch_measure_l2_residency,
+						plr, cpu_to_node(cpu),
 						"pseudo_lock_measure/%u",
 						cpu);
 	else if (sel == 3)
-		thread = kthread_create_on_node(measure_l3_residency, plr,
-						cpu_to_node(cpu),
+		thread = kthread_create_on_node(resctrl_arch_measure_l3_residency,
+						plr, cpu_to_node(cpu),
 						"pseudo_lock_measure/%u",
 						cpu);
 	else
@@ -1322,7 +1324,7 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp)
 
 	plr->thread_done = 0;
 
-	thread = kthread_create_on_node(pseudo_lock_fn, rdtgrp,
+	thread = kthread_create_on_node(resctrl_arch_pseudo_lock_fn, rdtgrp,
 					cpu_to_node(plr->cpu),
 					"pseudo_lock/%u", plr->cpu);
 	if (IS_ERR(thread)) {
Signature · 1 line
2.39.2
author reviewer
#110 lore raw

PATCH 20/31 x86/resctrl: Allow an architecture to disable pseudo lock

In reply to James Morse

Pseudo-lock relies on knowledge of the micro-architecture to disable prefetchers etc.

On arm64 these controls are typically secure only, meaning linux can't access them. Arm's cache-lockdown feature works in a very different way. Resctrl's pseudo-lock isn't going to be used on arm64 platforms.

Add a Kconfig symbol that can be selected by the architecture. This enables or disables building of the psuedo_lock.c file, and replaces the functions with stubs. An additional IS_ENABLED() check is needed in rdtgroup_mode_write() so that attempting to enable pseudo-lock reports an "Unknown or unsupported mode" to user-space.

---
 arch/x86/Kconfig                       |  7 ++++
 arch/x86/kernel/cpu/resctrl/Makefile   |  5 +--
 arch/x86/kernel/cpu/resctrl/internal.h | 48 +++++++++++++++++++++-----
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  3 +-
 4 files changed, 52 insertions(+), 11 deletions(-)
arch/x86/Kconfig +7 -0
index 7aed87cbf386..e071e564452e 100644
@@ -481,6 +481,7 @@ config X86_CPU_RESCTRL
 	depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
 	select KERNFS
 	select PROC_CPU_RESCTRL		if PROC_FS
+	select RESCTRL_FS_PSEUDO_LOCK
 	help
 	  Enable x86 CPU resource control support.
 
@@ -506,6 +507,12 @@ config X86_FRED
 	  ring transitions and exception/interrupt handling if the
 	  system supports.
 
+config RESCTRL_FS_PSEUDO_LOCK
+	bool
+	help
+	  Software mechanism to pin data in a cache portion using
+	  micro-architecture specific knowledge.
+
 if X86_32
 config X86_BIGSMP
 	bool "Support for big SMP systems with more than 8 CPUs"
arch/x86/kernel/cpu/resctrl/Makefile +3 -2
index 4a06c37b9cf1..0c13b0befd8a 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_X86_CPU_RESCTRL)	+= core.o rdtgroup.o monitor.o
-obj-$(CONFIG_X86_CPU_RESCTRL)	+= ctrlmondata.o pseudo_lock.o
+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
 CFLAGS_pseudo_lock.o = -I$(src)
arch/x86/kernel/cpu/resctrl/internal.h +40 -8

58 lines not on this page · raw message

arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -1
index 56a0bfdc11f7..9275d6f8a74e 100644
@@ -1452,7 +1452,8 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 				goto out;
 		}
 		rdtgrp->mode = RDT_MODE_EXCLUSIVE;
-	} else if (!strcmp(buf, "pseudo-locksetup")) {
+	} else if (IS_ENABLED(CONFIG_RESCTRL_FS_PSEUDO_LOCK) &&
+		   !strcmp(buf, "pseudo-locksetup")) {
 		ret = rdtgroup_locksetup_enter(rdtgrp);
 		if (ret)
 			goto out;
Signature · 1 line
2.39.2
maintainer
#111 lore raw

Re: [PATCH v1 20/31] x86/resctrl: Allow an architecture to disable pseudo lock

Hi James,

Quoted 9 lines · James Morse

Pseudo-lock relies on knowledge of the micro-architecture to disable prefetchers etc.

On arm64 these controls are typically secure only, meaning linux can't access them. Arm's cache-lockdown feature works in a very different way. Resctrl's pseudo-lock isn't going to be used on arm64 platforms.

Add a Kconfig symbol that can be selected by the architecture. This enables or disables building of the psuedo_lock.c file, and replaces

pseudo_lock.c

Quoted 4 lines

the functions with stubs. An additional IS_ENABLED() check is needed in rdtgroup_mode_write() so that attempting to enable pseudo-lock reports an "Unknown or unsupported mode" to user-space.

I am missing something here. It is not obvious to me why the IS_ENABLED() check is needed. Wouldn't rdtgroup_locksetup_enter()
return -EOPNOTSUPP if CONFIG_RESCTRL_FS_PSEUDO_LOCK is not enabled?

Reinette

reviewer
#112 lore raw

Re: [PATCH v1 20/31] x86/resctrl: Allow an architecture to disable pseudo lock

Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

Pseudo-lock relies on knowledge of the micro-architecture to disable prefetchers etc.

Quoted 8 lines
Quoted 6 lines

On arm64 these controls are typically secure only, meaning linux can't access them. Arm's cache-lockdown feature works in a very different way. Resctrl's pseudo-lock isn't going to be used on arm64 platforms.

Add a Kconfig symbol that can be selected by the architecture. This enables or disables building of the psuedo_lock.c file, and replaces

pseudo_lock.c

Noted.

Quoted 11 lines
Quoted 4 lines

the functions with stubs. An additional IS_ENABLED() check is needed in rdtgroup_mode_write() so that attempting to enable pseudo-lock reports an "Unknown or unsupported mode" to user-space.

I am missing something here. It is not obvious to me why the IS_ENABLED() check is needed. Wouldn't rdtgroup_locksetup_enter()
return -EOPNOTSUPP if CONFIG_RESCTRL_FS_PSEUDO_LOCK is not enabled?

Reinette

Hmm, if I've understood all this correctly, then it looks like the existing code in rdtgroup_mode_write() relies on the dispatched function (rdtgroup_locksetup_enter() etc.) to do an appropriate rdt_last_cmd_puts() on failure. If no function is called at all and the requested mode change is not a no-op or otherwise trivially successful, then it looks like we're supposed to fall into the else clause.

I'd guess James' intent here was to use the fallback else {} to write a suitable status string, while keeping the stub functions as trivial as possible.

Just taking the IS_ENABLED() away would result in error return from the write(), but no suitable last_cmd_status string.

For consistency with the existing x86 implementation, I wonder whether we should put a suitable rdt_last_cmd_puts() in the stub for rdtgroup_locksetup_enter().

There might be other ways to refactor or simplify this, though.

Thoughts?

Cheers
---Dave

maintainer
#113 lore raw

Re: [PATCH v1 20/31] x86/resctrl: Allow an architecture to disable pseudo lock

Hi Dave,

Quoted 45 lines · Dave Martin
Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

Pseudo-lock relies on knowledge of the micro-architecture to disable prefetchers etc.

Quoted 8 lines
Quoted 6 lines

On arm64 these controls are typically secure only, meaning linux can't access them. Arm's cache-lockdown feature works in a very different way. Resctrl's pseudo-lock isn't going to be used on arm64 platforms.

Add a Kconfig symbol that can be selected by the architecture. This enables or disables building of the psuedo_lock.c file, and replaces

pseudo_lock.c

Noted.

Quoted 11 lines
Quoted 4 lines

the functions with stubs. An additional IS_ENABLED() check is needed in rdtgroup_mode_write() so that attempting to enable pseudo-lock reports an "Unknown or unsupported mode" to user-space.

I am missing something here. It is not obvious to me why the IS_ENABLED() check is needed. Wouldn't rdtgroup_locksetup_enter()
return -EOPNOTSUPP if CONFIG_RESCTRL_FS_PSEUDO_LOCK is not enabled?

Reinette

Hmm, if I've understood all this correctly, then it looks like the existing code in rdtgroup_mode_write() relies on the dispatched function (rdtgroup_locksetup_enter() etc.) to do an appropriate rdt_last_cmd_puts() on failure. If no function is called at all and the requested mode change is not a no-op or otherwise trivially successful, then it looks like we're supposed to fall into the else clause.

I'd guess James' intent here was to use the fallback else {} to write a suitable status string, while keeping the stub functions as trivial as possible.

Just taking the IS_ENABLED() away would result in error return from the write(), but no suitable last_cmd_status string.

Quoted 7 lines

For consistency with the existing x86 implementation, I wonder whether we should put a suitable rdt_last_cmd_puts() in the stub for rdtgroup_locksetup_enter().

There might be other ways to refactor or simplify this, though.

Thoughts?

Thank you for digging into this. It was not obvious to me that the changelog referred to the last_cmd_status string. I do not think this warrants making the stubs more complicated.

Reinette

reviewer
#114 lore raw

Re: [PATCH v1 20/31] x86/resctrl: Allow an architecture to disable pseudo lock

Hi Reinette,

Quoted 54 lines · Reinette Chatre

Hi Dave,

Quoted 51 lines · Dave Martin
Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

Pseudo-lock relies on knowledge of the micro-architecture to disable prefetchers etc.

Quoted 8 lines
Quoted 6 lines

On arm64 these controls are typically secure only, meaning linux can't access them. Arm's cache-lockdown feature works in a very different way. Resctrl's pseudo-lock isn't going to be used on arm64 platforms.

Add a Kconfig symbol that can be selected by the architecture. This enables or disables building of the psuedo_lock.c file, and replaces

pseudo_lock.c

Noted.

Quoted 11 lines
Quoted 4 lines

the functions with stubs. An additional IS_ENABLED() check is needed in rdtgroup_mode_write() so that attempting to enable pseudo-lock reports an "Unknown or unsupported mode" to user-space.

I am missing something here. It is not obvious to me why the IS_ENABLED() check is needed. Wouldn't rdtgroup_locksetup_enter()
return -EOPNOTSUPP if CONFIG_RESCTRL_FS_PSEUDO_LOCK is not enabled?

Reinette

Hmm, if I've understood all this correctly, then it looks like the existing code in rdtgroup_mode_write() relies on the dispatched function (rdtgroup_locksetup_enter() etc.) to do an appropriate rdt_last_cmd_puts() on failure. If no function is called at all and the requested mode change is not a no-op or otherwise trivially successful, then it looks like we're supposed to fall into the else clause.

I'd guess James' intent here was to use the fallback else {} to write a suitable status string, while keeping the stub functions as trivial as possible.

Just taking the IS_ENABLED() away would result in error return from the write(), but no suitable last_cmd_status string.

For consistency with the existing x86 implementation, I wonder whether we should put a suitable rdt_last_cmd_puts() in the stub for rdtgroup_locksetup_enter().

There might be other ways to refactor or simplify this, though.

Quoted 8 lines
Quoted 1 line

Thoughts?

Thank you for digging into this. It was not obvious to me that the changelog referred to the last_cmd_status string. I do not think this warrants making the stubs more complicated.

Reinette

OK, I'll leave this as-is for now.

Cheers
---Dave

author reviewer
#115 lore raw

PATCH 21/31 x86/resctrl: Make prefetch_disable_bits belong to the arch code

In reply to James Morse

prefetch_disable_bits is set by rdtgroup_locksetup_enter() from a value provided by the architecture, but is largely read by other architecture helpers.

Instead of exporting this value, make resctrl_arch_get_prefetch_disable_bits() set it so that the other arch-code helpers can use the cached-value.

---
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +8 -5
index 856beb6f668b..5a66e3b2c2ea 100644
@@ -85,6 +85,8 @@ static const struct class pseudo_lock_class = {
  */
 u64 resctrl_arch_get_prefetch_disable_bits(void)
 {
+	prefetch_disable_bits = 0;
+
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
 	    boot_cpu_data.x86 != 6)
 		return 0;
@@ -100,7 +102,8 @@ u64 resctrl_arch_get_prefetch_disable_bits(void)
 		 * 3    DCU IP Prefetcher Disable (R/W)
 		 * 63:4 Reserved
 		 */
-		return 0xF;
+		prefetch_disable_bits = 0xF;
+		break;
 	case INTEL_FAM6_ATOM_GOLDMONT:
 	case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
 		/*
@@ -111,10 +114,11 @@ u64 resctrl_arch_get_prefetch_disable_bits(void)
 		 * 2     DCU Hardware Prefetcher Disable (R/W)
 		 * 63:3  Reserved
 		 */
-		return 0x5;
+		prefetch_disable_bits = 0x5;
+		break;
 	}
 
-	return 0;
+	return prefetch_disable_bits;
 }
 
 /**
@@ -715,8 +719,7 @@ int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp)
 	 * Not knowing the bits to disable prefetching implies that this
 	 * platform does not support Cache Pseudo-Locking.
 	 */
-	prefetch_disable_bits = resctrl_arch_get_prefetch_disable_bits();
-	if (prefetch_disable_bits == 0) {
+	if (resctrl_arch_get_prefetch_disable_bits() == 0) {
 		rdt_last_cmd_puts("Pseudo-locking not supported\n");
 		return -EINVAL;
 	}
Signature · 1 line
2.39.2
author reviewer
#116 lore raw

PATCH 22/31 x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr

In reply to James Morse

resctrl_arch_pseudo_lock_fn() has architecture specific behaviour, and takes a struct rdtgroup as an argument.

After the filesystem code moves to /fs/, the definition of struct rdtgroup will not be available to the architecture code.

The only reason resctrl_arch_pseudo_lock_fn() wants the rdtgroup is for the CLOSID. Embed that in the pseudo_lock_region as a hw_closid, and move the definition of struct pseudo_lock_region to resctrl.h.

---
 arch/x86/include/asm/resctrl.h            |  2 +-
 arch/x86/kernel/cpu/resctrl/internal.h    | 37 ---------------------
 arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 13 ++++----
 include/linux/resctrl.h                   | 39 +++++++++++++++++++++++
 4 files changed, 47 insertions(+), 44 deletions(-)
arch/x86/include/asm/resctrl.h +1 -1
index a88af68f9fe2..9940398e367e 100644
@@ -212,7 +212,7 @@ static inline void resctrl_arch_mon_ctx_free(struct rdt_resource *r, int evtid,
 					     void *ctx) { };
 
 u64 resctrl_arch_get_prefetch_disable_bits(void);
-int resctrl_arch_pseudo_lock_fn(void *_rdtgrp);
+int resctrl_arch_pseudo_lock_fn(void *_plr);
 int resctrl_arch_measure_cycles_lat_fn(void *_plr);
 int resctrl_arch_measure_l2_residency(void *_plr);
 int resctrl_arch_measure_l3_residency(void *_plr);
arch/x86/kernel/cpu/resctrl/internal.h +0 -37
index d6db15839dc4..be4e8f31b127 100644
@@ -182,43 +182,6 @@ struct mongroup {
 	u32			rmid;
 };
 
-/**
- * struct pseudo_lock_region - pseudo-lock region information
- * @s:			Resctrl schema for the resource to which this
- *			pseudo-locked region belongs
- * @d:			RDT domain to which this pseudo-locked region
- *			belongs
- * @cbm:		bitmask of the pseudo-locked region
- * @lock_thread_wq:	waitqueue used to wait on the pseudo-locking thread
- *			completion
- * @thread_done:	variable used by waitqueue to test if pseudo-locking
- *			thread completed
- * @cpu:		core associated with the cache on which the setup code
- *			will be run
- * @line_size:		size of the cache lines
- * @size:		size of pseudo-locked region in bytes
- * @kmem:		the kernel memory associated with pseudo-locked region
- * @minor:		minor number of character device associated with this
- *			region
- * @debugfs_dir:	pointer to this region's directory in the debugfs
- *			filesystem
- * @pm_reqs:		Power management QoS requests related to this region
- */
-struct pseudo_lock_region {
-	struct resctrl_schema	*s;
-	struct rdt_domain	*d;
-	u32			cbm;
-	wait_queue_head_t	lock_thread_wq;
-	int			thread_done;
-	int			cpu;
-	unsigned int		line_size;
-	unsigned int		size;
-	void			*kmem;
-	unsigned int		minor;
-	struct dentry		*debugfs_dir;
-	struct list_head	pm_reqs;
-};
-
 /**
  * struct rdtgroup - store rdtgroup's data in resctrl file system.
  * @kn:				kernfs node
arch/x86/kernel/cpu/resctrl/pseudo_lock.c +7 -6
index 5a66e3b2c2ea..ba51ab1f70e6 100644
@@ -416,7 +416,7 @@ static void pseudo_lock_free(struct rdtgroup *rdtgrp)
 
 /**
  * resctrl_arch_pseudo_lock_fn - Load kernel memory into cache
- * @_rdtgrp: resource group to which pseudo-lock region belongs
+ * @_plr: the pseudo-lock region descriptor
  *
  * This is the core pseudo-locking flow.
  *
@@ -433,10 +433,9 @@ static void pseudo_lock_free(struct rdtgroup *rdtgrp)
  *
  * Return: 0. Waiter on waitqueue will be woken on completion.
  */
-int resctrl_arch_pseudo_lock_fn(void *_rdtgrp)
+int resctrl_arch_pseudo_lock_fn(void *_plr)
 {
-	struct rdtgroup *rdtgrp = _rdtgrp;
-	struct pseudo_lock_region *plr = rdtgrp->plr;
+	struct pseudo_lock_region *plr = _plr;
 	u32 rmid_p, closid_p;
 	unsigned long i;
 	u64 saved_msr;
@@ -496,7 +495,8 @@ int resctrl_arch_pseudo_lock_fn(void *_rdtgrp)
 	 * pseudo-locked followed by reading of kernel memory to load it
 	 * into the cache.
 	 */
-	__wrmsr(MSR_IA32_PQR_ASSOC, rmid_p, rdtgrp->closid);
+	__wrmsr(MSR_IA32_PQR_ASSOC, rmid_p, plr->closid);
+
 	/*
 	 * Cache was flushed earlier. Now access kernel memory to read it
 	 * into cache region associated with just activated plr->closid.
@@ -1327,7 +1327,8 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp)
 
 	plr->thread_done = 0;
 
-	thread = kthread_create_on_node(resctrl_arch_pseudo_lock_fn, rdtgrp,
+	plr->closid = rdtgrp->closid;
+	thread = kthread_create_on_node(resctrl_arch_pseudo_lock_fn, plr,
 					cpu_to_node(plr->cpu),
 					"pseudo_lock/%u", plr->cpu);
 	if (IS_ERR(thread)) {
include/linux/resctrl.h +39 -0
index 6705d7960dfd..3de5bc63ace0 100644
@@ -25,6 +25,45 @@ int proc_resctrl_show(struct seq_file *m,
 /* max value for struct rdt_domain's mbps_val */
 #define MBA_MAX_MBPS   U32_MAX
 
+/**
+ * struct pseudo_lock_region - pseudo-lock region information
+ * @s:			Resctrl schema for the resource to which this
+ *			pseudo-locked region belongs
+ * @closid:		The closid that this pseudo-locked region uses
+ * @d:			RDT domain to which this pseudo-locked region
+ *			belongs
+ * @cbm:		bitmask of the pseudo-locked region
+ * @lock_thread_wq:	waitqueue used to wait on the pseudo-locking thread
+ *			completion
+ * @thread_done:	variable used by waitqueue to test if pseudo-locking
+ *			thread completed
+ * @cpu:		core associated with the cache on which the setup code
+ *			will be run
+ * @line_size:		size of the cache lines
+ * @size:		size of pseudo-locked region in bytes
+ * @kmem:		the kernel memory associated with pseudo-locked region
+ * @minor:		minor number of character device associated with this
+ *			region
+ * @debugfs_dir:	pointer to this region's directory in the debugfs
+ *			filesystem
+ * @pm_reqs:		Power management QoS requests related to this region
+ */
+struct pseudo_lock_region {
+	struct resctrl_schema	*s;
+	u32			closid;
+	struct rdt_domain	*d;
+	u32			cbm;
+	wait_queue_head_t	lock_thread_wq;
+	int			thread_done;
+	int			cpu;
+	unsigned int		line_size;
+	unsigned int		size;
+	void			*kmem;
+	unsigned int		minor;
+	struct dentry		*debugfs_dir;
+	struct list_head	pm_reqs;
+};
+
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded
Signature · 1 line
2.39.2
maintainer
#117 lore raw

Re: [PATCH v1 22/31] x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr

Hi James,

Quoted 8 lines · James Morse

resctrl_arch_pseudo_lock_fn() has architecture specific behaviour, and takes a struct rdtgroup as an argument.

After the filesystem code moves to /fs/, the definition of struct rdtgroup will not be available to the architecture code.

The only reason resctrl_arch_pseudo_lock_fn() wants the rdtgroup is for the CLOSID. Embed that in the pseudo_lock_region as a hw_closid,

Above creates expectation that the new member will be named hw_closid, but that is not what the code does.

Quoted 3 lines

and move the definition of struct pseudo_lock_region to resctrl.h.

...

Quoted 40 lines
include/linux/resctrl.h +32 -0
index 6705d7960dfd..3de5bc63ace0 100644
@@ -25,6 +25,45 @@ int proc_resctrl_show(struct seq_file *m,
 /* max value for struct rdt_domain's mbps_val */
 #define MBA_MAX_MBPS   U32_MAX
 
+/**
+ * struct pseudo_lock_region - pseudo-lock region information
+ * @s:			Resctrl schema for the resource to which this
+ *			pseudo-locked region belongs
+ * @closid:		The closid that this pseudo-locked region uses
+ * @d:			RDT domain to which this pseudo-locked region
+ *			belongs
+ * @cbm:		bitmask of the pseudo-locked region
+ * @lock_thread_wq:	waitqueue used to wait on the pseudo-locking thread
+ *			completion
+ * @thread_done:	variable used by waitqueue to test if pseudo-locking
+ *			thread completed
+ * @cpu:		core associated with the cache on which the setup code
+ *			will be run
+ * @line_size:		size of the cache lines
+ * @size:		size of pseudo-locked region in bytes
+ * @kmem:		the kernel memory associated with pseudo-locked region
+ * @minor:		minor number of character device associated with this
+ *			region
+ * @debugfs_dir:	pointer to this region's directory in the debugfs
+ *			filesystem
+ * @pm_reqs:		Power management QoS requests related to this region
+ */
+struct pseudo_lock_region {
+	struct resctrl_schema	*s;
+	u32			closid;
+	struct rdt_domain	*d;
+	u32			cbm;
+	wait_queue_head_t	lock_thread_wq;
+	int			thread_done;
+	int			cpu;
+	unsigned int		line_size;

include/linux/resctrl.h int proc_resctrl_show(struct seq_file *m, · line 69

Quoted 10 lines
include/linux/resctrl.h +7 -0
+	unsigned int		size;
+	void			*kmem;
+	unsigned int		minor;
+	struct dentry		*debugfs_dir;
+	struct list_head	pm_reqs;
+};
+
 /**
  * struct resctrl_staged_config - parsed configuration to be applied
  * @new_ctrl:		new ctrl value to be loaded

Reinette

reviewer
#118 lore raw

Re: [PATCH v1 22/31] x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr

Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

resctrl_arch_pseudo_lock_fn() has architecture specific behaviour, and takes a struct rdtgroup as an argument.

Quoted 8 lines
Quoted 5 lines

After the filesystem code moves to /fs/, the definition of struct rdtgroup will not be available to the architecture code.

The only reason resctrl_arch_pseudo_lock_fn() wants the rdtgroup is for the CLOSID. Embed that in the pseudo_lock_region as a hw_closid,

Above creates expectation that the new member will be named hw_closid, but that is not what the code does.

I'll flag this for review, but I'd guess that this can probably just be "closid". I'll make a note to consider what needs to change to make things consistent between the patch and commit message.

James might have had other ideas, connected with the remapping done for CDP emulation causing the resctrl closid being different from the actual value used by the hardware, at least for MPAM (see my response on patch 24). I don't fully understand how this works for x86 though.

So long as functionality is unaffected, and this patch is introducing no new confusion that wasn't there beforehand, the exact name may not matter too much(?)

Did you have other concerns here?

Cheers
---Dave

maintainer
#119 lore raw

Re: [PATCH v1 22/31] x86/resctrl: Make resctrl_arch_pseudo_lock_fn() take a plr

Hi Dave,

Quoted 20 lines · Dave Martin
Quoted 6 lines · Reinette Chatre

Hi James,

Quoted 3 lines · James Morse

resctrl_arch_pseudo_lock_fn() has architecture specific behaviour, and takes a struct rdtgroup as an argument.

Quoted 8 lines
Quoted 5 lines

After the filesystem code moves to /fs/, the definition of struct rdtgroup will not be available to the architecture code.

The only reason resctrl_arch_pseudo_lock_fn() wants the rdtgroup is for the CLOSID. Embed that in the pseudo_lock_region as a hw_closid,

Above creates expectation that the new member will be named hw_closid, but that is not what the code does.

I'll flag this for review, but I'd guess that this can probably just be "closid". I'll make a note to consider what needs to change to make things consistent between the patch and commit message.

Quoted 8 lines

James might have had other ideas, connected with the remapping done for CDP emulation causing the resctrl closid being different from the actual value used by the hardware, at least for MPAM (see my response on patch 24). I don't fully understand how this works for x86 though.

So long as functionality is unaffected, and this patch is introducing no new confusion that wasn't there beforehand, the exact name may not matter too much(?)

closid sounds good. It may be a good match for what is expected to be in general/fs code.

Quoted 2 lines

Did you have other concerns here?

No.

Reinette

author reviewer
#120 lore raw

PATCH 23/31 x86/resctrl: Move thread_throttle_mode_init() to be managed by resctrl

In reply to James Morse

thread_throttle_mode_init() is called from the architecture specific code to make the 'thread_throttle_mode' file visible. The architecture specific code has already set the membw.throttle_mode in the rdt_resource.

This doesn't need to be specific to the architecture, the throttle_mode can be used by resctrl to determine if the 'thread_throttle_mode' file should be visible.

Call thread_throttle_mode_init() from resctrl_setup(), check the membw.throttle_mode on the MBA resource. This avoids publishing an extra function between the architecture and filesystem code.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 1 -
 arch/x86/kernel/cpu/resctrl/internal.h | 1 -
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 9 ++++++++-
 3 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +0 -1
index 824a94593e9d..7cdecd8ac00b 100644
@@ -227,7 +227,6 @@ static bool __get_mem_config_intel(struct rdt_resource *r)
 		r->membw.throttle_mode = THREAD_THROTTLE_PER_THREAD;
 	else
 		r->membw.throttle_mode = THREAD_THROTTLE_MAX;
-	thread_throttle_mode_init();
 
 	r->alloc_capable = true;
 
arch/x86/kernel/cpu/resctrl/internal.h +0 -1
index be4e8f31b127..e849d4407769 100644
@@ -478,7 +478,6 @@ void cqm_handle_limbo(struct work_struct *work);
 bool has_busy_rmid(struct rdt_domain *d);
 void __check_limbo(struct rdt_domain *d, bool force_free);
 void rdt_domain_reconfigure_cdp(struct rdt_resource *r);
-void __init thread_throttle_mode_init(void);
 void mbm_config_rftype_init(const char *config);
 void rdt_staged_configs_clear(void);
 bool closid_allocated(unsigned int closid);
arch/x86/kernel/cpu/resctrl/rdtgroup.c +8 -1
index 9275d6f8a74e..702a94fad6db 100644
@@ -2069,10 +2069,15 @@ static struct rftype *rdtgroup_get_rftype_by_name(const char *name)
 	return NULL;
 }
 
-void __init thread_throttle_mode_init(void)
+static void __init thread_throttle_mode_init(void)
 {
+	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 	struct rftype *rft;
 
+	if (!r->alloc_capable ||
+	    r->membw.throttle_mode == THREAD_THROTTLE_UNDEFINED)
+		return;
+
 	rft = rdtgroup_get_rftype_by_name("thread_throttle_mode");
 	if (!rft)
 		return;
@@ -4194,6 +4199,8 @@ int __init resctrl_init(void)
 
 	rdtgroup_setup_default();
 
+	thread_throttle_mode_init();
+
 	ret = resctrl_mon_resource_init();
 	if (ret)
 		return ret;
Signature · 1 line
2.39.2
author reviewer
#121 lore raw

PATCH 24/31 x86/resctrl: Move get_config_index() to a header

In reply to James Morse

get_config_index() is used by the architecture specific code to map a CLOSID+type pair to an index in the configuration arrays.

MPAM needs to do this too to preserve the ABI to user-space, there is no reason to do it differently.

Move the helper to a header file.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 +++----------------
 include/linux/resctrl.h                   | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +3 -16
index 3603ade95f1d..b4627ae19291 100644
@@ -277,19 +277,6 @@ static int parse_line(char *line, struct resctrl_schema *s,
 	return -EINVAL;
 }
 
-static u32 get_config_index(u32 closid, enum resctrl_conf_type type)
-{
-	switch (type) {
-	default:
-	case CDP_NONE:
-		return closid;
-	case CDP_CODE:
-		return closid * 2 + 1;
-	case CDP_DATA:
-		return closid * 2;
-	}
-}
-
 static bool apply_config(struct rdt_hw_domain *hw_dom,
 			 struct resctrl_staged_config *cfg, u32 idx,
 			 cpumask_var_t cpu_mask)
@@ -311,7 +298,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
-	u32 idx = get_config_index(closid, t);
+	u32 idx = resctrl_get_config_index(closid, t);
 	struct msr_param msr_param;
 
 	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
@@ -351,7 +338,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 			if (!cfg->have_new_ctrl)
 				continue;
 
-			idx = get_config_index(closid, t);
+			idx = resctrl_get_config_index(closid, t);
 			if (!apply_config(hw_dom, cfg, idx, cpu_mask))
 				continue;
 
@@ -476,7 +463,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type)
 {
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
-	u32 idx = get_config_index(closid, type);
+	u32 idx = resctrl_get_config_index(closid, type);
 
 	return hw_dom->ctrl_val[idx];
 }
include/linux/resctrl.h +15 -0
index 3de5bc63ace0..73c111963433 100644
@@ -258,6 +258,21 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
 void resctrl_arch_mon_event_config_write(void *info);
 void resctrl_arch_mon_event_config_read(void *info);
 
+/* For use by arch code to remap resctrl's smaller CDP CLOSID range */
+static inline u32 resctrl_get_config_index(u32 closid,
+					   enum resctrl_conf_type type)
+{
+	switch (type) {
+	default:
+	case CDP_NONE:
+		return closid;
+	case CDP_CODE:
+			return (closid * 2) + 1;
+	case CDP_DATA:
+			return (closid * 2);
+	}
+}
+
 /*
  * Update the ctrl_val and apply this config right now.
  * Must be called on one of the domain's CPUs.
Signature · 1 line
2.39.2
maintainer
#122 lore raw

Re: [PATCH v1 24/31] x86/resctrl: Move get_config_index() to a header

Hi James,

Quoted 77 lines · James Morse

get_config_index() is used by the architecture specific code to map a CLOSID+type pair to an index in the configuration arrays.

MPAM needs to do this too to preserve the ABI to user-space, there is no reason to do it differently.

Move the helper to a header file.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 +++----------------
 include/linux/resctrl.h                   | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/resctrl/ctrlmondata.c +3 -16
index 3603ade95f1d..b4627ae19291 100644
@@ -277,19 +277,6 @@ static int parse_line(char *line, struct resctrl_schema *s,
 	return -EINVAL;
 }
 
-static u32 get_config_index(u32 closid, enum resctrl_conf_type type)
-{
-	switch (type) {
-	default:
-	case CDP_NONE:
-		return closid;
-	case CDP_CODE:
-		return closid * 2 + 1;
-	case CDP_DATA:
-		return closid * 2;
-	}
-}
-
 static bool apply_config(struct rdt_hw_domain *hw_dom,
 			 struct resctrl_staged_config *cfg, u32 idx,
 			 cpumask_var_t cpu_mask)
@@ -311,7 +298,7 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d,
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
-	u32 idx = get_config_index(closid, t);
+	u32 idx = resctrl_get_config_index(closid, t);
 	struct msr_param msr_param;
 
 	if (!cpumask_test_cpu(smp_processor_id(), &d->cpu_mask))
@@ -351,7 +338,7 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 			if (!cfg->have_new_ctrl)
 				continue;
 
-			idx = get_config_index(closid, t);
+			idx = resctrl_get_config_index(closid, t);
 			if (!apply_config(hw_dom, cfg, idx, cpu_mask))
 				continue;
 
@@ -476,7 +463,7 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d,
 			    u32 closid, enum resctrl_conf_type type)
 {
 	struct rdt_hw_domain *hw_dom = resctrl_to_arch_dom(d);
-	u32 idx = get_config_index(closid, type);
+	u32 idx = resctrl_get_config_index(closid, type);
 
 	return hw_dom->ctrl_val[idx];
 }
include/linux/resctrl.h +4 -0
index 3de5bc63ace0..73c111963433 100644
@@ -258,6 +258,21 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
 void resctrl_arch_mon_event_config_write(void *info);
 void resctrl_arch_mon_event_config_read(void *info);
 
+/* For use by arch code to remap resctrl's smaller CDP CLOSID range */
+static inline u32 resctrl_get_config_index(u32 closid,
+					   enum resctrl_conf_type type)
+{

include/linux/resctrl.h bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); · line 274

Quoted 10 lines
include/linux/resctrl.h +10 -0
+	switch (type) {
+	default:
+	case CDP_NONE:
+		return closid;
+	case CDP_CODE:
+			return (closid * 2) + 1;
+	case CDP_DATA:
+			return (closid * 2);
+	}
+}

(please check the tabs)

This change is unexpected to me. Could you please elaborate how MPAM's variant of CDP works?

Thank you very much.

Reinette

reviewer
#123 lore raw

Re: [PATCH v1 24/31] x86/resctrl: Move get_config_index() to a header

Quoted 16 lines · Reinette Chatre

Hi James,

Quoted 13 lines · James Morse

get_config_index() is used by the architecture specific code to map a CLOSID+type pair to an index in the configuration arrays.

MPAM needs to do this too to preserve the ABI to user-space, there is no reason to do it differently.

Move the helper to a header file.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 +++----------------
 include/linux/resctrl.h                   | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)

[...]

Quoted 8 lines
Quoted 8 lines
include/linux/resctrl.h +0 -0
index 3de5bc63ace0..73c111963433 100644
@@ -258,6 +258,21 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
 void resctrl_arch_mon_event_config_write(void *info);
 void resctrl_arch_mon_event_config_read(void *info);
 
Quoted 16 lines
Quoted 4 lines
include/linux/resctrl.h +4 -0
+/* For use by arch code to remap resctrl's smaller CDP CLOSID range */
+static inline u32 resctrl_get_config_index(u32 closid,
+					   enum resctrl_conf_type type)
+{

include/linux/resctrl.h bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); · line 274

Quoted 10 lines
include/linux/resctrl.h +10 -0
+	switch (type) {
+	default:
+	case CDP_NONE:
+		return closid;
+	case CDP_CODE:
+			return (closid * 2) + 1;
+	case CDP_DATA:
+			return (closid * 2);
+	}
+}

(please check the tabs)

Noted. I also see that redundant parentheses seem spuriously added compared with the original version of this moved code. I can make a note to drop them if you prefer.

Quoted 6 lines

This change is unexpected to me. Could you please elaborate how MPAM's variant of CDP works?

Thank you very much.

Reinette

Note: I haven't discussed this specifically with James, so the following is my best guess at the rationale... With that in mind:

For MPAM, CDP isn't a special mode; instead, the PARTIDs for instructions and data are always configured independently in the CPU. If resctrl is not configured for CDP, we simply program the same PARTID value both for instructions and data on task switch.

For a given resctrl control group we could pick two random unrelated PARTIDs, but there seems to be no advantage in doing that since resctrl enables cdp globally or not, and we would require more effort to translate resctrl closids to PARTIDs if we didn't pair the IDs up systematically.

(See [1], [2] in James' snapshot, which illustrate how he proposes to do it.)

So, we may as well stick with the same scheme already established for
x86: nothing forces us to do that, but it looks simpler than the alternatives. I think that's the idea, anyway.

Then, if the same scheme is used by multiple arches (and 100% of the arches currently known to resctrl), it probably makes sense to share the definition of the mapping at least as a default for arches that don't have their own different ways of doing it.

Does this make sense?

I can recommend adding some of this rationale to the commit message if it helps (and assuming I'm right!)

Cheers
---Dave

[1] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_resctrl.c?h=mpam/snapshot/v6.7-rc2#n206
[2] https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/arch/arm64/include/asm/mpam.h?h=mpam/snapshot/v6.7-rc2#n146

maintainer
#124 lore raw

Re: [PATCH v1 24/31] x86/resctrl: Move get_config_index() to a header

Hi Dave,

Quoted 78 lines · Dave Martin
Quoted 16 lines · Reinette Chatre

Hi James,

Quoted 13 lines · James Morse

get_config_index() is used by the architecture specific code to map a CLOSID+type pair to an index in the configuration arrays.

MPAM needs to do this too to preserve the ABI to user-space, there is no reason to do it differently.

Move the helper to a header file.

---
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 19 +++----------------
 include/linux/resctrl.h                   | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)

[...]

Quoted 8 lines
Quoted 8 lines
include/linux/resctrl.h +0 -0
index 3de5bc63ace0..73c111963433 100644
@@ -258,6 +258,21 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
 void resctrl_arch_mon_event_config_write(void *info);
 void resctrl_arch_mon_event_config_read(void *info);
 
Quoted 16 lines
Quoted 4 lines
include/linux/resctrl.h +4 -0
+/* For use by arch code to remap resctrl's smaller CDP CLOSID range */
+static inline u32 resctrl_get_config_index(u32 closid,
+					   enum resctrl_conf_type type)
+{

include/linux/resctrl.h bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); · line 274

Quoted 10 lines
include/linux/resctrl.h +10 -0
+	switch (type) {
+	default:
+	case CDP_NONE:
+		return closid;
+	case CDP_CODE:
+			return (closid * 2) + 1;
+	case CDP_DATA:
+			return (closid * 2);
+	}
+}

(please check the tabs)

Noted. I also see that redundant parentheses seem spuriously added compared with the original version of this moved code. I can make a note to drop them if you prefer.

Quoted 6 lines

This change is unexpected to me. Could you please elaborate how MPAM's variant of CDP works?

Thank you very much.

Reinette

Note: I haven't discussed this specifically with James, so the following is my best guess at the rationale... With that in mind:

For MPAM, CDP isn't a special mode; instead, the PARTIDs for instructions and data are always configured independently in the CPU. If resctrl is not configured for CDP, we simply program the same PARTID value both for instructions and data on task switch.

For a given resctrl control group we could pick two random unrelated PARTIDs, but there seems to be no advantage in doing that since resctrl enables cdp globally or not, and we would require more effort to translate resctrl closids to PARTIDs if we didn't pair the IDs up systematically.

(See [1], [2] in James' snapshot, which illustrate how he proposes to do it.)

So, we may as well stick with the same scheme already established for
x86: nothing forces us to do that, but it looks simpler than the alternatives. I think that's the idea, anyway.

Quoted 6 lines

Then, if the same scheme is used by multiple arches (and 100% of the arches currently known to resctrl), it probably makes sense to share the definition of the mapping at least as a default for arches that don't have their own different ways of doing it.

Does this make sense?

It does, thank you very much.

Quoted 3 lines

I can recommend adding some of this rationale to the commit message if it helps (and assuming I'm right!)

Sounds good, thank you.

Reinette

author reviewer
#125 lore raw

Re: [PATCH v1 24/31] x86/resctrl: Move get_config_index() to a header

Hi guys,

Quoted 69 lines · Reinette Chatre
Quoted 68 lines · Dave Martin
Quoted 17 lines · Reinette Chatre
Quoted 16 lines · James Morse

get_config_index() is used by the architecture specific code to map a CLOSID+type pair to an index in the configuration arrays.

MPAM needs to do this too to preserve the ABI to user-space, there is no reason to do it differently.

Move the helper to a header file.

include/linux/resctrl.h +0 -0
index 3de5bc63ace0..73c111963433 100644
@@ -258,6 +258,21 @@ bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt);
 void resctrl_arch_mon_event_config_write(void *info);
 void resctrl_arch_mon_event_config_read(void *info);
 
Quoted 16 lines
Quoted 4 lines
include/linux/resctrl.h +4 -0
+/* For use by arch code to remap resctrl's smaller CDP CLOSID range */
+static inline u32 resctrl_get_config_index(u32 closid,
+					   enum resctrl_conf_type type)
+{

include/linux/resctrl.h bool resctrl_arch_is_evt_configurable(enum resctrl_event_id evt); · line 274

Quoted 10 lines
include/linux/resctrl.h +10 -0
+	switch (type) {
+	default:
+	case CDP_NONE:
+		return closid;
+	case CDP_CODE:
+			return (closid * 2) + 1;
+	case CDP_DATA:
+			return (closid * 2);
+	}
+}

(please check the tabs)

Noted. I also see that redundant parentheses seem spuriously added compared with the original version of this moved code. I can make a note to drop them if you prefer.

Quoted 6 lines

This change is unexpected to me. Could you please elaborate how MPAM's variant of CDP works?

Thank you very much.

Reinette

Note: I haven't discussed this specifically with James, so the following is my best guess at the rationale... With that in mind:

For MPAM, CDP isn't a special mode; instead, the PARTIDs for instructions and data are always configured independently in the CPU. If resctrl is not configured for CDP, we simply program the same PARTID value both for instructions and data on task switch.

For a given resctrl control group we could pick two random unrelated PARTIDs, but there seems to be no advantage in doing that since resctrl enables cdp globally or not, and we would require more effort to translate resctrl closids to PARTIDs if we didn't pair the IDs up systematically.

(See [1], [2] in James' snapshot, which illustrate how he proposes to do it.)

So, we may as well stick with the same scheme already established for
x86: nothing forces us to do that, but it looks simpler than the alternatives. I think that's the idea, anyway.

Quoted 8 lines
Quoted 6 lines

Then, if the same scheme is used by multiple arches (and 100% of the arches currently known to resctrl), it probably makes sense to share the definition of the mapping at least as a default for arches that don't have their own different ways of doing it.

Does this make sense?

It does, thank you very much.

Thanks for the summary Dave - spot on!

There are some additional headaches for MPAM to provide the counters when CDP emulation is
enabled: because two CLOSID/PARTID are in use, two counters have to be allocated and read, and their counters summed. This is all done behind the scenes in the MPAM driver.

MBA gets even more fun - as there is no MBA_CODE/MBA_DATA - but whatever MPAM is using to back the MBA resource sees two CLOSID/PARTID. The result is the MPAM driver has to replay configuration changes to the second CLOSID/PARTID. Again, this is done behind the scenes in the MPAM driver.

(and as we're on this topic: I've had requests to make the counters available for code and data separately - I don't intend to do this in resctrl as it wouldn't be portable to x86. I'm looking at doing this with the perf pmu stuff)

Thanks,

James

author reviewer
#126 lore raw

PATCH 25/31 x86/resctrl: Claim get_domain_from_cpu() for resctrl

In reply to James Morse

get_domain_from_cpu() is a handy helper that both the arch code and resctrl need to use. Rename it resctrl_get_domain_from_cpu() so it gets moved out to /fs, and exported back to the arch code.

---
 arch/x86/kernel/cpu/resctrl/core.c     | 15 +--------------
 arch/x86/kernel/cpu/resctrl/internal.h |  1 -
 arch/x86/kernel/cpu/resctrl/monitor.c  |  2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |  2 +-
 include/linux/resctrl.h                | 19 +++++++++++++++++++
 5 files changed, 22 insertions(+), 17 deletions(-)
arch/x86/kernel/cpu/resctrl/core.c +1 -14
index 7cdecd8ac00b..f94ad04023c3 100644
@@ -355,19 +355,6 @@ cat_wrmsr(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
 		wrmsrl(hw_res->msr_base + i, hw_dom->ctrl_val[i]);
 }
 
-struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r)
-{
-	struct rdt_domain *d;
-
-	list_for_each_entry(d, &r->domains, list) {
-		/* Find the domain that contains this CPU */
-		if (cpumask_test_cpu(cpu, &d->cpu_mask))
-			return d;
-	}
-
-	return NULL;
-}
-
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r)
 {
 	return resctrl_to_arch_res(r)->num_closid;
@@ -381,7 +368,7 @@ void rdt_ctrl_update(void *arg)
 	int cpu = smp_processor_id();
 	struct rdt_domain *d;
 
-	d = get_domain_from_cpu(cpu, r);
+	d = resctrl_get_domain_from_cpu(cpu, r);
 	if (d) {
 		hw_res->msr_update(d, m, r);
 		return;
arch/x86/kernel/cpu/resctrl/internal.h +0 -1
index e849d4407769..3a3962736061 100644
@@ -452,7 +452,6 @@ unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r, struct rdt_domain *d,
 				  unsigned long cbm);
 enum rdtgrp_mode rdtgroup_mode_by_closid(int closid);
 int rdtgroup_tasks_assigned(struct rdtgroup *r);
-struct rdt_domain *get_domain_from_cpu(int cpu, struct rdt_resource *r);
 int closids_supported(void);
 void closid_free(int closid);
 int alloc_rmid(u32 closid);
arch/x86/kernel/cpu/resctrl/monitor.c +1 -1
index 287fb0a5f060..8b316d9acc3b 100644
@@ -676,7 +676,7 @@ static void update_mba_bw(struct rdtgroup *rgrp, struct rdt_domain *dom_mbm)
 	idx = resctrl_arch_rmid_idx_encode(closid, rmid);
 	pmbm_data = &dom_mbm->mbm_local[idx];
 
-	dom_mba = get_domain_from_cpu(smp_processor_id(), r_mba);
+	dom_mba = resctrl_get_domain_from_cpu(smp_processor_id(), r_mba);
 	if (!dom_mba) {
 		pr_warn_once("Failure to get domain for MBA update\n");
 		return;
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
index 702a94fad6db..085fb9c2333a 100644
@@ -4165,7 +4165,7 @@ void resctrl_offline_cpu(unsigned int cpu)
 	if (!l3->mon_capable)
 		goto out_unlock;
 
-	d = get_domain_from_cpu(cpu, l3);
+	d = resctrl_get_domain_from_cpu(cpu, l3);
 	if (d) {
 		if (resctrl_is_mbm_enabled() && cpu == d->mbm_work_cpu) {
 			cancel_delayed_work(&d->mbm_over);
include/linux/resctrl.h +19 -0
index 73c111963433..84420253dc05 100644
@@ -2,6 +2,7 @@
 #ifndef _RESCTRL_H
 #define _RESCTRL_H
 
+#include <linux/cpu.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/pid.h>
@@ -273,6 +274,24 @@ static inline u32 resctrl_get_config_index(u32 closid,
 	}
 }
 
+/*
+ * Caller must hold the cpuhp read lock to prevent the struct rdt_domain being
+ * freed.
+ */
+static inline struct rdt_domain *
+resctrl_get_domain_from_cpu(int cpu, struct rdt_resource *r)
+{
+	struct rdt_domain *d;
+
+	list_for_each_entry_rcu(d, &r->domains, list) {
+		/* Find the domain that contains this CPU */
+		if (cpumask_test_cpu(cpu, &d->cpu_mask))
+			return d;
+	}
+
+	return NULL;
+}
+
 /*
  * Update the ctrl_val and apply this config right now.
  * Must be called on one of the domain's CPUs.
Signature · 1 line
2.39.2
author reviewer
#127 lore raw

PATCH 26/31 x86/resctrl: Describe resctrl's bitmap size assumptions

In reply to James Morse

resctrl operates on configuration bitmaps and a bitmap of allocated CLOSID, both are stored in a u32.

MPAM supports configuration/portion bitmaps and PARTIDs larger than will fit in a u32.

Add some preprocessor values that make it clear why MPAM clamps some of these values. This will make it easier to find code related to these values if this resctrl behaviour ever changes.

---
 include/linux/resctrl.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/resctrl.h +11 -0
index 84420253dc05..f463fb949677 100644
@@ -26,6 +26,17 @@ int proc_resctrl_show(struct seq_file *m,
 /* max value for struct rdt_domain's mbps_val */
 #define MBA_MAX_MBPS   U32_MAX
 
+/*
+ * Resctrl uses a u32 as a closid bitmap. The maximum closid is 32.
+ */
+#define RESCTRL_MAX_CLOSID		32
+
+/*
+ * Resctrl uses u32 to hold the user-space config. The maximum bitmap size is
+ * 32.
+ */
+#define RESCTRL_MAX_CBM			32
+
 /**
  * struct pseudo_lock_region - pseudo-lock region information
  * @s:			Resctrl schema for the resource to which this
Signature · 1 line
2.39.2
author reviewer
#128 lore raw

PATCH 27/31 x86/resctrl: Rename resctrl_sched_in() to begin resctrl_arch_

In reply to 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 concistency. 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
index 9940398e367e..491342f56811 100644
@@ -177,7 +177,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);
@@ -220,7 +220,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
index 085fb9c2333a..218aebd6387f 100644
@@ -359,7 +359,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.
@@ -378,7 +378,7 @@ void resctrl_arch_sync_cpu_defaults(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);
 }
 
 /*
@@ -605,7 +605,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)
@@ -663,7 +663,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();
 
@@ -2946,8 +2946,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
index 0917c7f25720..8697b02dabf1 100644
@@ -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
index 7062b84dd467..d1cf885e8930 100644
@@ -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.39.2
maintainer
#129 lore raw

Re: [PATCH v1 27/31] x86/resctrl: Rename resctrl_sched_in() to begin resctrl_arch_

Hi James,

In subject, did you intend to say "to begin with"?

Quoted 9 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 concistency. This is purely cosmetic.

concistency -> consistency

Reinette

reviewer
#130 lore raw

Re: [PATCH v1 27/31] x86/resctrl: Rename resctrl_sched_in() to begin resctrl_arch_

Quoted 3 lines · Reinette Chatre

Hi James,

In subject, did you intend to say "to begin with"?

I'd say the subject is likely to be abbreviated rather than incorrect, but it certainly does no harm to clarify it. I'll make a note.

Quoted 5 lines · James Morse
Quoted 4 lines

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.

Quoted 7 lines
Quoted 5 lines

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 concistency. This is purely cosmetic.

concistency -> consistency

Noted.

Cheers
---Dave

reviewer
#131 lore raw

Re: [PATCH v1 27/31] x86/resctrl: Rename resctrl_sched_in() to begin resctrl_arch_

In reply to James Morse
Quoted 9 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 concistency. This is purely cosmetic.

s/concistency/consistency

Quoted 108 lines
---
 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
index 9940398e367e..491342f56811 100644
@@ -177,7 +177,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);
@@ -220,7 +220,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
index 085fb9c2333a..218aebd6387f 100644
@@ -359,7 +359,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.
@@ -378,7 +378,7 @@ void resctrl_arch_sync_cpu_defaults(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);
 }
 
 /*
@@ -605,7 +605,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)
@@ -663,7 +663,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();
 
@@ -2946,8 +2946,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
index 0917c7f25720..8697b02dabf1 100644
@@ -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
index 7062b84dd467..d1cf885e8930 100644
@@ -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 · 2 lines
Thanks
Babu Moger
author reviewer
#132 lore raw

PATCH 28/31 x86/resctrl: Drop __init/__exit on assorted symbols

In reply to James Morse

Because 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.

---
If 'late onlined secondaries' is an alien concept, I can add a worked example to the commit message:
If a system has two L3 caches, but during boot only CPU-0 is online, then no CPU is able to probe the features of the second L3 cache. It's not until user-space brings other CPUs online that the MPAM driver can finally get a glimpse of all the hardware to determine what properties the system has.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 2 +-
 arch/x86/kernel/cpu/resctrl/monitor.c  | 4 ++--
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 8 ++++----
 include/linux/resctrl.h                | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
index 3a3962736061..56218193a8ba 100644
@@ -457,7 +457,7 @@ 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 __exit resctrl_mon_resource_exit(void);
+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);
arch/x86/kernel/cpu/resctrl/monitor.c +2 -2
index 8b316d9acc3b..7e6fca138cb7 100644
@@ -954,7 +954,7 @@ static int dom_data_init(struct rdt_resource *r)
 	return err;
 }
 
-static void __exit dom_data_exit(struct rdt_resource *r)
+static void dom_data_exit(struct rdt_resource *r)
 {
 	if (!r->mon_capable)
 		return;
@@ -1076,7 +1076,7 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r)
 	return 0;
 }
 
-void __exit resctrl_mon_resource_exit(void)
+void resctrl_mon_resource_exit(void)
 {
 	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +4 -4
index 218aebd6387f..1425a33d201d 100644
@@ -2069,7 +2069,7 @@ static struct rftype *rdtgroup_get_rftype_by_name(const char *name)
 	return NULL;
 }
 
-static void __init thread_throttle_mode_init(void)
+static void thread_throttle_mode_init(void)
 {
 	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_MBA);
 	struct rftype *rft;
@@ -3997,7 +3997,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);
 
@@ -4190,7 +4190,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;
 
@@ -4244,7 +4244,7 @@ int __init resctrl_init(void)
 	return ret;
 }
 
-void __exit resctrl_exit(void)
+void resctrl_exit(void)
 {
 	debugfs_remove_recursive(debugfs_resctrl);
 	unregister_filesystem(&rdt_fs_type);
include/linux/resctrl.h +2 -2
index f463fb949677..5da55e58f229 100644
@@ -393,7 +393,7 @@ void resctrl_arch_reset_rmid_all(struct rdt_resource *r, struct rdt_domain *d);
 extern unsigned int resctrl_rmid_realloc_threshold;
 extern unsigned int resctrl_rmid_realloc_limit;
 
-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.39.2
maintainer
#133 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Hi James,

Quoted 8 lines · James Morse

Because 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.

Quoted 8 lines

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.

Obviously for the reasons you state this code has never been exercised. Were you able to test this error interrupt flow yet?

Reinette

reviewer
#134 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Quoted 20 lines · Reinette Chatre

Hi James,

Quoted 8 lines · James Morse

Because 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.

Quoted 8 lines

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.

Quoted 5 lines

Obviously for the reasons you state this code has never been exercised. Were you able to test this error interrupt flow yet?

Reinette

I think this will have to wait for James to respond.

There is code to tear down resctrl in response to an MPAM error interrupt, but I don't know how it has been exercised so far (if at all).

https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_devices.c?h=mpam/snapshot/v6.7-rc2#n1940

Cheers
---Dave

#135 lore raw

Re: [EXTERNAL] Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Hi Dave, Reinette,

Quoted 24 lines · Reinette Chatre
Quoted 23 lines

Hi James,

Quoted 8 lines · James Morse

Because 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.

Quoted 8 lines

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.

Obviously for the reasons you state this code has never been exercised. Were you able to test this error interrupt flow yet?

Quoted 7 lines
Quoted 2 lines

Reinette

I think this will have to wait for James to respond.

There is code to tear down resctrl in response to an MPAM error interrupt, but I don't know how it has been exercised so far (if at all).

We are managed to test the MPAM error interrupt (on the platform that supports MPAM interrupts on software errors). For instance programming
more resource control groups (part IDs) than available, and It appears to correctly remove the "resctrl" mount point (though mount command still shows resctrl on /sys/fs/resctrl type resctrl (rw,relatime) ), but

# mount -t resctrl resctrl /sys/fs/resctrl
mount: /sys/fs/resctrl: mount point does not exist.

Additionally, a question regarding this, Is a complete system restart necessary to regain the mount?

Thanks
-Amit

reviewer
#136 lore raw

Re: [EXTERNAL] Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Quoted 34 lines · Amit Singh Tomar

Hi Dave, Reinette,

Quoted 24 lines · Reinette Chatre
Quoted 23 lines

Hi James,

Quoted 8 lines · James Morse

Because 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.

Quoted 8 lines

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.

Obviously for the reasons you state this code has never been exercised. Were you able to test this error interrupt flow yet?

Quoted 7 lines
Quoted 2 lines

Reinette

I think this will have to wait for James to respond.

There is code to tear down resctrl in response to an MPAM error interrupt, but I don't know how it has been exercised so far (if at all).

Quoted 6 lines

We are managed to test the MPAM error interrupt (on the platform that supports MPAM interrupts on software errors). For instance programming more resource control groups (part IDs) than available, and It appears to correctly remove the "resctrl" mount point (though mount command still shows resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
), but

Thanks for trying this out!

Is it possible to unmount resctrl once the system is in this state?

Quoted 2 lines
# mount -t resctrl resctrl /sys/fs/resctrl
mount: /sys/fs/resctrl: mount point does not exist.

What if you now try to mount resctrl somewhere else, e.g.:

# mount -t resctrl resctrl /mnt

I'm guessing this _should_ fail if you weren't able to unmount resctrl, since resctrl seems to forbid multiple mount instances.

I'm not sure what the best behaviour is here. Leaving resctrl "half- mounted" might be a good thing: at this point the system is in a semi- bad state we want to make sure it can't be remounted. Unregistering the resctrl filesystem from the fs core feels cleaner if feasible though.

Leaving an impossible unmount operation for init to do during reboot/ shutdown feels unfortunate.

We might have to look at what other filesystems do in this area.

The mount machinery does provide other ways of getting into broken, impossible situations from userspace, so this doesn't feel like an entirely new problem.

Quoted 6 lines

Additionally, a question regarding this, Is a complete system restart necessary to regain the mount?

Thanks
-Amit

I think James will need to comment on this, but I think that yes, it is probably appropriate to require a reboot. I think an MPAM error interrupt should only happen if the software did something wrong, so it's a bit like hitting a BUG(): we don't promise that everything works 100% properly until the system is restarted. Misbehaviour should be contained to MPAM though.

Cheers
---Dave

#137 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Hi Dave,

Quoted 1 line

Is it possible to unmount resctrl once the system is in this state?

No, it can't be unmounted, as there is no mount exist.

Quoted 6 lines
Quoted 2 lines
# mount -t resctrl resctrl /sys/fs/resctrl
mount: /sys/fs/resctrl: mount point does not exist.

What if you now try to mount resctrl somewhere else, e.g.:

# mount -t resctrl resctrl /mnt
root@localhost:~# mount -t resctrl resctrl /test
mount: /test: unknown filesystem type 'resctrl'.
Quoted 25 lines

I'm guessing this _should_ fail if you weren't able to unmount resctrl, since resctrl seems to forbid multiple mount instances.

I'm not sure what the best behaviour is here. Leaving resctrl "half- mounted" might be a good thing: at this point the system is in a semi- bad state we want to make sure it can't be remounted. Unregistering the resctrl filesystem from the fs core feels cleaner if feasible though.

Leaving an impossible unmount operation for init to do during reboot/ shutdown feels unfortunate.

We might have to look at what other filesystems do in this area.

The mount machinery does provide other ways of getting into broken, impossible situations from userspace, so this doesn't feel like an entirely new problem.

Quoted 6 lines

Additionally, a question regarding this, Is a complete system restart necessary to regain the mount?

Thanks
-Amit

Quoted 7 lines

I think James will need to comment on this, but I think that yes, it is probably appropriate to require a reboot. I think an MPAM error interrupt should only happen if the software did something wrong, so it's a bit like hitting a BUG(): we don't promise that everything works 100% properly until the system is restarted. Misbehaviour should be contained to MPAM though.

if "resctrl" is nonfunctional in this state, then this comment[1] here does *not* make sense.

"restore any modified controls to their reset values."

Thanks
-Amit

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_devices.c?h=mpam/snapshot/v6.7-rc2#n2228

root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
root@localhost:~# devmem msc_addr 32 0x9999
[  687.096276] mpam: error irq from msc:1 'PARTID_SEL_Range', partid:39321, pmg: 0, ris: 0
root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
root@localhost:~# umount resctrl
umount: /sys/fs/resctrl: no mount point specified.
root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
root@localhost:~# mount -t resctrl resctrl /test
mount: /test: unknown filesystem type 'resctrl'.
reviewer
#138 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Quoted 4 lines · Amit Singh Tomar

Hi Dave,

Quoted 1 line

Is it possible to unmount resctrl once the system is in this state?

No, it can't be unmounted, as there is no mount exist.

I see.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
# mount -t resctrl resctrl /sys/fs/resctrl
mount: /sys/fs/resctrl: mount point does not exist.

What if you now try to mount resctrl somewhere else, e.g.:

# mount -t resctrl resctrl /mnt
root@localhost:~# mount -t resctrl resctrl /test
mount: /test: unknown filesystem type 'resctrl'.

Oh, right, so the resctrl filesystem gets unregistered in that case...

Quoted 32 lines
Quoted 25 lines

I'm guessing this _should_ fail if you weren't able to unmount resctrl, since resctrl seems to forbid multiple mount instances.

I'm not sure what the best behaviour is here. Leaving resctrl "half- mounted" might be a good thing: at this point the system is in a semi- bad state we want to make sure it can't be remounted. Unregistering the resctrl filesystem from the fs core feels cleaner if feasible though.

Leaving an impossible unmount operation for init to do during reboot/ shutdown feels unfortunate.

We might have to look at what other filesystems do in this area.

The mount machinery does provide other ways of getting into broken, impossible situations from userspace, so this doesn't feel like an entirely new problem.

Quoted 6 lines

Additionally, a question regarding this, Is a complete system restart necessary to regain the mount?

Thanks
-Amit

Quoted 7 lines

I think James will need to comment on this, but I think that yes, it is probably appropriate to require a reboot. I think an MPAM error interrupt should only happen if the software did something wrong, so it's a bit like hitting a BUG(): we don't promise that everything works 100% properly until the system is restarted. Misbehaviour should be contained to MPAM though.

Quoted 4 lines

if "resctrl" is nonfunctional in this state, then this comment[1] here does *not* make sense.

"restore any modified controls to their reset values."

Can you clarify what you mean here?

I think it makes sense to clean up the MPAM hardware as well as we can in these situations, even if we can't be certain what went wrong.

[final comments below]

Quoted 22 lines

Thanks
-Amit

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/tree/drivers/platform/mpam/mpam_devices.c?h=mpam/snapshot/v6.7-rc2#n2228

root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs
(rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
root@localhost:~# devmem msc_addr 32 0x9999
[  687.096276] mpam: error irq from msc:1 'PARTID_SEL_Range', partid:39321,
pmg: 0, ris: 0
root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs
(rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
root@localhost:~# umount resctrl
umount: /sys/fs/resctrl: no mount point specified.
Quoted 6 lines
root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs
(rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
root@localhost:~# mount -t resctrl resctrl /test
mount: /test: unknown filesystem type 'resctrl'.

Thanks for trying this out.

I guess the behaviour here might want a bit more thought.

I'm not too keen on us leaving a defective mount in the namespace, with a nonexistent mount pount. I'm wondering whether things like systemd may get confused by this...

Cheers
---Dave

#139 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I think James will need to comment on this, but I think that yes, it is probably appropriate to require a reboot. I think an MPAM error interrupt should only happen if the software did something wrong, so it's a bit like hitting a BUG(): we don't promise that everything works 100% properly until the system is restarted. Misbehaviour should be contained to MPAM though.

Quoted 6 lines
Quoted 4 lines

if "resctrl" is nonfunctional in this state, then this comment[1] here does *not* make sense.

"restore any modified controls to their reset values."

Can you clarify what you mean here?

What I meant was, What's the rationale behind restoring the modified controls, if user is going to restart the system anyways (in order to use MPAM again), but later realized that it is needed so that *non* MPAM loads (user may still want to run other things even after MPAM error interrupt) would not have any adverse effect with modified controls.

Therefore, taking my statement back.

Quoted 46 lines

I think it makes sense to clean up the MPAM hardware as well as we can in these situations, even if we can't be certain what went wrong.

[final comments below]

Quoted 22 lines

Thanks
-Amit

[1]: https://urldefense.proofpoint.com/v2/url?u=https-3A__git.kernel.org_pub_scm_linux_kernel_git_morse_linux.git_tree_drivers_platform_mpam_mpam-5Fdevices.c-3Fh-3Dmpam_snapshot_v6.7-2Drc2-23n2228&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=V_GK7jRuCHDErm6txmgDK1-MbUihtnSQ3gPgB-A-JKU&m=DzR4EYX-356bYvqcrD5mYQBzLmDppMaRaHx6yjN7nRE5GH7nogtw6VtDZchmqb_q&s=SKpVy4sPg3dbFJGfMfUGoo252IHOrHrLfcv5f0sCmm0&e=

root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs
(rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
root@localhost:~# devmem msc_addr 32 0x9999
[  687.096276] mpam: error irq from msc:1 'PARTID_SEL_Range', partid:39321,
pmg: 0, ris: 0
root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs
(rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
root@localhost:~# umount resctrl
umount: /sys/fs/resctrl: no mount point specified.
Quoted 6 lines
root@localhost:~# mount
tmpfs on /run/user/0 type tmpfs
(rw,nosuid,nodev,relatime,size=32923772k,nr_inodes=8230943,mode=700)
root@localhost:~# mount -t resctrl resctrl /test
mount: /test: unknown filesystem type 'resctrl'.

Thanks for trying this out.

I guess the behaviour here might want a bit more thought.

I'm not too keen on us leaving a defective mount in the namespace, with a nonexistent mount pount. I'm wondering whether things like systemd may get confused by this...

Cheers
---Dave

reviewer
#140 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Quoted 15 lines · Amit Singh Tomar
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

I think James will need to comment on this, but I think that yes, it is probably appropriate to require a reboot. I think an MPAM error interrupt should only happen if the software did something wrong, so it's a bit like hitting a BUG(): we don't promise that everything works 100% properly until the system is restarted. Misbehaviour should be contained to MPAM though.

Quoted 6 lines
Quoted 4 lines

if "resctrl" is nonfunctional in this state, then this comment[1] here does *not* make sense.

"restore any modified controls to their reset values."

Can you clarify what you mean here?

Quoted 7 lines

What I meant was, What's the rationale behind restoring the modified controls, if user is going to restart the system anyways (in order to use MPAM again), but later realized that it is needed so that *non* MPAM loads (user may still want to run other things even after MPAM error interrupt) would not have any adverse effect with modified controls.

Therefore, taking my statement back.

Ack: we can't force the system to restart without losing data. Really, the decision about when and whether to attempt a graceful shutdown or reboot should be left to userspace. But until userspace does shut down the system, we do our best to behave as if the broken part of the system (MPAM) were not present at all.

[...]

Cheers
---Dave

author reviewer
#141 lore raw

Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

Hi guys,

Quoted 7 lines · Dave Martin
Quoted 6 lines · Amit Singh Tomar
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

I think James will need to comment on this, but I think that yes, it is probably appropriate to require a reboot. I think an MPAM error interrupt should only happen if the software did something wrong, so it's a bit like hitting a BUG(): we don't promise that everything works 100% properly until the system is restarted. Misbehaviour should be contained to MPAM though.

Indeed - all the reasons for the MPAM error interrupt being triggered indicate a software bug, so re-mounting resctrl with the same buggy code isn't going to fix anything.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

if "resctrl" is nonfunctional in this state, then this comment[1] here does *not* make sense.

"restore any modified controls to their reset values."

The MPAM driver goes on to reset all the MPAM hardware to the best of its ability. These means everything gets set back to 100%, so its as if MPAM is not implemented. This is better than throttling the wrong task because an out-of-range PARTID for ${important_task} is using the configuration of ${background_process}...

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

Can you clarify what you mean here?

What I meant was, What's the rationale behind restoring the modified
controls, if user is going to restart the system anyways (in order to use
MPAM again), but later realized that it is needed so that *non* MPAM loads>> (user may still want to run other things even after MPAM error interrupt) would not have any adverse effect with modified controls.

Quoted 7 lines
Quoted 1 line

Therefore, taking my statement back.

Ack: we can't force the system to restart without losing data. Really, the decision about when and whether to attempt a graceful shutdown or reboot should be left to userspace. But until userspace does shut down the system, we do our best to behave as if the broken part of the system (MPAM) were not present at all.

Dave's systemd choking on this angle is interesting - I'll go experiment with this.

The alternative here is to delete the __exit text completely as it can't be run, and instead get MPAM's error interrupt to disable the static-keys and return -EIO for every call into the arch code.
I didn't do this as its likely to cause extra churn to ensure that every arch helper can propagate errors back to user-space, and this seemed like a good (re-)use of existing code.

The third option was to not do anything in MPAM, and just print a message to say bad things might be happening. Given its extra work for hardware to detect the error conditions, I previously assumed no-one would do this, and hardware would just 'go wrong' instead... but as someone has built this, it would be good to try and react to it.

Thanks,

James

author reviewer
#142 lore raw

Re: [EXTERNAL] Re: [PATCH v1 28/31] x86/resctrl: Drop __init/__exit on assorted symbols

In reply to Amit Singh Tomar

Hi Amit, Reinette,

Quoted 19 lines · Amit Singh Tomar
Quoted 19 lines · Reinette Chatre
Quoted 18 lines · James Morse
Quoted 16 lines

Because 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.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Obviously for the reasons you state this code has never been exercised. Were you able to test this error interrupt flow yet?

I think this will have to wait for James to respond.

There is code to tear down resctrl in response to an MPAM error interrupt, but I don't know how it has been exercised so far (if at all).

Previously I saw one or two kernfs structures left behind. (to discover this you had to leave a shell with its CWD in the filesystem), but it looks like those issues have been solved.

Dave points out that resctrl_exit() removing the sysfs mount point means the filesystem can't be umount()ed. Systemd doesn't seem to care today, but might choke on this in the future.

I think the right thing to do here is get resctrl_exit() to call rdtgroup_destroy_root(), and drop sysfs_remove_mount_point(). This creates a bit of asymmetry, but if resctrl were a module the mount-point stuff would be done in module init/exit - only we don't have a module to unload, so the asymmetry is to be expected. I don't think its worth adding new __exit text that we know will never be used for the sake of symmetry.

With this change, triggering the interrupt makes all the files under resctrl disappear, I can then umount() the filesystem, but not re-mount it.

The aim here is for the arch code to be able to say "this is broken, I can't support resctrl" with minimum changes to the existing code.

There are a couple of vanishingly unlikely corner cases that need tightening up: e.g. the rmid_ptrs[] array disappears, a syscall could get blocked on the rdtgroup_mutex while the teardown happens, once it gains the lock it discoverers a surprise NULL pointer.

Fixing these can wait until after the code is moved as these things can't happen on x86. (patches are in the 'extra's branch of the mpam tree:
https://git.kernel.org/pub/scm/linux/kernel/git/morse/linux.git/log/?h=mpam/snapshot%2bextras/v6.10-rc1
)

Quoted 7 lines

We are managed to test the MPAM error interrupt (on the platform that supports MPAM interrupts on software errors). For instance programming
more resource control groups (part IDs) than available, and It appears to correctly remove the "resctrl" mount point (though mount command still shows resctrl on /sys/fs/resctrl type resctrl (rw,relatime)
), but

Quoted 5 lines
# mount -t resctrl resctrl /sys/fs/resctrl
mount: /sys/fs/resctrl: mount point does not exist.

Additionally, a question regarding this, Is a complete system restart necessary to regain the mount?

It is - but you are likely to hit the same software bug again. The story here is about keeping the machine running without penalising the wrong task. I think its acceptable for programs driving resctrl to go wrong, provided the workload doesn't run with the wrong configuration.

Thanks,

James

author reviewer
#143 lore raw

PATCH 29/31 fs/resctrl: Add boiler plate for external resctrl code

In reply to James Morse

Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL for the common parts of the resctrl interface and make X86_CPU_RESCTRL depend on this.

---
 MAINTAINERS              |  1 +
 arch/Kconfig             |  8 ++++++++
 arch/x86/Kconfig         | 10 +++-------
 fs/Kconfig               |  1 +
 fs/Makefile              |  1 +
 fs/resctrl/Kconfig       | 23 +++++++++++++++++++++++
 fs/resctrl/Makefile      |  3 +++
 fs/resctrl/ctrlmondata.c |  0
 fs/resctrl/internal.h    |  0
 fs/resctrl/monitor.c     |  0
 fs/resctrl/psuedo_lock.c |  0
 fs/resctrl/rdtgroup.c    |  0
 include/linux/resctrl.h  |  4 ++++
 13 files changed, 44 insertions(+), 7 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/psuedo_lock.c
 create mode 100644 fs/resctrl/rdtgroup.c
MAINTAINERS +1 -0
index 5621dd823e79..c49090e9c777 100644
@@ -18543,6 +18543,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
index fd18b7db2c77..131d874d6738 100644
@@ -1406,6 +1406,14 @@ config STRICT_MODULE_RWX
 config ARCH_HAS_PHYS_TO_DMA
 	bool
 
+config ARCH_HAS_CPU_RESCTRL
+	bool
+	help
+	  The 'resctrl' filesystem allows CPU controls of shared resources
+	  such as caches and memory bandwidth to be configured. An architecture
+	  selects this if it provides the arch-specific hooks for the filesystem
+	  and needs the per-task CLOSID/RMID properties.
+
 config HAVE_ARCH_COMPILER_H
 	bool
 	help
arch/x86/Kconfig +3 -7
index e071e564452e..cb043543f088 100644
@@ -479,8 +479,10 @@ config GOLDFISH
 config X86_CPU_RESCTRL
 	bool "x86 CPU resource control support"
 	depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
+	depends on MISC_FILESYSTEMS
 	select KERNFS
-	select PROC_CPU_RESCTRL		if PROC_FS
+	select ARCH_HAS_CPU_RESCTRL
+	select RESCTRL_FS
 	select RESCTRL_FS_PSEUDO_LOCK
 	help
 	  Enable x86 CPU resource control support.
@@ -507,12 +509,6 @@ config X86_FRED
 	  ring transitions and exception/interrupt handling if the
 	  system supports.
 
-config RESCTRL_FS_PSEUDO_LOCK
-	bool
-	help
-	  Software mechanism to pin data in a cache portion using
-	  micro-architecture specific knowledge.
-
 if X86_32
 config X86_BIGSMP
 	bool "Support for big SMP systems with more than 8 CPUs"
fs/Kconfig +1 -0
index a46b0cbc4d8f..d8a36383b6dc 100644
@@ -331,6 +331,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/sysv/Kconfig"
fs/Makefile +1 -0
index 6ecc9b0a53f2..da6e2d028722 100644
@@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS)		+= efivarfs/
 obj-$(CONFIG_EROFS_FS)		+= erofs/
 obj-$(CONFIG_VBOXSF_FS)		+= vboxsf/
 obj-$(CONFIG_ZONEFS_FS)		+= zonefs/
+obj-$(CONFIG_RESCTRL_FS)	+= resctrl/
fs/resctrl/Kconfig new file +23 -0
new file mode 100644
index 000000000000..36a1ddbe6c21
@@ -0,0 +1,23 @@
+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
+	  Resctrl is a filesystem interface
+	  to control allocation and
+	  monitoring of system resources
+	  used by the CPUs.
+
+config RESCTRL_FS_PSEUDO_LOCK
+	bool
+	help
+          Software mechanism to pin data in a cache portion using
+          micro-architecture specific knowledge.
+
+config RESCTRL_RMID_DEPENDS_ON_CLOSID
+	bool
+	help
+	  Enable 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 +3 -0
new file mode 100644
index 000000000000..10fcfb0fdb10
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_RESCTRL_FS)		+= rdtgroup.o ctrlmondata.o monitor.o
+obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK)	+= psuedo_lock.o
fs/resctrl/ctrlmondata.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/internal.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/monitor.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/psuedo_lock.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/rdtgroup.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
include/linux/resctrl.h +4 -0
index 5da55e58f229..f786ffceeda3 100644
@@ -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.39.2
maintainer
#144 lore raw

Re: [PATCH v1 29/31] fs/resctrl: Add boiler plate for external resctrl code

Hi James,

Quoted 45 lines · James Morse

Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL for the common parts of the resctrl interface and make X86_CPU_RESCTRL depend on this.

---
 MAINTAINERS              |  1 +
 arch/Kconfig             |  8 ++++++++
 arch/x86/Kconfig         | 10 +++-------
 fs/Kconfig               |  1 +
 fs/Makefile              |  1 +
 fs/resctrl/Kconfig       | 23 +++++++++++++++++++++++
 fs/resctrl/Makefile      |  3 +++
 fs/resctrl/ctrlmondata.c |  0
 fs/resctrl/internal.h    |  0
 fs/resctrl/monitor.c     |  0
 fs/resctrl/psuedo_lock.c |  0
 fs/resctrl/rdtgroup.c    |  0
 include/linux/resctrl.h  |  4 ++++
 13 files changed, 44 insertions(+), 7 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/psuedo_lock.c
 create mode 100644 fs/resctrl/rdtgroup.c
MAINTAINERS +1 -0
index 5621dd823e79..c49090e9c777 100644
@@ -18543,6 +18543,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 +0 -0
index fd18b7db2c77..131d874d6738 100644

arch/Kconfig config STRICT_MODULE_RWX · line 1415

Quoted 10 lines
arch/Kconfig +7 -0
@@ -1406,6 +1406,14 @@ config STRICT_MODULE_RWX
 config ARCH_HAS_PHYS_TO_DMA
 	bool
 
+config ARCH_HAS_CPU_RESCTRL
+	bool
+	help
+	  The 'resctrl' filesystem allows CPU controls of shared resources
+	  such as caches and memory bandwidth to be configured. An architecture
+	  selects this if it provides the arch-specific hooks for the filesystem
+	  and needs the per-task CLOSID/RMID properties.

Should it mention monitoring capabilities?

Quoted 9 lines
arch/Kconfig +1 -0
+
 config HAVE_ARCH_COMPILER_H
 	bool
 	help
arch/x86/Kconfig +0 -0
index e071e564452e..cb043543f088 100644

arch/x86/Kconfig config GOLDFISH · line 483

Quoted 5 lines
arch/x86/Kconfig +1 -0
@@ -479,8 +479,10 @@ config GOLDFISH
 config X86_CPU_RESCTRL
 	bool "x86 CPU resource control support"
 	depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
+	depends on MISC_FILESYSTEMS
 	select KERNFS

Do both X86_CPU_RESCTRL and RESCTRL_FS need to select KERNFS?

fs/resctrl/Kconfig

Quoted 45 lines
arch/x86/Kconfig +2 -7
-	select PROC_CPU_RESCTRL		if PROC_FS
+	select ARCH_HAS_CPU_RESCTRL
+	select RESCTRL_FS
 	select RESCTRL_FS_PSEUDO_LOCK
 	help
 	  Enable x86 CPU resource control support.
@@ -507,12 +509,6 @@ config X86_FRED
 	  ring transitions and exception/interrupt handling if the
 	  system supports.
 
-config RESCTRL_FS_PSEUDO_LOCK
-	bool
-	help
-	  Software mechanism to pin data in a cache portion using
-	  micro-architecture specific knowledge.
-
 if X86_32
 config X86_BIGSMP
 	bool "Support for big SMP systems with more than 8 CPUs"
fs/Kconfig +1 -0
index a46b0cbc4d8f..d8a36383b6dc 100644
@@ -331,6 +331,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/sysv/Kconfig"
fs/Makefile +1 -0
index 6ecc9b0a53f2..da6e2d028722 100644
@@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS)		+= efivarfs/
 obj-$(CONFIG_EROFS_FS)		+= erofs/
 obj-$(CONFIG_VBOXSF_FS)		+= vboxsf/
 obj-$(CONFIG_ZONEFS_FS)		+= zonefs/
+obj-$(CONFIG_RESCTRL_FS)	+= resctrl/
fs/resctrl/Kconfig new file +0 -0
new file mode 100644
index 000000000000..36a1ddbe6c21

Could you please review the contents of this file for appropriate line length and consistent tab usage?

fs/resctrl/psuedo_lock.c

Quoted 43 lines
fs/resctrl/Kconfig new file +23 -0
@@ -0,0 +1,23 @@
+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
+	  Resctrl is a filesystem interface
+	  to control allocation and
+	  monitoring of system resources
+	  used by the CPUs.
+
+config RESCTRL_FS_PSEUDO_LOCK
+	bool
+	help
+          Software mechanism to pin data in a cache portion using
+          micro-architecture specific knowledge.
+
+config RESCTRL_RMID_DEPENDS_ON_CLOSID
+	bool
+	help
+	  Enable 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 +3 -0
new file mode 100644
index 000000000000..10fcfb0fdb10
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_RESCTRL_FS)		+= rdtgroup.o ctrlmondata.o monitor.o
+obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK)	+= psuedo_lock.o
fs/resctrl/ctrlmondata.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/internal.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/monitor.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/psuedo_lock.c +0 -0

pseudo_lock.c

Quoted 10 lines

new file mode 100644
index 000000000000..e69de29bb2d1

fs/resctrl/rdtgroup.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
include/linux/resctrl.h +0 -0
index 5da55e58f229..f786ffceeda3 100644

include/linux/resctrl.h line 17

Quoted 10 lines
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

Reinette

reviewer
#145 lore raw

Re: [PATCH v1 29/31] fs/resctrl: Add boiler plate for external resctrl code

Quoted 51 lines · Reinette Chatre

Hi James,

Quoted 48 lines · James Morse

Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL for the common parts of the resctrl interface and make X86_CPU_RESCTRL depend on this.

---
 MAINTAINERS              |  1 +
 arch/Kconfig             |  8 ++++++++
 arch/x86/Kconfig         | 10 +++-------
 fs/Kconfig               |  1 +
 fs/Makefile              |  1 +
 fs/resctrl/Kconfig       | 23 +++++++++++++++++++++++
 fs/resctrl/Makefile      |  3 +++
 fs/resctrl/ctrlmondata.c |  0
 fs/resctrl/internal.h    |  0
 fs/resctrl/monitor.c     |  0
 fs/resctrl/psuedo_lock.c |  0
 fs/resctrl/rdtgroup.c    |  0
 include/linux/resctrl.h  |  4 ++++
 13 files changed, 44 insertions(+), 7 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/psuedo_lock.c
 create mode 100644 fs/resctrl/rdtgroup.c
MAINTAINERS +1 -0
index 5621dd823e79..c49090e9c777 100644
@@ -18543,6 +18543,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 +0 -0
index fd18b7db2c77..131d874d6738 100644
@@ -1406,6 +1406,14 @@ config STRICT_MODULE_RWX
 config ARCH_HAS_PHYS_TO_DMA
 	bool
 
Quoted 9 lines

arch/Kconfig config STRICT_MODULE_RWX · line 1415

Quoted 7 lines
arch/Kconfig +7 -0
+config ARCH_HAS_CPU_RESCTRL
+	bool
+	help
+	  The 'resctrl' filesystem allows CPU controls of shared resources
+	  such as caches and memory bandwidth to be configured. An architecture
+	  selects this if it provides the arch-specific hooks for the filesystem
+	  and needs the per-task CLOSID/RMID properties.

Should it mention monitoring capabilities?

Probably, although I wonder whether it is better to describe this just once, under RESCTRL_FS. Does it makes sense to have something like this here?

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).

If so, I can propose this.

(Details on what gets added to task_struct is maybe unnecessarily low- level to bother with here...)

Quoted 8 lines
Quoted 8 lines
arch/Kconfig +1 -0
+
 config HAVE_ARCH_COMPILER_H
 	bool
 	help
arch/x86/Kconfig +0 -0
index e071e564452e..cb043543f088 100644
Quoted 8 lines

arch/x86/Kconfig config GOLDFISH · line 483

Quoted 6 lines
arch/x86/Kconfig +1 -0
@@ -479,8 +479,10 @@ config GOLDFISH
 config X86_CPU_RESCTRL
 	bool "x86 CPU resource control support"
 	depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
+	depends on MISC_FILESYSTEMS
 	select KERNFS

Do both X86_CPU_RESCTRL and RESCTRL_FS need to select KERNFS?

Hmmm, hopefully the arch backend doesn't need to re-depend on KERNFS. I'll note that for review.

(If not, we can probably drop filesystem-related #includes from the remaining x86 arch code too...)

[...]

Quoted 21 lines
Quoted 21 lines
fs/Kconfig +1 -0
index a46b0cbc4d8f..d8a36383b6dc 100644
@@ -331,6 +331,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/sysv/Kconfig"
fs/Makefile +1 -0
index 6ecc9b0a53f2..da6e2d028722 100644
@@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS)		+= efivarfs/
 obj-$(CONFIG_EROFS_FS)		+= erofs/
 obj-$(CONFIG_VBOXSF_FS)		+= vboxsf/
 obj-$(CONFIG_ZONEFS_FS)		+= zonefs/
+obj-$(CONFIG_RESCTRL_FS)	+= resctrl/
Quoted 8 lines

fs/resctrl/Kconfig

Quoted 5 lines
fs/resctrl/Kconfig new file +0 -0
new file mode 100644
index 000000000000..36a1ddbe6c21

Could you please review the contents of this file for appropriate line length and consistent tab usage?

Noted.

Quoted 11 lines

fs/resctrl/Kconfig line 10

Quoted 11 lines
fs/resctrl/Kconfig new file +10 -0
@@ -0,0 +1,23 @@
+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
+	  Resctrl is a filesystem interface
+	  to control allocation and
+	  monitoring of system resources
+	  used by the CPUs.

(Not quite a haiku, but I don't know how many syllables "resctrl" counts as...)

Since this is the Kconfig user's primary knob for enabling resctrl, maybe flesh this out and make it a bit more generic and newbie-friendly? Something like:

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.

If unsure, it is safe to say Y.

See <file:Documentation/arch/x86/resctrl.rst> for more information.

I'm assuming that just enabling this option doesn't introduce significant overheads. For MPAM I'm pretty sure it doesn't, but if this is a concern that we could go for "If unsure, say N."

If this looks OK, I can propose it to James.

Quoted 34 lines

fs/resctrl/psuedo_lock.c

Quoted 32 lines
fs/resctrl/Kconfig new file +13 -0
+
+config RESCTRL_FS_PSEUDO_LOCK
+	bool
+	help
+          Software mechanism to pin data in a cache portion using
+          micro-architecture specific knowledge.
+
+config RESCTRL_RMID_DEPENDS_ON_CLOSID
+	bool
+	help
+	  Enable 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 +3 -0
new file mode 100644
index 000000000000..10fcfb0fdb10
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_RESCTRL_FS)		+= rdtgroup.o ctrlmondata.o monitor.o
+obj-$(CONFIG_RESCTRL_FS_PSEUDO_LOCK)	+= psuedo_lock.o
fs/resctrl/ctrlmondata.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/internal.h new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/monitor.c new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
fs/resctrl/psuedo_lock.c +0 -0

pseudo_lock.c

[...]

Quoted 1 line

Reinette

Noted here, and in the Makefile snippet above.

Cheers
---Dave

maintainer
#146 lore raw

Re: [PATCH v1 29/31] fs/resctrl: Add boiler plate for external resctrl code

Hi Dave,

Quoted 62 lines · Dave Martin
Quoted 51 lines · Reinette Chatre

Hi James,

Quoted 48 lines · James Morse

Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL for the common parts of the resctrl interface and make X86_CPU_RESCTRL depend on this.

---
 MAINTAINERS              |  1 +
 arch/Kconfig             |  8 ++++++++
 arch/x86/Kconfig         | 10 +++-------
 fs/Kconfig               |  1 +
 fs/Makefile              |  1 +
 fs/resctrl/Kconfig       | 23 +++++++++++++++++++++++
 fs/resctrl/Makefile      |  3 +++
 fs/resctrl/ctrlmondata.c |  0
 fs/resctrl/internal.h    |  0
 fs/resctrl/monitor.c     |  0
 fs/resctrl/psuedo_lock.c |  0
 fs/resctrl/rdtgroup.c    |  0
 include/linux/resctrl.h  |  4 ++++
 13 files changed, 44 insertions(+), 7 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/psuedo_lock.c
 create mode 100644 fs/resctrl/rdtgroup.c
MAINTAINERS +1 -0
index 5621dd823e79..c49090e9c777 100644
@@ -18543,6 +18543,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 +0 -0
index fd18b7db2c77..131d874d6738 100644
@@ -1406,6 +1406,14 @@ config STRICT_MODULE_RWX
 config ARCH_HAS_PHYS_TO_DMA
 	bool
 
Quoted 9 lines

arch/Kconfig config STRICT_MODULE_RWX · line 1415

Quoted 7 lines
arch/Kconfig +7 -0
+config ARCH_HAS_CPU_RESCTRL
+	bool
+	help
+	  The 'resctrl' filesystem allows CPU controls of shared resources
+	  such as caches and memory bandwidth to be configured. An architecture
+	  selects this if it provides the arch-specific hooks for the filesystem
+	  and needs the per-task CLOSID/RMID properties.

Should it mention monitoring capabilities?

Quoted 8 lines

Probably, although I wonder whether it is better to describe this just once, under RESCTRL_FS. Does it makes sense to have something like this here?

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).

This looks good to me.

Quoted 82 lines

If so, I can propose this.

(Details on what gets added to task_struct is maybe unnecessarily low- level to bother with here...)

Quoted 8 lines
Quoted 8 lines
arch/Kconfig +1 -0
+
 config HAVE_ARCH_COMPILER_H
 	bool
 	help
arch/x86/Kconfig +0 -0
index e071e564452e..cb043543f088 100644
Quoted 8 lines

arch/x86/Kconfig config GOLDFISH · line 483

Quoted 6 lines
arch/x86/Kconfig +1 -0
@@ -479,8 +479,10 @@ config GOLDFISH
 config X86_CPU_RESCTRL
 	bool "x86 CPU resource control support"
 	depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
+	depends on MISC_FILESYSTEMS
 	select KERNFS

Do both X86_CPU_RESCTRL and RESCTRL_FS need to select KERNFS?

Hmmm, hopefully the arch backend doesn't need to re-depend on KERNFS. I'll note that for review.

(If not, we can probably drop filesystem-related #includes from the remaining x86 arch code too...)

[...]

Quoted 21 lines
Quoted 21 lines
fs/Kconfig +1 -0
index a46b0cbc4d8f..d8a36383b6dc 100644
@@ -331,6 +331,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/sysv/Kconfig"
fs/Makefile +1 -0
index 6ecc9b0a53f2..da6e2d028722 100644
@@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS)		+= efivarfs/
 obj-$(CONFIG_EROFS_FS)		+= erofs/
 obj-$(CONFIG_VBOXSF_FS)		+= vboxsf/
 obj-$(CONFIG_ZONEFS_FS)		+= zonefs/
+obj-$(CONFIG_RESCTRL_FS)	+= resctrl/
Quoted 8 lines

fs/resctrl/Kconfig

Quoted 5 lines
fs/resctrl/Kconfig new file +0 -0
new file mode 100644
index 000000000000..36a1ddbe6c21

Could you please review the contents of this file for appropriate line length and consistent tab usage?

Noted.

Quoted 11 lines

fs/resctrl/Kconfig line 10

Quoted 11 lines
fs/resctrl/Kconfig new file +10 -0
@@ -0,0 +1,23 @@
+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
+	  Resctrl is a filesystem interface
+	  to control allocation and
+	  monitoring of system resources
+	  used by the CPUs.

(Not quite a haiku, but I don't know how many syllables "resctrl" counts as...)

Since this is the Kconfig user's primary knob for enabling resctrl, maybe flesh this out and make it a bit more generic and newbie-friendly? Something like:

Quoted 5 lines

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).

Nit: We should double check with AMD how they want to refer to their feature. Their contribution to the resctrl docs used the term you provide but their spec uses PQOS.

Do you expect this snippet to be updated when MPAM full support lands or does resctrl have enough support at this point to include a mention of MPAM?

Quoted 8 lines

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.

Well written, thank you.

Quoted 8 lines

If unsure, it is safe to say Y.

See <file:Documentation/arch/x86/resctrl.rst> for more information.

I'm assuming that just enabling this option doesn't introduce significant overheads. For MPAM I'm pretty sure it doesn't, but if this is a concern that we could go for "If unsure, say N."

I would vote for N for when folks are not sure.

Quoted 3 lines

If this looks OK, I can propose it to James.

Reinette

reviewer
#147 lore raw

Re: [PATCH v1 29/31] fs/resctrl: Add boiler plate for external resctrl code

Quoted 69 lines · Reinette Chatre

Hi Dave,

Quoted 66 lines · Dave Martin
Quoted 51 lines · Reinette Chatre

Hi James,

Quoted 48 lines · James Morse

Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL for the common parts of the resctrl interface and make X86_CPU_RESCTRL depend on this.

---
 MAINTAINERS              |  1 +
 arch/Kconfig             |  8 ++++++++
 arch/x86/Kconfig         | 10 +++-------
 fs/Kconfig               |  1 +
 fs/Makefile              |  1 +
 fs/resctrl/Kconfig       | 23 +++++++++++++++++++++++
 fs/resctrl/Makefile      |  3 +++
 fs/resctrl/ctrlmondata.c |  0
 fs/resctrl/internal.h    |  0
 fs/resctrl/monitor.c     |  0
 fs/resctrl/psuedo_lock.c |  0
 fs/resctrl/rdtgroup.c    |  0
 include/linux/resctrl.h  |  4 ++++
 13 files changed, 44 insertions(+), 7 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/psuedo_lock.c
 create mode 100644 fs/resctrl/rdtgroup.c
MAINTAINERS +1 -0
index 5621dd823e79..c49090e9c777 100644
@@ -18543,6 +18543,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 +0 -0
index fd18b7db2c77..131d874d6738 100644
@@ -1406,6 +1406,14 @@ config STRICT_MODULE_RWX
 config ARCH_HAS_PHYS_TO_DMA
 	bool
 
Quoted 9 lines

arch/Kconfig config STRICT_MODULE_RWX · line 1415

Quoted 7 lines
arch/Kconfig +7 -0
+config ARCH_HAS_CPU_RESCTRL
+	bool
+	help
+	  The 'resctrl' filesystem allows CPU controls of shared resources
+	  such as caches and memory bandwidth to be configured. An architecture
+	  selects this if it provides the arch-specific hooks for the filesystem
+	  and needs the per-task CLOSID/RMID properties.

Should it mention monitoring capabilities?

Probably, although I wonder whether it is better to describe this just once, under RESCTRL_FS. Does it makes sense to have something like this here?

Quoted 6 lines
Quoted 4 lines

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).

This looks good to me.

Noted, thanks.

Quoted 24 lines
Quoted 24 lines

If so, I can propose this.

(Details on what gets added to task_struct is maybe unnecessarily low- level to bother with here...)

Quoted 16 lines
Quoted 9 lines
arch/Kconfig +1 -0
+
 config HAVE_ARCH_COMPILER_H
 	bool
 	help
arch/x86/Kconfig +0 -0
index e071e564452e..cb043543f088 100644

arch/x86/Kconfig config GOLDFISH · line 483

Quoted 5 lines
arch/x86/Kconfig +1 -0
@@ -479,8 +479,10 @@ config GOLDFISH
 config X86_CPU_RESCTRL
 	bool "x86 CPU resource control support"
 	depends on X86 && (CPU_SUP_INTEL || CPU_SUP_AMD)
+	depends on MISC_FILESYSTEMS
 	select KERNFS

Do both X86_CPU_RESCTRL and RESCTRL_FS need to select KERNFS?

Quoted 7 lines
Quoted 7 lines

Hmmm, hopefully the arch backend doesn't need to re-depend on KERNFS. I'll note that for review.

(If not, we can probably drop filesystem-related #includes from the remaining x86 arch code too...)

[...]

(I still need to look at this.)

Quoted 58 lines
Quoted 52 lines
Quoted 22 lines
Quoted 22 lines
fs/Kconfig +1 -0
index a46b0cbc4d8f..d8a36383b6dc 100644
@@ -331,6 +331,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/sysv/Kconfig"
fs/Makefile +1 -0
index 6ecc9b0a53f2..da6e2d028722 100644
@@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS)		+= efivarfs/
 obj-$(CONFIG_EROFS_FS)		+= erofs/
 obj-$(CONFIG_VBOXSF_FS)		+= vboxsf/
 obj-$(CONFIG_ZONEFS_FS)		+= zonefs/
+obj-$(CONFIG_RESCTRL_FS)	+= resctrl/
Quoted 8 lines

fs/resctrl/Kconfig

Quoted 5 lines
fs/resctrl/Kconfig new file +0 -0
new file mode 100644
index 000000000000..36a1ddbe6c21

Could you please review the contents of this file for appropriate line length and consistent tab usage?

Noted.

Quoted 11 lines

fs/resctrl/Kconfig line 10

Quoted 11 lines
fs/resctrl/Kconfig new file +10 -0
@@ -0,0 +1,23 @@
+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
+	  Resctrl is a filesystem interface
+	  to control allocation and
+	  monitoring of system resources
+	  used by the CPUs.

(Not quite a haiku, but I don't know how many syllables "resctrl" counts as...)

Since this is the Kconfig user's primary knob for enabling resctrl, maybe flesh this out and make it a bit more generic and newbie-friendly? Something like:

Quoted 5 lines

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).

Quoted 6 lines

Nit: We should double check with AMD how they want to refer to their feature. Their contribution to the resctrl docs used the term you provide but their spec uses PQOS.

Do you expect this snippet to be updated when MPAM full support lands or does resctrl have enough support at this point to include a mention of MPAM?

Probably yes, even if only to make the point that this is generic and relevant for more than one architecture.

For this series, MPAM is not known to the kernel, so I didn't want to give the impression that there was any support for it (yet).

Quoted 10 lines
Quoted 8 lines

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.

Well written, thank you.

Thanks for the once-over; I'll propose this to James for inclusion.

Quoted 11 lines
Quoted 9 lines

If unsure, it is safe to say Y.

See <file:Documentation/arch/x86/resctrl.rst> for more information.

I'm assuming that just enabling this option doesn't introduce significant overheads. For MPAM I'm pretty sure it doesn't, but if this is a concern that we could go for "If unsure, say N."

I would vote for N for when folks are not sure.

OK, fair enough. Noted.

Cheers
---Dave

reviewer
#148 lore raw

Re: [PATCH v1 29/31] fs/resctrl: Add boiler plate for external resctrl code

In reply to Reinette Chatre

Hi Babu,

[see below]

Quoted 12 lines · Reinette Chatre

Hi Dave,

Quoted 9 lines · Dave Martin
Quoted 8 lines · Reinette Chatre

Hi James,

Quoted 5 lines · James Morse

Add Makefile and Kconfig for fs/resctrl. Add ARCH_HAS_CPU_RESCTRL for the common parts of the resctrl interface and make X86_CPU_RESCTRL depend on this.

[...]

Quoted 36 lines
Quoted 30 lines
Quoted 8 lines

fs/resctrl/Kconfig

Quoted 5 lines
fs/resctrl/Kconfig new file +0 -0
new file mode 100644
index 000000000000..36a1ddbe6c21

Could you please review the contents of this file for appropriate line length and consistent tab usage?

Noted.

Quoted 11 lines

fs/resctrl/Kconfig line 10

Quoted 11 lines
fs/resctrl/Kconfig new file +10 -0
@@ -0,0 +1,23 @@
+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
+	  Resctrl is a filesystem interface
+	  to control allocation and
+	  monitoring of system resources
+	  used by the CPUs.

(Not quite a haiku, but I don't know how many syllables "resctrl" counts as...)

Since this is the Kconfig user's primary knob for enabling resctrl, maybe flesh this out and make it a bit more generic and newbie-friendly? Something like:

Quoted 5 lines

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).

Quoted 3 lines

Nit: We should double check with AMD how they want to refer to their feature. Their contribution to the resctrl docs used the term you provide but their spec uses PQOS.

Babu, do you have a view on this?

Initially I just pasted this across from the existing text in resctrl.rst and arch/x86/Kconfig.

Looking at the AMD's spec though, I'd probably follow Reinette's suggestion and go for:

[...] AMD's Platform Quality of Service (PQOS)

but I'm happy to take your recommendation if you think AMD would prefer different text here.

Cheers
---Dave

author reviewer
#149 lore raw

PATCH 30/31 x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

In reply to James Morse

Once 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.

---
 arch/x86/include/asm/resctrl.h         |  3 +++
 arch/x86/kernel/cpu/resctrl/core.c     |  5 ++++
 arch/x86/kernel/cpu/resctrl/internal.h | 36 --------------------------
 include/linux/resctrl.h                |  3 +++
 include/linux/resctrl_types.h          | 30 +++++++++++++++++++++
 5 files changed, 41 insertions(+), 36 deletions(-)
arch/x86/include/asm/resctrl.h +3 -0
index 491342f56811..746431c66fc4 100644
@@ -218,6 +218,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/core.c +5 -0
index f94ad04023c3..c0fb2e22e110 100644
@@ -306,6 +306,11 @@ static void rdt_get_cdp_l2_config(void)
 	rdt_get_cdp_config(RDT_RESOURCE_L2);
 }
 
+bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l)
+{
+	return rdt_resources_all[l].cdp_enabled;
+}
+
 static void
 mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct rdt_resource *r)
 {
arch/x86/kernel/cpu/resctrl/internal.h +0 -36
index 56218193a8ba..0f7e3f10941b 100644
@@ -15,12 +15,6 @@
 
 #define L2_QOS_CDP_ENABLE		0x01ULL
 
-#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
 
 #define RMID_VAL_ERROR			BIT_ULL(63)
@@ -210,29 +204,6 @@ struct rdtgroup {
 	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;
 
@@ -370,13 +341,6 @@ static inline struct rdt_resource *resctrl_inc(struct rdt_resource *res)
 	return &hw_res->r_resctrl;
 }
 
-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);
-
 /*
  * To return the common struct rdt_resource, which is contained in struct
  * rdt_hw_resource, walk the resctrl member of struct rdt_hw_resource.
include/linux/resctrl.h +3 -0
index f786ffceeda3..00cc0457af50 100644
@@ -41,6 +41,9 @@ int proc_resctrl_show(struct seq_file *m,
  */
 #define RESCTRL_MAX_CBM			32
 
+extern unsigned int resctrl_rmid_realloc_limit;
+extern unsigned int resctrl_rmid_realloc_threshold;
+
 /**
  * struct pseudo_lock_region - pseudo-lock region information
  * @s:			Resctrl schema for the resource to which this
include/linux/resctrl_types.h +30 -0
index 4788bd95dac6..fe0b10b589c0 100644
@@ -7,6 +7,36 @@
 #ifndef __LINUX_RESCTRL_TYPES_H
 #define __LINUX_RESCTRL_TYPES_H
 
+#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
+
+/* 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)
+
 /* Reads to Local DRAM Memory */
 #define READS_TO_LOCAL_MEM		BIT(0)
 
Signature · 1 line
2.39.2
#150 lore raw

RE: [PATCH v1 30/31] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

Hello James

Quoted 116 lines

Once 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.

---
 arch/x86/include/asm/resctrl.h         |  3 +++
 arch/x86/kernel/cpu/resctrl/core.c     |  5 ++++
 arch/x86/kernel/cpu/resctrl/internal.h | 36 --------------------------
 include/linux/resctrl.h                |  3 +++
 include/linux/resctrl_types.h          | 30
+++++++++++++++++++++
 5 files changed, 41 insertions(+), 36 deletions(-)
arch/x86/include/asm/resctrl.h +0 -0
index 491342f56811..746431c66fc4 100644
@@ -218,6 +218,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);

arch/x86/include/asm/resctrl.h +3 -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);
+
 #else
 
 static inline void resctrl_arch_sched_in(struct task_struct *tsk) {} diff --git

a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index f94ad04023c3..c0fb2e22e110 100644

arch/x86/kernel/cpu/resctrl/core.c +3 -0
@@ -306,6 +306,11 @@ static void rdt_get_cdp_l2_config(void)
 	rdt_get_cdp_config(RDT_RESOURCE_L2);
 }
 
+bool resctrl_arch_get_cdp_enabled(enum resctrl_res_level l) {
+	return rdt_resources_all[l].cdp_enabled; }
+
 static void
 mba_wrmsr_amd(struct rdt_domain *d, struct msr_param *m, struct

rdt_resource *r) { diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index 56218193a8ba..0f7e3f10941b 100644

arch/x86/kernel/cpu/resctrl/internal.h +0 -29
@@ -15,12 +15,6 @@
 
 #define L2_QOS_CDP_ENABLE		0x01ULL
 
-#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
 
 #define RMID_VAL_ERROR			BIT_ULL(63)
@@ -210,29 +204,6 @@ struct rdtgroup {
 	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;

arch/x86/kernel/cpu/resctrl/internal.h +0 -6
@@ -370,13 +341,6 @@ static inline struct rdt_resource *resctrl_inc(struct
 rdt_resource *res)
 	return &hw_res->r_resctrl;
 }
 
-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);
-
 /*
  * To return the common struct rdt_resource, which is contained in struct
  * rdt_hw_resource, walk the resctrl member of struct rdt_hw_resource.
include/linux/resctrl.h index renamed from include/linux/resctrl.h +0 -0

f786ffceeda3..00cc0457af50 100644

include/linux/resctrl.h int proc_resctrl_show(struct seq_file *m, · line 46

Quoted 6 lines
include/linux/resctrl.h +3 -0
@@ -41,6 +41,9 @@ int proc_resctrl_show(struct seq_file *m,
  */
 #define RESCTRL_MAX_CBM			32
 
+extern unsigned int resctrl_rmid_realloc_limit; extern unsigned int
+resctrl_rmid_realloc_threshold;
+

These two variables has been defined.
44 extern unsigned int resctrl_rmid_realloc_limit; 45 extern unsigned int resctrl_rmid_realloc_threshold;
400 extern unsigned int resctrl_rmid_realloc_threshold; 401 extern unsigned int resctrl_rmid_realloc_limit;

Best regards,
Shaopeng TAN

Quoted 49 lines
include/linux/resctrl.h +0 -0
 /**
  * struct pseudo_lock_region - pseudo-lock region information
  * @s:			Resctrl schema for the resource to which this
include/linux/resctrl_types.h +30 -0
index 4788bd95dac6..fe0b10b589c0 100644
@@ -7,6 +7,36 @@
 #ifndef __LINUX_RESCTRL_TYPES_H
 #define __LINUX_RESCTRL_TYPES_H
 
+#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
+
+/* 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)
+

/* Reads to Local DRAM Memory */
#define READS_TO_LOCAL_MEM BIT(0)

--
2.39.2

reviewer
#151 lore raw

Re: [PATCH v1 30/31] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

Quoted 20 lines · Shaopeng Tan (Fujitsu)

Hello James

Quoted 18 lines

Once 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.

---
 arch/x86/include/asm/resctrl.h         |  3 +++
 arch/x86/kernel/cpu/resctrl/core.c     |  5 ++++
 arch/x86/kernel/cpu/resctrl/internal.h | 36 --------------------------
 include/linux/resctrl.h                |  3 +++
 include/linux/resctrl_types.h          | 30
+++++++++++++++++++++
 5 files changed, 41 insertions(+), 36 deletions(-)

[...]

Quoted 11 lines

include/linux/resctrl.h int proc_resctrl_show(struct seq_file *m, · line 46

Quoted 11 lines
include/linux/resctrl.h index renamed from include/linux/resctrl.h +0 -0

f786ffceeda3..00cc0457af50 100644

include/linux/resctrl.h +3 -0
@@ -41,6 +41,9 @@ int proc_resctrl_show(struct seq_file *m,
  */
 #define RESCTRL_MAX_CBM			32
 
+extern unsigned int resctrl_rmid_realloc_limit; extern unsigned int
+resctrl_rmid_realloc_threshold;
+

[FYI, your mailer or editor seems to have messed this patch up a bit in your reply...]

Quoted 8 lines

These two variables has been defined.
44 extern unsigned int resctrl_rmid_realloc_limit; 45 extern unsigned int resctrl_rmid_realloc_threshold;
400 extern unsigned int resctrl_rmid_realloc_threshold; 401 extern unsigned int resctrl_rmid_realloc_limit;

Best regards,
Shaopeng TAN

[...]

Strange. This looks unintentional and there don't seem to be any relevant #ifdefs or references to these variables in the header that might justify reordering these declarations.

I'll propose to James that the addition of these duplicates be reverted out, so long as it doesn't break anything.

Cheers
---Dave

maintainer
#152 lore raw

Re: [PATCH v1 30/31] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

In reply to James Morse

Hi James,

On 3/21/2024 9:51 AM, James Morse wrote:
...

Quoted 31 lines
include/linux/resctrl_types.h +23 -0
index 4788bd95dac6..fe0b10b589c0 100644
@@ -7,6 +7,36 @@
 #ifndef __LINUX_RESCTRL_TYPES_H
 #define __LINUX_RESCTRL_TYPES_H
 
+#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
+
+/* 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)

include/linux/resctrl_types.h line 42

Quoted 10 lines
include/linux/resctrl_types.h +7 -0
+#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)
+
 /* Reads to Local DRAM Memory */
 #define READS_TO_LOCAL_MEM		BIT(0)
 

Not all these new seem to belong in this file. Could you please confirm?

For example:
Earlier in series it was mentioned that struct rdtgroup is private to the fs so having RDT_DELETED is unexpected as it implies access to struct rdtgroup.

CQM_LIMBOCHECK_INTERVAL seems private to the fs code, so too RFTYPE_FLAGS_CPUS_LIST.

Reinette

reviewer
#153 lore raw

Re: [PATCH v1 30/31] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

Quoted 48 lines · Reinette Chatre

Hi James,

On 3/21/2024 9:51 AM, James Morse wrote:
..

Quoted 31 lines
include/linux/resctrl_types.h +23 -0
index 4788bd95dac6..fe0b10b589c0 100644
@@ -7,6 +7,36 @@
 #ifndef __LINUX_RESCTRL_TYPES_H
 #define __LINUX_RESCTRL_TYPES_H
 
+#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
+
+/* 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)

include/linux/resctrl_types.h line 42

Quoted 10 lines
include/linux/resctrl_types.h +7 -0
+#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)
+
 /* Reads to Local DRAM Memory */
 #define READS_TO_LOCAL_MEM		BIT(0)
 

Not all these new seem to belong in this file. Could you please confirm?

Quoted 9 lines

For example:
Earlier in series it was mentioned that struct rdtgroup is private to the fs so having RDT_DELETED is unexpected as it implies access to struct rdtgroup.

CQM_LIMBOCHECK_INTERVAL seems private to the fs code, so too RFTYPE_FLAGS_CPUS_LIST.

Reinette

I'll flag this for James to review.

These have to be moved out of the x86 private headers, but you're right that some of them seem logically private to the resctrl core.

I guess some of these could move to fs/resctrl/internal.h?

OTOH, might it be preferable to keep all the flag definitions for a given member together for ease of maintenance, even if some are for resctrl internal use only?

Cheers
---Dave

maintainer
#154 lore raw

Re: [PATCH v1 30/31] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

Hi Dave,

Quoted 59 lines · Dave Martin
Quoted 48 lines · Reinette Chatre

Hi James,

On 3/21/2024 9:51 AM, James Morse wrote:
..

Quoted 31 lines
include/linux/resctrl_types.h +23 -0
index 4788bd95dac6..fe0b10b589c0 100644
@@ -7,6 +7,36 @@
 #ifndef __LINUX_RESCTRL_TYPES_H
 #define __LINUX_RESCTRL_TYPES_H
 
+#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
+
+/* 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)

include/linux/resctrl_types.h line 42

Quoted 10 lines
include/linux/resctrl_types.h +7 -0
+#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)
+
 /* Reads to Local DRAM Memory */
 #define READS_TO_LOCAL_MEM		BIT(0)
 

Not all these new seem to belong in this file. Could you please confirm?

Quoted 9 lines

For example:
Earlier in series it was mentioned that struct rdtgroup is private to the fs so having RDT_DELETED is unexpected as it implies access to struct rdtgroup.

CQM_LIMBOCHECK_INTERVAL seems private to the fs code, so too RFTYPE_FLAGS_CPUS_LIST.

Reinette

Quoted 6 lines

I'll flag this for James to review.

These have to be moved out of the x86 private headers, but you're right that some of them seem logically private to the resctrl core.

I guess some of these could move to fs/resctrl/internal.h?

It looks to me that way.

Quoted 4 lines

OTOH, might it be preferable to keep all the flag definitions for a given member together for ease of maintenance, even if some are for resctrl internal use only?

Indeed, those RFTYPE flags really seem to be fs code but I agree that architectures' use of RFTYPE_RES_CACHE and RFTYPE_RES_MB does make this complicated and having these in a central place is reasonable to me.

Reinette

reviewer
#155 lore raw

Re: [PATCH v1 30/31] x86/resctrl: Move the filesystem bits to headers visible to fs/resctrl

Quoted 76 lines · Reinette Chatre

Hi Dave,

Quoted 59 lines · Dave Martin
Quoted 48 lines · Reinette Chatre

Hi James,

On 3/21/2024 9:51 AM, James Morse wrote:
..

Quoted 31 lines
include/linux/resctrl_types.h +23 -0
index 4788bd95dac6..fe0b10b589c0 100644
@@ -7,6 +7,36 @@
 #ifndef __LINUX_RESCTRL_TYPES_H
 #define __LINUX_RESCTRL_TYPES_H
 
+#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
+
+/* 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)

include/linux/resctrl_types.h line 42

Quoted 10 lines
include/linux/resctrl_types.h +7 -0
+#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)
+
 /* Reads to Local DRAM Memory */
 #define READS_TO_LOCAL_MEM		BIT(0)
 

Not all these new seem to belong in this file. Could you please confirm?

Quoted 9 lines

For example:
Earlier in series it was mentioned that struct rdtgroup is private to the fs so having RDT_DELETED is unexpected as it implies access to struct rdtgroup.

CQM_LIMBOCHECK_INTERVAL seems private to the fs code, so too RFTYPE_FLAGS_CPUS_LIST.

Reinette

Quoted 6 lines

I'll flag this for James to review.

These have to be moved out of the x86 private headers, but you're right that some of them seem logically private to the resctrl core.

I guess some of these could move to fs/resctrl/internal.h?

It looks to me that way.

Quoted 4 lines

OTOH, might it be preferable to keep all the flag definitions for a given member together for ease of maintenance, even if some are for resctrl internal use only?

Quoted 5 lines

Indeed, those RFTYPE flags really seem to be fs code but I agree that architectures' use of RFTYPE_RES_CACHE and RFTYPE_RES_MB does make this complicated and having these in a central place is reasonable to me.

Reinette

Maybe we could split these into two groups, and clearly comment the ones that have no user outside resctrl as internal use only?

That's not as clean as removing those definitions from a shared header, but at least would help document the issue until/unless a better solution is found...

Cheers
---Dave