Skip to content

Conversation

marquiz
Copy link
Contributor

@marquiz marquiz commented Aug 15, 2025

Makes it possible e.g. to enable monitoring
(linux.intelRdt.enableMonitoring) without creating a CLOS (resctrl group) for the container.

Implements opencontainers/runtime-spec#1289.

@@ -287,7 +287,7 @@ func intelrdtCheck(config *configs.Config) error {
return fmt.Errorf("intelRdt is specified in config, but Intel RDT is not enabled")
}

if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || strings.Contains(config.IntelRdt.ClosID, "/") {
if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || (config.IntelRdt.ClosID != "/" && strings.Contains(config.IntelRdt.ClosID, "/")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to len > 1?

Suggested change
if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || (config.IntelRdt.ClosID != "/" && strings.Contains(config.IntelRdt.ClosID, "/")) {
if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || (len(config.IntelRdt.ClosID) > 1 && strings.Contains(config.IntelRdt.ClosID, "/")) {

(but maybe it's less readable, IDK)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I find that less obviouls, kinda obfuscating that we're looking for / as a special value. But let others comment on this, too...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the spec, I think what @kolyshkin suggested is slightly more readable for me. / is a special value, so something that is more than one char and contains a / is clearly not just a / in my mind.

I think I'd split it in two different error cases, one for "." and "..", the other for this. But this is really a personal preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I changed the code along these lines. However, I changed it to switch-case to make it shorter and more readable (imo)

@marquiz marquiz changed the title [RFC] libcontainer/intelrdt: support explicit assignment to root CLOS libcontainer/intelrdt: support explicit assignment to root CLOS Aug 27, 2025
@marquiz marquiz marked this pull request as ready for review August 27, 2025 07:17
@marquiz
Copy link
Contributor Author

marquiz commented Aug 27, 2025

Ready for review, opencontainers/runtime-spec#1289 was merged.

@AkihiroSuda @rata

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a unit test?

@marquiz
Copy link
Contributor Author

marquiz commented Aug 27, 2025

Can we have a unit test?

Check. I added comprehensive unit tests for the IntelRdt validation as a separate commit.

@rata @AkihiroSuda

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This almost lgtm, left a few suggestions to see if it can be slightly simpler

Comment on lines 24 to 31
type intelRdtStatus struct {
sync.Once
rdtEnabled bool
catEnabled bool
mbaEnabled bool
}

var intelRdt = &intelRdtStatus{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the methods and the struct might be better on a different file in this package now, it's growing.

However, do we need so much plumbing? Can't we have package-level bool variables just assigned with the result of intelrdt.IsEnabled() (and friends)? I'm not sure if this can change at runtime (it seems it doesn't) nor what the isEnabled() check does, but if that works, it seems simpler.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rata. This was exactly my initial implementation. However, I changed it in order to not cause ANY functional changes (other than the if logic). IOW, reason for the extensive plumbing here is to only do the discovery if the container config specifies linux.intelRdt (that involves parsing mounts and reading files from sysfs, for example)

I don't know how critical this really is for runc so I'm fully ok to do the simple thing you suggested. Thoughts @rata @kolyshkin @AkihiroSuda ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, no, let's keep this then. intelrdt is quite slow, let's do it conditional. But maybe move the methods and that to another file :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check. They're now in a separate file (libcontainer/configs/validate/intelrdt.go)

@@ -287,7 +287,7 @@ func intelrdtCheck(config *configs.Config) error {
return fmt.Errorf("intelRdt is specified in config, but Intel RDT is not enabled")
}

if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || strings.Contains(config.IntelRdt.ClosID, "/") {
if config.IntelRdt.ClosID == "." || config.IntelRdt.ClosID == ".." || (config.IntelRdt.ClosID != "/" && strings.Contains(config.IntelRdt.ClosID, "/")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the spec, I think what @kolyshkin suggested is slightly more readable for me. / is a special value, so something that is more than one char and contains a / is clearly not just a / in my mind.

I think I'd split it in two different error cases, one for "." and "..", the other for this. But this is really a personal preference.

Makes it possible e.g. to enable monitoring
(linux.intelRdt.enableMonitoring) without creating a CLOS (resctrl
group) for the container.

Implements opencontainers/runtime-spec#1289.

Signed-off-by: Markus Lehtonen <[email protected]>
@marquiz marquiz force-pushed the devel/rdt-root-clos branch from 748abd3 to ba68a17 Compare August 28, 2025 11:11
@marquiz
Copy link
Contributor Author

marquiz commented Aug 28, 2025

Updated:

  • change logic similar to what @kolyshkin suggested
  • put intelrdt plumbing into a separate file
  • put new unit tests into a separate file

@marquiz
Copy link
Contributor Author

marquiz commented Aug 28, 2025

Why do I get a linter error about missing package comment (in the new file)? None of the existing files have package comments 🤔

@rata
Copy link
Member

rata commented Aug 28, 2025

@marquiz not sure, but let's ignore them for now :)

rata
rata previously approved these changes Aug 29, 2025
Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@rata
Copy link
Member

rata commented Aug 29, 2025

@marquiz the linter is failing due to this PR now. Can you fix it?

@rata rata dismissed their stale review August 29, 2025 08:50

Linter is failing due to this PR (I thought it wasn't related, as before it was failing due to files not changed here)

Add package comment to make revive pass muster.

Signed-off-by: Markus Lehtonen <[email protected]>
@marquiz marquiz force-pushed the devel/rdt-root-clos branch from 0ae05e6 to 7628194 Compare August 29, 2025 09:36
@marquiz
Copy link
Contributor Author

marquiz commented Aug 29, 2025

Linter is failing due to this PR (I thought it wasn't related, as before it was failing due to files not changed here)

The linter failure had nothing to do with this PR, except that it added a new file and the linter started to complain about package comments because of this. Most of the packages in runc don't have package comments but because we lint with --new-from-rev=HEAD~ those are not picked up when golangci-lint version is bumbed and new warnings/errors get (silently) enabled.

However, I now added doc.go, even if outside the scope of this PR, to fix the failure

Copy link
Member

@rata rata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the doc one-liner to fix the linter :)

@rata rata merged commit 7a982f4 into opencontainers:main Aug 29, 2025
36 checks passed
@marquiz marquiz deleted the devel/rdt-root-clos branch August 29, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants