core_timing: Split off utility functions into core_timing_util
This commit is contained in:
parent
b8459d2778
commit
44646e2ea0
|
@ -10,6 +10,8 @@ add_library(core STATIC
|
||||||
core_cpu.h
|
core_cpu.h
|
||||||
core_timing.cpp
|
core_timing.cpp
|
||||||
core_timing.h
|
core_timing.h
|
||||||
|
core_timing_util.cpp
|
||||||
|
core_timing_util.h
|
||||||
file_sys/content_archive.cpp
|
file_sys/content_archive.cpp
|
||||||
file_sys/content_archive.h
|
file_sys/content_archive.h
|
||||||
file_sys/control_metadata.cpp
|
file_sys/control_metadata.cpp
|
||||||
|
|
|
@ -5,17 +5,15 @@
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cinttypes>
|
|
||||||
#include <limits>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/logging/log.h"
|
|
||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "common/threadsafe_queue.h"
|
#include "common/threadsafe_queue.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
|
|
||||||
namespace CoreTiming {
|
namespace CoreTiming {
|
||||||
|
|
||||||
|
@ -59,7 +57,6 @@ static u64 event_fifo_id;
|
||||||
static Common::MPSCQueue<Event, false> ts_queue;
|
static Common::MPSCQueue<Event, false> ts_queue;
|
||||||
|
|
||||||
constexpr int MAX_SLICE_LENGTH = 20000;
|
constexpr int MAX_SLICE_LENGTH = 20000;
|
||||||
constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
|
|
||||||
|
|
||||||
static s64 idled_cycles;
|
static s64 idled_cycles;
|
||||||
|
|
||||||
|
@ -72,54 +69,6 @@ static EventType* ev_lost = nullptr;
|
||||||
|
|
||||||
static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {}
|
static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {}
|
||||||
|
|
||||||
s64 usToCycles(s64 us) {
|
|
||||||
if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
|
||||||
return std::numeric_limits<s64>::max();
|
|
||||||
}
|
|
||||||
if (us > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
|
||||||
return BASE_CLOCK_RATE * (us / 1000000);
|
|
||||||
}
|
|
||||||
return (BASE_CLOCK_RATE * us) / 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
s64 usToCycles(u64 us) {
|
|
||||||
if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
|
||||||
return std::numeric_limits<s64>::max();
|
|
||||||
}
|
|
||||||
if (us > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
|
||||||
return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
|
|
||||||
}
|
|
||||||
return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
s64 nsToCycles(s64 ns) {
|
|
||||||
if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
|
||||||
return std::numeric_limits<s64>::max();
|
|
||||||
}
|
|
||||||
if (ns > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
|
||||||
return BASE_CLOCK_RATE * (ns / 1000000000);
|
|
||||||
}
|
|
||||||
return (BASE_CLOCK_RATE * ns) / 1000000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
s64 nsToCycles(u64 ns) {
|
|
||||||
if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
|
||||||
return std::numeric_limits<s64>::max();
|
|
||||||
}
|
|
||||||
if (ns > MAX_VALUE_TO_MULTIPLY) {
|
|
||||||
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
|
||||||
return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
|
|
||||||
}
|
|
||||||
return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventType* RegisterEvent(const std::string& name, TimedCallback callback) {
|
EventType* RegisterEvent(const std::string& name, TimedCallback callback) {
|
||||||
// check for existing type with same name.
|
// check for existing type with same name.
|
||||||
// we want event type names to remain unique so that we can use them for serialization.
|
// we want event type names to remain unique so that we can use them for serialization.
|
||||||
|
|
|
@ -23,59 +23,6 @@
|
||||||
|
|
||||||
namespace CoreTiming {
|
namespace CoreTiming {
|
||||||
|
|
||||||
// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz
|
|
||||||
// The exact value used is of course unverified.
|
|
||||||
constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked
|
|
||||||
|
|
||||||
inline s64 msToCycles(int ms) {
|
|
||||||
// since ms is int there is no way to overflow
|
|
||||||
return BASE_CLOCK_RATE * static_cast<s64>(ms) / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline s64 msToCycles(float ms) {
|
|
||||||
return static_cast<s64>(BASE_CLOCK_RATE * (0.001f) * ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline s64 msToCycles(double ms) {
|
|
||||||
return static_cast<s64>(BASE_CLOCK_RATE * (0.001) * ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline s64 usToCycles(float us) {
|
|
||||||
return static_cast<s64>(BASE_CLOCK_RATE * (0.000001f) * us);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline s64 usToCycles(int us) {
|
|
||||||
return (BASE_CLOCK_RATE * static_cast<s64>(us) / 1000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
s64 usToCycles(s64 us);
|
|
||||||
|
|
||||||
s64 usToCycles(u64 us);
|
|
||||||
|
|
||||||
inline s64 nsToCycles(float ns) {
|
|
||||||
return static_cast<s64>(BASE_CLOCK_RATE * (0.000000001f) * ns);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline s64 nsToCycles(int ns) {
|
|
||||||
return BASE_CLOCK_RATE * static_cast<s64>(ns) / 1000000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
s64 nsToCycles(s64 ns);
|
|
||||||
|
|
||||||
s64 nsToCycles(u64 ns);
|
|
||||||
|
|
||||||
inline u64 cyclesToNs(s64 cycles) {
|
|
||||||
return cycles * 1000000000 / BASE_CLOCK_RATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline s64 cyclesToUs(s64 cycles) {
|
|
||||||
return cycles * 1000000 / BASE_CLOCK_RATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline u64 cyclesToMs(s64 cycles) {
|
|
||||||
return cycles * 1000 / BASE_CLOCK_RATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoreTiming begins at the boundary of timing slice -1. An initial call to Advance() is
|
* CoreTiming begins at the boundary of timing slice -1. An initial call to Advance() is
|
||||||
* required to end slice -1 and start slice 0 before the first cycle of code is executed.
|
* required to end slice -1 and start slice 0 before the first cycle of code is executed.
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <limits>
|
||||||
|
#include "common/logging/log.h"
|
||||||
|
|
||||||
|
namespace CoreTiming {
|
||||||
|
|
||||||
|
constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
|
||||||
|
|
||||||
|
s64 usToCycles(s64 us) {
|
||||||
|
if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
||||||
|
return std::numeric_limits<s64>::max();
|
||||||
|
}
|
||||||
|
if (us > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
||||||
|
return BASE_CLOCK_RATE * (us / 1000000);
|
||||||
|
}
|
||||||
|
return (BASE_CLOCK_RATE * us) / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
s64 usToCycles(u64 us) {
|
||||||
|
if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
||||||
|
return std::numeric_limits<s64>::max();
|
||||||
|
}
|
||||||
|
if (us > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
||||||
|
return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
|
||||||
|
}
|
||||||
|
return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
s64 nsToCycles(s64 ns) {
|
||||||
|
if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
||||||
|
return std::numeric_limits<s64>::max();
|
||||||
|
}
|
||||||
|
if (ns > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
||||||
|
return BASE_CLOCK_RATE * (ns / 1000000000);
|
||||||
|
}
|
||||||
|
return (BASE_CLOCK_RATE * ns) / 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
s64 nsToCycles(u64 ns) {
|
||||||
|
if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_ERROR(Core_Timing, "Integer overflow, use max value");
|
||||||
|
return std::numeric_limits<s64>::max();
|
||||||
|
}
|
||||||
|
if (ns > MAX_VALUE_TO_MULTIPLY) {
|
||||||
|
LOG_DEBUG(Core_Timing, "Time very big, do rounding");
|
||||||
|
return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
|
||||||
|
}
|
||||||
|
return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CoreTiming
|
|
@ -0,0 +1,64 @@
|
||||||
|
// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace CoreTiming {
|
||||||
|
|
||||||
|
// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz
|
||||||
|
// The exact value used is of course unverified.
|
||||||
|
constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked
|
||||||
|
|
||||||
|
inline s64 msToCycles(int ms) {
|
||||||
|
// since ms is int there is no way to overflow
|
||||||
|
return BASE_CLOCK_RATE * static_cast<s64>(ms) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline s64 msToCycles(float ms) {
|
||||||
|
return static_cast<s64>(BASE_CLOCK_RATE * (0.001f) * ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline s64 msToCycles(double ms) {
|
||||||
|
return static_cast<s64>(BASE_CLOCK_RATE * (0.001) * ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline s64 usToCycles(float us) {
|
||||||
|
return static_cast<s64>(BASE_CLOCK_RATE * (0.000001f) * us);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline s64 usToCycles(int us) {
|
||||||
|
return (BASE_CLOCK_RATE * static_cast<s64>(us) / 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
s64 usToCycles(s64 us);
|
||||||
|
|
||||||
|
s64 usToCycles(u64 us);
|
||||||
|
|
||||||
|
inline s64 nsToCycles(float ns) {
|
||||||
|
return static_cast<s64>(BASE_CLOCK_RATE * (0.000000001f) * ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline s64 nsToCycles(int ns) {
|
||||||
|
return BASE_CLOCK_RATE * static_cast<s64>(ns) / 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
s64 nsToCycles(s64 ns);
|
||||||
|
|
||||||
|
s64 nsToCycles(u64 ns);
|
||||||
|
|
||||||
|
inline u64 cyclesToNs(s64 cycles) {
|
||||||
|
return cycles * 1000000000 / BASE_CLOCK_RATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline s64 cyclesToUs(s64 cycles) {
|
||||||
|
return cycles * 1000000 / BASE_CLOCK_RATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline u64 cyclesToMs(s64 cycles) {
|
||||||
|
return cycles * 1000 / BASE_CLOCK_RATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CoreTiming
|
|
@ -14,6 +14,7 @@
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/hle/kernel/errors.h"
|
#include "core/hle/kernel/errors.h"
|
||||||
#include "core/hle/kernel/handle_table.h"
|
#include "core/hle/kernel/handle_table.h"
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/hle/kernel/handle_table.h"
|
#include "core/hle/kernel/handle_table.h"
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
#include "core/hle/kernel/thread.h"
|
#include "core/hle/kernel/thread.h"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/hle/ipc_helpers.h"
|
#include "core/hle/ipc_helpers.h"
|
||||||
#include "core/hle/kernel/event.h"
|
#include "core/hle/kernel/event.h"
|
||||||
#include "core/hle/kernel/hle_ipc.h"
|
#include "core/hle/kernel/hle_ipc.h"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/hle/ipc_helpers.h"
|
#include "core/hle/ipc_helpers.h"
|
||||||
#include "core/hle/kernel/event.h"
|
#include "core/hle/kernel/event.h"
|
||||||
#include "core/hle/kernel/hle_ipc.h"
|
#include "core/hle/kernel/hle_ipc.h"
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/frontend/emu_window.h"
|
#include "core/frontend/emu_window.h"
|
||||||
#include "core/frontend/input.h"
|
#include "core/frontend/input.h"
|
||||||
#include "core/hle/ipc_helpers.h"
|
#include "core/hle/ipc_helpers.h"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
|
#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
|
||||||
#include "core/hle/service/nvdrv/nvdrv.h"
|
#include "core/hle/service/nvdrv/nvdrv.h"
|
||||||
#include "core/hle/service/nvflinger/buffer_queue.h"
|
#include "core/hle/service/nvflinger/buffer_queue.h"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/core_timing_util.h"
|
||||||
#include "core/hle/ipc_helpers.h"
|
#include "core/hle/ipc_helpers.h"
|
||||||
#include "core/hle/kernel/client_port.h"
|
#include "core/hle/kernel/client_port.h"
|
||||||
#include "core/hle/kernel/client_session.h"
|
#include "core/hle/kernel/client_session.h"
|
||||||
|
|
Reference in New Issue