Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for windows CPU affinity #1258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kiashok
Copy link

@kiashok kiashok commented Jun 20, 2024

This PR adds support for certain CRI fields in OCI runtime spec for supporting CPU affinity for windows containers.

CRI PR : kubernetes/kubernetes#124285
Github issue: kubernetes/kubernetes#125262
KEP: kubernetes/kubernetes#125262

@kiashok
Copy link
Author

kiashok commented Jun 20, 2024

@kiashok
Copy link
Author

kiashok commented Jun 20, 2024

@AkihiroSuda @thaJeztah could you please take a look? :) thanks!

specs-go/config.go Outdated Show resolved Hide resolved
specs-go/config.go Outdated Show resolved Hide resolved
specs-go/config.go Outdated Show resolved Hide resolved
@tianon
Copy link
Member

tianon commented Jun 28, 2024

Is there a compelling reason not to roughly match the naming convention adopted for Linux in #1253?

Also, please don't mark conversations with useful discussion/links as "resolved" especially if the PR itself didn't change as a result of the discussion but the discussion is still useful and potentially something someone else might reasonably ask about or want to discuss -- it makes them much more difficult to discover when reading the PR's comments.

@jsturtevant
Copy link

Is there a compelling reason not to roughly match the naming convention adopted for Linux in #1253?

For cpu's, Linux is a simple list where as on windows it is a bitmap with a group number (https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/miniport/ns-miniport-_group_affinity) and the naming/structure was used to map to those Windows specific concepts

For memory, I think it was the same idea, making sure it was known this is "perferred" but not guarenteed do to the Windows API's. Depending on outcome of #1258 (comment) we might not have this field

config-windows.md Outdated Show resolved Hide resolved
@kiashok
Copy link
Author

kiashok commented Sep 17, 2024

@AkihiroSuda @kevpar addressed review comments. Would you be able to take a look when you have some time please? Thanks!

@@ -82,6 +82,12 @@ The following parameters can be specified (mutually exclusive):
* **`count`** *(uint64, OPTIONAL)* - specifies the number of CPUs available to the container. It represents the fraction of the configured processor `count` in a container in relation to the processors available in the host. The fraction ultimately determines the portion of processor cycles that the threads in a container can use during each scheduling interval, as the number of cycles per 10,000 cycles.
* **`shares`** *(uint16, OPTIONAL)* - limits the share of processor time given to the container relative to other workloads on the processor. The processor `shares` (`weight` at the platform level) is a value between 0 and 10,000.
* **`maximum`** *(uint16, OPTIONAL)* - determines the portion of processor cycles that the threads in a container can use during each scheduling interval, as the number of cycles per 10,000 cycles. Set processor `maximum` to a percentage times 100.
* **`affinityCPUs`** *(array of objects, OPTIONAL)* - specifies the set of CPU to affinitize for this container.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why not just affinity (since this is a part of cpu struct/group, and other (ajacent) fields do not have CPU in them)

Copy link
Contributor

Choose a reason for hiding this comment

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

Answering to myself.

I see that earlier version had affinityCPUs and AffinityPreferredNumaNodes, but the latter was dropped.

Still, affinity would work, and, if we're to add NUMA affinity later, a name like NUMAaffinity (or affinityNUMA) would still work.

Copy link
Member

Choose a reason for hiding this comment

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

The sub fields could also be mask and group accordingly 👀

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. The less tautology the better.

Copy link
Author

Choose a reason for hiding this comment

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

@tianon @kolyshkin keeping it similar to how we've defined this in k/k proto file. There was a similar comment in that PR : kubernetes/kubernetes#124285 (comment)

group alone is a keyword in .proto so we couldn't just have mask or group. Thought uniformity would be good across the fields- prefix "cpu" in both fields or neither.

Copy link
Author

Choose a reason for hiding this comment

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

similar rationale to why affinityCPUs was used :
image

It is part of WindowsContainerResources struct which can mean cpus/memory or any other resource. So we named it affinityCPUs there. I understand that this struct in runtimespec is specifically for CPU alone. So if you would prefer me to drop "cpu" and just use "affinity" let me know, I can have that updated. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

I imagine there's got to be a way to convince Protobuf to use a keyword as an identifier, right? Some way to escape it?

Regardless, this spec is for a canonically-JSON-format, which doesn't have any constraints like that (or reserved keys at all), so I definitely still agree with @kolyshkin that we should ditch the duplication in the names and go for the simpler and more consistent all-lowercase versions (affinity or affinities, group, and mask).

Copy link
Author

Choose a reason for hiding this comment

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

@tianon have addressed this. Please take a look and let me know if it looks good. Thanks.

config-windows.md Outdated Show resolved Hide resolved
config-windows.md Outdated Show resolved Hide resolved
@kiashok
Copy link
Author

kiashok commented Oct 20, 2024

@tianon @kolyshkin @kevpar @jsturtevant could you please take a look at this PR when you have some time please? Thanks!

@jsturtevant
Copy link

/lgtm
for the functionality, I will defer to the reviewers here on the naming discussion

@@ -635,6 +635,17 @@ type WindowsCPUResources struct {
// cycles per 10,000 cycles. Set processor `maximum` to a percentage times
// 100.
Maximum *uint16 `json:"maximum,omitempty"`
// Set of CPUs to affinitize for this container.
AffinityCPUs []WindowsCPUGroupAffinity `json:"affinityCPUs,omitempty"`
Copy link

@rchincha rchincha Oct 28, 2024

Choose a reason for hiding this comment

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

Why is this specific to "Windows"? CPU affinity is more general?

Copy link
Member

Choose a reason for hiding this comment

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

The specific structure/fields supported are Windows-specific -- see https://github.com/opencontainers/runtime-spec/blob/8f3fbc881602d85699e5c448634ec1288860d966/config.md#:~:text=to%207%20(lowest).-,execCPUAffinity,-(object%2C%20OPTIONAL)%20specifies (execCPUAffinity) for how this is specified on Linux (part of the process object).

specs-go/config.go Outdated Show resolved Hide resolved
config-windows.md Outdated Show resolved Hide resolved
@kiashok
Copy link
Author

kiashok commented Nov 13, 2024

@tianon @kolyshkin @AkihiroSuda @thaJeztah could you please take a look when you have a chance please? thanks!

config-windows.md Outdated Show resolved Hide resolved
specs-go/config.go Outdated Show resolved Hide resolved
@jsturtevant
Copy link

LGTM

@tianon @kevpar @kolyshkin could you give a final look?

config-windows.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants