Skip to content

Commit 767666b

Browse files
authored
[release-1.6] Disable affinity testing when run inside of cpusets (#47968)
On later versions of Julia, we have the ability to set CPUs for our subprocesses more flexibly, but on v1.6 we don't, so let's ignore these tests for now. X-ref: 32b1305
1 parent b9865b7 commit 767666b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/threads.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,31 @@ running_under_rr() = 0 == ccall(:syscall, Int,
1414
(Int, Int, Int, Int, Int, Int, Int),
1515
SYS_rrcall_check_presence, 0, 0, 0, 0, 0, 0)
1616

17+
const uv_thread_t = UInt # TODO: this is usually correct (or tolerated by the API), but not guaranteed
18+
19+
function uv_thread_getaffinity()
20+
masksize = ccall(:uv_cpumask_size, Cint, ())
21+
self = ccall(:uv_thread_self, uv_thread_t, ())
22+
ref = Ref(self)
23+
cpumask = zeros(Bool, masksize)
24+
err = ccall(
25+
:uv_thread_getaffinity,
26+
Cint,
27+
(Ref{uv_thread_t}, Ptr{Bool}, Cssize_t),
28+
ref,
29+
cpumask,
30+
masksize,
31+
)
32+
Base.uv_error("getaffinity", err)
33+
n = something(findlast(cpumask)) # we must have at least one active core
34+
resize!(cpumask, n)
35+
return cpumask
36+
end
37+
1738
if Sys.islinux()
18-
if Sys.CPU_THREADS > 1 && Sys.which("taskset") !== nothing && !running_under_rr()
39+
# Only run this test if we can run on CPUs 0 and 1
40+
allowed_cpus = findall(uv_thread_getaffinity())
41+
if all(x allowed_cpus for x in (1,2)) && Sys.which("taskset") !== nothing && !running_under_rr()
1942
run_with_affinity(spec) = readchomp(`taskset -c $spec $(Base.julia_cmd()) -e "run(\`taskset -p \$(getpid())\`)"`)
2043
@test endswith(run_with_affinity("1"), "2")
2144
@test endswith(run_with_affinity("0,1"), "3")

0 commit comments

Comments
 (0)