]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: move Throttle to src/crimson/common. 35652/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 18 Jun 2020 13:24:14 +0000 (15:24 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 18 Jun 2020 14:15:45 +0000 (16:15 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/CMakeLists.txt
src/crimson/common/throttle.cc [new file with mode: 0644]
src/crimson/common/throttle.h [new file with mode: 0644]
src/crimson/net/Messenger.h
src/crimson/net/SocketConnection.h
src/crimson/thread/Throttle.cc [deleted file]
src/crimson/thread/Throttle.h [deleted file]
src/test/crimson/test_alien_echo.cc

index f11718fdeb2b76ee3a50d3add071ecdba682ffd6..e5b4da69888ea8df3b9aaff10cbbcca73a440e96 100644 (file)
@@ -19,7 +19,8 @@ set(crimson_common_srcs
   common/config_proxy.cc
   common/formatter.cc
   common/perf_counters_collection.cc
-  common/log.cc)
+  common/log.cc
+  common/throttle.cc)
 
 # the specialized version of ceph-common, where
 #  - the logging is sent to Seastar backend
@@ -166,14 +167,11 @@ set(crimson_net_srcs
   net/ProtocolV1.cc
   net/ProtocolV2.cc
   net/chained_dispatchers.cc)
-set(crimson_thread_srcs
-  thread/Throttle.cc)
 add_library(crimson STATIC
   ${crimson_auth_srcs}
   ${crimson_mgr_srcs}
   ${crimson_mon_srcs}
   ${crimson_net_srcs}
-  ${crimson_thread_srcs}
   ${CMAKE_SOURCE_DIR}/src/common/buffer_seastar.cc)
 target_compile_options(crimson PUBLIC
   "-ftemplate-backtrace-limit=0")
diff --git a/src/crimson/common/throttle.cc b/src/crimson/common/throttle.cc
new file mode 100644 (file)
index 0000000..4ddf77d
--- /dev/null
@@ -0,0 +1,59 @@
+#include "throttle.h"
+
+namespace crimson::common {
+
+int64_t Throttle::take(int64_t c)
+{
+  if (!max) {
+    return 0;
+  }
+  count += c;
+  return count;
+}
+
+int64_t Throttle::put(int64_t c)
+{
+  if (!max) {
+    return 0;
+  }
+  if (!c) {
+    return count;
+  }
+  on_free_slots.signal();
+  count -= c;
+  return count;
+}
+
+seastar::future<> Throttle::get(size_t c)
+{
+  if (!max) {
+    return seastar::now();
+  }
+  return on_free_slots.wait([this, c] {
+    return !_should_wait(c);
+  }).then([this, c] {
+    count += c;
+    return seastar::now();
+  });
+}
+
+void Throttle::reset_max(size_t m) {
+  if (max == m) {
+    return;
+  }
+
+  if (m > max) {
+    on_free_slots.signal();
+  }
+  max = m;
+}
+
+bool Throttle::_should_wait(size_t c) const {
+  if (!max) {
+    return false;
+  }
+  return ((c <= max && count + c > max) || // normally stay under max
+          (c >= max && count > max));      // except for large c
+}
+
+} // namespace crimson::common
diff --git a/src/crimson/common/throttle.h b/src/crimson/common/throttle.h
new file mode 100644 (file)
index 0000000..fea471c
--- /dev/null
@@ -0,0 +1,39 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <seastar/core/condition-variable.hh>
+// pull seastar::timer<...>::timer definitions. FIX SEASTAR or reactor.hh
+// is obligatory and should be included everywhere?
+#include <seastar/core/reactor.hh>
+
+#include "common/ThrottleInterface.h"
+
+namespace crimson::common {
+
+class Throttle final : public ThrottleInterface {
+  size_t max = 0;
+  size_t count = 0;
+  // we cannot change the "count" of seastar::semaphore after it is created,
+  // so use condition_variable instead.
+  seastar::condition_variable on_free_slots;
+public:
+  explicit Throttle(size_t m)
+    : max(m)
+  {}
+  int64_t take(int64_t c = 1) override;
+  int64_t put(int64_t c = 1) override;
+  seastar::future<> get(size_t c);
+  size_t get_current() const {
+    return count;
+  }
+  size_t get_max() const {
+    return max;
+  }
+  void reset_max(size_t m);
+private:
+  bool _should_wait(size_t c) const;
+};
+
+} // namespace crimson::common
index 2b136aa4fe09b207163ec9654004a186c0cac597..7065d2ad2afdff16b03e575553e8ef30192f4036 100644 (file)
@@ -17,8 +17,8 @@
 #include <seastar/core/future.hh>
 
 #include "Fwd.h"
+#include "crimson/common/throttle.h"
 #include "crimson/net/chained_dispatchers.h"
-#include "crimson/thread/Throttle.h"
 #include "msg/Message.h"
 #include "msg/Policy.h"
 
@@ -35,7 +35,7 @@ namespace crimson::net {
 class Interceptor;
 #endif
 
-using Throttle = crimson::thread::Throttle;
+using Throttle = crimson::common::Throttle;
 using SocketPolicy = ceph::net::Policy<Throttle>;
 
 class Messenger {
index 67657a6e190517f45ccddcee3f0371570ac4675a..0af08e0e4f28cc72448f37a7a7847adbd7d6649a 100644 (file)
 #include <seastar/core/sharded.hh>
 
 #include "msg/Policy.h"
+#include "crimson/common/throttle.h"
 #include "crimson/net/chained_dispatchers.h"
 #include "crimson/net/Connection.h"
 #include "crimson/net/Socket.h"
-#include "crimson/thread/Throttle.h"
 
 namespace crimson::net {
 
@@ -34,7 +34,7 @@ class SocketConnection : public Connection {
   SocketMessenger& messenger;
   std::unique_ptr<Protocol> protocol;
 
-  ceph::net::Policy<crimson::thread::Throttle> policy;
+  ceph::net::Policy<crimson::common::Throttle> policy;
 
   /// the seq num of the last transmitted message
   seq_num_t out_seq = 0;
diff --git a/src/crimson/thread/Throttle.cc b/src/crimson/thread/Throttle.cc
deleted file mode 100644 (file)
index 99be02f..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "Throttle.h"
-
-namespace crimson::thread {
-
-int64_t Throttle::take(int64_t c)
-{
-  if (!max) {
-    return 0;
-  }
-  count += c;
-  return count;
-}
-
-int64_t Throttle::put(int64_t c)
-{
-  if (!max) {
-    return 0;
-  }
-  if (!c) {
-    return count;
-  }
-  on_free_slots.signal();
-  count -= c;
-  return count;
-}
-
-seastar::future<> Throttle::get(size_t c)
-{
-  if (!max) {
-    return seastar::now();
-  }
-  return on_free_slots.wait([this, c] {
-    return !_should_wait(c);
-  }).then([this, c] {
-    count += c;
-    return seastar::now();
-  });
-}
-
-void Throttle::reset_max(size_t m) {
-  if (max == m) {
-    return;
-  }
-
-  if (m > max) {
-    on_free_slots.signal();
-  }
-  max = m;
-}
-
-bool Throttle::_should_wait(size_t c) const {
-  if (!max) {
-    return false;
-  }
-  return ((c <= max && count + c > max) || // normally stay under max
-          (c >= max && count > max));      // except for large c
-}
-
-} // namespace crimson::thread
diff --git a/src/crimson/thread/Throttle.h b/src/crimson/thread/Throttle.h
deleted file mode 100644 (file)
index 117924b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
-// vim: ts=8 sw=2 smarttab
-
-#pragma once
-
-#include <seastar/core/condition-variable.hh>
-// pull seastar::timer<...>::timer definitions. FIX SEASTAR or reactor.hh
-// is obligatory and should be included everywhere?
-#include <seastar/core/reactor.hh>
-
-#include "common/ThrottleInterface.h"
-
-namespace crimson::thread {
-
-class Throttle final : public ThrottleInterface {
-  size_t max = 0;
-  size_t count = 0;
-  // we cannot change the "count" of seastar::semaphore after it is created,
-  // so use condition_variable instead.
-  seastar::condition_variable on_free_slots;
-public:
-  explicit Throttle(size_t m)
-    : max(m)
-  {}
-  int64_t take(int64_t c = 1) override;
-  int64_t put(int64_t c = 1) override;
-  seastar::future<> get(size_t c);
-  size_t get_current() const {
-    return count;
-  }
-  size_t get_max() const {
-    return max;
-  }
-  void reset_max(size_t m);
-private:
-  bool _should_wait(size_t c) const;
-};
-
-} // namespace crimson::thread
index 0a0f22eb9aeba917b57352c867812ce94d590c8b..b5710adcbea07a39af365683a0cb08b1d8f52abf 100644 (file)
@@ -4,10 +4,10 @@
 #include "messages/MPing.h"
 #include "common/ceph_argparse.h"
 #include "crimson/auth/DummyAuth.h"
+#include "crimson/common/throttle.h"
 #include "crimson/net/Connection.h"
 #include "crimson/net/Dispatcher.h"
 #include "crimson/net/Messenger.h"
-#include "crimson/thread/Throttle.h"
 
 #include <seastar/core/alien.hh>
 #include <seastar/core/app-template.hh>
@@ -38,7 +38,7 @@ struct DummyAuthAuthorizer : public AuthAuthorizer {
 };
 
 struct Server {
-  crimson::thread::Throttle byte_throttler;
+  crimson::common::Throttle byte_throttler;
   crimson::net::MessengerRef msgr;
   crimson::auth::DummyAuthClientServer dummy_auth;
   struct ServerDispatcher : crimson::net::Dispatcher {
@@ -64,7 +64,7 @@ struct Server {
 };
 
 struct Client {
-  crimson::thread::Throttle byte_throttler;
+  crimson::common::Throttle byte_throttler;
   crimson::net::MessengerRef msgr;
   crimson::auth::DummyAuthClientServer dummy_auth;
   struct ClientDispatcher : crimson::net::Dispatcher {