MDEV-14529 - InnoDB rw-locks: optimize memory barriers

Remove volatile modifier from waiters: it's not supposed for inter-thread
communication, use appropriate atomic operations instead.

Changed waiters to int32_t, my_atomic friendly type.
This commit is contained in:
Sergey Vojtovich 2017-12-01 13:37:07 +04:00
commit 5b624f00fc
5 changed files with 13 additions and 10 deletions

View file

@ -574,7 +574,7 @@ struct rw_lock_t
int32_t lock_word; int32_t lock_word;
/** 1: there are waiters */ /** 1: there are waiters */
volatile uint32_t waiters; int32_t waiters;
/** number of granted SX locks. */ /** number of granted SX locks. */
volatile ulint sx_recursive; volatile ulint sx_recursive;

View file

@ -418,7 +418,7 @@ rw_lock_x_unlock_func(
We need to signal read/write waiters. We need to signal read/write waiters.
We do not need to signal wait_ex waiters, since they cannot We do not need to signal wait_ex waiters, since they cannot
exist when there is a writer. */ exist when there is a writer. */
if (my_atomic_load32_explicit((int32*) &lock->waiters, if (my_atomic_load32_explicit(&lock->waiters,
MY_MEMORY_ORDER_RELAXED)) { MY_MEMORY_ORDER_RELAXED)) {
my_atomic_store32((int32*) &lock->waiters, 0); my_atomic_store32((int32*) &lock->waiters, 0);
os_event_set(lock->event); os_event_set(lock->event);
@ -472,7 +472,8 @@ rw_lock_sx_unlock_func(
waiters. We do not need to signal wait_ex waiters, waiters. We do not need to signal wait_ex waiters,
since they cannot exist when there is an sx-lock since they cannot exist when there is an sx-lock
holder. */ holder. */
if (lock->waiters) { if (my_atomic_load32_explicit(&lock->waiters,
MY_MEMORY_ORDER_RELAXED)) {
my_atomic_store32((int32*) &lock->waiters, 0); my_atomic_store32((int32*) &lock->waiters, 0);
os_event_set(lock->event); os_event_set(lock->event);
sync_array_object_signalled(); sync_array_object_signalled();

View file

@ -1984,7 +1984,8 @@ row_merge_read_clustered_index(
} }
if (dbug_run_purge if (dbug_run_purge
|| dict_index_get_lock(clust_index)->waiters) { || my_atomic_load32_explicit(&clust_index->lock.waiters,
MY_MEMORY_ORDER_RELAXED)) {
/* There are waiters on the clustered /* There are waiters on the clustered
index tree lock, likely the purge index tree lock, likely the purge
thread. Store and restore the cursor thread. Store and restore the cursor

View file

@ -588,7 +588,7 @@ sync_array_cell_print(
fprintf(file, fprintf(file,
"number of readers " ULINTPF "number of readers " ULINTPF
", waiters flag %u, " ", waiters flag %d, "
"lock_word: %x\n" "lock_word: %x\n"
"Last time read locked in file %s line %u\n" "Last time read locked in file %s line %u\n"
"Last time write locked in file %s line %u" "Last time write locked in file %s line %u"
@ -598,7 +598,7 @@ sync_array_cell_print(
#endif #endif
"\n", "\n",
rw_lock_get_reader_count(rwlock), rw_lock_get_reader_count(rwlock),
rwlock->waiters, my_atomic_load32_explicit(&rwlock->waiters, MY_MEMORY_ORDER_RELAXED),
my_atomic_load32_explicit(&rwlock->lock_word, MY_MEMORY_ORDER_RELAXED), my_atomic_load32_explicit(&rwlock->lock_word, MY_MEMORY_ORDER_RELAXED),
innobase_basename(rwlock->last_s_file_name), innobase_basename(rwlock->last_s_file_name),
rwlock->last_s_line, rwlock->last_s_line,
@ -1397,7 +1397,8 @@ sync_arr_fill_sys_semphore_waits_table(
//OK(fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->store(rwlock->line, true)); //OK(fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->store(rwlock->line, true));
//fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->set_notnull(); //fields[SYS_SEMAPHORE_WAITS_HOLDER_LINE]->set_notnull();
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_READERS], rw_lock_get_reader_count(rwlock))); OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_READERS], rw_lock_get_reader_count(rwlock)));
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAITERS_FLAG], (longlong)rwlock->waiters)); OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_WAITERS_FLAG],
my_atomic_load32_explicit(&rwlock->waiters, MY_MEMORY_ORDER_RELAXED)));
OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LOCK_WORD], OK(field_store_ulint(fields[SYS_SEMAPHORE_WAITS_LOCK_WORD],
my_atomic_load32_explicit(&rwlock->lock_word, MY_MEMORY_ORDER_RELAXED))); my_atomic_load32_explicit(&rwlock->lock_word, MY_MEMORY_ORDER_RELAXED)));
OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_READER_FILE], innobase_basename(rwlock->last_s_file_name))); OK(field_store_string(fields[SYS_SEMAPHORE_WAITS_LAST_READER_FILE], innobase_basename(rwlock->last_s_file_name)));

View file

@ -897,7 +897,7 @@ rw_lock_validate(
MY_MEMORY_ORDER_RELAXED); MY_MEMORY_ORDER_RELAXED);
ut_ad(lock->magic_n == RW_LOCK_MAGIC_N); ut_ad(lock->magic_n == RW_LOCK_MAGIC_N);
ut_ad(my_atomic_load32_explicit((int32*) &lock->waiters, ut_ad(my_atomic_load32_explicit(const_cast<int32_t*>(&lock->waiters),
MY_MEMORY_ORDER_RELAXED) < 2); MY_MEMORY_ORDER_RELAXED) < 2);
ut_ad(lock_word > -(2 * X_LOCK_DECR)); ut_ad(lock_word > -(2 * X_LOCK_DECR));
ut_ad(lock_word <= X_LOCK_DECR); ut_ad(lock_word <= X_LOCK_DECR);
@ -1166,8 +1166,8 @@ rw_lock_list_print_info(
fprintf(file, "RW-LOCK: %p ", (void*) lock); fprintf(file, "RW-LOCK: %p ", (void*) lock);
if (lock->waiters) { if (int32_t waiters= my_atomic_load32_explicit(const_cast<int32_t*>(&lock->waiters), MY_MEMORY_ORDER_RELAXED)) {
fputs(" Waiters for the lock exist\n", file); fprintf(file, " (%d waiters)\n", waiters);
} else { } else {
putc('\n', file); putc('\n', file);
} }