From 04558290c0595a15c5fab77d6d91a6abcb4f0f04 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 26 May 2022 12:00:07 -0700 Subject: [PATCH] ircd: Toward improving cold/unlikely section population. --- include/ircd/panic.h | 4 ++-- ircd/assert.cc | 2 ++ ircd/cl.cc | 1 + ircd/client.cc | 1 + ircd/ctx.cc | 1 + ircd/ctx_ole.cc | 1 + ircd/db.cc | 5 +++-- ircd/db_database.cc | 1 + ircd/exception.cc | 14 +++++++++----- ircd/fpe.cc | 2 +- ircd/fs.cc | 4 ++-- ircd/fs_aio.cc | 1 + ircd/fs_iou.cc | 1 + ircd/info.cc | 1 - ircd/ios.cc | 3 +++ ircd/ircd.cc | 1 + ircd/json.cc | 12 ++++++------ ircd/magic.cc | 1 + ircd/magick.cc | 1 + ircd/mods.cc | 4 +++- ircd/net.cc | 1 + ircd/net_dns.cc | 1 + ircd/net_dns_netdb.cc | 1 + ircd/openssl.cc | 1 + ircd/rfc1035.cc | 1 + ircd/server.cc | 1 + 26 files changed, 47 insertions(+), 20 deletions(-) diff --git a/include/ircd/panic.h b/include/ircd/panic.h index 0eacb1a7c..de671d192 100644 --- a/include/ircd/panic.h +++ b/include/ircd/panic.h @@ -30,7 +30,7 @@ struct name \ :parent \ { \ template \ - [[gnu::noinline]] \ + [[gnu::noinline, gnu::cold]] \ name(const string_view &fmt, args&&... ap) noexcept \ :parent{generate_skip} \ { \ @@ -39,7 +39,7 @@ struct name \ } \ \ template \ - [[gnu::noinline]] \ + [[gnu::noinline, gnu::cold]] \ name(const string_view &fmt = " ") noexcept \ :parent{generate_skip} \ { \ diff --git a/ircd/assert.cc b/ircd/assert.cc index 532d8e73c..67afe21bb 100644 --- a/ircd/assert.cc +++ b/ircd/assert.cc @@ -15,6 +15,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #endif __clang__ +[[gnu::cold]] void __assert_fail(const char *__assertion, const char *__file, @@ -70,6 +71,7 @@ __assert_fail(const char *__assertion, #endif __clang__ #endif +[[gnu::cold]] void ircd::print_assertion(const char *const __assertion, const char *const __file, diff --git a/ircd/cl.cc b/ircd/cl.cc index fc3070fa9..e90b9d3b6 100644 --- a/ircd/cl.cc +++ b/ircd/cl.cc @@ -253,6 +253,7 @@ ircd::cl::init::init() log_dev_info(); } +[[gnu::cold]] ircd::cl::init::~init() noexcept { diff --git a/ircd/client.cc b/ircd/client.cc index 12cfbfb76..e6fd705bc 100644 --- a/ircd/client.cc +++ b/ircd/client.cc @@ -127,6 +127,7 @@ ircd::client::init::init() spawn(); } +[[gnu::cold]] ircd::client::init::~init() noexcept { diff --git a/ircd/ctx.cc b/ircd/ctx.cc index d065fec6c..a25a330e7 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -884,6 +884,7 @@ noexcept #endif #ifndef NDEBUG +[[gnu::cold]] void ircd::ctx::assert_critical() { diff --git a/ircd/ctx_ole.cc b/ircd/ctx_ole.cc index 9135a3341..1b1a590a0 100644 --- a/ircd/ctx_ole.cc +++ b/ircd/ctx_ole.cc @@ -40,6 +40,7 @@ ircd::ctx::ole::init::init() termination = false; } +[[gnu::cold]] ircd::ctx::ole::init::~init() noexcept { diff --git a/ircd/db.cc b/ircd/db.cc index fbc1d5ab5..b5eda0d59 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -138,6 +138,7 @@ catch(const std::exception &e) throw; } +[[gnu::cold]] ircd::db::init::~init() noexcept { @@ -1426,7 +1427,7 @@ ircd::db::txn::at(const op &op, const delta_closure &closure) const { - if(!get(op, col, closure)) + if(unlikely(!get(op, col, closure))) throw not_found { "db::txn::at(%s, %s): no matching delta in transaction", @@ -1476,7 +1477,7 @@ ircd::db::txn::at(const op &op, const value_closure &closure) const { - if(!get(op, col, key, closure)) + if(unlikely(!get(op, col, key, closure))) throw not_found { "db::txn::at(%s, %s, %s): no matching delta in transaction", diff --git a/ircd/db_database.cc b/ircd/db_database.cc index 17de80ea8..88f840dc0 100644 --- a/ircd/db_database.cc +++ b/ircd/db_database.cc @@ -2863,6 +2863,7 @@ noexcept }; } +[[gnu::cold]] void ircd::db::database::events::OnBackgroundError(rocksdb::BackgroundErrorReason reason, rocksdb::Status *const status) diff --git a/ircd/exception.cc b/ircd/exception.cc index a94827c64..59144ec38 100644 --- a/ircd/exception.cc +++ b/ircd/exception.cc @@ -8,13 +8,15 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. -[[noreturn]] static void +[[noreturn, gnu::cold]] +static void ircd_terminate_handler() noexcept { std::abort(); } +[[gnu::cold]] void ircd::_aborting_() noexcept @@ -22,6 +24,7 @@ noexcept std::set_terminate(&ircd_terminate_handler); } +[[gnu::cold]] void ircd::panicking(const std::exception_ptr &eptr) noexcept @@ -35,6 +38,7 @@ noexcept /// Called by the constructor of a panic exception when thown. We immediately /// log a critical message, which is actually what triggers a termination when /// assertions are enabled (!NDEBUG) otherwise a no-op. +[[gnu::cold]] void ircd::panicking(const std::exception &e) noexcept @@ -282,7 +286,7 @@ const noexcept // terminate // -[[noreturn]] +[[noreturn, gnu::cold]] ircd::terminate::terminate(std::exception_ptr eptr) noexcept { @@ -292,7 +296,7 @@ noexcept __builtin_unreachable(); } -[[noreturn]] +[[noreturn, gnu::cold]] ircd::terminate::terminate(const std::exception &e) noexcept :terminate @@ -303,7 +307,7 @@ noexcept __builtin_unreachable(); } -[[noreturn]] +[[noreturn, gnu::cold]] ircd::terminate::terminate() noexcept :terminate @@ -314,7 +318,7 @@ noexcept __builtin_unreachable(); } -[[noreturn]] +[[noreturn, gnu::cold]] ircd::terminate::~terminate() noexcept { diff --git a/ircd/fpe.cc b/ircd/fpe.cc index 7710c4880..6e8f5b287 100644 --- a/ircd/fpe.cc +++ b/ircd/fpe.cc @@ -12,7 +12,6 @@ #pragma STDC FENV_ACCESS on #endif -[[gnu::cold]] void ircd::fpe::debug_info() { @@ -68,6 +67,7 @@ ircd::fpe::debug_info() }; } +[[gnu::cold]] void ircd::fpe::_throw_errors(const ushort &flags) { diff --git a/ircd/fs.cc b/ircd/fs.cc index 38847c064..872cc6fb4 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -60,6 +60,7 @@ ircd::fs::init::init() init_dump_info(); } +[[gnu::cold]] ircd::fs::init::~init() noexcept { @@ -1646,7 +1647,6 @@ ircd::fs::aio::system; // #ifndef IRCD_USE_AIO -[[gnu::weak]] ircd::fs::aio::init::init() { assert(!system); @@ -1654,7 +1654,7 @@ ircd::fs::aio::init::init() #endif #ifndef IRCD_USE_AIO -[[gnu::weak]] +[[using gnu: weak, cold]] ircd::fs::aio::init::~init() noexcept { diff --git a/ircd/fs_aio.cc b/ircd/fs_aio.cc index a50ffd072..df421af30 100644 --- a/ircd/fs_aio.cc +++ b/ircd/fs_aio.cc @@ -126,6 +126,7 @@ ircd::fs::aio::init::init() ); } +[[gnu::cold]] ircd::fs::aio::init::~init() noexcept { diff --git a/ircd/fs_iou.cc b/ircd/fs_iou.cc index 95d2cdff4..7fc5e22f9 100644 --- a/ircd/fs_iou.cc +++ b/ircd/fs_iou.cc @@ -51,6 +51,7 @@ ircd::fs::iou::init::init() ); } +[[gnu::cold]] ircd::fs::iou::init::~init() noexcept { diff --git a/ircd/info.cc b/ircd/info.cc index 4d3d8415e..27b080451 100644 --- a/ircd/info.cc +++ b/ircd/info.cc @@ -42,7 +42,6 @@ ircd::info::credits nullptr }; -[[gnu::cold]] void ircd::info::dump() { diff --git a/ircd/ios.cc b/ircd/ios.cc index 8cc327df2..194a505da 100644 --- a/ircd/ios.cc +++ b/ircd/ios.cc @@ -78,6 +78,7 @@ ircd::ios::init(asio::executor &&user) ios::main = *ios::primary; } +[[gnu::cold]] void ircd::ios::forking() { @@ -88,6 +89,7 @@ ircd::ios::forking() #endif } +[[gnu::cold]] void ircd::ios::forked_child() { @@ -98,6 +100,7 @@ ircd::ios::forked_child() #endif } +[[gnu::cold]] void ircd::ios::forked_parent() { diff --git a/ircd/ircd.cc b/ircd/ircd.cc index 667ea11d5..99f694d52 100644 --- a/ircd/ircd.cc +++ b/ircd/ircd.cc @@ -246,6 +246,7 @@ catch(const std::exception &e) /// the run() will then return immediately after IRCd posts its transition to /// the HALT state. /// +[[gnu::cold]] bool ircd::quit() noexcept diff --git a/ircd/json.cc b/ircd/json.cc index e0b7c4dd9..76e6ca08b 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -595,7 +595,7 @@ noexcept }; } -[[gnu::noinline]] +[[gnu::noinline, gnu::cold, noreturn]] void ircd::json::parser::throws_exceeded() { @@ -626,7 +626,7 @@ ircd::json::replace(const object &s, } }; - if(!empty(s) && type(s) != type::OBJECT) + if(unlikely(!empty(s) && type(s) != type::OBJECT)) throw type_error { "Cannot replace member into JSON of type %s", @@ -652,7 +652,7 @@ ircd::json::strung ircd::json::replace(const object &s, const json::member &m_) { - if(!empty(s) && type(s) != type::OBJECT) + if(unlikely(!empty(s) && type(s) != type::OBJECT)) throw type_error { "Cannot replace member into JSON of type %s", @@ -676,7 +676,7 @@ ircd::json::strung ircd::json::insert(const object &s, const json::member &m) { - if(!empty(s) && type(s) != type::OBJECT) + if(unlikely(!empty(s) && type(s) != type::OBJECT)) throw type_error { "Cannot insert member into JSON of type %s", @@ -702,7 +702,7 @@ ircd::json::remove(const object &s, if(empty(s)) return s; - if(type(s) != type::OBJECT) + if(unlikely(type(s) != type::OBJECT)) throw type_error { "Cannot remove object member '%s' from JSON of type %s", @@ -729,7 +729,7 @@ ircd::json::remove(const object &s, if(empty(s)) return s; - if(type(s) != type::ARRAY) + if(unlikely(type(s) != type::ARRAY)) throw type_error { "Cannot remove array element [%zu] from JSON of type %s", diff --git a/ircd/magic.cc b/ircd/magic.cc index f0737203d..c45f25a52 100644 --- a/ircd/magic.cc +++ b/ircd/magic.cc @@ -106,6 +106,7 @@ ircd::magic::init::init() }; } +[[gnu::cold]] ircd::magic::init::~init() noexcept { diff --git a/ircd/magick.cc b/ircd/magick.cc index 639635c9e..f4c37075d 100644 --- a/ircd/magick.cc +++ b/ircd/magick.cc @@ -248,6 +248,7 @@ ircd::magick::init::init() }; } +[[gnu::cold]] ircd::magick::init::~init() noexcept { diff --git a/ircd/mods.cc b/ircd/mods.cc index 9592a8ffd..2f52095cd 100644 --- a/ircd/mods.cc +++ b/ircd/mods.cc @@ -126,7 +126,7 @@ noexcept children.size(), }; - if(!mapi::static_destruction) + if(unlikely(!mapi::static_destruction)) { handle_stuck(mod); return false; @@ -154,6 +154,7 @@ noexcept return true; } +[[gnu::cold]] void ircd::mods::handle_stuck(mod &mod) { @@ -182,6 +183,7 @@ ircd::mods::handle_stuck(mod &mod) }; } +[[gnu::cold]] void ircd::mods::handle_ebadf(const string_view &what) { diff --git a/ircd/net.cc b/ircd/net.cc index 4bd02fc0e..fe9f9c7f3 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -75,6 +75,7 @@ ircd::net::init::init() } /// Network subsystem shutdown +[[gnu::cold]] ircd::net::init::~init() noexcept { diff --git a/ircd/net_dns.cc b/ircd/net_dns.cc index e8e76a03f..a13992d73 100644 --- a/ircd/net_dns.cc +++ b/ircd/net_dns.cc @@ -42,6 +42,7 @@ ircd::net::dns::init::init() }; } +[[gnu::cold]] ircd::net::dns::init::~init() noexcept { diff --git a/ircd/net_dns_netdb.cc b/ircd/net_dns_netdb.cc index cb404ab0c..d11140cd5 100644 --- a/ircd/net_dns_netdb.cc +++ b/ircd/net_dns_netdb.cc @@ -47,6 +47,7 @@ ircd::net::dns::init::service_init() #endif } +[[gnu::cold]] void ircd::net::dns::init::service_fini() noexcept diff --git a/ircd/openssl.cc b/ircd/openssl.cc index ba05b876c..4d6f7d37e 100644 --- a/ircd/openssl.cc +++ b/ircd/openssl.cc @@ -1705,6 +1705,7 @@ ircd::openssl::init::init() */ } +[[gnu::cold]] ircd::openssl::init::~init() noexcept { diff --git a/ircd/rfc1035.cc b/ircd/rfc1035.cc index 979eca1b5..e9db8c908 100644 --- a/ircd/rfc1035.cc +++ b/ircd/rfc1035.cc @@ -550,6 +550,7 @@ ircd::rfc1035::valid_label(std::nothrow_t, return rfc3986::valid_hostname(std::nothrow, label); } +[[gnu::cold]] std::string ircd::rfc1035::header::debug() const diff --git a/ircd/server.cc b/ircd/server.cc index 4df41c69e..48cb98aa4 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -60,6 +60,7 @@ noexcept { } +[[gnu::cold]] ircd::server::init::~init() noexcept {