diff mbox series

[ovs-dev,v2,4/4] Prevent excessive contention of the logging mutex

Message ID 20200214175429.26111-4-anton.ivanov@cambridgegreys.com
State Changes Requested
Headers show
Series [ovs-dev,v2,1/4] Replace direct use of POLLXXX macros with OVS_POLLXXX | expand

Commit Message

Anton Ivanov Feb. 14, 2020, 5:54 p.m. UTC
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

The log levels for a module which specify "should I log or should
I go" can be checked witout a mutex.

We need to grab a mutex only once we know we are likely to be
logging in the first place.

This mutex is highly contended - this code is hit from 2300+
places around OVS - every time you encounter a VLOG statement.

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

Comments

0-day Robot Feb. 14, 2020, 7:10 p.m. UTC | #1
Bleep bloop.  Greetings Anton Ivanov, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line has trailing whitespace
#31 FILE: lib/vlog.c:1093:
    /* Quickly exit without contending the log mutex if the module log 

Lines checked: 48, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/lib/vlog.c b/lib/vlog.c
index 559943d87..be28b59a1 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -1088,10 +1088,19 @@  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;
+
+    /* Quickly exit without contending the log mutex if the module log 
+     * levels do not request any logging to start off with.
+     */
+
+    if (!(log_to_console || log_to_syslog || log_to_file)) {
+        return;
+    }
 
     ovs_mutex_lock(&log_file_mutex);
-    log_to_file = module->levels[VLF_FILE] >= level && log_fd >= 0;
+    /* check only log_fd under mutex */
+    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;