[ovs-dev] [PATCH] Fast path in vlog

anton.ivanov at cambridgegreys.com anton.ivanov at cambridgegreys.com
Tue Apr 21 08:24:38 UTC 2020


From: Anton Ivanov <anton.ivanov at cambridgegreys.com>

Avoid grabbing any mutexes if the log levels specify that
no logging is to take place.

Signed-off-by: Anton Ivanov <anton.ivanov at cambridgegreys.com>
---
 lib/vlog.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/vlog.c b/lib/vlog.c
index ee6b0d3a6..533f93755 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -1103,10 +1103,17 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level,
 {
     bool log_to_console = module->levels[VLF_CONSOLE] >= level;
     bool log_to_syslog = module->levels[VLF_SYSLOG] >= level;
-    bool log_to_file;
+    bool log_to_file = module->levels[VLF_FILE]  >= level;
+
+    if (!(log_to_console || log_to_syslog || log_to_file)) {
+        /* fast path - all logging levels specify no logging, no
+         * need to hog the log mutex
+         */
+        return;
+    }
 
     ovs_mutex_lock(&log_file_mutex);
-    log_to_file = module->levels[VLF_FILE] >= level && log_fd >= 0;
+    log_to_file &= (log_fd >= 0);
     ovs_mutex_unlock(&log_file_mutex);
     if (log_to_console || log_to_syslog || log_to_file) {
         int save_errno = errno;
-- 
2.20.1



More information about the dev mailing list