From 2fed9397d5f1a93e01d02b5914931420c4f28c37 Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Tue, 27 Jun 2023 10:31:11 +0800 Subject: [PATCH] crimson/net: cleanup, rename is_fixed_cpu Signed-off-by: Yingxin Cheng --- src/crimson/net/Messenger.cc | 4 ++-- src/crimson/net/Messenger.h | 2 +- src/crimson/net/Socket.cc | 22 ++++++++++++---------- src/crimson/net/Socket.h | 16 +++++++++++----- src/crimson/net/SocketMessenger.cc | 8 ++++---- src/crimson/net/SocketMessenger.h | 4 ++-- src/test/crimson/test_socket.cc | 2 +- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/crimson/net/Messenger.cc b/src/crimson/net/Messenger.cc index 9068453838812..1af1985897fda 100644 --- a/src/crimson/net/Messenger.cc +++ b/src/crimson/net/Messenger.cc @@ -10,10 +10,10 @@ MessengerRef Messenger::create(const entity_name_t& name, const std::string& lname, uint64_t nonce, - bool is_fixed_cpu) + bool dispatch_only_on_this_shard) { return seastar::make_shared( - name, lname, nonce, is_fixed_cpu); + name, lname, nonce, dispatch_only_on_this_shard); } } // namespace crimson::net diff --git a/src/crimson/net/Messenger.h b/src/crimson/net/Messenger.h index c06655d85b852..74df062d8de07 100644 --- a/src/crimson/net/Messenger.h +++ b/src/crimson/net/Messenger.h @@ -109,7 +109,7 @@ public: create(const entity_name_t& name, const std::string& lname, uint64_t nonce, - bool is_fixed_cpu); + bool dispatch_only_on_this_shard); #ifdef UNIT_TESTS_BUILT virtual void set_interceptor(Interceptor *) = 0; diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index da2140db69427..0894724a2ffa4 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -353,9 +353,9 @@ Socket::try_trap_post(bp_action_t& trap) { ShardedServerSocket::ShardedServerSocket( seastar::shard_id sid, - bool is_fixed_cpu, + bool dispatch_only_on_primary_sid, construct_tag) - : primary_sid{sid}, is_fixed_cpu{is_fixed_cpu} + : primary_sid{sid}, dispatch_only_on_primary_sid{dispatch_only_on_primary_sid} { } @@ -376,7 +376,7 @@ ShardedServerSocket::listen(entity_addr_t addr) seastar::socket_address s_addr(addr.in4_addr()); seastar::listen_options lo; lo.reuse_address = true; - if (ss.is_fixed_cpu) { + if (ss.dispatch_only_on_primary_sid) { lo.set_fixed_cpu(ss.primary_sid); } ss.listener = seastar::listen(s_addr, lo); @@ -414,7 +414,7 @@ ShardedServerSocket::accept(accept_func_t &&_fn_accept) return ss.listener->accept( ).then([&ss](seastar::accept_result accept_result) { #ifndef NDEBUG - if (ss.is_fixed_cpu) { + if (ss.dispatch_only_on_primary_sid) { // see seastar::listen_options::set_fixed_cpu() ceph_assert_always(seastar::this_shard_id() == ss.primary_sid); } @@ -426,9 +426,10 @@ ShardedServerSocket::accept(accept_func_t &&_fn_accept) SocketRef _socket = std::make_unique( std::move(socket), Socket::side_t::acceptor, peer_addr.get_port(), Socket::construct_tag{}); - logger().debug("ShardedServerSocket({})::accept(): " - "accepted peer {}, socket {}, is_fixed = {}", - ss.listen_addr, peer_addr, fmt::ptr(_socket), ss.is_fixed_cpu); + logger().debug("ShardedServerSocket({})::accept(): accepted peer {}, " + "socket {}, dispatch_only_on_primary_sid = {}", + ss.listen_addr, peer_addr, fmt::ptr(_socket), + ss.dispatch_only_on_primary_sid); std::ignore = seastar::with_gate( ss.shutdown_gate, [socket=std::move(_socket), peer_addr, &ss]() mutable { @@ -498,13 +499,14 @@ ShardedServerSocket::shutdown_destroy() } seastar::future -ShardedServerSocket::create(bool is_fixed_cpu) +ShardedServerSocket::create(bool dispatch_only_on_this_shard) { auto primary_sid = seastar::this_shard_id(); // start the sharded service: we should only construct/stop shards on #0 - return seastar::smp::submit_to(0, [primary_sid, is_fixed_cpu] { + return seastar::smp::submit_to(0, [primary_sid, dispatch_only_on_this_shard] { auto service = std::make_unique(); - return service->start(primary_sid, is_fixed_cpu, construct_tag{} + return service->start( + primary_sid, dispatch_only_on_this_shard, construct_tag{} ).then([service = std::move(service)]() mutable { auto p_shard = service.get(); p_shard->local().service = std::move(service); diff --git a/src/crimson/net/Socket.h b/src/crimson/net/Socket.h index 3d42abdb44b89..478f2d630208c 100644 --- a/src/crimson/net/Socket.h +++ b/src/crimson/net/Socket.h @@ -158,7 +158,10 @@ class ShardedServerSocket struct construct_tag {}; public: - ShardedServerSocket(seastar::shard_id sid, bool is_fixed_cpu, construct_tag); + ShardedServerSocket( + seastar::shard_id sid, + bool dispatch_only_on_primary_sid, + construct_tag); ~ShardedServerSocket(); @@ -167,7 +170,9 @@ public: ShardedServerSocket& operator=(ShardedServerSocket&&) = delete; ShardedServerSocket& operator=(const ShardedServerSocket&) = delete; - bool is_fixed() const { return is_fixed_cpu; } + bool is_fixed_shard_dispatching() const { + return dispatch_only_on_primary_sid; + } listen_ertr::future<> listen(entity_addr_t addr); @@ -177,12 +182,13 @@ public: seastar::future<> shutdown_destroy(); - static seastar::future create(bool is_fixed_cpu); + static seastar::future create( + bool dispatch_only_on_this_shard); private: - // the fixed CPU if is_fixed_cpu is true const seastar::shard_id primary_sid; - const bool is_fixed_cpu; + /// XXX: Remove once all infrastructure uses multi-core messenger + const bool dispatch_only_on_primary_sid; entity_addr_t listen_addr; std::optional listener; seastar::gate shutdown_gate; diff --git a/src/crimson/net/SocketMessenger.cc b/src/crimson/net/SocketMessenger.cc index 019c879d66ea3..382d08f986ce9 100644 --- a/src/crimson/net/SocketMessenger.cc +++ b/src/crimson/net/SocketMessenger.cc @@ -35,11 +35,11 @@ namespace crimson::net { SocketMessenger::SocketMessenger(const entity_name_t& myname, const std::string& logic_name, uint32_t nonce, - bool is_fixed_cpu) + bool dispatch_only_on_this_shard) : sid{seastar::this_shard_id()}, logic_name{logic_name}, nonce{nonce}, - is_fixed_cpu{is_fixed_cpu}, + dispatch_only_on_sid{dispatch_only_on_this_shard}, my_name{myname} {} @@ -94,7 +94,7 @@ SocketMessenger::do_listen(const entity_addrvec_t& addrs) set_myaddrs(addrs); return seastar::futurize_invoke([this] { if (!listener) { - return ShardedServerSocket::create(is_fixed_cpu + return ShardedServerSocket::create(dispatch_only_on_sid ).then([this] (auto _listener) { listener = _listener; }); @@ -232,7 +232,7 @@ seastar::future<> SocketMessenger::start( return listener->accept([this](SocketRef _socket, entity_addr_t peer_addr) { assert(get_myaddr().is_msgr2()); SocketFRef socket = seastar::make_foreign(std::move(_socket)); - if (listener->is_fixed()) { + if (listener->is_fixed_shard_dispatching()) { return accept(std::move(socket), peer_addr); } else { return seastar::smp::submit_to(sid, diff --git a/src/crimson/net/SocketMessenger.h b/src/crimson/net/SocketMessenger.h index 8d696bf885f27..e4ac631846df7 100644 --- a/src/crimson/net/SocketMessenger.h +++ b/src/crimson/net/SocketMessenger.h @@ -37,7 +37,7 @@ public: SocketMessenger(const entity_name_t& myname, const std::string& logic_name, uint32_t nonce, - bool is_fixed_cpu); + bool dispatch_only_on_this_shard); ~SocketMessenger() override; @@ -165,7 +165,7 @@ private: // Distinguish messengers with meaningful names for debugging const std::string logic_name; const uint32_t nonce; - const bool is_fixed_cpu; + const bool dispatch_only_on_sid; entity_name_t my_name; entity_addrvec_t my_addrs; diff --git a/src/test/crimson/test_socket.cc b/src/test/crimson/test_socket.cc index 1fa029c2ca2b4..17052c16d7a1c 100644 --- a/src/test/crimson/test_socket.cc +++ b/src/test/crimson/test_socket.cc @@ -202,7 +202,7 @@ class SocketFactory { logger().info("dispatch_sockets(): accepted at shard {}", seastar::this_shard_id()); psf->server_socket_CPU = seastar::this_shard_id(); - if (psf->pss->is_fixed()) { + if (psf->pss->is_fixed_shard_dispatching()) { ceph_assert_always(SERVER_CPU == seastar::this_shard_id()); } SocketFRef socket = seastar::make_foreign(std::move(_socket)); -- 2.39.5