From: Jasvinder Singh Date: Fri, 6 Jul 2018 17:21:03 +0000 (+0100) Subject: net/softnic: add thread X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=bd2fbb6252f91afb0e5c35e248ad48d6d6e42733;p=dpdk.git net/softnic: add thread Add thread data structure and init function to run softnic pipelines objects. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- diff --git a/drivers/net/softnic/Makefile b/drivers/net/softnic/Makefile index 2397fbd77b..d002062167 100644 --- a/drivers/net/softnic/Makefile +++ b/drivers/net/softnic/Makefile @@ -31,6 +31,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tm.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tap.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_action.c SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_pipeline.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_thread.c # # Export include files diff --git a/drivers/net/softnic/meson.build b/drivers/net/softnic/meson.build index 7fd4b194f5..16604fca42 100644 --- a/drivers/net/softnic/meson.build +++ b/drivers/net/softnic/meson.build @@ -10,5 +10,6 @@ sources = files('rte_eth_softnic_tm.c', 'rte_eth_softnic_link.c', 'rte_eth_softnic_tap.c', 'rte_eth_softnic_action.c', - 'rte_eth_softnic_pipeline.c') + 'rte_eth_softnic_pipeline.c', + 'rte_eth_softnic_thread.c') deps += ['pipeline', 'port', 'table', 'sched'] diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index f68d2eb604..f89a1058bd 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -217,6 +217,7 @@ static void * pmd_init(struct pmd_params *params) { struct pmd_internals *p; + int status; p = rte_zmalloc_socket(params->name, sizeof(struct pmd_internals), @@ -239,6 +240,12 @@ pmd_init(struct pmd_params *params) softnic_table_action_profile_init(p); softnic_pipeline_init(p); + status = softnic_thread_init(p); + if (status) { + rte_free(p); + return NULL; + } + return p; } @@ -248,6 +255,7 @@ pmd_free(struct pmd_internals *p) if (p == NULL) return; + softnic_thread_free(p); softnic_pipeline_free(p); softnic_table_action_profile_free(p); softnic_port_in_action_profile_free(p); diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 52da1ae715..1c789420d4 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -415,10 +415,68 @@ struct pipeline { TAILQ_HEAD(pipeline_list, pipeline); +/** + * Thread + */ +#ifndef THREAD_PIPELINES_MAX +#define THREAD_PIPELINES_MAX 256 +#endif + +#ifndef THREAD_MSGQ_SIZE +#define THREAD_MSGQ_SIZE 64 +#endif + +#ifndef THREAD_TIMER_PERIOD_MS +#define THREAD_TIMER_PERIOD_MS 100 +#endif + +/** + * Master thead: data plane thread context + */ +struct softnic_thread { + struct rte_ring *msgq_req; + struct rte_ring *msgq_rsp; + + uint32_t enabled; +}; + +/** + * Data plane threads: context + */ #ifndef TABLE_RULE_ACTION_SIZE_MAX #define TABLE_RULE_ACTION_SIZE_MAX 2048 #endif +struct softnic_table_data { + struct rte_table_action *a; +}; + +struct pipeline_data { + struct rte_pipeline *p; + struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX]; + uint32_t n_tables; + + struct rte_ring *msgq_req; + struct rte_ring *msgq_rsp; + uint64_t timer_period; /* Measured in CPU cycles. */ + uint64_t time_next; + + uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX]; +}; + +struct softnic_thread_data { + struct rte_pipeline *p[THREAD_PIPELINES_MAX]; + uint32_t n_pipelines; + + struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX]; + struct rte_ring *msgq_req; + struct rte_ring *msgq_rsp; + uint64_t timer_period; /* Measured in CPU cycles. */ + uint64_t time_next; + uint64_t time_next_min; + uint64_t iter; +} __rte_cache_aligned; + /** * PMD Internals */ @@ -438,6 +496,8 @@ struct pmd_internals { struct softnic_port_in_action_profile_list port_in_action_profile_list; struct softnic_table_action_profile_list table_action_profile_list; struct pipeline_list pipeline_list; + struct softnic_thread thread[RTE_MAX_LCORE]; + struct softnic_thread_data thread_data[RTE_MAX_LCORE]; }; /** @@ -626,4 +686,13 @@ softnic_pipeline_table_create(struct pmd_internals *p, const char *pipeline_name, struct softnic_table_params *params); +/** + * Thread + */ +int +softnic_thread_init(struct pmd_internals *p); + +void +softnic_thread_free(struct pmd_internals *p); + #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */ diff --git a/drivers/net/softnic/rte_eth_softnic_thread.c b/drivers/net/softnic/rte_eth_softnic_thread.c new file mode 100644 index 0000000000..17a5a55908 --- /dev/null +++ b/drivers/net/softnic/rte_eth_softnic_thread.c @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + */ + +#include + +#include +#include +#include + +#include "rte_eth_softnic_internals.h" + +/** + * Master thread: data plane thread init + */ +void +softnic_thread_free(struct pmd_internals *softnic) +{ + uint32_t i; + + RTE_LCORE_FOREACH_SLAVE(i) { + struct softnic_thread *t = &softnic->thread[i]; + + /* MSGQs */ + if (t->msgq_req) + rte_ring_free(t->msgq_req); + + if (t->msgq_rsp) + rte_ring_free(t->msgq_rsp); + } +} + +int +softnic_thread_init(struct pmd_internals *softnic) +{ + uint32_t i; + + RTE_LCORE_FOREACH_SLAVE(i) { + char ring_name[NAME_MAX]; + struct rte_ring *msgq_req, *msgq_rsp; + struct softnic_thread *t = &softnic->thread[i]; + struct softnic_thread_data *t_data = &softnic->thread_data[i]; + uint32_t cpu_id = rte_lcore_to_socket_id(i); + + /* MSGQs */ + snprintf(ring_name, sizeof(ring_name), "%s-TH%u-REQ", + softnic->params.name, + i); + + msgq_req = rte_ring_create(ring_name, + THREAD_MSGQ_SIZE, + cpu_id, + RING_F_SP_ENQ | RING_F_SC_DEQ); + + if (msgq_req == NULL) { + softnic_thread_free(softnic); + return -1; + } + + snprintf(ring_name, sizeof(ring_name), "%s-TH%u-RSP", + softnic->params.name, + i); + + msgq_rsp = rte_ring_create(ring_name, + THREAD_MSGQ_SIZE, + cpu_id, + RING_F_SP_ENQ | RING_F_SC_DEQ); + + if (msgq_rsp == NULL) { + softnic_thread_free(softnic); + return -1; + } + + /* Master thread records */ + t->msgq_req = msgq_req; + t->msgq_rsp = msgq_rsp; + t->enabled = 1; + + /* Data plane thread records */ + t_data->n_pipelines = 0; + t_data->msgq_req = msgq_req; + t_data->msgq_rsp = msgq_rsp; + t_data->timer_period = + (rte_get_tsc_hz() * THREAD_TIMER_PERIOD_MS) / 1000; + t_data->time_next = rte_get_tsc_cycles() + t_data->timer_period; + t_data->time_next_min = t_data->time_next; + } + + return 0; +}