1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2018 SUSE Linux Gmbh
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.
17 #include "rgw_dmclock_scheduler.h"
18 #include "rgw_dmclock_scheduler_ctx.h"
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
{
25 std::condition_variable
& req_cv
;
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
) {};
34 class SyncScheduler
: public Scheduler
{
36 template <typename
...Args
>
37 SyncScheduler(CephContext
*cct
, GetClientCounters
&& counters
,
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
);
49 void cancel(const client_id
& client
);
51 static void handle_request_cb(const client_id
& c
, std::unique_ptr
<SyncRequest
> req
,
52 PhaseType phase
, Cost cost
);
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
58 return add_request(client
, params
, time
, cost
);
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
;
67 CephContext
const *cct
;
68 GetClientCounters counters
; //< provides per-client perf counters
71 template <typename
...Args
>
72 SyncScheduler::SyncScheduler(CephContext
*cct
, GetClientCounters
&& counters
,
74 queue(std::forward
<Args
>(args
)...), cct(cct
), counters(std::move(counters
))
77 } // namespace rgw::dmclock