VirtualBox

source: vbox/trunk/include/iprt/ioqueue.h@ 99427

Last change on this file since 99427 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.3 KB
Line 
1/** @file
2 * IPRT Generic I/O queue API.
3 */
4
5/*
6 * Copyright (C) 2019-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_ioqueue_h
37#define IPRT_INCLUDED_ioqueue_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/types.h>
43#include <iprt/sg.h>
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_rt_ioqueue IPRT generic I/O queue API
48 * @ingroup grp_rt
49 *
50 * This API models a generic I/O queue which can be attached to different providers
51 * for different types of handles.
52 *
53 * @{
54 */
55
56
57/**
58 * I/O queue request operations.
59 */
60typedef enum RTIOQUEUEOP
61{
62 /** The usual invalid option. */
63 RTIOQUEUEOP_INVALID = 0,
64 /** Read request. */
65 RTIOQUEUEOP_READ,
66 /** Write request. */
67 RTIOQUEUEOP_WRITE,
68 /** Synchronize (i.e. flush) request. */
69 RTIOQUEUEOP_SYNC,
70 /** Usual 32bit hack. */
71 RTIOQUEUEOP_32BIT_HACK = 0x7fffffff
72} RTIOQUEUEOP;
73/** Pointer to a I/O queue operation code. */
74typedef RTIOQUEUEOP *PRTIOQUEUEOP;
75
76/** I/O queue provider (processes requests put into the I/O queue) handle. */
77typedef struct RTIOQUEUEPROVINT *RTIOQUEUEPROV;
78/** I/O queue handle. */
79typedef struct RTIOQUEUEINT *RTIOQUEUE;
80/** Pointer to an I/O queue handle. */
81typedef RTIOQUEUE *PRTIOQUEUE;
82/** NIL I/O queue handle value. */
83#define NIL_RTIOQUEUE ((RTIOQUEUE)0)
84
85
86/**
87 * I/O queue completion event.
88 */
89typedef struct RTIOQUEUECEVT
90{
91 /** The user data passed when preparing the request. */
92 void *pvUser;
93 /** The IPRT status code for this request. */
94 int rcReq;
95 /** Transferred data size if applicaple by the request. */
96 size_t cbXfered;
97} RTIOQUEUECEVT;
98/** Pointer to a I/O queue completion event. */
99typedef RTIOQUEUECEVT *PRTIOQUEUECEVT;
100/** Pointer to a const I/O queue completion event. */
101typedef const RTIOQUEUECEVT *PCRTIOQUEUECEVT;
102
103
104/**
105 * I/O queue provider virtual method table.
106 */
107typedef struct RTIOQUEUEPROVVTABLE
108{
109 /** The structure version (RTIOQUEUEPROVVTABLE_VERSION). */
110 uint32_t uVersion;
111 /** Provider ID. */
112 const char *pszId;
113 /** Size of provider specific data for an I/O queue instance. */
114 size_t cbIoQueueProv;
115 /** The handle type the provider is able to process. */
116 RTHANDLETYPE enmHnd;
117 /** Additional flags for exposing supported features or quirks to the user. */
118 uint32_t fFlags;
119
120 /**
121 * Returns whether the provider is supported on the calling host system.
122 *
123 * @returns Flag whether the provider is supported.
124 */
125 DECLCALLBACKMEMBER(bool, pfnIsSupported,(void));
126
127 /**
128 * Initializes the provider specific parts of the given I/O queue.
129 *
130 * @returns IPRT status code.
131 * @param hIoQueueProv The I/O queue provider instance to initialize.
132 * @param fFlags Flags for the queue.
133 * @param cSqEntries Number of entries for the submission queue.
134 * @param cCqEntries Number of entries for the completion queue.
135 */
136 DECLCALLBACKMEMBER(int, pfnQueueInit,(RTIOQUEUEPROV hIoQueueProv, uint32_t fFlags, uint32_t cSqEntries, uint32_t cCqEntries));
137
138 /**
139 * Destroys the provider specific parts of the I/O queue and frees all
140 * associated resources.
141 *
142 * @returns nothing.
143 * @param hIoQueueProv The I/O queue provider instance to destroy.
144 */
145 DECLCALLBACKMEMBER(void, pfnQueueDestroy,(RTIOQUEUEPROV hIoQueueProv));
146
147 /**
148 * Registers the given handle for use with the I/O queue instance.
149 * The generic code already checked for the correct handle type and that the
150 * handle wasn't registered already by tracking all registered handles.
151 *
152 * @returns IPRT status code.
153 * @param hIoQueueProv The I/O queue provider instance.
154 * @param pHandle The handle to register.
155 */
156 DECLCALLBACKMEMBER(int, pfnHandleRegister,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle));
157
158 /**
159 * Deregisters the given handle for use with the I/O queue instance.
160 * The generic code already checked for the correct handle type and that the
161 * handle was registered previously.
162 *
163 * @returns IPRT status code.
164 * @param hIoQueueProv The I/O queue provider instance.
165 * @param pHandle The handle to deregister.
166 */
167 DECLCALLBACKMEMBER(int, pfnHandleDeregister,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle));
168
169 /**
170 * Prepares a request for the given I/O queue.
171 *
172 * @returns IPRT status code.
173 * @param hIoQueueProv The I/O queue provider instance.
174 * @param pHandle The handle the request is for.
175 * @param enmOp The operation to perform.
176 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
177 * @param pvBuf Buffer to use for read/write operations (sync ignores this).
178 * @param cbBuf Size of the buffer in bytes.
179 * @param fReqFlags Additional flags for the request.
180 * @param pvUser Opaque user data which is passed back in the completion event.
181 */
182 DECLCALLBACKMEMBER(int, pfnReqPrepare,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
183 uint64_t off, void *pvBuf, size_t cbBuf, uint32_t fReqFlags, void *pvUser));
184
185 /**
186 * Prepares a request for the given I/O queue.
187 *
188 * @returns IPRT status code.
189 * @param hIoQueueProv The I/O queue provider instance.
190 * @param pHandle The handle the request is for.
191 * @param enmOp The operation to perform.
192 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
193 * @param pSgBuf The S/G buufer to use for read/write operations (sync ignores this).
194 * @param cbSg Number of bytes to transfer from the S/G buffer.
195 * @param fReqFlags Additional flags for the request.
196 * @param pvUser Opaque user data which is passed back in the completion event.
197 */
198 DECLCALLBACKMEMBER(int, pfnReqPrepareSg,(RTIOQUEUEPROV hIoQueueProv, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
199 uint64_t off, PCRTSGBUF pSgBuf, size_t cbSg, uint32_t fReqFlags, void *pvUser));
200
201 /**
202 * Commits all prepared requests to the consumer for processing.
203 *
204 * @returns IPRT status code.
205 * @param hIoQueueProv The I/O queue provider instance.
206 * @param pcReqsCommitted Where to store the number of requests actually committed.
207 */
208 DECLCALLBACKMEMBER(int, pfnCommit,(RTIOQUEUEPROV hIoQueueProv, uint32_t *pcReqsCommitted));
209
210 /**
211 * Waits for completion events from the given I/O queue.
212 *
213 * @returns IPRT status code.
214 * @retval VERR_IOQUEUE_EMPTY if there is nothing to wait for.
215 * @param hIoQueueProv The I/O queue provider instance.
216 * @param paCEvt Pointer to the array of completion event entries to fill.
217 * @param cCEvt Size of the completion event entry array.
218 * @param cMinWait Minimum number of completion events to wait for before returning.
219 * @param pcCEvt Where to store the number of completion events on success.
220 * @param fFlags Additional flags controlling the wait behavior.
221 */
222 DECLCALLBACKMEMBER(int, pfnEvtWait,(RTIOQUEUEPROV hIoQueueProv, PRTIOQUEUECEVT paCEvt, uint32_t cCEvt,
223 uint32_t cMinWait, uint32_t *pcCEvt, uint32_t fFlags));
224
225 /**
226 * Wakes up the thread waiting in RTIOQUEUEPROVVTABLE::pfnEvtWait().
227 *
228 * @returns IPRT status code.
229 * @param hIoQueueProv The I/O queue provider instance.
230 */
231 DECLCALLBACKMEMBER(int, pfnEvtWaitWakeup,(RTIOQUEUEPROV hIoQueueProv));
232
233 /** Marks the end of the structure (RTIOQUEUEPROVVTABLE_VERSION). */
234 uintptr_t uEndMarker;
235} RTIOQUEUEPROVVTABLE;
236/** Pointer to an I/O queue provider vtable. */
237typedef RTIOQUEUEPROVVTABLE *PRTIOQUEUEPROVVTABLE;
238/** Pointer to a const I/O queue provider vtable. */
239typedef RTIOQUEUEPROVVTABLE const *PCRTIOQUEUEPROVVTABLE;
240
241/** The RTIOQUEUEPROVVTABLE structure version. */
242#define RTIOQUEUEPROVVTABLE_VERSION RT_MAKE_U32_FROM_U8(0xff,0xf,1,0)
243
244/** @name RTIOQUEUEPROVVTABLE::fFlags
245 * @{ */
246/** Provider supports S/G lists. */
247#define RTIOQUEUEPROVVTABLE_F_SG RT_BIT_32(0)
248/** Mask of the valid I/O stream feature flags. */
249#define RTIOQUEUEPROVVTABLE_F_VALID_MASK UINT32_C(0x00000001)
250/** @} */
251
252
253/**
254 * Tries to return the best I/O queue provider for the given handle type on the called
255 * host system.
256 *
257 * @returns Pointer to the I/O queue provider handle table or NULL if no suitable
258 * provider was found for the given handle type.
259 * @param enmHnd The handle type to look for a provider.
260 */
261RTDECL(PCRTIOQUEUEPROVVTABLE) RTIoQueueProviderGetBestForHndType(RTHANDLETYPE enmHnd);
262
263
264/**
265 * Returns the I/O queue provider with the given ID.
266 *
267 * @returns Pointer to the I/O queue provider handle table or NULL if no provider with
268 * the given ID was found.
269 * @param pszId The ID to look for.
270 */
271RTDECL(PCRTIOQUEUEPROVVTABLE) RTIoQueueProviderGetById(const char *pszId);
272
273
274/**
275 * Creates a new I/O queue with the given consumer.
276 *
277 * @returns IPRT status code.
278 * @param phIoQueue Where to store the handle to the I/O queue on success.
279 * @param pProvVTable The I/O queue provider vtable which will process the requests.
280 * @param fFlags Flags for the queue (MBZ for now).
281 * @param cSqEntries Number of entries for the submission queue.
282 * @param cCqEntries Number of entries for the completion queue.
283 *
284 * @note The number of submission and completion queue entries serve only as a hint to the
285 * provider implementation. It may decide to align the number to a smaller or greater
286 * size.
287 */
288RTDECL(int) RTIoQueueCreate(PRTIOQUEUE phIoQueue, PCRTIOQUEUEPROVVTABLE pProvVTable,
289 uint32_t fFlags, uint32_t cSqEntries, uint32_t cCqEntries);
290
291
292/**
293 * Destroys the given I/O queue.
294 *
295 * @returns IPRT status code.
296 * @retval VERR_IOQUEUE_BUSY if the I/O queue is still processing requests.
297 * @param hIoQueue The I/O queue handle to destroy.
298 */
299RTDECL(int) RTIoQueueDestroy(RTIOQUEUE hIoQueue);
300
301
302/**
303 * Registers the given handle for use with the I/O queue.
304 *
305 * @returns IPRT status code.
306 * @retval VERR_ALREADY_EXISTS if the handle was already registered.
307 * @retval VERR_NOT_SUPPORTED if the handle type is not supported by the consumer
308 * for the given I/O queue.
309 * @param hIoQueue The I/O queue handle.
310 * @param pHandle The handle to register.
311 */
312RTDECL(int) RTIoQueueHandleRegister(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle);
313
314
315/**
316 * Deregisters the given handle from the given I/O queue.
317 *
318 * @returns IPRT status code.
319 * @retval VERR_IOQUEUE_HANDLE_NOT_REGISTERED if the handle wasn't registered by a call to RTIoQueueHandleRegister().
320 * @param hIoQueue The I/O queue handle.
321 * @param pHandle The handle to deregister.
322 */
323RTDECL(int) RTIoQueueHandleDeregister(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle);
324
325
326/**
327 * Prepares a request for the given I/O queue.
328 *
329 * @returns IPRT status code.
330 * @retval VERR_IOQUEUE_FULL if the I/O queue can't accept the new request because the submission queue is full.
331 * @retval VERR_IOQUEUE_HANDLE_NOT_REGISTERED if the handle wasn't registered for use with RTIoQueueHandleRegister() yet.
332 * @param hIoQueue The I/O queue handle.
333 * @param pHandle The handle the request is for.
334 * @param enmOp The operation to perform.
335 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
336 * @param pvBuf Buffer to use for read/write operations (sync ignores this).
337 * @param cbBuf Size of the buffer in bytes.
338 * @param fReqFlags Additional flags for the request.
339 * @param pvUser Opaque user data which is passed back in the completion event.
340 */
341RTDECL(int) RTIoQueueRequestPrepare(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
342 uint64_t off, void *pvBuf, size_t cbBuf, uint32_t fReqFlags,
343 void *pvUser);
344
345
346/**
347 * Prepares a request for the given I/O queue - S/G buffer variant.
348 *
349 * @returns IPRT status code.
350 * @retval VERR_IOQUEUE_FULL if the I/O queue can't accept the new request because the submission queue is full.
351 * @retval VERR_IOQUEUE_HANDLE_NOT_REGISTERED if the handle wasn't registered for use with RTIoQueueHandleRegister() yet.
352 * @param hIoQueue The I/O queue handle.
353 * @param pHandle The handle the request is for.
354 * @param enmOp The operation to perform.
355 * @param off Start offset (if applicable, not all handles support/require it and will ignore it).
356 * @param pSgBuf The S/G buufer to use for read/write operations (sync ignores this).
357 * @param cbSg Number of bytes to transfer from the S/G buffer.
358 * @param fReqFlags Additional flags for the request.
359 * @param pvUser Opaque user data which is passed back in the completion event.
360 */
361RTDECL(int) RTIoQueueRequestPrepareSg(RTIOQUEUE hIoQueue, PCRTHANDLE pHandle, RTIOQUEUEOP enmOp,
362 uint64_t off, PCRTSGBUF pSgBuf, size_t cbSg, uint32_t fReqFlags,
363 void *pvUser);
364
365
366/**
367 * Commits all prepared requests to the consumer for processing.
368 *
369 * @returns IPRT status code.
370 * @retval VERR_IOQUEUE_EMPTY if there is nothing to commit.
371 * @param hIoQueue The I/O queue handle.
372 */
373RTDECL(int) RTIoQueueCommit(RTIOQUEUE hIoQueue);
374
375
376/**
377 * Waits for completion events from the given I/O queue.
378 *
379 * @returns IPRT status code.
380 * @retval VERR_IOQUEUE_EMPTY if there is nothing to wait for.
381 * @param hIoQueue The I/O queue handle.
382 * @param paCEvt Pointer to the array of completion event entries to fill.
383 * @param cCEvt Size of the completion event entry array.
384 * @param cMinWait Minimum number of completion events to wait for before returning.
385 * @param pcCEvt Where to store the number of completion events on success.
386 * @param fFlags Additional flags controlling the wait behavior.
387 */
388RTDECL(int) RTIoQueueEvtWait(RTIOQUEUE hIoQueue, PRTIOQUEUECEVT paCEvt, uint32_t cCEvt, uint32_t cMinWait,
389 uint32_t *pcCEvt, uint32_t fFlags);
390
391
392/**
393 * Wakes up the thread waiting in RTIoQueueEvtWait().
394 *
395 * @returns IPRT status code.
396 * @param hIoQueue The I/O queue handle to wake up.
397 */
398RTDECL(int) RTIoQueueEvtWaitWakeup(RTIOQUEUE hIoQueue);
399
400/** @} */
401
402RT_C_DECLS_END
403
404#endif /* !IPRT_INCLUDED_ioqueue_h */
405
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette