From patchwork Mon Sep 17 02:35:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 146820 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3254735ljw; Sun, 16 Sep 2018 19:35:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZPjCs6wSF4r+RAXQjxGOYdd2t/aHk72ZUYpgI5bd4aNVPmP0qHrMC9s7mjTEVaLUa3BN/H X-Received: by 2002:a50:b941:: with SMTP id m59-v6mr38318653ede.20.1537151721451; Sun, 16 Sep 2018 19:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537151721; cv=none; d=google.com; s=arc-20160816; b=TiA0sc57UdfLfs7IwbPQ9pN7YhuzsZIL2WUtkRw2WzZH1osHiOEQifqTHEQumM3u5+ qm5Q7zIIMX/bh38gFvpNbwzVtC7xsTCaYSemN039t2T5oC3GKpG6pHZJup+TLrjziPb3 8nusGiRyQp/9O9iMr6CAJUJJgPgqyN0MsS8N9y+AHna3P+hkOIDbWZkh+HaGocEkVSF2 yGsfmop5OjlOQVfySi4qgg3NXIEMtrRTSIuCey42/GZfWTs0jOInOsAi/2QJKG8K1kyI T3+cDW86AibWTOhukTYimlMz4WmpkroGzAqbbYGp0aBANzKgdikhjWCb6q/sEw4xaMVA HqeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from; bh=8K68V3JaTe4R9Yb7ffpcH1/lDiDVxmlJvGg20wQRPiM=; b=Gz3OlLFHskmWRShB2qvbfTHpM7MNKhrPXOgVWdK/bxsJdTlHGHxA//EnDOD0yf5o4g UP5t9uLFtOX7uoKdMJ1Hw1bDOoumDP3MdZw2q2AD46FKFBi9llVpLMKKgkh3f8DFV3+0 HyP2+eifocwqIwSprXUgzXq2NP4IpzgQmnX34YiDbYYjnX6RLMMFKwGbkI6pDZjlj6fc glrPIOPYE41rJniJVWXCRxbH7pJAfvVnUUn3kGJh+jn73thFAx1RTM/B+6nQ8CjRUSpt Sn5cEZrARljSWYXClIUAc+uKvWS9SBYEkjNqz/fq8L1IO+J76TGis77tdgWW9zubWsGI 5j6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id b21-v6si5469054edr.54.2018.09.16.19.35.20; Sun, 16 Sep 2018 19:35:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 80955C21E3B; Mon, 17 Sep 2018 02:35:17 +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=none 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 2D617C21DAF; Mon, 17 Sep 2018 02:35:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 61362C21C27; Mon, 17 Sep 2018 02:35:13 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 18ED6C21DAF for ; Mon, 17 Sep 2018 02:35:13 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A4518AF00; Mon, 17 Sep 2018 02:35:12 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Mon, 17 Sep 2018 04:35:10 +0200 Message-Id: <20180917023510.50797-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Heinrich Schuchardt Subject: [U-Boot] [PATCH] efi_loader: Merge memory map entries 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We currently do not combine memory entries that are adjacent and have the same attributes. The problem with that is that our memory map can easily grow multiple hundreds of entries in a simple UEFI Shell environment. So let's make sure we always combine all entries to make the memory map as small as possible. That way every other piece of code that loops through it should also gain some nice speed ups. Signed-off-by: Alexander Graf --- lib/efi_loader/efi_memory.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 4f8cb545ad..5bd4f4d7fc 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -65,9 +65,54 @@ static int efi_mem_cmp(void *priv, struct list_head *a, struct list_head *b) return -1; } +static uint64_t desc_get_end(struct efi_mem_desc *desc) +{ + return desc->physical_start + (desc->num_pages << EFI_PAGE_SHIFT); +} + static void efi_mem_sort(void) { + struct list_head *lhandle; + struct efi_mem_list *prevmem = NULL; + bool merge_again = true; + list_sort(NULL, &efi_mem, efi_mem_cmp); + + /* Now merge entries that can be merged */ + while (merge_again) { + merge_again = false; + list_for_each(lhandle, &efi_mem) { + struct efi_mem_list *lmem; + struct efi_mem_desc *prev = &prevmem->desc; + struct efi_mem_desc *cur; + uint64_t pages; + + lmem = list_entry(lhandle, struct efi_mem_list, link); + if (!prevmem) { + prevmem = lmem; + continue; + } + + cur = &lmem->desc; + + if ((desc_get_end(cur) == prev->physical_start) && + (prev->type == cur->type) && + (prev->attribute == cur->attribute)) { + /* There is an existing map before, reuse it */ + pages = cur->num_pages; + prev->num_pages += pages; + prev->physical_start -= pages << EFI_PAGE_SHIFT; + prev->virtual_start -= pages << EFI_PAGE_SHIFT; + list_del(&lmem->link); + free(lmem); + + merge_again = true; + break; + } + + prevmem = lmem; + } + } } /** efi_mem_carve_out - unmap memory region