VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibCpuHotPlug.cpp@ 85271

Last change on this file since 85271 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: VBoxGuestR3LibCpuHotPlug.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, CPU Hot Plugging.
4 */
5
6/*
7 * Copyright (C) 2010-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "VBoxGuestR3LibInternal.h"
32#include <iprt/assert.h>
33#include <iprt/errcore.h>
34
35
36/**
37 * Initialize CPU hot plugging.
38 *
39 * This will enable the CPU hot plugging events.
40 *
41 * @returns VBox status code.
42 */
43VBGLR3DECL(int) VbglR3CpuHotPlugInit(void)
44{
45 int rc = VbglR3CtlFilterMask(VMMDEV_EVENT_CPU_HOTPLUG, 0);
46 if (RT_FAILURE(rc))
47 return rc;
48
49 VMMDevCpuHotPlugStatusRequest Req;
50 vmmdevInitRequest(&Req.header, VMMDevReq_SetCpuHotPlugStatus);
51 Req.enmStatusType = VMMDevCpuStatusType_Enable;
52 rc = vbglR3GRPerform(&Req.header);
53 if (RT_FAILURE(rc))
54 VbglR3CtlFilterMask(0, VMMDEV_EVENT_CPU_HOTPLUG);
55
56 return rc;
57}
58
59
60/**
61 * Terminate CPU hot plugging.
62 *
63 * This will disable the CPU hot plugging events.
64 *
65 * @returns VBox status code.
66 */
67VBGLR3DECL(int) VbglR3CpuHotPlugTerm(void)
68{
69 /* Clear the events. */
70 VbglR3CtlFilterMask(0, VMMDEV_EVENT_CPU_HOTPLUG);
71
72 VMMDevCpuHotPlugStatusRequest Req;
73 vmmdevInitRequest(&Req.header, VMMDevReq_SetCpuHotPlugStatus);
74 Req.enmStatusType = VMMDevCpuStatusType_Disable;
75 return vbglR3GRPerform(&Req.header);
76}
77
78
79/**
80 * Waits for a CPU hot plugging event and retrieve the data associated with it.
81 *
82 * @returns VBox status code.
83 * @param penmEventType Where to store the event type on success.
84 * @param pidCpuCore Where to store the CPU core ID on success.
85 * @param pidCpuPackage Where to store the CPU package ID on success.
86 */
87VBGLR3DECL(int) VbglR3CpuHotPlugWaitForEvent(VMMDevCpuEventType *penmEventType, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
88{
89 AssertPtrReturn(penmEventType, VERR_INVALID_POINTER);
90 AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER);
91 AssertPtrReturn(pidCpuPackage, VERR_INVALID_POINTER);
92
93 uint32_t fEvents = 0;
94 int rc = VbglR3WaitEvent(VMMDEV_EVENT_CPU_HOTPLUG, RT_INDEFINITE_WAIT, &fEvents);
95 if (RT_SUCCESS(rc))
96 {
97 /* did we get the right event? */
98 if (fEvents & VMMDEV_EVENT_CPU_HOTPLUG)
99 {
100 VMMDevGetCpuHotPlugRequest Req;
101
102 /* get the CPU hot plugging request */
103 vmmdevInitRequest(&Req.header, VMMDevReq_GetCpuHotPlugRequest);
104 Req.idCpuCore = UINT32_MAX;
105 Req.idCpuPackage = UINT32_MAX;
106 Req.enmEventType = VMMDevCpuEventType_None;
107 rc = vbglR3GRPerform(&Req.header);
108 if (RT_SUCCESS(rc))
109 {
110 *penmEventType = Req.enmEventType;
111 *pidCpuCore = Req.idCpuCore;
112 *pidCpuPackage = Req.idCpuPackage;
113 return VINF_SUCCESS;
114 }
115 }
116 else
117 rc = VERR_TRY_AGAIN;
118 }
119 else if (rc == VERR_TIMEOUT) /* just in case */
120 rc = VERR_TRY_AGAIN;
121 return rc;
122}
123
Note: See TracBrowser for help on using the repository browser.

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