void setup_extra_threads(void *(*handler)(void *));
void wait_for_threads_completion();
void set_thread_cpu_affinity();
+void thread_bind_to_cpu_map(uint tgrp, uint ltid);
unsigned long long ha_get_pthread_id(unsigned int thr);
extern volatile unsigned int rdv_requests;
#endif
}
-/* Tries to set the current thread's CPU affinity according to the cpu_map */
-void set_thread_cpu_affinity()
+/* Tries to bind the current thread to the CPUs the cpu_map assigns to
+ * the provided thread and thread group.
+ */
+void thread_bind_to_cpu_map(uint tgrp, uint ltid)
{
#if defined(USE_CPU_AFFINITY)
- /* no affinity setting for the master process */
- if (master)
- return;
-
- /* Now the CPU affinity for all threads */
- if (ha_cpuset_count(&cpu_map[tgid - 1].thread[ti->ltid])) {/* only do this if the thread has a THREAD map */
+ if (ha_cpuset_count(&cpu_map[tgrp].thread[ltid])) {/* only do this if the thread has a THREAD map */
# if defined(__APPLE__)
/* Note: this API is limited to the first 32/64 CPUs */
- unsigned long set = cpu_map[tgid - 1].thread[ti->ltid].cpuset;
+ unsigned long set = cpu_map[tgrp].thread[ltid].cpuset;
int j;
while ((j = ffsl(set)) > 0) {
set &= ~(1UL << (j - 1));
}
# else
- struct hap_cpuset *set = &cpu_map[tgid - 1].thread[ti->ltid];
+ struct hap_cpuset *set = &cpu_map[tgrp].thread[ltid];
pthread_setaffinity_np(pthread_self(), sizeof(set->cpuset), &set->cpuset);
# endif
#endif /* USE_CPU_AFFINITY */
}
+/* Tries to set the current thread's CPU affinity according to the cpu_map */
+void set_thread_cpu_affinity()
+{
+ /* no affinity setting for the master process */
+ if (master)
+ return;
+
+ /* Now the CPU affinity for all threads */
+ thread_bind_to_cpu_map(tgid - 1, ti->ltid);
+}
+
/* Retrieves the opaque pthread_t of thread <thr> cast to an unsigned long long
* since POSIX took great care of not specifying its representation, making it
* hard to export for post-mortem analysis. For this reason we copy it into a