Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2035c1e10e | |||
| d1343ff90c | |||
| 6136207436 | |||
| bbed99ba8c | |||
| 0ff6488545 | |||
| dc837e2bb1 | |||
| 443593e9f0 |
14 changed files with 172 additions and 90 deletions
44
README.md
44
README.md
|
|
@ -1,2 +1,44 @@
|
||||||
# tmr
|
x86 TSC-based tick timer written in C++ and extended ASM.
|
||||||
|
|
||||||
|
This timer queries RDTSCP/RDTSC manually on compatible systems and presents a quick and easy-to-use interface to obtain timestamps. On Windows, this is basically what `QueryPerformanceCounter` achieves behind the curtains (and with fallbacks where not applicable, like HPET), but with lower resolution.
|
||||||
|
|
||||||
|
While functional on some CPU families (Zen/+ and Haswell have been tested), this library is not ready for use. Linux support is TBD, alongside testing on different CPU families and implementing support for heterogeneous architectures and products (such as Tiger Lake+/Zen4+Zen4c systems).
|
||||||
|
|
||||||
|
Worth noting as well is the fact that [calculating TSC resolution from user-space on an AMD CPU is not possible.](https://github.com/jdmccalpin/low-overhead-timers/issues/1) Precise enough estimations can be calculated, but this artificial limitation adds a non-insignificant level of friction to this project.
|
||||||
|
|
||||||
|
A small console program to test this library and comparing it agains `QueryPerformancecounter` is provided, busywaiting for a second and comparing both.
|
||||||
|
|
||||||
|
# But why?
|
||||||
|
|
||||||
|
During development of the mouse-on-keyboard script, I grew curious about this topic. Win32's `Sleep()` is a reliably unreliable time-skipping measure, subject to the wishes of thread time-slicing and scheduling. High resolution timers in the vein of `QueryPerformanceCounter` are what Win32 offers in this regard, but a spark of interest and curiosity had already grown about this topic. I created this library, this incomplete pet-project, as a means to learn and refresh knowledge about x86 ASM, registry traversal and modification, modern OSes, current x86 hardware features and shared libraries.
|
||||||
|
|
||||||
|
# How to build
|
||||||
|
|
||||||
|
## Build requirements
|
||||||
|
|
||||||
|
- Both test and Developed and tested with `clang` using [**llvm-mingw UCRT 20220906**](https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906). Any `MinGW`-backed `clang` compiler should work, but your mileage may vary.
|
||||||
|
- This lib has only been compiled and tested as a dynamic lib, but it should work statically linked as well.
|
||||||
|
|
||||||
|
## How to compile
|
||||||
|
|
||||||
|
Add `TMRDEBUG` to print debug information. Currently, it only offers relevant information for ART calculation.
|
||||||
|
|
||||||
|
- Library
|
||||||
|
|
||||||
|
```
|
||||||
|
clang++ -shared src\tmrtsc.cpp -o libtmrtsc.dll -Wall -Wextra -Wpedantic -std=c++11 -L C:\pathtollvmmingw\x86_64-w64-mingw32\lib -Wl,-Bstatic -l c++ --verbose
|
||||||
|
```
|
||||||
|
|
||||||
|
- Test
|
||||||
|
|
||||||
|
```
|
||||||
|
clang++ src\test\test.cpp -o testd.exe -Wall -Wextra -Wpedantic -std=c++11 -L C:\pathtollvmmingw\x86_64-w64-mingw32\lib -L . -Wl,-Bstatic -l c++ -Wl,-Bdynamic -l tmrtsc --verbose
|
||||||
|
```
|
||||||
|
|
||||||
|
# Bonus
|
||||||
|
|
||||||
|
This repo contains this project's prototipe in `.\src\proto`, which can be messed with build very similarly:
|
||||||
|
|
||||||
|
```
|
||||||
|
clang++ src\proto\proto.cpp -o proto.exe -Wall -Wextra -Wpedantic -std=c++11 -L C:\pathtollvmmingw\x86_64-w64-mingw32\lib -static-libstdc++ --verbose
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
clang++ src\main.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
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
REM MS yo me cago en tus putisimos muertos que cojones es este bug centenario estupido y miserable con los parametros?
|
|
||||||
REM este comentario es de cuando me lo encontre hace rato, pero me hace gracia, asi que se queda
|
|
||||||
|
|
||||||
CALL buildlib.bat
|
|
||||||
CALL buildtest.bat
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
REM MS yo me cago en tus putisimos muertos que cojones es este bug centenario estupido y miserable con los parametros?
|
|
||||||
REM este comentario es de cuando me lo encontre hace rato, pero me hace gracia, asi que se queda
|
|
||||||
|
|
||||||
CALL builddlib.bat
|
|
||||||
CALL builddtest.bat
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
clang++ -DDEBUG -D_DEBUG -shared src\tmrtsc.cpp -o build\libtmrtscd.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
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
clang++ -DDEBUG -D_DEBUG -dynamic src\test\test.cpp -o build\testd.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_dbgx
|
|
||||||
REM -lmsvcrt -lucrtbase -lvcruntime140_app
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
clang++ -shared src\tmrtsc.cpp -o build\libtmrtsc.dll -Wall -Wextra -Wpedantic -std=c++11 -L C:\capybara\libclang\x86_64-w64-mingw32\bin -Wl,-Bstatic -l c++ -l unwind --verbose
|
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
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
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined (QT_DEBUG) || defined (DEBUG) || defined (_DEBUG)
|
#ifdef TMRDEBUG
|
||||||
|
|
||||||
#define log_debugcpp(str) do { \
|
#define log_debugcpp(str) do { \
|
||||||
std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \
|
std::cout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \
|
||||||
|
|
|
||||||
15
src/global.h
15
src/global.h
|
|
@ -1,15 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
//TODO enum capullo
|
|
||||||
#define ENDPOINT_MASTER_VOLUME -1
|
|
||||||
#define ENDPOINT_LEFT_CHANNEL_VOLUME 0
|
|
||||||
#define ENDPOINT_RIGHT_CHANNEL_VOLUME 1
|
|
||||||
|
|
||||||
#define STRING_MUTE "Mute"
|
|
||||||
#define STRING_UNMUTE "Unmute"
|
|
||||||
//INIT BACK
|
|
||||||
|
|
||||||
|
|
||||||
class OverseerHandler;
|
|
||||||
extern OverseerHandler *osh;
|
|
||||||
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* THREADIN THE LINUS: https://linux.die.net/man/2/sched_setaffinity
|
* THREADIN THE LINUS: https://linux.die.net/man/2/sched_setaffinity
|
||||||
*/
|
*/
|
||||||
|
|
@ -25,11 +26,16 @@ 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
|
//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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* no sé si desde dentro del dll/so, desde main, lo puedo forzar a X hilo. Es lo que faltaría para tener esta impl 100% funcional* [20:59] no puedo hacerlo bien del todo sin acceso a un procesador intel de 12a o 13a generación (editado) [21:00] si pudiese clampear la dll a hilo X desde ella misma cuando ntdll la carga, al menos estaría todo bien hardcodeadito al hilo 0 y funcionaría por el poder de la dureza [1:00] va a funcionar igual en el 9X% de casos, porque todos los so intentan sincronizar el tsc de todos los hilos hasta en multisocket [21:00] pero eso está técnicamente mal [21:01] y bueno, necesito un procesador de intel más reciente para explorar el cálculo del ART, y 12/13 gen para explorar el tsc entre hilos de cpu de distinta uarch [21:01] no va a pasar, así que a joderse [21:02] intentaré clampear desde dll a un hilo, pondré el Modo Unix™️ y a otra cosa
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
//#include <Windows.h>
|
//#include <Windows.h>
|
||||||
//#include <sysinfoapi.h>
|
//#includqe <sysinfoapi.h>
|
||||||
//#include <powerbase.h>
|
//#include <powerbase.h>
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
@ -41,17 +47,24 @@ Intel(R) 64 and IA-32 Architectures Software Developer's Manual Volume 3 (3A, 3B
|
||||||
#include <stringapiset.h>
|
#include <stringapiset.h>
|
||||||
#include <synchapi.h>
|
#include <synchapi.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef NOMESELDELINUS
|
#ifdef LOwOnus
|
||||||
//hilitos y tal
|
//hilitos y tal
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEBUG
|
|
||||||
#define DEBUG
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "debug.h"
|
#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
|
bool checkInvariantTSC(){ //Generic
|
||||||
uint64_t rdx;
|
uint64_t rdx;
|
||||||
|
|
@ -96,10 +109,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.
|
* 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
|
* Now parsing 0H for standard brand name
|
||||||
|
* https://github.com/jdmccalpin/low-overhead-timers/issues/1
|
||||||
*/
|
*/
|
||||||
char* palabritas = (char*)malloc(sizeof(char) * 13);
|
char* palabritas = (char*)malloc(sizeof(char) * 13);
|
||||||
uint8_t siguienteLetra = 0;
|
uint8_t siguienteLetra = 0;
|
||||||
|
|
@ -119,8 +133,8 @@ char* AMDMeCagoEnTusPutosMuertos () {
|
||||||
return palabritas;
|
return palabritas;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GMET on??????????? jfc wtf
|
//GMET on??????????? Zenbros...
|
||||||
bool AMDJoderMET(){
|
bool AMDGMET(){
|
||||||
uint64_t rdx;
|
uint64_t rdx;
|
||||||
asm volatile ( ".intel_syntax noprefix\t\n" \
|
asm volatile ( ".intel_syntax noprefix\t\n" \
|
||||||
"mov eax, 0x8000000A\t\n" \
|
"mov eax, 0x8000000A\t\n" \
|
||||||
|
|
@ -248,7 +262,7 @@ uint64_t estimandoFreq(){
|
||||||
valLen = MAX_VALUE_NAME;
|
valLen = MAX_VALUE_NAME;
|
||||||
//data NULL + len NON_NULL to get dataBufLen;
|
//data NULL + len NON_NULL to get dataBufLen;
|
||||||
//data allocated (NON-NULL) + len NON-NULL with previous value for dataLen
|
//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);
|
dataLen = sizeof(REG_QWORD) * (longestDataSize);
|
||||||
status = RegEnumValueW(key,
|
status = RegEnumValueW(key,
|
||||||
i,
|
i,
|
||||||
|
|
@ -278,9 +292,7 @@ uint64_t estimandoFreq(){
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
//dataLen = dataLen * 2lu;
|
//dataLen = dataLen * 2lu;
|
||||||
/* BROS YO ES QUE ME VOY A CAGAR EN SUS PUTOS MUERTOS
|
/* We do be usin' well designed APIs......
|
||||||
* ASí QUE PIDES DOS VECES, UNA TAMAńO, OTRA A TOPE PRESISO, EH
|
|
||||||
* PUTA BASURA DE API
|
|
||||||
* status = RegEnumValueW(key,
|
* status = RegEnumValueW(key,
|
||||||
* i,
|
* i,
|
||||||
* valName,
|
* valName,
|
||||||
|
|
@ -312,14 +324,15 @@ uint64_t estimandoFreq(){
|
||||||
|
|
||||||
int main(int argc, char** argv){
|
int main(int argc, char** argv){
|
||||||
//AMD Momento
|
//AMD Momento
|
||||||
char* opiniones = AMDMeCagoEnTusPutosMuertos();
|
char* opiniones = AMDTest();
|
||||||
bool w11 = AMDJoderMET();
|
bool w11 = AMDGMET();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
uint64_t isItActually32GHz = estimandoFreq();
|
uint64_t isItActually32GHz = estimandoFreq();
|
||||||
log_debugcpp("ayo we found " << isItActually32GHz << " flash knuckle");
|
log_debugcpp("ayo we found " << isItActually32GHz << " flash knuckle");
|
||||||
}
|
}
|
||||||
int64_t juas = getFreqFromReg();
|
int64_t juas = getFreqFromReg();
|
||||||
log_debugcpp("JODER " << juas);
|
log_debugcpp("satr " << checksatr());
|
||||||
|
log_debugcpp("Invariant " << checkInvariantTSC());
|
||||||
//iwintewel
|
//iwintewel
|
||||||
|
|
||||||
//Cordura
|
//Cordura
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define DllImport __declspec( dllimport )
|
#define DllImport __declspec( dllimport )
|
||||||
#define _MT
|
// #define _MT
|
||||||
#define _DLL
|
// #define _DLL
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <libloaderapi.h>
|
#include <fileapi.h>
|
||||||
|
//#include <libloaderapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
|
|
@ -14,11 +15,31 @@
|
||||||
using namespace tmr;
|
using namespace tmr;
|
||||||
|
|
||||||
#ifdef _WIN64
|
#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){
|
int main(int argc, char** argv){
|
||||||
HMODULE dell;
|
//HMODULE dell;
|
||||||
DWORD fracaso;
|
//DWORD fracaso;
|
||||||
//DllImport TSCTimer* timer;
|
//DllImport TSCTimer* timer;
|
||||||
int sleep = 1000;
|
uint64_t sleep = 1;
|
||||||
|
uint64_t checks = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL);
|
* dell = LoadLibraryExW(TEXT("libtmrtsc.dll"), NULL, NULL);
|
||||||
|
|
@ -31,13 +52,42 @@ int main(int argc, char** argv){
|
||||||
timer = TSCTimer::getTimer();
|
timer = TSCTimer::getTimer();
|
||||||
if(timer == nullptr)
|
if(timer == nullptr)
|
||||||
return -2;
|
return -2;
|
||||||
uint64_t t1 = timer->getTimeStamp();
|
uint64_t wfr = getQPCFrequency();
|
||||||
Sleep(sleep);
|
int64_t fr = 3193999000;//timer->getBaseFrequency();
|
||||||
uint64_t t2 = timer->getTimeStamp();
|
|
||||||
uint64_t fr = timer->getBaseFrequency();
|
|
||||||
std::cout << "Siestecita de: " << sleep << " ms" << std::endl;
|
uint64_t wt1 = getQPCTicks();
|
||||||
std::cout << "Windows Momento: \nt1: " << t1 << " t2: " << t2 << " fr: " << fr << std::endl;
|
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: \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 << " 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ namespace tmr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
palabritas[siguienteLetra] = '\0';
|
palabritas[siguienteLetra] = '\0';
|
||||||
|
log_debugcpp(palabritas);
|
||||||
return palabritas;
|
return palabritas;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t TSCTimer::intelRetrieveART(){
|
int64_t TSCTimer::intelRetrieveART(){
|
||||||
//TODO: Find a valid Intel CPU to debug ART route
|
//TODO: Find a valid Intel CPU to debug ART route
|
||||||
//if (freq == nullptr) return -
|
|
||||||
|
|
||||||
uint64_t raxde, rbxnum, rcxhz;
|
uint64_t raxde, rbxnum, rcxhz;
|
||||||
asm volatile ( ".intel_syntax noprefix\t\n" \
|
asm volatile ( ".intel_syntax noprefix\t\n" \
|
||||||
|
|
@ -79,9 +79,12 @@ namespace tmr {
|
||||||
LPBYTE dataContent = nullptr;
|
LPBYTE dataContent = nullptr;
|
||||||
DWORD dataLen;
|
DWORD dataLen;
|
||||||
|
|
||||||
status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), 0,
|
status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), 0, KEY_QUERY_VALUE, &key);
|
||||||
KEY_QUERY_VALUE, &key);
|
|
||||||
if(status != ERROR_SUCCESS) return CANT_OPEN_KEY;
|
if(status != ERROR_SUCCESS) {
|
||||||
|
status = RegCloseKey(key);
|
||||||
|
return CANT_OPEN_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
status = RegQueryInfoKey(
|
status = RegQueryInfoKey(
|
||||||
key, // key handle
|
key, // key handle
|
||||||
|
|
@ -96,7 +99,10 @@ namespace tmr {
|
||||||
&longestDataSize, // longest value data
|
&longestDataSize, // longest value data
|
||||||
NULL, // security descriptor
|
NULL, // security descriptor
|
||||||
NULL); // last write time
|
NULL); // last write time
|
||||||
if(status != ERROR_SUCCESS) return CANT_RETRIEVE_KEY_INFO;
|
if(status != ERROR_SUCCESS) {
|
||||||
|
status = RegCloseKey(key);
|
||||||
|
return CANT_RETRIEVE_KEY_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
dataLen = sizeof(REG_QWORD) * (longestDataSize);
|
dataLen = sizeof(REG_QWORD) * (longestDataSize);
|
||||||
dataContent = (LPBYTE)malloc(dataLen);
|
dataContent = (LPBYTE)malloc(dataLen);
|
||||||
|
|
@ -113,7 +119,10 @@ namespace tmr {
|
||||||
&dataLen
|
&dataLen
|
||||||
);
|
);
|
||||||
|
|
||||||
if(status != ERROR_SUCCESS) return CANT_READ_DATA_FROM_VALUE;
|
if(status != ERROR_SUCCESS) {
|
||||||
|
RegCloseKey(key);
|
||||||
|
return CANT_READ_DATA_FROM_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (CSTR_EQUAL == CompareStringEx(
|
if (CSTR_EQUAL == CompareStringEx(
|
||||||
LOCALE_NAME_INVARIANT,
|
LOCALE_NAME_INVARIANT,
|
||||||
|
|
@ -125,14 +134,15 @@ namespace tmr {
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
0
|
0
|
||||||
)
|
))
|
||||||
) {
|
{
|
||||||
LPDWORD PMHz = (LPDWORD)dataContent;
|
LPDWORD PMHz = (LPDWORD)dataContent;
|
||||||
DWORD MHz = *PMHz;
|
DWORD MHz = *PMHz;
|
||||||
free(dataContent);
|
free(dataContent);
|
||||||
return MHz * 1000000;
|
return MHz * 1000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
status = RegCloseKey(key);
|
||||||
return CANT_READ_DATA_FROM_VALUE;
|
return CANT_READ_DATA_FROM_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,6 +180,11 @@ namespace tmr {
|
||||||
TSCTimer* TSCTimer::getTimer() {
|
TSCTimer* TSCTimer::getTimer() {
|
||||||
if (!checkInvariantTSC()) return nullptr;
|
if (!checkInvariantTSC()) return nullptr;
|
||||||
//TODO debug dis
|
//TODO debug dis
|
||||||
|
#if defined TMRDEBUG && defined _WIN64
|
||||||
|
//AttachConsole(ATTACH_PARENT_PROCESS );
|
||||||
|
log_debugcpp("TSC Timer debug enabled.");
|
||||||
|
//FreeConsole();
|
||||||
|
#endif
|
||||||
const char vendorNames[2][13] = {
|
const char vendorNames[2][13] = {
|
||||||
{"AuthenticAMD"},
|
{"AuthenticAMD"},
|
||||||
{"GenuineIntel"}
|
{"GenuineIntel"}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
#define _WIN32_WINNT _WIN32_WINNT_WIN10 //0x0A00
|
#define _WIN32_WINNT _WIN32_WINNT_WIN10 //0x0A00
|
||||||
#define MAX_KEY_LENGTH 255
|
#define MAX_KEY_LENGTH 255
|
||||||
#define MAX_VALUE_NAME 32767
|
#define MAX_VALUE_NAME 32767
|
||||||
#define _MT
|
// #define _MT
|
||||||
#define _DLL
|
// #define _DLL
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <winreg.h>
|
#include <winreg.h>
|
||||||
#include <stringapiset.h>
|
#include <stringapiset.h>
|
||||||
|
|
@ -18,12 +18,10 @@
|
||||||
#define LIB_EXPORT
|
#define LIB_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
#if _WIN64
|
#if _WIN64
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue