VirtualBox

Ignore:
Timestamp:
Dec 6, 2013 9:38:28 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
91156
Message:

Devices/USB: First part of the rework, move most of the work to dedicated threads to improve performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/solaris/USBProxyDevice-solaris.cpp

    r47497 r49814  
    3838#include <iprt/file.h>
    3939#include <iprt/mem.h>
     40#include <iprt/pipe.h>
    4041#include "../USBProxyDevice.h"
    4142#include <VBox/usblib.h>
     
    9192    /** The tail of the landed solaris URBs. */
    9293    PUSBPROXYURBSOL                pTaxingTail;
     94    /** Pipe handle for waiking up - writing end. */
     95    RTPIPE                         hPipeWakeupW;
     96    /** Pipe handle for waiking up - reading end. */
     97    RTPIPE                         hPipeWakeupR;
    9398} USBPROXYDEVSOL, *PUSBPROXYDEVSOL;
    9499
     
    309314                    pProxyDev->Backend.pv = pDevSol;
    310315
    311                     int Instance;
    312                     char *pszDevicePath = NULL;
    313                     rc = USBLibGetClientInfo(szDeviceIdent, &pszDevicePath, &Instance);
     316                    /*
     317                     * Create wakeup pipe.
     318                     */
     319                    rc = RTPipeCreate(&pDevLnx->hPipeWakeupR, &pDevLnx->hPipeWakeupW, 0);
    314320                    if (RT_SUCCESS(rc))
    315321                    {
    316                         pDevSol->pszDevicePath = pszDevicePath;
    317 
    318                         /*
    319                          * Open the client driver.
    320                          */
    321                         RTFILE hFile;
    322                         rc = RTFileOpen(&hFile, pDevSol->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
     322                        int Instance;
     323                        char *pszDevicePath = NULL;
     324                        rc = USBLibGetClientInfo(szDeviceIdent, &pszDevicePath, &Instance);
    323325                        if (RT_SUCCESS(rc))
    324326                        {
    325                             pDevSol->hFile = hFile;
    326                             pDevSol->pProxyDev = pProxyDev;
     327                            pDevSol->pszDevicePath = pszDevicePath;
    327328
    328329                            /*
    329                              * Verify client driver version.
     330                             * Open the client driver.
    330331                             */
    331                             VBOXUSBREQ_GET_VERSION GetVersionReq;
    332                             bzero(&GetVersionReq, sizeof(GetVersionReq));
    333                             rc = usbProxySolarisIOCtl(pDevSol, VBOXUSB_IOCTL_GET_VERSION, &GetVersionReq, sizeof(GetVersionReq));
     332                            RTFILE hFile;
     333                            rc = RTFileOpen(&hFile, pDevSol->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
    334334                            if (RT_SUCCESS(rc))
    335335                            {
    336                                 if (   GetVersionReq.u32Major == VBOXUSB_VERSION_MAJOR
    337                                     && GetVersionReq.u32Minor >= VBOXUSB_VERSION_MINOR)
     336                                pDevSol->hFile = hFile;
     337                                pDevSol->pProxyDev = pProxyDev;
     338
     339                                /*
     340                                 * Verify client driver version.
     341                                 */
     342                                VBOXUSBREQ_GET_VERSION GetVersionReq;
     343                                bzero(&GetVersionReq, sizeof(GetVersionReq));
     344                                rc = usbProxySolarisIOCtl(pDevSol, VBOXUSB_IOCTL_GET_VERSION, &GetVersionReq, sizeof(GetVersionReq));
     345                                if (RT_SUCCESS(rc))
    338346                                {
    339                                     /*
    340                                      * Try & get the current cached config from Solaris.
    341                                      */
    342                                     usbProxySolarisGetActiveConfig(pDevSol);
    343                                     return VINF_SUCCESS;
     347                                    if (   GetVersionReq.u32Major == VBOXUSB_VERSION_MAJOR
     348                                        && GetVersionReq.u32Minor >= VBOXUSB_VERSION_MINOR)
     349                                    {
     350                                        /*
     351                                         * Try & get the current cached config from Solaris.
     352                                         */
     353                                        usbProxySolarisGetActiveConfig(pDevSol);
     354                                        return VINF_SUCCESS;
     355                                    }
     356                                    else
     357                                    {
     358                                        LogRel((USBPROXY ":version mismatch! driver v%d.%d expecting ~v%d.%d\n", GetVersionReq.u32Major,
     359                                                GetVersionReq.u32Minor, VBOXUSB_VERSION_MAJOR, VBOXUSB_VERSION_MINOR));
     360                                        rc = VERR_VERSION_MISMATCH;
     361                                    }
    344362                                }
    345363                                else
    346364                                {
    347                                     LogRel((USBPROXY ":version mismatch! driver v%d.%d expecting ~v%d.%d\n", GetVersionReq.u32Major,
    348                                             GetVersionReq.u32Minor, VBOXUSB_VERSION_MAJOR, VBOXUSB_VERSION_MINOR));
    349                                     rc = VERR_VERSION_MISMATCH;
     365                                    LogRel((USBPROXY ":failed to query driver version. rc=%Rrc\n", rc));
    350366                                }
     367
     368                                RTFileClose(pDevSol->hFile);
     369                                pDevSol->hFile = NIL_RTFILE;
     370                                pDevSol->pProxyDev = NULL;
    351371                            }
    352372                            else
    353                             {
    354                                 LogRel((USBPROXY ":failed to query driver version. rc=%Rrc\n", rc));
    355                             }
    356 
    357                             RTFileClose(pDevSol->hFile);
    358                             pDevSol->hFile = NIL_RTFILE;
    359                             pDevSol->pProxyDev = NULL;
     373                                LogRel((USBPROXY ":failed to open device. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
     374
     375                            RTStrFree(pDevSol->pszDevicePath);
     376                            pDevSol->pszDevicePath = NULL;
    360377                        }
    361378                        else
    362                             LogRel((USBPROXY ":failed to open device. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
    363 
    364                         RTStrFree(pDevSol->pszDevicePath);
    365                         pDevSol->pszDevicePath = NULL;
    366                     }
    367                     else
    368                     {
    369                         LogRel((USBPROXY ":failed to get client info. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
    370                         if (rc == VERR_NOT_FOUND)
    371                             rc = VERR_OPEN_FAILED;
     379                        {
     380                            LogRel((USBPROXY ":failed to get client info. rc=%Rrc pszDevicePath=%s\n", rc, pDevSol->pszDevicePath));
     381                            if (rc == VERR_NOT_FOUND)
     382                                rc = VERR_OPEN_FAILED;
     383                        }
     384                        RTPipeClose(pDevLnx->hPipeWakeupR);
     385                        RTPipeClose(pDevLnx->hPipeWakeupW);
    372386                    }
    373387
     
    431445        RTMemFree(pUrbSol);
    432446    }
     447
     448    RTPipeClose(pDevLnx->hPipeWakeupR);
     449    RTPipeClose(pDevLnx->hPipeWakeupW);
    433450
    434451    RTStrFree(pDevSol->pszDevicePath);
     
    703720        for (;;)
    704721        {
    705             struct pollfd pfd;
    706             pfd.fd = RTFileToNative(pDevSol->hFile);
    707             pfd.events = POLLIN;
    708             pfd.revents = 0;
    709             int rc = poll(&pfd, 1, cMillies);
     722            int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies;
     723            struct pollfd pfd[2];
     724
     725            pfd[0].fd = RTFileToNative(pDevSol->hFile);
     726            pfd[0].events = POLLIN;
     727            pfd[0].revents = 0;
     728
     729            pfd[1].fd = RTPipeToNative(pDevSol->hWakeupPipeR);
     730            pfd[1].events = POLLIN;
     731            pfd[1].revents = 0;
     732
     733            int rc = poll(&pfd, 2, cMilliesWait);
    710734            if (rc > 0)
    711735            {
    712                 if (pfd.revents & POLLHUP)
     736                if (pfd[0].revents & POLLHUP)
    713737                {
    714738                    LogRel((USBPROXY ":Reaping failed, USB Device '%s' disconnected!\n", pDevSol->pProxyDev->pUsbIns->pszName));
     
    716740                    usbProxySolarisCloseFile(pDevSol);
    717741                }
     742
     743                if (pfd[1].revents & POLLIN)
     744                {
     745                    /* Got woken up, drain pipe. */
     746                    uint8_t bRead;
     747                    size_t cbIgnored = 0;
     748                    RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored);
     749
     750                    /*
     751                     * It is possible that we got woken up and have an URB pending
     752                     * for completion. Do it on the way out. Otherwise return
     753                     * immediately to the caller.
     754                     */
     755                    if (!(pfd[0].revents & POLLIN))
     756                        return NULL;
     757                }
     758
    718759                break;
    719760            }
     
    852893
    853894
     895static DECLCALLBACK(int) usbProxySolarisWakeup(PUSBPROXYDEV pProxyDev)
     896{
     897    PUSBPROXYDEVSOL pDevSol = (PUSBPROXYDEVSOL)pProxyDev->Backend.pv;
     898    size_t cbIgnored;
     899
     900    LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
     901
     902    return RTPipeWrite(pDevSol->hPipeWakeupW, "", 1, &cbIgnored);
     903}
     904
    854905
    855906/**
     
    871922    usbProxySolarisUrbCancel,
    872923    usbProxySolarisUrbReap,
     924    usbProxySolarisWakeup,
    873925    0
    874926};
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette