From 6136207436a140320232574f8274d375144fe22c Mon Sep 17 00:00:00 2001 From: Hane Date: Wed, 17 Jan 2024 20:07:53 +0100 Subject: [PATCH 1/2] refactored test --- buildtest.bat | 2 +- src/test/test.cpp | 72 +++++++++++++++++++++++++++++++++++++++-------- src/tmrtsc.cpp | 1 - src/tmrtsc.hpp | 14 ++++----- 4 files changed, 69 insertions(+), 20 deletions(-) diff --git a/buildtest.bat b/buildtest.bat index 3ea2ae5..364e361 100644 --- a/buildtest.bat +++ b/buildtest.bat @@ -1 +1 @@ -clang++ -dynamic src\test\test.cpp -o build\test.exe -Wall -Wextra -Wpedantic -std=c++11 -L C:\capybara\libclang\x86_64-w64-mingw32\bin -L D:\Contenido\Capybara\Cositas\tmr\build -Wl,-Bstatic -l c++ -l unwind -Wl,-Bdynamic -l tmrtsc --verbose \ No newline at end of file +clang++ -dynamic src\test\test.cpp -o build\test.exe -Wall -Wextra -Wpedantic -std=c++11 -L C:\capybara\libclang\x86_64-w64-mingw32\bin -L D:\Contenido\Capybara\Cositas\tmr\build -Wl,-Bstatic -l c++ -l unwind -Wl,-Bdynamic -l tmrtsc --verbose diff --git a/src/test/test.cpp b/src/test/test.cpp index 1587e16..35b9e1d 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -5,7 +5,8 @@ #define _MT #define _DLL #include - #include + #include +//#include #endif #include "../debug.h" @@ -14,11 +15,31 @@ using namespace tmr; #ifdef _WIN64 +static inline int64_t getQPCTicks() { + LARGE_INTEGER ticks; + if (!QueryPerformanceCounter(&ticks)) + { + return 0; + } + return ticks.QuadPart; +} + +static inline int64_t getQPCFrequency() { + LARGE_INTEGER ticks; + if (!QueryPerformanceFrequency(&ticks)) + { + return 0; + } + return ticks.QuadPart; +} + + int main(int argc, char** argv){ - HMODULE dell; - DWORD fracaso; + //HMODULE dell; + //DWORD fracaso; //DllImport TSCTimer* timer; - int sleep = 1000; + uint64_t sleep = 1; + uint64_t checks = 0; /* * dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL); @@ -31,13 +52,42 @@ int main(int argc, char** argv){ timer = TSCTimer::getTimer(); if(timer == nullptr) return -2; - uint64_t t1 = timer->getTimeStamp(); - Sleep(sleep); - uint64_t t2 = timer->getTimeStamp(); - uint64_t fr = timer->getBaseFrequency(); - std::cout << "Siestecita de: " << sleep << " ms" << std::endl; - std::cout << "Windows Momento: \nt1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; - std::cout << "restita: " << t2-t1 << std::endl; + uint64_t wfr = getQPCFrequency(); + int64_t fr = timer->getBaseFrequency(); + + + uint64_t wt1 = getQPCTicks(); + int64_t t1 = timer->getTimeStamp(); + int64_t t2 = timer->getTimeStamp(); + while ((t2 - t1) < (sleep * fr)) { + t2 = timer->getTimeStamp(); + checks++; + } + //uint64_t fr = timer->getBaseFrequency(); + uint64_t wt2 = getQPCTicks(); + std::cout << "Sleep: " << sleep << "s\n-----------------\nTest 1: TSCTimer within QPC\n" << std::endl; + std::cout << " QPC Momento: \nt1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl; + std::cout << " restita: " << wt2-wt1 << std::endl; + std::cout << " TSCTimer Momento: \nt1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; + std::cout << " restita: " << t2-t1 << std::endl; + std::cout << " checks: " << checks << "\n-----------------\nTest 2: QPC within TSCTimer\n"<< std::endl; + + checks = 0; + t1 = timer->getTimeStamp(); + wt1 = getQPCTicks(); + wt2 = getQPCTicks(); + while ((wt2 - wt1) < (sleep * wfr)) { + wt2 = getQPCTicks(); + checks++; + } + //uint64_t fr = timer->getBaseFrequency(); + t2 = timer->getTimeStamp(); + std::cout << "QPC Momento: \n t1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl; + std::cout << "restita: " << wt2-wt1 << std::endl; + std::cout << "TSCTimer Momento: \n t1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; + std::cout << " restita: " << t2-t1 << std::endl; + std::cout << " checks: " << checks << std::endl; + return 0; } diff --git a/src/tmrtsc.cpp b/src/tmrtsc.cpp index bac4398..e940356 100644 --- a/src/tmrtsc.cpp +++ b/src/tmrtsc.cpp @@ -47,7 +47,6 @@ namespace tmr { int64_t TSCTimer::intelRetrieveART(){ //TODO: Find a valid Intel CPU to debug ART route - //if (freq == nullptr) return - uint64_t raxde, rbxnum, rcxhz; asm volatile ( ".intel_syntax noprefix\t\n" \ diff --git a/src/tmrtsc.hpp b/src/tmrtsc.hpp index 5eb10b5..6389381 100644 --- a/src/tmrtsc.hpp +++ b/src/tmrtsc.hpp @@ -32,18 +32,18 @@ namespace tmr { #ifdef _WIN64 enum winReturnValues{ - CANT_OPEN_KEY = -1, - CANT_RETRIEVE_KEY_INFO = -2, + CANT_OPEN_KEY = -1, + CANT_RETRIEVE_KEY_INFO = -2, CANT_READ_DATA_FROM_VALUE = -3, - CANT_RETRIEVE_FREQUENCY = -4 + CANT_RETRIEVE_FREQUENCY = -4 }; #endif enum ReturnValues { - OPERATION_SUCCESSFUL = 0, - INVARIANT_TSC_NOT_SUPPORTED = -1, - UNSUPPORTED_CPU = -2, + OPERATION_SUCCESSFUL = 0, + INVARIANT_TSC_NOT_SUPPORTED = -1, + UNSUPPORTED_CPU = -2, CANT_READ_FREQUENCY_FROM_SYSTEM = -3, - ART_NOT_REPORTED = -4 + ART_NOT_REPORTED = -4 }; class LIB_EXPORT TSCTimer { From d1343ff90c5fe1f85feede69173af9efb2a3e631 Mon Sep 17 00:00:00 2001 From: Hane Date: Wed, 17 Jan 2024 23:59:50 +0100 Subject: [PATCH 2/2] modified test and more proto --- buildproto.bat | 2 +- src/proto/proto.cpp | 39 +++++++++++++++++++++++---------------- src/test/test.cpp | 8 ++++---- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/buildproto.bat b/buildproto.bat index db46758..116a7a3 100644 --- a/buildproto.bat +++ b/buildproto.bat @@ -1 +1 @@ -clang++ -DDEBUG src\proto\proto.cpp -o build\ayo.exe -Wall -Wextra -Wpedantic -std=c++11 -g -gcodeview -Wl,-pdb= -L C:\capybara\libclang\x86_64-w64-mingw32\bin -l c++ -l unwind -static --verbose +clang++ -DDEBUG src\proto\proto.cpp -o build\ayo.exe -Wall -Wextra -Wpedantic -std=c++11 -g -gcodeview -Wl,-pdb= -L C:\capybara\libclang\x86_64-w64-mingw32\bin -static-libstdc++ -static --verbose diff --git a/src/proto/proto.cpp b/src/proto/proto.cpp index c5b2e7a..53ba00f 100644 --- a/src/proto/proto.cpp +++ b/src/proto/proto.cpp @@ -1,7 +1,3 @@ -<<<<<<< Updated upstream -======= -//si, bueno, testx ->>>>>>> Stashed changes /* * THREADIN THE LINUS: https://linux.die.net/man/2/sched_setaffinity */ @@ -29,7 +25,7 @@ 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 - +//https://github.com/jdmccalpin/low-overhead-timers/issues/1 #ifdef _WIN64 //#include @@ -45,7 +41,7 @@ Intel(R) 64 and IA-32 Architectures Software Developer's Manual Volume 3 (3A, 3B #include #include #endif -#ifdef NOMESELDELINUS +#ifdef LOwOnus //hilitos y tal #endif @@ -53,6 +49,17 @@ Intel(R) 64 and IA-32 Architectures Software Developer's Manual Volume 3 (3A, 3B #include #include "../debug.h" +uint64_t checksatr(){ //Generic + uint64_t rcx; + asm volatile (".intel_syntax noprefix\t\n" \ + "mov eax, 0x80000007\t\n" \ + // 080000007h\t\n" + "cpuid\t\n" : "=c" (rcx) ); + //bool iTSC = rcx & (1<<6); + //"and edx, 10000000\n") + return rcx; +} + bool checkInvariantTSC(){ //Generic uint64_t rdx; asm volatile (".intel_syntax noprefix\t\n" \ @@ -96,10 +103,11 @@ EDX Bits 31-00: Reserved = 0. */ -char* AMDMeCagoEnTusPutosMuertos () { +char* AMDTest() { /* * Extended name on AMD systems when using 8000_002-4. 8000_0000 for Extpagequant/vendor. Hijos de puta. * Now parsing 0H for standard brand name + * https://github.com/jdmccalpin/low-overhead-timers/issues/1 */ char* palabritas = (char*)malloc(sizeof(char) * 13); uint8_t siguienteLetra = 0; @@ -119,8 +127,8 @@ char* AMDMeCagoEnTusPutosMuertos () { return palabritas; } -//GMET on??????????? jfc wtf -bool AMDJoderMET(){ +//GMET on??????????? Zenbros... +bool AMDGMET(){ uint64_t rdx; asm volatile ( ".intel_syntax noprefix\t\n" \ "mov eax, 0x8000000A\t\n" \ @@ -248,7 +256,7 @@ uint64_t estimandoFreq(){ valLen = MAX_VALUE_NAME; //data NULL + len NON_NULL to get dataBufLen; //data allocated (NON-NULL) + len NON-NULL with previous value for dataLen - //JFC MS WHY. that why we defaultin to biggis. cos not worky. ewe + //MS WHY. that why we defaultin to biggis. cos not worky. ewe dataLen = sizeof(REG_QWORD) * (longestDataSize); status = RegEnumValueW(key, i, @@ -278,9 +286,7 @@ uint64_t estimandoFreq(){ ) ) { //dataLen = dataLen * 2lu; - /* BROS YO ES QUE ME VOY A CAGAR EN SUS PUTOS MUERTOS - * ASí QUE PIDES DOS VECES, UNA TAMAńO, OTRA A TOPE PRESISO, EH - * PUTA BASURA DE API + /* We do be usin' well designed APIs...... * status = RegEnumValueW(key, * i, * valName, @@ -312,14 +318,15 @@ uint64_t estimandoFreq(){ int main(int argc, char** argv){ //AMD Momento - char* opiniones = AMDMeCagoEnTusPutosMuertos(); - bool w11 = AMDJoderMET(); + char* opiniones = AMDTest(); + bool w11 = AMDGMET(); for (int i = 0; i < 3; i++) { uint64_t isItActually32GHz = estimandoFreq(); log_debugcpp("ayo we found " << isItActually32GHz << " flash knuckle"); } int64_t juas = getFreqFromReg(); - log_debugcpp("JODER " << juas); + log_debugcpp("satr " << checksatr()); + log_debugcpp("Invariant " << checkInvariantTSC()); //iwintewel //Cordura diff --git a/src/test/test.cpp b/src/test/test.cpp index 35b9e1d..8126175 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv){ if(timer == nullptr) return -2; uint64_t wfr = getQPCFrequency(); - int64_t fr = timer->getBaseFrequency(); + int64_t fr = 3193999000;//timer->getBaseFrequency(); uint64_t wt1 = getQPCTicks(); @@ -66,9 +66,9 @@ int main(int argc, char** argv){ //uint64_t fr = timer->getBaseFrequency(); uint64_t wt2 = getQPCTicks(); std::cout << "Sleep: " << sleep << "s\n-----------------\nTest 1: TSCTimer within QPC\n" << std::endl; - std::cout << " QPC Momento: \nt1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl; + std::cout << "QPC Momento: \n t1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl; std::cout << " restita: " << wt2-wt1 << std::endl; - std::cout << " TSCTimer Momento: \nt1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; + std::cout << "TSCTimer Momento: \n t1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; std::cout << " restita: " << t2-t1 << std::endl; std::cout << " checks: " << checks << "\n-----------------\nTest 2: QPC within TSCTimer\n"<< std::endl; @@ -83,7 +83,7 @@ int main(int argc, char** argv){ //uint64_t fr = timer->getBaseFrequency(); t2 = timer->getTimeStamp(); std::cout << "QPC Momento: \n t1: " << wt1 << " t2: " << wt2 << " fr: " << wfr << std::endl; - std::cout << "restita: " << wt2-wt1 << std::endl; + std::cout << " restita: " << wt2-wt1 << std::endl; std::cout << "TSCTimer Momento: \n t1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl; std::cout << " restita: " << t2-t1 << std::endl; std::cout << " checks: " << checks << std::endl;