VirtualBox

source: vbox/trunk/include/VBox/vmm/vmcpuset.h@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 17 months 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.8 KB
Line 
1/** @file
2 * VirtualBox - VMCPUSET Operation.
3 */
4
5/*
6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef VBOX_INCLUDED_vmm_vmcpuset_h
37#define VBOX_INCLUDED_vmm_vmcpuset_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <VBox/types.h>
43#include <iprt/asm.h>
44#include <iprt/string.h>
45
46/** @defgroup grp_vmcpuset VMCPUSET Operations
47 * @ingroup grp_types_both
48 * @sa VMCPUSET
49 * @{
50 */
51
52/** Tests if a valid CPU ID is present in the set. */
53#define VMCPUSET_IS_PRESENT(pSet, idCpu) ASMBitTest( &(pSet)->au32Bitmap[0], (idCpu))
54/** Adds a CPU to the set. */
55#define VMCPUSET_ADD(pSet, idCpu) ASMBitSet( &(pSet)->au32Bitmap[0], (idCpu))
56/** Deletes a CPU from the set. */
57#define VMCPUSET_DEL(pSet, idCpu) ASMBitClear(&(pSet)->au32Bitmap[0], (idCpu))
58/** Adds a CPU to the set, atomically. */
59#define VMCPUSET_ATOMIC_ADD(pSet, idCpu) ASMAtomicBitSet( &(pSet)->au32Bitmap[0], (idCpu))
60/** Deletes a CPU from the set, atomically. */
61#define VMCPUSET_ATOMIC_DEL(pSet, idCpu) ASMAtomicBitClear(&(pSet)->au32Bitmap[0], (idCpu))
62/** Empties the set. */
63#define VMCPUSET_EMPTY(pSet) memset(&(pSet)->au32Bitmap[0], '\0', sizeof((pSet)->au32Bitmap))
64/** Fills the set. */
65#define VMCPUSET_FILL(pSet) memset(&(pSet)->au32Bitmap[0], 0xff, sizeof((pSet)->au32Bitmap))
66/** Checks if two sets are equal to one another. */
67#define VMCPUSET_IS_EQUAL(pSet1, pSet2) (memcmp(&(pSet1)->au32Bitmap[0], &(pSet2)->au32Bitmap[0], sizeof((pSet1)->au32Bitmap)) == 0)
68/** Checks if the set is empty. */
69#define VMCPUSET_IS_EMPTY(a_pSet) ( (a_pSet)->au32Bitmap[0] == 0 \
70 && (a_pSet)->au32Bitmap[1] == 0 \
71 && (a_pSet)->au32Bitmap[2] == 0 \
72 && (a_pSet)->au32Bitmap[3] == 0 \
73 && (a_pSet)->au32Bitmap[4] == 0 \
74 && (a_pSet)->au32Bitmap[5] == 0 \
75 && (a_pSet)->au32Bitmap[6] == 0 \
76 && (a_pSet)->au32Bitmap[7] == 0 \
77 )
78/** Finds the first CPU present in the SET.
79 * @returns CPU index if found, NIL_VMCPUID if not. */
80#define VMCPUSET_FIND_FIRST_PRESENT(a_pSet) VMCpuSetFindFirstPresentInternal(a_pSet)
81
82/** Implements VMCPUSET_FIND_FIRST_PRESENT.
83 *
84 * @returns CPU index of the first CPU present in the set, NIL_VMCPUID if none
85 * are present.
86 * @param pSet The set to scan.
87 */
88DECLINLINE(int32_t) VMCpuSetFindFirstPresentInternal(PCVMCPUSET pSet)
89{
90 int i = ASMBitFirstSet(&pSet->au32Bitmap[0], RT_ELEMENTS(pSet->au32Bitmap) * 32);
91 return i >= 0 ? (VMCPUID)i : NIL_VMCPUID;
92}
93
94/** Finds the first CPU present in the SET.
95 * @returns CPU index if found, NIL_VMCPUID if not. */
96#define VMCPUSET_FIND_LAST_PRESENT(a_pSet) VMCpuSetFindLastPresentInternal(a_pSet)
97
98/** Implements VMCPUSET_FIND_LAST_PRESENT.
99 *
100 * @returns CPU index of the last CPU present in the set, NIL_VMCPUID if none
101 * are present.
102 * @param pSet The set to scan.
103 */
104DECLINLINE(int32_t) VMCpuSetFindLastPresentInternal(PCVMCPUSET pSet)
105{
106 uint32_t i = RT_ELEMENTS(pSet->au32Bitmap);
107 while (i-- > 0)
108 {
109 uint32_t u = pSet->au32Bitmap[i];
110 if (u)
111 {
112 u = ASMBitLastSetU32(u);
113 u--;
114 u |= i << 5;
115 return u;
116 }
117 }
118 return NIL_VMCPUID;
119}
120
121/** @} */
122
123#endif /* !VBOX_INCLUDED_vmm_vmcpuset_h */
124
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use