From patchwork Sun Jan 15 21:15:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1726831 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=jHaKWKFv; 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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nw7LH2C9wz23fk for ; Mon, 16 Jan 2023 08:18:31 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3ABB855DE; Sun, 15 Jan 2023 22:16:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jHaKWKFv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2FDAB8554E; Sun, 15 Jan 2023 22:16:37 +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.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2512C855BB for ; Sun, 15 Jan 2023 22:16:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd36.google.com with SMTP id d22so4045937iof.5 for ; Sun, 15 Jan 2023 13:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mwSTqDhx9io4WTT1nLYd1dR5cjYIpqrNkH/0UOQ+3H8=; b=jHaKWKFvmHxqmtCFBtgOM1zB6EcYjT8rl/Xspz4mnxLeuE/CAIasMwmEzwEO/Atm+Z riZFDK54oVoYfnWTYx0iHmiIeuPGNimtQZ3OdKaYfE0pF4gBFmgwiZW1I34E8HwGR/rM 0sUMxnqmLIHhXSON/xbAbHf51/ZIPFs3T6u/A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mwSTqDhx9io4WTT1nLYd1dR5cjYIpqrNkH/0UOQ+3H8=; b=te+luEVKDf9YGHCJOC056t35wSSck37MuMmq2/6O9lq/TWpUAU/f15E+s6fogSEFcm kA8JzQnvYCW54Xg39iPeHeKSyaezpDtV+C2XAAZkNz1MzcB0Iy5W0hHpnnE3IEAP0VrK 5qVu5Sm+jhAjSchc6OKqve3LMtE9goVN1P6ywa7wAyEKIoMj5wepsqZ5SY/TRRof9JvX 31fxX9AXDDS/8cKacSRCSwsnqMKiE0GWL6BY6LCmJxfDe6uocINNxZxBaBhEUYGBxo9x p3l3OaaLIsaklu+SVjVpCjpXBAg9VA/aGoPsoxTaJCQVRBfGNlDa/GL3bfDJr04jzldF dVdQ== X-Gm-Message-State: AFqh2kqcMZBmqdECQcLTnEw2reSpb2rY4uOjjmA69VkBGKTrjRnv7iF+ B+a8/3qfO7H9NN7R1ptsaLsY+zer5GtakOBtRT0= X-Google-Smtp-Source: AMrXdXscC+vm73sBvbasyafKAtRJGKnJ/6dDgXMYIvYp4+KIEy7GjV6hYh5IUrYC4KmInXiNtDZ02Q== X-Received: by 2002:a5d:9816:0:b0:6c3:a4b:9c17 with SMTP id a22-20020a5d9816000000b006c30a4b9c17mr56280218iol.5.1673817390694; Sun, 15 Jan 2023 13:16:30 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id j6-20020a6bf906000000b007046e9e138esm4329107iog.22.2023.01.15.13.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 13:16:30 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH 10/24] trace: Reduce the number of function sites Date: Sun, 15 Jan 2023 14:15:47 -0700 Message-Id: <20230115211602.1127661-11-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230115211602.1127661-1-sjg@chromium.org> References: <20230115211602.1127661-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean Given that the compiler adds two function calls into each function, the current spacing is overkill. Drop it down to 16 bytes per function, which is still plenty. This saves some space in the trace buffer. Also move the calculation into a function, so it is common code. Add a check for gd->mon_len being unset, which breaks tracing. Signed-off-by: Simon Glass --- include/trace.h | 6 ++++-- lib/trace.c | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/trace.h b/include/trace.h index 2be8d81b515..763d6d1255a 100644 --- a/include/trace.h +++ b/include/trace.h @@ -17,14 +17,16 @@ enum { * * The value here assumes a minimum instruction size of 4 bytes, * or that instructions are 2 bytes but there are at least 2 of - * them in every function. + * them in every function. Given that each function needs a call to + * __cyg_profile_func_enter() and __cyg_profile_func_exit() as well, + * we cannot have functions smaller that 16 bytes. * * Increasing this value reduces the number of functions we can * resolve, but reduces the size of the uintptr_t array used for * our function list, which is the length of the code divided by * this value. */ - FUNC_SITE_SIZE = 4, /* distance between function sites */ + FUNC_SITE_SIZE = 16, /* distance between function sites */ TRACE_VERSION = 1, }; diff --git a/lib/trace.c b/lib/trace.c index 2e2c1bed54f..12dae2089a4 100644 --- a/lib/trace.c +++ b/lib/trace.c @@ -321,6 +321,17 @@ void notrace trace_set_enabled(int enabled) trace_enabled = enabled != 0; } +static int get_func_count(void) +{ + /* Detect no support for mon_len since this means tracing cannot work */ + if (IS_ENABLED(CONFIG_SANDBOX) && !gd->mon_len) { + puts("Tracing is not supported on this board\n"); + return -ENOTSUPP; + } + + return gd->mon_len / FUNC_SITE_SIZE; +} + /** * trace_init() - initialize the tracing system and enable it * @@ -330,10 +341,12 @@ void notrace trace_set_enabled(int enabled) */ int notrace trace_init(void *buff, size_t buff_size) { - ulong func_count = gd->mon_len / FUNC_SITE_SIZE; + int func_count = get_func_count(); size_t needed; int was_disabled = !trace_enabled; + if (func_count < 0) + return func_count; trace_save_gd(); if (!was_disabled) { @@ -393,10 +406,12 @@ int notrace trace_init(void *buff, size_t buff_size) */ int notrace trace_early_init(void) { - ulong func_count = gd->mon_len / FUNC_SITE_SIZE; + int func_count = get_func_count(); size_t buff_size = CONFIG_TRACE_EARLY_SIZE; size_t needed; + if (func_count < 0) + return func_count; /* We can ignore additional calls to this function */ if (trace_enabled) return 0;