" -c, --segment-size=NUM Size in MB to cache from the wordfile",
" --bitmap-min=NUM Minimum number of bits allowed for bitmaps",
" --bitmap-max=NUM Maximum number of bits allowed for bitmaps",
- #ifndef OSX
" --cpu-affinity=STR Locks to CPU devices, separate with comma",
- #else
- " --cpu-affinity=STR Locks to CPU devices, separate with comma (disabled on OSX)",
- #endif
" --opencl-platforms=STR OpenCL platforms to use, separate with comma",
" -d, --opencl-devices=STR OpenCL devices to use, separate with comma",
" --opencl-device-types=STR OpenCL device-types to use, separate with comma, see references below",
uint increment = INCREMENT;
uint increment_min = INCREMENT_MIN;
uint increment_max = INCREMENT_MAX;
- #ifndef OSX
char *cpu_affinity = NULL;
- #endif
OCL_PTR *ocl = NULL;
char *opencl_devices = NULL;
char *opencl_platforms = NULL;
{"markov-classic", no_argument, 0, IDX_MARKOV_CLASSIC},
{"markov-threshold", required_argument, 0, IDX_MARKOV_THRESHOLD},
{"markov-hcstat", required_argument, 0, IDX_MARKOV_HCSTAT},
- #ifndef OSX
{"cpu-affinity", required_argument, 0, IDX_CPU_AFFINITY},
- #endif
{"opencl-devices", required_argument, 0, IDX_OPENCL_DEVICES},
{"opencl-platforms", required_argument, 0, IDX_OPENCL_PLATFORMS},
{"opencl-device-types", required_argument, 0, IDX_OPENCL_DEVICE_TYPES},
case IDX_HEX_CHARSET: hex_charset = 1; break;
case IDX_HEX_SALT: hex_salt = 1; break;
case IDX_HEX_WORDLIST: hex_wordlist = 1; break;
- #ifndef OSX
case IDX_CPU_AFFINITY: cpu_affinity = optarg; break;
- #endif
case IDX_OPENCL_DEVICES: opencl_devices = optarg; break;
case IDX_OPENCL_PLATFORMS: opencl_platforms = optarg; break;
case IDX_OPENCL_DEVICE_TYPES:
* cpu affinity
*/
- #ifndef OSX
if (cpu_affinity)
{
set_cpu_affinity (cpu_affinity);
}
- #endif
if (rp_gen_seed_chgd == 0)
{
logfile_top_uint64 (limit);
logfile_top_uint64 (skip);
logfile_top_char (separator);
- #ifndef OSX
logfile_top_string (cpu_affinity);
- #endif
logfile_top_string (custom_charset_1);
logfile_top_string (custom_charset_2);
logfile_top_string (custom_charset_3);
myfree (buf);
}
+#ifdef OSX
+int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set)
+{
+ int core;
+
+ for (core = 0; core < (8 * (int)cpu_size); core++)
+ if (CPU_ISSET(core, cpu_set)) break;
+
+ thread_affinity_policy_data_t policy = { core };
+
+ const int rc = thread_policy_set (pthread_mach_thread_np (thread), THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, 1);
+
+ if (data.quiet == 0)
+ {
+ if (rc != KERN_SUCCESS)
+ {
+ log_error ("ERROR: %s : %d", "thread_policy_set()", rc);
+ }
+ }
+
+ return rc;
+}
+#endif
+
void set_cpu_affinity (char *cpu_affinity)
{
#ifdef WIN
DWORD_PTR aff_mask = 0;
- #elif LINUX
+ #elif _POSIX
cpu_set_t cpuset;
CPU_ZERO (&cpuset);
#endif
{
#ifdef WIN
aff_mask = 0;
- #elif LINUX
+ #elif _POSIX
CPU_ZERO (&cpuset);
#endif
#ifdef WIN
aff_mask |= 1 << (cpu_id - 1);
- #elif LINUX
+ #elif _POSIX
CPU_SET ((cpu_id - 1), &cpuset);
#endif
#ifdef WIN
SetProcessAffinityMask (GetCurrentProcess (), aff_mask);
SetThreadAffinityMask (GetCurrentThread (), aff_mask);
- #elif LINUX
+ #elif _POSIX
pthread_t thread = pthread_self ();
pthread_setaffinity_np (thread, sizeof (cpu_set_t), &cpuset);
#endif