VirtualBox

Changeset 87391 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Jan 22, 2021 11:47:33 PM (4 years ago)
Author:
vboxsync
Message:

Allocate PDMLED console LED structs in a sensible manner for each virtual HW driver; not prearranged slices of an poorly sized global pool. bugref:9892

Location:
trunk/src/VBox/Main/src-client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r85745 r87391  
    422422    LogFlowThisFunc(("\n"));
    423423
    424     RT_ZERO(mapStorageLeds);
    425     RT_ZERO(mapNetworkLeds);
    426     RT_ZERO(mapUSBLed);
    427     RT_ZERO(mapSharedFolderLed);
    428     RT_ZERO(mapCrOglLed);
    429 
    430     for (unsigned i = 0; i < RT_ELEMENTS(maStorageDevType); ++i)
    431         maStorageDevType[i] = DeviceType_Null;
     424    mcLedSets = 0;
     425    RT_ZERO(maLedSets);
    432426
    433427    MYVMM2USERMETHODS *pVmm2UserMethods = (MYVMM2USERMETHODS *)RTMemAllocZ(sizeof(*mpVmm2UserMethods) + sizeof(Console *));
     
    822816    unconst(mptrExtPackManager).setNull();
    823817#endif
     818
     819    /* Release memory held by the LED sets. */
     820    for (size_t idxSet = 0; idxSet < mcLedSets; idxSet++)
     821    {
     822        RTMemFree(maLedSets[idxSet].papLeds);
     823        RTMemFree(maLedSets[idxSet].paSubTypes);
     824        maLedSets[idxSet].papLeds = NULL;
     825        maLedSets[idxSet].paSubTypes = NULL;
     826    }
     827    mcLedSets = 0;
    824828
    825829    LogFlowThisFuncLeave();
     
    26892693
    26902694/** read the value of a LED. */
    2691 inline uint32_t readAndClearLed(PPDMLED pLed)
     2695DECLINLINE(uint32_t) readAndClearLed(PPDMLED pLed)
    26922696{
    26932697    if (!pLed)
     
    27062710     */
    27072711
     2712    std::vector<bool> aWanted;
     2713    std::vector<PDMLEDCORE> aLED;
     2714    DeviceType_T maxWanted = (DeviceType_T) 0;
     2715    DeviceType_T enmType;
     2716
     2717    /* Make a roadmap of which DeviceType_T LED types are wanted */
     2718    for (size_t iType = 0; iType < aType.size(); ++iType)
     2719    {
     2720        enmType = aType[iType];
     2721        if (enmType > maxWanted)
     2722        {
     2723            maxWanted = enmType;
     2724            aWanted.resize(maxWanted + 1);
     2725        }
     2726        aWanted[enmType] = true;
     2727    }
     2728    aLED.resize(maxWanted + 1);
     2729
     2730    /* Collect all the LEDs in a single sweep through all drivers' sets */
     2731    for (uint32_t idxSet = 0; idxSet < mcLedSets; ++idxSet)
     2732    {
     2733        /* Look inside this driver's set of LEDs */
     2734        PLEDSET pLS = &maLedSets[idxSet];
     2735
     2736        /* Multi-type drivers (e.g. SCSI) have a subtype array which must be matched. */
     2737        if (pLS->paSubTypes)
     2738        {
     2739            for (uint32_t inSet = 0; inSet < pLS->cLeds; ++inSet)
     2740            {
     2741                enmType = pLS->paSubTypes[inSet];
     2742                if (enmType < maxWanted && aWanted[enmType])
     2743                    aLED[enmType].u32 |= readAndClearLed(pLS->papLeds[inSet]);
     2744            }
     2745        }
     2746        /* Single-type drivers (e.g. floppy) have the type in ->enmType */
     2747        else
     2748        {
     2749            enmType = pLS->enmType;
     2750            if (enmType < maxWanted && aWanted[enmType])
     2751                for (uint32_t inSet = 0; inSet < pLS->cLeds; ++inSet)
     2752                    aLED[enmType].u32 |= readAndClearLed(pLS->papLeds[inSet]);
     2753        }
     2754    }
     2755
    27082756    aActivity.resize(aType.size());
    2709 
    2710     size_t iType;
    2711     for (iType = 0; iType < aType.size(); ++iType)
    2712     {
    2713         /* Get LED array to read */
    2714         PDMLEDCORE SumLed = {0};
    2715         switch (aType[iType])
    2716         {
    2717             case DeviceType_Floppy:
    2718             case DeviceType_DVD:
    2719             case DeviceType_HardDisk:
    2720             {
    2721                 for (unsigned i = 0; i < RT_ELEMENTS(mapStorageLeds); ++i)
    2722                     if (maStorageDevType[i] == aType[iType])
    2723                         SumLed.u32 |= readAndClearLed(mapStorageLeds[i]);
    2724                 break;
    2725             }
    2726 
    2727             case DeviceType_Network:
    2728             {
    2729                 for (unsigned i = 0; i < RT_ELEMENTS(mapNetworkLeds); ++i)
    2730                     SumLed.u32 |= readAndClearLed(mapNetworkLeds[i]);
    2731                 break;
    2732             }
    2733 
    2734             case DeviceType_USB:
    2735             {
    2736                 for (unsigned i = 0; i < RT_ELEMENTS(mapUSBLed); ++i)
    2737                     SumLed.u32 |= readAndClearLed(mapUSBLed[i]);
    2738                 break;
    2739             }
    2740 
    2741             case DeviceType_SharedFolder:
    2742             {
    2743                 SumLed.u32 |= readAndClearLed(mapSharedFolderLed);
    2744                 break;
    2745             }
    2746 
    2747             case DeviceType_Graphics3D:
    2748             {
    2749                 SumLed.u32 |= readAndClearLed(mapCrOglLed);
    2750                 break;
    2751             }
    2752 
    2753             default:
    2754                 return setError(E_INVALIDARG, tr("Invalid device type: %d"), aType[iType]);
    2755         }
    2756 
     2757    for (size_t iType = 0; iType < aActivity.size(); ++iType)
     2758    {
    27572759        /* Compose the result */
    2758         switch (SumLed.u32 & (PDMLED_READING | PDMLED_WRITING))
     2760        switch (aLED[aType[iType]].u32 & (PDMLED_READING | PDMLED_WRITING))
    27592761        {
    27602762            case 0:
     
    1086410866        PPDMLED pLed;
    1086510867        int rc = pThis->pLedPorts->pfnQueryStatusLed(pThis->pLedPorts, iLUN, &pLed);
     10868        /*
     10869         * pLed now points directly to the per-unit struct PDMLED field
     10870         * inside the target device struct owned by the hardware driver.
     10871         */
    1086610872        if (RT_FAILURE(rc))
    1086710873            pLed = NULL;
    1086810874        ASMAtomicWritePtr(&pThis->papLeds[iLUN - pThis->iFirstLUN], pLed);
     10875        /*
     10876         * papLeds[] points to the struct PDMLED of each of this driver's
     10877         * units.  The entries are initialized here, called out of a loop
     10878         * in Console::i_drvStatus_Construct(), which previously called
     10879         * Console::i_attachStatusDriver() to allocate the array itself.
     10880         *
     10881         * The arrays (and thus individual LEDs) are eventually read out
     10882         * by Console::getDeviceActivity(), which is itself called from
     10883         * src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp
     10884         */
    1086910885        Log(("drvStatus_UnitChanged: iLUN=%d pLed=%p\n", iLUN, pLed));
    1087010886    }
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r87374 r87391  
    653653
    654654
    655 void Console::i_attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
    656                                    uint64_t uFirst, uint64_t uLast,
     655/**
     656 * Allocate a set of LEDs.
     657 *
     658 * This grabs a maLedSets entry and populates it with @a cLeds.
     659 *
     660 * @param  cLeds        The number of LEDs in the set.
     661 * @param  enmType      The device type.
     662 * @param  ppSubTypes   When not NULL, subtypes for each LED and return the array pointer here.
     663 * @throws HRESULT or ConfigError on trouble
     664 */
     665Console::PLEDSET Console::i_allocateDriverLeds(uint32_t cLeds, DeviceType_T enmType, DeviceType_T **ppaSubTypes)
     666{
     667    Assert(cLeds > 0);
     668    Assert(cLeds < 1024);  /* Adjust if any driver supports >=1024 units! */
     669
     670    /* Grab a LED set entry before we start allocating anything so the destructor can do the cleanups. */
     671    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Caller should have this already. Need protect mcLedSets check and update. */
     672    AssertStmt(mcLedSets < RT_ELEMENTS(maLedSets),
     673               throw ConfigError("AllocateDriverPapLeds", VERR_OUT_OF_RANGE, "Too many LED sets"));
     674    PLEDSET pLS = &maLedSets[mcLedSets++];
     675    pLS->papLeds = (PPDMLED *)RTMemAllocZ(sizeof(PPDMLED) * cLeds);
     676    AssertStmt(pLS->papLeds, throw E_OUTOFMEMORY);
     677    pLS->cLeds = cLeds;
     678    pLS->enmType = enmType;
     679    pLS->paSubTypes = NULL;
     680
     681    if (ppaSubTypes)
     682    {
     683        *ppaSubTypes = pLS->paSubTypes = (DeviceType_T *)RTMemAlloc(sizeof(DeviceType_T) * cLeds);
     684        AssertStmt(pLS->paSubTypes, throw E_OUTOFMEMORY);
     685        for (size_t idxSub = 0; idxSub < cLeds; ++idxSub)
     686            pLS->paSubTypes[idxSub] = DeviceType_Null;
     687    }
     688
     689    LogRel(("mcLedSets = %d, RT_ELEMENTS(maLedSets) = %d\n", mcLedSets, RT_ELEMENTS(maLedSets)));
     690    return pLS;
     691}
     692
     693
     694/** @todo r=bird: Drop uFirst as it's always zero? Then s/uLast/cLeds/g. */
     695void Console::i_attachStatusDriver(PCFGMNODE pCtlInst, DeviceType_T enmType,
     696                                   uint32_t uFirst, uint32_t uLast,
     697                                   DeviceType_T **ppaSubTypes,
    657698                                   Console::MediumAttachmentMap *pmapMediumAttachments,
    658699                                   const char *pcszDevice, unsigned uInstance)
    659700{
     701    Assert(uFirst <= uLast);
    660702    PCFGMNODE pLunL0, pCfg;
    661703    InsertConfigNode(pCtlInst,  "LUN#999", &pLunL0);
    662704    InsertConfigString(pLunL0,  "Driver",               "MainStatus");
    663705    InsertConfigNode(pLunL0,    "Config", &pCfg);
    664     InsertConfigInteger(pCfg,   "papLeds", (uintptr_t)papLeds);
     706    PLEDSET pLS = i_allocateDriverLeds(uLast - uFirst + 1, enmType, ppaSubTypes);
     707    InsertConfigInteger(pCfg,   "papLeds", (uintptr_t)pLS->papLeds);
    665708    if (pmapMediumAttachments)
    666709    {
     
    19882031                     * Attach the status driver.
    19892032                     */
    1990                     i_attachStatusDriver(pInst, &mapUSBLed[0], 0, 0, NULL, NULL, 0);
     2033                    i_attachStatusDriver(pInst, DeviceType_USB, 0, 0, NULL, NULL, NULL, 0);
    19912034                }
    19922035#ifdef VBOX_WITH_EHCI
     
    20192062                         * Attach the status driver.
    20202063                         */
    2021                         i_attachStatusDriver(pInst, &mapUSBLed[1], 0, 0, NULL, NULL, 0);
     2064                        i_attachStatusDriver(pInst, DeviceType_USB, 0, 0, NULL, NULL, NULL, 0);
    20222065                    }
    20232066# ifdef VBOX_WITH_EXTPACK
     
    20712114                         * Attach the status driver.
    20722115                         */
    2073                         i_attachStatusDriver(pInst, &mapUSBLed[0], 0, 1, NULL, NULL, 0);
     2116                        i_attachStatusDriver(pInst, DeviceType_USB, 0, 1, NULL, NULL, NULL, 0);
    20742117                    }
    20752118# ifdef VBOX_WITH_EXTPACK
     
    22722315
    22732316                    /* Attach the status driver */
    2274                     Assert(cLedScsi >= 16);
    2275                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedScsi], 0, 15,
    2276                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2277                     paLedDevType = &maStorageDevType[iLedScsi];
     2317                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, 15, &paLedDevType,
     2318                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    22782319                    break;
    22792320                }
     
    22962337
    22972338                    /* Attach the status driver */
    2298                     Assert(cLedScsi >= 16);
    2299                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedScsi], 0, 15,
    2300                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2301                     paLedDevType = &maStorageDevType[iLedScsi];
     2339                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, 15, &paLedDevType,
     2340                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    23022341                    break;
    23032342                }
     
    23462385
    23472386                    /* Attach the status driver */
    2348                     AssertRelease(cPorts <= cLedSata);
    2349                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedSata], 0, cPorts - 1,
    2350                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2351                     paLedDevType = &maStorageDevType[iLedSata];
     2387                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, cPorts - 1, &paLedDevType,
     2388                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    23522389                    break;
    23532390                }
     
    23632400                    InsertConfigString(pCfg,   "Type", controllerString(enmCtrlType));
    23642401                    /* Attach the status driver */
    2365                     Assert(cLedIde >= 4);
    2366                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedIde], 0, 3,
    2367                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2368                     paLedDevType = &maStorageDevType[iLedIde];
     2402                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, 3, &paLedDevType,
     2403                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    23692404
    23702405                    /* IDE flavors */
     
    23872422
    23882423                    /* Attach the status driver */
    2389                     Assert(cLedFloppy >= 2);
    2390                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedFloppy], 0, 1,
    2391                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2392                     paLedDevType = &maStorageDevType[iLedFloppy];
     2424                    i_attachStatusDriver(pCtlInst, DeviceType_Floppy, 0, 1, NULL,
     2425                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    23932426                    break;
    23942427                }
     
    24162449
    24172450                    /* Attach the status driver */
    2418                     Assert(cLedSas >= 8);
    2419                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedSas], 0, 7,
    2420                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2421                     paLedDevType = &maStorageDevType[iLedSas];
     2451                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, 7, &paLedDevType,
     2452                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    24222453                    break;
    24232454                }
     
    24522483
    24532484                    /* Attach the status driver */
    2454                     AssertRelease(cPorts <= cLedSata);
    2455                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedNvme], 0, cPorts - 1,
    2456                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2457                     paLedDevType = &maStorageDevType[iLedNvme];
     2485                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, cPorts - 1, NULL,
     2486                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    24582487                    break;
    24592488                }
     
    24692498
    24702499                    /* Attach the status driver */
    2471                     AssertRelease(cPorts <= cLedSata);
    2472                     i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedVirtio], 0, cPorts - 1,
    2473                                        &mapMediumAttachments, pszCtrlDev, ulInstance);
    2474                     paLedDevType = &maStorageDevType[iLedVirtio];
     2500                    i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, cPorts - 1, &paLedDevType,
     2501                                         &mapMediumAttachments, pszCtrlDev, ulInstance);
    24752502                    break;
    24762503                }
     
    27372764             * Attach the status driver.
    27382765             */
    2739             i_attachStatusDriver(pInst, &mapNetworkLeds[uInstance], 0, 0, NULL, NULL, 0);
     2766            i_attachStatusDriver(pInst, DeviceType_Network, 0, 0, NULL, NULL, NULL, 0);
    27402767
    27412768            /*
     
    29122939         * Attach the status driver.
    29132940         */
    2914         i_attachStatusDriver(pInst, &mapSharedFolderLed, 0, 0, NULL, NULL, 0);
     2941        i_attachStatusDriver(pInst, DeviceType_SharedFolder, 0, 0, NULL, NULL, NULL, 0);
    29152942
    29162943        /*
     
    39473974        InsertConfigInteger(pCfg,  "3DEnabled",            f3DEnabled);
    39483975
    3949         i_attachStatusDriver(pInst, &mapCrOglLed, 0, 0, NULL, NULL, 0);
     3976        i_attachStatusDriver(pInst, DeviceType_Graphics3D, 0, 0, NULL, NULL, NULL, 0);
    39503977
    39513978#ifdef VBOX_WITH_VMSVGA
     
    45844611                /** @todo No LED after hotplugging. */
    45854612                /* Attach the status driver */
    4586                 Assert(cLedUsb >= 8);
    4587                 i_attachStatusDriver(pCtlInst, &mapStorageLeds[iLedUsb], 0, 7,
    4588                                    &mapMediumAttachments, pcszDevice, 0);
    4589                 paLedDevType = &maStorageDevType[iLedUsb];
     4613                i_attachStatusDriver(pCtlInst, DeviceType_HardDisk, 0, 7, &paLedDevType,
     4614                                     &mapMediumAttachments, pcszDevice, 0);
    45904615            }
    45914616        }
Note: See TracChangeset for help on using the changeset viewer.

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