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>
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;
41 io_priority_class() = delete;
42 explicit io_priority_class(io_priority_class_id id) noexcept
46 bool rename_registered(sstring name);
49 io_priority_class_id id() const noexcept {
53 static io_priority_class register_one(sstring name, uint32_t shares);
55 /// \brief Updates the current amount of shares for a given priority class
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;
62 /// Renames an io priority class
64 /// Renames an `io_priority_class` previously created with register_one_priority_class().
66 /// The operation is global and affects all shards.
67 /// The operation affects the exported statistics labels.
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;
74 unsigned get_shares() const;
75 sstring get_name() const;
81 bool registered() const noexcept { return shares != 0; }
84 static constexpr unsigned _max_classes = 2048;
85 static std::mutex _register_lock;
86 static std::array<class_info, _max_classes> _infos;
89 const io_priority_class& default_priority_class();
91 } // namespace seastar