From patchwork Thu Jul 12 02:13:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 942752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Qzy62DGbz9s37 for ; Thu, 12 Jul 2018 12:13:50 +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.b="dv4jFKUg"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41Qzy53szCzF36N for ; Thu, 12 Jul 2018 12:13:49 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="dv4jFKUg"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c00::242; helo=mail-pf0-x242.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.b="dv4jFKUg"; dkim-atps=neutral Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41Qzxw45CBzF36H for ; Thu, 12 Jul 2018 12:13:39 +1000 (AEST) Received: by mail-pf0-x242.google.com with SMTP id s21-v6so19614309pfm.6 for ; Wed, 11 Jul 2018 19:13:39 -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; bh=dOkMNMRbrftgJM9noM4d3MPglBdWNQzUPP3ajRoAuow=; b=dv4jFKUghE1NLsgYAsaMuCbJTlwRqeQj354KMBXIVJzJ7FnRrhmGqweFg+uVYVHgS3 m7gH39sZ8Bh4O8WhhCqWqSc4Amv6JY5NaXqOaUMajfURjrNZ3jFNoBDgE3PJhKSg74/u WM3liJQspAHt7ygxQ7+VsjpcGruNz36eJG/Lk2zui/d7DmhRx1cZaWIp8RiS3kTPSg7i NSv74pGPdVRboLTtEgh3dTBideVC0gXlXBDGQJEN8q0BM4QA+mEoY4m5RsQkr9YXErhJ AvnesdlrQf03zgwLFqTtJSa8iBzPsow9GAqU2BptmOXHxwqVjGdoaH5CX3Y8poazqS4i VRUg== 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; bh=dOkMNMRbrftgJM9noM4d3MPglBdWNQzUPP3ajRoAuow=; b=OXTeUWxikBf2ZbhWFkcCNQkw4//kbJwbsp/MbsfQU15Yj/kKCD7OQhx/f5O3T3qTlt MPcjixerdp/VWxNJ5gFjNI4IhAi7obCY0ldK98P2CLCFUJD8FF+mNwliPvMQNg8za7nx e061guL476vxf7XHjE0sLcH6TO1VjU6h0P56xhUoylLyzo7QktmGpLU79bQTFa/wiKvB vBYA+6IZICWHSp8DbERXvPAm5v0jcV+caE0F2FQAJhpwqXAZz6tCgflIYd4El6Ze7Hp5 MMFSWRWupYcwupcCJxeByWEmC6v9Pe+weTK4Hz+S5Ntyp6mup1lTgO9HOgLsKXTlLfQo +NaQ== X-Gm-Message-State: AOUpUlFBGj11N5OB+Ufz+GiyG7AEnrkA0a3/jIQ2fDt0hW1D1k7khap+ eYFLEAyKXMrrq6cNrCiDoS9YRw== X-Google-Smtp-Source: AAOMgpfzEo9qrNhvT0XgXKXxpLIMbyzSdbzAUB2ORzT93dJ4Yq8zHcWP+dvqSTwET1cz3lx3YV+kgw== X-Received: by 2002:a65:5b08:: with SMTP id y8-v6mr297868pgq.297.1531361617768; Wed, 11 Jul 2018 19:13:37 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 66-v6sm10165158pfd.71.2018.07.11.19.13.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 19:13:37 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Thu, 12 Jul 2018 12:13:26 +1000 Message-Id: <20180712021326.16277-1-oohall@gmail.com> X-Mailer: git-send-email 2.9.5 Subject: [Skiboot] [PATCH] mem_region: Merge similar allocations when dumping X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently we print one line for each allocation done at runtime when dumping the memory allocations. We do a few thousand allocations at boot so this can result in a huge amount of text being printed which is a) slow to print, and b) Can result in the log buffer overflowing which destroys otherwise useful information. This patch adds a de-duplication to this memory allocation dump by merging "similar" allocations (same location, same size) into one. Unfortunately, the algorithm used to do the de-duplication is quadratic, but considering we only dump the allocations in the event of a fatal error I think this is acceptable. I also did some benchmarking and found that on a ZZ it takes ~3ms to do a dump with 12k allocations. On a Zaius it's slightly longer at about ~10ms for 10k allocs. However, the difference there was due to the output being written to the UART. This patch also bumps the log level to PR_NOTICE. PR_INFO messages are suppressed at the default log level, which probably isn't something you want considering we only dump the allocations when we run out of skiboot heap space. Signed-off-by: Oliver O'Halloran --- --- core/mem_region.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/core/mem_region.c b/core/mem_region.c index 8ae49bb790fd..f17ba1508037 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -96,7 +96,8 @@ static struct mem_region skiboot_cpu_stacks = { struct alloc_hdr { bool free : 1; bool prev_free : 1; - unsigned long num_longs : BITS_PER_LONG-2; /* Including header. */ + bool printed : 1; + unsigned long num_longs : BITS_PER_LONG-3; /* Including header. */ const char *location; }; @@ -285,7 +286,7 @@ static bool region_is_reserved(struct mem_region *region) void mem_dump_allocs(void) { struct mem_region *region; - struct alloc_hdr *hdr; + struct alloc_hdr *hdr, *i; /* Second pass: populate property data */ prlog(PR_INFO, "Memory regions:\n"); @@ -301,11 +302,40 @@ void mem_dump_allocs(void) prlog(PR_INFO, " no allocs\n"); continue; } + + /* + * XXX: When dumping the allocation list we coalase allocations + * with the same location and size into a single line. This is + * quadratic, but it makes the dump human-readable and the raw + * dump sometimes causes the log buffer to wrap. + */ + for (hdr = region_start(region); hdr; hdr = next_hdr(region, hdr)) + hdr->printed = false; + for (hdr = region_start(region); hdr; hdr = next_hdr(region, hdr)) { + unsigned long bytes; + int count = 0; + if (hdr->free) continue; - prlog(PR_INFO, " 0x%.8lx %s\n", hdr->num_longs * sizeof(long), - hdr_location(hdr)); + if (hdr->printed) + continue; + + for (i = hdr; i; i = next_hdr(region, i)) { + if (i->free) + continue; + if (i->num_longs != hdr->num_longs) + continue; + if (strcmp(i->location, hdr->location)) + continue; + + i->printed = true; + count++; + } + + bytes = hdr->num_longs * sizeof(long); + prlog(PR_NOTICE, " % 8d allocs of 0x%.8lx bytes at %s (total 0x%lx)\n", + count, bytes, hdr_location(hdr), bytes * count); } } }