]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_dmclock_scheduler.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / rgw / rgw_dmclock_scheduler.h
CommitLineData
11fdf7f2 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
11fdf7f2
TL
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2019 Red Hat, Inc.
7 * (C) 2019 SUSE LLC
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#ifndef RGW_DMCLOCK_SCHEDULER_H
16#define RGW_DMCLOCK_SCHEDULER_H
17
18#include "common/ceph_time.h"
19#include "common/ceph_context.h"
20#include "common/config.h"
21#include "common/async/yield_context.h"
22#include "rgw_dmclock.h"
23
24namespace rgw::dmclock {
25
26using crimson::dmclock::ReqParams;
27using crimson::dmclock::PhaseType;
28using crimson::dmclock::AtLimit;
29using crimson::dmclock::Time;
30using crimson::dmclock::get_time;
31
32/// function to provide client counters
33using GetClientCounters = std::function<PerfCounters*(client_id)>;
34
35struct Request {
36 client_id client;
37 Time started;
38 Cost cost;
39};
40
41enum class ReqState {
42 Wait,
43 Ready,
44 Cancelled
45};
46
47template <typename F>
48class Completer {
49public:
50 Completer(F &&f): f(std::move(f)) {}
51 // Default constructor is needed as we need to create an empty completer
52 // that'll be move assigned later in process request
53 Completer() = default;
54 ~Completer() {
55 if (f) {
56 f();
57 }
58 }
59 Completer(const Completer&) = delete;
60 Completer& operator=(const Completer&) = delete;
61 Completer(Completer&& other) = default;
62 Completer& operator=(Completer&& other) = default;
63private:
64 F f;
65};
66
67using SchedulerCompleter = Completer<std::function<void()>>;
68
69class Scheduler {
70public:
71 auto schedule_request(const client_id& client, const ReqParams& params,
72 const Time& time, const Cost& cost,
73 optional_yield yield)
74 {
75 int r = schedule_request_impl(client,params,time,cost,yield);
76 return std::make_pair(r,SchedulerCompleter(std::bind(&Scheduler::request_complete,this)));
77 }
78 virtual void request_complete() {};
79
80 virtual ~Scheduler() {};
81private:
82 virtual int schedule_request_impl(const client_id&, const ReqParams&,
83 const Time&, const Cost&,
84 optional_yield) = 0;
85};
86
87} // namespace rgw::dmclock
88
89#endif // RGW_DMCLOCK_SCHEDULER_H