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