From patchwork Mon Feb 22 15:59:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 62599 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1322281lbl; Mon, 22 Feb 2016 08:01:00 -0800 (PST) X-Received: by 10.140.228.146 with SMTP id y140mr7540014qhb.78.1456156858419; Mon, 22 Feb 2016 08:00:58 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l129si29995184qhc.103.2016.02.22.08.00.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 22 Feb 2016 08:00:58 -0800 (PST) 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; dkim=fail header.i=@linaro.org Received: from localhost ([::1]:49711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXsuv-0001fy-RX for patch@linaro.org; Mon, 22 Feb 2016 11:00:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXstz-0000j1-Ta for qemu-devel@nongnu.org; Mon, 22 Feb 2016 11:00:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXstz-0001BG-2U for qemu-devel@nongnu.org; Mon, 22 Feb 2016 10:59:59 -0500 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:37357) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXsty-0001B8-Rh for qemu-devel@nongnu.org; Mon, 22 Feb 2016 10:59:58 -0500 Received: by mail-wm0-x231.google.com with SMTP id g62so170350673wme.0 for ; Mon, 22 Feb 2016 07:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=drLxwSuDaIKulZamsl0nQL7/MgkSizYAoC7cbqRHmEM=; b=OLgLJu861EK0mTCGCL6LicFsCQXpnFD5gwJPw/NUtRzA7MnlSeZh68+3BiuE2cXFs/ LgXptjXodcUGE/IqUqlA/KtYsRUliAzMbOLgCiZxwowlJM4jjL5ihuI0lctrH12XJYFJ s7wkvl/z4XBITOKEpl7QTUY+tTiSaPUxNq4tY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=drLxwSuDaIKulZamsl0nQL7/MgkSizYAoC7cbqRHmEM=; b=h2EhdYLgy6QxtduKqDvJ0lvIyZm7711j0nU9kO9NKfsbvEngmJmzSSrsNHtM4a4RZn rQbfycQ15btTVCpampmrHdRUS926k5geAmwAftLQjhyHOrGORxTCzIUr5DEXy3h2FYBU a75HLqoKCTQ4KddGl95iAGR2n4qMRIGgpm6T++7nnHic7e4QpMe5QEjS795hZ+woQJVk zHuojZdKXa3PPW+H2z7u0LZDJ4uGQdm2mry0OKtCGr9DKXWntQUaxZZnvHf4NuOmrdc7 llBrLa6tI2MQL4FpNWIdn2mqKpoRzP4V7TVuO8KVVZ0QsHT4pVKtn00Jz/ZO5etngzec l4zA== X-Gm-Message-State: AG10YOSCSoIjt3v6/bB6DM21pjB5SVrUEtgEBzzT1BRI7n/412FxfMC3Mvq2MifS6PyKFwbi X-Received: by 10.28.49.69 with SMTP id x66mr12549819wmx.11.1456156798131; Mon, 22 Feb 2016 07:59:58 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id c7sm21621837wmd.13.2016.02.22.07.59.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Feb 2016 07:59:55 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 9EB263E0312; Mon, 22 Feb 2016 15:59:52 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 22 Feb 2016 15:59:41 +0000 Message-Id: <1456156787-17509-4-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456156787-17509-1-git-send-email-alex.bennee@linaro.org> References: <1456156787-17509-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Cc: Peter Maydell , dgilbert@redhat.com, crosthwaitepeter@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net, rth@twiddle.net Subject: [Qemu-devel] [PATCH v7 3/9] 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 --- v4 - fix s-o-b tags, add r-b tag --- include/qemu/log.h | 13 ++++++++++--- util/log.c | 11 ----------- 2 files changed, 10 insertions(+), 14 deletions(-) -- 2.7.1 diff --git a/include/qemu/log.h b/include/qemu/log.h index 30817f7..22c4dec 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -70,10 +70,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 c39fa7f..c89b226 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) {