diff --git a/gfx/filter.c b/gfx/filter.c index 1298b2cbb8..55e81f5e96 100644 --- a/gfx/filter.c +++ b/gfx/filter.c @@ -156,7 +156,7 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path, filt->max_height = max_height; filt->impl_data = filt->impl->create(input_fmt, input_fmt, max_width, max_height, - threads != RARCH_SOFTFILTER_THREADS_AUTO ? threads : 1, cpu_features); + threads != RARCH_SOFTFILTER_THREADS_AUTO ? threads : rarch_get_cpu_cores(), cpu_features); if (!filt->impl_data) { RARCH_ERR("Failed to create softfilter state.\n"); @@ -170,6 +170,8 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path, goto error; } + RARCH_LOG("Using %u threads for softfilter.\n", threads); + filt->packets = (struct softfilter_work_packet*)calloc(threads, sizeof(*filt->packets)); if (!filt->packets) { diff --git a/performance.c b/performance.c index b5054d5919..53b87dd574 100644 --- a/performance.c +++ b/performance.c @@ -71,6 +71,10 @@ #include #endif +#if defined(BSD) || defined(__APPLE__) +#include +#endif + #include #define MAX_COUNTERS 64 @@ -289,6 +293,40 @@ static void arm_enable_runfast_mode(void) } #endif +unsigned rarch_get_cpu_cores(void) +{ +#if defined(_WIN32) && !defined(_XBOX) // Win32 + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +#elif defined(_SC_NPROCESSORS_ONLN) // Linux, most unix-likes. + long ret = sysconf(_SC_NPROCESSORS_ONLN); + if (ret <= 0) + return 1; + return ret; +#elif defined(BSD) || defined(__APPLE__) // BSD + // Copypasta from stackoverflow, dunno if it works. + int num_cpu = 0; + int mib[4]; + size_t len = sizeof(num_cpu); + + mib[0] = CTL_HW; + mib[1] = HW_AVAILCPU; + sysctl(mib, 2, &num_cpu, &len, NULL, 0); + if (num_cpu < 1) + { + mib[1] = HW_NCPU; + sysctl(mib, 2, &num_cpu, &len, NULL, 0); + if (num_cpu < 1) + num_cpu = 1; + } + return num_cpu; +#else + // No idea, assume single core. + return 1; +#endif +} + uint64_t rarch_get_cpu_features(void) { uint64_t cpu = 0; diff --git a/performance.h b/performance.h index d4db324964..fb6dbe1c2c 100644 --- a/performance.h +++ b/performance.h @@ -55,6 +55,7 @@ static inline void rarch_perf_stop(struct retro_perf_counter *perf) } uint64_t rarch_get_cpu_features(void); +unsigned rarch_get_cpu_cores(void); // Used internally by RetroArch. #if defined(PERF_TEST) || !defined(RARCH_INTERNAL)