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