VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CPUProfileImpl.cpp@ 109008

Last change on this file since 109008 was 109008, checked in by vboxsync, 4 weeks ago

VMM,Main: Working on ARM CPU profile support, which is neede/useful for getting info about the host CPU as well. The CPUDBENTRY typedef is used externally by Main, so we can't have two definitions of it, so left the bits that are common to both x86 and ARM in CPUDBENTRY and created sub-structures for each of the two targets/platforms. Also started reworking the VBoxCpuReport tool so we can use it on arm as well (much left to do there, though). jiraref:VBP-1598

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: CPUProfileImpl.cpp 109008 2025-04-16 20:59:36Z vboxsync $ */
2/** @file
3 * VirtualBox Main - interface for CPU profiles, VBoxSVC.
4 */
5
6/*
7 * Copyright (C) 2020-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.215389.xyz.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include "CPUProfileImpl.h"
33
34#include <VBox/vmm/cpum.h>
35#include <iprt/x86.h>
36#include "AutoCaller.h"
37
38
39DEFINE_EMPTY_CTOR_DTOR(CPUProfile)
40
41/**
42 * Called by ComObjPtr::createObject when creating the object.
43 *
44 * Just initialize the basic object state, do the rest in initFromDbEntry().
45 *
46 * @returns S_OK.
47 */
48HRESULT CPUProfile::FinalConstruct()
49{
50 m_enmArchitecture = CPUArchitecture_Any;
51 return BaseFinalConstruct();
52}
53
54/**
55 * Initializes the CPU profile from the given CPUM CPU database entry.
56 *
57 * @returns COM status code.
58 * @param a_pDbEntry The CPU database entry.
59 */
60HRESULT CPUProfile::initFromDbEntry(PCCPUMDBENTRY a_pDbEntry) RT_NOEXCEPT
61{
62 AutoInitSpan autoInitSpan(this);
63 AssertReturn(autoInitSpan.isOk(), E_FAIL);
64
65 /*
66 * Initialize our private data.
67 */
68
69 /* Determin x86 or AMD64 by scanning the CPUID leaves for the long mode feature bit: */
70 if (a_pDbEntry->enmEntryType == CPUMDBENTRYTYPE_X86)
71 {
72 m_enmArchitecture = CPUArchitecture_x86;
73 PCCPUMDBENTRYX86 const pDbEntryX86 = (PCCPUMDBENTRYX86)a_pDbEntry;
74 uint32_t iLeaf = pDbEntryX86->cCpuIdLeaves;
75 while (iLeaf-- > 0)
76 if (pDbEntryX86->paCpuIdLeaves[iLeaf].uLeaf <= UINT32_C(0x80000001))
77 {
78 if ( pDbEntryX86->paCpuIdLeaves[iLeaf].uLeaf == UINT32_C(0x80000001)
79 && (pDbEntryX86->paCpuIdLeaves[iLeaf].uEdx & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE))
80 m_enmArchitecture = CPUArchitecture_AMD64;
81 break;
82 }
83 }
84 else if (a_pDbEntry->enmEntryType == CPUMDBENTRYTYPE_ARM)
85 m_enmArchitecture = CPUArchitecture_ARMv8_64;
86
87 HRESULT hrc = m_strName.assignEx(a_pDbEntry->pszName);
88 if (SUCCEEDED(hrc))
89 hrc = m_strFullName.assignEx(a_pDbEntry->pszFullName);
90
91 /*
92 * Update the object state.
93 */
94 if (SUCCEEDED(hrc))
95 autoInitSpan.setSucceeded();
96 else
97 autoInitSpan.setFailed(hrc);
98 return hrc;
99}
100
101/**
102 * COM cruft.
103 */
104void CPUProfile::FinalRelease()
105{
106 uninit();
107 BaseFinalRelease();
108}
109
110/**
111 * Do the actual cleanup.
112 */
113void CPUProfile::uninit()
114{
115 AutoUninitSpan autoUninitSpan(this);
116}
117
118/**
119 * Used by SystemProperties::getCPUProfiles to do matching.
120 */
121bool CPUProfile::i_match(CPUArchitecture_T a_enmArchitecture, CPUArchitecture_T a_enmSecondaryArch,
122 const com::Utf8Str &a_strNamePattern) const RT_NOEXCEPT
123{
124 if ( m_enmArchitecture == a_enmArchitecture
125 || m_enmArchitecture == a_enmSecondaryArch
126 || a_enmArchitecture == CPUArchitecture_Any)
127 {
128 if (a_strNamePattern.isEmpty())
129 return true;
130 return RTStrSimplePatternMatch(a_strNamePattern.c_str(), m_strName.c_str());
131 }
132 return false;
133}
134
135
136HRESULT CPUProfile::getName(com::Utf8Str &aName)
137{
138 return aName.assignEx(m_strName);
139}
140
141HRESULT CPUProfile::getFullName(com::Utf8Str &aFullName)
142{
143 return aFullName.assignEx(m_strFullName);
144}
145
146HRESULT CPUProfile::getArchitecture(CPUArchitecture_T *aArchitecture)
147{
148 *aArchitecture = m_enmArchitecture;
149 return S_OK;
150}
151
152
153/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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