* [dpdk-dev] [PATCH 1/2] sched: refine get base helper function
@ 2018-11-28 13:55 Tonghao Zhang
2018-11-28 13:55 ` [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize Tonghao Zhang
2018-12-20 19:10 ` [dpdk-dev] [PATCH 1/2] sched: refine get base helper function Dumitrescu, Cristian
0 siblings, 2 replies; 5+ messages in thread
From: Tonghao Zhang @ 2018-11-28 13:55 UTC (permalink / raw)
To: dev; +Cc: Tonghao Zhang
use switch instead of if, and it is more easy reading.
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
lib/librte_sched/rte_sched.c | 40 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
index 587d5e6..17de6e6 100644
--- a/lib/librte_sched/rte_sched.c
+++ b/lib/librte_sched/rte_sched.c
@@ -385,7 +385,7 @@ enum rte_sched_port_array {
uint32_t n_subports_per_port = params->n_subports_per_port;
uint32_t n_pipes_per_subport = params->n_pipes_per_subport;
uint32_t n_pipes_per_port = n_pipes_per_subport * n_subports_per_port;
- uint32_t n_queues_per_port = RTE_SCHED_QUEUES_PER_PIPE * n_pipes_per_subport * n_subports_per_port;
+ uint32_t n_queues_per_port = RTE_SCHED_QUEUES_PER_PIPE * n_pipes_per_port;
uint32_t size_subport = n_subports_per_port * sizeof(struct rte_sched_subport);
uint32_t size_pipe = n_pipes_per_port * sizeof(struct rte_sched_pipe);
@@ -407,35 +407,33 @@ enum rte_sched_port_array {
size_queue_array = n_pipes_per_port * size_per_pipe_queue_array;
base = 0;
+ switch (array) {
+ case e_RTE_SCHED_PORT_ARRAY_TOTAL:
+ base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
- if (array == e_RTE_SCHED_PORT_ARRAY_SUBPORT)
- return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_subport);
+ case e_RTE_SCHED_PORT_ARRAY_QUEUE_ARRAY:
+ base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
- if (array == e_RTE_SCHED_PORT_ARRAY_PIPE)
- return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
+ case e_RTE_SCHED_PORT_ARRAY_BMP_ARRAY:
+ base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
- if (array == e_RTE_SCHED_PORT_ARRAY_QUEUE)
- return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_queue);
+ case e_RTE_SCHED_PORT_ARRAY_PIPE_PROFILES:
+ base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
- if (array == e_RTE_SCHED_PORT_ARRAY_QUEUE_EXTRA)
- return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
+ case e_RTE_SCHED_PORT_ARRAY_QUEUE_EXTRA:
+ base += RTE_CACHE_LINE_ROUNDUP(size_queue);
- if (array == e_RTE_SCHED_PORT_ARRAY_PIPE_PROFILES)
- return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
+ case e_RTE_SCHED_PORT_ARRAY_QUEUE:
+ base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
- if (array == e_RTE_SCHED_PORT_ARRAY_BMP_ARRAY)
- return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
+ case e_RTE_SCHED_PORT_ARRAY_PIPE:
+ base += RTE_CACHE_LINE_ROUNDUP(size_subport);
- if (array == e_RTE_SCHED_PORT_ARRAY_QUEUE_ARRAY)
+ case e_RTE_SCHED_PORT_ARRAY_SUBPORT:
return base;
- base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
+ }
+ RTE_LOG(DEBUG, SCHED, "Should not reach here. \n");
return base;
}
--
1.8.3.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize
2018-11-28 13:55 [dpdk-dev] [PATCH 1/2] sched: refine get base helper function Tonghao Zhang
@ 2018-11-28 13:55 ` Tonghao Zhang
2018-12-11 2:54 ` Tonghao Zhang
2018-12-20 19:10 ` [dpdk-dev] [PATCH 1/2] sched: refine get base helper function Dumitrescu, Cristian
1 sibling, 1 reply; 5+ messages in thread
From: Tonghao Zhang @ 2018-11-28 13:55 UTC (permalink / raw)
To: dev; +Cc: Tonghao Zhang
In some case, we may create sched port dynamically,
if err when creating so memory will leak.
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
lib/librte_sched/rte_sched.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
index 17de6e6..a3adcca 100644
--- a/lib/librte_sched/rte_sched.c
+++ b/lib/librte_sched/rte_sched.c
@@ -724,6 +724,7 @@ struct rte_sched_port *
bmp_mem_size);
if (port->bmp == NULL) {
RTE_LOG(ERR, SCHED, "Bitmap init error\n");
+ rte_free(port);
return NULL;
}
--
1.8.3.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize
2018-11-28 13:55 ` [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize Tonghao Zhang
@ 2018-12-11 2:54 ` Tonghao Zhang
2018-12-20 19:09 ` Dumitrescu, Cristian
0 siblings, 1 reply; 5+ messages in thread
From: Tonghao Zhang @ 2018-12-11 2:54 UTC (permalink / raw)
To: dev
ping
On Wed, Nov 28, 2018 at 9:56 PM Tonghao Zhang <xiangxia.m.yue@gmail.com> wrote:
>
> In some case, we may create sched port dynamically,
> if err when creating so memory will leak.
>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
> lib/librte_sched/rte_sched.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
> index 17de6e6..a3adcca 100644
> --- a/lib/librte_sched/rte_sched.c
> +++ b/lib/librte_sched/rte_sched.c
> @@ -724,6 +724,7 @@ struct rte_sched_port *
> bmp_mem_size);
> if (port->bmp == NULL) {
> RTE_LOG(ERR, SCHED, "Bitmap init error\n");
> + rte_free(port);
> return NULL;
> }
>
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize
2018-12-11 2:54 ` Tonghao Zhang
@ 2018-12-20 19:09 ` Dumitrescu, Cristian
0 siblings, 0 replies; 5+ messages in thread
From: Dumitrescu, Cristian @ 2018-12-20 19:09 UTC (permalink / raw)
To: Tonghao Zhang, dev
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tonghao Zhang
> Sent: Tuesday, December 11, 2018 2:54 AM
> To: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize
>
> ping
> On Wed, Nov 28, 2018 at 9:56 PM Tonghao Zhang
> <xiangxia.m.yue@gmail.com> wrote:
> >
> > In some case, we may create sched port dynamically,
> > if err when creating so memory will leak.
> >
> > Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> > ---
> > lib/librte_sched/rte_sched.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
> > index 17de6e6..a3adcca 100644
> > --- a/lib/librte_sched/rte_sched.c
> > +++ b/lib/librte_sched/rte_sched.c
> > @@ -724,6 +724,7 @@ struct rte_sched_port *
> > bmp_mem_size);
> > if (port->bmp == NULL) {
> > RTE_LOG(ERR, SCHED, "Bitmap init error\n");
> > + rte_free(port);
> > return NULL;
> > }
> >
> > --
> > 1.8.3.1
> >
Also fixed another identical issue in the same function.
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Applied to next-qos tree, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [dpdk-dev] [PATCH 1/2] sched: refine get base helper function
2018-11-28 13:55 [dpdk-dev] [PATCH 1/2] sched: refine get base helper function Tonghao Zhang
2018-11-28 13:55 ` [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize Tonghao Zhang
@ 2018-12-20 19:10 ` Dumitrescu, Cristian
1 sibling, 0 replies; 5+ messages in thread
From: Dumitrescu, Cristian @ 2018-12-20 19:10 UTC (permalink / raw)
To: Tonghao Zhang, dev
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tonghao Zhang
> Sent: Wednesday, November 28, 2018 1:56 PM
> To: dev@dpdk.org
> Cc: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> Subject: [dpdk-dev] [PATCH 1/2] sched: refine get base helper function
>
> use switch instead of if, and it is more easy reading.
>
> Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
> ---
> lib/librte_sched/rte_sched.c | 40 +++++++++++++++++++---------------------
> 1 file changed, 19 insertions(+), 21 deletions(-)
>
> diff --git a/lib/librte_sched/rte_sched.c b/lib/librte_sched/rte_sched.c
> index 587d5e6..17de6e6 100644
> --- a/lib/librte_sched/rte_sched.c
> +++ b/lib/librte_sched/rte_sched.c
> @@ -385,7 +385,7 @@ enum rte_sched_port_array {
> uint32_t n_subports_per_port = params->n_subports_per_port;
> uint32_t n_pipes_per_subport = params->n_pipes_per_subport;
> uint32_t n_pipes_per_port = n_pipes_per_subport *
> n_subports_per_port;
> - uint32_t n_queues_per_port = RTE_SCHED_QUEUES_PER_PIPE *
> n_pipes_per_subport * n_subports_per_port;
> + uint32_t n_queues_per_port = RTE_SCHED_QUEUES_PER_PIPE *
> n_pipes_per_port;
>
> uint32_t size_subport = n_subports_per_port * sizeof(struct
> rte_sched_subport);
> uint32_t size_pipe = n_pipes_per_port * sizeof(struct
> rte_sched_pipe);
> @@ -407,35 +407,33 @@ enum rte_sched_port_array {
> size_queue_array = n_pipes_per_port *
> size_per_pipe_queue_array;
>
> base = 0;
> + switch (array) {
> + case e_RTE_SCHED_PORT_ARRAY_TOTAL:
> + base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_SUBPORT)
> - return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_subport);
> + case e_RTE_SCHED_PORT_ARRAY_QUEUE_ARRAY:
> + base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_PIPE)
> - return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
> + case e_RTE_SCHED_PORT_ARRAY_BMP_ARRAY:
> + base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_QUEUE)
> - return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_queue);
> + case e_RTE_SCHED_PORT_ARRAY_PIPE_PROFILES:
> + base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_QUEUE_EXTRA)
> - return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_queue_extra);
> + case e_RTE_SCHED_PORT_ARRAY_QUEUE_EXTRA:
> + base += RTE_CACHE_LINE_ROUNDUP(size_queue);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_PIPE_PROFILES)
> - return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_pipe_profiles);
> + case e_RTE_SCHED_PORT_ARRAY_QUEUE:
> + base += RTE_CACHE_LINE_ROUNDUP(size_pipe);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_BMP_ARRAY)
> - return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_bmp_array);
> + case e_RTE_SCHED_PORT_ARRAY_PIPE:
> + base += RTE_CACHE_LINE_ROUNDUP(size_subport);
>
> - if (array == e_RTE_SCHED_PORT_ARRAY_QUEUE_ARRAY)
> + case e_RTE_SCHED_PORT_ARRAY_SUBPORT:
> return base;
> - base += RTE_CACHE_LINE_ROUNDUP(size_queue_array);
> + }
>
> + RTE_LOG(DEBUG, SCHED, "Should not reach here. \n");
> return base;
> }
>
> --
> 1.8.3.1
NAK.
Sorry, but I completely disagree: to me, using the pattern you describe makes the code much harder to read as opposed to simpler to read.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-12-20 19:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 13:55 [dpdk-dev] [PATCH 1/2] sched: refine get base helper function Tonghao Zhang
2018-11-28 13:55 ` [dpdk-dev] [PATCH 2/2] sched: fix possible mem leak on initialize Tonghao Zhang
2018-12-11 2:54 ` Tonghao Zhang
2018-12-20 19:09 ` Dumitrescu, Cristian
2018-12-20 19:10 ` [dpdk-dev] [PATCH 1/2] sched: refine get base helper function Dumitrescu, Cristian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).