Changeset View
Changeset View
Standalone View
Standalone View
source/lib/sysdep/os/win/whrt/counter.cpp
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
Show All 15 Lines | |||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "lib/sysdep/os/win/whrt/counter.h" | #include "lib/sysdep/os/win/whrt/counter.h" | ||||
#include "lib/alignment.h" | #include "lib/alignment.h" | ||||
#include "lib/sysdep/cpu.h" // cpu_CAS | #include "lib/sysdep/cpu.h" // cpu_CAS | ||||
#include "lib/sysdep/os/win/whrt/tsc.h" | |||||
#include "lib/sysdep/os/win/whrt/hpet.h" | |||||
#include "lib/sysdep/os/win/whrt/pmt.h" | |||||
#include "lib/sysdep/os/win/whrt/qpc.h" | #include "lib/sysdep/os/win/whrt/qpc.h" | ||||
#include "lib/sysdep/os/win/whrt/tsc.h" | |||||
#include "lib/sysdep/os/win/whrt/tgt.h" | #include "lib/sysdep/os/win/whrt/tgt.h" | ||||
// to add a new counter type, simply include its header here and | // to add a new counter type, simply include its header here and | ||||
// insert a case in ConstructCounterAt's switch statement. | // insert a case in ConstructCounterAt's switch statement. | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
// create/destroy counters | // create/destroy counters | ||||
/** | /** | ||||
* @param id | * @param id | ||||
* @param address | * @param address | ||||
* @param size Maximum allowable size [bytes] of the subclass instance | * @param size Maximum allowable size [bytes] of the subclass instance | ||||
* @return pointer to a newly constructed ICounter subclass of type \<id\> at | * @return pointer to a newly constructed ICounter subclass of type \<id\> at | ||||
* the given address, or 0 iff the ID is invalid. | * the given address, or 0 iff the ID is invalid. | ||||
**/ | **/ | ||||
static ICounter* ConstructCounterAt(size_t id, void* address, size_t size) | static ICounter* ConstructCounterAt(size_t id, void* address, size_t size) | ||||
{ | { | ||||
// rationale for placement new: see call site. | // rationale for placement new: see call site. | ||||
// counters are chosen according to the following order. rationale: | // counters are chosen according to the following order. rationale: | ||||
// - TSC must come before QPC and PMT to make sure a bug in the latter on | // - QPC is used by most games engines and is more stable than the others. | ||||
// Pentium systems doesn't come up. | // - TSC is buggy on some machines like the AMD Zen 2 CPUs. | ||||
// - PMT works, but is inexplicably slower than QPC on a PIII Mobile. | |||||
// - TGT really isn't as safe as the others, so it should be last. | // - TGT really isn't as safe as the others, so it should be last. | ||||
// - low-overhead and high-resolution counters are preferred. | // - low-overhead and high-resolution counters are preferred. | ||||
switch(id) | switch(id) | ||||
{ | { | ||||
case 0: | case 0: | ||||
return CreateCounterHPET(address, size); | return CreateCounterQPC(address, size); | ||||
case 1: | case 1: | ||||
return CreateCounterTSC(address, size); | return CreateCounterTSC(address, size); | ||||
case 2: | case 2: | ||||
return CreateCounterQPC(address, size); | |||||
case 3: | |||||
return CreateCounterPMT(address, size); | |||||
case 4: | |||||
return CreateCounterTGT(address, size); | return CreateCounterTGT(address, size); | ||||
default: | default: | ||||
return 0; | return 0; | ||||
} | } | ||||
} | } | ||||
static volatile intptr_t isCounterAllocated; | static volatile intptr_t isCounterAllocated; | ||||
Show All 37 Lines |
Wildfire Games · Phabricator