Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FA0EC433FE for ; Sun, 30 Oct 2022 01:50:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CE3B48512B; Sun, 30 Oct 2022 02:47:55 +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="oSWejUBY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 16C7085110; Sun, 30 Oct 2022 02:47:49 +0100 (CET) Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (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 45D8185112 for ; Sun, 30 Oct 2022 02:47:45 +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-il1-x132.google.com with SMTP id r1so4773835ilg.6 for ; Sat, 29 Oct 2022 18:47:45 -0700 (PDT) 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=pQG8L9kwIFHmiJqKeQ7ovJgpFbBNb5Fk0qpy+ZSREuQ=; b=oSWejUBYafHtRz7QJLqh+Pbobw5tLDbUFoRHrC0vGaA/DfdWkZJ7+xkLCjUcdhcsGQ 3AsMDp8c4/WA5NTOjCN3i/WB2FbVWZ6rY0GdtUxvra/VqtLlLtY96AmkeeuSJp9POCbQ juhiR9DM3I80sKfcXGsq0BS0ztz2gwu5+YBhs= 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=pQG8L9kwIFHmiJqKeQ7ovJgpFbBNb5Fk0qpy+ZSREuQ=; b=2gQpoyji5RdiAjrxuWSFcmMWEdrSCodEBTXKQ5jM0M62WecR2XPg5jOVKYggLNcmku ySbNhOM3yvbekRXcxd2rHfJRSnRg3Qf8Gak3f7CZQVAfw6FrDF09d8C35yrBBEt/k98K oJyOIcrLwxmo++OVJ2LdBLAdZ+AQ+0A4CPeIRh1B+R6wQoOJ1H31Exx3U4QplWpGc9fo swm0eOUohsVfDbKAh+TDQBbwKGh8SrDRlEdPvgV8kO9WBNUWMdpOXky0gF3j1ZT6jEza 8WBrg6QX3ywXZxtJO9hwDVCl1SPGykAyMKwYWWRT8QDucAn8xy72Qp8MTDCVsKzPGPkh WgyA== X-Gm-Message-State: ACrzQf1IuCtN+CQUAclILm1z9nXmTAHB/zgYfyVWtetsQ46M2ZBUG42o 7oTOYwvaCpKHy2rgd1gZ/xQFe2B5ra2V/Q== X-Google-Smtp-Source: AMsMyM7uJKMxWuBXB1rVpNiFkbvWparSDiEs1iOe2gU3UfeyMi2uwWAhdCdWfvjW1r1c6KycgNzhmg== X-Received: by 2002:a92:d590:0:b0:300:8f53:1a8 with SMTP id a16-20020a92d590000000b003008f5301a8mr3163712iln.216.1667094464756; Sat, 29 Oct 2022 18:47:44 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id x66-20020a0294c8000000b00363c4307bb2sm810287jah.79.2022.10.29.18.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Oct 2022 18:47:44 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Heinrich Schuchardt , Simon Glass , AKASHI Takahiro , Marek Vasut , Mattijs Korpershoek , Michal Suchanek , Pavel Herrmann , Sean Anderson , Stefan Roese Subject: [PATCH 06/17] dm: test: Clear the block cache after running a test Date: Sat, 29 Oct 2022 19:47:08 -0600 Message-Id: <20221030014719.147327-7-sjg@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221030014719.147327-1-sjg@chromium.org> References: <20221030014719.147327-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Some tests access data in block devices and so cause the cache to fill up. This results in memory being allocated. Some tests check the malloc usage at the beginning and then again at the end, to ensure there is no memory leak caused by the test. The block cache makes this difficult, since the any test may cause entries to be allocated or even freed, if the cache becomes full. It is simpler to clear the block cache after each test. This ensures that it will not introduce noise in tests which check malloc usage. Add the logic to clear the cache, using the existing blkcache_invalidate() function. Drop the duplicate code at the same time. Signed-off-by: Simon Glass --- drivers/block/blkcache.c | 23 ++++++++++------------- include/blk.h | 9 +++++++-- test/test-main.c | 3 +++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/block/blkcache.c b/drivers/block/blkcache.c index b53420a3a88..f99465aa479 100644 --- a/drivers/block/blkcache.c +++ b/drivers/block/blkcache.c @@ -150,8 +150,8 @@ void blkcache_invalidate(int iftype, int devnum) list_for_each_safe(entry, n, &block_cache) { node = (struct block_cache_node *)entry; - if ((node->iftype == iftype) && - (node->devnum == devnum)) { + if (iftype == -1 || + (node->iftype == iftype && node->devnum == devnum)) { list_del(entry); free(node->cache); free(node); @@ -162,18 +162,10 @@ void blkcache_invalidate(int iftype, int devnum) void blkcache_configure(unsigned blocks, unsigned entries) { - struct block_cache_node *node; + /* invalidate cache if there is a change */ if ((blocks != _stats.max_blocks_per_entry) || - (entries != _stats.max_entries)) { - /* invalidate cache */ - while (!list_empty(&block_cache)) { - node = (struct block_cache_node *)block_cache.next; - list_del(&node->lh); - free(node->cache); - free(node); - } - _stats.entries = 0; - } + (entries != _stats.max_entries)) + blkcache_invalidate(-1, 0); _stats.max_blocks_per_entry = blocks; _stats.max_entries = entries; @@ -188,3 +180,8 @@ void blkcache_stats(struct block_cache_stats *stats) _stats.hits = 0; _stats.misses = 0; } + +void blkcache_free(void) +{ + blkcache_invalidate(-1, 0); +} diff --git a/include/blk.h b/include/blk.h index d3ab9a10b96..58322c39eec 100644 --- a/include/blk.h +++ b/include/blk.h @@ -147,8 +147,8 @@ void blkcache_fill(int iftype, int dev, * blkcache_invalidate() - discard the cache for a set of blocks * because of a write or device (re)initialization. * - * @param iftype - uclass_id_x for type of device - * @param dev - device index of particular type + * @iftype - UCLASS_ID_ for type of device, or -1 for any + * @dev - device index of particular type, if @iftype is not -1 */ void blkcache_invalidate(int iftype, int dev); @@ -178,6 +178,9 @@ struct block_cache_stats { */ void blkcache_stats(struct block_cache_stats *stats); +/** blkcache_free() - free all memory allocated to the block cache */ +void blkcache_free(void); + #else static inline int blkcache_read(int iftype, int dev, @@ -193,6 +196,8 @@ static inline void blkcache_fill(int iftype, int dev, static inline void blkcache_invalidate(int iftype, int dev) {} +static inline void blkcache_free(void) {} + #endif #if CONFIG_IS_ENABLED(BLK) diff --git a/test/test-main.c b/test/test-main.c index ddfd89c089a..954a280119e 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -353,6 +354,8 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test) free(uts->of_other); uts->of_other = NULL; + blkcache_free(); + return 0; } -- 2.38.1.273.g43a17bfeac-goog