From 7bf364ff04b7350a0f7f536f7705a424d551231b Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Fri, 18 Sep 2015 11:51:43 -0700 Subject: [PATCH] usnic: create blocking libevent for progress thread emulation In the v1.10 opal_progress_thread emulation, ensure to create a blocking libevent timer far in the future. Without that, opal_event_loop() will return immediately (and therefore the progress thread spins hard, stealing CPU cycles). --- opal/mca/btl/usnic/btl_usnic_compat.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/opal/mca/btl/usnic/btl_usnic_compat.c b/opal/mca/btl/usnic/btl_usnic_compat.c index 0451c58cd3..1289093ac1 100644 --- a/opal/mca/btl/usnic/btl_usnic_compat.c +++ b/opal/mca/btl/usnic/btl_usnic_compat.c @@ -152,8 +152,23 @@ int usnic_compat_free_list_init(opal_free_list_t *free_list, static volatile bool agent_thread_time_to_exit = false; static opal_thread_t agent_thread; +static opal_event_t blocker; // event to block on static opal_event_base_t *agent_evbase = NULL; +static struct timeval long_timeout = { + .tv_sec = 3600, + .tv_usec = 0 +}; + +/* + * If this event is fired, just restart it so that this event base + * continues to have something to block on. + */ +static void blocker_timeout_cb(int fd, short args, void *cbdata) +{ + opal_event_add(&blocker, &long_timeout); +} + /* * Agent progress thread main entry point */ @@ -176,6 +191,12 @@ opal_event_base_t *opal_progress_thread_init(const char *name) return NULL; } + /* add an event to the new event base (if there are no events, + opal_event_loop() will return immediately) */ + opal_event_set(agent_evbase, &blocker, -1, OPAL_EV_PERSIST, + blocker_timeout_cb, NULL); + opal_event_add(&blocker, &long_timeout); + /* Spawn the agent thread event loop */ OBJ_CONSTRUCT(&agent_thread, opal_thread_t); agent_thread.t_run = agent_thread_main;