Use pthread_setaffinity_np

On some systems, pthread_addr_setaffinity_np does not exist, so we need
to use pthread_setaffinity_np on thread after pthread_create

Provided by Julian Samaroo on github

https: //github.com/RadeonOpenCompute/ROCR-Runtime/pull/143
Change-Id: I4649f94333f2d7b0a5993b370a4bfc48d92acecb
这个提交包含在:
David Yat Sin
2023-12-01 20:42:33 +00:00
父节点 9b2ed66609
当前提交 6333fdecf3
+20 -20
查看文件
@@ -110,26 +110,7 @@ class os_thread {
return;
}
}
if (core::Runtime::runtime_singleton_->flag().override_cpu_affinity()) {
int cores = get_nprocs_conf();
cpu_set_t* cpuset = CPU_ALLOC(cores);
if (cpuset == nullptr) {
fprintf(stderr, "CPU_ALLOC failed: %s\n", strerror(errno));
return;
}
CPU_ZERO_S(CPU_ALLOC_SIZE(cores), cpuset);
for (int i = 0; i < cores; i++) {
CPU_SET_S(i, CPU_ALLOC_SIZE(cores), cpuset);
}
err = pthread_attr_setaffinity_np(&attrib, CPU_ALLOC_SIZE(cores), cpuset);
CPU_FREE(cpuset);
if (err != 0) {
fprintf(stderr, "pthread_attr_setaffinity_np failed: %s\n", strerror(err));
return;
}
}
\
err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get());
// Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN
@@ -148,6 +129,25 @@ class os_thread {
}
}
if (core::Runtime::runtime_singleton_->flag().override_cpu_affinity()) {
int cores = get_nprocs_conf();
cpu_set_t* cpuset = CPU_ALLOC(cores);
if (cpuset == nullptr) {
fprintf(stderr, "CPU_ALLOC failed: %s\n", strerror(errno));
return;
}
CPU_ZERO_S(CPU_ALLOC_SIZE(cores), cpuset);
for (int i = 0; i < cores; i++) {
CPU_SET_S(i, CPU_ALLOC_SIZE(cores), cpuset);
}
err = pthread_setaffinity_np(thread, CPU_ALLOC_SIZE(cores), cpuset);
CPU_FREE(cpuset);
if (err != 0) {
fprintf(stderr, "pthread_attr_setaffinity_np failed: %s\n", strerror(err));
return;
}
}
if (err == 0)
args.release();
else