VirtualBox

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

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

Storage: Convert from PDMDATASEG to RTSGSEG to avoid casting between those two in VBoxHDD and more async I/O updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.1 KB
Line 
1/* $Id: PDMAsyncCompletionFileInternal.h 28065 2010-04-07 20:54:34Z 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 /** Alignment */
406 bool afAlignment[3];
407 /** Number of times a write was deferred because the cache entry was still in progress */
408 STAMCOUNTER StatWriteDeferred;
409#endif
410} PDMACFILEENDPOINTCACHE, *PPDMACFILEENDPOINTCACHE;
411
412/**
413 * Backend type for the endpoint.
414 */
415typedef enum PDMACFILEEPBACKEND
416{
417 /** Non buffered. */
418 PDMACFILEEPBACKEND_NON_BUFFERED = 0,
419 /** Buffered (i.e host cache enabled) */
420 PDMACFILEEPBACKEND_BUFFERED,
421 /** 32bit hack */
422 PDMACFILEEPBACKEND_32BIT_HACK = 0x7fffffff
423} PDMACFILEEPBACKEND;
424/** Pointer to a backend type. */
425typedef PDMACFILEEPBACKEND *PPDMACFILEEPBACKEND;
426
427/**
428 * Global data for the file endpoint class.
429 */
430typedef struct PDMASYNCCOMPLETIONEPCLASSFILE
431{
432 /** Common data. */
433 PDMASYNCCOMPLETIONEPCLASS Core;
434 /** Override I/O manager type - set to SIMPLE after failure. */
435 PDMACEPFILEMGRTYPE enmMgrTypeOverride;
436 /** Default backend type for the endpoint. */
437 PDMACFILEEPBACKEND enmEpBackendDefault;
438 /** Flag whether the file data cache is enabled. */
439 bool fCacheEnabled;
440 /** Critical section protecting the list of async I/O managers. */
441 RTCRITSECT CritSect;
442 /** Pointer to the head of the async I/O managers. */
443 R3PTRTYPE(PPDMACEPFILEMGR) pAioMgrHead;
444 /** Number of async I/O managers currently running. */
445 unsigned cAioMgrs;
446 /** Maximum number of segments to cache per endpoint */
447 unsigned cTasksCacheMax;
448 /** Maximum number of simultaneous outstandingrequests. */
449 uint32_t cReqsOutstandingMax;
450 /** Bitmask for checking the alignment of a buffer. */
451 RTR3UINTPTR uBitmaskAlignment;
452 /** Global cache data. */
453 PDMACFILECACHEGLOBAL Cache;
454 /** Flag whether the out of resources warning was printed already. */
455 bool fOutOfResourcesWarningPrinted;
456 /** The global bandwidth control manager */
457 PPDMACFILEBWMGR pBwMgr;
458} PDMASYNCCOMPLETIONEPCLASSFILE;
459/** Pointer to the endpoint class data. */
460typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
461
462typedef enum PDMACEPFILEBLOCKINGEVENT
463{
464 /** The invalid event type */
465 PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
466 /** A task is about to be canceled */
467 PDMACEPFILEBLOCKINGEVENT_CANCEL,
468 /** Usual 32bit hack */
469 PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
470} PDMACEPFILEBLOCKINGEVENT;
471
472/**
473 * States of the endpoint.
474 */
475typedef enum PDMASYNCCOMPLETIONENDPOINTFILESTATE
476{
477 /** Invalid state. */
478 PDMASYNCCOMPLETIONENDPOINTFILESTATE_INVALID = 0,
479 /** Normal running state accepting new requests
480 * and processing them.
481 */
482 PDMASYNCCOMPLETIONENDPOINTFILESTATE_ACTIVE,
483 /** The endpoint is about to be closed - not accepting new tasks for endpoints but waiting for
484 * remaining ones to finish.
485 */
486 PDMASYNCCOMPLETIONENDPOINTFILESTATE_CLOSING,
487 /** Removing from current I/O manager state - not processing new tasks for endpoints but waiting
488 * for remaining ones to finish.
489 */
490 PDMASYNCCOMPLETIONENDPOINTFILESTATE_REMOVING,
491 /** The current endpoint will be migrated to another I/O manager. */
492 PDMASYNCCOMPLETIONENDPOINTFILESTATE_MIGRATING,
493 /** 32bit hack */
494 PDMASYNCCOMPLETIONENDPOINTFILESTATE_32BIT_HACK = 0x7fffffff
495} PDMASYNCCOMPLETIONENDPOINTFILESTATE;
496
497/**
498 * Data for the file endpoint.
499 */
500typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
501{
502 /** Common data. */
503 PDMASYNCCOMPLETIONENDPOINT Core;
504 /** Current state of the endpoint. */
505 PDMASYNCCOMPLETIONENDPOINTFILESTATE enmState;
506 /** The backend to use for this endpoint. */
507 PDMACFILEEPBACKEND enmBackendType;
508 /** async I/O manager this endpoint is assigned to. */
509 R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
510 /** Flags for opening the file. */
511 unsigned fFlags;
512 /** File handle. */
513 RTFILE File;
514 /** Size of the endpoint.
515 * Updated while data is appended even if it is
516 * only in the cache yet and not written to the file.
517 */
518 volatile uint64_t cbEndpoint;
519 /**
520 * Real size of the file. Only updated if
521 * data is appended.
522 */
523 volatile uint64_t cbFile;
524 /** List of new tasks. */
525 R3PTRTYPE(volatile PPDMACTASKFILE) pTasksNewHead;
526
527 /** Head of the small cache for allocated task segments for exclusive
528 * use by this endpoint. */
529 R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeHead;
530 /** Tail of the small cache for allocated task segments for exclusive
531 * use by this endpoint. */
532 R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeTail;
533 /** Number of elements in the cache. */
534 volatile uint32_t cTasksCached;
535
536 /** Cache of endpoint data. */
537 PDMACFILEENDPOINTCACHE DataCache;
538 /** Pointer to the associated bandwidth control manager */
539 PPDMACFILEBWMGR pBwMgr;
540
541 /** Flag whether a flush request is currently active */
542 PPDMACTASKFILE pFlushReq;
543
544#ifdef VBOX_WITH_STATISTICS
545 /** Time spend in a read. */
546 STAMPROFILEADV StatRead;
547 /** Time spend in a write. */
548 STAMPROFILEADV StatWrite;
549#endif
550
551 /** Event sempahore for blocking external events.
552 * The caller waits on it until the async I/O manager
553 * finished processing the event. */
554 RTSEMEVENT EventSemBlock;
555 /** Flag whether caching is enabled for this file. */
556 bool fCaching;
557 /** Flag whether the file was opened readonly. */
558 bool fReadonly;
559 /** Flag whether a blocking event is pending and needs
560 * processing by the I/O manager. */
561 bool fBlockingEventPending;
562 /** Blocking event type */
563 PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
564
565 /** Additional data needed for the event types. */
566 union
567 {
568 /** Cancelation event. */
569 struct
570 {
571 /** The task to cancel. */
572 PPDMACTASKFILE pTask;
573 } Cancel;
574 } BlockingEventData;
575 /** Data for exclusive use by the assigned async I/O manager. */
576 struct
577 {
578 /** Pointer to the next endpoint assigned to the manager. */
579 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
580 /** Pointer to the previous endpoint assigned to the manager. */
581 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
582 /** List of pending requests (not submitted due to usage restrictions
583 * or a pending flush request) */
584 R3PTRTYPE(PPDMACTASKFILE) pReqsPendingHead;
585 /** Tail of pending requests. */
586 R3PTRTYPE(PPDMACTASKFILE) pReqsPendingTail;
587 /** Tree of currently locked ranges.
588 * If a write task is enqueued the range gets locked and any other
589 * task writing to that range has to wait until the task completes.
590 */
591 PAVLRFOFFTREE pTreeRangesLocked;
592 /** Number of requests currently being processed for this endpoint
593 * (excluded flush requests). */
594 unsigned cRequestsActive;
595 /** Number of requests processed during the last second. */
596 unsigned cReqsPerSec;
597 /** Current number of processed requests for the current update period. */
598 unsigned cReqsProcessed;
599 /** Flag whether the endpoint is about to be moved to another manager. */
600 bool fMoving;
601 /** Destination I/O manager. */
602 PPDMACEPFILEMGR pAioMgrDst;
603 } AioMgr;
604} PDMASYNCCOMPLETIONENDPOINTFILE;
605/** Pointer to the endpoint class data. */
606typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
607
608/** Request completion function */
609typedef DECLCALLBACK(void) FNPDMACTASKCOMPLETED(PPDMACTASKFILE pTask, void *pvUser, int rc);
610/** Pointer to a request completion function. */
611typedef FNPDMACTASKCOMPLETED *PFNPDMACTASKCOMPLETED;
612
613/**
614 * Transfer type.
615 */
616typedef enum PDMACTASKFILETRANSFER
617{
618 /** Invalid. */
619 PDMACTASKFILETRANSFER_INVALID = 0,
620 /** Read transfer. */
621 PDMACTASKFILETRANSFER_READ,
622 /** Write transfer. */
623 PDMACTASKFILETRANSFER_WRITE,
624 /** Flush transfer. */
625 PDMACTASKFILETRANSFER_FLUSH
626} PDMACTASKFILETRANSFER;
627
628/**
629 * Data of a request.
630 */
631typedef struct PDMACTASKFILE
632{
633 /** Pointer to the range lock we are waiting for */
634 PPDMACFILERANGELOCK pRangeLock;
635 /** Next task in the list. (Depending on the state) */
636 struct PDMACTASKFILE *pNext;
637 /** Endpoint */
638 PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
639 /** Transfer type. */
640 PDMACTASKFILETRANSFER enmTransferType;
641 /** Start offset */
642 RTFOFF Off;
643 /** Data segment. */
644 RTSGSEG DataSeg;
645 /** Flag whether this segment uses a bounce buffer
646 * because the provided buffer doesn't meet host requirements. */
647 bool fBounceBuffer;
648 /** Pointer to the used bounce buffer if any. */
649 void *pvBounceBuffer;
650 /** Start offset in the bounce buffer to copy from. */
651 uint32_t uBounceBufOffset;
652 /** Flag whether this is a prefetch request. */
653 bool fPrefetch;
654 /** Completion function to call on completion. */
655 PFNPDMACTASKCOMPLETED pfnCompleted;
656 /** User data */
657 void *pvUser;
658} PDMACTASKFILE;
659
660/**
661 * Per task data.
662 */
663typedef struct PDMASYNCCOMPLETIONTASKFILE
664{
665 /** Common data. */
666 PDMASYNCCOMPLETIONTASK Core;
667 /** Number of bytes to transfer until this task completes. */
668 volatile int32_t cbTransferLeft;
669 /** Flag whether the task completed. */
670 volatile bool fCompleted;
671 /** Return code. */
672 volatile int rc;
673} PDMASYNCCOMPLETIONTASKFILE;
674
675int pdmacFileAioMgrFailsafe(RTTHREAD ThreadSelf, void *pvUser);
676int pdmacFileAioMgrNormal(RTTHREAD ThreadSelf, void *pvUser);
677
678int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
679void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
680
681int pdmacFileAioMgrCreate(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClass, PPPDMACEPFILEMGR ppAioMgr, PDMACEPFILEMGRTYPE enmMgrType);
682
683int pdmacFileAioMgrAddEndpoint(PPDMACEPFILEMGR pAioMgr, PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
684
685PPDMACTASKFILE pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
686PPDMACTASKFILE pdmacFileTaskAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
687void pdmacFileTaskFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
688 PPDMACTASKFILE pTask);
689
690int pdmacFileEpAddTask(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMACTASKFILE pTask);
691
692void pdmacFileEpTaskCompleted(PPDMACTASKFILE pTask, void *pvUser, int rc);
693
694bool pdmacFileBwMgrIsTransferAllowed(PPDMACFILEBWMGR pBwMgr, uint32_t cbTransfer);
695
696int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode);
697void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
698int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
699void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
700
701int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
702 RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
703 size_t cbRead);
704int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
705 RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
706 size_t cbWrite);
707int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask);
708
709RT_C_DECLS_END
710
711#endif
712
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