1
1

Update the opal_hotel class to support a given event base instead of defaulting to using opal_event_base

Этот коммит содержится в:
Ralph Castain 2015-07-11 06:42:23 -07:00
родитель 06dbcc1b25
Коммит 61fb067f14
4 изменённых файлов: 40 добавлений и 32 удалений

Просмотреть файл

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, LLC. All rights reserved * Copyright (c) 2012 Los Alamos National Security, LLC. All rights reserved
* Copyright (c) 2015 Intel, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * 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, int opal_hotel_init(opal_hotel_t *h, int num_rooms,
opal_event_base_t *evbase,
uint32_t eviction_timeout, uint32_t eviction_timeout,
int eviction_event_priority, int eviction_event_priority,
opal_hotel_eviction_callback_fn_t evict_callback_fn) 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->num_rooms = num_rooms;
h->evbase = evbase;
h->eviction_timeout.tv_usec = eviction_timeout % 1000000; h->eviction_timeout.tv_usec = eviction_timeout % 1000000;
h->eviction_timeout.tv_sec = eviction_timeout / 1000000; h->eviction_timeout.tv_sec = eviction_timeout / 1000000;
h->evict_callback_fn = evict_callback_fn; 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; h->eviction_args[i].room_num = i;
/* Create this room's event (but don't add it) */ /* Create this room's event (but don't add it) */
opal_event_set(opal_event_base, if (NULL != h->evbase) {
&(h->rooms[i].eviction_timer_event), opal_event_set(h->evbase,
-1, 0, local_eviction_callback, &(h->rooms[i].eviction_timer_event),
&(h->eviction_args[i])); -1, 0, local_eviction_callback,
&(h->eviction_args[i]));
/* Set the priority so it gets serviced properly */ /* Set the priority so it gets serviced properly */
opal_event_set_priority(&(h->rooms[i].eviction_timer_event), opal_event_set_priority(&(h->rooms[i].eviction_timer_event),
eviction_event_priority); eviction_event_priority);
}
} }
return OPAL_SUCCESS; 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) static void constructor(opal_hotel_t *h)
{ {
h->num_rooms = 0; h->num_rooms = 0;
h->evbase = NULL;
h->eviction_timeout.tv_sec = 0; h->eviction_timeout.tv_sec = 0;
h->eviction_timeout.tv_usec = 0; h->eviction_timeout.tv_usec = 0;
h->evict_callback_fn = NULL; h->evict_callback_fn = NULL;
@ -99,9 +105,11 @@ static void destructor(opal_hotel_t *h)
int i; int i;
/* Go through all occupied rooms and destroy their events */ /* Go through all occupied rooms and destroy their events */
for (i = 0; i < h->num_rooms; ++i) { if (NULL != h->evbase) {
if (NULL != h->rooms[i].occupant) { for (i = 0; i < h->num_rooms; ++i) {
opal_event_del(&(h->rooms[i].eviction_timer_event)); if (NULL != h->rooms[i].occupant) {
opal_event_del(&(h->rooms[i].eviction_timer_event));
}
} }
} }

Просмотреть файл

@ -111,6 +111,8 @@ typedef struct opal_hotel_t {
/* Max number of rooms in the hotel */ /* Max number of rooms in the hotel */
int num_rooms; int num_rooms;
/* event base to be used for eviction timeout */
opal_event_base_t *evbase;
struct timeval eviction_timeout; struct timeval eviction_timeout;
opal_hotel_eviction_callback_fn_t evict_callback_fn; 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 hotel Pointer to a hotel (IN)
* @param num_rooms The total number of rooms in the 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 * @param eviction_timeout Max length of a stay at the hotel before
* the eviction callback is invoked (in microseconds) * the eviction callback is invoked (in microseconds)
* @param eviction_event_priority Event lib priority for the eviction timeout * @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. * the error indicate what went wrong in the function.
*/ */
OPAL_DECLSPEC int opal_hotel_init(opal_hotel_t *hotel, int num_rooms, OPAL_DECLSPEC int opal_hotel_init(opal_hotel_t *hotel, int num_rooms,
opal_event_base_t *evbase,
uint32_t eviction_timeout, uint32_t eviction_timeout,
int eviction_event_priority, int eviction_event_priority,
opal_hotel_eviction_callback_fn_t evict_callback_fn); 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; room->occupant = occupant;
/* Assign the event and make it pending */ /* Assign the event and make it pending */
opal_event_add(&(room->eviction_timer_event), if (NULL != hotel->evbase) {
&(hotel->eviction_timeout)); opal_event_add(&(room->eviction_timer_event),
&(hotel->eviction_timeout));
}
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
@ -211,8 +217,10 @@ static inline void opal_hotel_checkin_with_res(opal_hotel_t *hotel,
room->occupant = occupant; room->occupant = occupant;
/* Assign the event and make it pending */ /* Assign the event and make it pending */
opal_event_add(&(room->eviction_timer_event), if (NULL != hotel->evbase) {
&(hotel->eviction_timeout)); 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]); room = &(hotel->rooms[room_num]);
if (OPAL_LIKELY(NULL != room->occupant)) { if (OPAL_LIKELY(NULL != room->occupant)) {
room->occupant = NULL; 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++; hotel->last_unoccupied_room++;
assert(hotel->last_unoccupied_room < hotel->num_rooms); assert(hotel->last_unoccupied_room < hotel->num_rooms);
hotel->unoccupied_rooms[hotel->last_unoccupied_room] = room_num; 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); opal_output (10, "checking out occupant %p from room num %d", room->occupant, room_num);
*occupant = room->occupant; *occupant = room->occupant;
room->occupant = NULL; 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++; hotel->last_unoccupied_room++;
assert(hotel->last_unoccupied_room < hotel->num_rooms); assert(hotel->last_unoccupied_room < hotel->num_rooms);
hotel->unoccupied_rooms[hotel->last_unoccupied_room] = room_num; 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; 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 END_C_DECLS
#endif /* OPAL_HOTEL_H */ #endif /* OPAL_HOTEL_H */

Просмотреть файл

@ -14,6 +14,7 @@
* Copyright (c) 2007 The Regents of the University of California. * Copyright (c) 2007 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2013-2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Intel, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * 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); OBJ_CONSTRUCT(&endpoint->endpoint_hotel, opal_hotel_t);
opal_hotel_init(&endpoint->endpoint_hotel, opal_hotel_init(&endpoint->endpoint_hotel,
WINDOW_SIZE, WINDOW_SIZE,
opal_event_base,
mca_btl_usnic_component.retrans_timeout, mca_btl_usnic_component.retrans_timeout,
0, 0,
opal_btl_usnic_ack_timeout); opal_btl_usnic_ack_timeout);

Просмотреть файл

@ -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; eviction_timeout = (ack_chan->timeout_secs + QOS_ACK_WINDOW_TIMEOUT_IN_SECS) * 100000;
/* init outstanding msg hotel */ /* init outstanding msg hotel */
opal_hotel_init (&ack_chan->outstanding_msgs, QOS_ACK_MAX_OUTSTANDING_MSGS, 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); orte_qos_ack_msg_ack_timeout_callback);
OPAL_OUTPUT_VERBOSE((1, orte_qos_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((1, orte_qos_base_framework.framework_output,
"%s ack_open channel = %p init hotel timeout =%d", "%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; eviction_timeout = (ack_chan->timeout_secs + QOS_ACK_WINDOW_TIMEOUT_IN_SECS) * 100000;
/* init outstanding msg hotel */ /* init outstanding msg hotel */
opal_hotel_init (&ack_chan->outstanding_msgs, QOS_ACK_MAX_OUTSTANDING_MSGS, 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); orte_qos_ack_recv_msg_timeout_callback);
OPAL_OUTPUT_VERBOSE((1, orte_qos_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((1, orte_qos_base_framework.framework_output,
"%s ack_open channel = %p init hotel timeout =%d", "%s ack_open channel = %p init hotel timeout =%d",