1- #include "main/host /tsc.h"
1+ #include "lib/tsc /tsc.h"
22
33#include <assert.h>
44#include <cpuid.h>
55#include <errno.h>
66#include <inttypes.h>
7- #include <string.h>
87#include <stdio.h>
8+ #include <string.h>
99#include <time.h>
1010#include <unistd.h>
1111#include <x86intrin.h>
1616#define rdtscp __rdtscp
1717
1818Tsc Tsc_measure () {
19- unsigned int a = 0 , b = 0 , c = 0 , d = 0 ;
19+ unsigned int a = 0 , b = 0 , c = 0 , d = 0 ;
2020 // Use the cpuid instruction (wrapped by __get_cpuid) to determine the clock
2121 // frequency. See "cpuid" in "Intel® 64 and IA-32 Architectures Software
2222 // Developer’s Manual Volume 2A".
@@ -36,7 +36,7 @@ Tsc Tsc_measure() {
3636 panic ("cpuid 0x15 unsupported; can't get tsc frequency" );
3737 }
3838
39- // cpuid 0x15 gives us
39+ // cpuid 0x15 gives us
4040 if (!__get_cpuid (0x15 , & a , & b , & c , & d )) {
4141 panic ("cpuid" );
4242 }
@@ -56,7 +56,7 @@ Tsc Tsc_measure() {
5656 // core crystal clock in Hz."
5757 unsigned int core = c ;
5858 if (core ) {
59- Tsc tsc = {(uint64_t )c * b / a };
59+ Tsc tsc = {(uint64_t )c * b / a };
6060 debug ("Calculated %" PRIu64 " cyclesPerSecond via cpuid 15h" , tsc .cyclesPerSecond );
6161 return tsc ;
6262 }
@@ -69,7 +69,7 @@ Tsc Tsc_measure() {
6969 // gives a 2 row table for this case:
7070
7171 // 6th and 7th generation Intel® Core™ processors -> 24 MHz
72- //
72+ //
7373 // Next Generation Intel® Atom™ processors based on Goldmont
7474 // Microarchitecture with CPUID signature 06_5CH -> 19.2 MHz.
7575 //
@@ -89,7 +89,7 @@ Tsc Tsc_measure() {
8989 return tsc ;
9090 }
9191#endif
92-
92+
9393 if (!__get_cpuid (0x80000000 , & a , & b , & c , & d )) {
9494 panic ("cpuid" );
9595 }
@@ -100,7 +100,7 @@ Tsc Tsc_measure() {
100100 }
101101 union {
102102 uint32_t ints [3 ][4 ];
103- char chars [12 * 4 ];
103+ char chars [12 * 4 ];
104104 } brand_string ;
105105 for (int i = 0 ; i < 3 ; ++ i ) {
106106 if (!__get_cpuid (0x80000002 + i , & a , & b , & c , & d )) {
@@ -112,7 +112,7 @@ Tsc Tsc_measure() {
112112 brand_string .ints [i ][3 ] = d ;
113113 }
114114 // Guaranteed to be null terminated.
115- assert (brand_string .chars [sizeof (brand_string )- 1 ] == '\0' );
115+ assert (brand_string .chars [sizeof (brand_string ) - 1 ] == '\0' );
116116
117117 trace ("Got brand string %s" , brand_string .chars );
118118
@@ -139,28 +139,25 @@ Tsc Tsc_measure() {
139139 panic ("Unrecognized scale character %c" , scale_c );
140140 }
141141
142- Tsc tsc = {frequency * scale };
142+ Tsc tsc = {frequency * scale };
143143 debug ("Calculated %" PRIu64 " cyclesPerSecond via brand string" , tsc .cyclesPerSecond );
144144 return tsc ;
145145}
146146
147- static void _Tsc_setRdtscCycles (const Tsc * tsc , struct user_regs_struct * regs ,
148- uint64_t nanos ) {
147+ static void _Tsc_setRdtscCycles (const Tsc * tsc , struct user_regs_struct * regs , uint64_t nanos ) {
149148 // Guaranteed not to overflow since the operands are both 64 bit.
150- __uint128_t gigaCycles = (__uint128_t )tsc -> cyclesPerSecond * nanos ;
149+ __uint128_t gigaCycles = (__uint128_t )tsc -> cyclesPerSecond * nanos ;
151150 uint64_t cycles = gigaCycles / 1000000000 ;
152151 regs -> rdx = (cycles >> 32 ) & 0xffffffff ;
153152 regs -> rax = cycles & 0xffffffff ;
154153}
155154
156- void Tsc_emulateRdtsc (const Tsc * tsc , struct user_regs_struct * regs ,
157- uint64_t nanos ) {
155+ void Tsc_emulateRdtsc (const Tsc * tsc , struct user_regs_struct * regs , uint64_t nanos ) {
158156 _Tsc_setRdtscCycles (tsc , regs , nanos );
159157 regs -> rip += 2 ;
160158}
161159
162- void Tsc_emulateRdtscp (const Tsc * tsc , struct user_regs_struct * regs ,
163- uint64_t nanos ) {
160+ void Tsc_emulateRdtscp (const Tsc * tsc , struct user_regs_struct * regs , uint64_t nanos ) {
164161 _Tsc_setRdtscCycles (tsc , regs , nanos );
165162 // rcx is set to IA32_TSC_AUX. According to the Intel developer manual
166163 // 17.17.2 "IA32_TSC_AUX Register and RDTSCP Support", "IA32_TSC_AUX
0 commit comments