]> git.proxmox.com Git - ceph.git/blob - ceph/src/osd/scheduler/OpScheduler.cc
b0d14b496b5dd367e4ed517ba87f233bc2bc5453
[ceph.git] / ceph / src / osd / scheduler / OpScheduler.cc
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) 2019 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 #include <ostream>
16
17 #include "osd/scheduler/OpScheduler.h"
18
19 #include "common/WeightedPriorityQueue.h"
20 #include "osd/scheduler/mClockScheduler.h"
21
22 namespace ceph::osd::scheduler {
23
24 OpSchedulerRef make_scheduler(
25 CephContext *cct, uint32_t num_shards,
26 bool is_rotational, std::string_view osd_objectstore)
27 {
28 const std::string *type = &cct->_conf->osd_op_queue;
29 if (*type == "debug_random") {
30 static const std::string index_lookup[] = { "mclock_scheduler",
31 "wpq" };
32 srand(time(NULL));
33 unsigned which = rand() % (sizeof(index_lookup) / sizeof(index_lookup[0]));
34 type = &index_lookup[which];
35 }
36
37 // Force the use of 'wpq' scheduler for filestore OSDs.
38 // The 'mclock_scheduler' is not supported for filestore OSDs.
39 if (*type == "wpq" || osd_objectstore == "filestore") {
40 return std::make_unique<
41 ClassedOpQueueScheduler<WeightedPriorityQueue<OpSchedulerItem, client>>>(
42 cct,
43 cct->_conf->osd_op_pq_max_tokens_per_priority,
44 cct->_conf->osd_op_pq_min_cost
45 );
46 } else if (*type == "mclock_scheduler") {
47 // default is 'mclock_scheduler'
48 return std::make_unique<mClockScheduler>(cct, num_shards, is_rotational);
49 } else {
50 ceph_assert("Invalid choice of wq" == 0);
51 }
52 }
53
54 std::ostream &operator<<(std::ostream &lhs, const OpScheduler &rhs) {
55 rhs.print(lhs);
56 return lhs;
57 }
58
59 }