Improve fifo allocator performance
[vpp.git] / src / uri / uri_tcp_test.c
index 0b4aae3..e201a35 100755 (executable)
@@ -173,6 +173,8 @@ wait_for_state_change (uri_tcp_test_main_t * utm, connection_state_t state)
        return 0;
       if (utm->state == STATE_FAILED)
        return -1;
+      if (utm->time_to_stop == 1)
+       return -1;
     }
   clib_warning ("timeout waiting for STATE_READY");
   return -1;
@@ -191,6 +193,7 @@ application_send_attach (uri_tcp_test_main_t * utm)
   bmp->context = ntohl (0xfeedface);
   bmp->options[APP_OPTIONS_FLAGS] =
     APP_OPTIONS_FLAGS_USE_FIFO | APP_OPTIONS_FLAGS_ADD_SEGMENT;
+  bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 16;
   bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = fifo_size;
   bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = fifo_size;
   bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20;
@@ -260,7 +263,8 @@ vl_api_application_attach_reply_t_handler (vl_api_application_attach_reply_t *
     }
 
   utm->our_event_queue =
-    (unix_shared_memory_queue_t *) mp->app_event_queue_address;
+    uword_to_pointer (mp->app_event_queue_address,
+                     unix_shared_memory_queue_t *);
   utm->state = STATE_ATTACHED;
 }
 
@@ -522,8 +526,9 @@ vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
       return;
     }
 
-  utm->vpp_event_queue = (unix_shared_memory_queue_t *)
-    mp->vpp_event_queue_address;
+  utm->vpp_event_queue =
+    uword_to_pointer (mp->vpp_event_queue_address,
+                     unix_shared_memory_queue_t *);
 
   /*
    * Setup session
@@ -532,9 +537,9 @@ vl_api_connect_uri_reply_t_handler (vl_api_connect_uri_reply_t * mp)
   pool_get (utm->sessions, session);
   session_index = session - utm->sessions;
 
-  rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
+  rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
   rx_fifo->client_session_index = session_index;
-  tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
+  tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
   tx_fifo->client_session_index = session_index;
 
   session->server_rx_fifo = rx_fifo;
@@ -736,7 +741,7 @@ vl_api_bind_uri_reply_t_handler (vl_api_bind_uri_reply_t * mp)
 
   if (mp->retval)
     {
-      clib_warning ("bind failed: %s", format_api_error,
+      clib_warning ("bind failed: %U", format_api_error,
                    clib_net_to_host_u32 (mp->retval));
       utm->state = STATE_FAILED;
       return;
@@ -856,16 +861,17 @@ vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
   ip_str = format (0, "%U", format_ip46_address, &mp->ip, mp->is_ip4);
   clib_warning ("Accepted session from: %s:%d", ip_str,
                clib_net_to_host_u16 (mp->port));
-  utm->vpp_event_queue = (unix_shared_memory_queue_t *)
-    mp->vpp_event_queue_address;
+  utm->vpp_event_queue =
+    uword_to_pointer (mp->vpp_event_queue_address,
+                     unix_shared_memory_queue_t *);
 
   /* Allocate local session and set it up */
   pool_get (utm->sessions, session);
   session_index = session - utm->sessions;
 
-  rx_fifo = (svm_fifo_t *) mp->server_rx_fifo;
+  rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *);
   rx_fifo->client_session_index = session_index;
-  tx_fifo = (svm_fifo_t *) mp->server_tx_fifo;
+  tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *);
   tx_fifo->client_session_index = session_index;
 
   session->server_rx_fifo = rx_fifo;