Skip to content

Commit

Permalink
Enable Time-based TSC for non-Ryzen CPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Jan 31, 2025
1 parent 57b6ced commit 394fc8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ u64 convert_to_timebased_time(u64 time)

u64 get_timebased_time()
{
if (0) if (u64 freq = utils::get_tsc_freq())
if (u64 freq = utils::get_tsc_freq())
{
const u64 tsc = utils::get_tsc();

Expand Down Expand Up @@ -207,7 +207,7 @@ void initialize_timebased_time(u64 timebased_init, bool reset)
// Returns some relative time in microseconds, don't change this fact
u64 get_system_time()
{
if (0) if (u64 freq = utils::get_tsc_freq())
if (u64 freq = utils::get_tsc_freq())
{
const u64 tsc = utils::get_tsc();

Expand Down
15 changes: 13 additions & 2 deletions rpcs3/util/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ std::string utils::get_system_info()
}
else
{
fmt::append(result, " | TSC: Bad");
fmt::append(result, " | TSC: Disabled");
}

if (has_avx())
Expand Down Expand Up @@ -772,15 +772,26 @@ static const bool s_tsc_freq_evaluated = []() -> bool
#endif

if (!utils::has_invariant_tsc())
{
return 0;
}

if (utils::get_cpu_brand().find("Ryzen") != umax)
{
return 0;
}

#ifdef _WIN32
LARGE_INTEGER freq;
if (!QueryPerformanceFrequency(&freq))
{
return 0;
}

if (freq.QuadPart <= 9'999'999)
{
return 0;
}

const ullong timer_freq = freq.QuadPart;
#else
Expand Down Expand Up @@ -880,7 +891,7 @@ static const bool s_tsc_freq_evaluated = []() -> bool
return round_tsc(res, utils::mul_saturate<u64>(utils::add_saturate<u64>(rdtsc_diff[0], rdtsc_diff[1]), utils::aligned_div(timer_freq, timer_data[1] - timer_data[0])));
}();

atomic_storage<u64>::release(utils::s_tsc_freq, cal_tsc);
atomic_storage<u64>::store(utils::s_tsc_freq, cal_tsc);
return true;
}();

Expand Down

0 comments on commit 394fc8e

Please sign in to comment.