Skip to content

Commit

Permalink
adjust gcthreads propagation, argument handling and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jun 27, 2023
1 parent bc97f39 commit 2da97ca
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
1 change: 0 additions & 1 deletion base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct JLOptions
cpu_target::Ptr{UInt8}
nthreadpools::Int16
nthreads::Int16
ngcthreads::Int16
nmarkthreads::Int16
nsweepthreads::Int8
nthreads_per_pool::Ptr{Int16}
Expand Down
1 change: 1 addition & 0 deletions base/threadingconstructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ end
Threads.ngcthreads() -> Int
Returns the number of GC threads currently configured.
This includes both mark threads and concurrent sweep threads.
"""
ngcthreads() = Int(unsafe_load(cglobal(:jl_n_gcthreads, Cint))) + 1

Expand Down
1 change: 0 additions & 1 deletion src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ JL_DLLEXPORT void jl_init_options(void)
NULL, // cpu_target ("native", "core2", etc...)
0, // nthreadpools
0, // nthreads
0, // ngcthreads
0, // nmarkthreads
0, // nsweepthreads
NULL, // nthreads_per_pool
Expand Down
1 change: 0 additions & 1 deletion src/jloptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ typedef struct {
const char *cpu_target;
int8_t nthreadpools;
int16_t nthreads;
int16_t ngcthreads;
int16_t nmarkthreads;
int8_t nsweepthreads;
const int16_t *nthreads_per_pool;
Expand Down
11 changes: 10 additions & 1 deletion stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,14 @@ function get_threads_spec(opts)
end
end

function get_gcthreads_spec(opts)
if opts.markthreads > 0 || opts.sweepthreads > 0
`--gcthreads=$(opts.markthreads),$(opts.sweepthreads)`
else
``
end
end

# Starts workers specified by (-n|--procs) and --machine-file command line options
function process_opts(opts)
# startup worker.
Expand All @@ -1346,7 +1354,8 @@ function process_opts(opts)

# Propagate --threads to workers
threads = get_threads_spec(opts)
gcthreads = opts.ngcthreads > 0 ? `--gcthreads=$(opts.ngcthreads)` : ``
# Propagate --gcthreads to workers
gcthreads = get_gcthreads_spec(opts)

exeflags = `$threads $gcthreads`

Expand Down
7 changes: 7 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,19 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
end
end

withenv("JULIA_NUM_GC_THREADS" => 2) do
@test read(`$exename -e $code`, String) == "2"
end

withenv("JULIA_NUM_GC_THREADS" => "2,1") do
@test read(`$exename -e $code`, String) == "3"
end

# --machine-file
# this does not check that machine file works,
# only that the filename gets correctly passed to the option struct
Expand Down
3 changes: 2 additions & 1 deletion test/gc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ using Test
function run_gctest(file)
let cmd = `$(Base.julia_cmd()) --depwarn=error --rr-detach --startup-file=no $file`
@testset for test_nthreads in (1, 2, 4)
@testset for concurrent_sweep in (0, 1)
new_env = copy(ENV)
new_env["JULIA_NUM_THREADS"] = string(test_nthreads)
new_env["JULIA_NUM_GC_THREADS"] = string(test_nthreads)
new_env["JULIA_NUM_GC_THREADS"] = "$(test_nthreads),$(concurrent_sweep)"
@test success(run(pipeline(setenv(cmd, new_env), stdout = stdout, stderr = stderr)))
end
end
Expand Down

0 comments on commit 2da97ca

Please sign in to comment.