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

More flexible test affinity setting #44677

Merged
merged 4 commits into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ using Test

using Base.Threads

include("print_process_affinity.jl") # import `uv_thread_getaffinity`

# simple sanity tests for locks under cooperative concurrent access
let lk = ReentrantLock()
c1 = Event()
Expand Down Expand Up @@ -96,9 +98,10 @@ end
const AFFINITY_SUPPORTED = (Sys.islinux() || Sys.iswindows()) && !running_under_rr()
Copy link
Member

Choose a reason for hiding this comment

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

You can potentially drop the rr check, since it will be implied (it sets an affinity mask to 1 cpu)

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's see how it goes: #44693


if AFFINITY_SUPPORTED
if Sys.CPU_THREADS > 1
@test run_with_affinity([2]) == "2"
@test run_with_affinity([1, 2]) == "1,2"
allowed_cpus = findall(uv_thread_getaffinity())
if length(allowed_cpus) ≥ 2
@test run_with_affinity(allowed_cpus[1:1]) == "$(allowed_cpus[1])"
@test run_with_affinity(allowed_cpus[1:2]) == "$(allowed_cpus[1]),$(allowed_cpus[2])"
end
end

Expand All @@ -113,18 +116,21 @@ function get_nthreads(options = ``; cpus = nothing)
end

@testset "nthreads determined based on CPU affinity" begin
if AFFINITY_SUPPORTED && Sys.CPU_THREADS ≥ 2
@test get_nthreads() ≥ 2
@test get_nthreads(cpus = [1]) == 1
@test get_nthreads(cpus = [2]) == 1
@test get_nthreads(cpus = [1, 2]) == 2
@test get_nthreads(`-t1`, cpus = [1]) == 1
@test get_nthreads(`-t1`, cpus = [2]) == 1
@test get_nthreads(`-t1`, cpus = [1, 2]) == 1
if AFFINITY_SUPPORTED
allowed_cpus = findall(uv_thread_getaffinity())
if length(allowed_cpus) ≥ 2
@test get_nthreads() ≥ 2
@test get_nthreads(cpus = allowed_cpus[1:1]) == 1
@test get_nthreads(cpus = allowed_cpus[2:2]) == 1
@test get_nthreads(cpus = allowed_cpus[1:2]) == 2
@test get_nthreads(`-t1`, cpus = allowed_cpus[1:1]) == 1
@test get_nthreads(`-t1`, cpus = allowed_cpus[2:2]) == 1
@test get_nthreads(`-t1`, cpus = allowed_cpus[1:2]) == 1

if Sys.CPU_THREADS ≥ 3
@test get_nthreads(cpus = [1, 3]) == 2
@test get_nthreads(cpus = [2, 3]) == 2
if length(allowed_cpus) ≥ 3
@test get_nthreads(cpus = allowed_cpus[1:2:3]) == 2
@test get_nthreads(cpus = allowed_cpus[2:3]) == 2
end
end
end
end
Expand Down