From patchwork Mon Aug 1 09:21:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steffen.Bauch@rohde-schwarz.com X-Patchwork-Id: 15067 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 1C5E22C0C; Mon, 1 Aug 2016 11:21:10 +0200 (CEST) Received: from mail02.rohde-schwarz.com (mail02.rohde-schwarz.com [80.246.32.97]) by dpdk.org (Postfix) with ESMTP id E0D302BE1 for ; Mon, 1 Aug 2016 11:21:08 +0200 (CEST) Received: from amu316.rsint.net ([10.0.26.65]) by mail02.rohde-schwarz.com with ESMTP id 2016080111210693-60510 ; Mon, 1 Aug 2016 11:21:06 +0200 Received: from rus19.rsint.net ([10.0.33.19]) by amu316.rsint.net (Totemo SMTP Server) with SMTP ID 436 for ; Mon, 1 Aug 2016 11:21:06 +0200 (CEST) To: dev@dpdk.org MIME-Version: 1.0 X-KeepSent: D6D2EBE6:173ADAC7-C1258002:0033343C; type=4; flags=0; name=$KeepSent X-Mailer: IBM Notes Release 9.0.1FP6 April 21, 2016 From: Steffen.Bauch@rohde-schwarz.com X-RUS_SENSITIVITY: 10 X-TNEFEvaluated: 1 Message-ID: Date: Mon, 1 Aug 2016 11:21:04 +0200 X-MIMETrack: Itemize by SMTP Server on RSSMTP02/RSSMTP at 01.08.2016 11:21:06, Serialize by Router on RSSMTP02/RSSMTP at 01.08.2016 11:21:07, Serialize complete at 01.08.2016 11:21:07 Subject: Re: [dpdk-dev] Application framework vs. library 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From c3be5420d921325559de9b1079354e1c4314220a Mon Sep 17 00:00:00 2001 From: Steffen Bauch Date: Mon, 25 Jul 2016 16:13:02 +0200 Subject: [PATCH] allow the call to rte_openlog_stream() before rte_eal_init() - only initialize the default_log_stream if it was not initialized before main initialization of EAL - save facility and logid in rte_default_log_args structure - call openlog only on setup of the default_log_stream in rte_openlog_stream --- lib/librte_eal/bsdapp/eal/eal_log.c | 6 ++--- lib/librte_eal/common/eal_common_log.c | 47 ++++++++++++++++++++++++++++++--- lib/librte_eal/common/eal_private.h | 40 +++++++++++++++++++++++++--- lib/librte_eal/common/include/rte_log.h | 7 +++++ lib/librte_eal/linuxapp/eal/eal_log.c | 24 +++++++++++++---- 5 files changed, 110 insertions(+), 14 deletions(-) return 0; } @@ -136,6 +150,6 @@ rte_eal_log_early_init(void) printf("Cannot configure early_log_stream\n"); return -1; } - rte_openlog_stream(early_log_stream); + rte_openlog_stream_initial(early_log_stream); return 0; } diff --git a/lib/librte_eal/bsdapp/eal/eal_log.c b/lib/librte_eal/bsdapp/eal/eal_log.c index a425f7a..5abd906 100644 --- a/lib/librte_eal/bsdapp/eal/eal_log.c +++ b/lib/librte_eal/bsdapp/eal/eal_log.c @@ -42,9 +42,9 @@ * once memzones are available. */ int -rte_eal_log_init(const char *id __rte_unused, int facility __rte_unused) +rte_eal_log_init(const char *id, int facility) { - if (rte_eal_common_log_init(stderr) < 0) + if (rte_eal_common_log_init(stderr, id, facility) < 0) return -1; return 0; } @@ -52,6 +52,6 @@ rte_eal_log_init(const char *id __rte_unused, int facility __rte_unused) int rte_eal_log_early_init(void) { - rte_openlog_stream(stderr); + rte_openlog_stream_initial(stderr); return 0; } diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index 7916c78..197e6c9 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -48,6 +48,14 @@ struct rte_logs rte_logs = { .file = NULL, }; +struct rte_default_log_args rte_default_log_args = +{ + .facility = 0, + .log_id = NULL, + .prepare_default_log = NULL, +}; + + static FILE *default_log_stream; /** @@ -82,9 +90,30 @@ int rte_openlog_stream(FILE *f) { if (f == NULL) + { + if (rte_default_log_args.prepare_default_log) + { + if (rte_default_log_args.prepare_default_log(rte_default_log_args.log_id, + rte_default_log_args.facility) < 0) + return -1; + } rte_logs.file = default_log_stream; + } else + { rte_logs.file = f; + } + return 0; +} + +int +rte_openlog_stream_initial(FILE *f) +{ + /* only initialize if not configured before rte_eal_init() */ + if (NULL == rte_logs.file) + { + return rte_openlog_stream(f); + } return 0; } @@ -176,14 +205,26 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...) return ret; } +int rte_eal_set_default_log_stream(FILE *default_log, const char *id, int facility, + int (*prepare_log)(const char *log_id, int facility)) +{ + rte_default_log_args.facility = facility; + rte_default_log_args.log_id = id; + rte_default_log_args.prepare_default_log = prepare_log; + default_log_stream = default_log; + + return 0; +} + /* * called by environment-specific log init function */ int -rte_eal_common_log_init(FILE *default_log) +rte_eal_common_log_init(FILE *default_log, const char *id, int facility, + int (*prepare_log)(const char *log_id, int facility)) { - default_log_stream = default_log; - rte_openlog_stream(default_log); + rte_eal_set_default_log_stream(default_log, id, facility, prepare_log); + rte_openlog_stream_initial(NULL); /* enable default log stream */ #if RTE_LOG_LEVEL >= RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug logs available - lower performance\n"); diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 857dc3e..f12a00d 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -49,13 +49,26 @@ int rte_eal_memzone_init(void); /** * Common log initialization function (private to eal). * - * @param default_log - * The default log stream to be used. + * @param default_log The default log stream to be used. + * @param id the id used for openlog call + * @param facility the facility used for openlog call + * @param prepare_log a platform specific log prepare function * @return * - 0 on success * - Negative on error */ -int rte_eal_common_log_init(FILE *default_log); +int rte_eal_common_log_init(FILE *default_log, const char *id, int facility, + int (*prepare_log)(const char *log_id, int facility)); + +/** + * A function that only sets the log stream if it has not previously been set. + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int rte_openlog_stream_initial(FILE *f); /** * Fill configuration with number of physical and logical processors @@ -97,6 +110,27 @@ int rte_eal_memory_init(void); int rte_eal_timer_init(void); /** + * Perform necessary initialization for the default stream before it is used + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int rte_eal_prepare_log(const char *id, int facility); + +/** + * Setup the default log stream and related parameters + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int rte_eal_set_default_log_stream(FILE *default_log, const char *id, int facility, + int (*prepare_log)(const char *log_id, int facility)); + +/** * Init early logs * * This function is private to EAL. diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index b1add04..4eb98a6 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -59,8 +59,15 @@ struct rte_logs { FILE *file; /**< Pointer to current FILE* for logs. */ }; +struct rte_default_log_args { + int facility; + const char *log_id; + int (*prepare_default_log)(const char *log_id, int facility); +}; + /** Global log informations */ extern struct rte_logs rte_logs; +extern struct rte_default_log_args rte_default_log_args; /* SDK log type */ #define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */ diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c b/lib/librte_eal/linuxapp/eal/eal_log.c index d391100..052237b 100644 --- a/lib/librte_eal/linuxapp/eal/eal_log.c +++ b/lib/librte_eal/linuxapp/eal/eal_log.c @@ -49,6 +49,8 @@ #include "eal_private.h" +static FILE *early_log_stream; + /* * default log function */ @@ -82,10 +84,18 @@ static cookie_io_functions_t console_log_func = { .write = console_log_write, }; +static int +rte_eal_prepare_default_log(const char *id, int facility) +{ + openlog(id, LOG_NDELAY | LOG_PID, facility); + return 0; +} + /* * set the log to default function, called during eal init process, * once memzones are available. */ + int rte_eal_log_init(const char *id, int facility) { @@ -95,10 +105,14 @@ rte_eal_log_init(const char *id, int facility) if (log_stream == NULL) return -1; - openlog(id, LOG_NDELAY | LOG_PID, facility); - - if (rte_eal_common_log_init(log_stream) < 0) - return -1; + if (rte_logs.file != early_log_stream) /* logging was initialized before rte_eal_init() */ + { + rte_eal_set_default_log_stream(log_stream, id, facility, rte_eal_prepare_default_log); + } else + { + if (rte_eal_common_log_init(log_stream, id, facility, rte_eal_prepare_default_log) < 0) + return -1; + }