From patchwork Mon Oct 1 18:22:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 977396 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42PB7w2c2kz9s55 for ; Tue, 2 Oct 2018 04:46:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 11F00C21FB6; Mon, 1 Oct 2018 18:38:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9D68EC21F35; Mon, 1 Oct 2018 18:24:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 084D4C2204B; Mon, 1 Oct 2018 18:23:58 +0000 (UTC) Received: from mail-io1-f73.google.com (mail-io1-f73.google.com [209.85.166.73]) by lists.denx.de (Postfix) with ESMTPS id B4508C2202F for ; Mon, 1 Oct 2018 18:23:54 +0000 (UTC) Received: by mail-io1-f73.google.com with SMTP id l24-v6so14191777iok.21 for ; Mon, 01 Oct 2018 11:23:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=28LpnIlSeuC37i3a7tiw1Jzjzn5O+PfyA7UTElDrLqU=; b=hTMccxKfSpJ+F9XFxjXyr3bscrbocrvWNqsTUum6jBGUVLeKHs/kQWShiw1uxqYzFr XsQnyoD/g4y+ViOk3sB44p3F131Vbypes2IzLdiElyaRiflcaKomRshEQe+Etwn8/f8q oeZpk9Hq4eNvvn3+YzGh/r8p8/1IvCyvLAwJHqgxIBLCXc6wFg0CEMT17xLywfBFSNIR KMpQi6j952pFQrRY4yP/VnQHzriYV6yd9HtWBcCL7bdACLAnuRd03uhN/fFrgMjPnQGc jfu37fqHtoV7pkgSDEBI5TOvtXYFtV1Cc+BvF3KHD9Lcw50pEyzuMZRVufi1PjQytG+C d/Fw== X-Gm-Message-State: ABuFfoj95YmaJtfVaW5lzlbIr0n72ihoiEu4+QFgMyulDZ3jI1aJZFRS FI5uore0yGdLl7AtQasWOiPicYU= X-Google-Smtp-Source: ACcGV63QXHPaUTxW38FhO81BxpP9hoF4LRG4tUidd+yF7O4TFn/FJLTNFLT3NU1jBI6rRhAdKOl1ZCE= X-Received: by 2002:a24:7dcb:: with SMTP id b194-v6mr2073446itc.18.1538418233812; Mon, 01 Oct 2018 11:23:53 -0700 (PDT) Date: Mon, 1 Oct 2018 12:22:33 -0600 In-Reply-To: <20181001182249.129565-1-sjg@chromium.org> Message-Id: <20181001182249.129565-30-sjg@chromium.org> Mime-Version: 1.0 References: <20181001182249.129565-1-sjg@chromium.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH 29/45] malloc_simple: Add logging of allocations X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" It is sometimes useful to see what memory is being allocated early during boot. Add logging to support this, using a new LOGC_ALLOC category. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- common/malloc_simple.c | 58 +++++++++++++++++++++++++++--------------- include/malloc.h | 1 + 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/common/malloc_simple.c b/common/malloc_simple.c index 871b5444bd7..aae0b66680a 100644 --- a/common/malloc_simple.c +++ b/common/malloc_simple.c @@ -5,6 +5,8 @@ * Copyright (c) 2014 Google, Inc */ +#define LOG_CATEGORY LOGC_ALLOC + #include #include #include @@ -12,40 +14,47 @@ DECLARE_GLOBAL_DATA_PTR; -void *malloc_simple(size_t bytes) +static void *alloc_simple(size_t bytes, int align) { - ulong new_ptr; + ulong addr, new_ptr; void *ptr; - new_ptr = gd->malloc_ptr + bytes; - debug("%s: size=%zx, ptr=%lx, limit=%lx: ", __func__, bytes, new_ptr, - gd->malloc_limit); + addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align); + new_ptr = addr + bytes - gd->malloc_base; + log_debug("size=%zx, ptr=%lx, limit=%lx: ", bytes, new_ptr, + gd->malloc_limit); if (new_ptr > gd->malloc_limit) { - debug("space exhausted\n"); + log(LOGC_ALLOC, LOGL_ERR, "alloc space exhausted\n"); return NULL; } - ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes); + + ptr = map_sysmem(addr, bytes); gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr)); - debug("%lx\n", (ulong)ptr); return ptr; } -void *memalign_simple(size_t align, size_t bytes) +void *malloc_simple(size_t bytes) { - ulong addr, new_ptr; void *ptr; - addr = ALIGN(gd->malloc_base + gd->malloc_ptr, align); - new_ptr = addr + bytes - gd->malloc_base; - if (new_ptr > gd->malloc_limit) { - debug("space exhausted\n"); - return NULL; - } + ptr = alloc_simple(bytes, 1); + if (!ptr) + return ptr; - ptr = map_sysmem(addr, bytes); - gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr)); - debug("%lx\n", (ulong)ptr); + log_debug("%lx\n", (ulong)ptr); + + return ptr; +} + +void *memalign_simple(size_t align, size_t bytes) +{ + void *ptr; + + ptr = alloc_simple(bytes, align); + if (!ptr) + return ptr; + log_debug("aligned to %lx\n", (ulong)ptr); return ptr; } @@ -57,9 +66,16 @@ void *calloc(size_t nmemb, size_t elem_size) void *ptr; ptr = malloc(size); - if (ptr) - memset(ptr, '\0', size); + if (!ptr) + return ptr; + memset(ptr, '\0', size); return ptr; } #endif + +void malloc_simple_info(void) +{ + log_info("malloc_simple: %lx bytes used, %lx remain\n", gd->malloc_ptr, + CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr); +} diff --git a/include/malloc.h b/include/malloc.h index 8175c75920c..b714fedf457 100644 --- a/include/malloc.h +++ b/include/malloc.h @@ -880,6 +880,7 @@ static inline void free(void *ptr) {} void *calloc(size_t nmemb, size_t size); void *memalign_simple(size_t alignment, size_t bytes); void *realloc_simple(void *ptr, size_t size); +void malloc_simple_info(void); #else # ifdef USE_DL_PREFIX