VirtualBox

source: vbox/trunk/src/VBox/VMM/include/PDMAsyncCompletionInternal.h@ 94249

Last change on this file since 94249 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/* $Id: PDMAsyncCompletionInternal.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device Manager, Async I/O Completion internal header.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle Corporation
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
18#ifndef VMM_INCLUDED_SRC_include_PDMAsyncCompletionInternal_h
19#define VMM_INCLUDED_SRC_include_PDMAsyncCompletionInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <iprt/critsect.h>
25#include <iprt/memcache.h>
26#include <iprt/sg.h>
27#include <VBox/types.h>
28#include <VBox/vmm/cfgm.h>
29#include <VBox/vmm/stam.h>
30#include <VBox/vmm/pdmasynccompletion.h>
31#include "PDMInternal.h"
32
33RT_C_DECLS_BEGIN
34
35
36/**
37 * PDM Async completion endpoint operations.
38 */
39typedef struct PDMASYNCCOMPLETIONEPCLASSOPS
40{
41 /** Version identifier. */
42 uint32_t u32Version;
43 /** Name of the endpoint class. */
44 const char *pszName;
45 /** Class type. */
46 PDMASYNCCOMPLETIONEPCLASSTYPE enmClassType;
47 /** Size of the global endpoint class data in bytes. */
48 size_t cbEndpointClassGlobal;
49 /** Size of an endpoint in bytes. */
50 size_t cbEndpoint;
51 /** size of a task in bytes. */
52 size_t cbTask;
53
54 /**
55 * Initializes the global data for a endpoint class.
56 *
57 * @returns VBox status code.
58 * @param pClassGlobals Pointer to the uninitialized globals data.
59 * @param pCfgNode Node for querying configuration data.
60 */
61 DECLR3CALLBACKMEMBER(int, pfnInitialize, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals, PCFGMNODE pCfgNode));
62
63 /**
64 * Frees all allocated resources which were allocated during init.
65 *
66 * @returns VBox status code.
67 * @param pClassGlobals Pointer to the globals data.
68 */
69 DECLR3CALLBACKMEMBER(void, pfnTerminate, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals));
70
71 /**
72 * Initializes a given endpoint.
73 *
74 * @returns VBox status code.
75 * @param pEndpoint Pointer to the uninitialized endpoint.
76 * @param pszUri Pointer to the string containing the endpoint
77 * destination (filename, IP address, ...)
78 * @param fFlags Creation flags.
79 */
80 DECLR3CALLBACKMEMBER(int, pfnEpInitialize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
81 const char *pszUri, uint32_t fFlags));
82
83 /**
84 * Closes a endpoint finishing all tasks.
85 *
86 * @returns VBox status code.
87 * @param pEndpoint Pointer to the endpoint to be closed.
88 */
89 DECLR3CALLBACKMEMBER(int, pfnEpClose, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint));
90
91 /**
92 * Initiates a read request from the given endpoint.
93 *
94 * @returns VBox status code.
95 * @param pTask Pointer to the task object associated with the request.
96 * @param pEndpoint Endpoint the request is for.
97 * @param off Where to start reading from.
98 * @param paSegments Scatter gather list to store the data in.
99 * @param cSegments Number of segments in the list.
100 * @param cbRead The overall number of bytes to read.
101 */
102 DECLR3CALLBACKMEMBER(int, pfnEpRead, (PPDMASYNCCOMPLETIONTASK pTask,
103 PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
104 PCRTSGSEG paSegments, size_t cSegments,
105 size_t cbRead));
106
107 /**
108 * Initiates a write request to the given endpoint.
109 *
110 * @returns VBox status code.
111 * @param pTask Pointer to the task object associated with the request.
112 * @param pEndpoint Endpoint the request is for.
113 * @param off Where to start writing to.
114 * @param paSegments Scatter gather list to store the data in.
115 * @param cSegments Number of segments in the list.
116 * @param cbRead The overall number of bytes to write.
117 */
118 DECLR3CALLBACKMEMBER(int, pfnEpWrite, (PPDMASYNCCOMPLETIONTASK pTask,
119 PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
120 PCRTSGSEG paSegments, size_t cSegments,
121 size_t cbWrite));
122
123 /**
124 * Initiates a flush request on the given endpoint.
125 *
126 * @returns VBox status code.
127 * @param pTask Pointer to the task object associated with the request.
128 * @param pEndpoint Endpoint the request is for.
129 */
130 DECLR3CALLBACKMEMBER(int, pfnEpFlush, (PPDMASYNCCOMPLETIONTASK pTask,
131 PPDMASYNCCOMPLETIONENDPOINT pEndpoint));
132
133 /**
134 * Queries the size of the endpoint. Optional.
135 *
136 * @returns VBox status code.
137 * @param pEndpoint Endpoint the request is for.
138 * @param pcbSize Where to store the size of the endpoint.
139 */
140 DECLR3CALLBACKMEMBER(int, pfnEpGetSize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
141 uint64_t *pcbSize));
142
143 /**
144 * Sets the size of the endpoint. Optional.
145 * This is a synchronous operation.
146 *
147 *
148 * @returns VBox status code.
149 * @param pEndpoint Endpoint the request is for.
150 * @param cbSize New size for the endpoint.
151 */
152 DECLR3CALLBACKMEMBER(int, pfnEpSetSize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
153 uint64_t cbSize));
154
155 /** Initialization safety marker. */
156 uint32_t u32VersionEnd;
157} PDMASYNCCOMPLETIONEPCLASSOPS;
158/** Pointer to a async completion endpoint class operation table. */
159typedef PDMASYNCCOMPLETIONEPCLASSOPS *PPDMASYNCCOMPLETIONEPCLASSOPS;
160/** Const pointer to a async completion endpoint class operation table. */
161typedef const PDMASYNCCOMPLETIONEPCLASSOPS *PCPDMASYNCCOMPLETIONEPCLASSOPS;
162
163/** Version for the endpoint class operations structure. */
164#define PDMAC_EPCLASS_OPS_VERSION 0x00000001
165
166/** Pointer to a bandwidth control manager. */
167typedef struct PDMACBWMGR *PPDMACBWMGR;
168
169/**
170 * PDM Async completion endpoint class.
171 * Common data.
172 */
173typedef struct PDMASYNCCOMPLETIONEPCLASS
174{
175 /** Pointer to the VM. */
176 PVM pVM;
177 /** Critical section protecting the lists below. */
178 RTCRITSECT CritSect;
179 /** Number of endpoints in the list. */
180 volatile unsigned cEndpoints;
181 /** Head of endpoints with this class. */
182 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pEndpointsHead;
183 /** Head of the bandwidth managers for this class. */
184 R3PTRTYPE(PPDMACBWMGR) pBwMgrsHead;
185 /** Pointer to the callback table. */
186 R3PTRTYPE(PCPDMASYNCCOMPLETIONEPCLASSOPS) pEndpointOps;
187 /** Task cache. */
188 RTMEMCACHE hMemCacheTasks;
189 /** Flag whether to gather advanced statistics about requests. */
190 bool fGatherAdvancedStatistics;
191} PDMASYNCCOMPLETIONEPCLASS;
192/** Pointer to the PDM async completion endpoint class data. */
193typedef PDMASYNCCOMPLETIONEPCLASS *PPDMASYNCCOMPLETIONEPCLASS;
194
195/**
196 * A PDM Async completion endpoint.
197 * Common data.
198 */
199typedef struct PDMASYNCCOMPLETIONENDPOINT
200{
201 /** Next endpoint in the list. */
202 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pNext;
203 /** Previous endpoint in the list. */
204 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pPrev;
205 /** Pointer to the class this endpoint belongs to. */
206 R3PTRTYPE(PPDMASYNCCOMPLETIONEPCLASS) pEpClass;
207 /** Template associated with this endpoint. */
208 PPDMASYNCCOMPLETIONTEMPLATE pTemplate;
209 /** Statistics ID for endpoints having a similar URI (same filename for example)
210 * to avoid assertions. */
211 unsigned iStatId;
212 /** URI describing the endpoint */
213 char *pszUri;
214 /** Pointer to the assigned bandwidth manager. */
215 volatile PPDMACBWMGR pBwMgr;
216 /** Aligns following statistic counters on a 8 byte boundary. */
217 uint32_t u32Alignment;
218 /** @name Request size statistics.
219 * @{ */
220 STAMCOUNTER StatReqSizeSmaller512;
221 STAMCOUNTER StatReqSize512To1K;
222 STAMCOUNTER StatReqSize1KTo2K;
223 STAMCOUNTER StatReqSize2KTo4K;
224 STAMCOUNTER StatReqSize4KTo8K;
225 STAMCOUNTER StatReqSize8KTo16K;
226 STAMCOUNTER StatReqSize16KTo32K;
227 STAMCOUNTER StatReqSize32KTo64K;
228 STAMCOUNTER StatReqSize64KTo128K;
229 STAMCOUNTER StatReqSize128KTo256K;
230 STAMCOUNTER StatReqSize256KTo512K;
231 STAMCOUNTER StatReqSizeOver512K;
232 STAMCOUNTER StatReqsUnaligned512;
233 STAMCOUNTER StatReqsUnaligned4K;
234 STAMCOUNTER StatReqsUnaligned8K;
235 /** @} */
236 /** @name Request completion time statistics.
237 * @{ */
238 STAMCOUNTER StatTaskRunTimesNs[10];
239 STAMCOUNTER StatTaskRunTimesUs[10];
240 STAMCOUNTER StatTaskRunTimesMs[10];
241 STAMCOUNTER StatTaskRunTimesSec[10];
242 STAMCOUNTER StatTaskRunOver100Sec;
243 STAMCOUNTER StatIoOpsPerSec;
244 STAMCOUNTER StatIoOpsStarted;
245 STAMCOUNTER StatIoOpsCompleted;
246 uint64_t tsIntervalStartMs;
247 uint64_t cIoOpsCompleted;
248 /** @} */
249} PDMASYNCCOMPLETIONENDPOINT;
250AssertCompileMemberAlignment(PDMASYNCCOMPLETIONENDPOINT, StatReqSizeSmaller512, sizeof(uint64_t));
251AssertCompileMemberAlignment(PDMASYNCCOMPLETIONENDPOINT, StatTaskRunTimesNs, sizeof(uint64_t));
252
253/**
254 * A PDM async completion task handle.
255 * Common data.
256 */
257typedef struct PDMASYNCCOMPLETIONTASK
258{
259 /** Next task in the list
260 * (for free and assigned tasks). */
261 R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pNext;
262 /** Previous task in the list
263 * (for free and assigned tasks). */
264 R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pPrev;
265 /** Endpoint this task is assigned to. */
266 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pEndpoint;
267 /** Opaque user data for this task. */
268 void *pvUser;
269 /** Start timestamp. */
270 uint64_t tsNsStart;
271} PDMASYNCCOMPLETIONTASK;
272
273void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, int rc, bool fCallCompletionHandler);
274bool pdmacEpIsTransferAllowed(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, uint32_t cbTransfer, RTMSINTERVAL *pmsWhenNext);
275
276RT_C_DECLS_END
277
278extern const PDMASYNCCOMPLETIONEPCLASSOPS g_PDMAsyncCompletionEndpointClassFile;
279
280#endif /* !VMM_INCLUDED_SRC_include_PDMAsyncCompletionInternal_h */
281
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