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