From patchwork Fri Mar 4 11:18:01 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: 8502781 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A3069F38C for ; Fri, 4 Mar 2016 11:21:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 833CE20165 for ; Fri, 4 Mar 2016 11:21:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D11CE20160 for ; Fri, 4 Mar 2016 11:21:48 +0000 (UTC) Received: from localhost ([::1]:40369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abnno-0002r9-61 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 04 Mar 2016 06:21:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abnkS-00060R-Bm for qemu-devel@nongnu.org; Fri, 04 Mar 2016 06:18:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abnkR-0003qr-Gz for qemu-devel@nongnu.org; Fri, 04 Mar 2016 06:18:20 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abnkR-0003qb-A7 for qemu-devel@nongnu.org; Fri, 04 Mar 2016 06:18:19 -0500 Received: by mail-wm0-x236.google.com with SMTP id n186so30037499wmn.1 for ; Fri, 04 Mar 2016 03:18:19 -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=0uY5MVMULe79cwhH9BotPX7SDo/UILqWOWVYO3GFJvQ=; b=kbLW/yEAbD/1FHvkTVctz9EDAcE5galwLOXQ6EkLV0K9CxO8cxyPYA0i33vf5zdtBL nE4iwNb7vDAhuisWc44eOQ04FGk/t6S9M092Juza3gVcy907OmotAA5Oe8XZ5jyy5sVh weRDPW6xSQgOc30DZeYt4LWjpsj/D/SRhfur4= 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=0uY5MVMULe79cwhH9BotPX7SDo/UILqWOWVYO3GFJvQ=; b=ZpL4iblxsqgXanQoe768xdCeiquFJ4JXzJxz1vjGizTuO462t+y5bn0kySqIKRnMkU 9TCyiEEZMVY7vVPB375yFWWWhWjT94/XAt/WkNNJBtRLw+h/RtZpcRgN5rMVxT4IuVJs Op5V59BVzhltfGO+wDykgWDyOu/Sto8rLktW58KFpOHrbTwy4x8BwMp4013RaN6E06d/ xkvmSk9JTU13xwxysGz3QFgg/Q9NIg1UTe3LXYlxMy0TTqx4vtB9Sv+PfXYzScN9/tAF Vky/8xDI8Ce2u5wJ8JlMiV6xgtPizhkFz4mftSv1KS9X21YFb1/KayvACCpB/U6Cr7AH +Bww== X-Gm-Message-State: AD7BkJLe0DwsRRcNesqTpLU0eqmOHoSSLzJDyTfIIf9b/fV2+fYcLKUIVO58f3JlVRBxaHsA X-Received: by 10.194.63.75 with SMTP id e11mr8295005wjs.79.1457090298740; Fri, 04 Mar 2016 03:18:18 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n131sm2812399wmf.9.2016.03.04.03.18.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Mar 2016 03:18:15 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 697FD3E0223; Fri, 4 Mar 2016 11:18:13 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 4 Mar 2016 11:18:01 +0000 Message-Id: <1457090287-8021-4-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1457090287-8021-1-git-send-email-alex.bennee@linaro.org> References: <1457090287-8021-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::236 Cc: Peter Maydell , crosthwaitepeter@gmail.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net, rth@twiddle.net Subject: [Qemu-devel] [PATCH v8 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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 6160b49..a0c0e53 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) {