1 | /* $Id: PDMAsyncCompletionFileInternal.h 57392 2015-08-17 14:38:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM Async I/O - Transport data asynchronous in R3 using EMT.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___PDMAsyncCompletionFileInternal_h
|
---|
19 | #define ___PDMAsyncCompletionFileInternal_h
|
---|
20 |
|
---|
21 | #include <VBox/vmm/cfgm.h>
|
---|
22 | #include <VBox/vmm/stam.h>
|
---|
23 | #include <VBox/vmm/tm.h>
|
---|
24 | #include <iprt/types.h>
|
---|
25 | #include <iprt/file.h>
|
---|
26 | #include <iprt/thread.h>
|
---|
27 | #include <iprt/semaphore.h>
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 | #include <iprt/avl.h>
|
---|
30 | #include <iprt/list.h>
|
---|
31 | #include <iprt/spinlock.h>
|
---|
32 | #include <iprt/memcache.h>
|
---|
33 |
|
---|
34 | #include "PDMAsyncCompletionInternal.h"
|
---|
35 |
|
---|
36 | /** @todo: Revise the caching of tasks. We have currently four caches:
|
---|
37 | * Per endpoint task cache
|
---|
38 | * Per class cache
|
---|
39 | * Per endpoint task segment cache
|
---|
40 | * Per class task segment cache
|
---|
41 | *
|
---|
42 | * We could use the RT heap for this probably or extend MMR3Heap (uses RTMemAlloc
|
---|
43 | * instead of managing larger blocks) to have this global for the whole VM.
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** Enable for delay injection from the debugger. */
|
---|
47 | #if 0
|
---|
48 | # define PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | RT_C_DECLS_BEGIN
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * A few forward declarations.
|
---|
55 | */
|
---|
56 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
57 | /** Pointer to a request segment. */
|
---|
58 | typedef struct PDMACTASKFILE *PPDMACTASKFILE;
|
---|
59 | /** Pointer to the endpoint class data. */
|
---|
60 | typedef struct PDMASYNCCOMPLETIONTASKFILE *PPDMASYNCCOMPLETIONTASKFILE;
|
---|
61 | /** Pointer to a cache LRU list. */
|
---|
62 | typedef struct PDMACFILELRULIST *PPDMACFILELRULIST;
|
---|
63 | /** Pointer to the global cache structure. */
|
---|
64 | typedef struct PDMACFILECACHEGLOBAL *PPDMACFILECACHEGLOBAL;
|
---|
65 | /** Pointer to a task segment. */
|
---|
66 | typedef struct PDMACFILETASKSEG *PPDMACFILETASKSEG;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Blocking event types.
|
---|
70 | */
|
---|
71 | typedef enum PDMACEPFILEAIOMGRBLOCKINGEVENT
|
---|
72 | {
|
---|
73 | /** Invalid tye */
|
---|
74 | PDMACEPFILEAIOMGRBLOCKINGEVENT_INVALID = 0,
|
---|
75 | /** An endpoint is added to the manager. */
|
---|
76 | PDMACEPFILEAIOMGRBLOCKINGEVENT_ADD_ENDPOINT,
|
---|
77 | /** An endpoint is removed from the manager. */
|
---|
78 | PDMACEPFILEAIOMGRBLOCKINGEVENT_REMOVE_ENDPOINT,
|
---|
79 | /** An endpoint is about to be closed. */
|
---|
80 | PDMACEPFILEAIOMGRBLOCKINGEVENT_CLOSE_ENDPOINT,
|
---|
81 | /** The manager is requested to terminate */
|
---|
82 | PDMACEPFILEAIOMGRBLOCKINGEVENT_SHUTDOWN,
|
---|
83 | /** The manager is requested to suspend */
|
---|
84 | PDMACEPFILEAIOMGRBLOCKINGEVENT_SUSPEND,
|
---|
85 | /** The manager is requested to resume */
|
---|
86 | PDMACEPFILEAIOMGRBLOCKINGEVENT_RESUME,
|
---|
87 | /** 32bit hack */
|
---|
88 | PDMACEPFILEAIOMGRBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
89 | } PDMACEPFILEAIOMGRBLOCKINGEVENT;
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * I/O manager type.
|
---|
93 | */
|
---|
94 | typedef enum PDMACEPFILEMGRTYPE
|
---|
95 | {
|
---|
96 | /** Simple aka failsafe */
|
---|
97 | PDMACEPFILEMGRTYPE_SIMPLE = 0,
|
---|
98 | /** Async I/O with host cache enabled. */
|
---|
99 | PDMACEPFILEMGRTYPE_ASYNC,
|
---|
100 | /** 32bit hack */
|
---|
101 | PDMACEPFILEMGRTYPE_32BIT_HACK = 0x7fffffff
|
---|
102 | } PDMACEPFILEMGRTYPE;
|
---|
103 | /** Pointer to a I/O manager type */
|
---|
104 | typedef PDMACEPFILEMGRTYPE *PPDMACEPFILEMGRTYPE;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * States of the I/O manager.
|
---|
108 | */
|
---|
109 | typedef enum PDMACEPFILEMGRSTATE
|
---|
110 | {
|
---|
111 | /** Invalid state. */
|
---|
112 | PDMACEPFILEMGRSTATE_INVALID = 0,
|
---|
113 | /** Normal running state accepting new requests
|
---|
114 | * and processing them.
|
---|
115 | */
|
---|
116 | PDMACEPFILEMGRSTATE_RUNNING,
|
---|
117 | /** Fault state - not accepting new tasks for endpoints but waiting for
|
---|
118 | * remaining ones to finish.
|
---|
119 | */
|
---|
120 | PDMACEPFILEMGRSTATE_FAULT,
|
---|
121 | /** Suspending state - not accepting new tasks for endpoints but waiting
|
---|
122 | * for remaining ones to finish.
|
---|
123 | */
|
---|
124 | PDMACEPFILEMGRSTATE_SUSPENDING,
|
---|
125 | /** Shutdown state - not accepting new tasks for endpoints but waiting
|
---|
126 | * for remaining ones to finish.
|
---|
127 | */
|
---|
128 | PDMACEPFILEMGRSTATE_SHUTDOWN,
|
---|
129 | /** The I/O manager waits for all active requests to complete and doesn't queue
|
---|
130 | * new ones because it needs to grow to handle more requests.
|
---|
131 | */
|
---|
132 | PDMACEPFILEMGRSTATE_GROWING,
|
---|
133 | /** 32bit hack */
|
---|
134 | PDMACEPFILEMGRSTATE_32BIT_HACK = 0x7fffffff
|
---|
135 | } PDMACEPFILEMGRSTATE;
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * State of a async I/O manager.
|
---|
139 | */
|
---|
140 | typedef struct PDMACEPFILEMGR
|
---|
141 | {
|
---|
142 | /** Next Aio manager in the list. */
|
---|
143 | R3PTRTYPE(struct PDMACEPFILEMGR *) pNext;
|
---|
144 | /** Previous Aio manager in the list. */
|
---|
145 | R3PTRTYPE(struct PDMACEPFILEMGR *) pPrev;
|
---|
146 | /** Manager type */
|
---|
147 | PDMACEPFILEMGRTYPE enmMgrType;
|
---|
148 | /** Current state of the manager. */
|
---|
149 | PDMACEPFILEMGRSTATE enmState;
|
---|
150 | /** Event semaphore the manager sleeps on when waiting for new requests. */
|
---|
151 | RTSEMEVENT EventSem;
|
---|
152 | /** Flag whether the thread waits in the event semaphore. */
|
---|
153 | volatile bool fWaitingEventSem;
|
---|
154 | /** Thread data */
|
---|
155 | RTTHREAD Thread;
|
---|
156 | /** The async I/O context for this manager. */
|
---|
157 | RTFILEAIOCTX hAioCtx;
|
---|
158 | /** Flag whether the I/O manager was woken up. */
|
---|
159 | volatile bool fWokenUp;
|
---|
160 | /** List of endpoints assigned to this manager. */
|
---|
161 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointsHead;
|
---|
162 | /** Number of endpoints assigned to the manager. */
|
---|
163 | unsigned cEndpoints;
|
---|
164 | /** Number of requests active currently. */
|
---|
165 | unsigned cRequestsActive;
|
---|
166 | /** Number of maximum requests active. */
|
---|
167 | uint32_t cRequestsActiveMax;
|
---|
168 | /** Pointer to an array of free async I/O request handles. */
|
---|
169 | RTFILEAIOREQ *pahReqsFree;
|
---|
170 | /** Index of the next free entry in the cache. */
|
---|
171 | uint32_t iFreeEntry;
|
---|
172 | /** Size of the array. */
|
---|
173 | unsigned cReqEntries;
|
---|
174 | /** Memory cache for file range locks. */
|
---|
175 | RTMEMCACHE hMemCacheRangeLocks;
|
---|
176 | /** Number of milliseconds to wait until the bandwidth is refreshed for at least
|
---|
177 | * one endpoint and it is possible to process more requests. */
|
---|
178 | RTMSINTERVAL msBwLimitExpired;
|
---|
179 | /** Critical section protecting the blocking event handling. */
|
---|
180 | RTCRITSECT CritSectBlockingEvent;
|
---|
181 | /** Event semaphore for blocking external events.
|
---|
182 | * The caller waits on it until the async I/O manager
|
---|
183 | * finished processing the event. */
|
---|
184 | RTSEMEVENT EventSemBlock;
|
---|
185 | /** Flag whether a blocking event is pending and needs
|
---|
186 | * processing by the I/O manager. */
|
---|
187 | volatile bool fBlockingEventPending;
|
---|
188 | /** Blocking event type */
|
---|
189 | volatile PDMACEPFILEAIOMGRBLOCKINGEVENT enmBlockingEvent;
|
---|
190 | /** Event type data */
|
---|
191 | union
|
---|
192 | {
|
---|
193 | /** Add endpoint event. */
|
---|
194 | struct
|
---|
195 | {
|
---|
196 | /** The endpoint to be added */
|
---|
197 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
198 | } AddEndpoint;
|
---|
199 | /** Remove endpoint event. */
|
---|
200 | struct
|
---|
201 | {
|
---|
202 | /** The endpoint to be removed */
|
---|
203 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
204 | } RemoveEndpoint;
|
---|
205 | /** Close endpoint event. */
|
---|
206 | struct
|
---|
207 | {
|
---|
208 | /** The endpoint to be closed */
|
---|
209 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
210 | } CloseEndpoint;
|
---|
211 | } BlockingEventData;
|
---|
212 | } PDMACEPFILEMGR;
|
---|
213 | /** Pointer to a async I/O manager state. */
|
---|
214 | typedef PDMACEPFILEMGR *PPDMACEPFILEMGR;
|
---|
215 | /** Pointer to a async I/O manager state pointer. */
|
---|
216 | typedef PPDMACEPFILEMGR *PPPDMACEPFILEMGR;
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * A file access range lock.
|
---|
220 | */
|
---|
221 | typedef struct PDMACFILERANGELOCK
|
---|
222 | {
|
---|
223 | /** AVL node in the locked range tree of the endpoint. */
|
---|
224 | AVLRFOFFNODECORE Core;
|
---|
225 | /** How many tasks have locked this range. */
|
---|
226 | uint32_t cRefs;
|
---|
227 | /** Flag whether this is a read or write lock. */
|
---|
228 | bool fReadLock;
|
---|
229 | /** List of tasks which are waiting that the range gets unlocked. */
|
---|
230 | PPDMACTASKFILE pWaitingTasksHead;
|
---|
231 | /** List of tasks which are waiting that the range gets unlocked. */
|
---|
232 | PPDMACTASKFILE pWaitingTasksTail;
|
---|
233 | } PDMACFILERANGELOCK, *PPDMACFILERANGELOCK;
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Backend type for the endpoint.
|
---|
237 | */
|
---|
238 | typedef enum PDMACFILEEPBACKEND
|
---|
239 | {
|
---|
240 | /** Non buffered. */
|
---|
241 | PDMACFILEEPBACKEND_NON_BUFFERED = 0,
|
---|
242 | /** Buffered (i.e host cache enabled) */
|
---|
243 | PDMACFILEEPBACKEND_BUFFERED,
|
---|
244 | /** 32bit hack */
|
---|
245 | PDMACFILEEPBACKEND_32BIT_HACK = 0x7fffffff
|
---|
246 | } PDMACFILEEPBACKEND;
|
---|
247 | /** Pointer to a backend type. */
|
---|
248 | typedef PDMACFILEEPBACKEND *PPDMACFILEEPBACKEND;
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Global data for the file endpoint class.
|
---|
252 | */
|
---|
253 | typedef struct PDMASYNCCOMPLETIONEPCLASSFILE
|
---|
254 | {
|
---|
255 | /** Common data. */
|
---|
256 | PDMASYNCCOMPLETIONEPCLASS Core;
|
---|
257 | /** Override I/O manager type - set to SIMPLE after failure. */
|
---|
258 | PDMACEPFILEMGRTYPE enmMgrTypeOverride;
|
---|
259 | /** Default backend type for the endpoint. */
|
---|
260 | PDMACFILEEPBACKEND enmEpBackendDefault;
|
---|
261 | RTCRITSECT CritSect;
|
---|
262 | /** Pointer to the head of the async I/O managers. */
|
---|
263 | R3PTRTYPE(PPDMACEPFILEMGR) pAioMgrHead;
|
---|
264 | /** Number of async I/O managers currently running. */
|
---|
265 | unsigned cAioMgrs;
|
---|
266 | /** Maximum number of segments to cache per endpoint */
|
---|
267 | unsigned cTasksCacheMax;
|
---|
268 | /** Maximum number of simultaneous outstandingrequests. */
|
---|
269 | uint32_t cReqsOutstandingMax;
|
---|
270 | /** Bitmask for checking the alignment of a buffer. */
|
---|
271 | RTR3UINTPTR uBitmaskAlignment;
|
---|
272 | /** Flag whether the out of resources warning was printed already. */
|
---|
273 | bool fOutOfResourcesWarningPrinted;
|
---|
274 | #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
275 | /** Timer for delayed request completion. */
|
---|
276 | PTMTIMERR3 pTimer;
|
---|
277 | /** Milliseconds until the next delay expires. */
|
---|
278 | volatile uint64_t cMilliesNext;
|
---|
279 | #endif
|
---|
280 | } PDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
281 | /** Pointer to the endpoint class data. */
|
---|
282 | typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
283 |
|
---|
284 | typedef enum PDMACEPFILEBLOCKINGEVENT
|
---|
285 | {
|
---|
286 | /** The invalid event type */
|
---|
287 | PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
|
---|
288 | /** A task is about to be canceled */
|
---|
289 | PDMACEPFILEBLOCKINGEVENT_CANCEL,
|
---|
290 | /** Usual 32bit hack */
|
---|
291 | PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
292 | } PDMACEPFILEBLOCKINGEVENT;
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * States of the endpoint.
|
---|
296 | */
|
---|
297 | typedef enum PDMASYNCCOMPLETIONENDPOINTFILESTATE
|
---|
298 | {
|
---|
299 | /** Invalid state. */
|
---|
300 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_INVALID = 0,
|
---|
301 | /** Normal running state accepting new requests
|
---|
302 | * and processing them.
|
---|
303 | */
|
---|
304 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_ACTIVE,
|
---|
305 | /** The endpoint is about to be closed - not accepting new tasks for endpoints but waiting for
|
---|
306 | * remaining ones to finish.
|
---|
307 | */
|
---|
308 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_CLOSING,
|
---|
309 | /** Removing from current I/O manager state - not processing new tasks for endpoints but waiting
|
---|
310 | * for remaining ones to finish.
|
---|
311 | */
|
---|
312 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_REMOVING,
|
---|
313 | /** The current endpoint will be migrated to another I/O manager. */
|
---|
314 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_MIGRATING,
|
---|
315 | /** 32bit hack */
|
---|
316 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_32BIT_HACK = 0x7fffffff
|
---|
317 | } PDMASYNCCOMPLETIONENDPOINTFILESTATE;
|
---|
318 |
|
---|
319 | typedef enum PDMACFILEREQTYPEDELAY
|
---|
320 | {
|
---|
321 | PDMACFILEREQTYPEDELAY_ANY = 0,
|
---|
322 | PDMACFILEREQTYPEDELAY_READ,
|
---|
323 | PDMACFILEREQTYPEDELAY_WRITE,
|
---|
324 | PDMACFILEREQTYPEDELAY_FLUSH,
|
---|
325 | PDMACFILEREQTYPEDELAY_32BIT_HACK = 0x7fffffff
|
---|
326 | } PDMACFILEREQTYPEDELAY;
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Data for the file endpoint.
|
---|
330 | */
|
---|
331 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
|
---|
332 | {
|
---|
333 | /** Common data. */
|
---|
334 | PDMASYNCCOMPLETIONENDPOINT Core;
|
---|
335 | /** Current state of the endpoint. */
|
---|
336 | PDMASYNCCOMPLETIONENDPOINTFILESTATE enmState;
|
---|
337 | /** The backend to use for this endpoint. */
|
---|
338 | PDMACFILEEPBACKEND enmBackendType;
|
---|
339 | /** async I/O manager this endpoint is assigned to. */
|
---|
340 | R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
|
---|
341 | /** Flags for opening the file. */
|
---|
342 | unsigned fFlags;
|
---|
343 | /** File handle. */
|
---|
344 | RTFILE hFile;
|
---|
345 | /** Real size of the file. Only updated if data is appended. */
|
---|
346 | volatile uint64_t cbFile;
|
---|
347 | /** List of new tasks. */
|
---|
348 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksNewHead;
|
---|
349 |
|
---|
350 | /** Head of the small cache for allocated task segments for exclusive
|
---|
351 | * use by this endpoint. */
|
---|
352 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeHead;
|
---|
353 | /** Tail of the small cache for allocated task segments for exclusive
|
---|
354 | * use by this endpoint. */
|
---|
355 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeTail;
|
---|
356 | /** Number of elements in the cache. */
|
---|
357 | volatile uint32_t cTasksCached;
|
---|
358 |
|
---|
359 | /** Flag whether a flush request is currently active */
|
---|
360 | PPDMACTASKFILE pFlushReq;
|
---|
361 |
|
---|
362 | #ifdef VBOX_WITH_STATISTICS
|
---|
363 | /** Time spend in a read. */
|
---|
364 | STAMPROFILEADV StatRead;
|
---|
365 | /** Time spend in a write. */
|
---|
366 | STAMPROFILEADV StatWrite;
|
---|
367 | #endif
|
---|
368 |
|
---|
369 | /** Event semaphore for blocking external events.
|
---|
370 | * The caller waits on it until the async I/O manager
|
---|
371 | * finished processing the event. */
|
---|
372 | RTSEMEVENT EventSemBlock;
|
---|
373 | /** Flag whether caching is enabled for this file. */
|
---|
374 | bool fCaching;
|
---|
375 | /** Flag whether the file was opened readonly. */
|
---|
376 | bool fReadonly;
|
---|
377 | /** Flag whether the host supports the async flush API. */
|
---|
378 | bool fAsyncFlushSupported;
|
---|
379 | #ifdef VBOX_WITH_DEBUGGER
|
---|
380 | /** Status code to inject for the next complete read. */
|
---|
381 | volatile int rcReqRead;
|
---|
382 | /** Status code to inject for the next complete write. */
|
---|
383 | volatile int rcReqWrite;
|
---|
384 | #endif
|
---|
385 | #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
386 | /** Request delay. */
|
---|
387 | volatile uint32_t msDelay;
|
---|
388 | /** Request delay jitter. */
|
---|
389 | volatile uint32_t msJitter;
|
---|
390 | /** Number of requests to delay. */
|
---|
391 | volatile uint32_t cReqsDelay;
|
---|
392 | /** Task type to delay. */
|
---|
393 | PDMACFILEREQTYPEDELAY enmTypeDelay;
|
---|
394 | /** The current task which gets delayed. */
|
---|
395 | PPDMASYNCCOMPLETIONTASKFILE pDelayedHead;
|
---|
396 | #endif
|
---|
397 | /** Flag whether a blocking event is pending and needs
|
---|
398 | * processing by the I/O manager. */
|
---|
399 | bool fBlockingEventPending;
|
---|
400 | /** Blocking event type */
|
---|
401 | PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
|
---|
402 |
|
---|
403 | /** Additional data needed for the event types. */
|
---|
404 | union
|
---|
405 | {
|
---|
406 | /** Cancelation event. */
|
---|
407 | struct
|
---|
408 | {
|
---|
409 | /** The task to cancel. */
|
---|
410 | PPDMACTASKFILE pTask;
|
---|
411 | } Cancel;
|
---|
412 | } BlockingEventData;
|
---|
413 | /** Data for exclusive use by the assigned async I/O manager. */
|
---|
414 | struct
|
---|
415 | {
|
---|
416 | /** Pointer to the next endpoint assigned to the manager. */
|
---|
417 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
|
---|
418 | /** Pointer to the previous endpoint assigned to the manager. */
|
---|
419 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
|
---|
420 | /** List of pending requests (not submitted due to usage restrictions
|
---|
421 | * or a pending flush request) */
|
---|
422 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingHead;
|
---|
423 | /** Tail of pending requests. */
|
---|
424 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingTail;
|
---|
425 | /** Tree of currently locked ranges.
|
---|
426 | * If a write task is enqueued the range gets locked and any other
|
---|
427 | * task writing to that range has to wait until the task completes.
|
---|
428 | */
|
---|
429 | PAVLRFOFFTREE pTreeRangesLocked;
|
---|
430 | /** Number of requests with a range lock active. */
|
---|
431 | unsigned cLockedReqsActive;
|
---|
432 | /** Number of requests currently being processed for this endpoint
|
---|
433 | * (excluded flush requests). */
|
---|
434 | unsigned cRequestsActive;
|
---|
435 | /** Number of requests processed during the last second. */
|
---|
436 | unsigned cReqsPerSec;
|
---|
437 | /** Current number of processed requests for the current update period. */
|
---|
438 | unsigned cReqsProcessed;
|
---|
439 | /** Flag whether the endpoint is about to be moved to another manager. */
|
---|
440 | bool fMoving;
|
---|
441 | /** Destination I/O manager. */
|
---|
442 | PPDMACEPFILEMGR pAioMgrDst;
|
---|
443 | } AioMgr;
|
---|
444 | } PDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
445 | /** Pointer to the endpoint class data. */
|
---|
446 | typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
447 | #ifdef VBOX_WITH_STATISTICS
|
---|
448 | AssertCompileMemberAlignment(PDMASYNCCOMPLETIONENDPOINTFILE, StatRead, sizeof(uint64_t));
|
---|
449 | #endif
|
---|
450 |
|
---|
451 | /** Request completion function */
|
---|
452 | typedef DECLCALLBACK(void) FNPDMACTASKCOMPLETED(PPDMACTASKFILE pTask, void *pvUser, int rc);
|
---|
453 | /** Pointer to a request completion function. */
|
---|
454 | typedef FNPDMACTASKCOMPLETED *PFNPDMACTASKCOMPLETED;
|
---|
455 |
|
---|
456 | /**
|
---|
457 | * Transfer type.
|
---|
458 | */
|
---|
459 | typedef enum PDMACTASKFILETRANSFER
|
---|
460 | {
|
---|
461 | /** Invalid. */
|
---|
462 | PDMACTASKFILETRANSFER_INVALID = 0,
|
---|
463 | /** Read transfer. */
|
---|
464 | PDMACTASKFILETRANSFER_READ,
|
---|
465 | /** Write transfer. */
|
---|
466 | PDMACTASKFILETRANSFER_WRITE,
|
---|
467 | /** Flush transfer. */
|
---|
468 | PDMACTASKFILETRANSFER_FLUSH
|
---|
469 | } PDMACTASKFILETRANSFER;
|
---|
470 |
|
---|
471 | /**
|
---|
472 | * Data of a request.
|
---|
473 | */
|
---|
474 | typedef struct PDMACTASKFILE
|
---|
475 | {
|
---|
476 | /** Pointer to the range lock we are waiting for */
|
---|
477 | PPDMACFILERANGELOCK pRangeLock;
|
---|
478 | /** Next task in the list. (Depending on the state) */
|
---|
479 | struct PDMACTASKFILE *pNext;
|
---|
480 | /** Endpoint */
|
---|
481 | PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
482 | /** Transfer type. */
|
---|
483 | PDMACTASKFILETRANSFER enmTransferType;
|
---|
484 | /** Start offset */
|
---|
485 | RTFOFF Off;
|
---|
486 | /** Data segment. */
|
---|
487 | RTSGSEG DataSeg;
|
---|
488 | /** When non-zero the segment uses a bounce buffer because the provided buffer
|
---|
489 | * doesn't meet host requirements. */
|
---|
490 | size_t cbBounceBuffer;
|
---|
491 | /** Pointer to the used bounce buffer if any. */
|
---|
492 | void *pvBounceBuffer;
|
---|
493 | /** Start offset in the bounce buffer to copy from. */
|
---|
494 | uint32_t offBounceBuffer;
|
---|
495 | /** Flag whether this is a prefetch request. */
|
---|
496 | bool fPrefetch;
|
---|
497 | /** Already prepared native I/O request.
|
---|
498 | * Used if the request is prepared already but
|
---|
499 | * was not queued because the host has not enough
|
---|
500 | * resources. */
|
---|
501 | RTFILEAIOREQ hReq;
|
---|
502 | /** Completion function to call on completion. */
|
---|
503 | PFNPDMACTASKCOMPLETED pfnCompleted;
|
---|
504 | /** User data */
|
---|
505 | void *pvUser;
|
---|
506 | } PDMACTASKFILE;
|
---|
507 |
|
---|
508 | /**
|
---|
509 | * Per task data.
|
---|
510 | */
|
---|
511 | typedef struct PDMASYNCCOMPLETIONTASKFILE
|
---|
512 | {
|
---|
513 | /** Common data. */
|
---|
514 | PDMASYNCCOMPLETIONTASK Core;
|
---|
515 | /** Number of bytes to transfer until this task completes. */
|
---|
516 | volatile int32_t cbTransferLeft;
|
---|
517 | /** Flag whether the task completed. */
|
---|
518 | volatile bool fCompleted;
|
---|
519 | /** Return code. */
|
---|
520 | volatile int rc;
|
---|
521 | #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
522 | volatile PPDMASYNCCOMPLETIONTASKFILE pDelayedNext;
|
---|
523 | /** Timestamp when the delay expires. */
|
---|
524 | uint64_t tsDelayEnd;
|
---|
525 | #endif
|
---|
526 | } PDMASYNCCOMPLETIONTASKFILE;
|
---|
527 |
|
---|
528 | DECLCALLBACK(int) pdmacFileAioMgrFailsafe(RTTHREAD hThreadSelf, void *pvUser);
|
---|
529 | DECLCALLBACK(int) pdmacFileAioMgrNormal(RTTHREAD hThreadSelf, void *pvUser);
|
---|
530 |
|
---|
531 | int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
|
---|
532 | void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
|
---|
533 |
|
---|
534 | int pdmacFileAioMgrCreate(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClass, PPPDMACEPFILEMGR ppAioMgr, PDMACEPFILEMGRTYPE enmMgrType);
|
---|
535 |
|
---|
536 | int pdmacFileAioMgrAddEndpoint(PPDMACEPFILEMGR pAioMgr, PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
537 |
|
---|
538 | PPDMACTASKFILE pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
539 | PPDMACTASKFILE pdmacFileTaskAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
540 | void pdmacFileTaskFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
|
---|
541 | PPDMACTASKFILE pTask);
|
---|
542 |
|
---|
543 | int pdmacFileEpAddTask(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMACTASKFILE pTask);
|
---|
544 |
|
---|
545 | int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode);
|
---|
546 | void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
547 | int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
548 | void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
549 |
|
---|
550 | int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
551 | RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
|
---|
552 | size_t cbRead);
|
---|
553 | int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
554 | RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
|
---|
555 | size_t cbWrite);
|
---|
556 | int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
557 |
|
---|
558 | RT_C_DECLS_END
|
---|
559 |
|
---|
560 | #endif
|
---|
561 |
|
---|