]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_dmclock_scheduler_ctx.h
import quincy 17.2.0
[ceph.git] / ceph / src / rgw / rgw_dmclock_scheduler_ctx.h
CommitLineData
9f95a23c
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab ft=cpp
3
11fdf7f2
TL
4#ifndef RGW_DMCLOCK_SCHEDULER_CTX_H
5#define RGW_DMCLOCK_SCHEDULER_CTX_H
6
7#include "common/perf_counters.h"
8#include "common/ceph_context.h"
9#include "common/config.h"
10#include "rgw_dmclock.h"
11
12namespace queue_counters {
13
14 enum {
15 l_first = 427150,
16 l_qlen,
17 l_cost,
18 l_res,
19 l_res_cost,
20 l_prio,
21 l_prio_cost,
22 l_limit,
23 l_limit_cost,
24 l_cancel,
25 l_cancel_cost,
26 l_res_latency,
27 l_prio_latency,
28 l_last,
29 };
30
31 PerfCountersRef build(CephContext *cct, const std::string& name);
32
33} // namespace queue_counters
34
35namespace throttle_counters {
36 enum {
37 l_first = 437219,
38 l_throttle,
f67539c2 39 l_outstanding,
11fdf7f2
TL
40 l_last
41 };
42
43 PerfCountersRef build(CephContext *cct, const std::string& name);
44} // namespace throttle
45
46namespace rgw::dmclock {
47
48// the last client counter would be for global scheduler stats
49static constexpr auto counter_size = static_cast<size_t>(client_id::count) + 1;
50/// array of per-client counters to serve as GetClientCounters
51class ClientCounters {
52 std::array<PerfCountersRef, counter_size> clients;
53 public:
54 ClientCounters(CephContext *cct);
55
56 PerfCounters* operator()(client_id client) const {
57 return clients[static_cast<size_t>(client)].get();
58 }
59};
60
61class ThrottleCounters {
62 PerfCountersRef counters;
63public:
64 ThrottleCounters(CephContext* const cct,const std::string& name):
65 counters(throttle_counters::build(cct, name)) {}
66
67 PerfCounters* operator()() const {
68 return counters.get();
69 }
70};
71
72
73struct ClientSum {
74 uint64_t count{0};
75 Cost cost{0};
76};
77
78constexpr auto client_count = static_cast<size_t>(client_id::count);
79using ClientSums = std::array<ClientSum, client_count>;
80
81void inc(ClientSums& sums, client_id client, Cost cost);
82void on_cancel(PerfCounters *c, const ClientSum& sum);
83void on_process(PerfCounters* c, const ClientSum& rsum, const ClientSum& psum);
84
85
86class ClientConfig : public md_config_obs_t {
87 std::vector<ClientInfo> clients;
88
89 void update(const ConfigProxy &conf);
90
91public:
92 ClientConfig(CephContext *cct);
93
94 ClientInfo* operator()(client_id client);
95
96 const char** get_tracked_conf_keys() const override;
97 void handle_conf_change(const ConfigProxy& conf,
98 const std::set<std::string>& changed) override;
99};
100
101class SchedulerCtx {
102public:
103 SchedulerCtx(CephContext* const cct) : sched_t(get_scheduler_t(cct))
104 {
105 if(sched_t == scheduler_t::dmclock) {
106 dmc_client_config = std::make_shared<ClientConfig>(cct);
107 // we don't have a move only cref std::function yet
108 dmc_client_counters = std::make_optional<ClientCounters>(cct);
109 }
110 }
111 // We need to construct a std::function from a NonCopyable object
112 ClientCounters& get_dmc_client_counters() { return dmc_client_counters.value(); }
113 ClientConfig* const get_dmc_client_config() const { return dmc_client_config.get(); }
114private:
115 scheduler_t sched_t;
116 std::shared_ptr<ClientConfig> dmc_client_config {nullptr};
117 std::optional<ClientCounters> dmc_client_counters {std::nullopt};
118};
119
120} // namespace rgw::dmclock
121
122#endif /* RGW_DMCLOCK_SCHEDULER_CTX_H */