benchmark/cmake/pthread_affinity.cpp
Yingwei Zheng 3b19d7222d
Fix CPU frequency estimation on riscv (#1549)
* Fix CPU frequency estimation on riscv

* Cleanup code for CPU frequency estimation

* Fix use before definition of the macro

* Move the platform definitions back

* Fix compilation error on windows

* Remove unused sleep.h and sleep.cc
2023-02-21 11:30:28 +00:00

17 lines
389 B
C++

#include <pthread.h>
int main() {
cpu_set_t set;
CPU_ZERO(&set);
for (int i = 0; i < CPU_SETSIZE; ++i) {
CPU_SET(i, &set);
CPU_CLR(i, &set);
}
pthread_t self = pthread_self();
int ret;
ret = pthread_getaffinity_np(self, sizeof(set), &set);
if (ret != 0) return ret;
ret = pthread_setaffinity_np(self, sizeof(set), &set);
if (ret != 0) return ret;
return 0;
}