diff mbox

[dpdk-dev] Application framework vs. library

Message ID OFD6D2EBE6.173ADAC7-ONC1258002.0033343C-C1258002.00335E09@rohde-schwarz.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Steffen.Bauch@rohde-schwarz.com Aug. 1, 2016, 9:21 a.m. UTC
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(-)

 
        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 mbox

Patch

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