pipeline: add SWX pipeline instructions
authorCristian Dumitrescu <cristian.dumitrescu@intel.com>
Thu, 1 Oct 2020 10:19:36 +0000 (11:19 +0100)
committerDavid Marchand <david.marchand@redhat.com>
Thu, 1 Oct 2020 16:43:07 +0000 (18:43 +0200)
The SWX pipeline instructions represent the main program that defines
the life of the packet. As packets go through tables that trigger
action subroutines, the headers and meta-data get transformed along
the way.

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

index c6357cf..6fe0aa0 100644 (file)
@@ -68,6 +68,7 @@ EXPERIMENTAL {
        rte_swx_pipeline_extern_type_member_func_register;
        rte_swx_pipeline_extern_type_register;
        rte_swx_pipeline_free;
+       rte_swx_pipeline_instructions_config;
        rte_swx_pipeline_packet_header_register;
        rte_swx_pipeline_packet_metadata_register;
        rte_swx_pipeline_port_in_config;
index eb5b327..2ae6229 100644 (file)
@@ -274,6 +274,10 @@ struct thread {
        /* Extern objects and functions. */
        struct extern_obj_runtime *extern_objs;
        struct extern_func_runtime *extern_funcs;
+
+       /* Instructions. */
+       struct instruction *ip;
+       struct instruction *ret;
 };
 
 #ifndef RTE_SWX_PIPELINE_THREADS_MAX
@@ -300,6 +304,7 @@ struct rte_swx_pipeline {
        struct port_out_runtime *out;
        struct instruction **action_instructions;
        struct rte_swx_table_state *table_state;
+       struct instruction *instructions;
        struct thread threads[RTE_SWX_PIPELINE_THREADS_MAX];
 
        uint32_t n_structs;
@@ -310,6 +315,7 @@ struct rte_swx_pipeline {
        uint32_t n_actions;
        uint32_t n_tables;
        uint32_t n_headers;
+       uint32_t n_instructions;
        int build_done;
        int numa_node;
 };
@@ -1424,6 +1430,12 @@ metadata_free(struct rte_swx_pipeline *p)
 /*
  * Instruction.
  */
+static inline void
+thread_ip_reset(struct rte_swx_pipeline *p, struct thread *t)
+{
+       t->ip = p->instructions;
+}
+
 static int
 instruction_config(struct rte_swx_pipeline *p __rte_unused,
                   struct action *a __rte_unused,
@@ -2110,6 +2122,8 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p)
        if (!p)
                return;
 
+       free(p->instructions);
+
        table_state_free(p);
        table_free(p);
        action_free(p);
@@ -2124,6 +2138,28 @@ rte_swx_pipeline_free(struct rte_swx_pipeline *p)
        free(p);
 }
 
+int
+rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
+                                    const char **instructions,
+                                    uint32_t n_instructions)
+{
+       int err;
+       uint32_t i;
+
+       err = instruction_config(p, NULL, instructions, n_instructions);
+       if (err)
+               return err;
+
+       /* Thread instruction pointer reset. */
+       for (i = 0; i < RTE_SWX_PIPELINE_THREADS_MAX; i++) {
+               struct thread *t = &p->threads[i];
+
+               thread_ip_reset(p, t);
+       }
+
+       return 0;
+}
+
 int
 rte_swx_pipeline_build(struct rte_swx_pipeline *p)
 {
index 4d2af1b..ec76294 100644 (file)
@@ -495,6 +495,26 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p,
                              const char *args,
                              uint32_t size);
 
+/**
+ * Pipeline instructions configure
+ *
+ * @param[in] p
+ *   Pipeline handle.
+ * @param[in] instructions
+ *   Pipeline instructions.
+ * @param[in] n_instructions
+ *   Number of pipeline instructions.
+ * @return
+ *   0 on success or the following error codes otherwise:
+ *   -EINVAL: Invalid argument;
+ *   -ENOMEM: Not enough space/cannot allocate memory.
+ */
+__rte_experimental
+int
+rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
+                                    const char **instructions,
+                                    uint32_t n_instructions);
+
 /**
  * Pipeline build
  *