This should be helpful for have all the logs in one place.
'ovs-appctl vlog' commands for 'dpdk' module can be used
to configure the log level. Lower bound for DPDK logging
(--log-level) still can be passed through 'dpdk-extra' field.

Signed-off-by: Ilya Maximets <i.maxim...@samsung.com>
---
 NEWS       |  5 +++++
 lib/dpdk.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/NEWS b/NEWS
index ce9fe88..8d4af9e 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,11 @@ Post-v2.7.0
        `egress_pkt_mark` OVSDB option.
    - EMC insertion probability is reduced to 1% and is configurable via
      the new 'other_config:emc-insert-inv-prob' option.
+   - DPDK:
+     * DPDK log messages redirected to OVS logging subsystem.
+       Log level can be changed in a usual OVS way using
+       'ovs-appctl vlog' commands for 'dpdk' module. Lower bound
+       still can be configured via extra arguments for DPDK EAL.
 
 v2.7.0 - xx xxx xxxx
 ---------------------
diff --git a/lib/dpdk.c b/lib/dpdk.c
index c1626e2..eb03ec9 100644
--- a/lib/dpdk.c
+++ b/lib/dpdk.c
@@ -17,10 +17,12 @@
 #include <config.h>
 #include "dpdk.h"
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <getopt.h>
 
+#include <rte_log.h>
 #include <rte_memzone.h>
 #ifdef DPDK_PDUMP
 #include <rte_mempool.h>
@@ -36,6 +38,8 @@
 
 VLOG_DEFINE_THIS_MODULE(dpdk);
 
+static FILE *log_stream = NULL;       /* Stream for DPDK log redirection */
+
 static char *vhost_sock_dir = NULL;   /* Location of vhost-user sockets */
 
 static int
@@ -262,6 +266,45 @@ argv_release(char **dpdk_argv, char **dpdk_argv_release, 
size_t dpdk_argc)
     free(dpdk_argv);
 }
 
+static ssize_t
+dpdk_log_write(void *c OVS_UNUSED, const char *buf, size_t size)
+{
+    char *str = xmalloc(size + 1);
+
+    strncpy(str, buf, size);
+    str[size] = '\0';
+
+    switch (rte_log_cur_msg_loglevel()) {
+        case RTE_LOG_DEBUG:
+            VLOG_DBG("%s", str);
+            break;
+        case RTE_LOG_INFO:
+        case RTE_LOG_NOTICE:
+            VLOG_INFO("%s", str);
+            break;
+        case RTE_LOG_WARNING:
+            VLOG_WARN("%s", str);
+            break;
+        case RTE_LOG_ERR:
+            VLOG_ERR("%s", str);
+            break;
+        case RTE_LOG_CRIT:
+        case RTE_LOG_ALERT:
+        case RTE_LOG_EMERG:
+            VLOG_EMER("%s", str);
+            break;
+        default:
+            OVS_NOT_REACHED();
+    }
+
+    free(str);
+    return size;
+}
+
+static cookie_io_functions_t dpdk_log_func = {
+    .write = dpdk_log_write,
+};
+
 static void
 dpdk_init__(const struct smap *ovs_other_config)
 {
@@ -273,6 +316,14 @@ dpdk_init__(const struct smap *ovs_other_config)
     cpu_set_t cpuset;
     char *sock_dir_subcomponent;
 
+    log_stream = fopencookie(NULL, "w+", dpdk_log_func);
+    if (log_stream == NULL) {
+        VLOG_ERR("Can't redirect DPDK log: %s.", ovs_strerror(errno));
+    } else {
+        setbuf(log_stream, NULL);
+        rte_openlog_stream(log_stream);
+    }
+
     if (process_vhost_flags("vhost-sock-dir", ovs_rundir(),
                             NAME_MAX, ovs_other_config,
                             &sock_dir_subcomponent)) {
-- 
2.7.4

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to