]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "osd_operation.h" | |
5 | #include "common/Formatter.h" | |
6 | ||
7 | namespace crimson::osd { | |
8 | ||
f67539c2 TL |
9 | OperationThrottler::OperationThrottler(ConfigProxy &conf) |
10 | : scheduler(crimson::osd::scheduler::make_scheduler(conf)) | |
11 | { | |
12 | conf.add_observer(this); | |
13 | update_from_config(conf); | |
14 | } | |
15 | ||
16 | void OperationThrottler::wake() | |
17 | { | |
18 | while ((!max_in_progress || in_progress < max_in_progress) && | |
19 | !scheduler->empty()) { | |
20 | auto item = scheduler->dequeue(); | |
21 | item.wake.set_value(); | |
22 | ++in_progress; | |
23 | --pending; | |
24 | } | |
25 | } | |
26 | ||
27 | void OperationThrottler::release_throttle() | |
28 | { | |
29 | ceph_assert(in_progress > 0); | |
30 | --in_progress; | |
31 | wake(); | |
32 | } | |
33 | ||
34 | blocking_future<> OperationThrottler::acquire_throttle( | |
35 | crimson::osd::scheduler::params_t params) | |
36 | { | |
37 | crimson::osd::scheduler::item_t item{params, seastar::promise<>()}; | |
38 | auto fut = item.wake.get_future(); | |
39 | scheduler->enqueue(std::move(item)); | |
40 | return make_blocking_future(std::move(fut)); | |
41 | } | |
42 | ||
43 | void OperationThrottler::dump_detail(Formatter *f) const | |
44 | { | |
45 | f->dump_unsigned("max_in_progress", max_in_progress); | |
46 | f->dump_unsigned("in_progress", in_progress); | |
47 | f->open_object_section("scheduler"); | |
48 | { | |
49 | scheduler->dump(*f); | |
50 | } | |
51 | f->close_section(); | |
52 | } | |
53 | ||
54 | void OperationThrottler::update_from_config(const ConfigProxy &conf) | |
55 | { | |
56 | max_in_progress = conf.get_val<uint64_t>("crimson_osd_scheduler_concurrency"); | |
57 | wake(); | |
58 | } | |
59 | ||
60 | const char** OperationThrottler::get_tracked_conf_keys() const | |
61 | { | |
62 | static const char* KEYS[] = { | |
63 | "crimson_osd_scheduler_concurrency", | |
64 | NULL | |
65 | }; | |
66 | return KEYS; | |
67 | } | |
68 | ||
69 | void OperationThrottler::handle_conf_change( | |
70 | const ConfigProxy& conf, | |
71 | const std::set<std::string> &changed) | |
72 | { | |
73 | update_from_config(conf); | |
74 | } | |
75 | ||
9f95a23c | 76 | } |