From a4a35bd911fed4eadb5748fe7a75d8295a5ae115 Mon Sep 17 00:00:00 2001 From: Hane Date: Tue, 25 Jul 2023 20:21:08 +0200 Subject: [PATCH] we gottem???? --- buildlib.bat | 4 +++- buildtest.bat | 5 +++-- src/test/test.cpp | 31 ++++++++++++++++++++++--------- src/tmrtsc.cpp | 16 +++++++++------- src/tmrtsc.hpp | 11 ++++++++++- 5 files changed, 47 insertions(+), 20 deletions(-) diff --git a/buildlib.bat b/buildlib.bat index 38e72f6..37c7ea6 100644 --- a/buildlib.bat +++ b/buildlib.bat @@ -1 +1,3 @@ -clang++ -DDEBUG -shared src\tmrtsc.cpp -o build\libtmrtsc.dll -Wall -Wextra -Wpedantic -std=c++11 -g -gcodeview -Wl,-pdb= -L C:\capybara\libclang\x86_64-w64-mingw32\bin -l c++ -l unwind --verbose +clang++ -DDEBUG -shared src\tmrtsc.cpp -o build\libtmrtsc.dll -Wall -Wextra -Wpedantic -std=c++11 -g -gcodeview -Wl,-pdb= -L C:\capybara\libclang\x86_64-w64-mingw32\bin -Wl,-Bstatic -l c++ -l unwind --verbose + +REM -lmsvcrt -lucrtbase -lvcruntime140_app diff --git a/buildtest.bat b/buildtest.bat index b2222a0..7fbd32a 100644 --- a/buildtest.bat +++ b/buildtest.bat @@ -1,3 +1,4 @@ -clang++ src\test\test.cpp -o build\test.exe -Wall -Wextra -Wpedantic -std=c++11 -g -gcodeview -Wl,-pdb= -L C:\capybara\libclang\x86_64-w64-mingw32\bin -l c++ -l unwind -L D:\Contenido\Capybara\Cositas\tmr\build -l tmrtsc --verbose +clang++ -DDEBUG -dynamic src\test\test.cpp -o build\test.exe -Wall -Wextra -Wpedantic -std=c++11 -g -gcodeview -Wl,-pdb= -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 -REM -fms-runtime-lib dll_dbg +REM -fms-runtime-lib dll_dbgx +REM -lmsvcrt -lucrtbase -lvcruntime140_app diff --git a/src/test/test.cpp b/src/test/test.cpp index 0c0152e..4076133 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -1,7 +1,15 @@ #ifdef _WIN64 #define UNICODE #define WIN32_LEAN_AND_MEAN - //#define DllImport __declspec( dllimport ) + #define DllImport __declspec( dllimport ) + #define _DEBUG + #define _MT + #define _DLL + /* + * #define _MT + * #define _DLL + * #define _DEBUG + */ #include #include #endif @@ -15,22 +23,27 @@ using namespace tmr; int main(int argc, char** argv){ HMODULE dell; DWORD fracaso; + //DllImport TSCTimer* timer; int sleep = 1000; - dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL); - if (dell == NULL) { - fracaso = GetLastError(); - return -1; - } + /* + * dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL); + * if (dell == NULL) { + * fracaso = GetLastError(); + * return -1; + * } + */ TSCTimer* timer = nullptr; - fracaso = TSCTimer::getTimer(timer); - if(fracaso != OPERATION_SUCCESSFUL) + 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 << "Windows Momento: \nt1: " << t1 << " t2: " << " fr: " << fr << std::endl; + 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; return 0; } diff --git a/src/tmrtsc.cpp b/src/tmrtsc.cpp index 054611d..aacffde 100644 --- a/src/tmrtsc.cpp +++ b/src/tmrtsc.cpp @@ -1,3 +1,4 @@ +//TODO juntar heaps? #include "tmrtsc.hpp" #if _WIN64 @@ -166,25 +167,26 @@ namespace tmr { return (rdxho << 32) + raxlo; //| } - int TSCTimer::getTimer(TSCTimer* timer) { - if (!checkInvariantTSC()) return INVARIANT_TSC_NOT_SUPPORTED; + TSCTimer* TSCTimer::getTimer() { + if (!checkInvariantTSC()) return nullptr; //TODO debug dis const char vendorNames[2][13] = { {"AuthenticAMD"}, {"GenuineIntel"} }; char* vendorName = readVendorName(); - int64_t baseFreq; + int64_t baseFreq = ART_NOT_REPORTED; - if (strcmp(vendorName, vendorNames[1])) + if (strcmp(vendorName, vendorNames[1]) == 0) baseFreq = intelRetrieveART(); if (baseFreq == ART_NOT_REPORTED) baseFreq = getFreqFromSystem(); if (baseFreq < OPERATION_SUCCESSFUL) - return CANT_READ_FREQUENCY_FROM_SYSTEM; + return nullptr; - timer = new TSCTimer(vendorName, baseFreq); - return OPERATION_SUCCESSFUL; + //timer = + return new TSCTimer(vendorName, baseFreq); + //return OPERATION_SUCCESSFUL; } uint64_t TSCTimer::getTimeStamp(){ diff --git a/src/tmrtsc.hpp b/src/tmrtsc.hpp index 3c07bca..f1cfe62 100644 --- a/src/tmrtsc.hpp +++ b/src/tmrtsc.hpp @@ -8,6 +8,14 @@ #define _WIN32_WINNT _WIN32_WINNT_WIN10 //0x0A00 #define MAX_KEY_LENGTH 255 #define MAX_VALUE_NAME 32767 + #define _DEBUG + #define _MT + #define _DLL + /* + * #define _MT + * #define _DLL + * #define _DEBUG + */ #include #include #include @@ -77,7 +85,8 @@ namespace tmr { uint64_t readRDTSCP(uint64_t* logicore = nullptr ); public: - static int getTimer(TSCTimer* timer = nullptr); + // static int getTimer(TSCTimer* timer = nullptr); + static TSCTimer* getTimer(); uint64_t getTimeStamp();