From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="ISO-8859-1" 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: , X-List-Received-Date: Mon, 01 Aug 2016 09:21:09 -0000 >>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=20 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=20 rte_openlog_stream --- lib/librte_eal/bsdapp/eal/eal_log.c | 6 ++--- lib/librte_eal/common/eal_common_log.c | 47=20 ++++++++++++++++++++++++++++++--- 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(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_log.c=20 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=20 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=20 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 =3D { .file =3D NULL, }; =20 +struct rte_default_log_args rte_default_log_args =3D +{ + .facility =3D 0, + .log_id =3D NULL, + .prepare_default_log =3D NULL, +}; + + static FILE *default_log_stream; =20 /** @@ -82,9 +90,30 @@ int rte_openlog_stream(FILE *f) { if (f =3D=3D NULL) + { + if (rte_default_log_args.prepare_default_log) + { + if=20 (rte_default_log_args.prepare_default_log(rte_default_log_args.log_id, + rte_default_log_args.facility) <=20 0) + return -1; + } rte_logs.file =3D default_log_stream; + } else + { rte_logs.file =3D f; + } + return 0; +} + +int +rte_openlog_stream_initial(FILE *f) +{ + /* only initialize if not configured before rte_eal_init() */ + if (NULL =3D=3D rte_logs.file) + { + return rte_openlog_stream(f); + } return 0; } =20 @@ -176,14 +205,26 @@ rte_log(uint32_t level, uint32_t logtype, const char= =20 *format, ...) return ret; } =20 +int rte_eal_set_default_log_stream(FILE *default_log, const char *id,=20 int facility, + int (*prepare_log)(const char=20 *log_id, int facility)) +{ + rte_default_log_args.facility =3D facility; + rte_default_log_args.log_id =3D id; + rte_default_log_args.prepare_default_log =3D prepare_log; + default_log_stream =3D 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=20 facility)) { - default_log_stream =3D default_log; - rte_openlog_stream(default_log); + rte_eal_set_default_log_stream(default_log, id, facility,=20 prepare_log); + rte_openlog_stream_initial(NULL); /* enable default log stream */ =20 #if RTE_LOG_LEVEL >=3D RTE_LOG_DEBUG RTE_LOG(NOTICE, EAL, "Debug logs available - lower=20 performance\n"); diff --git a/lib/librte_eal/common/eal_private.h=20 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=20 facility, + int (*prepare_log)(const char *log_id, int= =20 facility)); + +/** + * A function that only sets the log stream if it has not previously been= =20 set. + * + * This function is private to EAL. + * + * @return + * 0 on success, negative on error + */ +int rte_openlog_stream_initial(FILE *f); =20 /** * 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); =20 /** + * Perform necessary initialization for the default stream before it is=20 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,=20 int facility, + int (*prepare_log)(const char *log_id, int=20 facility)); + +/** * Init early logs * * This function is private to EAL. diff --git a/lib/librte_eal/common/include/rte_log.h=20 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. */ }; =20 +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; =20 /* SDK log type */ #define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */ diff --git a/lib/librte_eal/linuxapp/eal/eal_log.c=20 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 @@ =20 #include "eal_private.h" =20 +static FILE *early_log_stream; + /* * default log function */ @@ -82,10 +84,18 @@ static cookie_io_functions_t console_log_func =3D { .write =3D console_log_write, }; =20 +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 =3D=3D NULL) return -1; =20 - openlog(id, LOG_NDELAY | LOG_PID, facility); - - if (rte_eal_common_log_init(log_stream) < 0) - return -1; + if (rte_logs.file !=3D early_log_stream) /* logging was initialized= =20 before rte_eal_init() */ + { + rte_eal_set_default_log_stream(log_stream, id, facility,=20 rte_eal_prepare_default_log); + } else + { + if (rte_eal_common_log_init(log_stream, id, facility,=20 rte_eal_prepare_default_log) < 0) + return -1; + } =20 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; } --=20 2.9.2 --=20 Steffen Bauch Senior Software Engineer Platform & Technology R&S Cybersecurity ipoque GmbH Augustusplatz 9, D-04109 Leipzig Phone: + 49 341 59403 0 Email: steffen.bauch@rohde-schwarz.com Internet: www.ipoque.com Trade register Amtsgericht Leipzig HRB21462 Gesellschaft mit beschr=E4nkter Haftung (GmbH) Dirk Czepluch - Managing Director