From patchwork Wed Sep 9 02:30:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1360305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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 4BmQyd2602z9sSP for ; Wed, 9 Sep 2020 12:32:09 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=eWIkKLQY; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BmQyd10xqzDqM9 for ; Wed, 9 Sep 2020 12:32:09 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=eWIkKLQY; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (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 lists.ozlabs.org (Postfix) with ESMTPS id 4BmQxT00wMzDqMK for ; Wed, 9 Sep 2020 12:31:08 +1000 (AEST) Received: by mail-pg1-x541.google.com with SMTP id u13so960527pgh.1 for ; Tue, 08 Sep 2020 19:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RwRmO4lKs1KjV6fu5drVwlz/F1HI4njKx0qfst6vTLA=; b=eWIkKLQYjnlp4YCbzs7QD18SwkcLu9/7YSOetkBWCscW/mQ2ohNWP449a4cmyOw4ZO sv3sdmAYfVElv2UWnEi45FRDBzU5t7ssNe/Zk5u5pMX9AiHa+NNNu2/gfqMOZ/0opdIb oG7AxAlJbXFAJKJi4lIYeLMSq18WDeoQZd9+C8VLmC5Vo6DNChxz5csQb04ThElK9/Ch KhkCVzgS5T6Fb94ZR1u+umGHWukj/j2Dte2u9OZLFjNCrD3GcVejFAcWSK4/4G99COSz gCcBoWh0f8Ua3tgj2UU113dK1qi+jwj/0VsoO5PmyGaCpEwyfS7sABA7jVJgNmV8mehp vxFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RwRmO4lKs1KjV6fu5drVwlz/F1HI4njKx0qfst6vTLA=; b=lqZ9+KFfiFKqTAlRFoCMUM7VliSron/Aep6L972N0ZIDB/H3ruqf6CXvLSsGnUehtz iSu7doVcfxvsvl6PZ/FQPZAUa+d06PuYWkoLAUTABOD6Mavhm9Xr9Ws8sTeG9MUNw8Jt NiwP04S/gWHHv8GhrqtMiji7McTyZxdg/g2fFUvW8CM0All8YU2EuTNZA5T+SynZIVhX EwOnrwc5UaVMync186fSKqNWLWqvGn1ep6/uhA3+yACB3Yt0w6hDNxFU3g2hbSf3Xivq KPMDbaoU1T4JSPNhSUvfDKe2nOmvqyis3rpfHUpNBuwp0YQZ40MazUG+p99ovCGu+s/J Su4A== X-Gm-Message-State: AOAM530edoMu4UTskVLR7zHIx8Z0jniTJMKH4+40GOjHmtUIDmZ/S2a/ IvrMxVI4Hb3Lk3k/O8EJ92LqO+HTClWiyg== X-Google-Smtp-Source: ABdhPJylAG+IpxALzyRNQ+y/AMwVOt6IC8qs06nZ3mkZb8u2cxXNs5l1pFPFlU2W5IDY8LQX/JUaAQ== X-Received: by 2002:a17:902:6ac6:b029:cf:85a7:8373 with SMTP id i6-20020a1709026ac6b02900cf85a78373mr2008781plt.2.1599618664174; Tue, 08 Sep 2020 19:31:04 -0700 (PDT) Received: from localhost.ibm.com (194-193-34-182.tpgi.com.au. [194.193.34.182]) by smtp.gmail.com with ESMTPSA id v69sm495737pgd.61.2020.09.08.19.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 19:31:03 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Wed, 9 Sep 2020 12:30:50 +1000 Message-Id: <20200909023050.1996918-1-oohall@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Skiboot] [PATCH] stack: only print stack usage backtraces when we hit a new watermark X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ajd@linux.ibm.com Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" With DEBUG=1 builds we use the mcount hook to instrument how much stack space we're using. If we detect that a function call has come within 2KB of the bottom of the stack we currently print a backtrace. This can result in a huge amount of console IO in DEBUG=1 builds which can cause op-test timeouts, etc. Printing a backtrace on each function call isn't terribly useful, and it ends up crowding out the backtrace that's printed when we hit a new stack usage watermark. The watermark should provide enough information to find and fix excessive stack usage issues so drop the per-function backtrace printing and move the warning into the high-watermark check. This change is largely necessary because of DEBUG=1 expands adds a backtrace save area to struct lock which expands the size of it to nearly 2KB. struct cpu_thread (which lives at the bottom of the per-thread stacks) contains three locks and an additional backtrace save area which is enabled when DEBUG=1. The extra space requirements result in cpu_thread ballooning from ~420 bytes to nearly 8KB. Any growth in cpu_thread also results in less stack space being available for the thread, so when DEBUG=1 is enabled we go from having a 16KB stack to an 8KB stack. Although this seems large, skiboot does have some fairly deep call chains (UART console flushing, TPM drivers, both combined) which can cause the thread to come within 2KB of the stack use warning zone. Signed-off-by: Oliver O'Halloran --- Maybe we should swap locations of the normal and emergency stacks so cpu_thread takes space from the emergency stack rather than the normal one. The e-stack should only be used at runtime where the call chains should be smaller. --- core/stack.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/stack.c b/core/stack.c index 2df960b3e6cb..05506f6b364b 100644 --- a/core/stack.c +++ b/core/stack.c @@ -206,16 +206,16 @@ void __nomcount __mcount_stack_check(uint64_t sp, uint64_t lr) backtrace_create(c->stack_bot_bt, CPU_BACKTRACE_SIZE, &c->stack_bot_bt_metadata); unlock(&stack_check_lock); - } - /* Stack is within bounds ? check for warning and bail */ - if (sp >= (bot + STACK_SAFETY_GAP) && sp < top) { if (mark < STACK_WARNING_GAP) { prlog(PR_EMERG, "CPU %04x Stack usage danger !" " pc=%08llx sp=%08llx (gap=%lld) token=%lld\n", c->pir, lr, sp, mark, c->current_token); - backtrace(); } + } + + /* Stack is within bounds? */ + if (sp >= (bot + STACK_SAFETY_GAP) && sp < top) { c->in_mcount = false; return; }