Improve fifo allocator performance
[vpp.git] / src / vlibapi / api.h
index 87a5612..0e2c210 100644 (file)
@@ -25,6 +25,7 @@
 #include <vlib/vlib.h>
 #include <vlibmemory/unix_shared_memory_queue.h>
 #include <vlib/unix/unix.h>
+#include <stddef.h>
 
 typedef enum
 {
@@ -112,6 +113,14 @@ typedef struct
   u16 last_msg_id;
 } vl_api_msg_range_t;
 
+typedef clib_error_t *(vl_msg_api_init_function_t) (u32 client_index);
+
+typedef struct _vl_msg_api_init_function_list_elt
+{
+  struct _vl_msg_api_init_function_list_elt *next_init_function;
+  vl_msg_api_init_function_t *f;
+} _vl_msg_api_function_list_elt_t;
+
 typedef struct
 {
   void (**msg_handlers) (void *);
@@ -119,7 +128,7 @@ typedef struct
   void (**msg_cleanup_handlers) (void *);
   void (**msg_endian_handlers) (void *);
   void (**msg_print_handlers) (void *, void *);
-  char **msg_names;
+  const char **msg_names;
   u8 *message_bounce;
   u8 *is_mp_safe;
   struct ring_alloc_ *arings;
@@ -184,14 +193,21 @@ typedef struct
 
   i32 vlib_signal;
 
+  /* vlib input queue length */
+  u32 vlib_input_queue_length;
+
   /* client side message index hash table */
   uword *msg_index_by_name_and_crc;
 
-  char *region_name;
-  char *root_path;
+  const char *region_name;
+  const char *root_path;
 
   /* Replay in progress? */
   int replay_in_progress;
+
+  /* List of API client reaper functions */
+  _vl_msg_api_function_list_elt_t *reaper_function_registrations;
+
 } api_main_t;
 
 extern api_main_t api_main;
@@ -264,9 +280,11 @@ void vl_msg_api_register_pd_handler (void *handler,
 int vl_msg_api_pd_handler (void *mp, int rv);
 
 void vl_msg_api_set_first_available_msg_id (u16 first_avail);
-u16 vl_msg_api_get_msg_ids (char *name, int n);
-void vl_msg_api_add_msg_name_crc (api_main_t * am, char *string, u32 id);
+u16 vl_msg_api_get_msg_ids (const char *name, int n);
+void vl_msg_api_add_msg_name_crc (api_main_t * am, const char *string,
+                                 u32 id);
 u32 vl_api_get_msg_index (u8 * name_and_crc);
+u32 vl_msg_api_get_msg_length (void *msg_arg);
 
 /* node_serialize.c prototypes */
 u8 *vlib_node_serialize (vlib_node_main_t * nm, u8 * vector,
@@ -291,6 +309,47 @@ vlib_node_t **vlib_node_unserialize (u8 * vector);
   })
 
 
+#define _VL_MSG_API_FUNCTION_SYMBOL(x, type)   \
+  _vl_msg_api_##type##_function_##x
+
+#define VL_MSG_API_FUNCTION_SYMBOL(x)          \
+  _VL_MSG_API_FUNCTION_SYMBOL(x, reaper)
+
+#define VLIB_DECLARE_REAPER_FUNCTION(x, tag)                            \
+vl_msg_api_init_function_t * _VL_MSG_API_FUNCTION_SYMBOL (x, tag) = x;  \
+static void __vl_msg_api_add_##tag##_function_##x (void)                \
+    __attribute__((__constructor__)) ;                                  \
+                                                                        \
+static void __vl_msg_api_add_##tag##_function_##x (void)                \
+{                                                                       \
+ api_main_t * am = &api_main;                                           \
+ static _vl_msg_api_function_list_elt_t _vl_msg_api_function;           \
+ _vl_msg_api_function.next_init_function                                \
+    = am->tag##_function_registrations;                                 \
+  am->tag##_function_registrations = &_vl_msg_api_function;             \
+ _vl_msg_api_function.f = &x;                                           \
+}
+
+#define VL_MSG_API_REAPER_FUNCTION(x) VLIB_DECLARE_REAPER_FUNCTION(x,reaper)
+
+/* Call reaper function with client index */
+#define vl_msg_api_call_reaper_function(ci)                             \
+  ({                                                                    \
+    extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (reaper);   \
+    vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (reaper);     \
+    clib_error_t * _error = 0;                                          \
+    _error = _f (ci);                                                   \
+  })
+
+static inline u32
+vl_msg_api_get_msg_length_inline (void *msg_arg)
+{
+  u8 *msg = (u8 *) msg_arg;
+
+  msgbuf_t *header = (msgbuf_t *) (msg - offsetof (msgbuf_t, data));
+
+  return clib_net_to_host_u32 (header->data_len);
+}
 #endif /* included_api_h */
 
 /*