Skip to content

Commit df4cf17

Browse files
authored
Make sure systematic testing doesn't switch to suspended thread (#4647)
* Make sure systematic testing doesn't switch to suspended thread Prior to this commit, the systematic testing next thread logic would consider switching to the pinned actor thread even if it was suspended. This was very wasteful since the suspended pinned actor thread would not do any meaningful work and almost immediately re-suspend itself. This commit changes things so that the next thread logic properly takes into account whether the pinned actor thread is suspended or not when selecting the next thread to activate. * add release notes
1 parent f09998d commit df4cf17

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

.release-notes/4647.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Make sure systematic testing doesn't switch to suspended thread
2+
3+
Previously, the systematic testing next thread logic would consider switching to the pinned actor thread even if it was suspended. This was very wasteful since the suspended pinned actor thread would not do any meaningful work and almost immediately re-suspend itself.
4+
5+
We have changed things so that the next thread logic properly takes into account whether the pinned actor thread is suspended or not when selecting the next thread to activate.

src/libponyrt/sched/scheduler.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,14 @@ PONY_API pony_ctx_t* pony_ctx()
19031903
return &this_scheduler->ctx;
19041904
}
19051905

1906+
/**
1907+
* Gets whether the pinned actor scheduler is suspended or not
1908+
*/
1909+
bool ponyint_get_pinned_actor_scheduler_suspended()
1910+
{
1911+
return atomic_load_explicit(&pinned_actor_scheduler_suspended, memory_order_relaxed);
1912+
}
1913+
19061914
void ponyint_register_asio_thread()
19071915
{
19081916
pony_register_thread();

src/libponyrt/sched/scheduler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ void ponyint_sched_start_global_unmute(uint32_t from, pony_actor_t* actor);
135135

136136
bool ponyint_sched_unmute_senders(pony_ctx_t* ctx, pony_actor_t* actor);
137137

138+
bool ponyint_get_pinned_actor_scheduler_suspended();
139+
138140
PONY_API uint32_t pony_active_schedulers();
139141

140142
PONY_API int32_t pony_scheduler_index();

src/libponyrt/sched/systematic_testing.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,21 @@ void ponyint_systematic_testing_start(scheduler_t* schedulers, pony_thread_id_t
158158
static uint32_t get_next_index()
159159
{
160160
uint32_t active_scheduler_count = pony_active_schedulers();
161-
uint32_t active_count = active_scheduler_count + 2; // account for asio and pinned actor thread
162-
uint32_t next_index = 0;
161+
bool pinned_actor_scheduler_suspended = ponyint_get_pinned_actor_scheduler_suspended();
162+
uint32_t active_count = active_scheduler_count + 1; // account for asio thread
163+
// account for pinned actor thread if it is not suspended
164+
if(!pinned_actor_scheduler_suspended)
165+
active_count = active_count + 1;
166+
167+
uint32_t next_index = -1;
163168
do
164169
{
165170
next_index = rand() % active_count;
171+
172+
// skip over pinned actor thread index if it is suspended
173+
if(pinned_actor_scheduler_suspended)
174+
next_index = next_index + 1;
175+
166176
pony_assert(next_index <= total_threads);
167177
}
168178
while (threads_to_track[next_index].stopped);

0 commit comments

Comments
 (0)