VirtualBox

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

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

AsyncCompletion: Don't immediately commit dirty buffers to the endpoint to reduce the I/O load on the host and the I/O performance in the guest for often updated cache entries

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

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