File 2594-Remove-the-condition-variable-from-ErtsRunQueue_.patch of Package erlang
From c8179277b866457f26c87d6327ef90e233b1dc35 Mon Sep 17 00:00:00 2001
From: Robin Morisset <rmorisset@meta.com>
Date: Wed, 26 Mar 2025 09:55:45 -0700
Subject: [PATCH 14/15] Remove the condition variable from ErtsRunQueue_
It appears unused.
A comment next to it suggested that the sign of rq->waiting indicates
whether this condition variable is used. It appears that this sign is
always positive (against the comment), so I also removed the code for
the negative side, and the comment as well.
---
erts/emulator/beam/erl_process.c | 13 +++----------
erts/emulator/beam/erl_process.h | 3 +--
2 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c
index b67e03a52b..10036e2723 100644
--- a/erts/emulator/beam/erl_process.c
+++ b/erts/emulator/beam/erl_process.c
@@ -2921,7 +2921,7 @@ erts_active_schedulers(void)
{
Uint as = erts_no_schedulers;
- ERTS_ATOMIC_FOREACH_NORMAL_RUNQ(rq, as -= abs(rq->waiting));
+ ERTS_ATOMIC_FOREACH_NORMAL_RUNQ(rq, as -= rq->waiting);
return as;
}
@@ -2932,10 +2932,7 @@ sched_waiting(Uint no, ErtsRunQueue *rq)
ERTS_LC_ASSERT(erts_lc_runq_is_locked(rq));
(void) ERTS_RUNQ_FLGS_SET(rq, (ERTS_RUNQ_FLG_OUT_OF_WORK
| ERTS_RUNQ_FLG_HALFTIME_OUT_OF_WORK));
- if (rq->waiting < 0)
- rq->waiting--;
- else
- rq->waiting++;
+ rq->waiting++;
rq->woken = 0;
if (!ERTS_RUNQ_IX_IS_DIRTY(rq->ix) && erts_system_profile_flags.scheduler)
profile_scheduler(make_small(no), am_inactive);
@@ -2945,10 +2942,7 @@ static ERTS_INLINE void
sched_active(Uint no, ErtsRunQueue *rq)
{
ERTS_LC_ASSERT(erts_lc_runq_is_locked(rq));
- if (rq->waiting < 0)
- rq->waiting++;
- else
- rq->waiting--;
+ rq->waiting--;
if (!ERTS_RUNQ_IX_IS_DIRTY(rq->ix) && erts_system_profile_flags.scheduler)
profile_scheduler(make_small(no), am_active);
}
@@ -6147,7 +6141,6 @@ erts_init_scheduling(int no_schedulers, int no_schedulers_online, int no_poll_th
erts_mtx_init(&rq->mtx, "run_queue", make_small(ix + 1),
ERTS_LOCK_FLAGS_PROPERTY_STATIC | ERTS_LOCK_FLAGS_CATEGORY_SCHEDULER);
- erts_cnd_init(&rq->cnd);
if (ERTS_RUNQ_IX_IS_DIRTY(ix)) {
erts_mtx_init(&rq->sleepers.lock, "dirty_run_queue_sleep_list",
diff --git a/erts/emulator/beam/erl_process.h b/erts/emulator/beam/erl_process.h
index de96e35a6a..883a6acf68 100644
--- a/erts/emulator/beam/erl_process.h
+++ b/erts/emulator/beam/erl_process.h
@@ -472,12 +472,11 @@ struct ErtsRunQueue_ {
int ix;
erts_mtx_t mtx;
- erts_cnd_t cnd;
ErtsSchedulerSleepList sleepers;
ErtsSchedulerData *scheduler;
- int waiting; /* < 0 in sys schedule; > 0 on cnd variable */
+ int waiting;
int woken;
erts_atomic32_t flags;
int check_balance_reds;
--
2.43.0