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 minor issue with usage of STL thread::hardware_concurrency() #9672

Merged
merged 1 commit into from Jan 29, 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
2 changes: 1 addition & 1 deletion Utilities/Thread.cpp
Expand Up @@ -2518,7 +2518,7 @@ u64 thread_ctrl::get_affinity_mask(thread_class group)
{
detect_cpu_layout();

if (const auto thread_count = std::thread::hardware_concurrency())
if (const auto thread_count = utils::get_thread_count())
{
const u64 all_cores_mask = process_affinity_mask;

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -2130,7 +2130,7 @@ extern void ppu_initialize(const ppu_module& info)

static s32 limit()
{
return static_cast<s32>(std::thread::hardware_concurrency());
return static_cast<s32>(utils::get_thread_count());
}
};

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPURecompiler.cpp
Expand Up @@ -9035,7 +9035,7 @@ struct spu_llvm

u32 worker_count = 1;

if (uint hc = std::thread::hardware_concurrency(); hc >= 12)
if (uint hc = utils::get_thread_count(); hc >= 12)
{
worker_count = hc - 10;
}
Expand Down
4 changes: 3 additions & 1 deletion rpcs3/Emu/RSX/GL/GLPipelineCompiler.cpp
Expand Up @@ -4,6 +4,8 @@

#include <thread>

#include "util/sysinfo.hpp"

namespace gl
{
// Global list of worker threads
Expand Down Expand Up @@ -97,7 +99,7 @@ namespace gl
if (num_worker_threads == 0)
{
// Select optimal number of compiler threads
const auto hw_threads = std::thread::hardware_concurrency();
const auto hw_threads = utils::get_thread_count();
if (hw_threads > 12)
{
num_worker_threads = 6;
Expand Down
4 changes: 3 additions & 1 deletion rpcs3/Emu/RSX/VK/VKPipelineCompiler.cpp
Expand Up @@ -6,6 +6,8 @@

#include <thread>

#include "util/sysinfo.hpp"

namespace vk
{
// Global list of worker threads
Expand Down Expand Up @@ -186,7 +188,7 @@ namespace vk
if (num_worker_threads == 0)
{
// Select optimal number of compiler threads
const auto hw_threads = std::thread::hardware_concurrency();
const auto hw_threads = utils::get_thread_count();
if (hw_threads > 12)
{
num_worker_threads = 6;
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/RSX/rsx_cache.h
Expand Up @@ -16,6 +16,7 @@
#include <unordered_map>

#include "util/vm.hpp"
#include "util/sysinfo.hpp"

namespace rsx
{
Expand Down Expand Up @@ -628,7 +629,7 @@ namespace rsx

// Preload everything needed to compile the shaders
unpacked_type unpacked;
uint nb_workers = g_cfg.video.renderer == video_renderer::vulkan ? std::thread::hardware_concurrency() : 1;
uint nb_workers = g_cfg.video.renderer == video_renderer::vulkan ? utils::get_thread_count() : 1;

load_shaders(nb_workers, unpacked, directory_path, entries, entry_count, dlg);

Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/System.cpp
Expand Up @@ -2023,7 +2023,8 @@ std::string Emulator::GetFormattedTitle(double fps) const
u32 Emulator::GetMaxThreads() const
{
const u32 max_threads = static_cast<u32>(g_cfg.core.llvm_threads);
const u32 thread_count = max_threads > 0 ? std::min(max_threads, std::thread::hardware_concurrency()) : std::thread::hardware_concurrency();
const u32 hw_threads = utils::get_thread_count();
const u32 thread_count = max_threads > 0 ? std::min(max_threads, hw_threads) : hw_threads;
return thread_count;
}

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/settings_dialog.cpp
Expand Up @@ -1145,9 +1145,9 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> gui_settings, std

// Comboboxes

m_emu_settings->EnhanceComboBox(ui->maxLLVMThreads, emu_settings_type::MaxLLVMThreads, true, true, std::thread::hardware_concurrency());
m_emu_settings->EnhanceComboBox(ui->maxLLVMThreads, emu_settings_type::MaxLLVMThreads, true, true, utils::get_thread_count());
SubscribeTooltip(ui->gb_max_llvm, tooltips.settings.max_llvm_threads);
ui->maxLLVMThreads->setItemText(ui->maxLLVMThreads->findData(0), tr("All (%1)", "Max LLVM threads").arg(std::thread::hardware_concurrency()));
ui->maxLLVMThreads->setItemText(ui->maxLLVMThreads->findData(0), tr("All (%1)", "Max LLVM threads").arg(utils::get_thread_count()));

m_emu_settings->EnhanceComboBox(ui->perfOverlayDetailLevel, emu_settings_type::PerfOverlayDetailLevel);
SubscribeTooltip(ui->perf_overlay_detail_level, tooltips.settings.perf_overlay_detail_level);
Expand Down
13 changes: 9 additions & 4 deletions rpcs3/util/sysinfo.cpp
Expand Up @@ -409,13 +409,18 @@ u64 utils::get_total_memory()

u32 utils::get_thread_count()
{
static const u32 g_count = []()
{
#ifdef _WIN32
::SYSTEM_INFO sysInfo;
::GetNativeSystemInfo(&sysInfo);
return sysInfo.dwNumberOfProcessors;
::SYSTEM_INFO sysInfo;
::GetNativeSystemInfo(&sysInfo);
return sysInfo.dwNumberOfProcessors;
#else
return ::sysconf(_SC_NPROCESSORS_ONLN);
return ::sysconf(_SC_NPROCESSORS_ONLN);
#endif
}();

return g_count;
}

u32 utils::get_cpu_family()
Expand Down