]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/osd/scheduler/mclock_scheduler.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / crimson / osd / scheduler / mclock_scheduler.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 "crimson/osd/scheduler/scheduler.h"
27 #include "common/config.h"
28 #include "include/cmp.h"
29 #include "common/ceph_context.h"
30
31
32 namespace crimson::osd::scheduler {
33
34 using client_id_t = uint64_t;
35 using profile_id_t = uint64_t;
36
37 struct client_profile_id_t {
38 client_id_t client_id;
39 profile_id_t profile_id;
40 };
41
42 WRITE_EQ_OPERATORS_2(client_profile_id_t, client_id, profile_id)
43 WRITE_CMP_OPERATORS_2(client_profile_id_t, client_id, profile_id)
44
45
46 struct scheduler_id_t {
47 scheduler_class_t class_id;
48 client_profile_id_t client_profile_id;
49 };
50
51 WRITE_EQ_OPERATORS_2(scheduler_id_t, class_id, client_profile_id)
52 WRITE_CMP_OPERATORS_2(scheduler_id_t, class_id, client_profile_id)
53
54 /**
55 * Scheduler implementation based on mclock.
56 *
57 * TODO: explain configs
58 */
59 class mClockScheduler : public Scheduler, md_config_obs_t {
60
61 class ClientRegistry {
62 std::array<
63 crimson::dmclock::ClientInfo,
64 static_cast<size_t>(scheduler_class_t::client)
65 > internal_client_infos = {
66 // Placeholder, gets replaced with configured values
67 crimson::dmclock::ClientInfo(1, 1, 1),
68 crimson::dmclock::ClientInfo(1, 1, 1)
69 };
70
71 crimson::dmclock::ClientInfo default_external_client_info = {1, 1, 1};
72 std::map<client_profile_id_t,
73 crimson::dmclock::ClientInfo> external_client_infos;
74 const crimson::dmclock::ClientInfo *get_external_client(
75 const client_profile_id_t &client) const;
76 public:
77 void update_from_config(const ConfigProxy &conf);
78 const crimson::dmclock::ClientInfo *get_info(
79 const scheduler_id_t &id) const;
80 } client_registry;
81
82 using mclock_queue_t = crimson::dmclock::PullPriorityQueue<
83 scheduler_id_t,
84 item_t,
85 true,
86 true,
87 2>;
88 mclock_queue_t scheduler;
89 std::list<item_t> immediate;
90
91 static scheduler_id_t get_scheduler_id(const item_t &item) {
92 return scheduler_id_t{
93 item.params.klass,
94 client_profile_id_t{
95 item.params.owner,
96 0
97 }
98 };
99 }
100
101 public:
102 mClockScheduler(ConfigProxy &conf);
103
104 // Enqueue op in the back of the regular queue
105 void enqueue(item_t &&item) final;
106
107 // Enqueue the op in the front of the regular queue
108 void enqueue_front(item_t &&item) final;
109
110 // Return an op to be dispatch
111 item_t dequeue() final;
112
113 // Returns if the queue is empty
114 bool empty() const final {
115 return immediate.empty() && scheduler.empty();
116 }
117
118 // Formatted output of the queue
119 void dump(ceph::Formatter &f) const final;
120
121 void print(std::ostream &ostream) const final {
122 ostream << "mClockScheduler";
123 }
124
125 const char** get_tracked_conf_keys() const final;
126 void handle_conf_change(const ConfigProxy& conf,
127 const std::set<std::string> &changed) final;
128 };
129
130 }