From patchwork Mon Mar 12 16:00:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 131383 Delivered-To: patch@linaro.org Received: by 10.80.194.209 with SMTP id u17csp4380300edf; Mon, 12 Mar 2018 09:14:13 -0700 (PDT) X-Google-Smtp-Source: AG47ELumeJqDEavGN12htrimIcfcVa01446+2FIcVyZcuLRO+/TbceG+OfxSQ45VWeDbKpVviI9m X-Received: by 10.129.83.9 with SMTP id h9mr5016929ywb.56.1520871253399; Mon, 12 Mar 2018 09:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520871253; cv=none; d=google.com; s=arc-20160816; b=d4N4izioYnOb2DhtevZhXQx9PfrxSjYhLpo8H76DTtTqYjzFqVdOEQFZ14UQhCPDAe Zd6BWHnoO/iFIIDQCxn/4jNWCNvRsPgDci34gLnh11b9cS12p+CBikigQgotjlrSDhTV oWb1RphXBwqHp/Ibxecp3FZGwkU6MPBBxp9/TL3TRlKPqtj6AyQ/LZrt+uiHci9XouvV ELTK1vb7K9MbXKyOyxE6xaAMAZ+AaOYLzBnlOVdCNo/XDgrV/EyT5amH68ZVcvCZ9aCW 5w4KUeYUVfybXobwYL1Fm4ed7gPKu41DtivLDtHCDpx+UFLEwpFk8TwSqmzMLnRZtcqv u4Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=GQuB7KVcj+uehhDSQQYN4vSzNSBvQ855CEhoDsvL6Lg=; b=f4Ai6gE53wVWAuu4tE8tRGo1hl9YABtZ5ZARHdFxDKa+GGVr56bIEg6dq3tteMnjA4 dl2QqBRVkO5xg+VNHjny5M/tZiWknCB28HGjciCm5foNWMxZbU0YjiDPhhlWVAOGuTa4 iTp2MYXnFPmSt5Ggn8Ks2rSoDsyVwo4LeLHFnDuuBIMJZlKXvTYt6Q85zrB+wM+mJyec acTR8NVovk718uuFm9DGDsI0wtANcWjsKiT57F94x0F3kLVWBHxteers6xH1ntI48N8S Nv4MECifS1nmBYCRuP08lwHJ1x4D03adeBpBT3HvraZxjsGiA3jhpFt2Bdnx9n7exghn w6Yg== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d82-v6si292489ybb.68.2018.03.12.09.14.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 12 Mar 2018 09:14:13 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:32961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evQ5U-0006J9-Qo for patch@linaro.org; Mon, 12 Mar 2018 12:14:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evPsD-0004uN-OE for qemu-devel@nongnu.org; Mon, 12 Mar 2018 12:00:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evPs9-0000fr-EL for qemu-devel@nongnu.org; Mon, 12 Mar 2018 12:00:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55024 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1evPs9-0000fR-7b for qemu-devel@nongnu.org; Mon, 12 Mar 2018 12:00:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E2DC402290A; Mon, 12 Mar 2018 16:00:23 +0000 (UTC) Received: from localhost (unknown [10.36.118.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A7C810B0F46; Mon, 12 Mar 2018 16:00:20 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 12 Mar 2018 16:00:10 +0000 Message-Id: <20180312160014.6804-2-stefanha@redhat.com> In-Reply-To: <20180312160014.6804-1-stefanha@redhat.com> References: <20180312160014.6804-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 12 Mar 2018 16:00:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 12 Mar 2018 16:00:23 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 1/5] log-for-trace.h: Split out parts of log.h used by trace.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Stefan Hajnoczi , Cleber Rosa Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell A persistent build problem we see is where a source file accidentally omits the #include of log.h. This slips through local developer testing because if you configure with the default (log) trace backend trace.h will pull in log.h for you. Compilation fails only if some other backend is selected. To make this error cause a compile failure regardless of the configured trace backend, split out the parts of log.h that trace.h requires into a new log-for-trace.h header. Since almost all manual uses of the log.h functions will use constants or functions which aren't in log-for-trace.h, this will let us catch missing #include "qemu/log.h" more consistently. Signed-off-by: Peter Maydell Reviewed-by: Eric Blake Reviewed-by: Richard Henderson Message-id: 20180213140029.8308-1-peter.maydell@linaro.org Signed-off-by: Stefan Hajnoczi --- include/qemu/log-for-trace.h | 35 +++++++++++++++++++++++++++++++++++ include/qemu/log.h | 18 ++++-------------- scripts/tracetool/backend/log.py | 13 ++++++------- 3 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 include/qemu/log-for-trace.h -- 2.14.3 diff --git a/include/qemu/log-for-trace.h b/include/qemu/log-for-trace.h new file mode 100644 index 0000000000..2f0a5b080e --- /dev/null +++ b/include/qemu/log-for-trace.h @@ -0,0 +1,35 @@ +/* log-for-trace.h: logging basics required by the trace.h generated + * by the log trace backend. + * + * This should not be included directly by any .c file: if you + * need to use the logging functions include "qemu/log.h". + * + * The purpose of splitting these parts out into their own header + * is to catch the easy mistake where a .c file includes trace.h + * but forgets to include qemu/log.h. Without this split, that + * would result in the .c file compiling fine when the default + * trace backend is in use but failing to compile with any other + * backend. + * + * This code is licensed under the GNU General Public License, + * version 2 or (at your option) any later version. + */ + +#ifndef QEMU_LOG_FOR_TRACE_H +#define QEMU_LOG_FOR_TRACE_H + +/* Private global variable, don't use */ +extern int qemu_loglevel; + +#define LOG_TRACE (1 << 15) + +/* Returns true if a bit is set in the current loglevel mask */ +static inline bool qemu_loglevel_mask(int mask) +{ + return (qemu_loglevel & mask) != 0; +} + +/* main logging function */ +int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); + +#endif diff --git a/include/qemu/log.h b/include/qemu/log.h index a50e994c21..ff92a8b86a 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -1,10 +1,11 @@ #ifndef QEMU_LOG_H #define QEMU_LOG_H +/* A small part of this API is split into its own header */ +#include "qemu/log-for-trace.h" -/* Private global variables, don't use */ +/* Private global variable, don't use */ extern FILE *qemu_logfile; -extern int qemu_loglevel; /* * The new API: @@ -41,16 +42,9 @@ static inline bool qemu_log_separate(void) #define CPU_LOG_MMU (1 << 12) #define CPU_LOG_TB_NOCHAIN (1 << 13) #define CPU_LOG_PAGE (1 << 14) -#define LOG_TRACE (1 << 15) +/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1 << 16) -/* Returns true if a bit is set in the current loglevel mask - */ -static inline bool qemu_loglevel_mask(int mask) -{ - return (qemu_loglevel & mask) != 0; -} - /* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we * assume that qemu_loglevel_mask has already been tested, and that @@ -69,10 +63,6 @@ static inline void qemu_log_unlock(void) /* Logging functions: */ -/* main logging function - */ -int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); - /* vfprintf-like logging function */ static inline void GCC_FMT_ATTR(1, 0) diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py index da86f6b882..78933d03ad 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -20,7 +20,7 @@ PUBLIC = True def generate_h_begin(events, group): - out('#include "qemu/log.h"', + out('#include "qemu/log-for-trace.h"', '') @@ -35,14 +35,13 @@ def generate_h(event, group): else: cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) - out(' if (%(cond)s) {', + out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', ' struct timeval _now;', ' gettimeofday(&_now, NULL);', - ' qemu_log_mask(LOG_TRACE,', - ' "%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', - ' getpid(),', - ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', - ' %(argnames)s);', + ' qemu_log("%%d@%%zd.%%06zd:%(name)s " %(fmt)s "\\n",', + ' getpid(),', + ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', + ' %(argnames)s);', ' }', cond=cond, name=event.name,