Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make memory breakpoint faster #4961

Merged
merged 2 commits into from Mar 2, 2017
Merged

Conversation

aldelaro5
Copy link
Member

@aldelaro5 aldelaro5 commented Feb 25, 2017

Currently, slowmem is used at any time that memory breakpoints are in use. This commit makes it so that whenever the DBAT gets updated, if the address is overllaping any memchecks, it forces the use of slowmem. This allows to keep fastmem for any other cases and noticably increases performance when using memory breakpoints.

I did some practical tests on Rs2 and basically, here's an estimate of my observation (I just checked the FPS)

Without this optimisation: around 30-35% decrease when using memory breakpoints.
With this optimisation: around 10-15% decrease when using memory breakpoints.

Please note that I cannot rebase this because of some issues that happened from 5.0-2021 (the report is here: https://bugs.dolphin-emu.org/issues/10117 ). If I would rebase, no breakpoints including memory breakpoints would works properly since it's likely to get crashes. I had to go rebase back to 5.0-2012 and then add my commit on top of it so I can actually test it (I confirmed that the issues were regressions and weren't caused by my code, it's unrelated problems).

Because of this, I am not sure if this is okay to be merged until it's tested to a further revision, but it should be fine for tests and review.

EDIT: since #4983 has been merged, I could rebase this and it can now be reviewed, tested and potentially merged.

Tagging @degasus here who helped me do this just to know if it looks fine.

@@ -1175,6 +1195,8 @@ static void UpdateBATs(BatTable& bat_table, u32 base_spr)
valid_bit = 0x3;
else if ((address >> 28) == 0xE && (address < (0xE0000000 + Memory::L1_CACHE_SIZE)))
valid_bit = 0x3;
if (overlaps_memcheck(address | ((1 << BAT_INDEX_SHIFT) - 1)))

This comment was marked as off-topic.

This comment was marked as off-topic.

u32 page_end_suffix = ((1 << BAT_INDEX_SHIFT)) - 1;
for (TMemCheck memcheck : memchecks.GetMemChecks())
{
u32 memcheck_region_page_start = 0x00FFFFFF & memcheck.start_address;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

jo.memcheck = SConfig::GetInstance().bMMU || any_watchpoints;
jo.alwaysUseMemFuncs = any_watchpoints;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -171,6 +173,9 @@ void MemChecks::Add(const TMemCheck& memory_check)
bool had_any = HasAny();
if (GetMemCheck(memory_check.start_address) == nullptr)
m_mem_checks.push_back(memory_check);
bool lock = Core::PauseAndLock(true);
PowerPC::DBATUpdated();
Core::PauseAndLock(false, lock);

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

Currently, slowmem is used at any time that memory breakpoints are in use.  This commit makes it so that whenever the DBAT gets updated, if the address is overllaping any memchecks, it forces the use of slowmem.  This allows to keep fastmem for any other cases and noticably increases performance when using memory breakpoints.
@aldelaro5 aldelaro5 force-pushed the fast-memchecks branch 2 times, most recently from 3e6cc5f to d5268ea Compare March 2, 2017 09:16
Copy link
Member

@degasus degasus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpicks, else LGTM

// watchpoint-compatible code.
if (!had_any && g_jit)
g_jit->GetBlockCache()->SchedulateClearCacheThreadSafe();
bool lock = Core::PauseAndLock(true);

This comment was marked as off-topic.

@@ -184,8 +191,11 @@ void MemChecks::Remove(u32 address)
if (i->start_address == address)
{
m_mem_checks.erase(i);
bool lock = Core::PauseAndLock(true);

This comment was marked as off-topic.

@@ -1191,6 +1191,9 @@ static void UpdateBATs(BatTable& bat_table, u32 base_spr)
valid_bit = 0x3;
else if ((address >> 28) == 0xE && (address < (0xE0000000 + Memory::L1_CACHE_SIZE)))
valid_bit = 0x3;
if (PowerPC::memchecks.OverlapsMemcheck(((batu.BEPI | j) << BAT_INDEX_SHIFT),

This comment was marked as off-topic.

Currently, slowmem is used at any time that memory breakpoints are in use.  This commit makes it so that whenever the DBAT gets updated, if the address is overllaping any memchecks, it forces the use of slowmem.  This allows to keep fastmem for any other cases and noticably increases performance when using memory breakpoints.
@degasus degasus merged commit 521a777 into dolphin-emu:master Mar 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants