PDMAsyncCompletionInternal.h revision c458503b85d643d51c5287959b8d96a3e32d9499
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas/* $Id$ */
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas/** @file
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek * PDM - Pluggable Device Manager, Async I/O Completion internal header.
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek */
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek/*
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek * Copyright (C) 2006-2010 Oracle Corporation
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek *
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek * This file is part of VirtualBox Open Source Edition (OSE), as
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek * available from http://www.virtualbox.org. This file is free software;
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek * you can redistribute it and/or modify it under the terms of the GNU
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek * General Public License (GPL) as published by the Free Software
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas * Foundation, in version 2 as it comes in the "COPYING" file of the
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas */
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#ifndef ___PDMAsyncCompletionInternal_h
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#define ___PDMAsyncCompletionInternal_h
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#include <iprt/critsect.h>
299c397c127cda34facbe7d089f944a708ec95e9Zbigniew Jędrzejewski-Szmek#include <iprt/memcache.h>
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek#include <iprt/sg.h>
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek#include <VBox/types.h>
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#include <VBox/vmm/cfgm.h>
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#include <VBox/vmm/stam.h>
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#include <VBox/vmm/pdmasynccompletion.h>
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas#include "PDMInternal.h"
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-SzmekRT_C_DECLS_BEGIN
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek/**
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek * PDM Async completion endpoint operations.
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek */
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmektypedef struct PDMASYNCCOMPLETIONEPCLASSOPS
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek{
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek /** Version identifier. */
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek uint32_t u32Version;
fe05567c31cb88593a09ce5d8961d8b20627feb1Zbigniew Jędrzejewski-Szmek /** Name of the endpoint class. */
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas const char *pcszName;
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas /** Class type. */
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas PDMASYNCCOMPLETIONEPCLASSTYPE enmClassType;
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas /** Size of the global endpoint class data in bytes. */
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas size_t cbEndpointClassGlobal;
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek /** Size of an endpoint in bytes. */
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek size_t cbEndpoint;
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek /** size of a task in bytes. */
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek size_t cbTask;
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas /**
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek * Initializes the global data for a endpoint class.
2c12a402cb1e8277c271ced8dc9c06d20b8f6017Zbigniew Jędrzejewski-Szmek *
7abfbe7903d8e792850ec39286a3d86e616a6477William Giokas * @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;
} 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;
/** Reference count. */
unsigned cUsers;
/** URI describing the endpoint */
char *pszUri;
/** Pointer to the assigned bandwidth manager. */
volatile PPDMACBWMGR pBwMgr;
#ifdef VBOX_WITH_STATISTICS
uint32_t u32Alignment;
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;
#endif
} PDMASYNCCOMPLETIONENDPOINT;
#ifdef VBOX_WITH_STATISTICS
AssertCompileMemberAlignment(PDMASYNCCOMPLETIONENDPOINT, StatTaskRunTimesNs, sizeof(uint64_t));
#endif
/**
* 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;
/**
* Called by the endpoint if a task has finished.
*
* @returns nothing
* @param pTask Pointer to the finished task.
* @param rc Status code of the completed request.
* @param fCallCompletionHandler Flag whether the completion handler should be called to
* inform the owner of the task that it has completed.
*/
void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, int rc, bool fCallCompletionHandler);
/**
* Checks if the endpoint is allowed to transfer the given amount of bytes.
*
* @returns true if the endpoint is allowed to transfer the data.
* false otherwise
* @param pEndpoint The endpoint.
* @param cbTransfer The number of bytes to transfer.
* @param pmsWhenNext Where to store the number of milliseconds
* until the bandwidth is refreshed.
* Only set if false is returned.
*/
bool pdmacEpIsTransferAllowed(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, uint32_t cbTransfer, RTMSINTERVAL *pmsWhenNext);
RT_C_DECLS_END
extern const PDMASYNCCOMPLETIONEPCLASSOPS g_PDMAsyncCompletionEndpointClassFile;
#endif /* !___PDMAsyncCompletionInternal_h */