Condy v1.7.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
runtime_options.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
8#include <cstddef>
9#include <cstdint>
10#include <optional>
11#include <stdexcept>
12
13namespace condy {
14
15class Runtime;
16
24public:
25 using Self = RuntimeOptions;
26
33 Self &event_interval(size_t v) {
34 event_interval_ = v;
35 return *this;
36 }
37
46 [[deprecated(
47 "This option is deprecated and will be removed in future versions")]]
49 disable_register_ring_fd_ = true;
50 return *this;
51 }
52
56 Self &enable_iopoll() {
57 enable_iopoll_ = true;
58 return *this;
59 }
60
61#if !IO_URING_CHECK_VERSION(2, 9) // >= 2.9
66 if (!enable_iopoll_) {
67 throw std::logic_error(
68 "hybrid_iopoll cannot be enabled without iopoll");
69 }
70 enable_hybrid_iopoll_ = true;
71 return *this;
72 }
73#endif
74
80 Self &enable_sqpoll(size_t idle_time_ms = 1000,
81 std::optional<uint32_t> cpu = std::nullopt) {
82 if (enable_defer_taskrun_) {
83 throw std::logic_error(
84 "sqpoll cannot be enabled with defer_taskrun");
85 }
86 if (enable_coop_taskrun_) {
87 throw std::logic_error(
88 "sqpoll cannot be enabled with coop_taskrun");
89 }
90 if (enable_sq_rewind_) {
91 throw std::logic_error("sqpoll cannot be enabled with sq_rewind");
92 }
93 enable_sqpoll_ = true;
94 sqpoll_idle_time_ms_ = idle_time_ms;
95 sqpoll_thread_cpu_ = cpu;
96 return *this;
97 }
98
104 if (enable_sqpoll_) {
105 throw std::logic_error(
106 "defer_taskrun cannot be enabled with sqpoll");
107 }
108 if (enable_coop_taskrun_) {
109 throw std::logic_error(
110 "defer_taskrun cannot be enabled with coop_taskrun");
111 }
112 enable_defer_taskrun_ = true;
113 return *this;
114 }
115
120 Self &sq_size(size_t v) {
121 sq_size_ = v;
122 return *this;
123 }
124
129 Self &cq_size(size_t v) {
130 cq_size_ = v;
131 return *this;
132 }
133
137 Self &submit_batch(size_t v) {
138 submit_batch_ = v;
139 return *this;
140 }
141
148 Self &enable_attach_wq(Runtime &other) {
149 attach_wq_target_ = &other;
150 return *this;
151 }
152
158 if (enable_sqpoll_) {
159 throw std::logic_error(
160 "coop_taskrun cannot be enabled with sqpoll");
161 }
162 if (enable_defer_taskrun_) {
163 throw std::logic_error(
164 "coop_taskrun cannot be enabled with defer_taskrun");
165 }
166 enable_coop_taskrun_ = true;
167 return *this;
168 }
169
174 if (enable_sqe_mixed_) {
175 throw std::logic_error("sqe128 cannot be enabled with sqe_mixed");
176 }
177 enable_sqe128_ = true;
178 return *this;
179 }
180
184 Self &enable_cqe32() {
185 if (enable_cqe_mixed_) {
186 throw std::logic_error("cqe32 cannot be enabled with cqe_mixed");
187 }
188 enable_cqe32_ = true;
189 return *this;
190 }
191
192#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
197 if (enable_sqe128_) {
198 throw std::logic_error("sqe_mixed cannot be enabled with sqe128");
199 }
200 enable_sqe_mixed_ = true;
201 return *this;
202 }
203#endif
204
205#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
210 if (enable_cqe32_) {
211 throw std::logic_error("cqe_mixed cannot be enabled with cqe32");
212 }
213 enable_cqe_mixed_ = true;
214 return *this;
215 }
216#endif
217
218#if !IO_URING_CHECK_VERSION(2, 5) // >= 2.5
224 Self &enable_no_mmap(void *buf = nullptr, size_t buf_size = 0) {
225 enable_no_mmap_ = true;
226 no_mmap_buf_ = buf;
227 no_mmap_buf_size_ = buf_size;
228 return *this;
229 }
230#endif
231
232#if !IO_URING_CHECK_VERSION(2, 14) // >= 2.14
237 if (enable_sqpoll_) {
238 throw std::logic_error("sq_rewind cannot be enabled with sqpoll");
239 }
240 enable_sq_rewind_ = true;
241 return *this;
242 }
243#endif
244
245protected:
246 size_t event_interval_ = 61;
247 bool disable_register_ring_fd_ = false;
248 bool enable_iopoll_ = false;
249 bool enable_hybrid_iopoll_ = false;
250 bool enable_sqpoll_ = false;
251 size_t sqpoll_idle_time_ms_ = 1000;
252 std::optional<uint32_t> sqpoll_thread_cpu_ = std::nullopt;
253 bool enable_defer_taskrun_ = false;
254 size_t sq_size_ = 128;
255 size_t cq_size_ = 0; // 0 means default
256 size_t submit_batch_ = 0; // 0 means default
257 Runtime *attach_wq_target_ = nullptr;
258 bool enable_coop_taskrun_ = false;
259 bool enable_sqe128_ = false;
260 bool enable_cqe32_ = false;
261 bool enable_sqe_mixed_ = false;
262 bool enable_cqe_mixed_ = false;
263 bool enable_no_mmap_ = false;
264 void *no_mmap_buf_ = nullptr;
265 size_t no_mmap_buf_size_ = 0;
266 bool enable_sq_rewind_ = false;
267
268 friend class Runtime;
269};
270
271} // namespace condy
The event loop runtime for executing asynchronous.
Definition runtime.hpp:117
The main namespace for the Condy library.
Definition condy.hpp:31
Self & enable_sqe128()
See IORING_SETUP_SQE128.
Self & enable_attach_wq(Runtime &other)
See IORING_SETUP_ATTACH_WQ.
Self & enable_iopoll()
See IORING_SETUP_IOPOLL.
Self & sq_size(size_t v)
Set SQ size.
Self & enable_no_mmap(void *buf=nullptr, size_t buf_size=0)
See IORING_SETUP_NO_MMAP.
Self & cq_size(size_t v)
Set CQ size.
Self & enable_hybrid_iopoll()
See IORING_SETUP_HYBRID_IOPOLL.
Self & disable_register_ring_fd()
Disable register ring fd.
Self & enable_coop_taskrun()
See IORING_SETUP_COOP_TASKRUN and IORING_SETUP_TASKRUN_FLAG.
Self & enable_cqe32()
See IORING_SETUP_CQE32.
Self & event_interval(size_t v)
Set event interval.
Self & enable_cqe_mixed()
See IORING_SETUP_CQE_MIXED.
Self & enable_sqpoll(size_t idle_time_ms=1000, std::optional< uint32_t > cpu=std::nullopt)
See IORING_SETUP_SQPOLL.
Self & enable_sqe_mixed()
See IORING_SETUP_SQE_MIXED.
Self & submit_batch(size_t v)
Set batch size for operation submission.
Self & enable_defer_taskrun()
See IORING_SETUP_DEFER_TASKRUN and IORING_SETUP_TASKRUN_FLAG.
Self & enable_sq_rewind()
See IORING_SETUP_SQ_REWIND.