Xeon Phi messaging: Cleaned up of code
authorReto Achermann <acreto@student.ethz.ch>
Wed, 2 Jul 2014 13:20:05 +0000 (15:20 +0200)
committerStefan Kaestle <stefan.kaestle@inf.ethz.ch>
Wed, 20 Aug 2014 21:38:18 +0000 (23:38 +0200)
- partial refactoring
- cleaning up of printfs
- added debug ifdef switch

errors/errno.fugu
include/xeon_phi/xeon_phi_messaging.h
lib/xeon_phi/xeon_phi_messaging.c
lib/xeon_phi/xeon_phi_messaging_client.c

index 811c3c8..1db3c6a 100755 (executable)
@@ -1044,6 +1044,7 @@ errors virtio VIRTIO_ERR_ {
 errors xeon_phi XEON_PHI_ERR_ {
     failure MGR_REGISTER_FAILED  "Registration with the Xeon Phi Manager failed",
     failure MGR_MAX_CARDS        "There are too much drivers connected",
+    failure MSG_NOT_INITIALIZED  "Messaging service has not been initialized",
     failure DMA_NOT_INITIALIZED  "DMA library has not been initialized",
     failure DMA_ID_NOT_EXISTS    "The DMA transfer with that ID does not exist ",
     failure DMA_BUSY             "All DMA channels are busy",
index 159c370..9791678 100644 (file)
@@ -128,4 +128,15 @@ errval_t xeon_phi_messaging_service_start(uint8_t start_handler);
  */
 errval_t xeon_phi_messaging_service_start_phi(uint8_t xeon_phi_id);
 
+
+/**
+ * \brief sets the callback functions for the message handlers in the library
+ *
+ * \param fn the new function pointers to set.
+ *
+ * To disable callbacks either have the entry set to NULL or if fn==NULL then
+ * all callbacks are disabled.
+ */
+void xeon_phi_messaging_set_callbacks(struct xeon_phi_messaging_cb *fn);
+
 #endif // XEON_PHI_MESSAGING_H_
index 3b526ed..213b247 100644 (file)
@@ -6,7 +6,8 @@
  * If you do not find this file, copies can be found by writing to:
  * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
  */
-#include <stdio.h>
+#include <string.h>
+
 #include <barrelfish/barrelfish.h>
 #include <barrelfish/nameservice_client.h>
 
 
 #include <xeon_phi/xeon_phi_messaging.h>
 
-#define XPHI_MSG_DBG(x...) debug_printf(" MSGSVC | " x);
-//#define XPHI_MSG_DBG(x...)
+#ifdef XEON_PHI_DEBUG_MSG
+#define DEBUG_XMSG(x...) debug_printf(" [xpmsg-svc] " x);
+#else
+#define DEBUG_XMSG(x...)
+#endif
+#define PRINTF_XMSG(x...) debug_printf(" [xpmsg-svc] " x);
+
 
+/// flag indicating if we are running on the Xeon Phi driver
 uint8_t xpm_is_phi = 0x0;
 
 /**
- * enumration of all possible states of the service exportation process
+ * enumeration of all possible states of the service exporting process
  */
 enum xpm_svc_state
 {
+    XPM_SVC_STATE_INVALID,
     XPM_SVC_STATE_EXPORTING,
     XPM_SVC_STATE_EXPORT_OK,
     XPM_SVC_STATE_EXPORT_FAIL,
@@ -34,7 +42,7 @@ enum xpm_svc_state
 };
 
 /// represents the current state of the exporting process
-static enum xpm_svc_state svc_state = XPM_SVC_STATE_EXPORTING;
+static enum xpm_svc_state svc_state = XPM_SVC_STATE_INVALID;
 
 /// our own iref of the exported service
 static iref_t messaging_iref;
@@ -42,37 +50,59 @@ static iref_t messaging_iref;
 /// stores the callbacks to inform the user about arrived messages
 static struct xeon_phi_messaging_cb callbacks;
 
+/*
+ * ----------------------------------------------------------------------------
+ * Callbacks for the Flounder messages
+ * ----------------------------------------------------------------------------
+ */
+
+/**
+ * \brief handles the open requests targeting a specific card.
+ *
+ * \param _binding  Flounder binding we received the message from
+ * \param xid       ID of the Xeon Phi where the target is located
+ * \param msgframe  Capability of the message frame
+ * \param type      The type of the channel
+ * \param iface     Name of the interface
+ * \param length    length of the interface name
+ *
+ * This function may only be called on the Xeon Phi driver.
+ */
 static void open_card_call_rx(struct xeon_phi_messaging_binding *_binding,
-                              uint8_t id,
+                              uint8_t xid,
                               struct capref msgframe,
                               uint8_t type,
                               char *iface,
                               size_t length)
 {
+    DEBUG_XMSG("recv open: xphi=%u, iface=%s, type=0x%02x\n", xid, iface, type);
+
     assert(xpm_is_phi == 0x1);
     if (callbacks.open_card != NULL) {
-        callbacks.open_card(id, msgframe, type, iface);
+        callbacks.open_card(xid, msgframe, type, iface);
     }
 }
 
-static void open_call_rx(struct xeon_phi_messaging_binding *_binding,
-                         struct capref msgframe,
-                         uint8_t type)
-{
-    XPHI_MSG_DBG("Received channel open request type: %x\n", type);
-    assert(xpm_is_phi == 0x0);
-    if (callbacks.open != NULL) {
-        callbacks.open(msgframe, type);
-    }
-}
 
+
+/**
+ * \brief handles the open requests targeting the the associated card/host
+ *
+ * \param _binding  Flounder binding we received the message from
+ * \param msgframe  Capability of the message frame
+ * \param type      The type of the channel
+ * \param iface     Name of the interface
+ * \param length    length of the interface name
+ *
+ * This function may only be called on the Xeon Phi driver.
+ */
 static void open_iface_call_rx(struct xeon_phi_messaging_binding *_binding,
                                struct capref msgframe,
                                uint8_t type,
                                char *iface,
                                size_t length)
 {
-    XPHI_MSG_DBG("Received channel OPEN cmd: [%s, 0x%x]\n", iface, type);
+    DEBUG_XMSG("recv open: iface=%s, type=0x%02x\n", iface, type);
 
     assert(xpm_is_phi == 0x1);
 
@@ -81,27 +111,48 @@ static void open_iface_call_rx(struct xeon_phi_messaging_binding *_binding,
     }
 }
 
+/**
+ * \brief handles spawn requests on the Xeon Phi driver
+ *
+ * \param xid    ID of the target Xeon Phi
+ * \param core   Which core to start the domain
+ * \param name   Name of the domain to spawn
+ * \param length length of the name
+ *
+ * This function may only be called on the Xeon Phi driver
+ */
 static void spawn_card_call_rx(struct xeon_phi_messaging_binding *_binding,
-                               uint8_t id,
+                               uint8_t xid,
                                uint8_t core,
                                char *name,
                                size_t length)
 {
-    XPHI_MSG_DBG("Received spawn request: %s on Xeon Phi %u\n", name, id);
+    DEBUG_XMSG("recv spawn: %s.%u.%u\n", name, xid, core);
 
     assert(xpm_is_phi == 0x1);
 
     if (callbacks.spawn_card != NULL) {
-        callbacks.spawn_card(id, core, name);
+        callbacks.spawn_card(xid, core, name);
     }
 }
 
+/**
+ * \brief handles spawn requests on the Xeon Phi driver on the associated
+ *        Xeon Phi card or on the host.
+ *
+ * \param core   Which core to start the domain
+ * \param name   Name of the domain to spawn
+ * \param length length of the name
+ *
+ * This function may only be called on the Xeon Phi driver
+ */
 static void spawn_call_rx(struct xeon_phi_messaging_binding *_binding,
                           uint8_t core,
                           char *name,
                           size_t length)
 {
-    XPHI_MSG_DBG("Received spawn request: %s\n", name);
+    DEBUG_XMSG("recv spawn: %s.%u\n", name, core);
+
     assert(xpm_is_phi == 0x1);
 
     if (callbacks.spawn != NULL) {
@@ -109,6 +160,26 @@ static void spawn_call_rx(struct xeon_phi_messaging_binding *_binding,
     }
 }
 
+
+/**
+ * \brief handles the open requests of on the domain side
+ *
+ * \param _binding  Flounder binind we received the message from
+ * \param msgframe  capability of the message frame
+ * \param type      the type of the channel
+ */
+static void open_call_rx(struct xeon_phi_messaging_binding *_binding,
+                         struct capref msgframe,
+                         uint8_t type)
+{
+    DEBUG_XMSG("recv open: type=0x%02x\n", type);
+    assert(xpm_is_phi == 0x0);
+    if (callbacks.open != NULL) {
+        callbacks.open(msgframe, type);
+    }
+}
+
+/// Flounder receive vtbl
 static struct xeon_phi_messaging_rx_vtbl xpm_rx_vtbl = {
     .open_iface = open_iface_call_rx,
     .open = open_call_rx,
@@ -122,17 +193,27 @@ static struct xeon_phi_messaging_rx_vtbl xpm_rx_vtbl = {
  * Export and Connect functions
  */
 
+/**
+ * \brief Xeon Phi Messaging connect handler
+ *
+ * \param st       state, currently NULL
+ * \param binding  the Flounder binding of the new connection
+ */
 static errval_t svc_connect_cb(void *st,
-                               struct xeon_phi_messaging_binding *b)
+                               struct xeon_phi_messaging_binding *binding)
 {
-    XPHI_MSG_DBG("New connection request\n");
-    b->rx_vtbl = xpm_rx_vtbl;
+    DEBUG_XMSG("new connection to the service.\n");
+    binding->rx_vtbl = xpm_rx_vtbl;
 
     return SYS_ERR_OK;
 }
 
 /**
- * \brief
+ * \brief Xeon Phi Messaging export handler
+ *
+ * \param st   state, currently NULL
+ * \param err  outcome of the exportation process
+ * \param iref the iref of the exported interface
  */
 static void svc_export_cb(void *st,
                           errval_t err,
@@ -143,6 +224,8 @@ static void svc_export_cb(void *st,
         return;
     }
 
+    DEBUG_XMSG("service exported @ iref:%u\n", iref);
+
     messaging_iref = iref;
 
     svc_state = XPM_SVC_STATE_EXPORT_OK;
@@ -154,33 +237,28 @@ static void svc_export_cb(void *st,
  *
  * \param fn    callback functions which are invoked when a message arrives
  *
- * \returns SYS_ERR_OK un success
- *          errorcode on failure
+ * \returns SYS_ERR_OK on success
+ *          errval on failure
  */
 errval_t xeon_phi_messaging_service_init(struct xeon_phi_messaging_cb *fn)
 {
     errval_t err;
 
-    XPHI_MSG_DBG("Service initialization... callbacks=%p\n", fn);
+    DEBUG_XMSG("initializing Xeon Phi messaging service.\n");
 
-    if (fn) {
-        callbacks = *fn;
-    } else {
-        memset(&callbacks, 0, sizeof(callbacks));
-    }
+    xeon_phi_messaging_set_callbacks(fn);
 
-    struct waitset *ws = get_default_waitset();
+    svc_state = XPM_SVC_STATE_EXPORTING;
 
     err = xeon_phi_messaging_export(NULL,
                                     svc_export_cb,
                                     svc_connect_cb,
-                                    ws,
+                                    get_default_waitset(),
                                     IDC_EXPORT_FLAGS_DEFAULT);
     if (err_is_fail(err)) {
         return err;
     }
 
-    XPHI_MSG_DBG("Waiting for export... callbacks=%p\n", fn);
     while (svc_state == XPM_SVC_STATE_EXPORTING) {
         messages_wait_and_handle_next();
     }
@@ -193,65 +271,115 @@ errval_t xeon_phi_messaging_service_init(struct xeon_phi_messaging_cb *fn)
 }
 
 /**
- * \brief starts the service by registring the service with the name server
+ * \brief sets the callback functions for the message handlers in the library
+ *
+ * \param fn the new function pointers to set.
+ *
+ * To disable callbacks either have the entry set to NULL or if fn==NULL then
+ * all callbacks are disabled.
+ */
+void xeon_phi_messaging_set_callbacks(struct xeon_phi_messaging_cb *fn)
+{
+    if (fn) {
+        callbacks = *fn;
+    } else {
+        memset(&callbacks, 0, sizeof(callbacks));
+    }
+}
+
+/**
+ * \brief starts the service by registering the service with the service name
+ *
+ * \param start_handler if non zero this will start the message handler loop
  *
  * \returns SYS_ERR_OK on success
+ *          errval on failure
  *
- * NOTE: this also executes the messaging handler loop.
+ * This function must not be called on the Xeon  Phi driver.
  */
 errval_t xeon_phi_messaging_service_start(uint8_t start_handler)
 {
     errval_t err;
+
+    if (svc_state != XPM_SVC_STATE_EXPORT_OK) {
+        /* service state is not exported */
+        return XEON_PHI_ERR_MSG_NOT_INITIALIZED;
+    }
+
     svc_state = XPM_SVC_STATE_NS_REGISTERING;
 
     char buf[50];
     snprintf(buf, 50, "%s.%u", disp_name(), disp_get_core_id());
 
-    XPHI_MSG_DBG("Registering iref [%u] with name [%s]\n", messaging_iref, buf);
+    DEBUG_XMSG("registering iref:%u with name [%s]\n", messaging_iref, buf);
     err = nameservice_register(buf, messaging_iref);
     if (err_is_fail(err)) {
+        svc_state = XPM_SVC_STATE_NS_REGISTER_FAIL;
         return err;
     }
 
     svc_state = XPM_SVC_STATE_NS_REGISTER_OK;
 
-    if (start_handler) {
-        XPHI_MSG_DBG("Starting service...\n");
+    PRINTF_XMSG("service started on non-driver domain.\n");
 
+    xpm_is_phi = 0x0;
+
+    if (start_handler) {
         svc_state = XPM_SVC_STATE_RUNNING;
         messages_handler_loop();
     }
 
-    xpm_is_phi = 0x0;
-
     return SYS_ERR_OK;
 }
 
 /**
- * \brief starts the service when running on the xeon phi driver
+ * \brief starts the service by registering the service with the service name
+ *
+ * \param start_handler if non zero this will start the message handler loop
  *
  * \returns SYS_ERR_OK on success
+ *          errval on failure
+ *
+ * This function MUST only be called on the Xeon Phi driver!
  */
 errval_t xeon_phi_messaging_service_start_phi(uint8_t xeon_phi_id)
 {
     errval_t err;
+
+    /// a check that this function is called on the Xeon Phi driver domain.
+    assert(strcmp("xeon_phi", disp_name()) == 0);
+
+    if (svc_state != XPM_SVC_STATE_EXPORT_OK) {
+        /* service state is not exported */
+        return XEON_PHI_ERR_MSG_NOT_INITIALIZED;
+    }
+
     svc_state = XPM_SVC_STATE_NS_REGISTERING;
 
+    /*
+     * building the service name for exporting the iref. This is a bit different
+     * when running on the card because there is always just one driver running,
+     * whereas on the host, there may be up to 8 running.
+     */
     char buf[50];
 #if !defined(__k1om__)
     snprintf(buf, 50, "%s.%u", XEON_PHI_MESSAGING_NAME, xeon_phi_id);
 #else
     snprintf(buf, 50, "%s", XEON_PHI_MESSAGING_NAME);
 #endif
-    XPHI_MSG_DBG("Registering iref [%u] with name [%s]\n", messaging_iref, buf);
+
+    DEBUG_XMSG("registering iref:%u with name [%s]\n", messaging_iref, buf);
     err = nameservice_register(buf, messaging_iref);
     if (err_is_fail(err)) {
+        svc_state = XPM_SVC_STATE_NS_REGISTER_FAIL;
         return err;
     }
 
-    svc_state = XPM_SVC_STATE_NS_REGISTER_OK;
+    svc_state = XPM_SVC_STATE_RUNNING;
 
     xpm_is_phi = 0x1;
 
+    PRINTF_XMSG("service started on Xeon Phi driver\n");
+
     return SYS_ERR_OK;
 }
index e300930..e0a7058 100644 (file)
 
 #include <if/xeon_phi_messaging_defs.h>
 
-#define DEBUG_XPMC(x...) debug_printf(" XPMC | " x)
+#ifdef XEON_PHI_DEBUG_MSG
+#define DEBUG_XPMC(x...) debug_printf(" [xpmsg] " x);
+#else
+#define DEBUG_XPMC(x...)
+#endif
+#define PRINT_XPMC(x...) debug_printf(" [xpmsg] " x);
 
+/**
+ * state enumeration for the connection state
+ */
 enum xpm_state
 {
+    XPM_STATE_INVALID = 0,
     XPM_STATE_NSLOOKUP,
     XPM_STATE_BINDING,
     XPM_STATE_BIND_OK,
     XPM_STATE_BIND_FAIL,
+    XPM_STATE_CONNECTED
 };
 
-/* todo: extend this with array of 8 */
+/// the irefs of the messaging services
 static iref_t xpm_iref[XEON_PHI_NUM_MAX];
-struct xeon_phi_messaging_binding *xpm_binding[XEON_PHI_NUM_MAX];
 
-static enum xpm_state conn_state = XPM_STATE_NSLOOKUP;
+/// Xeon Phi Messaging bindings
+struct xeon_phi_messaging_binding *xpm_binding[XEON_PHI_NUM_MAX];
 
+/// connection states
+static enum xpm_state conn_state[XEON_PHI_NUM_MAX] = {
+    XPM_STATE_INVALID
+};
 
 /*
- * --------------------------------------------------------------------------
+ * ----------------------------------------------------------------------------
  * Handling of OPEN commands
+ * ----------------------------------------------------------------------------
  */
 
-static volatile uint8_t xpm_msg_open_sent = 0x1;
-
+/**
+ * stores the state of the open message being transmitted
+ */
 struct xpm_msg_param_open
 {
     struct capref frame;
     struct xeon_phi_messaging_binding *b;
+    errval_t err;
     uint8_t type;
     uint8_t xphi_id;
+    volatile uint8_t sent;
     char iface[44];
 };
 
+/**
+ * \brief message sent callback handler for open messages
+ *
+ * \param a pointer to struct xpm_msg_param_open
+ */
 static void xpm_msg_open_sent_cb(void *a)
 {
-    free(a);
-    xpm_msg_open_sent = 0x1;
+    struct xpm_msg_param_open *st = a;
+    st->err = SYS_ERR_OK;
+    st->sent = 0x1;
 }
 
-#ifndef __k1om__
+/**
+ * \brief sends the open message
+ *
+ * \param a pointer to struct xpm_msg_param_open
+ */
 static void xpm_msg_open_tx(void *a)
 {
     errval_t err;
@@ -66,135 +94,121 @@ static void xpm_msg_open_tx(void *a)
 
     struct event_closure txcont = MKCONT(xpm_msg_open_sent_cb, a);
 
-    size_t length = strlen(param->iface)+1;
+    size_t length = strlen(param->iface) + 1;
 
+#ifndef __k1om__
     err = xeon_phi_messaging_open_iface__tx(param->b,
-                                      txcont,
-                                      param->frame,
-                                      param->type,
-                                      param->iface,
-                                      length);
-    if (err_is_fail(err)) {
-        if (err_no(err) == FLOUNDER_ERR_TX_BUSY) {
-            txcont = MKCONT(xpm_msg_open_tx, a);
-            err = param->b->register_send(param->b,
-                                             get_default_waitset(),
-                                             txcont);
-            if (err_is_fail(err)) {
-                USER_PANIC_ERR(err, "failed to register send\n");
-            }
-        }
-    }
-}
+                    txcont,
+                    param->frame,
+                    param->type,
+                    param->iface,
+                    length);
 #else
-static void xpm_msg_open_card_tx(void *a)
-{
-    errval_t err;
-
-    struct xpm_msg_param_open *param = a;
-
-    struct event_closure txcont = MKCONT(xpm_msg_open_sent_cb, a);
-
-    size_t length = strlen(param->iface)+1;
-
     err = xeon_phi_messaging_open_card__tx(param->b,
-                                          txcont,
-                                          param->xphi_id,
-                                          param->frame,
-                                          param->type,
-                                          param->iface,
-                                          length);
+                                           txcont,
+                                           param->xphi_id,
+                                           param->frame,
+                                           param->type,
+                                           param->iface,
+                                           length);
+#endif
     if (err_is_fail(err)) {
         if (err_no(err) == FLOUNDER_ERR_TX_BUSY) {
-            txcont = MKCONT(xpm_msg_open_card_tx, a);
-            err = param->b->register_send(param->b,
-                                             get_default_waitset(),
-                                             txcont);
+            txcont = MKCONT(xpm_msg_open_tx, a);
+            err = param->b->register_send(param->b, get_default_waitset(), txcont);
             if (err_is_fail(err)) {
-                USER_PANIC_ERR(err, "failed to register send\n");
+                param->err = err;
+                param->sent = 0x1;
             }
         }
     }
 }
-#endif
 
 /*
- * --------------------------------------------------------------------------
+ * ----------------------------------------------------------------------------
  * Handling of SPAWN commands
+ * ----------------------------------------------------------------------------
+ */
+
+/**
+ * stores the spawn related information for sending the message
  */
 struct xpm_msg_param_spawn
 {
     struct xeon_phi_messaging_binding *b;
+    errval_t err;
     coreid_t core;
     uint8_t xphi_id;
+    uint8_t sent;
     char name[55];
 };
-#ifndef __k1om__
+
+/**
+ * \brief callback for the message sent event.
+ *
+ * \param a pointer to struct xpm_msg_param_spawn
+ */
+static void xpm_msg_spawn_sent_cb(void *a)
+{
+    struct xpm_msg_param_spawn *st = a;
+    st->err = SYS_ERR_OK;
+    st->sent = 0x1;
+}
+
+/**
+ * \brief send handler for spawn requests to the messaging service
+ *
+ * \param a pointer to struct xpm_msg_param_spawn
+ */
 static void xpm_msg_spawn_tx(void *a)
 {
     errval_t err;
 
     struct xpm_msg_param_spawn *param = a;
 
-    struct event_closure txcont = MKCONT(free, a);
+    struct event_closure txcont = MKCONT(xpm_msg_spawn_sent_cb, a);
 
-    size_t length = strlen(param->name)+1;
+    size_t length = strlen(param->name) + 1;
 
+    /*
+     * when running on the Xeon Phi, we can spawn the domain on another Xeon Phi
+     * or on the host.
+     */
+#ifndef __k1om__
     err = xeon_phi_messaging_spawn__tx(param->b,
-                                       txcont,
-                                       param->core,
-                                       param->name,
-                                       length);
-    if (err_is_fail(err)) {
-        if (err_no(err) == FLOUNDER_ERR_TX_BUSY) {
-            txcont = MKCONT(xpm_msg_spawn_tx, a);
-            err = param->b->register_send(param->b,
-                                             get_default_waitset(),
-                                             txcont);
-            if (err_is_fail(err)) {
-                USER_PANIC_ERR(err, "failed to register send\n");
-            }
-        }
-    }
-}
+                    txcont,
+                    param->core,
+                    param->name,
+                    length);
 #else
-static void xpm_msg_spawn_card_tx(void *a)
-{
-    errval_t err;
-
-    struct xpm_msg_param_spawn *param = a;
-
-    struct event_closure txcont = MKCONT(free, a);
-
-    size_t length = strlen(param->name)+1;
-
     err = xeon_phi_messaging_spawn_card__tx(param->b,
-                                       txcont,
-                                       param->xphi_id,
-                                       param->core,
-                                       param->name,
-                                       length);
+                                            txcont,
+                                            param->xphi_id,
+                                            param->core,
+                                            param->name,
+                                            length);
+#endif
     if (err_is_fail(err)) {
         if (err_no(err) == FLOUNDER_ERR_TX_BUSY) {
-            txcont = MKCONT(xpm_msg_spawn_card_tx, a);
-            err = param->b->register_send(param->b,
-                                             get_default_waitset(),
-                                             txcont);
+            txcont = MKCONT(xpm_msg_spawn_tx, a);
+            err = param->b->register_send(param->b, get_default_waitset(), txcont);
             if (err_is_fail(err)) {
-                USER_PANIC_ERR(err, "failed to register send\n");
+                param->err = err;
+                param->sent = 0x1;
             }
         }
     }
 }
-#endif
 
+/// Flounder recv vtbl
 static struct xeon_phi_messaging_rx_vtbl xpm_rx_vtbl = {
     .open = NULL
 };
 
 /*
- * --------------------------------------------------------------------------
+ * ----------------------------------------------------------------------------
  * Xeon Phi Manager Binding
+ * ----------------------------------------------------------------------------
  */
 
 /**
@@ -208,24 +222,24 @@ static void xpm_bind_cb(void *st,
                         errval_t err,
                         struct xeon_phi_messaging_binding *b)
 {
+    uint8_t xeon_phi_id = (uint8_t) (uintptr_t) st;
 
     if (err_is_fail(err)) {
-        conn_state = XPM_STATE_BIND_FAIL;
+        conn_state[xeon_phi_id] = XPM_STATE_BIND_FAIL;
+        DEBUG_XPMC("binding FAILED.\n");
         return;
     }
 
-    uint8_t xeon_phi_id = (uint8_t)(uintptr_t)st;
-
     assert(xpm_binding[xeon_phi_id] == 0);
 
+    DEBUG_XPMC("binding to Xeon Phi %u succeeded.\n", xeon_phi_id);
+
     b->rx_vtbl = xpm_rx_vtbl;
-    b->st = (void *)(uintptr_t)xeon_phi_id;
+    b->st = (void *) (uintptr_t) xeon_phi_id;
 
     xpm_binding[xeon_phi_id] = b;
 
-    DEBUG_XPMC("Binding ok.\n");
-
-    conn_state = XPM_STATE_BIND_OK;
+    conn_state[xeon_phi_id] = XPM_STATE_BIND_OK;
 }
 
 /**
@@ -246,38 +260,38 @@ static errval_t xpm_connect(uint8_t xeon_phi_id)
     snprintf(buf, 50, "%s", XEON_PHI_MESSAGING_NAME);
 #endif
 
-    DEBUG_XPMC("Nameservice lookup: %s\n", buf);
+    DEBUG_XPMC("nameservice lookup: %s\n", buf);
     err = nameservice_blocking_lookup(buf, &xpm_iref[xeon_phi_id]);
     if (err_is_fail(err)) {
         return err;
     }
 
-    conn_state = XPM_STATE_BINDING;
+    conn_state[xeon_phi_id] = XPM_STATE_BINDING;
 
-    DEBUG_XPMC("binding to iref [%u]... \n", xpm_iref[xeon_phi_id]);
-    err = xeon_phi_messaging_bind(xpm_iref[xeon_phi_id], xpm_bind_cb,
-                                  (void *)(uintptr_t)xeon_phi_id,
+    DEBUG_XPMC("binding to %s @ iref:%u\n", buf, xpm_iref[xeon_phi_id]);
+
+    err = xeon_phi_messaging_bind(xpm_iref[xeon_phi_id],
+                                  xpm_bind_cb,
+                                  (void *) (uintptr_t) xeon_phi_id,
                                   get_default_waitset(),
                                   IDC_BIND_FLAGS_DEFAULT);
     if (err_is_fail(err)) {
         return err;
     }
 
-    while (conn_state == XPM_STATE_BINDING) {
+    while (conn_state[xeon_phi_id] == XPM_STATE_BINDING) {
         messages_wait_and_handle_next();
     }
 
-    DEBUG_XPMC("binding to iref [%u] done. \n", xpm_iref[xeon_phi_id]);
-
-    if (conn_state == XPM_STATE_BIND_FAIL) {
+    if (conn_state[xeon_phi_id] == XPM_STATE_BIND_FAIL) {
         return FLOUNDER_ERR_BIND;
     }
 
+    conn_state[xeon_phi_id] = XPM_STATE_CONNECTED;
+
     return SYS_ERR_OK;
 }
 
-
-
 /*
  * --------------------------------------------------------------------------
  * Public Interface
@@ -299,6 +313,10 @@ errval_t xeon_phi_messaging_open(uint8_t xeon_phi_id,
 {
     errval_t err;
 
+    /*
+     * if we are running on the Xeon Phi, there is just a single service instace
+     * running, so we enforce the Xeon Phi ID to be zero
+     */
 #ifdef __k1om__
     uint8_t xphi = 0;
 #else
@@ -311,31 +329,25 @@ errval_t xeon_phi_messaging_open(uint8_t xeon_phi_id,
         }
     }
 
-    xpm_msg_open_sent = 0x0;
+    DEBUG_XPMC("open request to %s.%u type=%02x\n", iface, xeon_phi_id, type);
 
-    struct xpm_msg_param_open *param = malloc(sizeof(struct xpm_msg_param_open));
-    if (param == NULL) {
-        return LIB_ERR_MALLOC_FAIL;
-    }
-
-    param->frame = frame;
-    param->type = type;
-    param->b = xpm_binding[xphi];
-    param->xphi_id = xeon_phi_id;
+    struct xpm_msg_param_open param = {
+        .sent = 0x0,
+        .frame = frame,
+        .type = type,
+        .b = xpm_binding[xphi],
+        .xphi_id = xeon_phi_id  // here we have to take the original ID
+    };
 
-    snprintf(param->iface, sizeof(param->iface), "%s", iface);
+    snprintf(param.iface, sizeof(param.iface), "%s", iface);
 
-#ifdef __k1om__
-    xpm_msg_open_card_tx(param);
-#else
-    xpm_msg_open_tx(param);
-#endif
+    xpm_msg_open_tx(&param);
 
-    while(!xpm_msg_open_sent) {
+    while (!param.sent) {
         messages_wait_and_handle_next();
     }
 
-    return SYS_ERR_OK;
+    return param.err;
 }
 
 /**
@@ -353,13 +365,18 @@ errval_t xeon_phi_messaging_spawn(uint8_t xeon_phi_id,
 {
     errval_t err;
 
-    DEBUG_XPMC("Send spawn request %s on core %u.%u\n", name, xeon_phi_id, core);
-
+    /*
+     * if we are running on the Xeon Phi, there is just a single service instace
+     * running, so we enforce the Xeon Phi ID to be zero
+     */
 #ifdef __k1om__
     uint8_t xphi = 0;
 #else
     uint8_t xphi = xeon_phi_id;
 #endif
+
+    DEBUG_XPMC("spawn request %s on core %u.%u\n", name, xeon_phi_id, core);
+
     if (xpm_binding[xphi] == NULL) {
         err = xpm_connect(xphi);
         if (err_is_fail(err)) {
@@ -367,21 +384,22 @@ errval_t xeon_phi_messaging_spawn(uint8_t xeon_phi_id,
         }
     }
 
-    struct xpm_msg_param_spawn *param = malloc(sizeof(struct xpm_msg_param_spawn));
-    if (param == NULL) {
-        return LIB_ERR_MALLOC_FAIL;
+    struct xpm_msg_param_spawn param = {
+        .sent = 0x0,
+        .b = xpm_binding[xphi],
+        .core = core,
+        .xphi_id = xeon_phi_id  // here we have to take the original ID
+    };
+
+    snprintf(param.name, sizeof(param.name), "%s", name);
+
+    xpm_msg_spawn_tx(&param);
+
+    while (!param.sent) {
+        messages_wait_and_handle_next();
     }
 
-    param->b = xpm_binding[xphi];
-    param->core = core;
-    param->xphi_id = xeon_phi_id;
-    snprintf(param->name, sizeof(param->name), "%s", name);
-#ifdef __k1om__
-    xpm_msg_spawn_card_tx(param);
-#else
-    xpm_msg_spawn_tx(param);
-#endif
-    return SYS_ERR_OK;
+    return param.err;
 }
 
 /**
@@ -409,5 +427,7 @@ errval_t xeon_phi_messaging_kill(uint8_t xeon_phi_id,
         }
     }
 
+    assert(!"NYI");
+
     return SYS_ERR_OK;
 }