Skip to content

Commit

Permalink
erts: Improve erts_sched_local_random to work without process
Browse files Browse the repository at this point in the history
Seen to cause problem (GH-5981) when crash dump is iterating over
ETS ordered_set with write_concurrency (catree) and the
thread doing it does not have a 'current_process'.

Change erts_sched_local_random to instead use a single mutated rand_state.
  • Loading branch information
sverker committed Jun 20, 2022
1 parent 3002f55 commit 184634a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions erts/emulator/beam/erl_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -5873,6 +5873,7 @@ init_scheduler_data(ErtsSchedulerData* esdp, int num,
}

esdp->reductions = 0;
esdp->rand_state = (Uint64)(UWord)esdp + ((Uint64)(UWord)esdp << 32);

init_sched_wall_time(esdp, time_stamp);
erts_port_task_handle_init(&esdp->nosuspend_port_task_handle);
Expand Down
13 changes: 5 additions & 8 deletions erts/emulator/beam/erl_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ struct ErtsSchedulerData_ {
} pending_signal;

Uint64 reductions;
Uint64 rand_state;
ErtsSchedWallTime sched_wall_time;
ErtsGCInfo gc_info;
ErtsPortTaskHandle nosuspend_port_task_handle;
Expand Down Expand Up @@ -2798,19 +2799,15 @@ Uint32 erts_sched_local_random_hash_64_to_32_shift(Uint64 key)

/*
* This function attempts to return a random number based on the state
* of the scheduler, the current process and the additional_seed
* parameter.
* of the scheduler and the additional_seed parameter.
*/
ERTS_GLB_INLINE
Uint32 erts_sched_local_random(Uint additional_seed)
{
ErtsSchedulerData *esdp = erts_get_scheduler_data();
Uint64 seed =
additional_seed +
esdp->reductions +
esdp->current_process->fcalls +
(((Uint64)esdp->no) << 32);
return erts_sched_local_random_hash_64_to_32_shift(seed);
esdp->rand_state++;
return erts_sched_local_random_hash_64_to_32_shift(esdp->rand_state
+ additional_seed);
}

#ifdef DEBUG
Expand Down

0 comments on commit 184634a

Please sign in to comment.