DPDK patches and discussions
 help / color / mirror / Atom feed
From: David Marchand <david.marchand@6wind.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 11/11] eal: set log level from command line
Date: Tue, 26 Aug 2014 16:09:21 +0200	[thread overview]
Message-ID: <1409062162-19575-12-git-send-email-david.marchand@6wind.com> (raw)
In-Reply-To: <1409062162-19575-1-git-send-email-david.marchand@6wind.com>

Add a --log-level option to set the default eal log level.

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_eal/bsdapp/eal/eal.c                    |   43 ++++++++++++++++++++
 .../bsdapp/eal/include/eal_internal_cfg.h          |    1 +
 lib/librte_eal/linuxapp/eal/eal.c                  |   43 ++++++++++++++++++++
 .../linuxapp/eal/include/eal_internal_cfg.h        |    1 +
 4 files changed, 88 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 38c6cfc..96b54e3 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -94,6 +94,7 @@
 #define OPT_PCI_BLACKLIST "pci-blacklist"
 #define OPT_VDEV        "vdev"
 #define OPT_SYSLOG      "syslog"
+#define OPT_LOG_LEVEL   "log-level"
 
 #define RTE_EAL_BLACKLIST_SIZE	0x100
 
@@ -311,6 +312,7 @@ eal_usage(const char *prgname)
 	       "  -v           : Display version information on startup\n"
 	       "  -m MB        : memory to allocate\n"
 	       "  -r NUM       : force number of memory ranks (don't detect)\n"
+	       "  --"OPT_LOG_LEVEL"  : set default log level\n"
 	       "  --"OPT_PROC_TYPE"  : type of this process\n"
 	       "  --"OPT_PCI_BLACKLIST", -b: add a PCI device in black list.\n"
 	       "               Prevent EAL from using this PCI device. The argument\n"
@@ -458,6 +460,28 @@ eal_parse_syslog(const char *facility)
 	return -1;
 }
 
+static int
+eal_parse_log_level(const char *level, uint32_t *log_level)
+{
+	char *end;
+	unsigned long tmp;
+
+	errno = 0;
+	tmp = strtoul(level, &end, 0);
+
+	/* check for errors */
+	if ((errno != 0) || (level[0] == '\0') ||
+	    end == NULL || (*end != '\0'))
+		return -1;
+
+	/* log_level is a uint32_t */
+	if (tmp >= UINT32_MAX)
+		return -1;
+
+	*log_level = tmp;
+	return 0;
+}
+
 static inline size_t
 eal_get_hugepage_mem_size(void)
 {
@@ -512,6 +536,7 @@ eal_parse_args(int argc, char **argv)
 		{OPT_PCI_BLACKLIST, 1, 0, 0},
 		{OPT_VDEV, 1, 0, 0},
 		{OPT_SYSLOG, 1, NULL, 0},
+		{OPT_LOG_LEVEL, 1, NULL, 0},
 		{0, 0, 0, 0}
 	};
 
@@ -524,6 +549,8 @@ eal_parse_args(int argc, char **argv)
 	internal_config.hugepage_dir = NULL;
 	internal_config.force_sockets = 0;
 	internal_config.syslog_facility = LOG_DAEMON;
+	/* default value from build option */
+	internal_config.log_level = RTE_LOG_LEVEL;
 #ifdef RTE_LIBEAL_USE_HPET
 	internal_config.no_hpet = 0;
 #else
@@ -671,6 +698,19 @@ eal_parse_args(int argc, char **argv)
 					return -1;
 				}
 			}
+			else if (!strcmp(lgopts[option_index].name,
+					 OPT_LOG_LEVEL)) {
+				uint32_t log;
+
+				if (eal_parse_log_level(optarg, &log) < 0) {
+					RTE_LOG(ERR, EAL,
+						"invalid parameters for --"
+						OPT_LOG_LEVEL "\n");
+					eal_usage(prgname);
+					return -1;
+				}
+				internal_config.log_level = log;
+			}
 			break;
 
 		default:
@@ -811,6 +851,9 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			eal_hugepage_info_init() < 0)
diff --git a/lib/librte_eal/bsdapp/eal/include/eal_internal_cfg.h b/lib/librte_eal/bsdapp/eal/include/eal_internal_cfg.h
index 2d06c7f..24cefc2 100644
--- a/lib/librte_eal/bsdapp/eal/include/eal_internal_cfg.h
+++ b/lib/librte_eal/bsdapp/eal/include/eal_internal_cfg.h
@@ -75,6 +75,7 @@ struct internal_config {
 	volatile uint64_t socket_mem[RTE_MAX_NUMA_NODES]; /**< amount of memory per socket */
 	uintptr_t base_virtaddr;          /**< base address to try and reserve memory from */
 	volatile int syslog_facility;	  /**< facility passed to openlog() */
+	volatile uint32_t log_level;	  /**< default log level */
 	const char *hugefile_prefix;      /**< the base filename of hugetlbfs files */
 	const char *hugepage_dir;         /**< specific hugetlbfs directory to use */
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index ad43914..874209b 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -97,6 +97,7 @@
 #define OPT_PCI_BLACKLIST "pci-blacklist"
 #define OPT_VDEV        "vdev"
 #define OPT_SYSLOG      "syslog"
+#define OPT_LOG_LEVEL   "log-level"
 #define OPT_BASE_VIRTADDR   "base-virtaddr"
 #define OPT_XEN_DOM0    "xen-dom0"
 #define OPT_CREATE_UIO_DEV "create-uio-dev"
@@ -386,6 +387,7 @@ eal_usage(const char *prgname)
 	       "  --"OPT_XEN_DOM0" : support application running on Xen Domain0 "
 			   "without hugetlbfs\n"
 	       "  --"OPT_SYSLOG"     : set syslog facility\n"
+	       "  --"OPT_LOG_LEVEL"  : set default log level\n"
 	       "  --"OPT_SOCKET_MEM" : memory to allocate on specific \n"
 		   "                 sockets (use comma separated values)\n"
 	       "  --"OPT_HUGE_DIR"   : directory where hugetlbfs is mounted\n"
@@ -550,6 +552,28 @@ eal_parse_syslog(const char *facility)
 }
 
 static int
