From: Jasvinder Singh Date: Thu, 29 Mar 2018 18:31:23 +0000 (+0100) Subject: pipeline: add traffic manager action X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=c8ae949197ca64c35181d01ef2943006c8296d8b;p=dpdk.git pipeline: add traffic manager action Add implementation of traffic manager action. Signed-off-by: Cristian Dumitrescu --- diff --git a/lib/librte_pipeline/Makefile b/lib/librte_pipeline/Makefile index 72e4c7c36d..c0eaa095b3 100644 --- a/lib/librte_pipeline/Makefile +++ b/lib/librte_pipeline/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_table -LDLIBS += -lrte_port -lrte_meter +LDLIBS += -lrte_port -lrte_meter -lrte_sched EXPORT_MAP := rte_pipeline_version.map diff --git a/lib/librte_pipeline/meson.build b/lib/librte_pipeline/meson.build index 71da2952f4..1ee276f62b 100644 --- a/lib/librte_pipeline/meson.build +++ b/lib/librte_pipeline/meson.build @@ -5,4 +5,4 @@ version = 3 allow_experimental_apis = true sources = files('rte_pipeline.c', 'rte_table_action.c') headers = files('rte_pipeline.h', 'rte_table_action.h') -deps += ['port', 'table', 'meter'] +deps += ['port', 'table', 'meter', 'sched'] diff --git a/lib/librte_pipeline/rte_table_action.c b/lib/librte_pipeline/rte_table_action.c index f3be28a337..791fc20f5e 100644 --- a/lib/librte_pipeline/rte_table_action.c +++ b/lib/librte_pipeline/rte_table_action.c @@ -297,6 +297,73 @@ pkt_work_mtr(struct rte_mbuf *mbuf, return drop_mask; } +/** + * RTE_TABLE_ACTION_TM + */ +static int +tm_cfg_check(struct rte_table_action_tm_config *tm) +{ + if ((tm->n_subports_per_port == 0) || + (rte_is_power_of_2(tm->n_subports_per_port) == 0) || + (tm->n_subports_per_port > UINT16_MAX) || + (tm->n_pipes_per_subport == 0) || + (rte_is_power_of_2(tm->n_pipes_per_subport) == 0)) + return -ENOTSUP; + + return 0; +} + +struct tm_data { + uint16_t queue_tc_color; + uint16_t subport; + uint32_t pipe; +} __attribute__((__packed__)); + +static int +tm_apply_check(struct rte_table_action_tm_params *p, + struct rte_table_action_tm_config *cfg) +{ + if ((p->subport_id >= cfg->n_subports_per_port) || + (p->pipe_id >= cfg->n_pipes_per_subport)) + return -EINVAL; + + return 0; +} + +static int +tm_apply(struct tm_data *data, + struct rte_table_action_tm_params *p, + struct rte_table_action_tm_config *cfg) +{ + int status; + + /* Check input arguments */ + status = tm_apply_check(p, cfg); + if (status) + return status; + + /* Apply */ + data->queue_tc_color = 0; + data->subport = (uint16_t) p->subport_id; + data->pipe = p->pipe_id; + + return 0; +} + +static __rte_always_inline void +pkt_work_tm(struct rte_mbuf *mbuf, + struct tm_data *data, + struct dscp_table_data *dscp_table, + uint32_t dscp) +{ + struct dscp_table_entry_data *dscp_entry = &dscp_table->entry[dscp]; + struct tm_data *sched_ptr = (struct tm_data *) &mbuf->hash.sched; + struct tm_data sched; + + sched = *data; + sched.queue_tc_color = dscp_entry->queue_tc_color; + *sched_ptr = sched; +} /** * Action profile @@ -307,6 +374,7 @@ action_valid(enum rte_table_action_type action) switch (action) { case RTE_TABLE_ACTION_FWD: case RTE_TABLE_ACTION_MTR: + case RTE_TABLE_ACTION_TM: return 1; default: return 0; @@ -320,6 +388,7 @@ struct ap_config { uint64_t action_mask; struct rte_table_action_common_config common; struct rte_table_action_mtr_config mtr; + struct rte_table_action_tm_config tm; }; static size_t @@ -328,6 +397,8 @@ action_cfg_size(enum rte_table_action_type action) switch (action) { case RTE_TABLE_ACTION_MTR: return sizeof(struct rte_table_action_mtr_config); + case RTE_TABLE_ACTION_TM: + return sizeof(struct rte_table_action_tm_config); default: return 0; } @@ -341,6 +412,9 @@ action_cfg_get(struct ap_config *ap_config, case RTE_TABLE_ACTION_MTR: return &ap_config->mtr; + case RTE_TABLE_ACTION_TM: + return &ap_config->tm; + default: return NULL; } @@ -375,6 +449,9 @@ action_data_size(enum rte_table_action_type action, case RTE_TABLE_ACTION_MTR: return mtr_data_size(&ap_config->mtr); + case RTE_TABLE_ACTION_TM: + return sizeof(struct tm_data); + default: return 0; } @@ -450,6 +527,10 @@ rte_table_action_profile_action_register(struct rte_table_action_profile *profil status = mtr_cfg_check(action_config); break; + case RTE_TABLE_ACTION_TM: + status = tm_cfg_check(action_config); + break; + default: status = 0; break; @@ -567,6 +648,11 @@ rte_table_action_apply(struct rte_table_action *action, action->mp, RTE_DIM(action->mp)); + case RTE_TABLE_ACTION_TM: + return tm_apply(action_data, + action_params, + &action->cfg.tm); + default: return -EINVAL; } @@ -581,7 +667,8 @@ rte_table_action_dscp_table_update(struct rte_table_action *action, /* Check input arguments */ if ((action == NULL) || - (action->cfg.action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) || + ((action->cfg.action_mask & ((1LLU << RTE_TABLE_ACTION_MTR) | + (1LLU << RTE_TABLE_ACTION_TM))) == 0) || (dscp_mask == 0) || (table == NULL)) return -EINVAL; @@ -773,6 +860,16 @@ pkt_work(struct rte_mbuf *mbuf, total_length); } + if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) { + void *data = + action_data_get(table_entry, action, RTE_TABLE_ACTION_TM); + + pkt_work_tm(mbuf, + data, + &action->dscp_table, + dscp); + } + return drop_mask; } @@ -886,6 +983,37 @@ pkt4_work(struct rte_mbuf **mbufs, total_length3); } + if (cfg->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) { + void *data0 = + action_data_get(table_entry0, action, RTE_TABLE_ACTION_TM); + void *data1 = + action_data_get(table_entry1, action, RTE_TABLE_ACTION_TM); + void *data2 = + action_data_get(table_entry2, action, RTE_TABLE_ACTION_TM); + void *data3 = + action_data_get(table_entry3, action, RTE_TABLE_ACTION_TM); + + pkt_work_tm(mbuf0, + data0, + &action->dscp_table, + dscp0); + + pkt_work_tm(mbuf1, + data1, + &action->dscp_table, + dscp1); + + pkt_work_tm(mbuf2, + data2, + &action->dscp_table, + dscp2); + + pkt_work_tm(mbuf3, + data3, + &action->dscp_table, + dscp3); + } + return drop_mask0 | (drop_mask1 << 1) | (drop_mask2 << 2) | diff --git a/lib/librte_pipeline/rte_table_action.h b/lib/librte_pipeline/rte_table_action.h index c2f4a55435..98babc501d 100644 --- a/lib/librte_pipeline/rte_table_action.h +++ b/lib/librte_pipeline/rte_table_action.h @@ -70,6 +70,9 @@ enum rte_table_action_type { /** Traffic Metering and Policing. */ RTE_TABLE_ACTION_MTR, + + /** Traffic Management. */ + RTE_TABLE_ACTION_TM, }; /** Common action configuration (per table action profile). */ @@ -255,6 +258,27 @@ struct rte_table_action_mtr_counters { uint32_t tc_mask; }; +/** + * RTE_TABLE_ACTION_TM + */ +/** Traffic management action configuration (per table action profile). */ +struct rte_table_action_tm_config { + /** Number of subports per port. */ + uint32_t n_subports_per_port; + + /** Number of pipes per subport. */ + uint32_t n_pipes_per_subport; +}; + +/** Traffic management action parameters (per table rule). */ +struct rte_table_action_tm_params { + /** Subport ID. */ + uint32_t subport_id; + + /** Pipe ID. */ + uint32_t pipe_id; +}; + /** * Table action profile. */