From patchwork Thu Feb 4 14:56:15 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: 61191 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp505662lbl; Thu, 4 Feb 2016 06:59:18 -0800 (PST) X-Received: by 10.140.28.162 with SMTP id 31mr2080726qgz.81.1454597958354; Thu, 04 Feb 2016 06:59:18 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 107si5445225qgo.100.2016.02.04.06.59.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 04 Feb 2016 06:59:18 -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]:42226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRLNN-0005Nw-Sm for patch@linaro.org; Thu, 04 Feb 2016 09:59:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRLKo-0001fE-0y for qemu-devel@nongnu.org; Thu, 04 Feb 2016 09:56:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRLKm-0001QX-VA for qemu-devel@nongnu.org; Thu, 04 Feb 2016 09:56:37 -0500 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:35831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRLKm-0001Q9-DK for qemu-devel@nongnu.org; Thu, 04 Feb 2016 09:56:36 -0500 Received: by mail-wm0-x232.google.com with SMTP id r129so215666771wmr.0 for ; Thu, 04 Feb 2016 06:56:36 -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-type:content-transfer-encoding; bh=wZbSySjNEDTQfnby+MPXj3rh/90Cm1MmR+LMk2HBR5E=; b=ZRCfEX+E+n9pyJnTfgiMaGwpZq4aVFmbL6EcYuCzhQ770/uu6vbvPyljRqMt2xEk95 QL0A5sgRmozmW/C33z+N7hgrZS4IZvCeuPq8LSClftYPNDYaOI4NE8iTb8LNGuJMaIBf mTLP2lYGeQH9D93D6pgfE9HZjjGh8OMfj7A3Y= 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-type:content-transfer-encoding; bh=wZbSySjNEDTQfnby+MPXj3rh/90Cm1MmR+LMk2HBR5E=; b=U+EmA2Z6/nT6cyvwgnf5VWUIWiEf0qS7hpsYKE8a7OBm+BVxZev4/4JlTSHeYPKS7H 1FdiGmbRDvRdO6LAESvMbdNtYSptXxXbRNmhDRBmdC1o1l2/v31K26HxnYLgYio5ITKv Zv6+m/mnh5S15+PTo9rffvFx719I5iSD9rlqygt5wbAjliZIkCxp7FrqogaWjsjsz56C GszCR6ul/1KUr3UO+Ejrp0ni5Ei4G+K/IRKvETz5McqpCvB3jXDrJHXTqeDht7yyiazY wx0XavLaP8NibOVcXRHUmN5P/Xv7QEoahMcwie9jm4JkqMJm29degbo3Z4Kz2YZ5EF6+ NM4A== X-Gm-Message-State: AG10YORT+zSap4rETn22MbgUa3S9fmTbuLRvigMSIKd+x/Bn9OoZ/bZJuN/GTv833UpVOJjv X-Received: by 10.28.153.14 with SMTP id b14mr19503902wme.93.1454597795768; Thu, 04 Feb 2016 06:56:35 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id e9sm11691151wja.25.2016.02.04.06.56.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Feb 2016 06:56:32 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C23013E0770; Thu, 4 Feb 2016 14:56:29 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 4 Feb 2016 14:56:15 +0000 Message-Id: <1454597781-18115-4-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454597781-18115-1-git-send-email-alex.bennee@linaro.org> References: <1454597781-18115-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::232 Cc: peter.maydell@linaro.org, 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 v5 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 ++++++++++--- qemu-log.c | 11 ----------- 2 files changed, 10 insertions(+), 14 deletions(-) -- 2.7.0 diff --git a/include/qemu/log.h b/include/qemu/log.h index d837d90..776ceaf 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -73,10 +73,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) /* Special cases: */ diff --git a/qemu-log.c b/qemu-log.c index 5d11fe7..8c59063 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -36,17 +36,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) {