Seastar
High performance C++ framework for concurrent servers
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 #ifndef SEASTAR_MODULE
25 #include <seastar/core/sstring.hh>
26 #include <seastar/core/future.hh>
27 #include <seastar/util/modules.hh>
28 
29 #include <array>
30 #include <mutex>
31 #endif
32 
33 namespace seastar {
34 
35 class io_queue;
36 
37 SEASTAR_MODULE_EXPORT_BEGIN
38 
39 using io_priority_class_id = unsigned;
40 
41 #if SEASTAR_API_LEVEL < 7
42 // We could very well just add the name to the io_priority_class. However, because that
43 // structure is passed along all the time - and sometimes we can't help but copy it, better keep
44 // it lean. The name won't really be used for anything other than monitoring.
45 class io_priority_class {
46  io_priority_class_id _id;
47 
48  io_priority_class() = delete;
49  explicit io_priority_class(io_priority_class_id id) noexcept
50  : _id(id)
51  { }
52 
53  bool rename_registered(sstring name);
54 
55 public:
56  io_priority_class_id id() const noexcept {
57  return _id;
58  }
59 
60  [[deprecated("Use scheduling_groups and API level >= 7")]]
61  static io_priority_class register_one(sstring name, uint32_t shares);
62 
68  future<> update_shares(uint32_t shares) const;
69 
77  future<> update_bandwidth(uint64_t bandwidth) const;
78 
89  future<> rename(sstring new_name) noexcept;
90 
91  unsigned get_shares() const;
92  sstring get_name() const;
93 
94 private:
95  struct class_info {
96  unsigned shares = 0;
97  sstring name;
98  bool registered() const noexcept { return shares != 0; }
99  };
100 
101  static constexpr unsigned _max_classes = 2048;
102  static std::mutex _register_lock;
103  static std::array<class_info, _max_classes> _infos;
104 
105  friend std::tuple<unsigned, sstring> get_class_info(io_priority_class_id pc);
106 };
107 
108 const io_priority_class& default_priority_class();
109 
110 #endif
111 
112 SEASTAR_MODULE_EXPORT_END
113 
114 namespace internal {
115 #if SEASTAR_API_LEVEL >= 7
116 struct maybe_priority_class_ref {
117 };
118 #else
119 struct maybe_priority_class_ref {
120  const io_priority_class& pc;
121  explicit maybe_priority_class_ref(const io_priority_class& p) noexcept : pc(p) {}
122  maybe_priority_class_ref() noexcept : pc(default_priority_class()) {}
123 };
124 #endif
125 }
126 
127 } // namespace seastar
Seastar API namespace.
Definition: abort_on_ebadf.hh:26