Commit 8b34aabf authored by Marko Mäkelä's avatar Marko Mäkelä

Follow-up to MDEV-12534: Align srv_sys

Allocate srv_sys statically so that the desired alignment can be
guaranteed. This silences -fsanitize=undefined warnings.
There probably is no performance impact of this, because the
reason for the alignment to ensure the absence of false sharing
between counters. Even with the misalignment, each counter would
have been been aligned at 64 bits, and the counters would reside
in separate cache lines.
parent 9f89b94b
...@@ -293,7 +293,7 @@ UNIV_INTERN double srv_adaptive_flushing_lwm = 10.0; ...@@ -293,7 +293,7 @@ UNIV_INTERN double srv_adaptive_flushing_lwm = 10.0;
UNIV_INTERN ulong srv_flushing_avg_loops = 30; UNIV_INTERN ulong srv_flushing_avg_loops = 30;
/* The number of purge threads to use.*/ /* The number of purge threads to use.*/
UNIV_INTERN ulong srv_n_purge_threads = 1; UNIV_INTERN ulong srv_n_purge_threads;
/* the number of pages to purge in one batch */ /* the number of pages to purge in one batch */
UNIV_INTERN ulong srv_purge_batch_size = 20; UNIV_INTERN ulong srv_purge_batch_size = 20;
...@@ -490,16 +490,16 @@ UNIV_INTERN uint srv_simulate_comp_failures = 0; ...@@ -490,16 +490,16 @@ UNIV_INTERN uint srv_simulate_comp_failures = 0;
/** Acquire the system_mutex. */ /** Acquire the system_mutex. */
#define srv_sys_mutex_enter() do { \ #define srv_sys_mutex_enter() do { \
mutex_enter(&srv_sys->mutex); \ mutex_enter(&srv_sys.mutex); \
} while (0) } while (0)
/** Test if the system mutex is owned. */ /** Test if the system mutex is owned. */
#define srv_sys_mutex_own() (mutex_own(&srv_sys->mutex) \ #define srv_sys_mutex_own() (mutex_own(&srv_sys.mutex) \
&& !srv_read_only_mode) && !srv_read_only_mode)
/** Release the system mutex. */ /** Release the system mutex. */
#define srv_sys_mutex_exit() do { \ #define srv_sys_mutex_exit() do { \
mutex_exit(&srv_sys->mutex); \ mutex_exit(&srv_sys.mutex); \
} while (0) } while (0)
#define fetch_lock_wait_timeout(trx) \ #define fetch_lock_wait_timeout(trx) \
...@@ -591,7 +591,7 @@ struct srv_sys_t{ ...@@ -591,7 +591,7 @@ struct srv_sys_t{
ulint n_sys_threads; /*!< size of the sys_threads ulint n_sys_threads; /*!< size of the sys_threads
array */ array */
srv_slot_t* sys_threads; /*!< server thread table; srv_slot_t sys_threads[32 + 1]; /*!< server thread table;
os_event_set() and os_event_set() and
os_event_reset() on os_event_reset() on
sys_threads[]->event are sys_threads[]->event are
...@@ -611,7 +611,7 @@ struct srv_sys_t{ ...@@ -611,7 +611,7 @@ struct srv_sys_t{
UNIV_INTERN ib_mutex_t server_mutex; UNIV_INTERN ib_mutex_t server_mutex;
#endif /* !HAVE_ATOMIC_BUILTINS */ #endif /* !HAVE_ATOMIC_BUILTINS */
static srv_sys_t* srv_sys = NULL; static srv_sys_t srv_sys;
/** Event to signal srv_monitor_thread. Not protected by a mutex. /** Event to signal srv_monitor_thread. Not protected by a mutex.
Set after setting srv_print_innodb_monitor. */ Set after setting srv_print_innodb_monitor. */
...@@ -633,10 +633,10 @@ and/or load it during startup. */ ...@@ -633,10 +633,10 @@ and/or load it during startup. */
UNIV_INTERN char srv_buffer_pool_dump_at_shutdown = FALSE; UNIV_INTERN char srv_buffer_pool_dump_at_shutdown = FALSE;
UNIV_INTERN char srv_buffer_pool_load_at_startup = FALSE; UNIV_INTERN char srv_buffer_pool_load_at_startup = FALSE;
/** Slot index in the srv_sys->sys_threads array for the purge thread. */ /** Slot index in the srv_sys.sys_threads array for the purge thread. */
static const ulint SRV_PURGE_SLOT = 1; static const ulint SRV_PURGE_SLOT = 1;
/** Slot index in the srv_sys->sys_threads array for the master thread. */ /** Slot index in the srv_sys.sys_threads array for the master thread. */
static const ulint SRV_MASTER_SLOT = 0; static const ulint SRV_MASTER_SLOT = 0;
/*********************************************************************//** /*********************************************************************//**
...@@ -737,21 +737,21 @@ srv_reserve_slot( ...@@ -737,21 +737,21 @@ srv_reserve_slot(
switch (type) { switch (type) {
case SRV_MASTER: case SRV_MASTER:
slot = &srv_sys->sys_threads[SRV_MASTER_SLOT]; slot = &srv_sys.sys_threads[SRV_MASTER_SLOT];
break; break;
case SRV_PURGE: case SRV_PURGE:
slot = &srv_sys->sys_threads[SRV_PURGE_SLOT]; slot = &srv_sys.sys_threads[SRV_PURGE_SLOT];
break; break;
case SRV_WORKER: case SRV_WORKER:
/* Find an empty slot, skip the master and purge slots. */ /* Find an empty slot, skip the master and purge slots. */
for (slot = &srv_sys->sys_threads[2]; for (slot = &srv_sys.sys_threads[2];
slot->in_use; slot->in_use;
++slot) { ++slot) {
ut_a(slot < &srv_sys->sys_threads[ ut_a(slot < &srv_sys.sys_threads[
srv_sys->n_sys_threads]); srv_sys.n_sys_threads]);
} }
break; break;
...@@ -767,7 +767,7 @@ srv_reserve_slot( ...@@ -767,7 +767,7 @@ srv_reserve_slot(
ut_ad(srv_slot_get_type(slot) == type); ut_ad(srv_slot_get_type(slot) == type);
++srv_sys->n_threads_active[type]; ++srv_sys.n_threads_active[type];
srv_sys_mutex_exit(); srv_sys_mutex_exit();
...@@ -797,27 +797,27 @@ srv_suspend_thread_low( ...@@ -797,27 +797,27 @@ srv_suspend_thread_low(
case SRV_MASTER: case SRV_MASTER:
/* We have only one master thread and it /* We have only one master thread and it
should be the first entry always. */ should be the first entry always. */
ut_a(srv_sys->n_threads_active[type] == 1); ut_a(srv_sys.n_threads_active[type] == 1);
break; break;
case SRV_PURGE: case SRV_PURGE:
/* We have only one purge coordinator thread /* We have only one purge coordinator thread
and it should be the second entry always. */ and it should be the second entry always. */
ut_a(srv_sys->n_threads_active[type] == 1); ut_a(srv_sys.n_threads_active[type] == 1);
break; break;
case SRV_WORKER: case SRV_WORKER:
ut_a(srv_n_purge_threads > 1); ut_a(srv_n_purge_threads > 1);
ut_a(srv_sys->n_threads_active[type] > 0); ut_a(srv_sys.n_threads_active[type] > 0);
break; break;
} }
ut_a(!slot->suspended); ut_a(!slot->suspended);
slot->suspended = TRUE; slot->suspended = TRUE;
ut_a(srv_sys->n_threads_active[type] > 0); ut_a(srv_sys.n_threads_active[type] > 0);
srv_sys->n_threads_active[type]--; srv_sys.n_threads_active[type]--;
return(os_event_reset(slot->event)); return(os_event_reset(slot->event));
} }
...@@ -872,7 +872,7 @@ srv_resume_thread(srv_slot_t* slot, ib_int64_t sig_count = 0, bool wait = true, ...@@ -872,7 +872,7 @@ srv_resume_thread(srv_slot_t* slot, ib_int64_t sig_count = 0, bool wait = true,
ut_ad(slot->suspended); ut_ad(slot->suspended);
slot->suspended = FALSE; slot->suspended = FALSE;
++srv_sys->n_threads_active[slot->type]; ++srv_sys.n_threads_active[slot->type];
srv_sys_mutex_exit(); srv_sys_mutex_exit();
return(timeout); return(timeout);
} }
...@@ -894,8 +894,8 @@ srv_release_threads(enum srv_thread_type type, ulint n) ...@@ -894,8 +894,8 @@ srv_release_threads(enum srv_thread_type type, ulint n)
srv_sys_mutex_enter(); srv_sys_mutex_enter();
for (ulint i = 0; i < srv_sys->n_sys_threads; i++) { for (ulint i = 0; i < srv_sys.n_sys_threads; i++) {
srv_slot_t* slot = &srv_sys->sys_threads[i]; srv_slot_t* slot = &srv_sys.sys_threads[i];
if (!slot->in_use || srv_slot_get_type(slot) != type) { if (!slot->in_use || srv_slot_get_type(slot) != type) {
continue; continue;
...@@ -915,7 +915,7 @@ srv_release_threads(enum srv_thread_type type, ulint n) ...@@ -915,7 +915,7 @@ srv_release_threads(enum srv_thread_type type, ulint n)
should be the first entry always. */ should be the first entry always. */
ut_a(n == 1); ut_a(n == 1);
ut_a(i == SRV_MASTER_SLOT); ut_a(i == SRV_MASTER_SLOT);
ut_a(srv_sys->n_threads_active[type] == 0); ut_a(srv_sys.n_threads_active[type] == 0);
break; break;
case SRV_PURGE: case SRV_PURGE:
...@@ -924,12 +924,12 @@ srv_release_threads(enum srv_thread_type type, ulint n) ...@@ -924,12 +924,12 @@ srv_release_threads(enum srv_thread_type type, ulint n)
ut_a(n == 1); ut_a(n == 1);
ut_a(i == SRV_PURGE_SLOT); ut_a(i == SRV_PURGE_SLOT);
ut_a(srv_n_purge_threads > 0); ut_a(srv_n_purge_threads > 0);
ut_a(srv_sys->n_threads_active[type] == 0); ut_a(srv_sys.n_threads_active[type] == 0);
break; break;
case SRV_WORKER: case SRV_WORKER:
ut_a(srv_n_purge_threads > 1); ut_a(srv_n_purge_threads > 1);
ut_a(srv_sys->n_threads_active[type] ut_a(srv_sys.n_threads_active[type]
< srv_n_purge_threads - 1); < srv_n_purge_threads - 1);
break; break;
} }
...@@ -967,9 +967,6 @@ void ...@@ -967,9 +967,6 @@ void
srv_init(void) srv_init(void)
/*==========*/ /*==========*/
{ {
ulint n_sys_threads = 0;
ulint srv_sys_sz = sizeof(*srv_sys);
#ifndef HAVE_ATOMIC_BUILTINS #ifndef HAVE_ATOMIC_BUILTINS
mutex_create(server_mutex_key, &server_mutex, SYNC_ANY_LATCH); mutex_create(server_mutex_key, &server_mutex, SYNC_ANY_LATCH);
#endif /* !HAVE_ATOMIC_BUILTINS */ #endif /* !HAVE_ATOMIC_BUILTINS */
...@@ -977,29 +974,19 @@ srv_init(void) ...@@ -977,29 +974,19 @@ srv_init(void)
mutex_create(srv_innodb_monitor_mutex_key, mutex_create(srv_innodb_monitor_mutex_key,
&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK); &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
if (!srv_read_only_mode) { srv_sys.n_sys_threads = srv_read_only_mode
? 0
/* Number of purge threads + master thread */ : srv_n_purge_threads + 1/* purge coordinator */;
n_sys_threads = srv_n_purge_threads + 1;
srv_sys_sz += n_sys_threads * sizeof(*srv_sys->sys_threads);
}
srv_sys = static_cast<srv_sys_t*>(mem_zalloc(srv_sys_sz));
srv_sys->n_sys_threads = n_sys_threads;
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
mutex_create(srv_sys_mutex_key, &srv_sys->mutex, SYNC_THREADS); mutex_create(srv_sys_mutex_key, &srv_sys.mutex, SYNC_THREADS);
mutex_create(srv_sys_tasks_mutex_key, mutex_create(srv_sys_tasks_mutex_key,
&srv_sys->tasks_mutex, SYNC_ANY_LATCH); &srv_sys.tasks_mutex, SYNC_ANY_LATCH);
srv_sys->sys_threads = (srv_slot_t*) &srv_sys[1];
for (ulint i = 0; i < srv_sys->n_sys_threads; ++i) { for (ulint i = 0; i < srv_sys.n_sys_threads; ++i) {
srv_slot_t* slot = &srv_sys->sys_threads[i]; srv_slot_t* slot = &srv_sys.sys_threads[i];
slot->event = os_event_create(); slot->event = os_event_create();
...@@ -1048,10 +1035,8 @@ srv_free(void) ...@@ -1048,10 +1035,8 @@ srv_free(void)
{ {
srv_conc_free(); srv_conc_free();
/* The mutexes srv_sys->mutex and srv_sys->tasks_mutex should have /* The mutexes srv_sys.mutex and srv_sys.tasks_mutex should have
been freed by sync_close() already. */ been freed by sync_close() already. */
mem_free(srv_sys);
srv_sys = NULL;
trx_i_s_cache_free(trx_i_s_cache); trx_i_s_cache_free(trx_i_s_cache);
...@@ -1882,7 +1867,7 @@ void ...@@ -1882,7 +1867,7 @@ void
srv_inc_activity_count(void) srv_inc_activity_count(void)
/*========================*/ /*========================*/
{ {
srv_sys->activity_count.inc(); srv_sys.activity_count.inc();
} }
/**********************************************************************//** /**********************************************************************//**
...@@ -1904,7 +1889,7 @@ srv_get_active_thread_type(void) ...@@ -1904,7 +1889,7 @@ srv_get_active_thread_type(void)
srv_sys_mutex_enter(); srv_sys_mutex_enter();
for (ulint i = SRV_WORKER; i <= SRV_MASTER; ++i) { for (ulint i = SRV_WORKER; i <= SRV_MASTER; ++i) {
if (srv_sys->n_threads_active[i] != 0) { if (srv_sys.n_threads_active[i] != 0) {
ret = static_cast<srv_thread_type>(i); ret = static_cast<srv_thread_type>(i);
break; break;
} }
...@@ -1977,12 +1962,12 @@ srv_active_wake_master_thread(void) ...@@ -1977,12 +1962,12 @@ srv_active_wake_master_thread(void)
srv_inc_activity_count(); srv_inc_activity_count();
if (srv_sys->n_threads_active[SRV_MASTER] == 0) { if (srv_sys.n_threads_active[SRV_MASTER] == 0) {
srv_slot_t* slot; srv_slot_t* slot;
srv_sys_mutex_enter(); srv_sys_mutex_enter();
slot = &srv_sys->sys_threads[SRV_MASTER_SLOT]; slot = &srv_sys.sys_threads[SRV_MASTER_SLOT];
/* Only if the master thread has been started. */ /* Only if the master thread has been started. */
...@@ -2009,7 +1994,7 @@ srv_wake_purge_thread_if_not_active(void) ...@@ -2009,7 +1994,7 @@ srv_wake_purge_thread_if_not_active(void)
ut_ad(!srv_sys_mutex_own()); ut_ad(!srv_sys_mutex_own());
if (purge_sys->state == PURGE_STATE_RUN if (purge_sys->state == PURGE_STATE_RUN
&& srv_sys->n_threads_active[SRV_PURGE] == 0) { && srv_sys.n_threads_active[SRV_PURGE] == 0) {
srv_release_threads(SRV_PURGE, 1); srv_release_threads(SRV_PURGE, 1);
} }
...@@ -2038,7 +2023,7 @@ ulint ...@@ -2038,7 +2023,7 @@ ulint
srv_get_activity_count(void) srv_get_activity_count(void)
/*========================*/ /*========================*/
{ {
return(srv_sys->activity_count); return(srv_sys.activity_count);
} }
/*******************************************************************//** /*******************************************************************//**
...@@ -2050,7 +2035,7 @@ srv_check_activity( ...@@ -2050,7 +2035,7 @@ srv_check_activity(
/*===============*/ /*===============*/
ulint old_activity_count) /*!< in: old activity count */ ulint old_activity_count) /*!< in: old activity count */
{ {
return(srv_sys->activity_count != old_activity_count); return(srv_sys.activity_count != old_activity_count);
} }
/********************************************************************//** /********************************************************************//**
...@@ -2415,7 +2400,7 @@ DECLARE_THREAD(srv_master_thread)( ...@@ -2415,7 +2400,7 @@ DECLARE_THREAD(srv_master_thread)(
srv_main_thread_id = os_thread_pf(os_thread_get_curr_id()); srv_main_thread_id = os_thread_pf(os_thread_get_curr_id());
slot = srv_reserve_slot(SRV_MASTER); slot = srv_reserve_slot(SRV_MASTER);
ut_a(slot == srv_sys->sys_threads); ut_a(slot == srv_sys.sys_threads);
last_print_time = ut_time(); last_print_time = ut_time();
loop: loop:
...@@ -2505,18 +2490,18 @@ srv_task_execute(void) ...@@ -2505,18 +2490,18 @@ srv_task_execute(void)
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
ut_a(srv_force_recovery < SRV_FORCE_NO_BACKGROUND); ut_a(srv_force_recovery < SRV_FORCE_NO_BACKGROUND);
mutex_enter(&srv_sys->tasks_mutex); mutex_enter(&srv_sys.tasks_mutex);
if (UT_LIST_GET_LEN(srv_sys->tasks) > 0) { if (UT_LIST_GET_LEN(srv_sys.tasks) > 0) {
thr = UT_LIST_GET_FIRST(srv_sys->tasks); thr = UT_LIST_GET_FIRST(srv_sys.tasks);
ut_a(que_node_get_type(thr->child) == QUE_NODE_PURGE); ut_a(que_node_get_type(thr->child) == QUE_NODE_PURGE);
UT_LIST_REMOVE(queue, srv_sys->tasks, thr); UT_LIST_REMOVE(queue, srv_sys.tasks, thr);
} }
mutex_exit(&srv_sys->tasks_mutex); mutex_exit(&srv_sys.tasks_mutex);
if (thr != NULL) { if (thr != NULL) {
...@@ -2556,7 +2541,7 @@ DECLARE_THREAD(srv_worker_thread)( ...@@ -2556,7 +2541,7 @@ DECLARE_THREAD(srv_worker_thread)(
srv_sys_mutex_enter(); srv_sys_mutex_enter();
ut_a(srv_sys->n_threads_active[SRV_WORKER] < srv_n_purge_threads); ut_a(srv_sys.n_threads_active[SRV_WORKER] < srv_n_purge_threads);
srv_sys_mutex_exit(); srv_sys_mutex_exit();
...@@ -2885,11 +2870,11 @@ srv_que_task_enqueue_low( ...@@ -2885,11 +2870,11 @@ srv_que_task_enqueue_low(
que_thr_t* thr) /*!< in: query thread */ que_thr_t* thr) /*!< in: query thread */
{ {
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
mutex_enter(&srv_sys->tasks_mutex); mutex_enter(&srv_sys.tasks_mutex);
UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr); UT_LIST_ADD_LAST(queue, srv_sys.tasks, thr);
mutex_exit(&srv_sys->tasks_mutex); mutex_exit(&srv_sys.tasks_mutex);
srv_release_threads(SRV_WORKER, 1); srv_release_threads(SRV_WORKER, 1);
} }
...@@ -2906,11 +2891,11 @@ srv_get_task_queue_length(void) ...@@ -2906,11 +2891,11 @@ srv_get_task_queue_length(void)
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
mutex_enter(&srv_sys->tasks_mutex); mutex_enter(&srv_sys.tasks_mutex);
n_tasks = UT_LIST_GET_LEN(srv_sys->tasks); n_tasks = UT_LIST_GET_LEN(srv_sys.tasks);
mutex_exit(&srv_sys->tasks_mutex); mutex_exit(&srv_sys.tasks_mutex);
return(n_tasks); return(n_tasks);
} }
......
...@@ -400,7 +400,7 @@ UNIV_INTERN my_bool srv_cleaner_thread_priority = FALSE; ...@@ -400,7 +400,7 @@ UNIV_INTERN my_bool srv_cleaner_thread_priority = FALSE;
UNIV_INTERN my_bool srv_master_thread_priority = FALSE; UNIV_INTERN my_bool srv_master_thread_priority = FALSE;
/* The number of purge threads to use.*/ /* The number of purge threads to use.*/
UNIV_INTERN ulong srv_n_purge_threads = 1; UNIV_INTERN ulong srv_n_purge_threads;
/* the number of pages to purge in one batch */ /* the number of pages to purge in one batch */
UNIV_INTERN ulong srv_purge_batch_size = 20; UNIV_INTERN ulong srv_purge_batch_size = 20;
...@@ -619,16 +619,16 @@ current_time % 5 != 0. */ ...@@ -619,16 +619,16 @@ current_time % 5 != 0. */
/** Acquire the system_mutex. */ /** Acquire the system_mutex. */
#define srv_sys_mutex_enter() do { \ #define srv_sys_mutex_enter() do { \
mutex_enter(&srv_sys->mutex); \ mutex_enter(&srv_sys.mutex); \
} while (0) } while (0)
/** Test if the system mutex is owned. */ /** Test if the system mutex is owned. */
#define srv_sys_mutex_own() (mutex_own(&srv_sys->mutex) \ #define srv_sys_mutex_own() (mutex_own(&srv_sys.mutex) \
&& !srv_read_only_mode) && !srv_read_only_mode)
/** Release the system mutex. */ /** Release the system mutex. */
#define srv_sys_mutex_exit() do { \ #define srv_sys_mutex_exit() do { \
mutex_exit(&srv_sys->mutex); \ mutex_exit(&srv_sys.mutex); \
} while (0) } while (0)
#define fetch_lock_wait_timeout(trx) \ #define fetch_lock_wait_timeout(trx) \
...@@ -723,7 +723,7 @@ struct srv_sys_t{ ...@@ -723,7 +723,7 @@ struct srv_sys_t{
ulint n_sys_threads; /*!< size of the sys_threads ulint n_sys_threads; /*!< size of the sys_threads
array */ array */
srv_slot_t* sys_threads; /*!< server thread table; srv_slot_t sys_threads[32 + 1]; /*!< server thread table;
os_event_set() and os_event_set() and
os_event_reset() on os_event_reset() on
sys_threads[]->event are sys_threads[]->event are
...@@ -747,7 +747,7 @@ struct srv_sys_t{ ...@@ -747,7 +747,7 @@ struct srv_sys_t{
UNIV_INTERN ib_mutex_t server_mutex; UNIV_INTERN ib_mutex_t server_mutex;
#endif /* !HAVE_ATOMIC_BUILTINS */ #endif /* !HAVE_ATOMIC_BUILTINS */
static srv_sys_t* srv_sys = NULL; static srv_sys_t srv_sys;
/** Event to signal srv_monitor_thread. Not protected by a mutex. /** Event to signal srv_monitor_thread. Not protected by a mutex.
Set after setting srv_print_innodb_monitor. */ Set after setting srv_print_innodb_monitor. */
...@@ -769,10 +769,10 @@ and/or load it during startup. */ ...@@ -769,10 +769,10 @@ and/or load it during startup. */
UNIV_INTERN char srv_buffer_pool_dump_at_shutdown = FALSE; UNIV_INTERN char srv_buffer_pool_dump_at_shutdown = FALSE;
UNIV_INTERN char srv_buffer_pool_load_at_startup = FALSE; UNIV_INTERN char srv_buffer_pool_load_at_startup = FALSE;
/** Slot index in the srv_sys->sys_threads array for the purge thread. */ /** Slot index in the srv_sys.sys_threads array for the purge thread. */
static const ulint SRV_PURGE_SLOT = 1; static const ulint SRV_PURGE_SLOT = 1;
/** Slot index in the srv_sys->sys_threads array for the master thread. */ /** Slot index in the srv_sys.sys_threads array for the master thread. */
static const ulint SRV_MASTER_SLOT = 0; static const ulint SRV_MASTER_SLOT = 0;
UNIV_INTERN os_event_t srv_checkpoint_completed_event; UNIV_INTERN os_event_t srv_checkpoint_completed_event;
...@@ -882,21 +882,21 @@ srv_reserve_slot( ...@@ -882,21 +882,21 @@ srv_reserve_slot(
switch (type) { switch (type) {
case SRV_MASTER: case SRV_MASTER:
slot = &srv_sys->sys_threads[SRV_MASTER_SLOT]; slot = &srv_sys.sys_threads[SRV_MASTER_SLOT];
break; break;
case SRV_PURGE: case SRV_PURGE:
slot = &srv_sys->sys_threads[SRV_PURGE_SLOT]; slot = &srv_sys.sys_threads[SRV_PURGE_SLOT];
break; break;
case SRV_WORKER: case SRV_WORKER:
/* Find an empty slot, skip the master and purge slots. */ /* Find an empty slot, skip the master and purge slots. */
for (slot = &srv_sys->sys_threads[2]; for (slot = &srv_sys.sys_threads[2];
slot->in_use; slot->in_use;
++slot) { ++slot) {
ut_a(slot < &srv_sys->sys_threads[ ut_a(slot < &srv_sys.sys_threads[
srv_sys->n_sys_threads]); srv_sys.n_sys_threads]);
} }
break; break;
...@@ -912,7 +912,7 @@ srv_reserve_slot( ...@@ -912,7 +912,7 @@ srv_reserve_slot(
ut_ad(srv_slot_get_type(slot) == type); ut_ad(srv_slot_get_type(slot) == type);
++srv_sys->n_threads_active[type]; ++srv_sys.n_threads_active[type];
srv_sys_mutex_exit(); srv_sys_mutex_exit();
...@@ -942,27 +942,27 @@ srv_suspend_thread_low( ...@@ -942,27 +942,27 @@ srv_suspend_thread_low(
case SRV_MASTER: case SRV_MASTER:
/* We have only one master thread and it /* We have only one master thread and it
should be the first entry always. */ should be the first entry always. */
ut_a(srv_sys->n_threads_active[type] == 1); ut_a(srv_sys.n_threads_active[type] == 1);
break; break;
case SRV_PURGE: case SRV_PURGE:
/* We have only one purge coordinator thread /* We have only one purge coordinator thread
and it should be the second entry always. */ and it should be the second entry always. */
ut_a(srv_sys->n_threads_active[type] == 1); ut_a(srv_sys.n_threads_active[type] == 1);
break; break;
case SRV_WORKER: case SRV_WORKER:
ut_a(srv_n_purge_threads > 1); ut_a(srv_n_purge_threads > 1);
ut_a(srv_sys->n_threads_active[type] > 0); ut_a(srv_sys.n_threads_active[type] > 0);
break; break;
} }
ut_a(!slot->suspended); ut_a(!slot->suspended);
slot->suspended = TRUE; slot->suspended = TRUE;
ut_a(srv_sys->n_threads_active[type] > 0); ut_a(srv_sys.n_threads_active[type] > 0);
srv_sys->n_threads_active[type]--; srv_sys.n_threads_active[type]--;
return(os_event_reset(slot->event)); return(os_event_reset(slot->event));
} }
...@@ -1017,7 +1017,7 @@ srv_resume_thread(srv_slot_t* slot, ib_int64_t sig_count = 0, bool wait = true, ...@@ -1017,7 +1017,7 @@ srv_resume_thread(srv_slot_t* slot, ib_int64_t sig_count = 0, bool wait = true,
ut_ad(slot->suspended); ut_ad(slot->suspended);
slot->suspended = FALSE; slot->suspended = FALSE;
++srv_sys->n_threads_active[slot->type]; ++srv_sys.n_threads_active[slot->type];
srv_sys_mutex_exit(); srv_sys_mutex_exit();
return(timeout); return(timeout);
} }
...@@ -1039,8 +1039,8 @@ srv_release_threads(enum srv_thread_type type, ulint n) ...@@ -1039,8 +1039,8 @@ srv_release_threads(enum srv_thread_type type, ulint n)
srv_sys_mutex_enter(); srv_sys_mutex_enter();
for (ulint i = 0; i < srv_sys->n_sys_threads; i++) { for (ulint i = 0; i < srv_sys.n_sys_threads; i++) {
srv_slot_t* slot = &srv_sys->sys_threads[i]; srv_slot_t* slot = &srv_sys.sys_threads[i];
if (!slot->in_use || srv_slot_get_type(slot) != type) { if (!slot->in_use || srv_slot_get_type(slot) != type) {
continue; continue;
...@@ -1060,7 +1060,7 @@ srv_release_threads(enum srv_thread_type type, ulint n) ...@@ -1060,7 +1060,7 @@ srv_release_threads(enum srv_thread_type type, ulint n)
should be the first entry always. */ should be the first entry always. */
ut_a(n == 1); ut_a(n == 1);
ut_a(i == SRV_MASTER_SLOT); ut_a(i == SRV_MASTER_SLOT);
ut_a(srv_sys->n_threads_active[type] == 0); ut_a(srv_sys.n_threads_active[type] == 0);
break; break;
case SRV_PURGE: case SRV_PURGE:
...@@ -1069,12 +1069,12 @@ srv_release_threads(enum srv_thread_type type, ulint n) ...@@ -1069,12 +1069,12 @@ srv_release_threads(enum srv_thread_type type, ulint n)
ut_a(n == 1); ut_a(n == 1);
ut_a(i == SRV_PURGE_SLOT); ut_a(i == SRV_PURGE_SLOT);
ut_a(srv_n_purge_threads > 0); ut_a(srv_n_purge_threads > 0);
ut_a(srv_sys->n_threads_active[type] == 0); ut_a(srv_sys.n_threads_active[type] == 0);
break; break;
case SRV_WORKER: case SRV_WORKER:
ut_a(srv_n_purge_threads > 1); ut_a(srv_n_purge_threads > 1);
ut_a(srv_sys->n_threads_active[type] ut_a(srv_sys.n_threads_active[type]
< srv_n_purge_threads - 1); < srv_n_purge_threads - 1);
break; break;
} }
...@@ -1112,9 +1112,6 @@ void ...@@ -1112,9 +1112,6 @@ void
srv_init(void) srv_init(void)
/*==========*/ /*==========*/
{ {
ulint n_sys_threads = 0;
ulint srv_sys_sz = sizeof(*srv_sys);
#ifndef HAVE_ATOMIC_BUILTINS #ifndef HAVE_ATOMIC_BUILTINS
mutex_create(server_mutex_key, &server_mutex, SYNC_ANY_LATCH); mutex_create(server_mutex_key, &server_mutex, SYNC_ANY_LATCH);
#endif /* !HAVE_ATOMIC_BUILTINS */ #endif /* !HAVE_ATOMIC_BUILTINS */
...@@ -1122,29 +1119,19 @@ srv_init(void) ...@@ -1122,29 +1119,19 @@ srv_init(void)
mutex_create(srv_innodb_monitor_mutex_key, mutex_create(srv_innodb_monitor_mutex_key,
&srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK); &srv_innodb_monitor_mutex, SYNC_NO_ORDER_CHECK);
if (!srv_read_only_mode) { srv_sys.n_sys_threads = srv_read_only_mode
? 0
/* Number of purge threads + master thread */ : srv_n_purge_threads + 1/* purge coordinator */;
n_sys_threads = srv_n_purge_threads + 1;
srv_sys_sz += n_sys_threads * sizeof(*srv_sys->sys_threads);
}
srv_sys = static_cast<srv_sys_t*>(mem_zalloc(srv_sys_sz));
srv_sys->n_sys_threads = n_sys_threads;
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
mutex_create(srv_sys_mutex_key, &srv_sys->mutex, SYNC_THREADS); mutex_create(srv_sys_mutex_key, &srv_sys.mutex, SYNC_THREADS);
mutex_create(srv_sys_tasks_mutex_key, mutex_create(srv_sys_tasks_mutex_key,
&srv_sys->tasks_mutex, SYNC_ANY_LATCH); &srv_sys.tasks_mutex, SYNC_ANY_LATCH);
srv_sys->sys_threads = (srv_slot_t*) &srv_sys[1]; for (ulint i = 0; i < srv_sys.n_sys_threads; ++i) {
srv_slot_t* slot = &srv_sys.sys_threads[i];
for (ulint i = 0; i < srv_sys->n_sys_threads; ++i) {
srv_slot_t* slot = &srv_sys->sys_threads[i];
slot->event = os_event_create(); slot->event = os_event_create();
...@@ -1203,8 +1190,8 @@ srv_free(void) ...@@ -1203,8 +1190,8 @@ srv_free(void)
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
for (ulint i = 0; i < srv_sys->n_sys_threads; i++) for (ulint i = 0; i < srv_sys.n_sys_threads; i++)
os_event_free(srv_sys->sys_threads[i].event); os_event_free(srv_sys.sys_threads[i].event);
os_event_free(srv_error_event); os_event_free(srv_error_event);
srv_error_event = NULL; srv_error_event = NULL;
...@@ -1216,8 +1203,8 @@ srv_free(void) ...@@ -1216,8 +1203,8 @@ srv_free(void)
srv_checkpoint_completed_event = NULL; srv_checkpoint_completed_event = NULL;
os_event_free(srv_redo_log_tracked_event); os_event_free(srv_redo_log_tracked_event);
srv_redo_log_tracked_event = NULL; srv_redo_log_tracked_event = NULL;
mutex_free(&srv_sys->mutex); mutex_free(&srv_sys.mutex);
mutex_free(&srv_sys->tasks_mutex); mutex_free(&srv_sys.tasks_mutex);
} }
#ifndef HAVE_ATOMIC_BUILTINS #ifndef HAVE_ATOMIC_BUILTINS
...@@ -1226,9 +1213,6 @@ srv_free(void) ...@@ -1226,9 +1213,6 @@ srv_free(void)
mutex_free(&srv_innodb_monitor_mutex); mutex_free(&srv_innodb_monitor_mutex);
mutex_free(&page_zip_stat_per_index_mutex); mutex_free(&page_zip_stat_per_index_mutex);
mem_free(srv_sys);
srv_sys = NULL;
trx_i_s_cache_free(trx_i_s_cache); trx_i_s_cache_free(trx_i_s_cache);
} }
...@@ -2305,9 +2289,9 @@ srv_inc_activity_count( ...@@ -2305,9 +2289,9 @@ srv_inc_activity_count(
is caused by the background is caused by the background
change buffer merge */ change buffer merge */
{ {
srv_sys->activity_count.inc(); srv_sys.activity_count.inc();
if (ibuf_merge_activity) if (ibuf_merge_activity)
srv_sys->ibuf_merge_activity_count.inc(); srv_sys.ibuf_merge_activity_count.inc();
} }
/**********************************************************************//** /**********************************************************************//**
...@@ -2329,7 +2313,7 @@ srv_get_active_thread_type(void) ...@@ -2329,7 +2313,7 @@ srv_get_active_thread_type(void)
srv_sys_mutex_enter(); srv_sys_mutex_enter();
for (ulint i = SRV_WORKER; i <= SRV_MASTER; ++i) { for (ulint i = SRV_WORKER; i <= SRV_MASTER; ++i) {
if (srv_sys->n_threads_active[i] != 0) { if (srv_sys.n_threads_active[i] != 0) {
ret = static_cast<srv_thread_type>(i); ret = static_cast<srv_thread_type>(i);
break; break;
} }
...@@ -2582,12 +2566,12 @@ srv_active_wake_master_thread(void) ...@@ -2582,12 +2566,12 @@ srv_active_wake_master_thread(void)
srv_inc_activity_count(); srv_inc_activity_count();
if (srv_sys->n_threads_active[SRV_MASTER] == 0) { if (srv_sys.n_threads_active[SRV_MASTER] == 0) {
srv_slot_t* slot; srv_slot_t* slot;
srv_sys_mutex_enter(); srv_sys_mutex_enter();
slot = &srv_sys->sys_threads[SRV_MASTER_SLOT]; slot = &srv_sys.sys_threads[SRV_MASTER_SLOT];
/* Only if the master thread has been started. */ /* Only if the master thread has been started. */
...@@ -2614,7 +2598,7 @@ srv_wake_purge_thread_if_not_active(void) ...@@ -2614,7 +2598,7 @@ srv_wake_purge_thread_if_not_active(void)
ut_ad(!srv_sys_mutex_own()); ut_ad(!srv_sys_mutex_own());
if (purge_sys->state == PURGE_STATE_RUN if (purge_sys->state == PURGE_STATE_RUN
&& srv_sys->n_threads_active[SRV_PURGE] == 0) { && srv_sys.n_threads_active[SRV_PURGE] == 0) {
srv_release_threads(SRV_PURGE, 1); srv_release_threads(SRV_PURGE, 1);
} }
...@@ -2643,7 +2627,7 @@ ulint ...@@ -2643,7 +2627,7 @@ ulint
srv_get_activity_count(void) srv_get_activity_count(void)
/*========================*/ /*========================*/
{ {
return(srv_sys->activity_count); return(srv_sys.activity_count);
} }
/** Get current server ibuf merge activity count. /** Get current server ibuf merge activity count.
...@@ -2652,7 +2636,7 @@ static ...@@ -2652,7 +2636,7 @@ static
ulint ulint
srv_get_ibuf_merge_activity_count(void) srv_get_ibuf_merge_activity_count(void)
{ {
return(srv_sys->ibuf_merge_activity_count); return(srv_sys.ibuf_merge_activity_count);
} }
/*******************************************************************//** /*******************************************************************//**
...@@ -2671,14 +2655,14 @@ srv_check_activity( ...@@ -2671,14 +2655,14 @@ srv_check_activity(
ULINT_UNDEFINED */ ULINT_UNDEFINED */
ulint old_ibuf_merge_activity_count) ulint old_ibuf_merge_activity_count)
{ {
ulint new_activity_count = srv_sys->activity_count; ulint new_activity_count = srv_sys.activity_count;
if (old_ibuf_merge_activity_count == ULINT_UNDEFINED) if (old_ibuf_merge_activity_count == ULINT_UNDEFINED)
return(new_activity_count != old_activity_count); return(new_activity_count != old_activity_count);
/* If we care about ibuf merge activity, then the server is considered /* If we care about ibuf merge activity, then the server is considered
idle if all activity, if any, was due to ibuf merge. */ idle if all activity, if any, was due to ibuf merge. */
ulint new_ibuf_merge_activity_count ulint new_ibuf_merge_activity_count
= srv_sys->ibuf_merge_activity_count; = srv_sys.ibuf_merge_activity_count;
ut_ad(new_ibuf_merge_activity_count <= new_activity_count); ut_ad(new_ibuf_merge_activity_count <= new_activity_count);
ut_ad(new_ibuf_merge_activity_count >= old_ibuf_merge_activity_count); ut_ad(new_ibuf_merge_activity_count >= old_ibuf_merge_activity_count);
...@@ -3069,7 +3053,7 @@ DECLARE_THREAD(srv_master_thread)( ...@@ -3069,7 +3053,7 @@ DECLARE_THREAD(srv_master_thread)(
srv_main_thread_id = os_thread_pf(os_thread_get_curr_id()); srv_main_thread_id = os_thread_pf(os_thread_get_curr_id());
slot = srv_reserve_slot(SRV_MASTER); slot = srv_reserve_slot(SRV_MASTER);
ut_a(slot == srv_sys->sys_threads); ut_a(slot == srv_sys.sys_threads);
last_print_time = ut_time(); last_print_time = ut_time();
loop: loop:
...@@ -3165,18 +3149,18 @@ srv_task_execute(void) ...@@ -3165,18 +3149,18 @@ srv_task_execute(void)
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
ut_a(srv_force_recovery < SRV_FORCE_NO_BACKGROUND); ut_a(srv_force_recovery < SRV_FORCE_NO_BACKGROUND);
mutex_enter(&srv_sys->tasks_mutex); mutex_enter(&srv_sys.tasks_mutex);
if (UT_LIST_GET_LEN(srv_sys->tasks) > 0) { if (UT_LIST_GET_LEN(srv_sys.tasks) > 0) {
thr = UT_LIST_GET_FIRST(srv_sys->tasks); thr = UT_LIST_GET_FIRST(srv_sys.tasks);
ut_a(que_node_get_type(thr->child) == QUE_NODE_PURGE); ut_a(que_node_get_type(thr->child) == QUE_NODE_PURGE);
UT_LIST_REMOVE(queue, srv_sys->tasks, thr); UT_LIST_REMOVE(queue, srv_sys.tasks, thr);
} }
mutex_exit(&srv_sys->tasks_mutex); mutex_exit(&srv_sys.tasks_mutex);
if (thr != NULL) { if (thr != NULL) {
...@@ -3226,7 +3210,7 @@ DECLARE_THREAD(srv_worker_thread)( ...@@ -3226,7 +3210,7 @@ DECLARE_THREAD(srv_worker_thread)(
srv_sys_mutex_enter(); srv_sys_mutex_enter();
ut_a(srv_sys->n_threads_active[SRV_WORKER] < srv_n_purge_threads); ut_a(srv_sys.n_threads_active[SRV_WORKER] < srv_n_purge_threads);
srv_sys_mutex_exit(); srv_sys_mutex_exit();
...@@ -3566,11 +3550,11 @@ srv_que_task_enqueue_low( ...@@ -3566,11 +3550,11 @@ srv_que_task_enqueue_low(
que_thr_t* thr) /*!< in: query thread */ que_thr_t* thr) /*!< in: query thread */
{ {
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
mutex_enter(&srv_sys->tasks_mutex); mutex_enter(&srv_sys.tasks_mutex);
UT_LIST_ADD_LAST(queue, srv_sys->tasks, thr); UT_LIST_ADD_LAST(queue, srv_sys.tasks, thr);
mutex_exit(&srv_sys->tasks_mutex); mutex_exit(&srv_sys.tasks_mutex);
srv_release_threads(SRV_WORKER, 1); srv_release_threads(SRV_WORKER, 1);
} }
...@@ -3587,11 +3571,11 @@ srv_get_task_queue_length(void) ...@@ -3587,11 +3571,11 @@ srv_get_task_queue_length(void)
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
mutex_enter(&srv_sys->tasks_mutex); mutex_enter(&srv_sys.tasks_mutex);
n_tasks = UT_LIST_GET_LEN(srv_sys->tasks); n_tasks = UT_LIST_GET_LEN(srv_sys.tasks);
mutex_exit(&srv_sys->tasks_mutex); mutex_exit(&srv_sys.tasks_mutex);
return(n_tasks); return(n_tasks);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment