]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_dmclock_scheduler_ctx.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #ifndef RGW_DMCLOCK_SCHEDULER_CTX_H
5 #define RGW_DMCLOCK_SCHEDULER_CTX_H
7 #include "common/perf_counters.h"
8 #include "common/ceph_context.h"
9 #include "common/config.h"
10 #include "rgw_dmclock.h"
12 namespace queue_counters
{
31 PerfCountersRef
build(CephContext
*cct
, const std::string
& name
);
33 } // namespace queue_counters
35 namespace throttle_counters
{
42 PerfCountersRef
build(CephContext
*cct
, const std::string
& name
);
43 } // namespace throttle
45 namespace rgw::dmclock
{
47 // the last client counter would be for global scheduler stats
48 static constexpr auto counter_size
= static_cast<size_t>(client_id::count
) + 1;
49 /// array of per-client counters to serve as GetClientCounters
50 class ClientCounters
{
51 std::array
<PerfCountersRef
, counter_size
> clients
;
53 ClientCounters(CephContext
*cct
);
55 PerfCounters
* operator()(client_id client
) const {
56 return clients
[static_cast<size_t>(client
)].get();
60 class ThrottleCounters
{
61 PerfCountersRef counters
;
63 ThrottleCounters(CephContext
* const cct
,const std::string
& name
):
64 counters(throttle_counters::build(cct
, name
)) {}
66 PerfCounters
* operator()() const {
67 return counters
.get();
77 constexpr auto client_count
= static_cast<size_t>(client_id::count
);
78 using ClientSums
= std::array
<ClientSum
, client_count
>;
80 void inc(ClientSums
& sums
, client_id client
, Cost cost
);
81 void on_cancel(PerfCounters
*c
, const ClientSum
& sum
);
82 void on_process(PerfCounters
* c
, const ClientSum
& rsum
, const ClientSum
& psum
);
85 class ClientConfig
: public md_config_obs_t
{
86 std::vector
<ClientInfo
> clients
;
88 void update(const ConfigProxy
&conf
);
91 ClientConfig(CephContext
*cct
);
93 ClientInfo
* operator()(client_id client
);
95 const char** get_tracked_conf_keys() const override
;
96 void handle_conf_change(const ConfigProxy
& conf
,
97 const std::set
<std::string
>& changed
) override
;
102 SchedulerCtx(CephContext
* const cct
) : sched_t(get_scheduler_t(cct
))
104 if(sched_t
== scheduler_t::dmclock
) {
105 dmc_client_config
= std::make_shared
<ClientConfig
>(cct
);
106 // we don't have a move only cref std::function yet
107 dmc_client_counters
= std::make_optional
<ClientCounters
>(cct
);
110 // We need to construct a std::function from a NonCopyable object
111 ClientCounters
& get_dmc_client_counters() { return dmc_client_counters
.value(); }
112 ClientConfig
* const get_dmc_client_config() const { return dmc_client_config
.get(); }
115 std::shared_ptr
<ClientConfig
> dmc_client_config
{nullptr};
116 std::optional
<ClientCounters
> dmc_client_counters
{std::nullopt
};
119 } // namespace rgw::dmclock
121 #endif /* RGW_DMCLOCK_SCHEDULER_CTX_H */