Hi, I tried to speedup the cond_post a bit with real-time prioritiess (see attached patch), but it seems that latmon is unable to cope with it. $ sudo ./inproc_lat 1 10000 Assertion failed: event == self.event (/usr/src/nanomsg/nanomsg/src/utils/latmon.c:80) Regards Andreas
diff --git a/CMakeLists.txt b/CMakeLists.txt index f024806..6d41383 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,7 +156,7 @@ endif () # Optional deugging/profiling tools to switch on. # add_definitions (-DNN_ALLOC_MONITOR) -# add_definitions (-DNN_LATENCY_MONITOR=1000) +add_definitions (-DNN_LATENCY_MONITOR=1000) # Subdirectories to build. diff --git a/src/utils/mutex.c b/src/utils/mutex.c index cc827b9..f086d7d 100644 --- a/src/utils/mutex.c +++ b/src/utils/mutex.c @@ -20,6 +20,8 @@ IN THE SOFTWARE. */ +#define _GNU_SOURCE + #include "mutex.h" #include "err.h" @@ -51,7 +53,10 @@ void nn_mutex_init (struct nn_mutex *self) { int rc; - rc = pthread_mutex_init (&self->mutex, NULL); + pthread_mutexattr_init (&self->attr); + pthread_mutexattr_setprotocol (&self->attr, PTHREAD_PRIO_INHERIT); + rc = pthread_mutex_init (&self->mutex, &self->attr); + errnum_assert (rc == 0, rc); } diff --git a/src/utils/mutex.h b/src/utils/mutex.h index 14cccca..d424d50 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -33,6 +33,7 @@ struct nn_mutex { #ifdef NN_HAVE_WINDOWS CRITICAL_SECTION mutex; #else + pthread_mutexattr_t attr; pthread_mutex_t mutex; #endif }; diff --git a/src/utils/thread.c b/src/utils/thread.c index d7d16ed..5a7eee5 100644 --- a/src/utils/thread.c +++ b/src/utils/thread.c @@ -89,10 +89,15 @@ void nn_thread_init (struct nn_thread *self, nn_thread_routine *routine, void *arg) { int rc; + pthread_attr_t attr; + + pthread_attr_init(&attr); + rc = pthread_attr_setschedpolicy(&attr, SCHED_FIFO); + errnum_assert (rc == 0, rc); self->routine = routine; self->arg = arg; - rc = pthread_create (&self->handle, NULL, nn_thread_main_routine, + rc = pthread_create (&self->handle, &attr, nn_thread_main_routine, (void*) self); errnum_assert (rc == 0, rc); }