Commit 23643b76 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-24142: De-inline the PERFORMANCE_SCHEMA instrumentation

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.
parent 6b0f2ce5
...@@ -115,6 +115,12 @@ class srw_lock ...@@ -115,6 +115,12 @@ class srw_lock
srw_lock_low lock; srw_lock_low lock;
PSI_rwlock *pfs_psi; 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: public:
void init(mysql_pfs_key_t key) void init(mysql_pfs_key_t key)
{ {
...@@ -134,22 +140,8 @@ class srw_lock ...@@ -134,22 +140,8 @@ class srw_lock
void rd_lock(const char *file, unsigned line) void rd_lock(const char *file, unsigned line)
{ {
if (psi_likely(pfs_psi != nullptr)) if (psi_likely(pfs_psi != nullptr))
{ psi_rd_lock<support_u_lock>(file, line);
PSI_rwlock_locker_state state; else
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(); lock.rd_lock();
} }
void rd_unlock() void rd_unlock()
...@@ -161,15 +153,8 @@ class srw_lock ...@@ -161,15 +153,8 @@ class srw_lock
void u_lock(const char *file, unsigned line) void u_lock(const char *file, unsigned line)
{ {
if (psi_likely(pfs_psi != nullptr)) if (psi_likely(pfs_psi != nullptr))
{ psi_u_lock(file, line);
PSI_rwlock_locker_state state; else
PSI_rwlock_locker *locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)
(&state, pfs_psi, PSI_RWLOCK_SHAREDEXCLUSIVELOCK, file, line);
lock.u_lock();
if (locker)
PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, 0);
return;
}
lock.u_lock(); lock.u_lock();
} }
void u_unlock() void u_unlock()
...@@ -182,21 +167,8 @@ class srw_lock ...@@ -182,21 +167,8 @@ class srw_lock
void wr_lock(const char *file, unsigned line) void wr_lock(const char *file, unsigned line)
{ {
if (psi_likely(pfs_psi != nullptr)) if (psi_likely(pfs_psi != nullptr))
{ psi_wr_lock<support_u_lock>(file, line);
PSI_rwlock_locker_state state; else
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(); lock.wr_lock();
} }
void wr_unlock() void wr_unlock()
...@@ -208,19 +180,8 @@ class srw_lock ...@@ -208,19 +180,8 @@ class srw_lock
void u_wr_upgrade(const char *file, unsigned line) void u_wr_upgrade(const char *file, unsigned line)
{ {
if (psi_likely(pfs_psi != nullptr)) if (psi_likely(pfs_psi != nullptr))
{ psi_u_wr_upgrade(file, line);
PSI_rwlock_locker_state state; else
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(); lock.u_wr_upgrade();
} }
bool rd_lock_try() { return lock.rd_lock_try(); } bool rd_lock_try() { return lock.rd_lock_try(); }
......
...@@ -225,3 +225,81 @@ void srw_lock_low::write_lock(bool holding_u) ...@@ -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::rd_unlock() { if (read_unlock()) writer_wake(); }
void srw_lock_low::u_unlock() { if (update_unlock()) writer_wake(); } void srw_lock_low::u_unlock() { if (update_unlock()) writer_wake(); }
void srw_lock_low::wr_unlock() { write_unlock(); readers_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 */
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