Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ AC_SEARCH_LIBS([rdma_create_id], [rdmacm], [], [
])
AC_CHECK_HEADERS([rdma/rdma_cma.h],[], [AC_MSG_ERROR(missing rdma headers)])

# Check if RDMA_CM Libs supports rdma_lib_reset()
AC_CHECK_FUNC([rdma_lib_reset], [
AC_DEFINE([HAVE_RDMA_LIB_RESET], [1], [Define if rdma_lib_reset() is supported.])
])

AC_DEFINE( [VERSION_COMMENT], ["libmooshika and examples"], [No Comment])

# Git latest commit
Expand Down
3 changes: 3 additions & 0 deletions include/mooshika.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ static inline int msk_wait_write(msk_trans_t *trans, msk_data_t *data, msk_rloc_

int msk_init(msk_trans_t **ptrans, msk_trans_attr_t *attr);

void msk_lib_reset(void);
int msk_fork_init(void);

// server specific:
int msk_bind_server(msk_trans_t *trans);
msk_trans_t *msk_accept_one_wait(msk_trans_t *trans, int msleep);
Expand Down
53 changes: 53 additions & 0 deletions src/trans_rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,48 @@ void __attribute__ ((destructor)) msk_internals_fini(void) {
}
}

/**
* Reset global state.
* Should (only) be called to reset global data in child process after a fork.
*/
void msk_lib_reset(void)
{
/* Close epoll fd's */
if (msk_global_state->cm_epollfd != 0)
close(msk_global_state->cm_epollfd);

if (msk_global_state->cq_epollfd != 0)
close(msk_global_state->cq_epollfd);

if (msk_global_state->stats_epollfd != 0)
close(msk_global_state->stats_epollfd);

/* Free worker pool resources */
if (msk_global_state->worker_pool.w_efd != 0)
close(msk_global_state->worker_pool.w_efd);

if (msk_global_state->worker_pool.m_efd != 0)
close(msk_global_state->worker_pool.m_efd);

if (msk_global_state->worker_pool.thrids)
free(msk_global_state->worker_pool.thrids);

if (msk_global_state->worker_pool.wd_queue)
free(msk_global_state->worker_pool.wd_queue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(these are missing in msk_internals_fini and should be added there regardless of reusing the functions; thanks for finding these)


/* Brutal re-initialization of global state */
memset(msk_global_state, 0, sizeof(*msk_global_state));

msk_global_state->run_threads = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do that beforefreeing the various items/closing fd and try to join threads like in msk_internals_fini

Actually we might be able to reuse these directly, it will free/realloc msk_global_state but the cost is negligible compared to thread joins etc so just something like msk_internals_fini(); rdma_lib_reset(); msk_internals_init(); is probably cleanest?

if (pthread_mutex_init(&msk_global_state->lock, NULL))
ERROR_LOG("pthread_mutex_init failed?!");

#ifdef HAVE_RDMA_LIB_RESET
/* Reset librdmacm (Mellanox MOFED interface) */
rdma_lib_reset();
#endif
}

/* forward declarations */

static void *msk_cq_thread(void *arg);
Expand Down Expand Up @@ -212,6 +254,17 @@ static inline int msk_cond_timedwait(int debug,
}


/**
* msk_fork_init: wrapper around ibv_fork_init()
* Initialize libibverbs to support fork().
*
* @return 0 on success, the value of errno on failure
*/
int msk_fork_init(void)
{
return ibv_fork_init();
}

/**
* msk_getpd: helper function to get the right pd for a given trans
*
Expand Down