Condy v1.7.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
ring_settings.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
9#include "condy/utils.hpp"
10#include <cassert>
11#include <cerrno>
12#include <cstddef>
13#include <cstring>
14
15namespace condy {
16
22class FdTable {
23public:
24 FdTable(io_uring &ring) : ring_(ring) {}
25
26 CONDY_DELETE_COPY_MOVE(FdTable);
27
28public:
34 int init(size_t capacity) noexcept {
35 return io_uring_register_files_sparse(&ring_, capacity);
36 }
37
45 int init(const int *fds, unsigned nr_fds) {
46 return io_uring_register_files(&ring_, fds, nr_fds);
47 }
48
53 int destroy() noexcept { return io_uring_unregister_files(&ring_); }
54
63 int update(unsigned index_base, const int *fds, unsigned nr_fds) noexcept {
64 return io_uring_register_files_update(&ring_, index_base, fds, nr_fds);
65 }
66
73 int set_file_alloc_range(unsigned offset, unsigned size) noexcept {
74 return io_uring_register_file_alloc_range(&ring_, offset, size);
75 }
76
77private:
78 io_uring &ring_;
79};
80
86class BufferTable {
87public:
88 BufferTable(io_uring &ring) : ring_(ring) {}
89
90 CONDY_DELETE_COPY_MOVE(BufferTable);
91
92public:
98 int init(size_t capacity) noexcept {
99 return io_uring_register_buffers_sparse(&ring_, capacity);
100 }
101
109 int init(const iovec *vecs, unsigned nr_vecs) {
110 return io_uring_register_buffers(&ring_, vecs, nr_vecs);
111 }
112
117 int destroy() noexcept { return io_uring_unregister_buffers(&ring_); }
118
127 int update(unsigned index_base, const iovec *vecs,
128 unsigned nr_vecs) noexcept {
129 return io_uring_register_buffers_update_tag(&ring_, index_base, vecs,
130 nullptr, nr_vecs);
131 }
132
133#if !IO_URING_CHECK_VERSION(2, 10) // >= 2.10
134
143 int clone_buffers(BufferTable &src, unsigned int dst_off = 0,
144 unsigned int src_off = 0, unsigned int nr = 0) noexcept {
145 auto *src_ring = &src.ring_;
146 auto *dst_ring = &ring_;
147 return __io_uring_clone_buffers_offset(dst_ring, src_ring, dst_off,
148 src_off, nr,
149 IORING_REGISTER_DST_REPLACE);
150 }
151#endif
152
153private:
154 io_uring &ring_;
155};
156
162class RingSettings {
163public:
164 RingSettings(io_uring &ring) : ring_(ring) {}
165
166 ~RingSettings() {
167 if (probe_) {
168 io_uring_free_probe(probe_);
169 probe_ = nullptr;
170 }
171 }
172
173 CONDY_DELETE_COPY_MOVE(RingSettings);
174
175public:
182 int apply_iowq_aff(size_t cpusz, const cpu_set_t *mask) noexcept {
183 return io_uring_register_iowq_aff(&ring_, cpusz, mask);
184 }
185
189 int remove_iowq_aff() noexcept {
190 return io_uring_unregister_iowq_aff(&ring_);
191 }
192
199 int set_iowq_max_workers(unsigned int *values) noexcept {
200 return io_uring_register_iowq_max_workers(&ring_, values);
201 }
202
208 io_uring_probe *get_probe() noexcept {
209 if (probe_) {
210 return probe_;
211 }
212 probe_ = io_uring_get_probe_ring(&ring_);
213 return probe_;
214 }
215
220 uint32_t get_features() const noexcept { return ring_.features; }
221
222#if !IO_URING_CHECK_VERSION(2, 6) // >= 2.6
228 int apply_napi(io_uring_napi *napi) noexcept {
229 return io_uring_register_napi(&ring_, napi);
230 }
231
235 int remove_napi(io_uring_napi *napi = nullptr) noexcept {
236 return io_uring_unregister_napi(&ring_, napi);
237 }
238#endif
239
240#if !IO_URING_CHECK_VERSION(2, 8) // >= 2.8
246 int set_clock(io_uring_clock_register *clock_reg) noexcept {
247 return io_uring_register_clock(&ring_, clock_reg);
248 }
249#endif
250
251#if !IO_URING_CHECK_VERSION(2, 9) // >= 2.9
257 int set_rings_size(io_uring_params *params) noexcept {
258 return io_uring_resize_rings(&ring_, params);
259 }
260#endif
261
262#if !IO_URING_CHECK_VERSION(2, 10) // >= 2.10
268 int set_iowait(bool enable_iowait) noexcept {
269 return io_uring_set_iowait(&ring_, enable_iowait);
270 }
271#endif
272
273private:
274 io_uring &ring_;
275 io_uring_probe *probe_ = nullptr;
276};
277
278} // namespace condy
int clone_buffers(BufferTable &src, unsigned int dst_off=0, unsigned int src_off=0, unsigned int nr=0) noexcept
Clone buffers from another BufferTable into this one.
int update(unsigned index_base, const iovec *vecs, unsigned nr_vecs) noexcept
Update the buffer table starting from the given index.
int init(size_t capacity) noexcept
Initialize the buffer table with the given capacity.
int destroy() noexcept
Destroy the buffer table.
int init(const iovec *vecs, unsigned nr_vecs)
Initialize the buffer table with the given array of iovec structures.
int init(size_t capacity) noexcept
Initialize the file descriptor table with the given capacity.
int destroy() noexcept
Destroy the file descriptor table.
int init(const int *fds, unsigned nr_fds)
Initialize the file descriptor table with the given array of file descriptors.
int set_file_alloc_range(unsigned offset, unsigned size) noexcept
Set the file allocation range for the fd table.
int update(unsigned index_base, const int *fds, unsigned nr_fds) noexcept
Update the file descriptor table starting from the given index.
int set_rings_size(io_uring_params *params) noexcept
Resize the rings of the io_uring instance.
int apply_napi(io_uring_napi *napi) noexcept
Apply NAPI settings to the io_uring instance.
io_uring_probe * get_probe() noexcept
Get the io_uring probe for the ring.
uint32_t get_features() const noexcept
Get the supported features of the ring.
int set_iowq_max_workers(unsigned int *values) noexcept
Set the maximum number of I/O workers.
int apply_iowq_aff(size_t cpusz, const cpu_set_t *mask) noexcept
Apply I/O worker queue affinity settings.
int remove_iowq_aff() noexcept
Remove I/O worker queue affinity settings.
int set_clock(io_uring_clock_register *clock_reg) noexcept
Set the clock registration for the io_uring instance.
int set_iowait(bool enable_iowait) noexcept
Enable or disable iowait for the io_uring instance.
int remove_napi(io_uring_napi *napi=nullptr) noexcept
Remove NAPI settings from the io_uring instance.
The main namespace for the Condy library.
Definition condy.hpp:31
Internal utility classes and functions used by Condy.