[dpdk-dev] [PATCH v2 02/10] sched: add subport profile table
Savinay Dharmappa
savinay.dharmappa at intel.com
Thu Sep 10 20:48:29 CEST 2020
Add subport profile table to internal port data structure and
update the port config function.
Signed-off-by: Savinay Dharmappa <savinay.dharmappa at intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh at intel.com>
---
lib/librte_sched/rte_sched.c | 185 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 182 insertions(+), 3 deletions(-)
diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
index 474422b..ec6e6bf 100644
--- a/lib/librte_sched/rte_sched.c
+++ b/lib/librte_sched/rte_sched.c
@@ -223,6 +223,8 @@ struct rte_sched_port {
uint16_t pipe_queue[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
uint8_t pipe_tc[RTE_SCHED_QUEUES_PER_PIPE];
uint8_t tc_queue[RTE_SCHED_QUEUES_PER_PIPE];
+ uint32_t n_subport_profiles;
+ uint32_t n_max_subport_profiles;
uint64_t rate;
uint32_t mtu;
uint32_t frame_overhead;
@@ -241,6 +243,7 @@ struct rte_sched_port {
uint32_t subport_id;
/* Large data structures */
+ struct rte_sched_subport_profile *subport_profiles;
struct rte_sched_subport *subports[0] __rte_cache_aligned;
} __rte_cache_aligned;
@@ -387,8 +390,60 @@ pipe_profile_check(struct rte_sched_pipe_params *params,
}
static int
+subport_profile_check(struct rte_sched_subport_profile_params *params,
+ uint64_t rate)
+{
+ uint32_t i;
+
+ /* Check user parameters */
+ if (params == NULL) {
+ RTE_LOG(ERR, SCHED, "%s: "
+ "Incorrect value for parameter params\n", __func__);
+ return -EINVAL;
+ }
+
+ if (params->tb_rate == 0 || params->tb_rate > rate) {
+ RTE_LOG(ERR, SCHED, "%s: "
+ "Incorrect value for tb rate\n", __func__);
+ return -EINVAL;
+ }
+
+ if (params->tb_size == 0) {
+ RTE_LOG(ERR, SCHED, "%s: "
+ "Incorrect value for tb size\n", __func__);
+ return -EINVAL;
+ }
+
+ for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
+ uint64_t tc_rate = params->tc_rate[i];
+
+ if (tc_rate == 0 || (tc_rate > params->tb_rate)) {
+ RTE_LOG(ERR, SCHED, "%s: "
+ "Incorrect value for tc rate\n", __func__);
+ return -EINVAL;
+ }
+ }
+
+ if (params->tc_rate[RTE_SCHED_TRAFFIC_CLASS_BE] == 0) {
+ RTE_LOG(ERR, SCHED, "%s: "
+ "Incorrect tc rate(best effort)\n", __func__);
+ return -EINVAL;
+ }
+
+ if (params->tc_period == 0) {
+ RTE_LOG(ERR, SCHED, "%s: "
+ "Incorrect value for tc period\n", __func__);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int
rte_sched_port_check_params(struct rte_sched_port_params *params)
{
+ uint32_t i;
+
if (params == NULL) {
RTE_LOG(ERR, SCHED,
"%s: Incorrect value for parameter params\n", __func__);
@@ -425,6 +480,29 @@ rte_sched_port_check_params(struct rte_sched_port_params *params)
return -EINVAL;
}
+ if (params->subport_profiles == NULL ||
+ params->n_subport_profiles == 0 ||
+ params->n_max_subport_profiles == 0 ||
+ params->n_subport_profiles > params->n_max_subport_profiles) {
+ RTE_LOG(ERR, SCHED,
+ "%s: Incorrect value for subport profiles\n", __func__);
+ return -EINVAL;
+ }
+
+ for (i = 0; i < params->n_subport_profiles; i++) {
+ struct rte_sched_subport_profile_params *p =
+ params->subport_profiles + i;
+ int status;
+
+ status = subport_profile_check(p, params->rate);
+ if (status != 0) {
+ RTE_LOG(ERR, SCHED,
+ "%s: subport profile check failed(%d)\n",
+ __func__, status);
+ return -EINVAL;
+ }
+ }
+
/* n_pipes_per_subport: non-zero, power of 2 */
if (params->n_pipes_per_subport == 0 ||
!rte_is_power_of_2(params->n_pipes_per_subport)) {
@@ -566,6 +644,42 @@ rte_sched_port_log_pipe_profile(struct rte_sched_subport *subport, uint32_t i)
p->wrr_cost[0], p->wrr_cost[1], p->wrr_cost[2], p->wrr_cost[3]);
}
+static void
+rte_sched_port_log_subport_profile(struct rte_sched_port *port, uint32_t i)
+{
+ struct rte_sched_subport_profile *p = port->subport_profiles + i;
+
+ RTE_LOG(DEBUG, SCHED, "Low level config for subport profile %u:\n"
+ "Token bucket: period = %"PRIu64", credits per period = %"PRIu64","
+ "size = %"PRIu64"\n"
+ "Traffic classes: period = %"PRIu64",\n"
+ "credits per period = [%"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
+ " %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64", %"PRIu64
+ " %"PRIu64", %"PRIu64", %"PRIu64"]\n",
+ i,
+
+ /* Token bucket */
+ p->tb_period,
+ p->tb_credits_per_period,
+ p->tb_size,
+
+ /* Traffic classes */
+ p->tc_period,
+ p->tc_credits_per_period[0],
+ p->tc_credits_per_period[1],
+ p->tc_credits_per_period[2],
+ p->tc_credits_per_period[3],
+ p->tc_credits_per_period[4],
+ p->tc_credits_per_period[5],
+ p->tc_credits_per_period[6],
+ p->tc_credits_per_period[7],
+ p->tc_credits_per_period[8],
+ p->tc_credits_per_period[9],
+ p->tc_credits_per_period[10],
+ p->tc_credits_per_period[11],
+ p->tc_credits_per_period[12]);
+}
+
static inline uint64_t
rte_sched_time_ms_to_bytes(uint64_t time_ms, uint64_t rate)
{
@@ -635,6 +749,37 @@ rte_sched_pipe_profile_convert(struct rte_sched_subport *subport,
}
static void
+rte_sched_subport_profile_convert(struct rte_sched_subport_profile_params *src,
+ struct rte_sched_subport_profile *dst,
+ uint64_t rate)
+{
+ uint32_t i;
+
+ /* Token Bucket */
+ if (src->tb_rate == rate) {
+ dst->tb_credits_per_period = 1;
+ dst->tb_period = 1;
+ } else {
+ double tb_rate = (double) src->tb_rate
+ / (double) rate;
+ double d = RTE_SCHED_TB_RATE_CONFIG_ERR;
+
+ rte_approx_64(tb_rate, d, &dst->tb_credits_per_period,
+ &dst->tb_period);
+ }
+
+ dst->tb_size = src->tb_size;
+
+ /* Traffic Classes */
+ dst->tc_period = rte_sched_time_ms_to_bytes(src->tc_period, rate);
+
+ for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
+ dst->tc_credits_per_period[i]
+ = rte_sched_time_ms_to_bytes(src->tc_period,
+ src->tc_rate[i]);
+}
+
+static void
rte_sched_subport_config_pipe_profile_table(struct rte_sched_subport *subport,
struct rte_sched_subport_params *params, uint64_t rate)
{
@@ -658,6 +803,24 @@ rte_sched_subport_config_pipe_profile_table(struct rte_sched_subport *subport,
}
}
+static void
+rte_sched_port_config_subport_profile_table(struct rte_sched_port *port,
+ struct rte_sched_port_params *params,
+ uint64_t rate)
+{
+ uint32_t i;
+
+ for (i = 0; i < port->n_subport_profiles; i++) {
+ struct rte_sched_subport_profile_params *src
+ = params->subport_profiles + i;
+ struct rte_sched_subport_profile *dst
+ = port->subport_profiles + i;
+
+ rte_sched_subport_profile_convert(src, dst, rate);
+ rte_sched_port_log_subport_profile(port, i);
+ }
+}
+
static int
rte_sched_subport_check_params(struct rte_sched_subport_params *params,
uint32_t n_max_pipes_per_subport,
@@ -804,7 +967,7 @@ struct rte_sched_port *
rte_sched_port_config(struct rte_sched_port_params *params)
{
struct rte_sched_port *port = NULL;
- uint32_t size0, size1;
+ uint32_t size0, size1, size2;
uint32_t cycles_per_byte;
uint32_t i, j;
int status;
@@ -819,10 +982,21 @@ rte_sched_port_config(struct rte_sched_port_params *params)
size0 = sizeof(struct rte_sched_port);
size1 = params->n_subports_per_port * sizeof(struct rte_sched_subport *);
+ size2 = params->n_max_subport_profiles *
+ sizeof(struct rte_sched_subport_profile);
/* Allocate memory to store the data structures */
- port = rte_zmalloc_socket("qos_params", size0 + size1, RTE_CACHE_LINE_SIZE,
- params->socket);
+ port = rte_zmalloc_socket("qos_params", size0 + size1,
+ RTE_CACHE_LINE_SIZE, params->socket);
+ if (port == NULL) {
+ RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
+
+ return NULL;
+ }
+
+ /* Allocate memory to store the subport profile */
+ port->subport_profiles = rte_zmalloc_socket("subport_profile", size2,
+ RTE_CACHE_LINE_SIZE, params->socket);
if (port == NULL) {
RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__);
@@ -831,6 +1005,8 @@ rte_sched_port_config(struct rte_sched_port_params *params)
/* User parameters */
port->n_subports_per_port = params->n_subports_per_port;
+ port->n_subport_profiles = params->n_subport_profiles;
+ port->n_max_subport_profiles = params->n_max_subport_profiles;
port->n_pipes_per_subport = params->n_pipes_per_subport;
port->n_pipes_per_subport_log2 =
__builtin_ctz(params->n_pipes_per_subport);
@@ -861,6 +1037,9 @@ rte_sched_port_config(struct rte_sched_port_params *params)
port->time_cpu_bytes = 0;
port->time = 0;
+ /* Subport profile table */
+ rte_sched_port_config_subport_profile_table(port, params, port->rate);
+
cycles_per_byte = (rte_get_tsc_hz() << RTE_SCHED_TIME_SHIFT)
/ params->rate;
port->inv_cycles_per_byte = rte_reciprocal_value(cycles_per_byte);
--
2.7.4
More information about the dev
mailing list