pipeline: introduce custom instructions
authorCristian Dumitrescu <cristian.dumitrescu@intel.com>
Mon, 13 Sep 2021 16:44:37 +0000 (17:44 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 27 Sep 2021 10:09:13 +0000 (12:09 +0200)
For better performance, the option to create custom instructions when
the program is translated and add them on-the-fly to the pipeline is
now provided. Multiple regular instructions can now be consolidated
into a single C function optimized by the C compiler directly.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
lib/pipeline/rte_swx_pipeline.c
lib/pipeline/rte_swx_pipeline_internal.h

index 0d02548..9afe42e 100644 (file)
@@ -6590,8 +6590,6 @@ error:
        return err;
 }
 
-typedef void (*instr_exec_t)(struct rte_swx_pipeline *);
-
 static instr_exec_t instruction_table[] = {
        [INSTR_RX] = instr_rx_exec,
        [INSTR_TX] = instr_tx_exec,
@@ -6782,12 +6780,41 @@ static instr_exec_t instruction_table[] = {
        [INSTR_RETURN] = instr_return_exec,
 };
 
+static int
+instruction_table_build(struct rte_swx_pipeline *p)
+{
+       p->instruction_table = calloc(RTE_SWX_PIPELINE_INSTRUCTION_TABLE_SIZE_MAX,
+                                     sizeof(struct instr_exec_t *));
+       if (!p->instruction_table)
+               return -EINVAL;
+
+       memcpy(p->instruction_table, instruction_table, sizeof(instruction_table));
+
+       return 0;
+}
+
+static void
+instruction_table_build_free(struct rte_swx_pipeline *p)
+{
+       if (!p->instruction_table)
+               return;
+
+       free(p->instruction_table);
+       p->instruction_table = NULL;
+}
+
+static void
+instruction_table_free(struct rte_swx_pipeline *p)
+{
+       instruction_table_build_free(p);
+}
+
 static inline void
 instr_exec(struct rte_swx_pipeline *p)
 {
        struct thread *t = &p->threads[p->thread_id];
        struct instruction *ip = t->ip;
-       instr_exec_t instr = instruction_table[ip->type];
+       instr_exec_t instr = p->instruction_table[ip->type];
 
        instr(p);
 }
@@ -8916,6 +8943,7 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p)
        selector_free(p);
        table_free(p);
        action_free(p);
+       instruction_table_free(p);
        metadata_free(p);
        header_free(p);
        extern_func_free(p);
@@ -8985,6 +9013,10 @@ rte_swx_pipeline_build(struct rte_swx_pipeline *p)
        if (status)
                goto error;
 
+       status = instruction_table_build(p);
+       if (status)
+               goto error;
+
        status = action_build(p);
        if (status)
                goto error;
@@ -9024,6 +9056,7 @@ error:
        selector_build_free(p);
        table_build_free(p);
        action_build_free(p);
+       instruction_table_build_free(p);
        metadata_build_free(p);
        header_build_free(p);
        extern_func_build_free(p);
index 3578a10..64625b4 100644 (file)
@@ -541,6 +541,9 @@ enum instruction_type {
         * Return from action
         */
        INSTR_RETURN,
+
+       /* Start of custom instructions. */
+       INSTR_CUSTOM_0,
 };
 
 struct instr_operand {
@@ -686,6 +689,8 @@ struct instruction_data {
        int invalid;
 };
 
+typedef void (*instr_exec_t)(struct rte_swx_pipeline *);
+
 /*
  * Action.
  */
@@ -1363,6 +1368,10 @@ instr_operand_nbo(struct thread *t, const struct instr_operand *x)
 #define RTE_SWX_PIPELINE_THREADS_MAX 16
 #endif
 
+#ifndef RTE_SWX_PIPELINE_INSTRUCTION_TABLE_SIZE_MAX
+#define RTE_SWX_PIPELINE_INSTRUCTION_TABLE_SIZE_MAX 256
+#endif
+
 struct rte_swx_pipeline {
        struct struct_type_tailq struct_types;
        struct port_in_type_tailq port_in_types;
@@ -1396,6 +1405,7 @@ struct rte_swx_pipeline {
        struct metarray_runtime *metarray_runtime;
        struct instruction *instructions;
        struct instruction_data *instruction_data;
+       instr_exec_t *instruction_table;
        struct thread threads[RTE_SWX_PIPELINE_THREADS_MAX];
 
        uint32_t n_structs;