DPDK patches and discussions
 help / color / mirror / Atom feed
From: Steffen.Bauch@rohde-schwarz.com
To: dev@dpdk.org
Subject: Re: [dpdk-dev] Application framework vs. library
Date: Mon, 1 Aug 2016 11:21:04 +0200	[thread overview]
Message-ID: <OFD6D2EBE6.173ADAC7-ONC1258002.0033343C-C1258002.00335E09@rohde-schwarz.com> (raw)

>From c3be5420d921325559de9b1079354e1c4314220a Mon Sep 17 00:00:00 2001
From: Steffen Bauch <steffen.bauch@rohde-schwarz.com>
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(-)

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;
+       }
 
        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;
 }
-- 
2.9.2

-- 

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änkter Haftung (GmbH)
Dirk Czepluch - Managing Director

             reply	other threads:[~2016-08-01  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-01  9:21 Steffen.Bauch [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-08-01  9:22 Steffen.Bauch
2016-08-01  8:18 Steffen.Bauch
2016-08-01 10:04 ` Thomas Monjalon
2016-08-01 15:27   ` Wiles, Keith

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=OFD6D2EBE6.173ADAC7-ONC1258002.0033343C-C1258002.00335E09@rohde-schwarz.com \
    --to=steffen.bauch@rohde-schwarz.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).