VirtualBox

Changeset 36041 in vbox for trunk/src/VBox/VMM/VMMR3


Ignore:
Timestamp:
Feb 21, 2011 4:04:53 PM (14 years ago)
Author:
vboxsync
Message:

Main/VMM: Use UVM w/ refcounting - part 1.

Location:
trunk/src/VBox/VMM/VMMR3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/PDM.cpp

    r35787 r36041  
    20872087    LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n",
    20882088             pszDevice, pszDevice, iInstance, iLun, ppBase));
     2089    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
    20892090
    20902091    /*
  • trunk/src/VBox/VMM/VMMR3/VM.cpp

    r35810 r36041  
    8181#include <iprt/semaphore.h>
    8282#include <iprt/thread.h>
     83#include <iprt/uuid.h>
    8384
    8485
     
    461462    AssertCompile(sizeof(pUVM->vm.s) <= sizeof(pUVM->vm.padding));
    462463
     464    pUVM->vm.s.cUvmRefs      = 1;
    463465    pUVM->vm.s.ppAtStateNext = &pUVM->vm.s.pAtState;
    464466    pUVM->vm.s.ppAtErrorNext = &pUVM->vm.s.pAtError;
     
    466468
    467469    pUVM->vm.s.enmHaltMethod = VMHALTMETHOD_BOOTSTRAP;
     470    RTUuidClear(&pUVM->vm.s.Uuid);
    468471
    469472    /* Initialize the VMCPU array in the UVM. */
     
    563566static int vmR3CreateU(PUVM pUVM, uint32_t cCpus, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM)
    564567{
    565     int rc = VINF_SUCCESS;
    566 
    567568    /*
    568569     * Load the VMMR0.r0 module so that we can call GVMMR0CreateVM.
    569570     */
    570     rc = PDMR3LdrLoadVMMR0U(pUVM);
     571    int rc = PDMR3LdrLoadVMMR0U(pUVM);
    571572    if (RT_FAILURE(rc))
    572573    {
     
    657658                }
    658659            }
     660
     661            /*
     662             * Get the CPU execution cap.
     663             */
    659664            if (RT_SUCCESS(rc))
    660665            {
    661666                rc = CFGMR3QueryU32Def(pRoot, "CpuExecutionCap", &pVM->uCpuExecutionCap, 100);
    662667                AssertLogRelMsgRC(rc, ("Configuration error: Querying \"CpuExecutionCap\" as integer failed, rc=%Rrc\n", rc));
    663 
     668            }
     669
     670            /*
     671             * Get the VM name and UUID.
     672             */
     673            if (RT_SUCCESS(rc))
     674            {
     675                rc = CFGMR3QueryStringAllocDef(pRoot, "Name", &pUVM->vm.s.pszName, "<unknown>");
     676                AssertLogRelMsg(RT_SUCCESS(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND, ("Configuration error: Querying \"Name\" failed, rc=%Rrc\n", rc));
     677            }
     678
     679            if (RT_SUCCESS(rc))
     680            {
     681                rc = CFGMR3QueryBytes(pRoot, "UUID", &pUVM->vm.s.Uuid, sizeof(pUVM->vm.s.Uuid));
     682                AssertLogRelMsg(RT_SUCCESS(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND, ("Configuration error: Querying \"UUID\" failed, rc=%Rrc\n", rc));
     683            }
     684
     685            if (RT_SUCCESS(rc))
     686            {
    664687                /*
    665688                 * Init the ring-3 components and ring-3 per cpu data, finishing it off
     
    22632286     */
    22642287    if (!pVM)
    2265         return VERR_INVALID_PARAMETER;
     2288        return VERR_INVALID_VM_HANDLE;
    22662289    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
    22672290    AssertLogRelReturn(!VM_IS_EMT(pVM), VERR_VM_THREAD_IS_EMT);
     
    25412564
    25422565    /*
    2543      * Destroy the MM heap and free the UVM structure.
    2544      */
    2545     MMR3TermUVM(pUVM);
    2546     STAMR3TermUVM(pUVM);
    2547 
     2566     * Release the UVM structure reference.
     2567     */
     2568    VMR3ReleaseUVM(pUVM);
     2569
     2570    /*
     2571     * Clean up and flush logs.
     2572     */
    25482573#ifdef LOG_ENABLED
    25492574    RTLogSetCustomPrefixCallback(NULL, NULL, NULL);
    25502575#endif
    2551     RTTlsFree(pUVM->vm.s.idxTLS);
    2552 
    2553     ASMAtomicUoWriteU32(&pUVM->u32Magic, UINT32_MAX);
    2554     RTMemPageFree(pUVM, RT_OFFSETOF(UVM, aCpus[pUVM->cCpus]));
    2555 
    25562576    RTLogFlush(NULL);
    25572577}
     
    28522872
    28532873/**
     2874 * Gets the user mode VM structure pointer given the VM handle.
     2875 *
     2876 * @returns Pointer to the user mode VM structure on success. NULL if @a pVM is
     2877 *          invalid (asserted).
     2878 * @param   pVM                 The VM handle.
     2879 * @sa      VMR3GetVM, VMR3RetainUVM
     2880 */
     2881VMMR3DECL(PUVM) VMR3GetUVM(PVM pVM)
     2882{
     2883    VM_ASSERT_VALID_EXT_RETURN(pVM, NULL);
     2884    return pVM->pUVM;
     2885}
     2886
     2887
     2888/**
     2889 * Gets the shared VM structure pointer given the pointer to the user mode VM
     2890 * structure.
     2891 *
     2892 * @returns Pointer to the shared VM structure.
     2893 *          NULL if @a pUVM is invalid (asserted) or if no shared VM structure
     2894 *          is currently associated with it.
     2895 * @param   pUVM                The user mode VM handle.
     2896 * @sa      VMR3GetUVM
     2897 */
     2898VMMR3DECL(PVM) VMR3GetVM(PUVM pUVM)
     2899{
     2900    UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
     2901    return pUVM->pVM;
     2902}
     2903
     2904
     2905/**
     2906 * Retain the user mode VM handle.
     2907 *
     2908 * @returns Reference count.
     2909 *          UINT32_MAX if @a pUVM is invalid.
     2910 *
     2911 * @param   pUVM                The user mode VM handle.
     2912 * @sa      VMR3ReleaseUVM
     2913 */
     2914VMMR3DECL(uint32_t) VMR3RetainUVM(PUVM pUVM)
     2915{
     2916    UVM_ASSERT_VALID_EXT_RETURN(pUVM, UINT32_MAX);
     2917    uint32_t cRefs = ASMAtomicIncU32(&pUVM->vm.s.cUvmRefs);
     2918    AssertMsg(cRefs > 0 && cRefs < _64K, ("%u\n", cRefs));
     2919    return cRefs;
     2920}
     2921
     2922
     2923/**
     2924 * Does the final release of the UVM structure.
     2925 *
     2926 * @param   pUVM                The user mode VM handle.
     2927 */
     2928static void vmR3DoReleaseUVM(PUVM pUVM)
     2929{
     2930    /*
     2931     * Free the UVM.
     2932     */
     2933    Assert(!pUVM->pVM);
     2934
     2935    MMR3TermUVM(pUVM);
     2936    STAMR3TermUVM(pUVM);
     2937
     2938    ASMAtomicUoWriteU32(&pUVM->u32Magic, UINT32_MAX);
     2939    RTTlsFree(pUVM->vm.s.idxTLS);
     2940    RTMemPageFree(pUVM, RT_OFFSETOF(UVM, aCpus[pUVM->cCpus]));
     2941}
     2942
     2943
     2944/**
     2945 * Releases a refernece to the mode VM handle.
     2946 *
     2947 * @returns The new reference count, 0 if destroyed.
     2948 *          UINT32_MAX if @a pUVM is invalid.
     2949 *
     2950 * @param   pUVM                The user mode VM handle.
     2951 * @sa      VMR3RetainUVM
     2952 */
     2953VMMR3DECL(uint32_t) VMR3ReleaseUVM(PUVM pUVM)
     2954{
     2955    if (!pUVM)
     2956        return 0;
     2957    UVM_ASSERT_VALID_EXT_RETURN(pUVM, UINT32_MAX);
     2958    uint32_t cRefs = ASMAtomicDecU32(&pUVM->vm.s.cUvmRefs);
     2959    if (!cRefs)
     2960        vmR3DoReleaseUVM(pUVM);
     2961    else
     2962        AssertMsg(cRefs < _64K, ("%u\n", cRefs));
     2963    return cRefs;
     2964}
     2965
     2966
     2967/**
     2968 * Gets the VM name.
     2969 *
     2970 * @returns Pointer to a read-only string containing the name. NULL if called
     2971 *          too early.
     2972 * @param   pUVM                The user mode VM handle.
     2973 */
     2974VMMR3DECL(const char *) VMR3GetName(PUVM pUVM)
     2975{
     2976    UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
     2977    return pUVM->vm.s.pszName;
     2978}
     2979
     2980
     2981/**
     2982 * Gets the VM UUID.
     2983 *
     2984 * @returns pUuid on success, NULL on failure.
     2985 * @param   pUVM                The user mode VM handle.
     2986 * @param   pUuid               Where to store the UUID.
     2987 */
     2988VMMR3DECL(PRTUUID) VMR3GetUuid(PUVM pUVM, PRTUUID pUuid)
     2989{
     2990    UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
     2991    AssertPtrReturn(pUuid, NULL);
     2992
     2993    *pUuid = pUVM->vm.s.Uuid;
     2994    return pUuid;
     2995}
     2996
     2997
     2998/**
    28542999 * Gets the current VM state.
    28553000 *
     
    28603005VMMR3DECL(VMSTATE) VMR3GetState(PVM pVM)
    28613006{
     3007    VM_ASSERT_VALID_EXT_RETURN(pVM, VMSTATE_TERMINATED);
    28623008    return pVM->enmVMState;
     3009}
     3010
     3011
     3012/**
     3013 * Gets the current VM state.
     3014 *
     3015 * @returns The current VM state.
     3016 * @param   pUVM            The user-mode VM handle.
     3017 * @thread  Any
     3018 */
     3019VMMR3DECL(VMSTATE) VMR3GetStateU(PUVM pUVM)
     3020{
     3021    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VMSTATE_TERMINATED);
     3022    if (RT_UNLIKELY(!pUVM->pVM))
     3023        return VMSTATE_TERMINATED;
     3024    return pUVM->pVM->enmVMState;
    28633025}
    28643026
     
    34593621VMMR3DECL(int)   VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser)
    34603622{
     3623    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
    34613624    return VMR3AtErrorRegisterU(pVM->pUVM, pfnAtError, pvUser);
    34623625}
     
    41694332VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
    41704333{
     4334    /*
     4335     * Validate input.
     4336     */
     4337    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     4338    AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER);
     4339    AssertPtrReturn(pidCpuPackage, VERR_INVALID_POINTER);
    41714340    if (idCpu >= pVM->cCpus)
    41724341        return VERR_INVALID_CPU_ID;
    41734342
     4343    /*
     4344     * Set return values.
     4345     */
    41744346#ifdef VBOX_WITH_MULTI_CORE
    41754347    *pidCpuCore    = idCpu;
     
    42234395VMMR3DECL(int) VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu)
    42244396{
     4397    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
    42254398    AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
    42264399
     
    42424415VMMR3DECL(int) VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu)
    42434416{
     4417    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
    42444418    AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
    42454419
     
    42544428 * @returns VBox status code.
    42554429 * @param   pVM                 The VM to operate on.
    4256  * @param   ulCpuExecutionCap   New CPU execution cap
    4257  */
    4258 VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, unsigned ulCpuExecutionCap)
    4259 {
    4260     AssertReturn(ulCpuExecutionCap > 0 && ulCpuExecutionCap <= 100, VERR_INVALID_PARAMETER);
    4261 
    4262     Log(("VMR3SetCpuExecutionCap: new priority = %d\n", ulCpuExecutionCap));
     4430 * @param   uCpuExecutionCap    New CPU execution cap in precent, 1-100. Where
     4431 *                              100 is max performance (default).
     4432 */
     4433VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, uint32_t uCpuExecutionCap)
     4434{
     4435    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     4436    AssertReturn(uCpuExecutionCap > 0 && uCpuExecutionCap <= 100, VERR_INVALID_PARAMETER);
     4437
     4438    Log(("VMR3SetCpuExecutionCap: new priority = %d\n", uCpuExecutionCap));
    42634439    /* Note: not called from EMT. */
    4264     pVM->uCpuExecutionCap = ulCpuExecutionCap;
     4440    pVM->uCpuExecutionCap = uCpuExecutionCap;
    42654441    return VINF_SUCCESS;
    42664442}
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