Commit c8dd4117 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-22544 Inconsistent and Incorrect rw-lock stats

The rw_lock_stats were incorrectly updated.
While global statistics have limited usefulness, we cannot
remove them from a GA version. This contribution is slightly
improving performance in write workloads.
parents ad6171b9 dcb0bd59
...@@ -293,10 +293,13 @@ rw_lock_s_lock_spin( ...@@ -293,10 +293,13 @@ rw_lock_s_lock_spin(
ut_ad(rw_lock_validate(lock)); ut_ad(rw_lock_validate(lock));
rw_lock_stats.rw_s_spin_wait_count.inc();
lock_loop: lock_loop:
/* Spin waiting for the writer field to become free */ /* Spin waiting for the writer field to become free */
HMT_low(); HMT_low();
ulint j = i;
while (i < srv_n_spin_wait_rounds && lock->lock_word <= 0) { while (i < srv_n_spin_wait_rounds && lock->lock_word <= 0) {
ut_delay(srv_spin_wait_delay); ut_delay(srv_spin_wait_delay);
i++; i++;
...@@ -307,7 +310,7 @@ rw_lock_s_lock_spin( ...@@ -307,7 +310,7 @@ rw_lock_s_lock_spin(
os_thread_yield(); os_thread_yield();
} }
++spin_count; spin_count += lint(i - j);
/* We try once again to obtain the lock */ /* We try once again to obtain the lock */
if (rw_lock_s_lock_low(lock, pass, file_name, line)) { if (rw_lock_s_lock_low(lock, pass, file_name, line)) {
...@@ -428,7 +431,7 @@ rw_lock_x_lock_wait_func( ...@@ -428,7 +431,7 @@ rw_lock_x_lock_wait_func(
HMT_medium(); HMT_medium();
/* If there is still a reader, then go to sleep.*/ /* If there is still a reader, then go to sleep.*/
++n_spins; n_spins += i;
sync_cell_t* cell; sync_cell_t* cell;
...@@ -654,6 +657,12 @@ rw_lock_x_lock_func( ...@@ -654,6 +657,12 @@ rw_lock_x_lock_func(
ut_ad(rw_lock_validate(lock)); ut_ad(rw_lock_validate(lock));
ut_ad(!rw_lock_own(lock, RW_LOCK_S)); ut_ad(!rw_lock_own(lock, RW_LOCK_S));
if (rw_lock_x_lock_low(lock, pass, file_name, line)) {
/* Locking succeeded */
return;
}
rw_lock_stats.rw_x_spin_wait_count.inc();
lock_loop: lock_loop:
if (rw_lock_x_lock_low(lock, pass, file_name, line)) { if (rw_lock_x_lock_low(lock, pass, file_name, line)) {
...@@ -673,6 +682,7 @@ rw_lock_x_lock_func( ...@@ -673,6 +682,7 @@ rw_lock_x_lock_func(
/* Spin waiting for the lock_word to become free */ /* Spin waiting for the lock_word to become free */
HMT_low(); HMT_low();
ulint j = i;
while (i < srv_n_spin_wait_rounds while (i < srv_n_spin_wait_rounds
&& lock->lock_word <= X_LOCK_HALF_DECR) { && lock->lock_word <= X_LOCK_HALF_DECR) {
...@@ -681,7 +691,7 @@ rw_lock_x_lock_func( ...@@ -681,7 +691,7 @@ rw_lock_x_lock_func(
} }
HMT_medium(); HMT_medium();
spin_count += i; spin_count += lint(i - j);
if (i >= srv_n_spin_wait_rounds) { if (i >= srv_n_spin_wait_rounds) {
...@@ -749,11 +759,17 @@ rw_lock_sx_lock_func( ...@@ -749,11 +759,17 @@ rw_lock_sx_lock_func(
sync_array_t* sync_arr; sync_array_t* sync_arr;
ulint spin_count = 0; ulint spin_count = 0;
uint64_t count_os_wait = 0; uint64_t count_os_wait = 0;
ulint spin_wait_count = 0;
ut_ad(rw_lock_validate(lock)); ut_ad(rw_lock_validate(lock));
ut_ad(!rw_lock_own(lock, RW_LOCK_S)); ut_ad(!rw_lock_own(lock, RW_LOCK_S));
if (rw_lock_sx_lock_low(lock, pass, file_name, line)) {
/* Locking succeeded */
return;
}
rw_lock_stats.rw_sx_spin_wait_count.inc();
lock_loop: lock_loop:
if (rw_lock_sx_lock_low(lock, pass, file_name, line)) { if (rw_lock_sx_lock_low(lock, pass, file_name, line)) {
...@@ -765,16 +781,14 @@ rw_lock_sx_lock_func( ...@@ -765,16 +781,14 @@ rw_lock_sx_lock_func(
} }
rw_lock_stats.rw_sx_spin_round_count.add(spin_count); rw_lock_stats.rw_sx_spin_round_count.add(spin_count);
rw_lock_stats.rw_sx_spin_wait_count.add(spin_wait_count);
/* Locking succeeded */ /* Locking succeeded */
return; return;
} else { } else {
++spin_wait_count;
/* Spin waiting for the lock_word to become free */ /* Spin waiting for the lock_word to become free */
ulint j = i;
while (i < srv_n_spin_wait_rounds while (i < srv_n_spin_wait_rounds
&& lock->lock_word <= X_LOCK_HALF_DECR) { && lock->lock_word <= X_LOCK_HALF_DECR) {
...@@ -782,7 +796,7 @@ rw_lock_sx_lock_func( ...@@ -782,7 +796,7 @@ rw_lock_sx_lock_func(
i++; i++;
} }
spin_count += i; spin_count += lint(i - j);
if (i >= srv_n_spin_wait_rounds) { if (i >= srv_n_spin_wait_rounds) {
...@@ -814,7 +828,6 @@ rw_lock_sx_lock_func( ...@@ -814,7 +828,6 @@ rw_lock_sx_lock_func(
} }
rw_lock_stats.rw_sx_spin_round_count.add(spin_count); rw_lock_stats.rw_sx_spin_round_count.add(spin_count);
rw_lock_stats.rw_sx_spin_wait_count.add(spin_wait_count);
/* Locking succeeded */ /* Locking succeeded */
return; return;
......
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