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.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * Copyright 2021 ScyllaDB
24 #include <seastar/core/sstring.hh>
25 #include <seastar/core/future.hh>
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;
40 io_priority_class() = delete;
41 explicit io_priority_class(io_priority_class_id id) noexcept
45 bool rename_registered(sstring name);
48 io_priority_class_id id() const noexcept {
52 static io_priority_class register_one(sstring name, uint32_t shares);
54 /// \brief Updates the current amount of shares for a given priority class
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;
61 /// \brief Updates the current bandwidth for a given priority class
63 /// The bandwidth applied is NOT shard-local, instead it is applied so that
64 /// all shards cannot consume more bytes-per-second altogether
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;
70 /// Renames an io priority class
72 /// Renames an `io_priority_class` previously created with register_one_priority_class().
74 /// The operation is global and affects all shards.
75 /// The operation affects the exported statistics labels.
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;
82 unsigned get_shares() const;
83 sstring get_name() const;
89 bool registered() const noexcept { return shares != 0; }
92 static constexpr unsigned _max_classes = 2048;
93 static std::mutex _register_lock;
94 static std::array<class_info, _max_classes> _infos;
97 const io_priority_class& default_priority_class();
99 } // namespace seastar