From patchwork Fri Feb 14 17:54:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1238257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48K1HH6gJSz9sSb for ; Sat, 15 Feb 2020 04:54:51 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3725B87727; Fri, 14 Feb 2020 17:54:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yORTfPSb0uUA; Fri, 14 Feb 2020 17:54:45 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id BA8168771B; Fri, 14 Feb 2020 17:54:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A2B80C1D89; Fri, 14 Feb 2020 17:54:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5656CC0177 for ; Fri, 14 Feb 2020 17:54:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 44AFC88299 for ; Fri, 14 Feb 2020 17:54:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1sl4nocGZ4lC for ; Fri, 14 Feb 2020 17:54:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.kot-begemot.co.uk (ivanoab7.miniserver.com [37.128.132.42]) by hemlock.osuosl.org (Postfix) with ESMTPS id DEBA288289 for ; Fri, 14 Feb 2020 17:54:42 +0000 (UTC) Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j2fAm-00057k-Uy; Fri, 14 Feb 2020 17:54:41 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1j2fAj-0006o3-Ec; Fri, 14 Feb 2020 17:54:39 +0000 From: anton.ivanov@cambridgegreys.com To: dev@openvswitch.org Date: Fri, 14 Feb 2020 17:54:29 +0000 Message-Id: <20200214175429.26111-4-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214175429.26111-1-anton.ivanov@cambridgegreys.com> References: <20200214175429.26111-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: Anton Ivanov Subject: [ovs-dev] [PATCH v2 4/4] Prevent excessive contention of the logging mutex X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Anton Ivanov 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 --- lib/vlog.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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;