2010-06-24 14:13:45 +00:00
|
|
|
/*
|
2019-08-03 05:10:55 +02:00
|
|
|
* Copyright (C) 2010-2013 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
|
* Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
2010-06-24 14:13:45 +00:00
|
|
|
|
|
|
|
|
#ifdef WAF_BUILD
|
|
|
|
|
#include "libpbd-config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-08-04 16:26:26 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2010-06-24 14:13:45 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
|
#include <unistd.h>
|
2025-02-01 11:19:16 +01:00
|
|
|
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
2013-01-30 12:32:53 +00:00
|
|
|
#include <stddef.h>
|
2010-06-24 14:13:45 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/sysctl.h>
|
2014-12-23 17:43:02 +02:00
|
|
|
#elif defined(PLATFORM_WINDOWS)
|
2014-12-23 23:06:46 +01:00
|
|
|
#include <windows.h>
|
2010-06-24 14:13:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "pbd/cpus.h"
|
|
|
|
|
|
2025-12-05 16:00:09 +01:00
|
|
|
#if defined(COMPILER_MSVC) && !defined(__PTW32_VERSION)
|
|
|
|
|
#include <ardourext/pthread.h> // Gets us '__PTW32_VERSION'
|
2014-10-08 15:00:51 +01:00
|
|
|
#endif
|
|
|
|
|
|
2025-08-15 21:51:22 +02:00
|
|
|
int32_t
|
2025-08-15 22:10:31 +02:00
|
|
|
PBD::max_mmcss_threads_per_process ()
|
2025-08-15 21:51:22 +02:00
|
|
|
{
|
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
|
DWORD dwType = REG_DWORD;
|
|
|
|
|
DWORD dwSize = 4;
|
|
|
|
|
int32_t rv = 32;
|
|
|
|
|
HKEY hKey;
|
|
|
|
|
if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion\\Multimedia\\SystemProfile", 0, KEY_READ, &hKey)) {
|
|
|
|
|
if (ERROR_SUCCESS == RegQueryValueExA (hKey, "MaxThreadsPerProcess", 0, &dwType, (LPBYTE)&rv, &dwSize)) {
|
|
|
|
|
if (dwType == REG_DWORD && dwSize == 4) {
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 32;
|
|
|
|
|
#else
|
|
|
|
|
return INT32_MAX;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-24 14:13:45 +00:00
|
|
|
uint32_t
|
2025-08-15 22:10:31 +02:00
|
|
|
PBD::hardware_concurrency()
|
2010-06-24 14:13:45 +00:00
|
|
|
{
|
2019-07-26 16:44:29 +02:00
|
|
|
if (getenv("ARDOUR_CONCURRENCY")) {
|
|
|
|
|
int c = atoi (getenv("ARDOUR_CONCURRENCY"));
|
2017-08-04 16:26:26 +02:00
|
|
|
if (c > 0) {
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-05 16:00:09 +01:00
|
|
|
#if defined(__PTW32_VERSION) || defined(__hpux)
|
2017-08-04 16:26:37 +02:00
|
|
|
return pthread_num_processors_np();
|
2016-06-26 16:43:07 +02:00
|
|
|
#elif defined(__APPLE__)
|
2017-08-04 16:26:37 +02:00
|
|
|
int count;
|
|
|
|
|
size_t size=sizeof(count);
|
2019-04-12 18:30:52 +02:00
|
|
|
# ifdef MIXBUS
|
2025-11-12 01:52:10 +01:00
|
|
|
return sysctlbyname ("hw.logicalcpu", &count, &size, NULL, 0) ? 1 : count;
|
2019-04-12 18:30:52 +02:00
|
|
|
# else
|
2025-11-12 01:52:10 +01:00
|
|
|
return sysctlbyname ("hw.physicalcpu", &count, &size, NULL, 0) ? 1 :count;
|
2019-04-12 18:30:52 +02:00
|
|
|
# endif
|
2016-06-26 16:43:07 +02:00
|
|
|
#elif defined(__FreeBSD__)
|
2017-08-04 16:26:37 +02:00
|
|
|
int count;
|
|
|
|
|
size_t size=sizeof(count);
|
2025-11-12 01:52:10 +01:00
|
|
|
return sysctlbyname ("hw.ncpu", &count, &size, NULL, 0) ? 1 : count;
|
2025-11-09 20:22:33 +01:00
|
|
|
#elif defined(HAVE_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
|
2025-11-12 01:52:10 +01:00
|
|
|
int const count = sysconf (_SC_NPROCESSORS_ONLN);
|
|
|
|
|
return count > 1 ? count : 1;
|
2014-12-23 17:43:02 +02:00
|
|
|
#elif defined(PLATFORM_WINDOWS)
|
2017-08-04 16:26:37 +02:00
|
|
|
SYSTEM_INFO sys_info;
|
2025-11-12 01:52:10 +01:00
|
|
|
GetSystemInfo (&sys_info);
|
2017-08-04 16:26:37 +02:00
|
|
|
return sys_info.dwNumberOfProcessors;
|
2010-06-24 14:13:45 +00:00
|
|
|
#else
|
2025-11-12 01:52:10 +01:00
|
|
|
return 1;
|
2010-06-24 14:13:45 +00:00
|
|
|
#endif
|
|
|
|
|
}
|