1 | /* $Id: PDMAsyncCompletionFileInternal.h 26689 2010-02-22 22:11:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM Async I/O - Transport data asynchronous in R3 using EMT.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.alldomusa.eu.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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ___PDMAsyncCompletionFileInternal_h
|
---|
23 | #define ___PDMAsyncCompletionFileInternal_h
|
---|
24 |
|
---|
25 | #include <VBox/cfgm.h>
|
---|
26 | #include <VBox/stam.h>
|
---|
27 | #include <VBox/tm.h>
|
---|
28 | #include <iprt/types.h>
|
---|
29 | #include <iprt/file.h>
|
---|
30 | #include <iprt/thread.h>
|
---|
31 | #include <iprt/semaphore.h>
|
---|
32 | #include <iprt/critsect.h>
|
---|
33 | #include <iprt/avl.h>
|
---|
34 |
|
---|
35 | #include "PDMAsyncCompletionInternal.h"
|
---|
36 |
|
---|
37 | /** @todo: Revise the caching of tasks. We have currently four caches:
|
---|
38 | * Per endpoint task cache
|
---|
39 | * Per class cache
|
---|
40 | * Per endpoint task segment cache
|
---|
41 | * Per class task segment cache
|
---|
42 | *
|
---|
43 | * We could use the RT heap for this probably or extend MMR3Heap (uses RTMemAlloc
|
---|
44 | * instead of managing larger blocks) to have this global for the whole VM.
|
---|
45 | */
|
---|
46 |
|
---|
47 | RT_C_DECLS_BEGIN
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * A few forward declerations.
|
---|
51 | */
|
---|
52 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
53 | /** Pointer to a request segment. */
|
---|
54 | typedef struct PDMACTASKFILE *PPDMACTASKFILE;
|
---|
55 | /** Pointer to the endpoint class data. */
|
---|
56 | typedef struct PDMASYNCCOMPLETIONTASKFILE *PPDMASYNCCOMPLETIONTASKFILE;
|
---|
57 | /** Pointer to a cache LRU list. */
|
---|
58 | typedef struct PDMACFILELRULIST *PPDMACFILELRULIST;
|
---|
59 | /** Pointer to the global cache structure. */
|
---|
60 | typedef struct PDMACFILECACHEGLOBAL *PPDMACFILECACHEGLOBAL;
|
---|
61 | /** Pointer to a task segment. */
|
---|
62 | typedef struct PDMACFILETASKSEG *PPDMACFILETASKSEG;
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Blocking event types.
|
---|
66 | */
|
---|
67 | typedef enum PDMACEPFILEAIOMGRBLOCKINGEVENT
|
---|
68 | {
|
---|
69 | /** Invalid tye */
|
---|
70 | PDMACEPFILEAIOMGRBLOCKINGEVENT_INVALID = 0,
|
---|
71 | /** An endpoint is added to the manager. */
|
---|
72 | PDMACEPFILEAIOMGRBLOCKINGEVENT_ADD_ENDPOINT,
|
---|
73 | /** An endpoint is removed from the manager. */
|
---|
74 | PDMACEPFILEAIOMGRBLOCKINGEVENT_REMOVE_ENDPOINT,
|
---|
75 | /** An endpoint is about to be closed. */
|
---|
76 | PDMACEPFILEAIOMGRBLOCKINGEVENT_CLOSE_ENDPOINT,
|
---|
77 | /** The manager is requested to terminate */
|
---|
78 | PDMACEPFILEAIOMGRBLOCKINGEVENT_SHUTDOWN,
|
---|
79 | /** The manager is requested to suspend */
|
---|
80 | PDMACEPFILEAIOMGRBLOCKINGEVENT_SUSPEND,
|
---|
81 | /** The manager is requested to resume */
|
---|
82 | PDMACEPFILEAIOMGRBLOCKINGEVENT_RESUME,
|
---|
83 | /** 32bit hack */
|
---|
84 | PDMACEPFILEAIOMGRBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
85 | } PDMACEPFILEAIOMGRBLOCKINGEVENT;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * States of the I/O manager.
|
---|
89 | */
|
---|
90 | typedef enum PDMACEPFILEMGRSTATE
|
---|
91 | {
|
---|
92 | /** Invalid state. */
|
---|
93 | PDMACEPFILEMGRSTATE_INVALID = 0,
|
---|
94 | /** Normal running state accepting new requests
|
---|
95 | * and processing them.
|
---|
96 | */
|
---|
97 | PDMACEPFILEMGRSTATE_RUNNING,
|
---|
98 | /** Fault state - not accepting new tasks for endpoints but waiting for
|
---|
99 | * remaining ones to finish.
|
---|
100 | */
|
---|
101 | PDMACEPFILEMGRSTATE_FAULT,
|
---|
102 | /** Suspending state - not accepting new tasks for endpoints but waiting
|
---|
103 | * for remaining ones to finish.
|
---|
104 | */
|
---|
105 | PDMACEPFILEMGRSTATE_SUSPENDING,
|
---|
106 | /** Shutdown state - not accepting new tasks for endpoints but waiting
|
---|
107 | * for remaining ones to finish.
|
---|
108 | */
|
---|
109 | PDMACEPFILEMGRSTATE_SHUTDOWN,
|
---|
110 | /** 32bit hack */
|
---|
111 | PDMACEPFILEMGRSTATE_32BIT_HACK = 0x7fffffff
|
---|
112 | } PDMACEPFILEMGRSTATE;
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * State of a async I/O manager.
|
---|
116 | */
|
---|
117 | typedef struct PDMACEPFILEMGR
|
---|
118 | {
|
---|
119 | /** Next Aio manager in the list. */
|
---|
120 | R3PTRTYPE(struct PDMACEPFILEMGR *) pNext;
|
---|
121 | /** Previous Aio manager in the list. */
|
---|
122 | R3PTRTYPE(struct PDMACEPFILEMGR *) pPrev;
|
---|
123 | /** Current state of the manager. */
|
---|
124 | PDMACEPFILEMGRSTATE enmState;
|
---|
125 | /** Event semaphore the manager sleeps on when waiting for new requests. */
|
---|
126 | RTSEMEVENT EventSem;
|
---|
127 | /** Flag whether the thread waits in the event semaphore. */
|
---|
128 | volatile bool fWaitingEventSem;
|
---|
129 | /** Flag whether this manager uses the failsafe method. */
|
---|
130 | bool fFailsafe;
|
---|
131 | /** Thread data */
|
---|
132 | RTTHREAD Thread;
|
---|
133 | /** The async I/O context for this manager. */
|
---|
134 | RTFILEAIOCTX hAioCtx;
|
---|
135 | /** Flag whether the I/O manager was woken up. */
|
---|
136 | volatile bool fWokenUp;
|
---|
137 | /** List of endpoints assigned to this manager. */
|
---|
138 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointsHead;
|
---|
139 | /** Number of endpoints assigned to the manager. */
|
---|
140 | unsigned cEndpoints;
|
---|
141 | /** Number of requests active currently. */
|
---|
142 | unsigned cRequestsActive;
|
---|
143 | /** Pointer to an array of free async I/O request handles. */
|
---|
144 | RTFILEAIOREQ *pahReqsFree;
|
---|
145 | /** Next free position for a free request handle. */
|
---|
146 | unsigned iFreeEntryNext;
|
---|
147 | /** Position of the next free task handle */
|
---|
148 | unsigned iFreeReqNext;
|
---|
149 | /** Size of the array. */
|
---|
150 | unsigned cReqEntries;
|
---|
151 | /** Flag whether at least one endpoint reached its bandwidth limit. */
|
---|
152 | bool fBwLimitReached;
|
---|
153 | /** Critical section protecting the blocking event handling. */
|
---|
154 | RTCRITSECT CritSectBlockingEvent;
|
---|
155 | /** Event sempahore for blocking external events.
|
---|
156 | * The caller waits on it until the async I/O manager
|
---|
157 | * finished processing the event. */
|
---|
158 | RTSEMEVENT EventSemBlock;
|
---|
159 | /** Flag whether a blocking event is pending and needs
|
---|
160 | * processing by the I/O manager. */
|
---|
161 | volatile bool fBlockingEventPending;
|
---|
162 | /** Blocking event type */
|
---|
163 | volatile PDMACEPFILEAIOMGRBLOCKINGEVENT enmBlockingEvent;
|
---|
164 | /** Event type data */
|
---|
165 | union
|
---|
166 | {
|
---|
167 | /** Add endpoint event. */
|
---|
168 | struct
|
---|
169 | {
|
---|
170 | /** The endpoint to be added */
|
---|
171 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
172 | } AddEndpoint;
|
---|
173 | /** Remove endpoint event. */
|
---|
174 | struct
|
---|
175 | {
|
---|
176 | /** The endpoint to be removed */
|
---|
177 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
178 | } RemoveEndpoint;
|
---|
179 | /** Close endpoint event. */
|
---|
180 | struct
|
---|
181 | {
|
---|
182 | /** The endpoint to be closed */
|
---|
183 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
184 | } CloseEndpoint;
|
---|
185 | } BlockingEventData;
|
---|
186 | } PDMACEPFILEMGR;
|
---|
187 | /** Pointer to a async I/O manager state. */
|
---|
188 | typedef PDMACEPFILEMGR *PPDMACEPFILEMGR;
|
---|
189 | /** Pointer to a async I/O manager state pointer. */
|
---|
190 | typedef PPDMACEPFILEMGR *PPPDMACEPFILEMGR;
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Bandwidth control manager instance data
|
---|
194 | */
|
---|
195 | typedef struct PDMACFILEBWMGR
|
---|
196 | {
|
---|
197 | /** Maximum number of bytes the VM is allowed to transfer (Max is 4GB/s) */
|
---|
198 | uint32_t cbVMTransferPerSecMax;
|
---|
199 | /** Number of bytes we start with */
|
---|
200 | uint32_t cbVMTransferPerSecStart;
|
---|
201 | /** Step after each update */
|
---|
202 | uint32_t cbVMTransferPerSecStep;
|
---|
203 | /** Number of bytes we are allowed to transfer till the next update.
|
---|
204 | * Resetted by the refresh timer. */
|
---|
205 | volatile uint32_t cbVMTransferAllowed;
|
---|
206 | /** Timestamp of the last update */
|
---|
207 | volatile uint64_t tsUpdatedLast;
|
---|
208 | /** Reference counter - How many endpoints are associated with this manager. */
|
---|
209 | uint32_t cRefs;
|
---|
210 | } PDMACFILEBWMGR;
|
---|
211 | /** Pointer to a bandwidth control manager */
|
---|
212 | typedef PDMACFILEBWMGR *PPDMACFILEBWMGR;
|
---|
213 | /** Pointer to a bandwidth control manager pointer */
|
---|
214 | typedef PPDMACFILEBWMGR *PPPDMACFILEBWMGR;
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * A file access range lock.
|
---|
218 | */
|
---|
219 | typedef struct PDMACFILERANGELOCK
|
---|
220 | {
|
---|
221 | /** AVL node in the locked range tree of the endpoint. */
|
---|
222 | AVLRFOFFNODECORE Core;
|
---|
223 | /** How many tasks have locked this range. */
|
---|
224 | uint32_t cRefs;
|
---|
225 | /** Flag whether this is a read or write lock. */
|
---|
226 | bool fReadLock;
|
---|
227 | /** List of tasks which are waiting that the range gets unlocked. */
|
---|
228 | PPDMACTASKFILE pWaitingTasksHead;
|
---|
229 | /** List of tasks which are waiting that the range gets unlocked. */
|
---|
230 | PPDMACTASKFILE pWaitingTasksTail;
|
---|
231 | } PDMACFILERANGELOCK, *PPDMACFILERANGELOCK;
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Data for one request segment waiting for cache entry.
|
---|
235 | */
|
---|
236 | typedef struct PDMACFILETASKSEG
|
---|
237 | {
|
---|
238 | /** Next task segment in the list. */
|
---|
239 | struct PDMACFILETASKSEG *pNext;
|
---|
240 | /** Task this segment is for. */
|
---|
241 | PPDMASYNCCOMPLETIONTASKFILE pTask;
|
---|
242 | /** Offset into the cache entry buffer to start reading from. */
|
---|
243 | uint32_t uBufOffset;
|
---|
244 | /** Number of bytes to transfer. */
|
---|
245 | size_t cbTransfer;
|
---|
246 | /** Pointer to the buffer. */
|
---|
247 | void *pvBuf;
|
---|
248 | /** Flag whether this entry writes data to the cache. */
|
---|
249 | bool fWrite;
|
---|
250 | } PDMACFILETASKSEG;
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * A cache entry
|
---|
254 | */
|
---|
255 | typedef struct PDMACFILECACHEENTRY
|
---|
256 | {
|
---|
257 | /** The AVL entry data. */
|
---|
258 | AVLRFOFFNODECORE Core;
|
---|
259 | /** Pointer to the previous element. Used in one of the LRU lists.*/
|
---|
260 | struct PDMACFILECACHEENTRY *pPrev;
|
---|
261 | /** Pointer to the next element. Used in one of the LRU lists.*/
|
---|
262 | struct PDMACFILECACHEENTRY *pNext;
|
---|
263 | /** Pointer to the list the entry is in. */
|
---|
264 | PPDMACFILELRULIST pList;
|
---|
265 | /** Pointer to the global cache structure. */
|
---|
266 | PPDMACFILECACHEGLOBAL pCache;
|
---|
267 | /** Endpoint the entry belongs to. */
|
---|
268 | PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
269 | /** Flags for this entry. Combinations of PDMACFILECACHE_* #defines */
|
---|
270 | volatile uint32_t fFlags;
|
---|
271 | /** Reference counter. Prevents eviction of the entry if > 0. */
|
---|
272 | volatile uint32_t cRefs;
|
---|
273 | /** Size of the entry. */
|
---|
274 | size_t cbData;
|
---|
275 | /** Pointer to the memory containing the data. */
|
---|
276 | uint8_t *pbData;
|
---|
277 | /** Pointer to the buffer replacing the current one
|
---|
278 | * if the deprecated flag is set. */
|
---|
279 | uint8_t *pbDataReplace;
|
---|
280 | /** Head of list of tasks waiting for this one to finish. */
|
---|
281 | PPDMACFILETASKSEG pWaitingHead;
|
---|
282 | /** Tail of list of tasks waiting for this one to finish. */
|
---|
283 | PPDMACFILETASKSEG pWaitingTail;
|
---|
284 | } PDMACFILECACHEENTRY, *PPDMACFILECACHEENTRY;
|
---|
285 | /** I/O is still in progress for this entry. This entry is not evictable. */
|
---|
286 | #define PDMACFILECACHE_ENTRY_IO_IN_PROGRESS RT_BIT(0)
|
---|
287 | /** Entry is locked and thus not evictable. */
|
---|
288 | #define PDMACFILECACHE_ENTRY_LOCKED RT_BIT(1)
|
---|
289 | /** Entry is dirty */
|
---|
290 | #define PDMACFILECACHE_ENTRY_IS_DIRTY RT_BIT(2)
|
---|
291 | /** The current buffer used for the entry is deprecated.
|
---|
292 | * The new one is available and will be replaced as soon as the file update
|
---|
293 | * completed.
|
---|
294 | */
|
---|
295 | #define PDMACFILECACHE_ENTRY_IS_DEPRECATED RT_BIT(3)
|
---|
296 | /** Entry is not evictable. */
|
---|
297 | #define PDMACFILECACHE_NOT_EVICTABLE (PDMACFILECACHE_ENTRY_LOCKED | PDMACFILECACHE_IO_IN_PROGRESS | PDMACFILECACHE_ENTRY_IS_DEPRECATED)
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * LRU list data
|
---|
301 | */
|
---|
302 | typedef struct PDMACFILELRULIST
|
---|
303 | {
|
---|
304 | /** Head of the list. */
|
---|
305 | PPDMACFILECACHEENTRY pHead;
|
---|
306 | /** Tail of the list. */
|
---|
307 | PPDMACFILECACHEENTRY pTail;
|
---|
308 | /** Number of bytes cached in the list. */
|
---|
309 | uint32_t cbCached;
|
---|
310 | } PDMACFILELRULIST;
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Global cache data.
|
---|
314 | */
|
---|
315 | typedef struct PDMACFILECACHEGLOBAL
|
---|
316 | {
|
---|
317 | /** Maximum size of the cache in bytes. */
|
---|
318 | uint32_t cbMax;
|
---|
319 | /** Current size of the cache in bytes. */
|
---|
320 | uint32_t cbCached;
|
---|
321 | /** Critical section protecting the cache. */
|
---|
322 | RTCRITSECT CritSect;
|
---|
323 | uint32_t cbRecentlyUsedInMax;
|
---|
324 | uint32_t cbRecentlyUsedOutMax;
|
---|
325 | PDMACFILELRULIST LruRecentlyUsedIn;
|
---|
326 | PDMACFILELRULIST LruRecentlyUsedOut;
|
---|
327 | PDMACFILELRULIST LruFrequentlyUsed;
|
---|
328 | #ifdef VBOX_WITH_STATISTICS
|
---|
329 | /** Hit counter. */
|
---|
330 | STAMCOUNTER cHits;
|
---|
331 | /** Partial hit counter. */
|
---|
332 | STAMCOUNTER cPartialHits;
|
---|
333 | /** Miss counter. */
|
---|
334 | STAMCOUNTER cMisses;
|
---|
335 | /** Bytes read from cache. */
|
---|
336 | STAMCOUNTER StatRead;
|
---|
337 | /** Bytes written to the cache. */
|
---|
338 | STAMCOUNTER StatWritten;
|
---|
339 | /** Time spend to get an entry in the AVL tree. */
|
---|
340 | STAMPROFILEADV StatTreeGet;
|
---|
341 | /** Time spend to insert an entry in the AVL tree. */
|
---|
342 | STAMPROFILEADV StatTreeInsert;
|
---|
343 | /** Time spend to remove an entry in the AVL tree. */
|
---|
344 | STAMPROFILEADV StatTreeRemove;
|
---|
345 | /** Number of times a buffer could be reused. */
|
---|
346 | STAMCOUNTER StatBuffersReused;
|
---|
347 | #endif
|
---|
348 | } PDMACFILECACHEGLOBAL;
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * Per endpoint cache data.
|
---|
352 | */
|
---|
353 | typedef struct PDMACFILEENDPOINTCACHE
|
---|
354 | {
|
---|
355 | /** AVL tree managing cache entries. */
|
---|
356 | PAVLRFOFFTREE pTree;
|
---|
357 | /** R/W semaphore protecting cached entries for this endpoint. */
|
---|
358 | RTSEMRW SemRWEntries;
|
---|
359 | /** Pointer to the gobal cache data */
|
---|
360 | PPDMACFILECACHEGLOBAL pCache;
|
---|
361 | /** Number of writes outstanding. */
|
---|
362 | volatile uint32_t cWritesOutstanding;
|
---|
363 | /** Handle of the flush request if one is active */
|
---|
364 | volatile PPDMASYNCCOMPLETIONTASKFILE pTaskFlush;
|
---|
365 | #ifdef VBOX_WITH_STATISTICS
|
---|
366 | /** Number of times a write was deferred because the cache entry was still in progress */
|
---|
367 | STAMCOUNTER StatWriteDeferred;
|
---|
368 | #endif
|
---|
369 | } PDMACFILEENDPOINTCACHE, *PPDMACFILEENDPOINTCACHE;
|
---|
370 |
|
---|
371 | /**
|
---|
372 | * Global data for the file endpoint class.
|
---|
373 | */
|
---|
374 | typedef struct PDMASYNCCOMPLETIONEPCLASSFILE
|
---|
375 | {
|
---|
376 | /** Common data. */
|
---|
377 | PDMASYNCCOMPLETIONEPCLASS Core;
|
---|
378 | /** Flag whether we use the failsafe method. */
|
---|
379 | bool fFailsafe;
|
---|
380 | /** Flag whether the file data cache is enabled. */
|
---|
381 | bool fCacheEnabled;
|
---|
382 | /** Flag whether the host cache should be used too. */
|
---|
383 | bool fHostCacheEnabled;
|
---|
384 | /** Critical section protecting the list of async I/O managers. */
|
---|
385 | RTCRITSECT CritSect;
|
---|
386 | /** Pointer to the head of the async I/O managers. */
|
---|
387 | R3PTRTYPE(PPDMACEPFILEMGR) pAioMgrHead;
|
---|
388 | /** Number of async I/O managers currently running. */
|
---|
389 | unsigned cAioMgrs;
|
---|
390 | /** Maximum number of segments to cache per endpoint */
|
---|
391 | unsigned cTasksCacheMax;
|
---|
392 | /** Maximum number of simultaneous outstandingrequests. */
|
---|
393 | uint32_t cReqsOutstandingMax;
|
---|
394 | /** Bitmask for checking the alignment of a buffer. */
|
---|
395 | RTR3UINTPTR uBitmaskAlignment;
|
---|
396 | /** Global cache data. */
|
---|
397 | PDMACFILECACHEGLOBAL Cache;
|
---|
398 | /** Flag whether the out of resources warning was printed already. */
|
---|
399 | bool fOutOfResourcesWarningPrinted;
|
---|
400 | /** The global bandwidth control manager */
|
---|
401 | PPDMACFILEBWMGR pBwMgr;
|
---|
402 | } PDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
403 | /** Pointer to the endpoint class data. */
|
---|
404 | typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
405 |
|
---|
406 | typedef enum PDMACEPFILEBLOCKINGEVENT
|
---|
407 | {
|
---|
408 | /** The invalid event type */
|
---|
409 | PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
|
---|
410 | /** A task is about to be canceled */
|
---|
411 | PDMACEPFILEBLOCKINGEVENT_CANCEL,
|
---|
412 | /** Usual 32bit hack */
|
---|
413 | PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
414 | } PDMACEPFILEBLOCKINGEVENT;
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * States of the endpoint.
|
---|
418 | */
|
---|
419 | typedef enum PDMASYNCCOMPLETIONENDPOINTFILESTATE
|
---|
420 | {
|
---|
421 | /** Invalid state. */
|
---|
422 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_INVALID = 0,
|
---|
423 | /** Normal running state accepting new requests
|
---|
424 | * and processing them.
|
---|
425 | */
|
---|
426 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_ACTIVE,
|
---|
427 | /** The endpoint is about to be closed - not accepting new tasks for endpoints but waiting for
|
---|
428 | * remaining ones to finish.
|
---|
429 | */
|
---|
430 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_CLOSING,
|
---|
431 | /** Removing from current I/O manager state - not processing new tasks for endpoints but waiting
|
---|
432 | * for remaining ones to finish.
|
---|
433 | */
|
---|
434 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_REMOVING,
|
---|
435 | /** The current endpoint will be migrated to another I/O manager. */
|
---|
436 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_MIGRATING,
|
---|
437 | /** 32bit hack */
|
---|
438 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_32BIT_HACK = 0x7fffffff
|
---|
439 | } PDMASYNCCOMPLETIONENDPOINTFILESTATE;
|
---|
440 |
|
---|
441 | /**
|
---|
442 | * Data for the file endpoint.
|
---|
443 | */
|
---|
444 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
|
---|
445 | {
|
---|
446 | /** Common data. */
|
---|
447 | PDMASYNCCOMPLETIONENDPOINT Core;
|
---|
448 | /** Current state of the endpoint. */
|
---|
449 | PDMASYNCCOMPLETIONENDPOINTFILESTATE enmState;
|
---|
450 | /** async I/O manager this endpoint is assigned to. */
|
---|
451 | R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
|
---|
452 | /** Flags for opening the file. */
|
---|
453 | unsigned fFlags;
|
---|
454 | /** File handle. */
|
---|
455 | RTFILE File;
|
---|
456 | /** Size of the underlying file.
|
---|
457 | * Updated while data is appended. */
|
---|
458 | volatile uint64_t cbFile;
|
---|
459 | /** Flag whether caching is enabled for this file. */
|
---|
460 | bool fCaching;
|
---|
461 | /** Flag whether the file was opened readonly. */
|
---|
462 | bool fReadonly;
|
---|
463 | /** List of new tasks. */
|
---|
464 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksNewHead;
|
---|
465 |
|
---|
466 | /** Head of the small cache for allocated task segments for exclusive
|
---|
467 | * use by this endpoint. */
|
---|
468 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeHead;
|
---|
469 | /** Tail of the small cache for allocated task segments for exclusive
|
---|
470 | * use by this endpoint. */
|
---|
471 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeTail;
|
---|
472 | /** Number of elements in the cache. */
|
---|
473 | volatile uint32_t cTasksCached;
|
---|
474 |
|
---|
475 | /** Cache of endpoint data. */
|
---|
476 | PDMACFILEENDPOINTCACHE DataCache;
|
---|
477 | /** Pointer to the associated bandwidth control manager */
|
---|
478 | PPDMACFILEBWMGR pBwMgr;
|
---|
479 |
|
---|
480 | /** Flag whether a flush request is currently active */
|
---|
481 | PPDMACTASKFILE pFlushReq;
|
---|
482 |
|
---|
483 | /** Event sempahore for blocking external events.
|
---|
484 | * The caller waits on it until the async I/O manager
|
---|
485 | * finished processing the event. */
|
---|
486 | RTSEMEVENT EventSemBlock;
|
---|
487 | /** Flag whether a blocking event is pending and needs
|
---|
488 | * processing by the I/O manager. */
|
---|
489 | bool fBlockingEventPending;
|
---|
490 | /** Blocking event type */
|
---|
491 | PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
|
---|
492 |
|
---|
493 | #ifdef VBOX_WITH_STATISTICS
|
---|
494 | /** Time spend in a read. */
|
---|
495 | STAMPROFILEADV StatRead;
|
---|
496 | /** Time spend in a write. */
|
---|
497 | STAMPROFILEADV StatWrite;
|
---|
498 | #endif
|
---|
499 |
|
---|
500 | /** Additional data needed for the event types. */
|
---|
501 | union
|
---|
502 | {
|
---|
503 | /** Cancelation event. */
|
---|
504 | struct
|
---|
505 | {
|
---|
506 | /** The task to cancel. */
|
---|
507 | PPDMACTASKFILE pTask;
|
---|
508 | } Cancel;
|
---|
509 | } BlockingEventData;
|
---|
510 | /** Data for exclusive use by the assigned async I/O manager. */
|
---|
511 | struct
|
---|
512 | {
|
---|
513 | /** Pointer to the next endpoint assigned to the manager. */
|
---|
514 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
|
---|
515 | /** Pointer to the previous endpoint assigned to the manager. */
|
---|
516 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
|
---|
517 | /** List of pending requests (not submitted due to usage restrictions
|
---|
518 | * or a pending flush request) */
|
---|
519 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingHead;
|
---|
520 | /** Tail of pending requests. */
|
---|
521 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingTail;
|
---|
522 | /** Tree of currently locked ranges.
|
---|
523 | * If a write task is enqueued the range gets locked and any other
|
---|
524 | * task writing to that range has to wait until the task completes.
|
---|
525 | */
|
---|
526 | PAVLRFOFFTREE pTreeRangesLocked;
|
---|
527 | /** Number of requests currently being processed for this endpoint
|
---|
528 | * (excluded flush requests). */
|
---|
529 | unsigned cRequestsActive;
|
---|
530 | /** Number of requests processed during the last second. */
|
---|
531 | unsigned cReqsPerSec;
|
---|
532 | /** Current number of processed requests for the current update period. */
|
---|
533 | unsigned cReqsProcessed;
|
---|
534 | /** Flag whether the endpoint is about to be moved to another manager. */
|
---|
535 | bool fMoving;
|
---|
536 | /** Destination I/O manager. */
|
---|
537 | PPDMACEPFILEMGR pAioMgrDst;
|
---|
538 | } AioMgr;
|
---|
539 | } PDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
540 | /** Pointer to the endpoint class data. */
|
---|
541 | typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
542 |
|
---|
543 | /** Request completion function */
|
---|
544 | typedef DECLCALLBACK(void) FNPDMACTASKCOMPLETED(PPDMACTASKFILE pTask, void *pvUser);
|
---|
545 | /** Pointer to a request completion function. */
|
---|
546 | typedef FNPDMACTASKCOMPLETED *PFNPDMACTASKCOMPLETED;
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * Transfer type.
|
---|
550 | */
|
---|
551 | typedef enum PDMACTASKFILETRANSFER
|
---|
552 | {
|
---|
553 | /** Invalid. */
|
---|
554 | PDMACTASKFILETRANSFER_INVALID = 0,
|
---|
555 | /** Read transfer. */
|
---|
556 | PDMACTASKFILETRANSFER_READ,
|
---|
557 | /** Write transfer. */
|
---|
558 | PDMACTASKFILETRANSFER_WRITE,
|
---|
559 | /** Flush transfer. */
|
---|
560 | PDMACTASKFILETRANSFER_FLUSH
|
---|
561 | } PDMACTASKFILETRANSFER;
|
---|
562 |
|
---|
563 | /**
|
---|
564 | * Data of a request.
|
---|
565 | */
|
---|
566 | typedef struct PDMACTASKFILE
|
---|
567 | {
|
---|
568 | /** Pointer to the range lock we are waiting for */
|
---|
569 | PPDMACFILERANGELOCK pRangeLock;
|
---|
570 | /** Next task in the list. (Depending on the state) */
|
---|
571 | struct PDMACTASKFILE *pNext;
|
---|
572 | /** Endpoint */
|
---|
573 | PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
574 | /** Transfer type. */
|
---|
575 | PDMACTASKFILETRANSFER enmTransferType;
|
---|
576 | /** Start offset */
|
---|
577 | RTFOFF Off;
|
---|
578 | /** Data segment. */
|
---|
579 | PDMDATASEG DataSeg;
|
---|
580 | /** Flag whether this segment uses a bounce buffer
|
---|
581 | * because the provided buffer doesn't meet host requirements. */
|
---|
582 | bool fBounceBuffer;
|
---|
583 | /** Pointer to the used bounce buffer if any. */
|
---|
584 | void *pvBounceBuffer;
|
---|
585 | /** Start offset in the bounce buffer to copy from. */
|
---|
586 | uint32_t uBounceBufOffset;
|
---|
587 | /** Flag whether this is a prefetch request. */
|
---|
588 | bool fPrefetch;
|
---|
589 | /** Completion function to call on completion. */
|
---|
590 | PFNPDMACTASKCOMPLETED pfnCompleted;
|
---|
591 | /** User data */
|
---|
592 | void *pvUser;
|
---|
593 | } PDMACTASKFILE;
|
---|
594 |
|
---|
595 | /**
|
---|
596 | * Per task data.
|
---|
597 | */
|
---|
598 | typedef struct PDMASYNCCOMPLETIONTASKFILE
|
---|
599 | {
|
---|
600 | /** Common data. */
|
---|
601 | PDMASYNCCOMPLETIONTASK Core;
|
---|
602 | /** Number of bytes to transfer until this task completes. */
|
---|
603 | volatile int32_t cbTransferLeft;
|
---|
604 | /** Flag whether the task completed. */
|
---|
605 | volatile bool fCompleted;
|
---|
606 | } PDMASYNCCOMPLETIONTASKFILE;
|
---|
607 |
|
---|
608 | int pdmacFileAioMgrFailsafe(RTTHREAD ThreadSelf, void *pvUser);
|
---|
609 | int pdmacFileAioMgrNormal(RTTHREAD ThreadSelf, void *pvUser);
|
---|
610 |
|
---|
611 | int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
|
---|
612 | void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
|
---|
613 |
|
---|
614 | int pdmacFileAioMgrCreate(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClass, PPPDMACEPFILEMGR ppAioMgr, bool fFailsafe);
|
---|
615 |
|
---|
616 | int pdmacFileAioMgrAddEndpoint(PPDMACEPFILEMGR pAioMgr, PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
617 |
|
---|
618 | PPDMACTASKFILE pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
619 | PPDMACTASKFILE pdmacFileTaskAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
620 | void pdmacFileTaskFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
|
---|
621 | PPDMACTASKFILE pTask);
|
---|
622 |
|
---|
623 | int pdmacFileEpAddTask(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMACTASKFILE pTask);
|
---|
624 |
|
---|
625 | void pdmacFileEpTaskCompleted(PPDMACTASKFILE pTask, void *pvUser);
|
---|
626 |
|
---|
627 | bool pdmacFileBwMgrIsTransferAllowed(PPDMACFILEBWMGR pBwMgr, uint32_t cbTransfer);
|
---|
628 |
|
---|
629 | int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode);
|
---|
630 | void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
631 | int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
632 | void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
633 |
|
---|
634 | int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
635 | RTFOFF off, PCPDMDATASEG paSegments, size_t cSegments,
|
---|
636 | size_t cbRead);
|
---|
637 | int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
638 | RTFOFF off, PCPDMDATASEG paSegments, size_t cSegments,
|
---|
639 | size_t cbWrite);
|
---|
640 | int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask);
|
---|
641 |
|
---|
642 | RT_C_DECLS_END
|
---|
643 |
|
---|
644 | #endif
|
---|
645 |
|
---|