]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/io_priority_class.hh
import quincy beta 17.1.0
[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 /// \cond internal
33 class io_queue;
34 using io_priority_class_id = unsigned;
35 // We could very well just add the name to the io_priority_class. However, because that
36 // structure is passed along all the time - and sometimes we can't help but copy it, better keep
37 // it lean. The name won't really be used for anything other than monitoring.
38 class io_priority_class {
39 io_priority_class_id _id;
40
41 io_priority_class() = delete;
42 explicit io_priority_class(io_priority_class_id id) noexcept
43 : _id(id)
44 { }
45
46 bool rename_registered(sstring name);
47
48 public:
49 io_priority_class_id id() const noexcept {
50 return _id;
51 }
52
53 static io_priority_class register_one(sstring name, uint32_t shares);
54
55 /// \brief Updates the current amount of shares for a given priority class
56 ///
57 /// \param pc the priority class handle
58 /// \param shares the new shares value
59 /// \return a future that is ready when the share update is applied
60 future<> update_shares(uint32_t shares) const;
61
62 /// Renames an io priority class
63 ///
64 /// Renames an `io_priority_class` previously created with register_one_priority_class().
65 ///
66 /// The operation is global and affects all shards.
67 /// The operation affects the exported statistics labels.
68 ///
69 /// \param pc The io priority class to be renamed
70 /// \param new_name The new name for the io priority class
71 /// \return a future that is ready when the io priority class have been renamed
72 future<> rename(sstring new_name) noexcept;
73
74 unsigned get_shares() const;
75 sstring get_name() const;
76
77 private:
78 struct class_info {
79 unsigned shares = 0;
80 sstring name;
81 bool registered() const noexcept { return shares != 0; }
82 };
83
84 static constexpr unsigned _max_classes = 2048;
85 static std::mutex _register_lock;
86 static std::array<class_info, _max_classes> _infos;
87 };
88
89 const io_priority_class& default_priority_class();
90
91 } // namespace seastar