VirtualBox

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

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

VMM/PDMAsyncCompletion: Add basic working manager using RTFileAio API (Only tested on Linux) yet without caching. Splitted normal and failsafe manager into separate files to make the code easier to read

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
Line 
1/* $Id: PDMAsyncCompletionFileInternal.h 21496 2009-07-10 20:16:09Z 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 <iprt/types.h>
26#include <iprt/file.h>
27#include <iprt/thread.h>
28#include <iprt/semaphore.h>
29
30#include "PDMAsyncCompletionInternal.h"
31
32/** @todo: Revise the caching of tasks. We have currently four caches:
33 * Per endpoint task cache
34 * Per class cache
35 * Per endpoint task segment cache
36 * Per class task segment cache
37 *
38 * We could use the RT heap for this probably or extend MMR3Heap (uses RTMemAlloc
39 * instead of managing larger blocks) to have this global for the whole VM.
40 */
41
42RT_C_DECLS_BEGIN
43
44/**
45 * A few forward declerations.
46 */
47typedef struct PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
48/** Pointer to a request segment. */
49typedef struct PDMACTASKFILESEG *PPDMACTASKFILESEG;
50/** Pointer to the endpoint class data. */
51typedef struct PDMASYNCCOMPLETIONTASKFILE *PPDMASYNCCOMPLETIONTASKFILE;
52
53/**
54 * Blocking event types.
55 */
56typedef enum PDMACEPFILEAIOMGRBLOCKINGEVENT
57{
58 /** Invalid tye */
59 PDMACEPFILEAIOMGRBLOCKINGEVENT_INVALID = 0,
60 /** An endpoint is added to the manager. */
61 PDMACEPFILEAIOMGRBLOCKINGEVENT_ADD_ENDPOINT,
62 /** An endpoint is removed from the manager. */
63 PDMACEPFILEAIOMGRBLOCKINGEVENT_REMOVE_ENDPOINT,
64 /** An endpoint is about to be closed. */
65 PDMACEPFILEAIOMGRBLOCKINGEVENT_CLOSE_ENDPOINT,
66 /** The manager is requested to terminate */
67 PDMACEPFILEAIOMGRBLOCKINGEVENT_SHUTDOWN,
68 /** The manager is requested to suspend */
69 PDMACEPFILEAIOMGRBLOCKINGEVENT_SUSPEND,
70 /** 32bit hack */
71 PDMACEPFILEAIOMGRBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
72} PDMACEPFILEAIOMGRBLOCKINGEVENT;
73
74/**
75 * State of a async I/O manager.
76 */
77typedef struct PDMACEPFILEMGR
78{
79 /** Next Aio manager in the list. */
80 R3PTRTYPE(struct PDMACEPFILEMGR *) pNext;
81 /** Previous Aio manager in the list. */
82 R3PTRTYPE(struct PDMACEPFILEMGR *) pPrev;
83 /** Event semaphore the manager sleeps on when waiting for new requests. */
84 RTSEMEVENT EventSem;
85 /** Flag whether the thread waits in the event semaphore. */
86 volatile bool fWaitingEventSem;
87 /** Flag whether this manager uses the failsafe method. */
88 bool fFailsafe;
89 /** Thread data */
90 RTTHREAD Thread;
91 /** The async I/O context for this manager. */
92 RTFILEAIOCTX hAioCtx;
93 /** Flag whether the I/O manager is requested to terminate */
94 volatile bool fShutdown;
95 /** Flag whether the I/O manager was woken up. */
96 volatile bool fWokenUp;
97 /** List of endpoints assigned to this manager. */
98 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointsHead;
99 /** Number of requests active currently. */
100 unsigned cRequestsActive;
101 /** Critical section protecting the blocking event handling. */
102 RTCRITSECT CritSectBlockingEvent;
103 /** Event sempahore for blocking external events.
104 * The caller waits on it until the async I/O manager
105 * finished processing the event. */
106 RTSEMEVENT EventSemBlock;
107 /** Flag whether a blocking event is pending and needs
108 * processing by the I/O manager. */
109 volatile bool fBlockingEventPending;
110 /** Blocking event type */
111 volatile PDMACEPFILEAIOMGRBLOCKINGEVENT enmBlockingEvent;
112 /** Event type data */
113 union
114 {
115 /** Add endpoint event. */
116 struct
117 {
118 /** The endpoint to be added */
119 volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
120 } AddEndpoint;
121 /** Remove endpoint event. */
122 struct
123 {
124 /** The endpoint to be removed */
125 volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
126 } RemoveEndpoint;
127 /** Close endpoint event. */
128 struct
129 {
130 /** The endpoint to be closed */
131 volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
132 } CloseEndpoint;
133 } BlockingEventData;
134} PDMACEPFILEMGR;
135/** Pointer to a async I/O manager state. */
136typedef PDMACEPFILEMGR *PPDMACEPFILEMGR;
137/** Pointer to a async I/O manager state pointer. */
138typedef PPDMACEPFILEMGR *PPPDMACEPFILEMGR;
139
140/**
141 * Global data for the file endpoint class.
142 */
143typedef struct PDMASYNCCOMPLETIONEPCLASSFILE
144{
145 /** Common data. */
146 PDMASYNCCOMPLETIONEPCLASS Core;
147 /** Flag whether we use the failsafe method. */
148 bool fFailsafe;
149 /** Critical section protecting the list of async I/O managers. */
150 RTCRITSECT CritSect;
151 /** Pointer to the head of the async I/O managers. */
152 R3PTRTYPE(PPDMACEPFILEMGR) pAioMgrHead;
153 /** Number of async I/O managers currently running. */
154 unsigned cAioMgrs;
155 /** Maximum number of segments to cache per endpoint */
156 unsigned cSegmentsCacheMax;
157 /** Maximum number of simultaneous outstandingrequests. */
158 uint32_t cReqsOutstandingMax;
159 /** Bitmask for checking the alignment of a buffer. */
160 RTR3UINTPTR uBitmaskAlignment;
161} PDMASYNCCOMPLETIONEPCLASSFILE;
162/** Pointer to the endpoint class data. */
163typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
164
165typedef enum PDMACEPFILEBLOCKINGEVENT
166{
167 /** The invalid event type */
168 PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
169 /** A task is about to be canceled */
170 PDMACEPFILEBLOCKINGEVENT_CANCEL,
171 /** Usual 32bit hack */
172 PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
173} PDMACEPFILEBLOCKINGEVENT;
174
175/**
176 * Data for the file endpoint.
177 */
178typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
179{
180 /** Common data. */
181 PDMASYNCCOMPLETIONENDPOINT Core;
182 /** async I/O manager this endpoint is assigned to. */
183 R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
184 /** Filename */
185 char *pszFilename;
186 /** Flags for opening the file. */
187 unsigned fFlags;
188 /** File handle. */
189 RTFILE File;
190 /** Flag whether caching is enabled for this file. */
191 bool fCaching;
192 /** List of new tasks. */
193 R3PTRTYPE(volatile PPDMASYNCCOMPLETIONTASK) pTasksNewHead;
194
195 /** Head of the small cache for allocated task segments for exclusive
196 * use by this endpoint. */
197 R3PTRTYPE(volatile PPDMACTASKFILESEG) pSegmentsFreeHead;
198 /** Tail of the small cache for allocated task segments for exclusive
199 * use by this endpoint. */
200 R3PTRTYPE(volatile PPDMACTASKFILESEG) pSegmentsFreeTail;
201 /** Number of elements in the cache. */
202 volatile uint32_t cSegmentsCached;
203
204 /** Flag whether a flush request is currently active */
205 R3PTRTYPE(PPDMASYNCCOMPLETIONTASKFILE) pFlushReq;
206
207 /** Flag whether the endpoint is currently closed or removed from
208 * the active endpoint. */
209 bool fRemovedOrClosed;
210
211 /** Event sempahore for blocking external events.
212 * The caller waits on it until the async I/O manager
213 * finished processing the event. */
214 RTSEMEVENT EventSemBlock;
215 /** Flag whether a blocking event is pending and needs
216 * processing by the I/O manager. */
217 bool fBlockingEventPending;
218 /** Blocking event type */
219 PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
220 /** Additional data needed for the event types. */
221 union
222 {
223 /** Cancelation event. */
224 struct
225 {
226 /** The task to cancel. */
227 PPDMASYNCCOMPLETIONTASK pTask;
228 } Cancel;
229 } BlockingEventData;
230 /** Data for exclusive use by the assigned async I/O manager. */
231 struct
232 {
233 /** Pointer to the next endpoint assigned to the manager. */
234 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
235 /** Pointer to the previous endpoint assigned to the manager. */
236 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
237 /** List of pending requests (not submitted due to usage restrictions
238 * or a pending flush request) */
239 R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pReqsPendingHead;
240 /** Tail of pending requests. */
241 R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pReqsPendingTail;
242 /** Number of requests currently being processed for this endpoint
243 * (excluded flush requests). */
244 unsigned cRequestsActive;
245 } AioMgr;
246} PDMASYNCCOMPLETIONENDPOINTFILE;
247/** Pointer to the endpoint class data. */
248typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
249
250/**
251 * Segment data of a request.
252 */
253typedef struct PDMACTASKFILESEG
254{
255 /** Pointer to the next segment in the list. */
256 R3PTRTYPE(struct PDMACTASKFILESEG *) pNext;
257 /** Pointer to the previous segment in the list. */
258 R3PTRTYPE(struct PDMACTASKFILESEG *) pPrev;
259 /** Pointer to the task owning the segment. */
260 R3PTRTYPE(PPDMASYNCCOMPLETIONTASKFILE) pTask;
261 /** Data segment. */
262 PDMDATASEG DataSeg;
263 /** Flag whether this segment uses a bounce buffer
264 * because the provided buffer doesn't meet host requirements. */
265 bool fBounceBuffer;
266 /** Pointer to the used bounce buffer if any. */
267 void *pvBounceBuffer;
268 /** AIO request */
269 RTFILEAIOREQ hAioReq;
270} PDMACTASKFILESEG;
271
272/**
273 * Transfer type.
274 */
275typedef enum PDMACTASKFILETRANSFER
276{
277 /** Invalid. */
278 PDMACTASKFILETRANSFER_INVALID = 0,
279 /** Read transfer. */
280 PDMACTASKFILETRANSFER_READ,
281 /** Write transfer. */
282 PDMACTASKFILETRANSFER_WRITE,
283 /** Flush transfer. */
284 PDMACTASKFILETRANSFER_FLUSH
285} PDMACTASKFILETRANSFER;
286
287/**
288 * Per task data.
289 */
290typedef struct PDMASYNCCOMPLETIONTASKFILE
291{
292 /** Common data. */
293 PDMASYNCCOMPLETIONTASK Core;
294 /** Transfer type. */
295 PDMACTASKFILETRANSFER enmTransferType;
296 /** Type dependent data. */
297 union
298 {
299 /** Data for a data transfer */
300 struct
301 {
302 /** Start offset. */
303 RTFOFF off;
304 /** Number of bytes to transfer. */
305 size_t cbTransfer;
306 /** Number of segments which still needs to be processed before the task
307 * completes. */
308 unsigned cSegments;
309 /** Head of the request segments list for read and write requests. */
310 PPDMACTASKFILESEG pSegmentsHead;
311 } DataTransfer;
312 } u;
313} PDMASYNCCOMPLETIONTASKFILE;
314
315int pdmacFileAioMgrFailsafe(RTTHREAD ThreadSelf, void *pvUser);
316int pdmacFileAioMgrNormal(RTTHREAD ThreadSelf, void *pvUser);
317
318int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
319void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
320
321PPDMASYNCCOMPLETIONTASK pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
322PPDMACTASKFILESEG pdmacFileSegmentAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
323void pdmacFileSegmentFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
324 PPDMACTASKFILESEG pSeg);
325
326RT_C_DECLS_END
327
328#endif
329
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