From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 32952A0548; Fri, 23 Apr 2021 13:01:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0BBEE41DE0; Fri, 23 Apr 2021 13:01:11 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 9DD2241DD3 for ; Fri, 23 Apr 2021 13:01:07 +0200 (CEST) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FRWVp3f2LzvSVK for ; Fri, 23 Apr 2021 18:58:42 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Fri, 23 Apr 2021 19:01:01 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Fri, 23 Apr 2021 19:01:12 +0800 Message-ID: <1619175672-20016-3-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619175672-20016-1-git-send-email-humin29@huawei.com> References: <1619175672-20016-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 2/2] lib/sched: optimize exception handling code X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Huisong Li Currently, rte_sched_free_memory() is called multiple times by the exception handling code in rte_sched_subport_config() and rte_sched_pipe_config(). This patch optimizes them into a unified outlet to free memory. Fixes: ac6fcb841b0f ("sched: update subport rate dynamically") Fixes: 34a90f86657c ("sched: modify pipe functions for config flexibility") Fixes: ce7c4fd7c2ac ("sched: add pipe config to subport level") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) --- lib/sched/rte_sched.c | 56 +++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/sched/rte_sched.c b/lib/sched/rte_sched.c index df0ab5c..a858f61 100644 --- a/lib/sched/rte_sched.c +++ b/lib/sched/rte_sched.c @@ -1090,6 +1090,7 @@ rte_sched_subport_config(struct rte_sched_port *port, uint32_t n_subport_pipe_queues, i; uint32_t size0, size1, bmp_mem_size; int status; + int ret; /* Check user parameters */ if (port == NULL) { @@ -1101,17 +1102,16 @@ rte_sched_subport_config(struct rte_sched_port *port, if (subport_id >= port->n_subports_per_port) { RTE_LOG(ERR, SCHED, "%s: Incorrect value for subport id\n", __func__); - - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } if (subport_profile_id >= port->n_max_subport_profiles) { RTE_LOG(ERR, SCHED, "%s: " "Number of subport profile exceeds the max limit\n", __func__); - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } /** Memory is allocated only on first invocation of the api for a @@ -1127,9 +1127,8 @@ rte_sched_subport_config(struct rte_sched_port *port, RTE_LOG(NOTICE, SCHED, "%s: Port scheduler params check failed (%d)\n", __func__, status); - - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } /* Determine the amount of memory to allocate */ @@ -1143,9 +1142,8 @@ rte_sched_subport_config(struct rte_sched_port *port, if (s == NULL) { RTE_LOG(ERR, SCHED, "%s: Memory allocation fails\n", __func__); - - rte_sched_free_memory(port, n_subports); - return -ENOMEM; + ret = -ENOMEM; + goto out; } n_subports++; @@ -1185,12 +1183,11 @@ rte_sched_subport_config(struct rte_sched_port *port, params->red_params[i][j].min_th, params->red_params[i][j].max_th, params->red_params[i][j].maxp_inv) != 0) { - rte_sched_free_memory(port, n_subports); - RTE_LOG(NOTICE, SCHED, "%s: RED configuration init fails\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto out; } } } @@ -1238,9 +1235,8 @@ rte_sched_subport_config(struct rte_sched_port *port, if (s->bmp == NULL) { RTE_LOG(ERR, SCHED, "%s: Subport bitmap init error\n", __func__); - - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } for (i = 0; i < RTE_SCHED_PORT_N_GRINDERS; i++) @@ -1285,6 +1281,11 @@ rte_sched_subport_config(struct rte_sched_port *port, rte_sched_port_log_subport_profile(port, subport_profile_id); return 0; + +out: + rte_sched_free_memory(port, n_subports); + + return ret; } int @@ -1299,6 +1300,7 @@ rte_sched_pipe_config(struct rte_sched_port *port, struct rte_sched_pipe_profile *params; uint32_t n_subports = subport_id + 1; uint32_t deactivate, profile, i; + int ret; /* Check user parameters */ profile = (uint32_t) pipe_profile; @@ -1313,26 +1315,23 @@ rte_sched_pipe_config(struct rte_sched_port *port, if (subport_id >= port->n_subports_per_port) { RTE_LOG(ERR, SCHED, "%s: Incorrect value for parameter subport id\n", __func__); - - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } s = port->subports[subport_id]; if (pipe_id >= s->n_pipes_per_subport_enabled) { RTE_LOG(ERR, SCHED, "%s: Incorrect value for parameter pipe id\n", __func__); - - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } if (!deactivate && profile >= s->n_pipe_profiles) { RTE_LOG(ERR, SCHED, "%s: Incorrect value for parameter pipe profile\n", __func__); - - rte_sched_free_memory(port, n_subports); - return -EINVAL; + ret = -EINVAL; + goto out; } sp = port->subport_profiles + s->profile; @@ -1406,6 +1405,11 @@ rte_sched_pipe_config(struct rte_sched_port *port, } return 0; + +out: + rte_sched_free_memory(port, n_subports); + + return ret; } int -- 2.7.4