2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Move per-thread RCU setup into isc_thread

All the per-loop `libuv` setup remains in `isc_loop`, but the per-thread
RCU setup is moved to `isc_thread` alongside the other per-thread setup.
This avoids repeating the per-thread setup for `call_rcu()` helpers,
and explains a little better why some parts of the per-thread setup
is missing for `call_rcu()` helpers.

This also removes the per-loop `call_rcu()` helpers as we refactored the
isc__random_initialize() in the previous commit.
This commit is contained in:
Tony Finch
2023-03-31 20:42:47 +01:00
committed by Ondřej Surý
parent 65021dbf52
commit 7d1ceaf35d
5 changed files with 77 additions and 63 deletions

View File

@@ -103,6 +103,7 @@ resume_loop(isc_loop_t *loop) {
(void)isc_barrier_wait(&loopmgr->resuming);
loop->paused = false;
rcu_thread_online();
}
@@ -268,54 +269,17 @@ static void
quiescent_cb(uv_prepare_t *handle) {
isc__qsbr_quiescent_cb(handle);
#ifndef RCU_QSBR
INSIST(!rcu_read_ongoing());
#else
#if defined(RCU_QSBR)
/* safe memory reclamation */
rcu_quiescent_state();
/* mark the thread offline when polling */
rcu_thread_offline();
#else
INSIST(!rcu_read_ongoing());
#endif
}
static void
loop_call_rcu_init(struct rcu_head *rcu_head __attribute__((__unused__))) {
/* Work around the jemalloc bug, see trampoline.c for details */
void *ptr = malloc(8);
free(ptr);
/* Initialize the random generator in the call_rcu thread */
isc__random_initialize();
}
static void
loop_run(isc_loop_t *loop) {
int r = uv_prepare_start(&loop->quiescent, quiescent_cb);
UV_RUNTIME_CHECK(uv_prepare_start, r);
isc_barrier_wait(&loop->loopmgr->starting);
isc_async_run(loop, setup_jobs_cb, loop);
rcu_register_thread();
struct call_rcu_data *crdp = create_call_rcu_data(0, -1);
set_thread_call_rcu_data(crdp);
call_rcu(&loop->rcu_head, loop_call_rcu_init);
r = uv_run(&loop->loop, UV_RUN_DEFAULT);
UV_RUNTIME_CHECK(uv_run, r);
rcu_unregister_thread();
set_thread_call_rcu_data(NULL);
call_rcu_data_free(crdp);
isc_barrier_wait(&loop->loopmgr->stopping);
}
static void
loop_close(isc_loop_t *loop) {
int r = uv_loop_close(&loop->loop);
@@ -337,7 +301,17 @@ loop_thread(void *arg) {
isc__tid_init(loop->tid);
loop_run(loop);
int r = uv_prepare_start(&loop->quiescent, quiescent_cb);
UV_RUNTIME_CHECK(uv_prepare_start, r);
isc_barrier_wait(&loop->loopmgr->starting);
isc_async_run(loop, setup_jobs_cb, loop);
r = uv_run(&loop->loop, UV_RUN_DEFAULT);
UV_RUNTIME_CHECK(uv_run, r);
isc_barrier_wait(&loop->loopmgr->stopping);
return (NULL);
}
@@ -511,7 +485,7 @@ isc_loopmgr_run(isc_loopmgr_t *loopmgr) {
isc_thread_setname(loop->thread, name);
}
loop_thread(&loopmgr->loops[0]);
isc_thread_main(loop_thread, &loopmgr->loops[0]);
}
void