Skip to content

Commit 048714d

Browse files
devnexenhtejun
authored andcommitted
tools/sched_ext: scx_userland: fix restart and stats thread lifecycle bugs
Fix three issues in scx_userland's restart path: - exit_req is not reset on restart, causing sched_main_loop() to exit immediately without doing any scheduling work. - stats_printer thread handle is local to spawn_stats_thread(), making it impossible to join from main(). Promote it to file scope. - The stats thread continues reading skel->bss after the skeleton is destroyed on restart, causing a use-after-free. Join the stats thread before destroying the skeleton to ensure it has exited. Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 988369d commit 048714d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tools/sched_ext/scx_userland.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static bool verbose;
5454
static volatile int exit_req;
5555
static int enqueued_fd, dispatched_fd;
5656

57+
static pthread_t stats_printer;
5758
static struct scx_userland *skel;
5859
static struct bpf_link *ops_link;
5960

@@ -319,8 +320,6 @@ static void *run_stats_printer(void *arg)
319320

320321
static int spawn_stats_thread(void)
321322
{
322-
pthread_t stats_printer;
323-
324323
return pthread_create(&stats_printer, NULL, run_stats_printer, NULL);
325324
}
326325

@@ -375,6 +374,7 @@ static void pre_bootstrap(int argc, char **argv)
375374

376375
static void bootstrap(char *comm)
377376
{
377+
exit_req = 0;
378378
skel = SCX_OPS_OPEN(userland_ops, scx_userland);
379379

380380
skel->rodata->num_possible_cpus = libbpf_num_possible_cpus();
@@ -428,6 +428,7 @@ int main(int argc, char **argv)
428428

429429
exit_req = 1;
430430
bpf_link__destroy(ops_link);
431+
pthread_join(stats_printer, NULL);
431432
ecode = UEI_REPORT(skel, uei);
432433
scx_userland__destroy(skel);
433434

0 commit comments

Comments
 (0)