[strongSwan-dev] [PATCH] log: do not acquire lock if nobody is listening

Christophe Gouault christophe.gouault at 6wind.com
Tue Apr 8 17:12:04 CEST 2014


The vlog function is called for each log generated by charon.
Even if nobody is listening for these logs, vlog acquires the log
lock.

Under high load, this useless lock/unlock hogs a lot of CPU.

Avoid this useless locking by checking if somebody is listening for logs.

perf report before patch:

+  49.87%  charon  [kernel.kallsyms]                [k] do_raw_spin_lock
+  23.84%  charon  libcrypto.so.1.0.0               [.] 0xbc65e
+   2.32%  charon  libc-2.13.so                     [.] 0x7706e
+   1.59%  charon  libpthread-2.13.so               [.] pthread_rwlock_rdlock
+   1.25%  charon  libpthread-2.13.so               [.] pthread_rwlock_unlock
+   0.97%  charon  libpthread-2.13.so               [.] __lll_lock_wait
+   0.96%  charon  libcharon.so.0.0.0               [.] vlog

perf report after patch:

+  56.53%  charon  libcrypto.so.1.0.0               [.] 0xbc978
+   5.95%  charon  libc-2.13.so                     [.] 0x79939
+   1.92%  charon  [kernel.kallsyms]                [k] native_write_msr_safe
+   1.73%  charon  libc-2.13.so                     [.] malloc

Signed-off-by: Christophe Gouault <christophe.gouault at 6wind.com>
---
 src/libcharon/bus/bus.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/libcharon/bus/bus.c b/src/libcharon/bus/bus.c
index b461848..5daa7fd 100644
--- a/src/libcharon/bus/bus.c
+++ b/src/libcharon/bus/bus.c
@@ -324,6 +324,10 @@ METHOD(bus_t, vlog, void,
 	linked_list_t *loggers;
 	log_data_t data;
 
+	if (this->max_level[group] < level &&
+		this->max_vlevel[group] < level)
+		return;
+
 	this->log_lock->read_lock(this->log_lock);
 	loggers = this->loggers[group];
 
-- 
1.7.10.4



More information about the Dev mailing list