VirtualBox

source: vbox/trunk/src/VBox/VMM/PDMAsyncCompletionFileInternal.h@ 27563

Last change on this file since 27563 was 27563, checked in by vboxsync, 15 years ago

I/O cache: Remove a bit of code which is not used very often anymore after the commit delay was added. Reduces complexity and fixes a bug causing file corruption

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette