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