This commit is contained in:
Hane 2023-07-13 00:13:40 +02:00
commit fb4dc61950

View file

@ -16,6 +16,8 @@ Intel(R) 64 and IA-32 Architectures Software Developer's Manual Volume 3 (3A, 3B
*/
//TSC is incremented by the base multiplier once every reference clock, so on my Xeon E5-2680 (Sandy Bridge EP) this is an increment of 27 every 10 ns
//#ifdef WIN64
#ifndef DEBUG
@ -36,6 +38,28 @@ bool checkInvariantTSC(){
//"and edx, 10000000\n")
return iTSC;
}
/*
15H NOTES: If EBX[31:0] is 0, the TSC/"core crystal clock" ratio is not enumerated.
EBX[31:0]/EAX[31:0] indicates the ratio of the TSC frequency and the core crystal clock frequency. If ECX is 0, the nominal core crystal clock frequency is not enumerated. "TSC frequency" = "core crystal clock frequency" * EBX/EAX. The core crystal clock may differ from the reference clock, bus clock, or core clock frequencies.
EAX Bits 31-00: An unsigned integer which is the denominator of the TSC/"core crystal clock" ratio.
EBX Bits 31-00: An unsigned integer which is the numerator of the TSC/"core crystal clock" ratio.
ECX Bits 31-00: An unsigned integer which is the nominal frequency of the core crystal clock in Hz.
EDX Bits 31-00: Reserved = 0.
*/
void checkFrequencyTSC(uint64_t* freq){
if (logicore == nullptr) return NULL;
uint64_t raxlo,rdxho, rcx;
asm volatile ( ".intel_syntax noprefix\t\n"
"rdtscp\t\n"
"lfence\t\n": "=a" (raxlo), "=d" (rdxho), "=c" (rcx) );
//"rdtscp\n" : "=a" (raxlo), "=d" (rdxho));
freq
}
//static inline
uint64_t rdtsc() {
uint64_t raxlo,rdxho;
@ -49,6 +73,7 @@ uint64_t rdtsc() {
//static inline
uint64_t rdtscp(uint64_t* logicore ) {
if (logicore == nullptr) return NULL;
uint64_t raxlo,rdxho, rcx;
asm volatile ( ".intel_syntax noprefix\t\n"
"rdtscp\t\n"