Skip to content

Add support for windows CPU affinity#1258

Merged
AkihiroSuda merged 1 commit into
opencontainers:mainfrom
kiashok:cpuAffinity-oci
Jan 6, 2025
Merged

Add support for windows CPU affinity#1258
AkihiroSuda merged 1 commit into
opencontainers:mainfrom
kiashok:cpuAffinity-oci

Conversation

@kiashok

@kiashok kiashok commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

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

kiashok commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

@kiashok

kiashok commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

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

Comment thread specs-go/config.go
Comment thread specs-go/config.go Outdated
Comment thread specs-go/config.go Outdated
Comment thread specs-go/config.go Outdated
@tianon

tianon commented Jun 28, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown

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

Comment thread config-windows.md Outdated
@kiashok

kiashok commented Sep 17, 2024

Copy link
Copy Markdown
Contributor Author

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

Comment thread config-windows.md Outdated
* **`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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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.

Comment thread config-windows.md Outdated
Comment thread config-windows.md Outdated
@kiashok

kiashok commented Oct 20, 2024

Copy link
Copy Markdown
Contributor Author

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

@jsturtevant

Copy link
Copy Markdown

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

Comment thread specs-go/config.go Outdated
// 100.
Maximum *uint16 `json:"maximum,omitempty"`
// Set of CPUs to affinitize for this container.
AffinityCPUs []WindowsCPUGroupAffinity `json:"affinityCPUs,omitempty"`

@rchincha rchincha Oct 28, 2024

Copy link
Copy Markdown

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
Copy Markdown
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).

Comment thread config-windows.md Outdated
Comment thread specs-go/config.go Outdated
Comment thread config-windows.md Outdated
@kiashok

kiashok commented Nov 13, 2024

Copy link
Copy Markdown
Contributor Author

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

Comment thread config-windows.md Outdated
Comment thread specs-go/config.go Outdated
@jsturtevant

Copy link
Copy Markdown

LGTM

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

Comment thread config-windows.md Outdated

@kevpar kevpar left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@tianon tianon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A couple really minor nits, but I think this is probably fine.

Maybe we need to update the JSON schema also?

"cpu": {
"type": "object",
"properties": {
"count": {
"$ref": "defs.json#/definitions/uint64"
},
"shares": {
"$ref": "defs.json#/definitions/uint16"
},
"maximum": {
"$ref": "defs.json#/definitions/uint16"
}
}
},

Comment thread config-windows.md Outdated
Comment thread config-windows.md

Each entry has the following structure:

Ref: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/miniport/ns-miniport-_group_affinity

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this ref should probably be after the list (like the other one in this same section), but it is a little odd then to have the ref for count+shares+maximum follow immediately. 🤔 Maybe it's fine (since the indentation should make it clear which is which)? Maybe that's why you chose to put it here instead of matching the outer pattern?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah that's right - I thought keeping it closest to the declaration might help. The indentation is helping keep it readable.

Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
@kiashok

kiashok commented Dec 16, 2024

Copy link
Copy Markdown
Contributor Author

A couple really minor nits, but I think this is probably fine.

Maybe we need to update the JSON schema also?

"cpu": {
"type": "object",
"properties": {
"count": {
"$ref": "defs.json#/definitions/uint64"
},
"shares": {
"$ref": "defs.json#/definitions/uint16"
},
"maximum": {
"$ref": "defs.json#/definitions/uint16"
}
}
},

Addressed this!

@kiashok

kiashok commented Dec 26, 2024

Copy link
Copy Markdown
Contributor Author

@tianon would you be able to take a look at this PR when you have a chance please? Thanks!

@jsturtevant

Copy link
Copy Markdown

LGTM

@AkihiroSuda AkihiroSuda added this to the v1.2.1 (tentative) milestone Jan 6, 2025
@AkihiroSuda AkihiroSuda merged commit d61dee6 into opencontainers:main Jan 6, 2025
@thaJeztah thaJeztah mentioned this pull request Feb 26, 2025
11 tasks
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