168 #ifdef HAVE_PTHREAD_SETAFFINITY_NP
171 #include <sys/param.h>
172 #include <sys/cpuset.h>
173 #include <pthread_np.h>
174 typedef cpuset_t cpu_set_t;
192 static inline int int_rem(
int a,
unsigned int b)
198 int ret = (a % int_b) + int_b;
199 return ret >= int_b ? (ret - int_b) : ret;
204 #ifdef HAVE_PTHREAD_SETAFFINITY_NP
205 int i, num_cores = 0;
208 int ret = pthread_getaffinity_np(native_thread,
sizeof(cpu_set_t), &cpuset);
211 for (i = 0; i < CPU_SETSIZE; i++) {
212 if (CPU_ISSET(i, &cpuset)) {
216 *p_num_cores = num_cores;
226 #ifdef HAVE_PTHREAD_SETAFFINITY_NP
228 int ret = pthread_getaffinity_np(native_thread,
sizeof(cpu_set_t), &cpuset);
231 int i, j, num_cpuids = 0;
232 for (i = 0; i < CPU_SETSIZE; i++) {
233 if (CPU_ISSET(i, &cpuset))
239 for (i = 0, j = 0; i < CPU_SETSIZE; i++) {
240 if (CPU_ISSET(i, &cpuset))
241 p_cpuset->
cpuids[j++] = i;
250 int *cpuids,
int *p_num_cpuids)
252 #ifdef HAVE_PTHREAD_SETAFFINITY_NP
254 int ret = pthread_getaffinity_np(native_thread,
sizeof(cpu_set_t), &cpuset);
257 int i, num_cpuids = 0;
258 for (i = 0; i < CPU_SETSIZE; i++) {
259 if (CPU_ISSET(i, &cpuset)) {
260 if (num_cpuids < max_cpuids) {
261 cpuids[num_cpuids] = i;
266 *p_num_cpuids = num_cpuids;
276 #ifdef HAVE_PTHREAD_SETAFFINITY_NP
289 int ret = pthread_setaffinity_np(native_thread,
sizeof(cpu_set_t), &cpuset);
301 pthread_t self_native_thread = pthread_self();
315 if (p_list->
num == 0) {
327 for (i = 0; i < p_list->
num; i++) {
329 uint32_t j, num_cpuids = 0, len_cpuids = 8;
334 for (j = 0; j < p_id_list->
num; j++) {
341 for (k = 0; k < num_cpuids; k++) {
348 if (num_cpuids == len_cpuids) {
350 sizeof(
int) * len_cpuids * 2,
362 if (num_cpuids != len_cpuids) {
364 sizeof(
int) * num_cpuids,
406 pthread_t self_native_thread = pthread_self();
429 int max_cpuids,
int *cpuids,