From patchwork Mon Sep 1 10:24:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 290 Return-Path: Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by dpdk.org (Postfix) with ESMTP id 1A5F9B3F1 for ; Mon, 1 Sep 2014 12:20:51 +0200 (CEST) Received: by mail-wi0-f182.google.com with SMTP id z2so5812487wiv.15 for ; Mon, 01 Sep 2014 03:25:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=LPe7EIm4pAhwgT2Gt8oItMB05d8MN68ObjVjyaoC+SE=; b=FJd/9ccIQAqIdgXeptYevbMwz7iP4dbRKSSI/0Z1cPxxTe/FPjqBlqqLni7N5jfr8u 8Ld/nAjKNqhY0ZHW6TcVGQVIkXBKf4R4xtS6Ia0HK1P20ZWFi2af9aE/DxS8LXxmzaoE pd+2OMULFRA/OWNmxKIjdUbwD2RgLNXQAT6BZ09p4hUdknn1nyub6eaLBUISshraCVjk d5ZaRFGdDbzoxWjsRSyGxSothllf5rDAHZtmDz5p73sxv5WW0XCHkEeSS4y5ddt/DB4r eA0iPmueE92BvHED4LSdL1+DIYvra15vFoqzNvUohJNJRlL6sBsKjnkPkTwaie78KFvy nTHQ== X-Gm-Message-State: ALoCoQnkCnGA9ZjBxcQBJLIQCvKxEkPX938W2erBq6cEqzCzvCiuKsxuCHcMcpegzfngAq2PV5cR X-Received: by 10.194.87.102 with SMTP id w6mr30723024wjz.24.1409567117989; Mon, 01 Sep 2014 03:25:17 -0700 (PDT) Received: from alcyon.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id lm18sm24287018wic.22.2014.09.01.03.25.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Sep 2014 03:25:17 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Mon, 1 Sep 2014 12:24:40 +0200 Message-Id: <1409567080-27083-18-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1409567080-27083-1-git-send-email-david.marchand@6wind.com> References: <1409567080-27083-1-git-send-email-david.marchand@6wind.com> Subject: [dpdk-dev] [PATCH v2 17/17] eal: set log level from command line X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Sep 2014 10:20:51 -0000 Add a --log-level option to set the default eal log level. Signed-off-by: David Marchand --- lib/librte_eal/bsdapp/eal/eal.c | 42 +++++++++++++++++++ .../bsdapp/eal/include/eal_internal_cfg.h | 1 + lib/librte_eal/linuxapp/eal/eal.c | 44 +++++++++++++++++++- .../linuxapp/eal/include/eal_internal_cfg.h | 1 + 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 71f93e0..2f84742 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 MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -293,6 +294,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" @@ -440,6 +442,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) { @@ -494,6 +518,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} }; @@ -506,6 +531,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 @@ -652,6 +679,18 @@ eal_parse_args(int argc, char **argv) eal_usage(prgname); 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; @@ -793,6 +832,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 4869e7c..38cace6 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" @@ -384,7 +385,8 @@ eal_usage(const char *prgname) " --"OPT_XEN_DOM0" : support application running on Xen Domain0 " "without hugetlbfs\n" " --"OPT_SYSLOG" : set syslog facility\n" - " --"OPT_SOCKET_MEM" : memory to allocate on specific \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" " --"OPT_PROC_TYPE" : type of this process\n" @@ -548,6 +550,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]; @@ -699,6 +723,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}, @@ -716,6 +741,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; @@ -887,6 +914,18 @@ eal_parse_args(int argc, char **argv) eal_usage(prgname); 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) { @@ -1054,6 +1093,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 */