1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 Red Hat Inc.
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.
22 #include "boost/variant.hpp"
24 #include "dmclock/src/dmclock_server.h"
26 #include "crimson/osd/scheduler/scheduler.h"
27 #include "common/config.h"
28 #include "include/cmp.h"
29 #include "common/ceph_context.h"
32 namespace crimson::osd::scheduler
{
34 using client_id_t
= uint64_t;
35 using profile_id_t
= uint64_t;
37 struct client_profile_id_t
{
38 client_id_t client_id
;
39 profile_id_t profile_id
;
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
)
46 struct scheduler_id_t
{
47 scheduler_class_t class_id
;
48 client_profile_id_t client_profile_id
;
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
)
55 * Scheduler implementation based on mclock.
57 * TODO: explain configs
59 class mClockScheduler
: public Scheduler
, md_config_obs_t
{
61 class ClientRegistry
{
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)
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;
77 void update_from_config(const ConfigProxy
&conf
);
78 const crimson::dmclock::ClientInfo
*get_info(
79 const scheduler_id_t
&id
) const;
82 using mclock_queue_t
= crimson::dmclock::PullPriorityQueue
<
88 mclock_queue_t scheduler
;
89 std::list
<item_t
> immediate
;
91 static scheduler_id_t
get_scheduler_id(const item_t
&item
) {
92 return scheduler_id_t
{
102 mClockScheduler(ConfigProxy
&conf
);
104 // Enqueue op in the back of the regular queue
105 void enqueue(item_t
&&item
) final
;
107 // Enqueue the op in the front of the regular queue
108 void enqueue_front(item_t
&&item
) final
;
110 // Return an op to be dispatch
111 item_t
dequeue() final
;
113 // Returns if the queue is empty
114 bool empty() const final
{
115 return immediate
.empty() && scheduler
.empty();
118 // Formatted output of the queue
119 void dump(ceph::Formatter
&f
) const final
;
121 void print(std::ostream
&ostream
) const final
{
122 ostream
<< "mClockScheduler";
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
;