[dpdk-dev] [PATCH v5 25/33] eal/trace: add trace bufsize configuration parameter

jerinj at marvell.com jerinj at marvell.com
Mon Apr 13 17:01:08 CEST 2020


From: Sunil Kumar Kori <skori at marvell.com>

Trace library exposes --trace-bufsz EAL parameter to configure
maximum size of ring buffer where events are to be stored.

Signed-off-by: Sunil Kumar Kori <skori at marvell.com>
---
 doc/guides/linux_gsg/eal_args.include.rst     | 13 ++++++++
 lib/librte_eal/common/eal_common_options.c    | 17 +++++++++++
 lib/librte_eal/common/eal_common_trace.c      |  3 ++
 .../common/eal_common_trace_utils.c           | 30 +++++++++++++++++++
 lib/librte_eal/common/eal_options.h           |  2 ++
 lib/librte_eal/common/eal_trace.h             |  2 ++
 6 files changed, 67 insertions(+)

diff --git a/doc/guides/linux_gsg/eal_args.include.rst b/doc/guides/linux_gsg/eal_args.include.rst
index 98bfcd357..b921c83b8 100644
--- a/doc/guides/linux_gsg/eal_args.include.rst
+++ b/doc/guides/linux_gsg/eal_args.include.rst
@@ -163,6 +163,19 @@ Debugging options
     By default, trace output will created at ``home`` directory and parameter
     must be specified once only.
 
+*   ``--trace-bufsz=<val>``
+
+    Specify maximum size of allocated memory for trace output for each thread.
+    Valid unit can be either ``B`` or ``K`` or ``M`` for ``Bytes``, ``KBytes``
+    and ``MBytes`` respectively. For example:
+
+    Configuring ``2MB`` as a maximum size for trace output file::
+
+        --trace-bufsz=2M
+
+    By default, size of trace output file is ``1MB`` and parameter
+    must be specified once only.
+
 Other options
 ~~~~~~~~~~~~~
 
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index d6b3ea5ca..aea743e6f 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -70,6 +70,7 @@ eal_long_options[] = {
 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
 	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
 	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
+	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
 	{OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
 	{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
 	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
@@ -1440,6 +1441,15 @@ eal_parse_common_option(int opt, const char *optarg,
 		break;
 	}
 
+	case OPT_TRACE_BUF_SIZE_NUM: {
+		if (eal_trace_bufsz_args_save(optarg) < 0) {
+			RTE_LOG(ERR, EAL, "invalid parameters for --"
+				OPT_TRACE_BUF_SIZE "\n");
+			return -1;
+		}
+		break;
+	}
+
 	case OPT_LCORES_NUM:
 		if (eal_parse_lcores(optarg) < 0) {
 			RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1724,6 +1734,13 @@ eal_common_usage(void)
 	       "                      By default, trace output will created at\n"
 	       "                      $HOME directory and parameter must be\n"
 	       "                      specified once only.\n"
+	       "  --"OPT_TRACE_BUF_SIZE"=<int>\n"
+	       "                      Specify maximum size of allocated memory\n"
+	       "                      for trace output for each thread. Valid\n"
+	       "                      unit can be either 'B|K|M' for 'Bytes',\n"
+	       "                      'KBytes' and 'MBytes' respectively.\n"
+	       "                      Default is 1MB and parameter must be\n"
+	       "                      specified once only.\n"
 	       "  -v                  Display version information on startup\n"
 	       "  -h, --help          This help\n"
 	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c
index dd8086b88..9e76d90fb 100644
--- a/lib/librte_eal/common/eal_common_trace.c
+++ b/lib/librte_eal/common/eal_common_trace.c
@@ -64,6 +64,9 @@ eal_trace_init(void)
 	/* Generate UUID ver 4 with total size of events and number of events */
 	trace_uuid_generate();
 
+	/* Apply buffer size configuration for trace output */
+	trace_bufsz_args_apply();
+
 	/* Generate CTF TDSL metadata */
 	if (trace_metadata_create() < 0)
 		goto fail;
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 41f2bdd05..b4ac79c95 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -193,6 +193,36 @@ trace_args_apply(const char *arg)
 	return 0;
 }
 
+int
+eal_trace_bufsz_args_save(char const *optarg)
+{
+	struct trace *trace = trace_obj_get();
+	uint64_t bufsz;
+
+	if (optarg == NULL) {
+		trace_err("no optarg is passed");
+		return -EINVAL;
+	}
+
+	bufsz = rte_str_to_size(optarg);
+	if (bufsz == 0) {
+		trace_err("buffer size cannot be zero");
+		return -EINVAL;
+	}
+
+	trace->buff_len = bufsz;
+	return 0;
+}
+
+void
+trace_bufsz_args_apply(void)
+{
+	struct trace *trace = trace_obj_get();
+
+	if (trace->buff_len == 0)
+		trace->buff_len = 1024 * 1024; /* 1MB */
+}
+
 int
 eal_trace_dir_args_save(char const *optarg)
 {
diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
index 04222e57f..3e9a54f3a 100644
--- a/lib/librte_eal/common/eal_options.h
+++ b/lib/librte_eal/common/eal_options.h
@@ -37,6 +37,8 @@ enum {
 	OPT_TRACE_NUM,
 #define OPT_TRACE_DIR         "trace-dir"
 	OPT_TRACE_DIR_NUM,
+#define OPT_TRACE_BUF_SIZE    "trace-bufsz"
+	OPT_TRACE_BUF_SIZE_NUM,
 #define OPT_MASTER_LCORE      "master-lcore"
 	OPT_MASTER_LCORE_NUM,
 #define OPT_MBUF_POOL_OPS_NAME "mbuf-pool-ops-name"
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index ce4e90b8d..890d1d1ee 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h
@@ -100,6 +100,7 @@ struct trace_point_head *trace_list_head_get(void);
 const char *trace_mode_to_string(enum rte_trace_mode mode);
 const char *trace_area_to_string(enum trace_area_e area);
 int trace_args_apply(const char *arg);
+void trace_bufsz_args_apply(void);
 bool trace_has_duplicate_entry(void);
 void trace_uuid_generate(void);
 int trace_metadata_create(void);
@@ -114,5 +115,6 @@ void eal_trace_fini(void);
 int eal_trace_args_save(const char *optarg);
 void eal_trace_args_free(void);
 int eal_trace_dir_args_save(const char *optarg);
+int eal_trace_bufsz_args_save(const char *optarg);
 
 #endif /* __EAL_TRACE_H */
-- 
2.25.1



More information about the dev mailing list