forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
setcpuaffinity(cmd, cpus)
for setting CPU affinity of subproces…
…ses (JuliaLang#42469) Support running commands with cpumask.
- Loading branch information
1 parent
d811fcb
commit 9f19050
Showing
9 changed files
with
122 additions
and
13 deletions.
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 |
---|---|---|
|
@@ -944,6 +944,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,31 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
const uv_thread_t = UInt # TODO: this is usually correct (or tolerated by the API), but not guaranteed | ||
|
||
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, | ||
) | ||
Base.uv_error("getaffinity", err) | ||
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