]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/io_priority_class.hh
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / include / seastar / core / io_priority_class.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright 2021 ScyllaDB
20 */
21
22 #pragma once
23
24 #include <seastar/core/sstring.hh>
25 #include <seastar/core/future.hh>
26
27 #include <array>
28 #include <mutex>
29
30 namespace seastar {
31
32 class io_queue;
33 using io_priority_class_id = unsigned;
34 // We could very well just add the name to the io_priority_class. However, because that
35 // structure is passed along all the time - and sometimes we can't help but copy it, better keep
36 // it lean. The name won't really be used for anything other than monitoring.
37 class io_priority_class {
38 io_priority_class_id _id;
39
40 io_priority_class() = delete;
41 explicit io_priority_class(io_priority_class_id id) noexcept
42 : _id(id)
43 { }
44
45 bool rename_registered(sstring name);
46
47 public:
48 io_priority_class_id id() const noexcept {
49 return _id;
50 }
51
52 static io_priority_class register_one(sstring name, uint32_t shares);
53
54 /// \brief Updates the current amount of shares for a given priority class
55 ///
56 /// \param pc the priority class handle
57 /// \param shares the new shares value
58 /// \return a future that is ready when the share update is applied
59 future<> update_shares(uint32_t shares) const;
60
61 /// \brief Updates the current bandwidth for a given priority class
62 ///
63 /// The bandwidth applied is NOT shard-local, instead it is applied so that
64 /// all shards cannot consume more bytes-per-second altogether
65 ///
66 /// \param bandwidth the new bandwidth value in bytes/second
67 /// \return a future that is ready when the bandwidth update is applied
68 future<> update_bandwidth(uint64_t bandwidth) const;
69
70 /// Renames an io priority class
71 ///
72 /// Renames an `io_priority_class` previously created with register_one_priority_class().
73 ///
74 /// The operation is global and affects all shards.
75 /// The operation affects the exported statistics labels.
76 ///
77 /// \param pc The io priority class to be renamed
78 /// \param new_name The new name for the io priority class
79 /// \return a future that is ready when the io priority class have been renamed
80 future<> rename(sstring new_name) noexcept;
81
82 unsigned get_shares() const;
83 sstring get_name() const;
84
85 private:
86 struct class_info {
87 unsigned shares = 0;
88 sstring name;
89 bool registered() const noexcept { return shares != 0; }
90 };
91
92 static constexpr unsigned _max_classes = 2048;
93 static std::mutex _register_lock;
94 static std::array<class_info, _max_classes> _infos;
95 };
96
97 const io_priority_class& default_priority_class();
98
99 } // namespace seastar