VirtualBox

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

Last change on this file since 81732 was 79983, checked in by vboxsync, 5 years ago

Runtime/RTIoQueue: Updates

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