summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-12-02 19:23:00 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2020-12-02 19:23:00 +0200
commit23643b7632d9c32c44e0e2133e6abecfbbf106a9 (patch)
tree3955269bae5773f4ae2af09a4ea14ca1baf8e6f0
parent6b0f2ce5673686a53e48bf3c1c5b37f8619100b7 (diff)
downloadmariadb-git-bb-10.6-MDEV-24142-2.tar.gz
MDEV-24142: De-inline the PERFORMANCE_SCHEMA instrumentationbb-10.6-MDEV-24142-2
Let us try to avoid code bloat for the common case that performance_schema is disabled at runtime, and use non-inlined functions for instrumented latch acquisition.
-rw-r--r--storage/innobase/include/srw_lock.h73
-rw-r--r--storage/innobase/sync/srw_lock.cc78
2 files changed, 95 insertions, 56 deletions
diff --git a/storage/innobase/include/srw_lock.h b/storage/innobase/include/srw_lock.h
index 0dd2add7c45..0ea0c14e814 100644
--- a/storage/innobase/include/srw_lock.h
+++ b/storage/innobase/include/srw_lock.h
@@ -115,6 +115,12 @@ class srw_lock
srw_lock_low lock;
PSI_rwlock *pfs_psi;
+ template<bool support_u_lock>
+ void psi_rd_lock(const char *file, unsigned line);
+ void psi_u_lock(const char *file, unsigned line);
+ template<bool support_u_lock>
+ void psi_wr_lock(const char *file, unsigned line);
+ void psi_u_wr_upgrade(const char *file, unsigned line);
public:
void init(mysql_pfs_key_t key)
{
@@ -134,23 +140,9 @@ public:
void rd_lock(const char *file, unsigned line)
{
if (psi_likely(pfs_psi != nullptr))
- {
- PSI_rwlock_locker_state state;
- uint32_t l;
- bool nowait= lock.read_trylock(l);
- PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)
- (&state, pfs_psi,
- support_u_lock
- ? (nowait ? PSI_RWLOCK_TRYSHAREDLOCK : PSI_RWLOCK_SHAREDLOCK)
- : (nowait ? PSI_RWLOCK_TRYREADLOCK : PSI_RWLOCK_READLOCK),
- file, line);
- if (!nowait)
- lock.read_lock(l);
- if (locker)
- PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
- return;
- }
- lock.rd_lock();
+ psi_rd_lock<support_u_lock>(file, line);
+ else
+ lock.rd_lock();
}
void rd_unlock()
{
@@ -161,16 +153,9 @@ public:
void u_lock(const char *file, unsigned line)
{
if (psi_likely(pfs_psi != nullptr))
- {
- PSI_rwlock_locker_state state;
- PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
- (&state, pfs_psi, PSI_RWLOCK_SHAREDEXCLUSIVELOCK, file, line);
+ psi_u_lock(file, line);
+ else
lock.u_lock();
- if (locker)
- PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
- return;
- }
- lock.u_lock();
}
void u_unlock()
{
@@ -182,22 +167,9 @@ public:
void wr_lock(const char *file, unsigned line)
{
if (psi_likely(pfs_psi != nullptr))
- {
- PSI_rwlock_locker_state state;
- bool nowait= lock.write_trylock();
- PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
- (&state, pfs_psi,
- support_u_lock
- ? (nowait ? PSI_RWLOCK_TRYEXCLUSIVELOCK : PSI_RWLOCK_EXCLUSIVELOCK)
- : (nowait ? PSI_RWLOCK_TRYWRITELOCK : PSI_RWLOCK_WRITELOCK),
- file, line);
- if (!nowait)
- lock.wr_lock();
- if (locker)
- PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
- return;
- }
- lock.wr_lock();
+ psi_wr_lock<support_u_lock>(file, line);
+ else
+ lock.wr_lock();
}
void wr_unlock()
{
@@ -208,20 +180,9 @@ public:
void u_wr_upgrade(const char *file, unsigned line)
{
if (psi_likely(pfs_psi != nullptr))
- {
- PSI_rwlock_locker_state state;
- bool nowait= lock.upgrade_trylock();
- PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
- (&state, pfs_psi,
- nowait ? PSI_RWLOCK_TRYEXCLUSIVELOCK : PSI_RWLOCK_EXCLUSIVELOCK,
- file, line);
- if (!nowait)
- lock.write_lock(true);
- if (locker)
- PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
- return;
- }
- lock.u_wr_upgrade();
+ psi_u_wr_upgrade(file, line);
+ else
+ lock.u_wr_upgrade();
}
bool rd_lock_try() { return lock.rd_lock_try(); }
bool u_lock_try() { return lock.u_lock_try(); }
diff --git a/storage/innobase/sync/srw_lock.cc b/storage/innobase/sync/srw_lock.cc
index 79594995b11..8ae9ed93293 100644
--- a/storage/innobase/sync/srw_lock.cc
+++ b/storage/innobase/sync/srw_lock.cc
@@ -225,3 +225,81 @@ void srw_lock_low::write_lock(bool holding_u)
void srw_lock_low::rd_unlock() { if (read_unlock()) writer_wake(); }
void srw_lock_low::u_unlock() { if (update_unlock()) writer_wake(); }
void srw_lock_low::wr_unlock() { write_unlock(); readers_wake(); }
+
+#ifdef UNIV_PFS_RWLOCK
+template<bool support_u_lock>
+void srw_lock::psi_rd_lock(const char *file, unsigned line)
+{
+ PSI_rwlock_locker_state state;
+ uint32_t l;
+ const bool nowait= lock.read_trylock(l);
+ if (PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)
+ (&state, pfs_psi,
+ support_u_lock
+ ? (nowait ? PSI_RWLOCK_TRYSHAREDLOCK : PSI_RWLOCK_SHAREDLOCK)
+ : (nowait ? PSI_RWLOCK_TRYREADLOCK : PSI_RWLOCK_READLOCK), file, line))
+ {
+ if (!nowait)
+ lock.read_lock(l);
+ PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
+ }
+ else if (!nowait)
+ lock.read_lock(l);
+}
+
+template void srw_lock::psi_rd_lock<false>(const char *, unsigned);
+template void srw_lock::psi_rd_lock<true>(const char *, unsigned);
+
+void srw_lock::psi_u_lock(const char *file, unsigned line)
+{
+ PSI_rwlock_locker_state state;
+ if (PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
+ (&state, pfs_psi, PSI_RWLOCK_SHAREDEXCLUSIVELOCK, file, line))
+ {
+ lock.u_lock();
+ PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
+ }
+ else
+ lock.u_lock();
+}
+
+template<bool support_u_lock>
+void srw_lock::psi_wr_lock(const char *file, unsigned line)
+{
+ PSI_rwlock_locker_state state;
+ const bool nowait= lock.write_trylock();
+ if (PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
+ (&state, pfs_psi,
+ support_u_lock
+ ? (nowait ? PSI_RWLOCK_TRYEXCLUSIVELOCK : PSI_RWLOCK_EXCLUSIVELOCK)
+ : (nowait ? PSI_RWLOCK_TRYWRITELOCK : PSI_RWLOCK_WRITELOCK),
+ file, line))
+ {
+ if (!nowait)
+ lock.wr_lock();
+ PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
+ }
+ else if (!nowait)
+ lock.wr_lock();
+}
+
+template void srw_lock::psi_wr_lock<false>(const char *, unsigned);
+template void srw_lock::psi_wr_lock<true>(const char *, unsigned);
+
+void srw_lock::psi_u_wr_upgrade(const char *file, unsigned line)
+{
+ PSI_rwlock_locker_state state;
+ const bool nowait= lock.upgrade_trylock();
+ if (PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
+ (&state, pfs_psi,
+ nowait ? PSI_RWLOCK_TRYEXCLUSIVELOCK : PSI_RWLOCK_EXCLUSIVELOCK,
+ file, line))
+ {
+ if (!nowait)
+ lock.write_lock(true);
+ PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
+ }
+ else if (!nowait)
+ lock.write_lock(true);
+}
+#endif /* UNIV_PFS_RWLOCK */