DPDK patches and discussions
 help / color / mirror / Atom feed
From: Harman Kalra <hkalra@marvell.com>
To: "remy.horton@intel.com" <remy.horton@intel.com>,
	"anatoly.burakov@intel.com" <anatoly.burakov@intel.com>,
	"marko.kovacevic@intel.com" <marko.kovacevic@intel.com>,
	"john.mcnamara@intel.com" <john.mcnamara@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"stable@dpdk.org" <stable@dpdk.org>,
	"Harman Kalra" <hkalra@marvell.com>
Subject: [dpdk-dev] [PATCH v2 1/2] metrics: new API to deinitialise metrics library
Date: Fri, 1 Mar 2019 10:07:35 +0000	[thread overview]
Message-ID: <1551434828-3518-1-git-send-email-hkalra@marvell.com> (raw)
In-Reply-To: <1551264691-26353-1-git-send-email-hkalra@marvell.com>

Once the library usage is over, it must be deinitialized which
will free the shared memory reserved during initialization.

Fixes: observed an issue while running 'metrics_autotest'
continuously without quiting. For the first run 'metrics_autotest'
passes all test cases but second run onwards first test case
fails because metrics library is already initialized during
first run.
Cc: stable@dpdk.org

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
v2:
* Adding stable@dpdk.org into cc as this patch falls between bug fix
and new feature.

 doc/guides/prog_guide/metrics_lib.rst      | 14 ++++++++++++++
 lib/librte_metrics/rte_metrics.c           | 20 ++++++++++++++++++++
 lib/librte_metrics/rte_metrics.h           | 17 +++++++++++++++++
 lib/librte_metrics/rte_metrics_version.map |  6 ++++++
 4 files changed, 57 insertions(+)

diff --git a/doc/guides/prog_guide/metrics_lib.rst b/doc/guides/prog_guide/metrics_lib.rst
index e68e4e743..08e107df3 100644
--- a/doc/guides/prog_guide/metrics_lib.rst
+++ b/doc/guides/prog_guide/metrics_lib.rst
@@ -154,6 +154,20 @@ print out all metrics for a given port:
     }
 
 
+Deinitialising the library
+------------------------
+
+Once the library usage is done, it must be deinitialized by calling
+``rte_metrics_deinit()`` which will free the shared memory reserved
+during initialization.
+
+.. code-block:: c
+
+    err = rte_metrics_deinit(void);
+
+If the return value is negative, it means deinitialization failed.
+This function **must** be called from a primary process.
+
 Bit-rate statistics library
 ---------------------------
 
diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c
index 99a96b651..0c816a1fc 100644
--- a/lib/librte_metrics/rte_metrics.c
+++ b/lib/librte_metrics/rte_metrics.c
@@ -76,6 +76,26 @@ rte_metrics_init(int socket_id)
 	rte_spinlock_init(&stats->lock);
 }
 
+int __rte_experimental
+rte_metrics_deinit(void)
+{
+	struct rte_metrics_data_s *stats;
+	const struct rte_memzone *memzone;
+
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return -EINVAL;
+
+	memzone = rte_memzone_lookup(RTE_METRICS_MEMZONE_NAME);
+	if (memzone == NULL)
+		return -EIO;
+
+	stats = memzone->addr;
+	memset(stats, 0, sizeof(struct rte_metrics_data_s));
+
+	return rte_memzone_free(memzone);
+
+}
+
 int
 rte_metrics_reg_name(const char *name)
 {
diff --git a/lib/librte_metrics/rte_metrics.h b/lib/librte_metrics/rte_metrics.h
index 67a60fadd..0957a94b6 100644
--- a/lib/librte_metrics/rte_metrics.h
+++ b/lib/librte_metrics/rte_metrics.h
@@ -24,6 +24,7 @@
 #define _RTE_METRICS_H_
 
 #include <stdint.h>
+#include <rte_compat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -80,6 +81,22 @@ struct rte_metric_value {
  */
 void rte_metrics_init(int socket_id);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Deinitialize metric module. This function must be called from
+ * a primary process after all the metrics usage is over, to
+ *  release the shared memory.
+ *
+ * @return
+ *  -EINVAL - invalid parameter.
+ *  -EIO: Error, unable to access metrics shared memory
+ *    (rte_metrics_init() not called)
+ *  0 - success
+ */
+int __rte_experimental rte_metrics_deinit(void);
+
 /**
  * Register a metric, making it available as a reporting parameter.
  *
diff --git a/lib/librte_metrics/rte_metrics_version.map b/lib/librte_metrics/rte_metrics_version.map
index 4c5234cd1..6ac99a44a 100644
--- a/lib/librte_metrics/rte_metrics_version.map
+++ b/lib/librte_metrics/rte_metrics_version.map
@@ -11,3 +11,9 @@ DPDK_17.05 {
 
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	rte_metrics_deinit;
+};
-- 
2.18.0

  reply	other threads:[~2019-03-01 10:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 14:45 [dpdk-dev] [PATCH " Harman Kalra
2019-02-22 14:45 ` [dpdk-dev] [PATCH 2/2] test/metrics: first test case fails on continuous execution Harman Kalra
2019-02-25 12:21   ` Remy Horton
2019-02-25 12:21 ` [dpdk-dev] [PATCH 1/2] metrics: new API to deinitialise metrics library Remy Horton
2019-02-27 10:51   ` Harman Kalra
2019-03-01 10:07     ` Harman Kalra [this message]
2019-03-01 10:07       ` [dpdk-dev] [PATCH v2 2/2] test/metrics: first test case fails on continuous Harman Kalra
2019-06-27 10:59       ` [dpdk-dev] [PATCH v2 1/2] metrics: new API to deinitialise metrics library Pattan, Reshma
2019-06-27 11:03       ` Pattan, Reshma
2019-07-10 10:52         ` [dpdk-dev] [PATCH v3 " Harman Kalra
2019-07-10 10:52           ` [dpdk-dev] [PATCH v3 2/2] test/metrics: fix metrics autotest failure Harman Kalra
2019-07-10 22:08           ` [dpdk-dev] [dpdk-stable] [PATCH v3 1/2] metrics: new API to deinitialise metrics library Thomas Monjalon
2019-07-11  8:12             ` Harman Kalra
2019-07-11  8:34               ` Thomas Monjalon
2019-07-11  9:26                 ` [dpdk-dev] [PATCH v4 " Harman Kalra
2019-07-11  9:26                   ` [dpdk-dev] [PATCH v4 2/2] test/metrics: fix metrics autotest failure Harman Kalra
2019-07-16 10:49                   ` [dpdk-dev] [PATCH v4 1/2] metrics: new API to deinitialise metrics library Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1551434828-3518-1-git-send-email-hkalra@marvell.com \
    --to=hkalra@marvell.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=remy.horton@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).