add -m coremask option

This commit is contained in:
Ryo Nakamura
2022-11-15 19:57:53 +09:00
parent 0421172778
commit a69115a4dc
4 changed files with 124 additions and 8 deletions

View File

@@ -24,6 +24,14 @@ int nr_cpus()
return n;
}
int set_thread_affinity(pthread_t tid, int core)
{
errno = ENOTSUP;
pr_err("setting thread afinity is not implemented on apple\n");
return -1;
}
#endif
#ifdef linux
@@ -34,5 +42,19 @@ int nr_cpus()
return CPU_COUNT(&cpu_set);
return -1;
}
int set_thread_affinity(pthread_t tid, int core)
{
cpu_set_t target_cpu_set;
int ret = 0;
CPU_ZERO(&target_cpu_set);
CPU_SET(core, &target_cpu_set);
ret = pthread_setaffinity_np(tid, sizeof(target_cpu_set), &target_cpu_set);
if (ret < 0)
pr_err("failed to set thread/cpu affinity for core %d: %s",
core, strerrno());
return ret;
}
#endif