diff --git a/opal/class/opal_hotel.c b/opal/class/opal_hotel.c index 209e66eb9e..0fd8f1ea03 100644 --- a/opal/class/opal_hotel.c +++ b/opal/class/opal_hotel.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012 Los Alamos National Security, LLC. All rights reserved + * Copyright (c) 2015 Intel, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -33,6 +34,7 @@ static void local_eviction_callback(int fd, short flags, void *arg) int opal_hotel_init(opal_hotel_t *h, int num_rooms, + opal_event_base_t *evbase, uint32_t eviction_timeout, int eviction_event_priority, opal_hotel_eviction_callback_fn_t evict_callback_fn) @@ -46,6 +48,7 @@ int opal_hotel_init(opal_hotel_t *h, int num_rooms, } h->num_rooms = num_rooms; + h->evbase = evbase; h->eviction_timeout.tv_usec = eviction_timeout % 1000000; h->eviction_timeout.tv_sec = eviction_timeout / 1000000; h->evict_callback_fn = evict_callback_fn; @@ -69,14 +72,16 @@ int opal_hotel_init(opal_hotel_t *h, int num_rooms, h->eviction_args[i].room_num = i; /* Create this room's event (but don't add it) */ - opal_event_set(opal_event_base, - &(h->rooms[i].eviction_timer_event), - -1, 0, local_eviction_callback, - &(h->eviction_args[i])); + if (NULL != h->evbase) { + opal_event_set(h->evbase, + &(h->rooms[i].eviction_timer_event), + -1, 0, local_eviction_callback, + &(h->eviction_args[i])); - /* Set the priority so it gets serviced properly */ - opal_event_set_priority(&(h->rooms[i].eviction_timer_event), - eviction_event_priority); + /* Set the priority so it gets serviced properly */ + opal_event_set_priority(&(h->rooms[i].eviction_timer_event), + eviction_event_priority); + } } return OPAL_SUCCESS; @@ -85,6 +90,7 @@ int opal_hotel_init(opal_hotel_t *h, int num_rooms, static void constructor(opal_hotel_t *h) { h->num_rooms = 0; + h->evbase = NULL; h->eviction_timeout.tv_sec = 0; h->eviction_timeout.tv_usec = 0; h->evict_callback_fn = NULL; @@ -99,9 +105,11 @@ static void destructor(opal_hotel_t *h) int i; /* Go through all occupied rooms and destroy their events */ - for (i = 0; i < h->num_rooms; ++i) { - if (NULL != h->rooms[i].occupant) { - opal_event_del(&(h->rooms[i].eviction_timer_event)); + if (NULL != h->evbase) { + for (i = 0; i < h->num_rooms; ++i) { + if (NULL != h->rooms[i].occupant) { + opal_event_del(&(h->rooms[i].eviction_timer_event)); + } } } diff --git a/opal/class/opal_hotel.h b/opal/class/opal_hotel.h index f8ecd4c0cb..c08f44aebb 100644 --- a/opal/class/opal_hotel.h +++ b/opal/class/opal_hotel.h @@ -111,6 +111,8 @@ typedef struct opal_hotel_t { /* Max number of rooms in the hotel */ int num_rooms; + /* event base to be used for eviction timeout */ + opal_event_base_t *evbase; struct timeval eviction_timeout; opal_hotel_eviction_callback_fn_t evict_callback_fn; @@ -133,6 +135,7 @@ OBJ_CLASS_DECLARATION(opal_hotel_t); * * @param hotel Pointer to a hotel (IN) * @param num_rooms The total number of rooms in the hotel (IN) + * @param evbase Pointer to event base used for eviction timeout * @param eviction_timeout Max length of a stay at the hotel before * the eviction callback is invoked (in microseconds) * @param eviction_event_priority Event lib priority for the eviction timeout @@ -147,6 +150,7 @@ OBJ_CLASS_DECLARATION(opal_hotel_t); * the error indicate what went wrong in the function. */ OPAL_DECLSPEC int opal_hotel_init(opal_hotel_t *hotel, int num_rooms, + opal_event_base_t *evbase, uint32_t eviction_timeout, int eviction_event_priority, opal_hotel_eviction_callback_fn_t evict_callback_fn); @@ -188,8 +192,10 @@ static inline int opal_hotel_checkin(opal_hotel_t *hotel, room->occupant = occupant; /* Assign the event and make it pending */ - opal_event_add(&(room->eviction_timer_event), - &(hotel->eviction_timeout)); + if (NULL != hotel->evbase) { + opal_event_add(&(room->eviction_timer_event), + &(hotel->eviction_timeout)); + } return OPAL_SUCCESS; } @@ -211,8 +217,10 @@ static inline void opal_hotel_checkin_with_res(opal_hotel_t *hotel, room->occupant = occupant; /* Assign the event and make it pending */ - opal_event_add(&(room->eviction_timer_event), - &(hotel->eviction_timeout)); + if (NULL != hotel->evbase) { + opal_event_add(&(room->eviction_timer_event), + &(hotel->eviction_timeout)); + } } /** @@ -237,8 +245,9 @@ static inline void opal_hotel_checkout(opal_hotel_t *hotel, int room_num) room = &(hotel->rooms[room_num]); if (OPAL_LIKELY(NULL != room->occupant)) { room->occupant = NULL; - opal_event_del(&(room->eviction_timer_event)); - + if (NULL != hotel->evbase) { + opal_event_del(&(room->eviction_timer_event)); + } hotel->last_unoccupied_room++; assert(hotel->last_unoccupied_room < hotel->num_rooms); hotel->unoccupied_rooms[hotel->last_unoccupied_room] = room_num; @@ -273,7 +282,9 @@ static inline void opal_hotel_checkout_and_return_occupant(opal_hotel_t *hotel, opal_output (10, "checking out occupant %p from room num %d", room->occupant, room_num); *occupant = room->occupant; room->occupant = NULL; - opal_event_del(&(room->eviction_timer_event)); + if (NULL != hotel->evbase) { + opal_event_del(&(room->eviction_timer_event)); + } hotel->last_unoccupied_room++; assert(hotel->last_unoccupied_room < hotel->num_rooms); hotel->unoccupied_rooms[hotel->last_unoccupied_room] = room_num; @@ -298,19 +309,6 @@ static inline bool opal_hotel_is_empty (opal_hotel_t *hotel) return false; } -/** - * Destroy a hotel. - * - * @param hotel Pointer to hotel (IN) - * - * @return OPAL_SUCCESS Always - * - * The hotel (and all of its rooms) is destroyed. No further eviction - * callbacks will be invoked. - */ -OPAL_DECLSPEC int opal_hotel_finalize(opal_hotel_t *hotel); - - END_C_DECLS #endif /* OPAL_HOTEL_H */ diff --git a/opal/mca/btl/usnic/btl_usnic_endpoint.c b/opal/mca/btl/usnic/btl_usnic_endpoint.c index 998e4576c3..5891fc5568 100644 --- a/opal/mca/btl/usnic/btl_usnic_endpoint.c +++ b/opal/mca/btl/usnic/btl_usnic_endpoint.c @@ -14,6 +14,7 @@ * Copyright (c) 2007 The Regents of the University of California. * All rights reserved. * Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015 Intel, Inc. All rights reserved * $COPYRIGHT$ * * Additional copyrights may follow @@ -86,6 +87,7 @@ static void endpoint_construct(mca_btl_base_endpoint_t* endpoint) OBJ_CONSTRUCT(&endpoint->endpoint_hotel, opal_hotel_t); opal_hotel_init(&endpoint->endpoint_hotel, WINDOW_SIZE, + opal_event_base, mca_btl_usnic_component.retrans_timeout, 0, opal_btl_usnic_ack_timeout); diff --git a/orte/mca/qos/ack/qos_ack_component.c b/orte/mca/qos/ack/qos_ack_component.c index 9acb5c500e..9416789d84 100644 --- a/orte/mca/qos/ack/qos_ack_component.c +++ b/orte/mca/qos/ack/qos_ack_component.c @@ -188,7 +188,7 @@ static int ack_open (void *qos_channel, opal_buffer_t * buf) { eviction_timeout = (ack_chan->timeout_secs + QOS_ACK_WINDOW_TIMEOUT_IN_SECS) * 100000; /* init outstanding msg hotel */ opal_hotel_init (&ack_chan->outstanding_msgs, QOS_ACK_MAX_OUTSTANDING_MSGS, - eviction_timeout, 0, + orte_event_base, eviction_timeout, 0, orte_qos_ack_msg_ack_timeout_callback); OPAL_OUTPUT_VERBOSE((1, orte_qos_base_framework.framework_output, "%s ack_open channel = %p init hotel timeout =%d", @@ -466,7 +466,7 @@ static int ack_init_recv (void *channel, opal_list_t *attributes) { eviction_timeout = (ack_chan->timeout_secs + QOS_ACK_WINDOW_TIMEOUT_IN_SECS) * 100000; /* init outstanding msg hotel */ opal_hotel_init (&ack_chan->outstanding_msgs, QOS_ACK_MAX_OUTSTANDING_MSGS, - eviction_timeout, 0, + orte_event_base, eviction_timeout, 0, orte_qos_ack_recv_msg_timeout_callback); OPAL_OUTPUT_VERBOSE((1, orte_qos_base_framework.framework_output, "%s ack_open channel = %p init hotel timeout =%d",