From patchwork Mon Dec 18 14:38:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 135275 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7C2EC43735; Mon, 18 Dec 2023 15:40:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B7C841611; Mon, 18 Dec 2023 15:39:04 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id B72E3415D7 for ; Mon, 18 Dec 2023 15:39:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702910342; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=quHOG9Ywju/HpMeVD1rJXjyUI6V//UIXfFpnqtVMoak=; b=N1Pbn6tIfwRC8Hdtb0KqBz370tEVPRs0PZ0oBcqY+RVUAMf1Z1ZvE5AWx0P/0dh+zyx082 Ivhwov4sB9aV9afc8qhLeYGxR8S0OE9RNnKyoaw5OmN2rO5J77QY6QTXGaUr28+6RleLTx xcub5c1f4ntOWnCQt9GJDD1wA2M1+XU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-245-MOgKbIbMPDm8YSrhXt84qg-1; Mon, 18 Dec 2023 09:38:58 -0500 X-MC-Unique: MOgKbIbMPDm8YSrhXt84qg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3C073C1E9DE; Mon, 18 Dec 2023 14:38:55 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DA991C060AF; Mon, 18 Dec 2023 14:38:54 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, bruce.richardson@intel.com, stephen@networkplumber.org, mb@smartsharesystems.com, Chengwen Feng Subject: [PATCH v4 11/14] log: add a per line log helper Date: Mon, 18 Dec 2023 15:38:00 +0100 Message-ID: <20231218143805.1500121-12-david.marchand@redhat.com> In-Reply-To: <20231218143805.1500121-1-david.marchand@redhat.com> References: <20231117131824.1977792-1-david.marchand@redhat.com> <20231218143805.1500121-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org gcc builtin __builtin_strchr can be used as a static assertion to check whether passed format strings contain a \n. This can be useful to detect double \n in log messages. Signed-off-by: David Marchand Acked-by: Stephen Hemminger Acked-by: Chengwen Feng --- Changes since v3: - fixed some checkpatch complaints, Changes since RFC v1: - added a check in checkpatches.sh, --- devtools/checkpatches.sh | 8 ++++++++ lib/log/rte_log.h | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 10b79ca2bc..10d1bf490b 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -53,6 +53,14 @@ print_usage () { check_forbidden_additions() { # res=0 + # refrain from new calls to RTE_LOG + awk -v FOLDERS="lib" \ + -v EXPRESSIONS="RTE_LOG\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Prefer RTE_LOG_LINE' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # refrain from new additions of rte_panic() and rte_exit() # multiple folders and expressions are separated by spaces awk -v FOLDERS="lib drivers" \ diff --git a/lib/log/rte_log.h b/lib/log/rte_log.h index 3394746103..637e9dcc9a 100644 --- a/lib/log/rte_log.h +++ b/lib/log/rte_log.h @@ -17,6 +17,7 @@ extern "C" { #endif +#include #include #include #include @@ -358,6 +359,26 @@ int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \ 0) +#ifdef RTE_TOOLCHAIN_GCC +#define RTE_LOG_CHECK_NO_NEWLINE(fmt) \ + static_assert(!__builtin_strchr(fmt, '\n'), \ + "This log format string contains a \\n") +#else +#define RTE_LOG_CHECK_NO_NEWLINE(...) +#endif + +#define RTE_LOG_LINE(l, t, ...) do { \ + RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \ + RTE_LOG(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ + RTE_FMT_TAIL(__VA_ARGS__ ,))); \ +} while (0) + +#define RTE_LOG_DP_LINE(l, t, ...) do { \ + RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \ + RTE_LOG_DP(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \ + RTE_FMT_TAIL(__VA_ARGS__ ,))); \ +} while (0) + #define RTE_LOG_REGISTER_IMPL(type, name, level) \ int type; \ RTE_INIT(__##type) \