Commit 2765aa14 authored by Marek Vavrusa's avatar Marek Vavrusa

Fixed OS X not supporting cpu_set_t.

parent b04dcd94
......@@ -854,15 +854,18 @@ int dt_stop(dt_unit_t *unit)
// return KNOTD_EOK;
//}
int dt_setaffinity(dthread_t *thread, cpu_set_t *mask)
int dt_setaffinity(dthread_t *thread, void *mask, size_t len)
{
if (thread == NULL || mask == NULL) {
return KNOTD_EINVAL;
}
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
if (len != sizeof(cpu_set_t)) {
return KNOTD_EINVAL;
}
pthread_t tid = pthread_self();
int ret = pthread_setaffinity_np(tid, sizeof(cpu_set_t), mask);
int ret = pthread_setaffinity_np(tid, len, (cpu_set_t*)mask);
if (ret < 0) {
return KNOTD_ERROR;
}
......
......@@ -254,12 +254,12 @@ int dt_stop(dt_unit_t *unit);
* \brief Set thread affinity to masked CPU's.
*
* \param thread Target thread instance.
* \param mask CPU mask.
* \param mask CPU mask (should be pointer to cpu_set_t).
*
* \retval KNOTD_EOK on success.
* \retval KNOTD_EINVAL on invalid parameters.
*/
int dt_setaffinity(dthread_t *thread, cpu_set_t *mask);
int dt_setaffinity(dthread_t *thread, void *mask, size_t len);
/*!
* \brief Set thread to execute another runnable.
......
......@@ -204,6 +204,7 @@ static inline int udp_master_recvfrom(dthread_t *thread, stat_t *thread_stat)
/* Set CPU affinity to improve load distribution on multicore systems.
* Partial overlapping mask to be nice to scheduler.
*/
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
int cpcount = dt_online_cpus();
if (cpcount > 0) {
unsigned tid = dt_get_id(thread);
......@@ -211,8 +212,9 @@ static inline int udp_master_recvfrom(dthread_t *thread, stat_t *thread_stat)
CPU_ZERO(&cpus);
CPU_SET(tid % cpcount, &cpus);
CPU_SET((tid + 1) % cpcount, &cpus);
dt_setaffinity(thread, &cpus);
dt_setaffinity(thread, &cpus, sizeof(cpu_set_t));
}
#endif
knot_nameserver_t *ns = h->server->nameserver;
......@@ -405,6 +407,7 @@ static inline int udp_master_recvmmsg(dthread_t *thread, stat_t *thread_stat)
/* Set CPU affinity to improve load distribution on multicore systems.
* Partial overlapping mask to be nice to scheduler.
*/
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
int cpcount = dt_online_cpus();
if (cpcount > 0) {
unsigned tid = dt_get_id(thread);
......@@ -412,8 +415,9 @@ static inline int udp_master_recvmmsg(dthread_t *thread, stat_t *thread_stat)
CPU_ZERO(&cpus);
CPU_SET(tid % cpcount, &cpus);
CPU_SET((tid + 1) % cpcount, &cpus);
dt_setaffinity(thread, &cpus);
dt_setaffinity(thread, &cpus, sizeof(cpu_set_t));
}
#endif
/* Loop until all data is read. */
ssize_t n = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment