]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_dmclock_sync_scheduler.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / rgw_dmclock_sync_scheduler.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2018 SUSE Linux Gmbh
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #pragma once
16
17 #include "rgw_dmclock_scheduler.h"
18 #include "rgw_dmclock_scheduler_ctx.h"
19
20 namespace rgw::dmclock {
21 // For a blocking SyncRequest we hold a reference to a cv and the caller must
22 // ensure the lifetime
23 struct SyncRequest : public Request {
24 std::mutex& req_mtx;
25 std::condition_variable& req_cv;
26 ReqState& req_state;
27 GetClientCounters& counters;
28 explicit SyncRequest(client_id _id, Time started, Cost cost,
29 std::mutex& mtx, std::condition_variable& _cv,
30 ReqState& _state, GetClientCounters& counters):
31 Request{_id, started, cost}, req_mtx(mtx), req_cv(_cv), req_state(_state), counters(counters) {};
32 };
33
34 class SyncScheduler: public Scheduler {
35 public:
36 template <typename ...Args>
37 SyncScheduler(CephContext *cct, GetClientCounters&& counters,
38 Args&& ...args);
39 ~SyncScheduler();
40
41 // submit a blocking request for dmclock scheduling, this function waits until
42 // the request is ready.
43 int add_request(const client_id& client, const ReqParams& params,
44 const Time& time, Cost cost);
45
46
47 void cancel();
48
49 void cancel(const client_id& client);
50
51 static void handle_request_cb(const client_id& c, std::unique_ptr<SyncRequest> req,
52 PhaseType phase, Cost cost);
53 private:
54 int schedule_request_impl(const client_id& client, const ReqParams& params,
55 const Time& time, const Cost& cost,
56 optional_yield _y [[maybe_unused]]) override
57 {
58 return add_request(client, params, time, cost);
59 }
60
61 static constexpr bool IsDelayed = false;
62 using Queue = crimson::dmclock::PushPriorityQueue<client_id, SyncRequest, IsDelayed>;
63 using RequestRef = typename Queue::RequestRef;
64 using Clock = ceph::coarse_real_clock;
65
66 Queue queue;
67 CephContext const *cct;
68 GetClientCounters counters; //< provides per-client perf counters
69 };
70
71 template <typename ...Args>
72 SyncScheduler::SyncScheduler(CephContext *cct, GetClientCounters&& counters,
73 Args&& ...args):
74 queue(std::forward<Args>(args)...), cct(cct), counters(std::move(counters))
75 {}
76
77 } // namespace rgw::dmclock