From patchwork Tue Mar 22 14:16:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 64180 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2098565lbc; Tue, 22 Mar 2016 07:27:11 -0700 (PDT) X-Received: by 10.55.192.154 with SMTP id v26mr47461600qkv.36.1458656830997; Tue, 22 Mar 2016 07:27:10 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a14si13998412qgf.96.2016.03.22.07.27.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 22 Mar 2016 07:27:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:37320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiNH4-000278-8j for patch@linaro.org; Tue, 22 Mar 2016 10:27:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiN80-0004z7-Ef for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiN7z-0006j0-Dx for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiN7z-0006iW-8T for qemu-devel@nongnu.org; Tue, 22 Mar 2016 10:17:47 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id F1E7C8E36C; Tue, 22 Mar 2016 14:17:46 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-37.ams2.redhat.com [10.36.112.37]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MEH9Q8004983; Tue, 22 Mar 2016 10:17:45 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 22 Mar 2016 15:16:58 +0100 Message-Id: <1458656229-32043-19-git-send-email-pbonzini@redhat.com> In-Reply-To: <1458656229-32043-1-git-send-email-pbonzini@redhat.com> References: <1458656229-32043-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [Qemu-devel] [PULL 18/29] qemu-log: Avoid function call for disabled qemu_log_mask logging X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell Make qemu_log_mask() a macro which only calls the function to do the actual work if the logging is enabled. This avoids making a function call in possible fast paths where logging is disabled. Signed-off-by: Peter Maydell Signed-off-by: Alex Bennée Reviewed-by: Andreas Färber Signed-off-by: Paolo Bonzini --- include/qemu/log.h | 13 ++++++++++--- util/log.c | 11 ----------- 2 files changed, 10 insertions(+), 14 deletions(-) -- 2.5.0 diff --git a/include/qemu/log.h b/include/qemu/log.h index 40c24fd..523c886 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -66,10 +66,17 @@ qemu_log_vprintf(const char *fmt, va_list va) } } -/* log only if a bit is set on the current loglevel mask +/* log only if a bit is set on the current loglevel mask: + * @mask: bit to check in the mask + * @fmt: printf-style format string + * @args: optional arguments for format string */ -void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...); - +#define qemu_log_mask(MASK, FMT, ...) \ + do { \ + if (unlikely(qemu_loglevel_mask(MASK))) { \ + qemu_log(FMT, ## __VA_ARGS__); \ + } \ + } while (0) /* Maintenance: */ diff --git a/util/log.c b/util/log.c index a14d480..4e69586 100644 --- a/util/log.c +++ b/util/log.c @@ -38,17 +38,6 @@ void qemu_log(const char *fmt, ...) va_end(ap); } -void qemu_log_mask(int mask, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - if ((qemu_loglevel & mask) && qemu_logfile) { - vfprintf(qemu_logfile, fmt, ap); - } - va_end(ap); -} - /* enable or disable low levels log */ void do_qemu_set_log(int log_flags, bool use_own_buffers) {