Bug #97150 rwlock: refine lock->recursive with C11 atomics
Submitted: 9 Oct 2019 1:37 Modified: 14 Feb 15:52
Reporter: Cai Yibo (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S5 (Performance)
Version:8.0 OS:Any
Assigned to: CPU Architecture:ARM
Tags: Contribution

[9 Oct 2019 1:37] Cai Yibo
Description:
This is a followup patch of Bug #96504(Refine atomics and barriers for weak memory order platform), https://bugs.mysql.com/bug.php?id=96504

Setting lock->recursive publishes valid lock->writer_thread, their
ordering must be enforced in both writing and reading side.

Current implementation uses wmb and rmb for this purpose. This patch
leverages C++11 memory model to refine it with store-release and
load-acquire ordering, which is designed for this typical use case
and more friendly to weak memory order platforms like Arm.

Atomic operations of current code are based on GCC __sync_xxx or
__atomic_xxx builtins for Linux and Solaris, and MSVC InterlockedXXX
ones for Windows.[1]

It's hard to add another set of atomic operations with memory order
parameters and keep existing code concise at the same time(without
exploding #ifdef). So I'm using C++11 std::atomic, which is supported
by all compilers per mysql8.0 source installation prerequisites.[2]
Added an os_atomic_t class which wraps std::atomic and does some
refinements, it will also be used in later patches.

[1] https://github.com/mysql/mysql-server/blob/8.0/storage/innobase/include/os0atomic.h
[2] https://dev.mysql.com/doc/refman/8.0/en/source-installation-prerequisites.html

How to repeat:
NA
[9 Oct 2019 1:40] Cai Yibo
patch

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: 0001-rwlock-refine-lock-recursive-with-C-11-atomics.patch (text/x-patch), 9.23 KiB.

[9 Oct 2019 12:02] Sinisa Milivojevic
Hi Mr. Yibo,

Thank you for your bug report.

I have analysed your patch and concluded that it is very useful for the ARM platform.

Verified as reported.
[14 Feb 15:52] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 8.0.20 release, and here's the changelog entry:

Read-write lock code (rw_lock_t) that controls ordering of access to the
boolean recursive flag and the writer thread ID using GCC builtins or
os_mutex when the builtins are not available, was revised to use C++
std::atomic in some instances.
[14 Feb 15:53] Sinisa Milivojevic
Thank you, Daniel.
[19 Feb 19:36] Daniel Price
Posted by developer:
 
Contribution from Cai Yibo is noted in the changelog entry.