PDMAsyncCompletion.cpp revision 70aa086e9e9d2f85d2e997d0e69169018a001e54
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * PDM Async I/O - Transport data asynchronous in R3 using EMT.
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync * Copyright (C) 2006-2011 Oracle Corporation
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * available from http://www.virtualbox.org. This file is free software;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Header Files *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Structures and Typedefs *
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync*******************************************************************************/
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Async I/O type.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Device . */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Driver consumer. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Internal consumer. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Usb consumer. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * PDM Async I/O template.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to the next template in the list. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to the previous template in the list. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Type specific data. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** PDMASYNCCOMPLETIONTEMPLATETYPE_DEV */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to consumer function. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to the device instance owning the template. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** PDMASYNCCOMPLETIONTEMPLATETYPE_DRV */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to consumer function. */
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsync /** Pointer to the driver instance owning the template. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync /** User argument given during template creation.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * This is only here to make things much easier
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * for DrVVD. */
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsync /** PDMASYNCCOMPLETIONTEMPLATETYPE_INTERNAL */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to consumer function. */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync /** Pointer to user data. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** PDMASYNCCOMPLETIONTEMPLATETYPE_USB */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /** Pointer to consumer function. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /** Pointer to the usb instance owning the template. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /** Template type. */
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync /** Pointer to the VM. */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Use count of the template. */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync * Bandwidth control manager instance data
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsynctypedef struct PDMACBWMGR
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync /** Pointer to the next manager in the list. */
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync /** Pointer to the shared UVM structure. */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Identifier of the manager. */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Maximum number of bytes the endpoints are allowed to transfer (Max is 4GB/s currently) */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Number of bytes we start with */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Step after each update */
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync /** Number of bytes we are allowed to transfer till the next update.
05406988cc320ac1b0971de976b6cf0c986044a9vboxsync * Reset by the refresh timer. */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Timestamp of the last update */
1db6afc370c2fa84144478dffa9c1ed3c28c7158vboxsync /** Reference counter - How many endpoints are associated with this manager. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/** Pointer to a bandwidth control manager pointer. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync/*******************************************************************************
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync* Internal Functions *
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync*******************************************************************************/
323b78bf4831666c95416edf3b6e54657a769e5dvboxsyncstatic void pdmR3AsyncCompletionPutTask(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, PPDMASYNCCOMPLETIONTASK pTask);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Internal worker for the creation apis
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM VM handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppTemplate Where to store the template handle.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pdmR3AsyncCompletionTemplateCreate(PVM pVM, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync int rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_ASYNC_COMPLETION, sizeof(PDMASYNCCOMPLETIONTEMPLATE), (void **)&pTemplate);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Initialize fields.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Add template to the global VM template list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pTemplate->pNext = pUVM->pdm.s.pAsyncCompletionTemplates;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pUVM->pdm.s.pAsyncCompletionTemplates->pPrev = pTemplate;
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Creates a async completion template for a device instance.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * The template is used when creating new completion tasks.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDevIns The device instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppTemplate Where to store the template pointer on success.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * @param pfnCompleted The completion callback routine.
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync * @param pszDesc Description.
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDEV pfnCompleted, const char *pszDesc)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("%s: pDevIns=%p ppTemplate=%p pfnCompleted=%p pszDesc=%s\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync __FUNCTION__, pDevIns, ppTemplate, pfnCompleted, pszDesc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Validate input.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertPtrReturn(pfnCompleted, VERR_INVALID_POINTER);
61e80138f3c5ea5213990bde94a973c8e64d1dadvboxsync * Create the template.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pdmR3AsyncCompletionTemplateCreate(pVM, &pTemplate, PDMASYNCCOMPLETIONTEMPLATETYPE_DEV);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("PDM: Created device template %p: pfnCompleted=%p pDevIns=%p\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Creates a async completion template for a driver instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The template is used when creating new completion tasks.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDrvIns The driver instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppTemplate Where to store the template pointer on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pfnCompleted The completion callback routine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvTemplateUser Template user argument
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pszDesc Description.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser, const char *pszDesc)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("%s: pDrvIns=%p ppTemplate=%p pfnCompleted=%p pszDesc=%s\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync __FUNCTION__, pDrvIns, ppTemplate, pfnCompleted, pszDesc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Validate input.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertPtrReturn(pfnCompleted, VERR_INVALID_POINTER);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Create the template.
be9bc9b4ba510c4b4159c193f783d024633ef8e9vboxsync int rc = pdmR3AsyncCompletionTemplateCreate(pVM, &pTemplate, PDMASYNCCOMPLETIONTEMPLATETYPE_DRV);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("PDM: Created driver template %p: pfnCompleted=%p pDrvIns=%p\n",
2afbe132eb7931e0125141eabe3a48e08f1ffab5vboxsync * Creates a async completion template for a USB device instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The template is used when creating new completion tasks.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pUsbIns The USB device instance.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param ppTemplate Where to store the template pointer on success.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param pfnCompleted The completion callback routine.
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * @param pszDesc Description.
090f6abdd6282f48527b83162b8b441425f05e36vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEUSB pfnCompleted, const char *pszDesc)
090f6abdd6282f48527b83162b8b441425f05e36vboxsync LogFlow(("%s: pUsbIns=%p ppTemplate=%p pfnCompleted=%p pszDesc=%s\n",
090f6abdd6282f48527b83162b8b441425f05e36vboxsync __FUNCTION__, pUsbIns, ppTemplate, pfnCompleted, pszDesc));
118e1c3f853f78b4aec64afdcb8379981f41314fvboxsync * Validate input.
090f6abdd6282f48527b83162b8b441425f05e36vboxsync AssertPtrReturn(pfnCompleted, VERR_INVALID_POINTER);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Create the template.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pdmR3AsyncCompletionTemplateCreate(pVM, &pTemplate, PDMASYNCCOMPLETIONTEMPLATETYPE_USB);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("PDM: Created usb template %p: pfnCompleted=%p pDevIns=%p\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Creates a async completion template for internally by the VMM.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * The template is used when creating new completion tasks.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param ppTemplate Where to store the template pointer on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pfnCompleted The completion callback routine.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pvUser2 The 2nd user argument for the callback.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pszDesc Description.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateInternal(PVM pVM, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEINT pfnCompleted, void *pvUser2, const char *pszDesc)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("%s: ppTemplate=%p pfnCompleted=%p pvUser2=%p pszDesc=%s\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync __FUNCTION__, ppTemplate, pfnCompleted, pvUser2, pszDesc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Validate input.
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync AssertPtrReturn(pfnCompleted, VERR_INVALID_POINTER);
0ebb1ef53864eb9cc97580f722288c9b29bc5d03vboxsync * Create the template.
f5395a2af3050ddd694b0ad505975f7b717ab4f1vboxsync int rc = pdmR3AsyncCompletionTemplateCreate(pVM, &pTemplate, PDMASYNCCOMPLETIONTEMPLATETYPE_INTERNAL);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync Log(("PDM: Created internal template %p: pfnCompleted=%p pvUser2=%p\n",
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * Destroys the specified async completion template.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status codes:
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * @retval VINF_SUCCESS on success.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if the template is still in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pTemplate The template in question.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroy(PPDMASYNCCOMPLETIONTEMPLATE pTemplate)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("%s: pTemplate=%p\n", __FUNCTION__, pTemplate));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Check if the template is still used.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * Unlink the template from the list.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pPrev = pTemplate->pPrev;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pNext = pTemplate->pNext;
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * Free the template.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Destroys all the specified async completion templates for the given device instance.
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync * @returns VBox status codes:
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDevIns The device instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDevice(PVM pVM, PPDMDEVINS pDevIns)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("%s: pDevIns=%p\n", __FUNCTION__, pDevIns));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Validate input.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * Unlink it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplate = pUVM->pdm.s.pAsyncCompletionTemplates;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ( pTemplate->enmType == PDMASYNCCOMPLETIONTEMPLATETYPE_DEV
a64bf60e92e5cb8a76aa6c8e92193932d88a906fvboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplateDestroy = pTemplate;
04a471b98d492ee51b1f40424c7f90ddf44a90f0vboxsync int rc = PDMR3AsyncCompletionTemplateDestroy(pTemplateDestroy);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * Destroys all the specified async completion templates for the given driver instance.
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @returns VBox status codes:
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pDrvIns The driver instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns)
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync LogFlow(("%s: pDevIns=%p\n", __FUNCTION__, pDrvIns));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * Validate input.
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsync * Unlink it.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplate = pUVM->pdm.s.pAsyncCompletionTemplates;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ( pTemplate->enmType == PDMASYNCCOMPLETIONTEMPLATETYPE_DRV
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplateDestroy = pTemplate;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = PDMR3AsyncCompletionTemplateDestroy(pTemplateDestroy);
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync * Destroys all the specified async completion templates for the given USB device instance.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status codes:
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * @retval VINF_SUCCESS on success.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pUsbIns The USB device instance.
13d75a5db336ccb682d7ab28b397a4f0b8982ea3vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("%s: pUsbIns=%p\n", __FUNCTION__, pUsbIns));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Validate input.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Unlink it.
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplate = pUVM->pdm.s.pAsyncCompletionTemplates;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if ( pTemplate->enmType == PDMASYNCCOMPLETIONTEMPLATETYPE_USB
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplateDestroy = pTemplate;
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync int rc = PDMR3AsyncCompletionTemplateDestroy(pTemplateDestroy);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsyncstatic PPDMACBWMGR pdmacBwMgrFindById(PPDMASYNCCOMPLETIONEPCLASS pEpClass, const char *pcszId)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = RTCritSectEnter(&pEpClass->CritSect); AssertRC(rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = RTCritSectLeave(&pEpClass->CritSect); AssertRC(rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONEPCLASS pEpClass = pBwMgr->pEpClass;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = RTCritSectEnter(&pEpClass->CritSect); AssertRC(rc);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync rc = RTCritSectLeave(&pEpClass->CritSect); AssertRC(rc);
7e960d3a0a8a3a84d7aba2cca45d72b1c31cc97bvboxsync PPDMASYNCCOMPLETIONEPCLASS pEpClass = pBwMgr->pEpClass;
42c1972c22e09797b4b24afbd0ec114ed076c37cvboxsync int rc = RTCritSectEnter(&pEpClass->CritSect); AssertRC(rc);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = RTCritSectLeave(&pEpClass->CritSect); AssertRC(rc);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync#endif /* SOME_UNUSED_FUNCTION */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic int pdmacAsyncCompletionBwMgrCreate(PPDMASYNCCOMPLETIONEPCLASS pEpClass, const char *pcszBwMgr, uint32_t cbTransferPerSecMax,
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync uint32_t cbTransferPerSecStart, uint32_t cbTransferPerSecStep)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlowFunc(("pEpClass=%#p pcszBwMgr=%#p{%s} cbTransferPerSecMax=%u cbTransferPerSecStart=%u cbTransferPerSecStep=%u\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pEpClass, pcszBwMgr, cbTransferPerSecMax, cbTransferPerSecStart, cbTransferPerSecStep));
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync AssertReturn(*pcszBwMgr != '\0', VERR_INVALID_PARAMETER);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMACBWMGR pBwMgr = pdmacBwMgrFindById(pEpClass, pcszBwMgr);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = MMR3HeapAllocZEx(pEpClass->pVM, MM_TAG_PDM_ASYNC_COMPLETION,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Init I/O flow control. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pBwMgr->cbTransferPerSecStart = cbTransferPerSecStart;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pBwMgr->cbTransferPerSecStep = cbTransferPerSecStep;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pBwMgr->cbTransferAllowed = pBwMgr->cbTransferPerSecStart;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncDECLINLINE(void) pdmacBwMgrUnref(PPDMACBWMGR pBwMgr)
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsyncbool pdmacEpIsTransferAllowed(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, uint32_t cbTransfer, RTMSINTERVAL *pmsWhenNext)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync bool fAllowed = true;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMACBWMGR pBwMgr = ASMAtomicReadPtrT(&pEndpoint->pBwMgr, PPDMACBWMGR);
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync LogFlowFunc(("pEndpoint=%p pBwMgr=%p cbTransfer=%u\n", pEndpoint, pBwMgr, cbTransfer));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint32_t cbOld = ASMAtomicSubU32(&pBwMgr->cbTransferAllowed, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* We are out of resources Check if we can update again. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint64_t tsUpdatedLast = ASMAtomicUoReadU64(&pBwMgr->tsUpdatedLast);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (ASMAtomicCmpXchgU64(&pBwMgr->tsUpdatedLast, tsNow, tsUpdatedLast))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pBwMgr->cbTransferPerSecStart < pBwMgr->cbTransferPerSecMax)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pBwMgr->cbTransferPerSecStart = RT_MIN(pBwMgr->cbTransferPerSecMax, pBwMgr->cbTransferPerSecStart + pBwMgr->cbTransferPerSecStep);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlow(("AIOMgr: Increasing maximum bandwidth to %u bytes/sec\n", pBwMgr->cbTransferPerSecStart));
e11fe099decbb0f65cfcc7e2939fa00bacefbb1cvboxsync /* Update */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ASMAtomicWriteU32(&pBwMgr->cbTransferAllowed, pBwMgr->cbTransferPerSecStart - cbTransfer);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync ASMAtomicAddU32(&pBwMgr->cbTransferAllowed, cbTransfer);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync *pmsWhenNext = ((1000*1000*1000) - (tsNow - tsUpdatedLast)) / (1000*1000);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncvoid pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, int rc, bool fCallCompletionHandler)
1df4b0cdc5ec23d817014f9347ef28222b51e3fbvboxsync LogFlow(("%s: pTask=%#p fCallCompletionHandler=%RTbool\n", __FUNCTION__, pTask, fCallCompletionHandler));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONTEMPLATE pTemplate = pTask->pEndpoint->pTemplate;
9a0f1c40d078ffc54c3209648d12c70f36480067vboxsync pTemplate->u.Dev.pfnCompleted(pTemplate->u.Dev.pDevIns, pTask->pvUser, rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pTemplate->u.Drv.pfnCompleted(pTemplate->u.Drv.pDrvIns, pTemplate->u.Drv.pvTemplateUser, pTask->pvUser, rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pTemplate->u.Usb.pfnCompleted(pTemplate->u.Usb.pUsbIns, pTask->pvUser, rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pTemplate->u.Int.pfnCompleted(pTemplate->pVM, pTask->pvUser, pTemplate->u.Int.pvUser, rc);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pdmR3AsyncCompletionPutTask(pTask->pEndpoint, pTask);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Worker initializing a endpoint class.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM instance data.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pEpClass Pointer to the endpoint class structure.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param pCfgHandle Pointer to the the CFGM tree.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsyncint pdmR3AsyncCompletionEpClassInit(PVM pVM, PCPDMASYNCCOMPLETIONEPCLASSOPS pEpClassOps, PCFGMNODE pCfgHandle)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Validate input. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertPtrReturn(pEpClassOps, VERR_INVALID_POINTER);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertReturn(pEpClassOps->u32Version == PDMAC_EPCLASS_OPS_VERSION, VERR_VERSION_MISMATCH);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync AssertReturn(pEpClassOps->u32VersionEnd == PDMAC_EPCLASS_OPS_VERSION, VERR_VERSION_MISMATCH);
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync LogFlowFunc((": pVM=%p pEpClassOps=%p{%s}\n", pVM, pEpClassOps, pEpClassOps->pcszName));
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync /* Allocate global class data. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync int rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_ASYNC_COMPLETION,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Initialize common data. */
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync PCFGMNODE pCfgNodeClass = CFGMR3GetChild(pCfgHandle, pEpClassOps->pcszName);
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync /* Create task cache */
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync rc = RTMemCacheCreate(&pEndpointClass->hMemCacheTasks, pEpClassOps->cbTask,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Call the specific endpoint class initializer. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync rc = pEpClassOps->pfnInitialize(pEndpointClass, pCfgNodeClass);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Create all bandwidth groups for resource control. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PCFGMNODE pCfgBwGrp = CFGMR3GetChild(pCfgNodeClass, "BwGroups");
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (PCFGMNODE pCur = CFGMR3GetFirstChild(pCfgBwGrp); pCur; pCur = CFGMR3GetNextChild(pCur))
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = CFGMR3QueryU32Def(pCur, "Start", &cbStart, cbMax);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pdmacAsyncCompletionBwMgrCreate(pEndpointClass, pszBwGrpId, cbMax, cbStart, cbStep);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync AssertMsg(!pUVM->pdm.s.apAsyncCompletionEndpointClass[pEpClassOps->enmClassType],
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync ("Endpoint class was already initialized\n"));
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync pUVM->pdm.s.apAsyncCompletionEndpointClass[pEpClassOps->enmClassType] = pEndpointClass;
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync LogFlowFunc((": Initialized endpoint class \"%s\" rc=%Rrc\n", pEpClassOps->pcszName, rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlowFunc((": Failed to initialize endpoint class rc=%Rrc\n", rc));
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync * Worker terminating all endpoint classes.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns nothing
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pEndpointClass Pointer to the endpoint class to terminate.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * @remarks This method ensures that any still open endpoint is closed.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pdmR3AsyncCompletionEpClassTerminate(PPDMASYNCCOMPLETIONEPCLASS pEndpointClass)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Close all still open endpoints. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PDMR3AsyncCompletionEpClose(pEndpointClass->pEndpointsHead);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Destroy the bandwidth managers. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Call the termination callback of the class. */
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync pEndpointClass->pEndpointOps->pfnTerminate(pEndpointClass);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Free the memory of the class finally and clear the entry in the class array. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pVM->pUVM->pdm.s.apAsyncCompletionEndpointClass[pEndpointClass->pEndpointOps->enmClassType] = NULL;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Initialize the async completion manager.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PCFGMNODE pCfgAsyncCompletion = CFGMR3GetChild(CFGMR3GetChild(pCfgRoot, "PDM"), "AsyncCompletion");
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = pdmR3AsyncCompletionEpClassInit(pVM, &g_PDMAsyncCompletionEndpointClassFile, pCfgAsyncCompletion);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * Terminates the async completion manager.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns VBox status code
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @param pVM Pointer to the shared VM structure.
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync for (size_t i = 0; i < RT_ELEMENTS(pUVM->pdm.s.apAsyncCompletionEndpointClass); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pdmR3AsyncCompletionEpClassTerminate(pUVM->pdm.s.apAsyncCompletionEndpointClass[i]);
8dee1778d3770cdc584752c84acf4899d8bfc9f9vboxsync * Resume worker for the async completion manager.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync * @returns nothing.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @param pVM Pointer to the shared VM structure.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Log the bandwidth groups and all assigned endpoints. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (size_t i = 0; i < RT_ELEMENTS(pUVM->pdm.s.apAsyncCompletionEndpointClass); i++)
0f8b9243304469cd1e58d6986931bbfed5ba359evboxsync PPDMASYNCCOMPLETIONEPCLASS pEpClass = pUVM->pdm.s.apAsyncCompletionEndpointClass[i];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogRel(("AIOMgr: Bandwidth groups for class '%s'\n", i == PDMASYNCCOMPLETIONEPCLASSTYPE_FILE
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogRel(("AIOMgr: Max: %u B/s\n", pBwMgr->cbTransferPerSecMax));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogRel(("AIOMgr: Start: %u B/s\n", pBwMgr->cbTransferPerSecStart));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogRel(("AIOMgr: Step: %u B/s\n", pBwMgr->cbTransferPerSecStep));
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* Print all endpoints without assigned bandwidth groups. */
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync LogRel(("AIOMgr: Endpoints without assigned bandwidth groups:\n"));
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync * Tries to get a free task from the endpoint or class cache
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * allocating the task if it fails.
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsync * @returns Pointer to a new and initialized task or NULL
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pEndpoint The endpoint the task is for.
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync * @param pvUser Opaque user data for the task.
1f24d758b35a86f1075a86a4760da9bbc1e80229vboxsyncstatic PPDMASYNCCOMPLETIONTASK pdmR3AsyncCompletionGetTask(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, void *pvUser)
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync PPDMASYNCCOMPLETIONEPCLASS pEndpointClass = pEndpoint->pEpClass;
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync PPDMASYNCCOMPLETIONTASK pTask = (PPDMASYNCCOMPLETIONTASK)RTMemCacheAlloc(pEndpointClass->hMemCacheTasks);
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /* Initialize common parts. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Clear list pointers for safety. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * Puts a task in one of the caches.
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync * @returns nothing.
96dce0123cc032388e78766d08f9ee5a66b80facvboxsync * @param pEndpoint The endpoint the task belongs to.
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync * @param pTask The task to cache.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncstatic void pdmR3AsyncCompletionPutTask(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, PPDMASYNCCOMPLETIONTASK pTask)
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync PPDMASYNCCOMPLETIONEPCLASS pEndpointClass = pEndpoint->pEpClass;
9f16100a870e25701da9bc9819e15c0f9fb3870evboxsync uint64_t cNsRun = RTTimeNanoTS() - pTask->tsNsStart;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogRel(("AsyncCompletion: Task %#p completed after %llu seconds\n", pTask, cNsRun / RT_NS_1SEC));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pStatCounter = &pEndpoint->StatTaskRunTimesNs[cNsRun / (RT_NS_1US / 10)];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pStatCounter = &pEndpoint->StatTaskRunTimesUs[cNsRun / (RT_NS_1MS / 10)];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pStatCounter = &pEndpoint->StatTaskRunTimesMs[cNsRun / (RT_NS_1SEC / 10)];
61283d6341bac43f73cf33c9ec754a59f674fa19vboxsync pStatCounter = &pEndpoint->StatTaskRunTimesSec[cNsRun / (RT_NS_1SEC_64*100 / 10)];
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync uint64_t tsInterval = tsMsCur - pEndpoint->tsIntervalStartMs;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync pEndpoint->StatIoOpsPerSec.c = pEndpoint->cIoOpsCompleted / (tsInterval / 1000);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync#endif /* VBOX_WITH_STATISTICS */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync RTMemCacheFree(pEndpointClass->hMemCacheTasks, pTask);
61283d6341bac43f73cf33c9ec754a59f674fa19vboxsyncstatic PPDMASYNCCOMPLETIONENDPOINT pdmR3AsyncCompletionFindEndpointWithUri(PPDMASYNCCOMPLETIONEPCLASS pEndpointClass,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync const char *pszUri)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONENDPOINT pEndpoint = pEndpointClass->pEndpointsHead;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpCreateForFile(PPPDMASYNCCOMPLETIONENDPOINT ppEndpoint,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync LogFlowFunc((": ppEndpoint=%p pszFilename=%p{%s} fFlags=%u pTemplate=%p\n",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ppEndpoint, pszFilename, pszFilename, fFlags, pTemplate));
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync /* Sanity checks. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Check that the flags are valid. */
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync AssertReturn(((~(PDMACEP_FILE_FLAGS_READ_ONLY | PDMACEP_FILE_FLAGS_DONT_LOCK | PDMACEP_FILE_FLAGS_HOST_CACHE_ENABLED) & fFlags) == 0),
22408fe91738075b3c413b14a421d641aacad508vboxsync PPDMASYNCCOMPLETIONEPCLASS pEndpointClass = pUVM->pdm.s.apAsyncCompletionEndpointClass[PDMASYNCCOMPLETIONEPCLASSTYPE_FILE];
22408fe91738075b3c413b14a421d641aacad508vboxsync AssertMsg(pEndpointClass, ("File endpoint class was not initialized\n"));
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync /* Search for a already opened endpoint for this file. */
c279ef9298ff04e966225aa896bc7010562820b5vboxsync pEndpoint = pdmR3AsyncCompletionFindEndpointWithUri(pEndpointClass, pszFilename);
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /* Endpoint found. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Create an endpoint. */
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync int rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_ASYNC_COMPLETION,
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /* Initialize common parts. */
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync /* Call the initializer for the endpoint. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = pEndpointClass->pEndpointOps->pfnEpInitialize(pEndpoint, pszFilename, fFlags);
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync /* Link it into the list of endpoints. */
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync /* Reference the template. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Init the statistics part */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesNs); i++)
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatTaskRunTimesNs[i], STAMTYPE_COUNTER,
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync "Nanosecond resolution runtime statistics",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesUs); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatTaskRunTimesUs[i], STAMTYPE_COUNTER,
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync "Microsecond resolution runtime statistics",
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync "/PDM/AsyncCompletion/File/%s/TaskRun2MicroSec-%u-%u",
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesMs); i++)
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatTaskRunTimesMs[i], STAMTYPE_COUNTER,
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync "Milliseconds resolution runtime statistics",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesMs); i++)
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatTaskRunTimesSec[i], STAMTYPE_COUNTER,
3f1e0eea71cabeb90529e546f16eb7aee513fde9vboxsync "Second resolution runtime statistics",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatTaskRunOver100Sec, STAMTYPE_COUNTER,
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync "Tasks which ran more than 100sec",
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync "/PDM/AsyncCompletion/File/%s/TaskRunSecGreater100Sec",
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatIoOpsPerSec, STAMTYPE_COUNTER,
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync "Processed I/O operations per second",
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatIoOpsStarted, STAMTYPE_COUNTER,
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync "Started I/O operations for this endpoint",
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync rc = STAMR3RegisterF(pVM, &pEndpoint->StatIoOpsCompleted, STAMTYPE_COUNTER,
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync "Completed I/O operations for this endpoint",
ebf9e36b6e5548e4db69cebbef120e669a459afevboxsync /** @todo why bother maintaing rc when it's just ignored /
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync logged and not returned? */
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync LogFlowFunc((": Created endpoint for %s: rc=%Rrc\n", pszFilename, rc));
3cbb4f9a6a320e58ed398ef7aaa004cc8727abc5vboxsync LogFlowFunc((": Creation of endpoint for %s failed: rc=%Rrc\n", pszFilename, rc));
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsyncVMMR3DECL(void) PDMR3AsyncCompletionEpClose(PPDMASYNCCOMPLETIONENDPOINT pEndpoint)
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /* Sanity checks. */
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync /* If the last user closed the endpoint we will free it. */
94f9530895973c2a15ee8da2442cd600fd91d4d7vboxsync PPDMASYNCCOMPLETIONEPCLASS pEndpointClass = pEndpoint->pEpClass;
dd8efff5286a99cf8d9b3a5e8dd62340973f3cc1vboxsync pEndpointClass->pEndpointOps->pfnEpClose(pEndpoint);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Drop reference from the template. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync /* Unlink the endpoint from the list. */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync int rc = RTCritSectEnter(&pEndpointClass->CritSect);
47b5427d1a541bcd269bc625c35b19d849071edfvboxsync AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync PPDMASYNCCOMPLETIONENDPOINT pEndpointNext = pEndpoint->pNext;
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync PPDMASYNCCOMPLETIONENDPOINT pEndpointPrev = pEndpoint->pPrev;
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync AssertMsg(RT_SUCCESS(rc), ("Failed to enter critical section rc=%Rrc\n", rc));
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync /* Deregister the statistics part */
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesNs); i++)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync STAMR3Deregister(pVM, &pEndpoint->StatTaskRunTimesNs[i]);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesUs); i++)
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatTaskRunTimesUs[i]);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesMs); i++)
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatTaskRunTimesMs[i]);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync for (unsigned i = 0; i < RT_ELEMENTS(pEndpoint->StatTaskRunTimesMs); i++)
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatTaskRunTimesSec[i]);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatTaskRunOver100Sec);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatIoOpsPerSec);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatIoOpsStarted);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync STAMR3Deregister(pVM, &pEndpoint->StatIoOpsCompleted);
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpRead(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
8bc010ff67963900f9c39d93ce1a64a4e1c08ba1vboxsync AssertReturn(cSegments > 0, VERR_INVALID_PARAMETER);
51afd9e19409617e8f3a204d58e96e22ee618e57vboxsync pTask = pdmR3AsyncCompletionGetTask(pEndpoint, pvUser);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync int rc = pEndpoint->pEpClass->pEndpointOps->pfnEpRead(pTask, pEndpoint, off,
e131925debcc0add6ebecf92e6d09d62150476a4vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpWrite(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync AssertReturn(cSegments > 0, VERR_INVALID_PARAMETER);
323b78bf4831666c95416edf3b6e54657a769e5dvboxsync pTask = pdmR3AsyncCompletionGetTask(pEndpoint, pvUser);
2afbe132eb7931e0125141eabe3a48e08f1ffab5vboxsync int rc = pEndpoint->pEpClass->pEndpointOps->pfnEpWrite(pTask, pEndpoint, off,
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpFlush(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync pTask = pdmR3AsyncCompletionGetTask(pEndpoint, pvUser);
e131925debcc0add6ebecf92e6d09d62150476a4vboxsync int rc = pEndpoint->pEpClass->pEndpointOps->pfnEpFlush(pTask, pEndpoint);
e131925debcc0add6ebecf92e6d09d62150476a4vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpGetSize(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync if (pEndpoint->pEpClass->pEndpointOps->pfnEpGetSize)
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync return pEndpoint->pEpClass->pEndpointOps->pfnEpGetSize(pEndpoint, pcbSize);
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpSetSize(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
22408fe91738075b3c413b14a421d641aacad508vboxsync if (pEndpoint->pEpClass->pEndpointOps->pfnEpSetSize)
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync return pEndpoint->pEpClass->pEndpointOps->pfnEpSetSize(pEndpoint, cbSize);
22408fe91738075b3c413b14a421d641aacad508vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionEpSetBwMgr(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
22408fe91738075b3c413b14a421d641aacad508vboxsync pBwMgrNew = pdmacBwMgrFindById(pEndpoint->pEpClass, pcszBwMgr);
22408fe91738075b3c413b14a421d641aacad508vboxsync pBwMgrOld = ASMAtomicXchgPtrT(&pEndpoint->pBwMgr, pBwMgrNew, PPDMACBWMGR);
3242fe628b2306c050fb28c489d50bc63118f0c5vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionTaskCancel(PPDMASYNCCOMPLETIONTASK pTask)
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsyncVMMR3DECL(int) PDMR3AsyncCompletionBwMgrSetMaxForFile(PVM pVM, const char *pcszBwMgr, uint32_t cbMaxNew)
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync PPDMASYNCCOMPLETIONEPCLASS pEpClass = pVM->pUVM->pdm.s.apAsyncCompletionEndpointClass[PDMASYNCCOMPLETIONEPCLASSTYPE_FILE];
188ea1a2ae27e2575ff4361c41b368f29128a8c5vboxsync PPDMACBWMGR pBwMgr = pdmacBwMgrFindById(pEpClass, pcszBwMgr);
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * Set the new value for the start and max value to let the manager pick up
afa761a969c8883e5ea370e898d40ce053fbcb22vboxsync * the new limit immediately.
d408b82da0773c7e8cd4b3a01cb8a065a2c73a2dvboxsync ASMAtomicXchgU32(&pBwMgr->cbTransferPerSecMax, cbMaxNew);