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

Fix sum bux #9690

Merged
merged 4 commits into from Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 33 additions & 26 deletions rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -2265,7 +2265,7 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
if (!src)
{
ppu_log.error("Failed to decrypt '%s'", path);
continue;
continue;
}

elf_error prx_err{}, ovl_err{};
Expand All @@ -2289,7 +2289,7 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
// Log error
prx_err = elf_error::header_type;
}

if (const ppu_exec_object obj = src; (ovl_err = obj, obj == elf_error::ok))
{
while (ovl_err == elf_error::ok)
Expand Down Expand Up @@ -2758,38 +2758,40 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
break;
}

globals.emplace_back(fmt::format("__mptr%x", suffix), reinterpret_cast<u64>(vm::g_base_addr));
globals.emplace_back(fmt::format("__cptr%x", suffix), reinterpret_cast<u64>(vm::g_exec_addr));

// Initialize segments for relocations
for (u32 i = 0, num = 0; i < info.segs.size(); i++)
if (!check_only)
{
if (!info.segs[i].addr) continue;
globals.emplace_back(fmt::format("__seg%u_%x", num++, suffix), info.segs[i].addr);
}
globals.emplace_back(fmt::format("__mptr%x", suffix), reinterpret_cast<u64>(vm::g_base_addr));
globals.emplace_back(fmt::format("__cptr%x", suffix), reinterpret_cast<u64>(vm::g_exec_addr));

link_workload.emplace_back(obj_name, false);
// Initialize segments for relocations
for (u32 i = 0, num = 0; i < info.segs.size(); i++)
{
if (!info.segs[i].addr) continue;
globals.emplace_back(fmt::format("__seg%u_%x", num++, suffix), info.segs[i].addr);
}

link_workload.emplace_back(obj_name, false);
}

// Check object file
if (jit_compiler::check(cache_path + obj_name))
{
if (!jit && !check_only)
{
ppu_log.success("LLVM: Module exists: %s", obj_name);
continue;
}

continue;
}

// Remember, used in ppu_initialize(void)
compiled_new = true;

if (check_only)
{
return true;
}

// Remember, used in ppu_initialize(void)
compiled_new = true;

// Adjust information (is_compiled)
link_workload.back().second = true;

Expand All @@ -2800,6 +2802,11 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
g_progr_ptotal++;
}

if (check_only)
{
return false;
}

// Create worker threads for compilation (TODO: how many threads)
{
u32 thread_count = Emu.GetMaxThreads();
Expand All @@ -2822,26 +2829,26 @@ bool ppu_initialize(const ppu_module& info, bool check_only)
// Set low priority
thread_ctrl::scoped_priority low_prio(-1);

for (u32 i = work_cv++; i < workload.size(); i = work_cv++)
for (u32 i = work_cv++; i < workload.size(); i = work_cv++, g_progr_pdone++)
{
if (Emu.IsStopped())
{
continue;
}

// Keep allocating workload
const auto [obj_name, part] = std::as_const(workload)[i];

// Allocate "core"
std::lock_guard jlock(g_fxo->get<jit_core_allocator>()->sem);

if (!Emu.IsStopped())
{
ppu_log.warning("LLVM: Compiling module %s%s", cache_path, obj_name);

// Use another JIT instance
jit_compiler jit2({}, g_cfg.core.llvm_cpu, 0x1);
ppu_initialize2(jit2, part, cache_path, obj_name);
ppu_log.warning("LLVM: Compiling module %s%s", cache_path, obj_name);

ppu_log.success("LLVM: Compiled module %s", obj_name);
}
// Use another JIT instance
jit_compiler jit2({}, g_cfg.core.llvm_cpu, 0x1);
ppu_initialize2(jit2, part, cache_path, obj_name);

g_progr_pdone++;
ppu_log.success("LLVM: Compiled module %s", obj_name);
}
});

Expand Down
6 changes: 1 addition & 5 deletions rpcs3/Emu/Cell/SPURecompiler.cpp
Expand Up @@ -457,13 +457,12 @@ void spu_cache::initialize()
std::vector<be_t<u32>> ls(0x10000);

// Build functions
for (usz func_i = fnext++; func_i < func_list.size(); func_i = fnext++)
for (usz func_i = fnext++; func_i < func_list.size(); func_i = fnext++, g_progr_pdone++)
{
const spu_program& func = std::as_const(func_list)[func_i];

if (Emu.IsStopped() || fail_flag)
{
g_progr_pdone++;
continue;
}

Expand All @@ -489,7 +488,6 @@ void spu_cache::initialize()
(inverse_bounds && (hash_start < g_cfg.core.spu_llvm_lower_bound && hash_start > g_cfg.core.spu_llvm_upper_bound)))
{
spu_log.error("[Debug] Skipped function %s", fmt::base57(hash_start));
g_progr_pdone++;
result++;
continue;
}
Expand All @@ -516,8 +514,6 @@ void spu_cache::initialize()
// Clear fake LS
std::memset(ls.data() + start / 4, 0, 4 * (size0 - 1));

g_progr_pdone++;

result++;
}

Expand Down
19 changes: 12 additions & 7 deletions rpcs3/Emu/System.cpp
Expand Up @@ -372,12 +372,17 @@ namespace
// Update progress
while (thread_ctrl::state() != thread_state::aborting)
{
if (ftotal != g_progr_ftotal || fdone != g_progr_fdone || ptotal != g_progr_ptotal || pdone != g_progr_pdone)
const u32 ftotal_new = g_progr_ftotal;
const u32 fdone_new = g_progr_fdone;
const u32 ptotal_new = g_progr_ptotal;
const u32 pdone_new = g_progr_pdone;

if (ftotal != ftotal_new || fdone != fdone_new || ptotal != ptotal_new || pdone != pdone_new)
{
ftotal = g_progr_ftotal;
fdone = g_progr_fdone;
ptotal = g_progr_ptotal;
pdone = g_progr_pdone;
ftotal = ftotal_new;
fdone = fdone_new;
ptotal = ptotal_new;
pdone = pdone_new;
Copy link
Contributor

@elad335 elad335 Jan 31, 2021

Choose a reason for hiding this comment

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

Not a race but then again there's nothing wrong here as well, but its a good practice to avoid redundent atomic reads.


// Compute new progress in percents
const u32 total = ftotal + ptotal;
Expand Down Expand Up @@ -418,9 +423,9 @@ namespace
}

// Cleanup
g_progr_ftotal -= fdone;
g_progr_ftotal -= ftotal;
g_progr_fdone -= fdone;
g_progr_ptotal -= pdone;
g_progr_ptotal -= ptotal;
g_progr_pdone -= pdone;

if (dlg)
Expand Down