lib/metrics: fix to reset the init flag
PATCH 1/2 lib/metrics: fix to reset the init flag
metrics_initialized shall be reset in deinit function This is currently causing issue in running metrics_autotest mulutiple times
--- lib/librte_metrics/rte_metrics.c | 2 ++ 1 file changed, 2 insertions(+)
lib/librte_metrics/rte_metrics.c +2 -0
@@ -96,6 +96,8 @@ rte_metrics_deinit(void) stats = memzone->addr;memset (stats,0 ,sizeof (struct rte_metrics_data_s )); + metrics_initialized =0 ; +return rte_memzone_free (memzone); }
Signature · 1 line
2.17.1
PATCH 2/2 test: support cleanup in bitrate and latency test
both bitratestats_autotest latency test initializes the metrics library. It should be cleaned during exit.
--- app/test/test_bitratestats.c | 14 ++++++++++++++ app/test/test_latencystats.c | 3 +++ 2 files changed, 17 insertions(+)
app/test/test_bitratestats.c +14 -0
@@ -32,6 +32,18 @@ test_stats_bitrate_create(void)return TEST_SUCCESS ; } +/* To test free the resources from bitrate_reg test */ +static int +test_stats_bitrate_free (void ) +{ +int ret =0 ; + + ret =rte_metrics_deinit (); +TEST_ASSERT (ret >=0 ,"Test Failed: rte_metrics_deinit failed" ); + +return TEST_SUCCESS ; +} +/* To test bit rate registration */ static int test_stats_bitrate_reg (void )
@@ -214,6 +226,8 @@ unit_test_suite bitratestats_testsuite = {*/ TEST_CASE_ST (test_bit_packet_forward,NULL , test_stats_bitrate_calc), +/* TEST CASE 9: Test to do the cleanup w.r.t create */ +TEST_CASE (test_stats_bitrate_free), TEST_CASES_END() } };
app/test/test_latencystats.c +3 -0
@@ -60,6 +60,9 @@ static int test_latency_uninit(void) ret =rte_latencystats_uninit ();TEST_ASSERT (ret >=0 ,"Test Failed: rte_latencystats_uninit failed" ); + ret =rte_metrics_deinit (); +TEST_ASSERT (ret >=0 ,"Test Failed: rte_metrics_deinit failed" ); +return TEST_SUCCESS ; }
Signature · 1 line
2.17.1
Quoted 17 lines · Hemant Agrawal
metrics_initializedshall be reset in deinit function This is currently causing issue in runningmetrics_autotestmulutiple timesFixes 07c1b6925b65 ("telemetry: invert dependency on metrics library")Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_metrics/rte_metrics.c | 2 ++ 1 file changed, 2 insertions(+)lib/librte_metrics/rte_metrics.c +0
-0
lib/librte_metrics/rte_metrics.c rte_metrics_deinit(void) · line 101
Quoted 6 lines
lib/librte_metrics/rte_metrics.c +2
-0@@ -96,6 +96,8 @@ rte_metrics_deinit(void) stats = memzone->addr;memset (stats,0 ,sizeof (struct rte_metrics_data_s )); + metrics_initialized =0 ; +return rte_memzone_free (memzone);
Should this flag be reset only if rte_memzone_free succeeds?
Signature · 1 line
David Marchand
Quoted 24 lines
Quoted 21 lines · Hemant Agrawal
metrics_initializedshall be reset in deinit function This is currently causing issue in runningmetrics_autotestmulutiple timesFixes 07c1b6925b65 ("telemetry: invert dependency on metricslibrary")
Signed-off-by Hemant Agrawal <[email protected]>--- lib/librte_metrics/rte_metrics.c | 2 ++ 1 file changed, 2 insertions(+)lib/librte_metrics/rte_metrics.c +0
-0@@ -96,6 +96,8 @@ rte_metrics_deinit(void) stats = memzone->addr;memset (stats,0 ,sizeof (struct rte_metrics_data_s ));
Quoted 6 lines
lib/librte_metrics/rte_metrics.c rte_metrics_deinit(void) · line 101
Quoted 3 lines
lib/librte_metrics/rte_metrics.c +2
-0+ metrics_initialized =0 ; +return rte_memzone_free (memzone);Should this flag be reset only if
rte_memzone_freesucceeds?
[Hemant] I thought about it but I did not do it for following reasons.
1. If the memzone is not freed, It will not be initialized next time due to following check in init routine.
memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME); if (memzone != NULL) return;
2. Most applications have very weak error handling in de-init/cleanup parts.
Having said that. It can be changed to do it only on the success of rte_memzone_free
Quoted 3 lines
--
David Marchand
PATCH v2 1/2 lib/metrics: fix to reset the init flag
In reply to Hemant Agrawalmetrics_initialized shall be reset in deinit function This is currently causing issue in running metrics_autotest mulutiple times
--- lib/librte_metrics/rte_metrics.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
lib/librte_metrics/rte_metrics.c +5 -2
@@ -85,6 +85,7 @@ rte_metrics_deinit(void) {struct rte_metrics_data_s *stats;const struct rte_memzone *memzone; +int ret =0 ;if (rte_eal_process_type () !=RTE_PROC_PRIMARY )return -EINVAL ;
@@ -96,8 +97,10 @@ rte_metrics_deinit(void) stats = memzone->addr;memset (stats,0 ,sizeof (struct rte_metrics_data_s )); -return rte_memzone_free (memzone); - + ret =rte_memzone_free (memzone); +if (ret ==0 ) + metrics_initialized =0 ; +return ret; }int
Signature · 1 line
2.17.1
PATCH v2 2/2 test: support cleanup in bitrate and latency test
both bitratestats_autotest latency test initializes the metrics library. It should be cleaned during exit.
--- app/test/test_bitratestats.c | 14 ++++++++++++++ app/test/test_latencystats.c | 3 +++ 2 files changed, 17 insertions(+)
app/test/test_bitratestats.c +14 -0
@@ -32,6 +32,18 @@ test_stats_bitrate_create(void)return TEST_SUCCESS ; } +/* To test free the resources from bitrate_reg test */ +static int +test_stats_bitrate_free (void ) +{ +int ret =0 ; + + ret =rte_metrics_deinit (); +TEST_ASSERT (ret >=0 ,"Test Failed: rte_metrics_deinit failed" ); + +return TEST_SUCCESS ; +} +/* To test bit rate registration */ static int test_stats_bitrate_reg (void )
@@ -214,6 +226,8 @@ unit_test_suite bitratestats_testsuite = {*/ TEST_CASE_ST (test_bit_packet_forward,NULL , test_stats_bitrate_calc), +/* TEST CASE 9: Test to do the cleanup w.r.t create */ +TEST_CASE (test_stats_bitrate_free), TEST_CASES_END() } };
app/test/test_latencystats.c +3 -0
@@ -60,6 +60,9 @@ static int test_latency_uninit(void) ret =rte_latencystats_uninit ();TEST_ASSERT (ret >=0 ,"Test Failed: rte_latencystats_uninit failed" ); + ret =rte_metrics_deinit (); +TEST_ASSERT (ret >=0 ,"Test Failed: rte_metrics_deinit failed" ); +return TEST_SUCCESS ; }
Signature · 1 line
2.17.1
Re: [dpdk-dev] [PATCH v2 2/2] test: support cleanup in bitrate and latency test
app/test/test_bitratestats.c test_stats_bitrate_create(void) · line 41
Quoted 7 lines · On Tue, 19 May 2020 16:22:58 +0530 Hemant Agrawal <[email protected]>…
app/test/test_bitratestats.c +7
-0+/* To test free the resources from bitrate_reg test */ +static int +test_stats_bitrate_free (void ) +{ +int ret =0 ; + + ret =rte_metrics_deinit ();
Coverity will complain about extra initialization like this
Quoted 8 lines · Hemant Agrawal
metrics_initializedshall be reset in deinit function This is currently causing issue in runningmetrics_autotestmulutiple timesFixes 07c1b6925b65 ("telemetry: invert dependency on metrics library")Signed-off-by Hemant Agrawal <[email protected]>
For the series,
Applied, thanks.
Signature · 1 line
David Marchand
lib/librte_metrics/rte_metrics.c rte_metrics_deinit(void) · line 89
Quoted 10 lines · On Tue, 19 May 2020 16:22:57 +0530 Hemant Agrawal <[email protected]>…
lib/librte_metrics/rte_metrics.c +1
-0@@ -85,6 +85,7 @@ rte_metrics_deinit(void) {struct rte_metrics_data_s *stats;const struct rte_memzone *memzone; +int ret =0 ;
Why do gratuitous initialization? It blocks compiler from finding buggy code.