1 | /* $Id: bs3-locking-1.c 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - bs3-locking-1, 16-bit C code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
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 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <bs3kit.h>
|
---|
42 | #include <iprt/asm-amd64-x86.h>
|
---|
43 |
|
---|
44 | #include <VBox/VMMDevTesting.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | /*********************************************************************************************************************************
|
---|
48 | * Global Variables *
|
---|
49 | *********************************************************************************************************************************/
|
---|
50 | static struct
|
---|
51 | {
|
---|
52 | const char * BS3_FAR pszName;
|
---|
53 | uint32_t cInnerLoops;
|
---|
54 | uint32_t uCtrlLo;
|
---|
55 | uint32_t uCtrlHi;
|
---|
56 | } g_aLockingTests[] =
|
---|
57 | {
|
---|
58 | #if 1
|
---|
59 | # if 1 /* no contention benchmark */
|
---|
60 | {
|
---|
61 | "None 0us/inf/0k",
|
---|
62 | _32K,
|
---|
63 | 0,
|
---|
64 | 0,
|
---|
65 | },
|
---|
66 | {
|
---|
67 | "RW None Exl 0us/inf/0k",
|
---|
68 | _32K,
|
---|
69 | 0,
|
---|
70 | 0 | VMMDEV_TESTING_LOCKED_HI_TYPE_RW,
|
---|
71 | },
|
---|
72 | # endif
|
---|
73 | {
|
---|
74 | "RW None Shr 0us/inf/0k",
|
---|
75 | _32K,
|
---|
76 | 0,
|
---|
77 | 0 | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_EMT_SHARED,
|
---|
78 | },
|
---|
79 | # if 1
|
---|
80 | {
|
---|
81 | "Contention 500us/250us/64k",
|
---|
82 | 2000 + 16384,
|
---|
83 | 500 | (UINT32_C(250) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
84 | 64 | VMMDEV_TESTING_LOCKED_HI_ENABLED,
|
---|
85 | },
|
---|
86 | {
|
---|
87 | "Contention 100us/50us/8k",
|
---|
88 | 10000 + 4096,
|
---|
89 | 100 | (UINT32_C(50) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
90 | 8 | VMMDEV_TESTING_LOCKED_HI_ENABLED,
|
---|
91 | },
|
---|
92 | {
|
---|
93 | "Contention 10us/1us/0k",
|
---|
94 | 16384 + 4096,
|
---|
95 | 10 | (UINT32_C(1) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
96 | 0 | VMMDEV_TESTING_LOCKED_HI_ENABLED,
|
---|
97 | },
|
---|
98 | {
|
---|
99 | "Contention 500us/250us/64k poke",
|
---|
100 | 2000 + 16384,
|
---|
101 | 500 | (UINT32_C(250) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
102 | 64 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_POKE,
|
---|
103 | },
|
---|
104 | {
|
---|
105 | "Contention 100us/50us/1k poke",
|
---|
106 | 10000 + 4096,
|
---|
107 | 100 | (UINT32_C(50) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
108 | 1 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_POKE,
|
---|
109 | },
|
---|
110 | {
|
---|
111 | "Contention 500us/250us/64k poke void",
|
---|
112 | 2000 + 16384,
|
---|
113 | 500 | (UINT32_C(250) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
114 | 64 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_POKE | VMMDEV_TESTING_LOCKED_HI_BUSY_SUCCESS
|
---|
115 | },
|
---|
116 | {
|
---|
117 | "Contention 50us/25us/8k poke void",
|
---|
118 | 20000 + 4096,
|
---|
119 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
120 | 1 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_POKE | VMMDEV_TESTING_LOCKED_HI_BUSY_SUCCESS
|
---|
121 | },
|
---|
122 | # endif
|
---|
123 | # if 1
|
---|
124 | {
|
---|
125 | "RW Contention Exl/Exl 50us/25us/16k",
|
---|
126 | 20000 + 4096,
|
---|
127 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
128 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW
|
---|
129 | },
|
---|
130 | # endif
|
---|
131 | {
|
---|
132 | "RW Contention Shr/Exl 50us/25us/16k",
|
---|
133 | 20000 + 4096,
|
---|
134 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
135 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_THREAD_SHARED
|
---|
136 | },
|
---|
137 | # if 1
|
---|
138 | {
|
---|
139 | "RW Contention Exl/Exl 50us/25us/16k poke",
|
---|
140 | 20000 + 4096,
|
---|
141 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
142 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_POKE
|
---|
143 | },
|
---|
144 | # endif
|
---|
145 | {
|
---|
146 | "RW Contention Shr/Exl 50us/25us/16k poke",
|
---|
147 | 20000 + 4096,
|
---|
148 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
149 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_THREAD_SHARED
|
---|
150 | | VMMDEV_TESTING_LOCKED_HI_POKE | VMMDEV_TESTING_LOCKED_HI_BUSY_SUCCESS
|
---|
151 | },
|
---|
152 | # if 1
|
---|
153 | {
|
---|
154 | "RW Contention Exl/Exl 50us/25us/16k poke void",
|
---|
155 | 20000 + 4096,
|
---|
156 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
157 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_POKE
|
---|
158 | },
|
---|
159 | # endif
|
---|
160 | {
|
---|
161 | "RW Contention Shr/Exl 50us/25us/16k poke void",
|
---|
162 | 20000 + 4096,
|
---|
163 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
164 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_THREAD_SHARED
|
---|
165 | | VMMDEV_TESTING_LOCKED_HI_POKE | VMMDEV_TESTING_LOCKED_HI_BUSY_SUCCESS
|
---|
166 | },
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | {
|
---|
170 | "RW Contention Exl/Shr 50us/25us/16k",
|
---|
171 | 20000 + 4096,
|
---|
172 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
173 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_EMT_SHARED
|
---|
174 | },
|
---|
175 | {
|
---|
176 | "RW Contention Exl/Shr poke 250us/25us/16k",
|
---|
177 | 10000 + 4096,
|
---|
178 | 250 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
179 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_EMT_SHARED
|
---|
180 | | VMMDEV_TESTING_LOCKED_HI_POKE
|
---|
181 | },
|
---|
182 | {
|
---|
183 | "RW Contention Exl/Shr poke void 250us/25us/16k",
|
---|
184 | 10000 + 4096,
|
---|
185 | 250 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
186 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW | VMMDEV_TESTING_LOCKED_HI_EMT_SHARED
|
---|
187 | | VMMDEV_TESTING_LOCKED_HI_POKE | VMMDEV_TESTING_LOCKED_HI_BUSY_SUCCESS
|
---|
188 | },
|
---|
189 | {
|
---|
190 | "RW None Shr/Shr 50us/25us/16k",
|
---|
191 | 20000 + 4096,
|
---|
192 | 50 | (UINT32_C(25) << VMMDEV_TESTING_LOCKED_LO_WAIT_SHIFT),
|
---|
193 | 16 | VMMDEV_TESTING_LOCKED_HI_ENABLED | VMMDEV_TESTING_LOCKED_HI_TYPE_RW
|
---|
194 | | VMMDEV_TESTING_LOCKED_HI_THREAD_SHARED | VMMDEV_TESTING_LOCKED_HI_EMT_SHARED
|
---|
195 | },
|
---|
196 | };
|
---|
197 |
|
---|
198 |
|
---|
199 | BS3_DECL(void) Main_rm()
|
---|
200 | {
|
---|
201 | uint64_t const cNsPerTest = RT_NS_15SEC;
|
---|
202 | unsigned i;
|
---|
203 |
|
---|
204 | Bs3InitAll_rm();
|
---|
205 | Bs3TestInit("bs3-locking-1");
|
---|
206 |
|
---|
207 | /*
|
---|
208 | * Since this is a host-side test and we don't have raw-mode any more, we
|
---|
209 | * just stay in raw-mode when doing the test.
|
---|
210 | */
|
---|
211 | for (i = 0; i < RT_ELEMENTS(g_aLockingTests); i++)
|
---|
212 | {
|
---|
213 | uint64_t const nsStart = Bs3TestNow();
|
---|
214 | uint64_t cNsElapsed = 0;
|
---|
215 | uint32_t cTotal = 0;
|
---|
216 | uint32_t j;
|
---|
217 |
|
---|
218 | Bs3TestSub(g_aLockingTests[i].pszName);
|
---|
219 | ASMOutU32(VMMDEV_TESTING_IOPORT_LOCKED_LO, g_aLockingTests[i].uCtrlLo);
|
---|
220 | ASMOutU32(VMMDEV_TESTING_IOPORT_LOCKED_HI, g_aLockingTests[i].uCtrlHi);
|
---|
221 |
|
---|
222 | for (j = 0; j < _2M && cTotal < _1G; j++)
|
---|
223 | {
|
---|
224 |
|
---|
225 | /* The inner loop should avoid calling Bs3TestNow too often, while not overshooting the . */
|
---|
226 | unsigned iInner = (unsigned)g_aLockingTests[i].cInnerLoops;
|
---|
227 | cTotal += iInner;
|
---|
228 | while (iInner-- > 0)
|
---|
229 | ASMInU32(VMMDEV_TESTING_IOPORT_LOCKED_LO);
|
---|
230 |
|
---|
231 | cNsElapsed = Bs3TestNow() - nsStart;
|
---|
232 | if (cNsElapsed >= cNsPerTest)
|
---|
233 | break;
|
---|
234 | }
|
---|
235 |
|
---|
236 | /* Disable locking. */
|
---|
237 | ASMOutU32(VMMDEV_TESTING_IOPORT_LOCKED_HI, 0);
|
---|
238 |
|
---|
239 | Bs3TestValue("Loops", cTotal, VMMDEV_TESTING_UNIT_OCCURRENCES);
|
---|
240 | Bs3TestValue("Elapsed", cNsElapsed, VMMDEV_TESTING_UNIT_NS);
|
---|
241 | Bs3TestValue("PerLoop", cNsElapsed / cTotal, VMMDEV_TESTING_UNIT_NS_PER_OCCURRENCE);
|
---|
242 | }
|
---|
243 |
|
---|
244 | Bs3TestTerm();
|
---|
245 | }
|
---|
246 |
|
---|