From patchwork Fri Nov 6 17:53:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1395799 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=GSJL3bC3; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CSSjt0Hfrz9sTD for ; Sat, 7 Nov 2020 04:56:01 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 40D2A8239C; Fri, 6 Nov 2020 18:55:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.b="GSJL3bC3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD1F3808F1; Fri, 6 Nov 2020 18:55:26 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2CAA0808F1 for ; Fri, 6 Nov 2020 18:55:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A6Hm993026881; Fri, 6 Nov 2020 18:55:09 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=STMicroelectronics; bh=Q/FuSe6MrF9sAEIINJEgq2sS6l/2AW8JVAHeDqsIyP8=; b=GSJL3bC3mVPuPgq8Z+WK9yJ1YXP4xfsU8gQaObSByk7ZJL0ymKX7MPOkm8JhSr7phXqd NiaQt7D13GvFJu10ioV4c66GeuZloudC6KdPH+phAnVqse7xxP3r5rO6effjKEROKZKt ALCuMoiv6GD10p1AB3CC5DrZgk6L8zn8DDxnDZBl37JmiNhCcVVrObyyWpJiqKBwhdO+ 6U0tWOI6e/51TyZDwmiN7Jqnnn7kQ48nO0RAZdsTbPYGQyqyyRItowWYq2K9wCAFHvHh 4cIZqXgYWwyROwQZgu9vh1wtuId+QwP2jOs/twR0YDwwEC+TfkmobJbajNG0S8Bq4SVN 0w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 34gyw1xfdb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Nov 2020 18:55:09 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 039BC10002A; Fri, 6 Nov 2020 18:55:09 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id ECA402150F7; Fri, 6 Nov 2020 18:55:08 +0100 (CET) Received: from localhost (10.75.127.45) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 6 Nov 2020 18:55:08 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Simon Glass , U-Boot STM32 Subject: [PATCH 1/3] log: don't build the trace buffer when log is not ready Date: Fri, 6 Nov 2020 18:53:37 +0100 Message-ID: <20201106175339.30683-1-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-06_06:2020-11-05, 2020-11-06 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Update _log function to drop any traces when log is yet initialized: vsnprintf is no more executed in this case. This patch allows to reduce the cost for the dropped early debug trace. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- common/log.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/log.c b/common/log.c index 4b6f3fcd04..aadf533fb2 100644 --- a/common/log.c +++ b/common/log.c @@ -227,6 +227,9 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, struct log_rec rec; va_list args; + if (!gd) + return -ENOSYS; + /* Check for message continuation */ if (cat == LOGC_CONT) cat = gd->logc_prev; @@ -239,15 +242,15 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, rec.file = file; rec.line = line; rec.func = func; + + if (!(gd->flags & GD_FLG_LOG_READY)) { + gd->log_drop_count++; + return -ENOSYS; + } va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); rec.msg = buf; - if (!gd || !(gd->flags & GD_FLG_LOG_READY)) { - if (gd) - gd->log_drop_count++; - return -ENOSYS; - } if (!log_dispatch(&rec)) { gd->logc_prev = cat; gd->logl_prev = level; From patchwork Fri Nov 6 17:53:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1395797 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=avMCKs5y; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CSSjJ1hBnz9sTD for ; Sat, 7 Nov 2020 04:55:30 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5697680404; Fri, 6 Nov 2020 18:55:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.b="avMCKs5y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 80E65822DF; Fri, 6 Nov 2020 18:55:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 797748000F for ; Fri, 6 Nov 2020 18:55:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A6Hm995026881; Fri, 6 Nov 2020 18:55:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=NKJnkwI37CqYaEf3cv11ZIE2UwwdylOaOX+xLQMh5WU=; b=avMCKs5yFcLKyc1zp5NCrub/OGyQcRpwUfdwJsMY6P0qukW5WuBRBaKjiLDJOvuv1IPH A+eW8VYMa1YETQHttwrbQ6pQ/YHKwBknSy+EZdAfOc0dbzkMB5VfI9bUQikRTMmsYC4u us9w9nXzHJWw1aWVhGItltGWGetUURCfcrGjf6/Azxg9seBKe/VhrSGNvB3VkLoXsJ6i fGEGdmJS2TnRUvD7qA3upyuJIu/JeapRiZCESAatCBAA1xqz8wYon8Z/+o1+diEjbHYH 2Kz57UEswLOI1/jvxOkzUwbozmegXaosYI2Y7uJmjcYyDPHACEmyuSksithpTIE5UjJ3 6w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 34gyw1xfdg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Nov 2020 18:55:10 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1A9E4100034; Fri, 6 Nov 2020 18:55:10 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 0A3702150F7; Fri, 6 Nov 2020 18:55:10 +0100 (CET) Received: from localhost (10.75.127.46) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 6 Nov 2020 18:55:09 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Simon Glass , U-Boot STM32 Subject: [PATCH 2/3] log: use debug uart to output trace before LOG init Date: Fri, 6 Nov 2020 18:53:38 +0100 Message-ID: <20201106175339.30683-2-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201106175339.30683-1-patrick.delaunay@st.com> References: <20201106175339.30683-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-06_06:2020-11-05, 2020-11-06 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Use the debug uart functions to output the traces before the log initialization (when CONFIG_LOG is not activated) as it is done in puts/putc function in console.c. This patch allows to display the first U-Boot traces (with macro debug) when CONFIG_DEBUG_UART is activated and not only drop them. For example for traces in board_f.c requested by the macro debug, when LOG_DEBUG is defined and CONFIG_LOG is activated. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- common/log.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/log.c b/common/log.c index aadf533fb2..aa5505943f 100644 --- a/common/log.c +++ b/common/log.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -245,6 +246,16 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, if (!(gd->flags & GD_FLG_LOG_READY)) { gd->log_drop_count++; + + /* manage droppped trace at default level with debug uart */ + if (IS_ENABLED(CONFIG_DEBUG_UART) && + (rec.level <= CONFIG_LOG_DEFAULT_LEVEL || rec.force_debug)) { + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + printascii(buf); + va_end(args); + } + return -ENOSYS; } va_start(args, fmt); From patchwork Fri Nov 6 17:53:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick DELAUNAY X-Patchwork-Id: 1395798 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.a=rsa-sha256 header.s=STMicroelectronics header.b=PlwyzQNZ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CSSjZ0HPDz9sTK for ; Sat, 7 Nov 2020 04:55:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DA1208234E; Fri, 6 Nov 2020 18:55:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=st.com header.i=@st.com header.b="PlwyzQNZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 56CEE80404; Fri, 6 Nov 2020 18:55:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 79E7D801D8 for ; Fri, 6 Nov 2020 18:55:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.delaunay@st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A6HlJ3F018848; Fri, 6 Nov 2020 18:55:11 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=4Awi5vF9cPkyJlBy0OlAHmDBg5xgHUqdMWIof8hBf3U=; b=PlwyzQNZ2UhkfIzakNzh0+aC65ScohMytRiicnOV6agRWtbvtHkTwviU6CaN0EIZfQ1B HFYhuqLAo+pbEFCbeU7qrmDFMHiQXFVjtBb26pnGMmXjsSeAcbzd96iZVjIcGhSR2j00 B64eOCRAuO4uopmaWeyR952w9bgLxlctlwk1oftI0PSDlhn4r4dVB9hSOfqGYoxQ1VOA 7uPBPy9rmVk5kl1pKTGwxdsyZKDFzAbiCfUEIAx7uIlju2ipUnk89ApoRvVxDWcmcSvm eeWv4wVt7Tt7xy5bYZLSmRlb+sUkV0RZ6v6WBiVhiUM8bMEz6bmSBLN1ciZ3LbJqtgHD FA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 34h0328r12-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 06 Nov 2020 18:55:11 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 062B510002A; Fri, 6 Nov 2020 18:55:11 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id ED4A22150F7; Fri, 6 Nov 2020 18:55:10 +0100 (CET) Received: from localhost (10.75.127.47) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 6 Nov 2020 18:55:10 +0100 From: Patrick Delaunay To: CC: Patrick Delaunay , Simon Glass , U-Boot STM32 Subject: [PATCH 3/3] log: call vsnprintf only when it is needed to emit trace Date: Fri, 6 Nov 2020 18:53:39 +0100 Message-ID: <20201106175339.30683-3-patrick.delaunay@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201106175339.30683-1-patrick.delaunay@st.com> References: <20201106175339.30683-1-patrick.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-06_06:2020-11-05, 2020-11-06 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Reduce the log overhead when the traces are filtered, by moving the vsnprintf call from _log() to log_dispatch(). This patch avoids the printf treatment when LOG features is activated, but trace is filtered, for example when MAX_LOG_LEVEL=8 and LOG_DEFAULT_LEVEL=6. Signed-off-by: Patrick Delaunay # Conflicts: # common/log.c Reviewed-by: Simon Glass --- common/log.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/common/log.c b/common/log.c index aa5505943f..e5681ab323 100644 --- a/common/log.c +++ b/common/log.c @@ -198,9 +198,10 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec) * @rec: log record to dispatch * Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ -static int log_dispatch(struct log_rec *rec) +static int log_dispatch(struct log_rec *rec, const char *fmt, va_list args) { struct log_device *ldev; + char buf[CONFIG_SYS_CBSIZE]; /* * When a log driver writes messages (e.g. via the network stack) this @@ -214,8 +215,13 @@ static int log_dispatch(struct log_rec *rec) gd->processing_msg = true; list_for_each_entry(ldev, &gd->log_head, sibling_node) { if ((ldev->flags & LOGDF_ENABLE) && - log_passes_filters(ldev, rec)) + log_passes_filters(ldev, rec)) { + if (!rec->msg) { + vsnprintf(buf, sizeof(buf), fmt, args); + rec->msg = buf; + } ldev->drv->emit(ldev, rec); + } } gd->processing_msg = false; return 0; @@ -224,7 +230,6 @@ static int log_dispatch(struct log_rec *rec) int _log(enum log_category_t cat, enum log_level_t level, const char *file, int line, const char *func, const char *fmt, ...) { - char buf[CONFIG_SYS_CBSIZE]; struct log_rec rec; va_list args; @@ -243,13 +248,16 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, rec.file = file; rec.line = line; rec.func = func; + rec.msg = NULL; if (!(gd->flags & GD_FLG_LOG_READY)) { gd->log_drop_count++; - /* manage droppped trace at default level with debug uart */ + /* manage droppped traces at default level with debug uart */ if (IS_ENABLED(CONFIG_DEBUG_UART) && (rec.level <= CONFIG_LOG_DEFAULT_LEVEL || rec.force_debug)) { + char buf[CONFIG_SYS_CBSIZE]; + va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); printascii(buf); @@ -259,13 +267,11 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, return -ENOSYS; } va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - rec.msg = buf; - if (!log_dispatch(&rec)) { + if (!log_dispatch(&rec, fmt, args)) { gd->logc_prev = cat; gd->logl_prev = level; } + va_end(args); return 0; }