-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 setcpuaffinity(cmd, cpus)
for setting CPU affinity of subprocesses
#42469
Merged
Merged
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d501456
Support running commands with cpumask
tkf 2a72e24
Apply suggestions from code review
tkf 17eadca
Rename: setcpus -> setcpuaffinity
tkf 9af2985
Include it in docs and news
tkf a59228e
Include examples in the docstring
tkf d65cacd
Delay converting to cpumask; define show
tkf ba5559f
Fill between the lines in the docstring
tkf 4d37558
Merge branch 'master' into cpumask
tkf 7edc261
Apply suggestions from code review
tkf 038c116
Fix cpus type
tkf 7739a25
Add compat annotation
tkf 994e081
Fix show
tkf 20618b9
Fix a typo
tkf fa1b115
Don't run test with uv_thread_getaffinity on Windows
tkf e446956
Mention that it's Linux-only for now
tkf b9feb8d
Merge branch 'master' into cpumask
tkf 304330e
Through a proper error in print_process_affinity.jl
tkf a83b105
Fix print_process_affinity.jl for Windows
tkf 1beffff
Merge branch 'master' into cpumask
tkf 21ff94d
Merge branch 'master' into cpumask
tkf 123a072
Merge branch 'master' into cpumask
tkf 70138f4
Merge branch 'master' into cpumask
tkf 24763b0
Clarify supported platform
tkf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -941,6 +941,7 @@ export | |
run, | ||
setenv, | ||
addenv, | ||
setcpuaffinity, | ||
success, | ||
withenv, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
const pthread_t = Culong # TODO: this is wrong, but usually tolerable by the ABI | ||
const uv_thread_t = pthread_t | ||
tkf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function uv_thread_getaffinity() | ||
masksize = ccall(:uv_cpumask_size, Cint, ()) | ||
self = ccall(:uv_thread_self, uv_thread_t, ()) | ||
ref = Ref(self) | ||
cpumask = zeros(Bool, masksize) | ||
err = ccall( | ||
:uv_thread_getaffinity, | ||
Cint, | ||
(Ref{uv_thread_t}, Ptr{Bool}, Cssize_t), | ||
ref, | ||
cpumask, | ||
masksize, | ||
) | ||
@assert err == 0 | ||
tkf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
n = something(findlast(cpumask)) # we must have at least one active core | ||
resize!(cpumask, n) | ||
return cpumask | ||
end | ||
|
||
function print_process_affinity() | ||
join(stdout, findall(uv_thread_getaffinity()), ",") | ||
println() | ||
end | ||
|
||
if Base.Filesystem.samefile(PROGRAM_FILE, @__FILE__) | ||
print_process_affinity() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic required to go from the first command to understand the point of the second feels a bit large here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good point. I added a bit more explanations in the latest commit.