diff mbox

[ovs-dev] dpdk: Redirect DPDK log to OVS logging subsystem.

Message ID 1488453367-7202-1-git-send-email-i.maximets@samsung.com
State Superseded
Headers show

Commit Message

Ilya Maximets March 2, 2017, 11:16 a.m. UTC
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.maximets@samsung.com>
---
 NEWS       |  5 +++++
 lib/dpdk.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

Comments

Aaron Conole March 2, 2017, 7:22 p.m. UTC | #1
Ilya Maximets <i.maximets@samsung.com> writes:

> 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.maximets@samsung.com>
> ---

+1 - good change!
...
> diff --git a/lib/dpdk.c b/lib/dpdk.c
> index c1626e2..eb03ec9 100644
> --- a/lib/dpdk.c
> +++ b/lib/dpdk.c
...
> @@ -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';

Small nit - does it make more sense here to use xmemdup0(), instead?  If
you're not worried about non-printable characters, what about xstrdup or
even xasprintf("%s", buf)?

-Aaron
Ilya Maximets March 6, 2017, 6:53 a.m. UTC | #2
On 02.03.2017 22:22, Aaron Conole wrote:
> Ilya Maximets <i.maximets@samsung.com> writes:
> 
>> 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.maximets@samsung.com>
>> ---
> 
> +1 - good change!

Thanks.

> ...
>> diff --git a/lib/dpdk.c b/lib/dpdk.c
>> index c1626e2..eb03ec9 100644
>> --- a/lib/dpdk.c
>> +++ b/lib/dpdk.c
> ...
>> @@ -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';
> 
> Small nit - does it make more sense here to use xmemdup0(), instead?  If
> you're not worried about non-printable characters, what about xstrdup or
> even xasprintf("%s", buf)?

Good point. I've sent v2 with 'xmemdup0()'.

P.S. String functions can't be used here. Otherwise, where will be no
     need for copy at all.

Best regards, Ilya Maximets.
diff mbox

Patch

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)) {