Skip to content

Commit 2ed26a0

Browse files
KenoKristofferC
authored andcommitted
Exclude threads test from rr tracing
(cherry picked from commit 7a3c153)
1 parent 0d21397 commit 2ed26a0

File tree

7 files changed

+43
-8
lines changed

7 files changed

+43
-8
lines changed

base/options.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct JLOptions
4545
image_file_specified::Int8
4646
warn_scope::Int8
4747
image_codegen::Int8
48+
rr_detach::Int8
4849
end
4950

5051
# This runs early in the sysimage != is not defined yet

src/jlapi.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,17 @@ static void lock_low32(void)
651651
// Actual definition in `ast.c`
652652
void jl_lisp_prompt(void);
653653

654+
static void rr_detach_teleport(void) {
655+
#ifdef _OS_LINUX_
656+
#define RR_CALL_BASE 1000
657+
#define SYS_rrcall_detach_teleport (RR_CALL_BASE + 9)
658+
int err = syscall(SYS_rrcall_detach_teleport, 0, 0, 0, 0, 0, 0);
659+
if (err < 0 || jl_running_under_rr(1)) {
660+
jl_error("Failed to detach from rr session");
661+
}
662+
#endif
663+
}
664+
654665
JL_DLLEXPORT int repl_entrypoint(int argc, char *argv[])
655666
{
656667
// no-op on Windows, note that the caller must have already converted
@@ -666,7 +677,19 @@ JL_DLLEXPORT int repl_entrypoint(int argc, char *argv[])
666677
memmove(&argv[1], &argv[2], (argc-2)*sizeof(void*));
667678
argc--;
668679
}
680+
char **orig_argv = argv;
669681
jl_parse_opts(&argc, (char***)&argv);
682+
683+
// The parent process requested that we detach from the rr session.
684+
// N.B.: In a perfect world, we would only do this for the portion of
685+
// the execution where we actually need to exclude rr (e.g. because we're
686+
// testing for the absence of a memory-model-dependent bug).
687+
if (jl_options.rr_detach && jl_running_under_rr(0)) {
688+
rr_detach_teleport();
689+
execv("/proc/self/exe", orig_argv);
690+
jl_error("Failed to self-execute");
691+
}
692+
670693
julia_init(jl_options.image_file_specified ? JL_IMAGE_CWD : JL_IMAGE_JULIA_HOME);
671694
if (lisp_prompt) {
672695
jl_get_ptls_states()->world_age = jl_get_world_counter();

src/jloptions.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jl_options_t jl_options = { 0, // quiet
7575
0, // image_file_specified
7676
JL_OPTIONS_WARN_SCOPE_ON, // ambiguous scope warning
7777
0, // image-codegen
78+
0, // rr-detach
7879
};
7980

8081
static const char usage[] = "julia [switches] -- [programfile] [args...]\n";
@@ -203,6 +204,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
203204
opt_project,
204205
opt_bug_report,
205206
opt_image_codegen,
207+
opt_rr_detach,
206208
};
207209
static const char* const shortopts = "+vhqH:e:E:L:J:C:it:p:O:g:";
208210
static const struct option longopts[] = {
@@ -254,6 +256,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
254256
{ "bind-to", required_argument, 0, opt_bind_to },
255257
{ "lisp", no_argument, 0, 1 },
256258
{ "image-codegen", no_argument, 0, opt_image_codegen },
259+
{ "rr-detach", no_argument, 0, opt_rr_detach },
257260
{ 0, 0, 0, 0 }
258261
};
259262

@@ -655,6 +658,9 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
655658
case opt_image_codegen:
656659
jl_options.image_codegen = 1;
657660
break;
661+
case opt_rr_detach:
662+
jl_options.rr_detach = 1;
663+
break;
658664
default:
659665
jl_errorf("julia: unhandled option -- %c\n"
660666
"This is a bug, please report it.", c);

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,7 @@ typedef struct {
19441944
int8_t image_file_specified;
19451945
int8_t warn_scope;
19461946
int8_t image_codegen;
1947+
int8_t rr_detach;
19471948
} jl_options_t;
19481949

19491950
extern JL_DLLEXPORT jl_options_t jl_options;

src/julia_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ void JL_UV_LOCK(void);
8383
extern "C" {
8484
#endif
8585

86+
int jl_running_under_rr(int recheck);
87+
8688
//--------------------------------------------------
8789
// timers
8890
// Returns time in nanosec

src/partr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ JL_DLLEXPORT int jl_enqueue_task(jl_task_t *task)
274274
}
275275

276276

277-
static int running_under_rr(void)
277+
int jl_running_under_rr(int recheck)
278278
{
279279
#ifdef _OS_LINUX_
280280
#define RR_CALL_BASE 1000
281281
#define SYS_rrcall_check_presence (RR_CALL_BASE + 8)
282282
static int checked_running_under_rr = 0;
283283
static int is_running_under_rr = 0;
284-
if (!checked_running_under_rr) {
284+
if (!checked_running_under_rr || recheck) {
285285
int ret = syscall(SYS_rrcall_check_presence, 0, 0, 0, 0, 0, 0);
286286
if (ret == -1) {
287287
// Should always be ENOSYS, but who knows what people do for
@@ -311,7 +311,7 @@ static int sleep_check_after_threshold(uint64_t *start_cycles)
311311
* scheduling logic from switching to other threads. Just don't bother
312312
* trying to wait here
313313
*/
314-
if (running_under_rr())
314+
if (jl_running_under_rr(0))
315315
return 1;
316316
if (!(*start_cycles)) {
317317
*start_cycles = jl_hrtime();

test/threads.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
let cmd = `$(Base.julia_cmd()) --depwarn=error --startup-file=no threads_exec.jl`
3+
using Test
4+
5+
let cmd = `$(Base.julia_cmd()) --depwarn=error --rr-detach --startup-file=no threads_exec.jl`
46
for test_nthreads in (1, 2, 4, 4) # run once to try single-threaded mode, then try a couple times to trigger bad races
57
run(pipeline(setenv(cmd, "JULIA_NUM_THREADS" => test_nthreads), stdout = stdout, stderr = stderr))
68
end
79
end
810

911
# issue #34415 - make sure external affinity settings work
12+
const SYS_rrcall_check_presence = 1008
13+
running_under_rr() = 0 == ccall(:syscall, Int,
14+
(Int, Int, Int, Int, Int, Int, Int),
15+
SYS_rrcall_check_presence, 0, 0, 0, 0, 0, 0)
1016

1117
if Sys.islinux()
12-
const SYS_rrcall_check_presence = 1008
13-
running_under_rr() = 0 == ccall(:syscall, Int,
14-
(Int, Int, Int, Int, Int, Int, Int),
15-
SYS_rrcall_check_presence, 0, 0, 0, 0, 0, 0)
1618
if Sys.CPU_THREADS > 1 && Sys.which("taskset") !== nothing && !running_under_rr()
1719
run_with_affinity(spec) = readchomp(`taskset -c $spec $(Base.julia_cmd()) -e "run(\`taskset -p \$(getpid())\`)"`)
1820
@test endswith(run_with_affinity("1"), "2")

0 commit comments

Comments
 (0)