1 | /* $Id: PDMAsyncCompletionFileInternal.h 41469 2012-05-28 22:58:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM Async I/O - Transport data asynchronous in R3 using EMT.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 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 | } PDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
275 | /** Pointer to the endpoint class data. */
|
---|
276 | typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
277 |
|
---|
278 | typedef enum PDMACEPFILEBLOCKINGEVENT
|
---|
279 | {
|
---|
280 | /** The invalid event type */
|
---|
281 | PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
|
---|
282 | /** A task is about to be canceled */
|
---|
283 | PDMACEPFILEBLOCKINGEVENT_CANCEL,
|
---|
284 | /** Usual 32bit hack */
|
---|
285 | PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
286 | } PDMACEPFILEBLOCKINGEVENT;
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * States of the endpoint.
|
---|
290 | */
|
---|
291 | typedef enum PDMASYNCCOMPLETIONENDPOINTFILESTATE
|
---|
292 | {
|
---|
293 | /** Invalid state. */
|
---|
294 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_INVALID = 0,
|
---|
295 | /** Normal running state accepting new requests
|
---|
296 | * and processing them.
|
---|
297 | */
|
---|
298 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_ACTIVE,
|
---|
299 | /** The endpoint is about to be closed - not accepting new tasks for endpoints but waiting for
|
---|
300 | * remaining ones to finish.
|
---|
301 | */
|
---|
302 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_CLOSING,
|
---|
303 | /** Removing from current I/O manager state - not processing new tasks for endpoints but waiting
|
---|
304 | * for remaining ones to finish.
|
---|
305 | */
|
---|
306 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_REMOVING,
|
---|
307 | /** The current endpoint will be migrated to another I/O manager. */
|
---|
308 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_MIGRATING,
|
---|
309 | /** 32bit hack */
|
---|
310 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_32BIT_HACK = 0x7fffffff
|
---|
311 | } PDMASYNCCOMPLETIONENDPOINTFILESTATE;
|
---|
312 |
|
---|
313 | typedef enum PDMACFILEREQTYPEDELAY
|
---|
314 | {
|
---|
315 | PDMACFILEREQTYPEDELAY_ANY = 0,
|
---|
316 | PDMACFILEREQTYPEDELAY_READ,
|
---|
317 | PDMACFILEREQTYPEDELAY_WRITE,
|
---|
318 | PDMACFILEREQTYPEDELAY_FLUSH,
|
---|
319 | PDMACFILEREQTYPEDELAY_32BIT_HACK = 0x7fffffff
|
---|
320 | } PDMACFILEREQTYPEDELAY;
|
---|
321 |
|
---|
322 | /**
|
---|
323 | * Data for the file endpoint.
|
---|
324 | */
|
---|
325 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
|
---|
326 | {
|
---|
327 | /** Common data. */
|
---|
328 | PDMASYNCCOMPLETIONENDPOINT Core;
|
---|
329 | /** Current state of the endpoint. */
|
---|
330 | PDMASYNCCOMPLETIONENDPOINTFILESTATE enmState;
|
---|
331 | /** The backend to use for this endpoint. */
|
---|
332 | PDMACFILEEPBACKEND enmBackendType;
|
---|
333 | /** async I/O manager this endpoint is assigned to. */
|
---|
334 | R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
|
---|
335 | /** Flags for opening the file. */
|
---|
336 | unsigned fFlags;
|
---|
337 | /** File handle. */
|
---|
338 | RTFILE hFile;
|
---|
339 | /** Real size of the file. Only updated if data is appended. */
|
---|
340 | volatile uint64_t cbFile;
|
---|
341 | /** List of new tasks. */
|
---|
342 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksNewHead;
|
---|
343 |
|
---|
344 | /** Head of the small cache for allocated task segments for exclusive
|
---|
345 | * use by this endpoint. */
|
---|
346 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeHead;
|
---|
347 | /** Tail of the small cache for allocated task segments for exclusive
|
---|
348 | * use by this endpoint. */
|
---|
349 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeTail;
|
---|
350 | /** Number of elements in the cache. */
|
---|
351 | volatile uint32_t cTasksCached;
|
---|
352 |
|
---|
353 | /** Flag whether a flush request is currently active */
|
---|
354 | PPDMACTASKFILE pFlushReq;
|
---|
355 |
|
---|
356 | #ifdef VBOX_WITH_STATISTICS
|
---|
357 | /** Time spend in a read. */
|
---|
358 | STAMPROFILEADV StatRead;
|
---|
359 | /** Time spend in a write. */
|
---|
360 | STAMPROFILEADV StatWrite;
|
---|
361 | #endif
|
---|
362 |
|
---|
363 | /** Event semaphore for blocking external events.
|
---|
364 | * The caller waits on it until the async I/O manager
|
---|
365 | * finished processing the event. */
|
---|
366 | RTSEMEVENT EventSemBlock;
|
---|
367 | /** Flag whether caching is enabled for this file. */
|
---|
368 | bool fCaching;
|
---|
369 | /** Flag whether the file was opened readonly. */
|
---|
370 | bool fReadonly;
|
---|
371 | /** Flag whether the host supports the async flush API. */
|
---|
372 | bool fAsyncFlushSupported;
|
---|
373 | #ifdef VBOX_WITH_DEBUGGER
|
---|
374 | /** Status code to inject for the next complete read. */
|
---|
375 | volatile int rcReqRead;
|
---|
376 | /** Status code to inject for the next complete write. */
|
---|
377 | volatile int rcReqWrite;
|
---|
378 | #endif
|
---|
379 | #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
380 | /** Request delay. */
|
---|
381 | volatile uint32_t msDelay;
|
---|
382 | /** Number of requests to delay. */
|
---|
383 | volatile uint32_t cReqsDelay;
|
---|
384 | /** Task type to delay. */
|
---|
385 | PDMACFILEREQTYPEDELAY enmTypeDelay;
|
---|
386 | /** The current task which gets delayed. */
|
---|
387 | PPDMASYNCCOMPLETIONTASKFILE pDelayedHead;
|
---|
388 | #endif
|
---|
389 | /** Flag whether a blocking event is pending and needs
|
---|
390 | * processing by the I/O manager. */
|
---|
391 | bool fBlockingEventPending;
|
---|
392 | /** Blocking event type */
|
---|
393 | PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
|
---|
394 |
|
---|
395 | /** Additional data needed for the event types. */
|
---|
396 | union
|
---|
397 | {
|
---|
398 | /** Cancelation event. */
|
---|
399 | struct
|
---|
400 | {
|
---|
401 | /** The task to cancel. */
|
---|
402 | PPDMACTASKFILE pTask;
|
---|
403 | } Cancel;
|
---|
404 | } BlockingEventData;
|
---|
405 | /** Data for exclusive use by the assigned async I/O manager. */
|
---|
406 | struct
|
---|
407 | {
|
---|
408 | /** Pointer to the next endpoint assigned to the manager. */
|
---|
409 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
|
---|
410 | /** Pointer to the previous endpoint assigned to the manager. */
|
---|
411 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
|
---|
412 | /** List of pending requests (not submitted due to usage restrictions
|
---|
413 | * or a pending flush request) */
|
---|
414 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingHead;
|
---|
415 | /** Tail of pending requests. */
|
---|
416 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingTail;
|
---|
417 | /** Tree of currently locked ranges.
|
---|
418 | * If a write task is enqueued the range gets locked and any other
|
---|
419 | * task writing to that range has to wait until the task completes.
|
---|
420 | */
|
---|
421 | PAVLRFOFFTREE pTreeRangesLocked;
|
---|
422 | /** Number of requests currently being processed for this endpoint
|
---|
423 | * (excluded flush requests). */
|
---|
424 | unsigned cRequestsActive;
|
---|
425 | /** Number of requests processed during the last second. */
|
---|
426 | unsigned cReqsPerSec;
|
---|
427 | /** Current number of processed requests for the current update period. */
|
---|
428 | unsigned cReqsProcessed;
|
---|
429 | /** Flag whether the endpoint is about to be moved to another manager. */
|
---|
430 | bool fMoving;
|
---|
431 | /** Destination I/O manager. */
|
---|
432 | PPDMACEPFILEMGR pAioMgrDst;
|
---|
433 | } AioMgr;
|
---|
434 | } PDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
435 | /** Pointer to the endpoint class data. */
|
---|
436 | typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
437 | #ifdef VBOX_WITH_STATISTICS
|
---|
438 | AssertCompileMemberAlignment(PDMASYNCCOMPLETIONENDPOINTFILE, StatRead, sizeof(uint64_t));
|
---|
439 | #endif
|
---|
440 |
|
---|
441 | /** Request completion function */
|
---|
442 | typedef DECLCALLBACK(void) FNPDMACTASKCOMPLETED(PPDMACTASKFILE pTask, void *pvUser, int rc);
|
---|
443 | /** Pointer to a request completion function. */
|
---|
444 | typedef FNPDMACTASKCOMPLETED *PFNPDMACTASKCOMPLETED;
|
---|
445 |
|
---|
446 | /**
|
---|
447 | * Transfer type.
|
---|
448 | */
|
---|
449 | typedef enum PDMACTASKFILETRANSFER
|
---|
450 | {
|
---|
451 | /** Invalid. */
|
---|
452 | PDMACTASKFILETRANSFER_INVALID = 0,
|
---|
453 | /** Read transfer. */
|
---|
454 | PDMACTASKFILETRANSFER_READ,
|
---|
455 | /** Write transfer. */
|
---|
456 | PDMACTASKFILETRANSFER_WRITE,
|
---|
457 | /** Flush transfer. */
|
---|
458 | PDMACTASKFILETRANSFER_FLUSH
|
---|
459 | } PDMACTASKFILETRANSFER;
|
---|
460 |
|
---|
461 | /**
|
---|
462 | * Data of a request.
|
---|
463 | */
|
---|
464 | typedef struct PDMACTASKFILE
|
---|
465 | {
|
---|
466 | /** Pointer to the range lock we are waiting for */
|
---|
467 | PPDMACFILERANGELOCK pRangeLock;
|
---|
468 | /** Next task in the list. (Depending on the state) */
|
---|
469 | struct PDMACTASKFILE *pNext;
|
---|
470 | /** Endpoint */
|
---|
471 | PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
472 | /** Transfer type. */
|
---|
473 | PDMACTASKFILETRANSFER enmTransferType;
|
---|
474 | /** Start offset */
|
---|
475 | RTFOFF Off;
|
---|
476 | /** Data segment. */
|
---|
477 | RTSGSEG DataSeg;
|
---|
478 | /** When non-zero the segment uses a bounce buffer because the provided buffer
|
---|
479 | * doesn't meet host requirements. */
|
---|
480 | size_t cbBounceBuffer;
|
---|
481 | /** Pointer to the used bounce buffer if any. */
|
---|
482 | void *pvBounceBuffer;
|
---|
483 | /** Start offset in the bounce buffer to copy from. */
|
---|
484 | uint32_t offBounceBuffer;
|
---|
485 | /** Flag whether this is a prefetch request. */
|
---|
486 | bool fPrefetch;
|
---|
487 | /** Already prepared native I/O request.
|
---|
488 | * Used if the request is prepared already but
|
---|
489 | * was not queued because the host has not enough
|
---|
490 | * resources. */
|
---|
491 | RTFILEAIOREQ hReq;
|
---|
492 | /** Completion function to call on completion. */
|
---|
493 | PFNPDMACTASKCOMPLETED pfnCompleted;
|
---|
494 | /** User data */
|
---|
495 | void *pvUser;
|
---|
496 | } PDMACTASKFILE;
|
---|
497 |
|
---|
498 | /**
|
---|
499 | * Per task data.
|
---|
500 | */
|
---|
501 | typedef struct PDMASYNCCOMPLETIONTASKFILE
|
---|
502 | {
|
---|
503 | /** Common data. */
|
---|
504 | PDMASYNCCOMPLETIONTASK Core;
|
---|
505 | /** Number of bytes to transfer until this task completes. */
|
---|
506 | volatile int32_t cbTransferLeft;
|
---|
507 | /** Flag whether the task completed. */
|
---|
508 | volatile bool fCompleted;
|
---|
509 | /** Return code. */
|
---|
510 | volatile int rc;
|
---|
511 | #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
512 | volatile PPDMASYNCCOMPLETIONTASKFILE pDelayedNext;
|
---|
513 | /** Timestamp when the delay expires. */
|
---|
514 | uint64_t tsDelayEnd;
|
---|
515 | #endif
|
---|
516 | } PDMASYNCCOMPLETIONTASKFILE;
|
---|
517 |
|
---|
518 | DECLCALLBACK(int) pdmacFileAioMgrFailsafe(RTTHREAD hThreadSelf, void *pvUser);
|
---|
519 | DECLCALLBACK(int) pdmacFileAioMgrNormal(RTTHREAD hThreadSelf, void *pvUser);
|
---|
520 |
|
---|
521 | int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
|
---|
522 | void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
|
---|
523 |
|
---|
524 | int pdmacFileAioMgrCreate(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClass, PPPDMACEPFILEMGR ppAioMgr, PDMACEPFILEMGRTYPE enmMgrType);
|
---|
525 |
|
---|
526 | int pdmacFileAioMgrAddEndpoint(PPDMACEPFILEMGR pAioMgr, PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
527 |
|
---|
528 | PPDMACTASKFILE pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
529 | PPDMACTASKFILE pdmacFileTaskAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
530 | void pdmacFileTaskFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
|
---|
531 | PPDMACTASKFILE pTask);
|
---|
532 |
|
---|
533 | int pdmacFileEpAddTask(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMACTASKFILE pTask);
|
---|
534 |
|
---|
535 | void pdmacFileEpTaskCompleted(PPDMACTASKFILE pTask, void *pvUser, int rc);
|
---|
536 |
|
---|
537 | int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode);
|
---|
538 | void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
539 | int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
540 | void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
541 |
|
---|
542 | int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
543 | RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
|
---|
544 | size_t cbRead);
|
---|
545 | int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
546 | RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
|
---|
547 | size_t cbWrite);
|
---|
548 | int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
549 |
|
---|
550 | RT_C_DECLS_END
|
---|
551 |
|
---|
552 | #endif
|
---|
553 |
|
---|