]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/scheduler/mClockScheduler.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / osd / scheduler / mClockScheduler.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 Red Hat Inc.
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
16 #pragma once
17
18 #include <ostream>
19 #include <map>
20 #include <vector>
21
22 #include "boost/variant.hpp"
23
24 #include "dmclock/src/dmclock_server.h"
25
26 #include "osd/scheduler/OpScheduler.h"
27 #include "common/config.h"
28 #include "include/cmp.h"
29 #include "common/ceph_context.h"
30 #include "common/mClockPriorityQueue.h"
31 #include "osd/scheduler/OpSchedulerItem.h"
32
33
34 namespace ceph::osd::scheduler {
35
36 using client_id_t = uint64_t;
37 using profile_id_t = uint64_t;
38
39 struct client_profile_id_t {
40 client_id_t client_id;
41 profile_id_t profile_id;
42 };
43
44 WRITE_EQ_OPERATORS_2(client_profile_id_t, client_id, profile_id)
45 WRITE_CMP_OPERATORS_2(client_profile_id_t, client_id, profile_id)
46
47
48 struct scheduler_id_t {
49 op_scheduler_class class_id;
50 client_profile_id_t client_profile_id;
51 };
52
53 WRITE_EQ_OPERATORS_2(scheduler_id_t, class_id, client_profile_id)
54 WRITE_CMP_OPERATORS_2(scheduler_id_t, class_id, client_profile_id)
55
56 /**
57 * Scheduler implementation based on mclock.
58 *
59 * TODO: explain configs
60 */
61 class mClockScheduler : public OpScheduler, md_config_obs_t {
62
63 class ClientRegistry {
64 std::array<
65 crimson::dmclock::ClientInfo,
66 static_cast<size_t>(op_scheduler_class::immediate)
67 > internal_client_infos = {
68 // Placeholder, gets replaced with configured values
69 crimson::dmclock::ClientInfo(1, 1, 1),
70 crimson::dmclock::ClientInfo(1, 1, 1)
71 };
72
73 crimson::dmclock::ClientInfo default_external_client_info = {1, 1, 1};
74 std::map<client_profile_id_t,
75 crimson::dmclock::ClientInfo> external_client_infos;
76 const crimson::dmclock::ClientInfo *get_external_client(
77 const client_profile_id_t &client) const;
78 public:
79 void update_from_config(const ConfigProxy &conf);
80 const crimson::dmclock::ClientInfo *get_info(
81 const scheduler_id_t &id) const;
82 } client_registry;
83
84 using mclock_queue_t = crimson::dmclock::PullPriorityQueue<
85 scheduler_id_t,
86 OpSchedulerItem,
87 true,
88 true,
89 2>;
90 mclock_queue_t scheduler;
91 std::list<OpSchedulerItem> immediate;
92
93 static scheduler_id_t get_scheduler_id(const OpSchedulerItem &item) {
94 return scheduler_id_t{
95 item.get_scheduler_class(),
96 client_profile_id_t{
97 item.get_owner(),
98 0
99 }
100 };
101 }
102
103 public:
104 mClockScheduler(CephContext *cct);
105
106 // Enqueue op in the back of the regular queue
107 void enqueue(OpSchedulerItem &&item) final;
108
109 // Enqueue the op in the front of the regular queue
110 void enqueue_front(OpSchedulerItem &&item) final;
111
112 // Return an op to be dispatch
113 OpSchedulerItem dequeue() final;
114
115 // Returns if the queue is empty
116 bool empty() const final {
117 return immediate.empty() && scheduler.empty();
118 }
119
120 // Formatted output of the queue
121 void dump(ceph::Formatter &f) const final;
122
123 void print(std::ostream &ostream) const final {
124 ostream << "mClockScheduler";
125 }
126
127 const char** get_tracked_conf_keys() const final;
128 void handle_conf_change(const ConfigProxy& conf,
129 const std::set<std::string> &changed) final;
130 };
131
132 }