+eal_parse_log_level(const char *level, uint32_t *log_level)
+{
+	char *end;
+	unsigned long tmp;
+
+	errno = 0;
+	tmp = strtoul(level, &end, 0);
+
+	/* check for errors */
+	if ((errno != 0) || (level[0] == '\0') ||
+	    end == NULL || (*end != '\0'))
+		return -1;
+
+	/* log_level is a uint32_t */
+	if (tmp >= UINT32_MAX)
+		return -1;
+
+	*log_level = tmp;
+	return 0;
+}
+
+static int
 eal_parse_socket_mem(char *socket_mem)
 {
 	char * arg[RTE_MAX_NUMA_NODES];
@@ -701,6 +725,7 @@ eal_parse_args(int argc, char **argv)
 		{OPT_PCI_BLACKLIST, 1, 0, 0},
 		{OPT_VDEV, 1, 0, 0},
 		{OPT_SYSLOG, 1, NULL, 0},
+		{OPT_LOG_LEVEL, 1, NULL, 0},
 		{OPT_VFIO_INTR, 1, NULL, 0},
 		{OPT_BASE_VIRTADDR, 1, 0, 0},
 		{OPT_XEN_DOM0, 0, 0, 0},
@@ -718,6 +743,8 @@ eal_parse_args(int argc, char **argv)
 	internal_config.hugepage_dir = NULL;
 	internal_config.force_sockets = 0;
 	internal_config.syslog_facility = LOG_DAEMON;
+	/* default value from build option */
+	internal_config.log_level = RTE_LOG_LEVEL;
 	internal_config.xen_dom0_support = 0;
 	/* if set to NONE, interrupt mode is determined automatically */
 	internal_config.vfio_intr_mode = RTE_INTR_MODE_NONE;
@@ -890,6 +917,19 @@ eal_parse_args(int argc, char **argv)
 					return -1;
 				}
 			}
+			else if (!strcmp(lgopts[option_index].name,
+					 OPT_LOG_LEVEL)) {
+				uint32_t log;
+
+				if (eal_parse_log_level(optarg, &log) < 0) {
+					RTE_LOG(ERR, EAL,
+						"invalid parameters for --"
+						OPT_LOG_LEVEL "\n");
+					eal_usage(prgname);
+					return -1;
+				}
+				internal_config.log_level = log;
+			}
 			else if (!strcmp(lgopts[option_index].name, OPT_BASE_VIRTADDR)) {
 				if (eal_parse_base_virtaddr(optarg) < 0) {
 					RTE_LOG(ERR, EAL, "invalid parameter for --"
@@ -1056,6 +1096,9 @@ rte_eal_init(int argc, char **argv)
 	if (fctret < 0)
 		exit(1);
 
+	/* set log level as early as possible */
+	rte_set_log_level(internal_config.log_level);
+
 	if (internal_config.no_hugetlbfs == 0 &&
 			internal_config.process_type != RTE_PROC_SECONDARY &&
 			internal_config.xen_dom0_support == 0 &&
diff --git a/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h b/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h
index 498ade2..8749390 100644
--- a/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h
+++ b/lib/librte_eal/linuxapp/eal/include/eal_internal_cfg.h
@@ -77,6 +77,7 @@ struct internal_config {
 	volatile uint64_t socket_mem[RTE_MAX_NUMA_NODES]; /**< amount of memory per socket */
 	uintptr_t base_virtaddr;          /**< base address to try and reserve memory from */
 	volatile int syslog_facility;	  /**< facility passed to openlog() */
+	volatile uint32_t log_level;	  /**< default log level */
 	/** default interrupt mode for VFIO */
 	volatile enum rte_intr_mode vfio_intr_mode;
 	const char *hugefile_prefix;      /**< the base filename of hugetlbfs files */
-- 
1.7.10.4

      parent reply	other threads:[~2014-08-26 14:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26 14:09 [dpdk-dev] [PATCH 00/11] cleanup logs in main PMDs David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 01/11] ixgbe: clean log messages David Marchand
2014-08-26 14:23   ` Jay Rolette
2014-08-26 14:55     ` David Marchand
2014-08-27 13:53       ` Jay Rolette
2014-08-27 18:06         ` Stephen Hemminger
2014-08-29  7:45           ` David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 02/11] ixgbe: always log init messages David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 03/11] ixgbe: add a message when forcing scatter mode David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 04/11] ixgbe: add log messages when rx bulk mode is not usable David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 05/11] i40e: clean log messages David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 06/11] i40e: always log init messages David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 07/11] i40e: add log messages when rx bulk mode is not usable David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 08/11] e1000: clean log messages David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 09/11] e1000: always log init messages David Marchand
2014-08-26 14:09 ` [dpdk-dev] [PATCH 10/11] e1000: add a message when forcing scatter mode David Marchand
2014-08-26 14:09 ` David Marchand [this message]

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=1409062162-19575-12-git-send-email-david.marchand@6wind.com \
    --to=david.marchand@6wind.com \
    --cc=dev@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).