VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-timing-1-32.c32@ 89146

Last change on this file since 89146 was 89142, checked in by vboxsync, 4 years ago

ValKit/bootsectors: Added a rough outline for a TSC timing test. bugref:10009

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: bs3-timing-1-32.c32 89142 2021-05-18 14:33:03Z vboxsync $ */
2/** @file
3 * BS3Kit - bs3-timinig-1, 32-bit C code.
4 */
5
6/*
7 * Copyright (C) 2007-2021 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#include <iprt/asm-math.h>
34
35
36static void bs3Timing1_Tsc_One(void)
37{
38 uint64_t const nsStart = Bs3TestNow();
39 uint64_t const uTscStart = ASMReadTSC();
40 uint64_t const nsDeadline = nsStart + RT_NS_10SEC;
41 uint64_t cNsElapsed;
42 uint64_t cTicksElapsed;
43 uint64_t cTicksMin = UINT64_MAX;
44 uint64_t cTicksMax = 0;
45 uint64_t cTicksSum = 0;
46 uint64_t cBelow512 = 0;
47 uint64_t cBelow1K = 0;
48 uint64_t cBelow4K = 0;
49 uint64_t cAbove512K = 0;
50 uint64_t cAbove1M = 0;
51 uint64_t cAbove10M = 0;
52 uint64_t cTotalLoops = 0;
53
54 /*
55 * Test loop.
56 */
57 do
58 {
59 unsigned cLoops = 100000 + 1;
60 cTotalLoops += cLoops - 1;
61 while (--cLoops != 0)
62 {
63 uint64_t uTscPrev = ASMReadTSC();
64 uint64_t uTscNow = ASMReadTSC();
65 uint64_t cTicks = uTscNow - uTscPrev;
66
67 /* min/max/avg */
68 cTicksSum += cTicks;
69 if (cTicks < cTicksMin)
70 cTicksMin = cTicks;
71 if (cTicks > cTicksMax)
72 cTicksMax = cTicks;
73
74 /* range. */
75 if (cTicks < _4K)
76 {
77 cBelow4K++;
78 if (cTicks < _1K)
79 {
80 cBelow1K++;
81 if (cTicks < 512)
82 cBelow512++;
83 }
84 }
85 else if (cTicks >= _512K)
86 {
87 cAbove512K++;
88 if (cTicks >= _1M)
89 {
90 cAbove1M++;
91 if (cTicks >= 10*_1M)
92 cAbove10M++;
93 }
94 }
95 }
96 } while ((cNsElapsed = Bs3TestNow()) < nsDeadline);
97 cTicksElapsed = ASMReadTSC();
98 cTicksElapsed -= uTscStart;
99 cNsElapsed -= nsStart;
100
101 /*
102 * Report results.
103 *
104 * Note! in 32-bit and 16-bit mode, values 4G or higher gets formatted as
105 * hexadecimal to avoid 64-bit division.
106 */
107
108 Bs3TestPrintf("%'14RU64 loops in %'RU64 ns / %'RU64 ticks\n", cTotalLoops, cNsElapsed, cTicksElapsed);
109
110 /* Report results in ticks. */
111 Bs3TestPrintf("average %RU64 ticks, min %'RU64, max %'RU64\n",
112 cTicksSum / cTotalLoops, cTicksMin, cTicksMax);
113 Bs3TestPrintf("%'14RU64 below 512\n", cBelow512);
114 Bs3TestPrintf("%'14RU64 below 1K\n", cBelow1K);
115 Bs3TestPrintf("%'14RU64 below 4K\n", cBelow4K);
116 Bs3TestPrintf("%'14RU64 inbetween\n", cTotalLoops - cBelow4K - cAbove512K);
117 Bs3TestPrintf("%'14RU64 above 512K\n", cAbove512K);
118 Bs3TestPrintf("%'14RU64 above 1M\n", cAbove1M);
119 Bs3TestPrintf("%'14RU64 above 10M\n", cAbove10M);
120
121 /* results in nanoseconds */
122 if (cNsElapsed && cTicksElapsed)
123 {
124 /* Missing ??U8M and the assembly bugger. */
125 //uint64_t const uFreq = ASMMultU64ByU32DivByU32(cTicksElapsed, RT_NS_1SEC, cNsElapsed);
126 //uint64_t const uFreq = cTicksElapsed * (uint64_t)RT_NS_1SEC / cNsElapsed;
127 uint64_t const uFreq = cTicksElapsed / cNsElapsed;
128 Bs3TestPrintf("%RU64 Hz\n", uFreq);
129 }
130}
131
132BS3_DECL(void) bs3Timing1_Tsc_pe32(void)
133{
134 Bs3TestPrintf("bs3Timing1_Tsc_pe32\n");
135 bs3Timing1_Tsc_One();
136}
137
138/* P.S. don't forget: VBoxManage setextradata bs3-timing-1 VBoxInternal/Devices/VMMDev/0/Config/TestingEnabled 1 */
139
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