From patchwork Tue Jan 28 10:19:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 860377 Delivered-To: patch@linaro.org Received: by 2002:a5d:6b8c:0:b0:385:e875:8a9e with SMTP id n12csp281895wrx; Tue, 28 Jan 2025 02:30:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU1NvMoxuwIfn1Nv3kfxG56ex1EQ6sL0Wp6W+jEZPrBh64WDbqObQ80+jXqjYUhmchY3YR0vA==@linaro.org X-Google-Smtp-Source: AGHT+IF6IYwP2fr06/augRlOt5IRuCyA6qhlK2SaYzTeiYg9yiSUbmNtd9B8jd4B3LcPpR86GisL X-Received: by 2002:a17:907:969f:b0:aa6:762e:8c20 with SMTP id a640c23a62f3a-ab38b37cf93mr4581580966b.43.1738060243246; Tue, 28 Jan 2025 02:30:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738060243; cv=none; d=google.com; s=arc-20240605; b=H20LTudYwNteYp5OiMvvlvjrM7yKiQKF9dAvpVlX3MiBbpR7i1Y5dtnS+4tKtsX1GE MFTcjl3EhSlLL5t+udg7/uAXbGzQEawQGEOq/2wTLqlzkz5zn/wOmBT+oT49JFIcC89s TVvkdXhinqUxq0xuWm9Z6i+TFN7PuFqbE0hiol/A+mRMJPLwDRpSUepWI1FPz02J56++ qKx9tY5/o8Itx8uSdSLKf6i9RV9RzCk3JtAAF7L6t7phT5O0Rz6YYEKR9rKbAtV6w+FD V9fI0fw4/CLeDV0VpJ0phDDTUYfiGhgnzBPG3XNABczQ3I9QOY7iufeFDIga8AIErnoU I1pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BqWBxBeSBN85uoyU0epbXFnDKcvIpLM2onBGrSfc4vg=; fh=Nk/iIugUz6rZzcw+U4zB1tZpnMlZYNJpKOQcuMdjy8o=; b=ZkZuSC1sQ1rQfxybSwebiQqgHnPiUEl1O4ecRrlKb4thez1gGfxIrhGJf1TnoF26qW GA8ksVkTGy472/ZIphFM8OsZKHRTOhMD9dE1zcatyZ4eCArZz1iGSGTDy1O6kjSC5hH9 d1ofdAmT/t/DrYAQz9nUy6AJWQGbgvyhmuLe+HyUkbsM5yrePgsSJ7WNORIEMArO/6C+ zNwQ4KKr01v3oOeP+Nbpow0cR7AEP7faeohXxLvlJYbupLfm7h1fv601Od7NkyTpz1Fc kioyt9jPThdtp5oHMKS9HWQxwnzg5zvzqgWIT3OrUQMWeKDHRo4WVQlE5Gyfhhw9RK+N Mi4g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vehJIa2e; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-ab6762ab446si721183466b.737.2025.01.28.02.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 02:30:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vehJIa2e; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A330081DA8; Tue, 28 Jan 2025 11:20:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vehJIa2e"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 74B3F81D42; Tue, 28 Jan 2025 11:20:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (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 B6A0781D5A for ; Tue, 28 Jan 2025 11:20:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43690d4605dso36335555e9.0 for ; Tue, 28 Jan 2025 02:20:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738059607; x=1738664407; darn=lists.denx.de; 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=BqWBxBeSBN85uoyU0epbXFnDKcvIpLM2onBGrSfc4vg=; b=vehJIa2eEzlk1fnQMCYu+iQhmYQH9Je4igXoDWQAXZ4n2gOunoZaGQphO8FoG10UWu Ngj91iDbINccGT0rnxO/5NEQOlitd5maXaCGi1sg7HWuRvYtp386g2eJKYQXK5Gfyffa rftnMLSaNJFVMgtvYWO1RH4o2Tw9m4mwQMyEBHvMIhTyovHy9wi3HOCqYo9RrBnNGs91 PMGD45QYftjW0fBOodFdz7XRif/Aa0abwf9dPPMjtNVc8JQ58ntW57BzcYU0CWoDPxov GT7TSlmGVsfwz4sdR2aRVU8WzgS8KNCgFwfUDQrnrg1MoE0jFzLfjvxWr7h+O5F/wM1x tVnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738059607; x=1738664407; 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=BqWBxBeSBN85uoyU0epbXFnDKcvIpLM2onBGrSfc4vg=; b=OTltHAG10kVeifjZ+Swb09KCmXQpjUXWAASX9eUpMpgyoyO7QryJVJgJjF9Sk2KrKW uD+FmsEDetZkdfPTiPCygXauwiEa6DRA+2VaIImzDNcwVGqIHLJnAeki5NOcnvHI5/1x JREYIKrPtRhOVt/nXjrp4w43ggeS1EhMbtgquSUNUjAhInF4L4C44SZuc8wCBnwdnYWO NVYiLdRIhKu2EVqxCBQAOpzu1QkCEHH6ELET2qfk0YHU2CeL1ImWnwFhH9arHacIPOEZ uS6o4D1PRABXQcOIyf+KXtcg5om1eQI4PfrcAhIX1Jpdfe2vb3dSGLRxQGYMs3zsSRH7 SVrQ== X-Gm-Message-State: AOJu0YzHQEiY/yepSnSPEFyPkq0EzIw1F3vQMXcRhcRi7G+P0Sjjm2jh Xx6crlBTlqYClEoEOSCTgtn1ar/jX+mtgXl9CJN/nd8BdZHg7qypmSR/TdQT0pOhrnXPQgSUOTV 40/TX6Q== X-Gm-Gg: ASbGncsSdJZjHbFJUDmsnYY+LkE982zskDHvqJln3U25VE7HEWY47sOo9QQBdbyiUIy idOpQP1gCBIMm+/kTpeoeDjeMJ0pUIuaWqMfC49EcgxZR5ULFQFLlGxWQMfyMZ/oXqrXuaO5q9t VqZd3Mx2na3ASCVz9Ob351vbjO0J61jqLIVc1b4jZxoRYDW9dwCJr7UBUGpgBXo9/8JVldQ8UBq 66z8Knfi2Ch8VW9rZP8MQ/faOtWJVRbLE3LV3sguYlnTDUbU8UuZCgdw452MPl0Mj9236jyfIvk xQWA17nSbmTAk9s43Pt2ZVow2/vjqqwYAQ== X-Received: by 2002:a05:600c:3149:b0:436:5fc9:30ba with SMTP id 5b1f17b1804b1-43891441f57mr423818165e9.29.1738059606927; Tue, 28 Jan 2025 02:20:06 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:45e:43e2:ed61:42fe]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4b9977sm164651245e9.25.2025.01.28.02.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2025 02:20:06 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Heinrich Schuchardt , Tom Rini , Simon Glass Subject: [RFC PATCH v2 2/3] efi_loader: optimize efi_init_obj_list() with coroutines Date: Tue, 28 Jan 2025 11:19:16 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean When COROUTINES is enabled, schedule efi_disks_register() and efi_tcg2_register() as two coroutines in efi_init_obj_list() instead of invoking them sequentially. The voluntary yield point is introduced inside udelay() which is called frequently as a result of each function polling the hardware. This allows the two coroutines to make progress simultaneously and reduce the wall clock time required by efi_init_obj_list(). Tested on Kria KV260 with a microSD card inserted with the "printenv -e" command. With COROUTINES disabled, efi_init_obj_list() completes in 2821 ms on average (2825, 2822, 2817). With COROUTINES enabled, it takes 2265 ms (2262, 2260, 2272). That is a reduction of 556 ms which is not bad at all considering that measured separately, efi_tcg2_register() takes ~825 ms and efi_disks_register() needs ~600 ms, so assuming they would overlap perfectly one can expect a 600 ms improvement at best. The code size penalty for this improvement is 1340 bytes. Signed-off-by: Jerome Forissier --- lib/efi_loader/efi_setup.c | 113 +++++++++++++++++++++++++++++++++++-- lib/time.c | 14 ++++- 2 files changed, 122 insertions(+), 5 deletions(-) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index aa59bc7779d..94160f4bd86 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -7,10 +7,12 @@ #define LOG_CATEGORY LOGC_EFI +#include #include #include #include #include +#include #define OBJ_LIST_NOT_INITIALIZED 1 @@ -208,6 +210,46 @@ out: return -1; } +#if CONFIG_IS_ENABLED(COROUTINES) + +static void efi_disks_register_co(void) +{ + efi_status_t ret; + + if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) + goto out; + + /* + * Probe block devices to find the ESP. + * efi_disks_register() must be called before efi_init_variables(). + */ + ret = efi_disks_register(); + if (ret != EFI_SUCCESS) + efi_obj_list_initialized = ret; +out: + co_exit(); +} + +static void efi_tcg2_register_co(void) +{ + efi_status_t ret = EFI_SUCCESS; + + if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) + goto out; + + if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { + ret = efi_tcg2_register(); + if (ret != EFI_SUCCESS) + efi_obj_list_initialized = ret; + } +out: + co_exit(); +} + +extern int udelay_yield; + +#endif /* COROUTINES */ + /** * efi_init_obj_list() - Initialize and populate EFI object list * @@ -216,6 +258,12 @@ out: efi_status_t efi_init_obj_list(void) { efi_status_t ret = EFI_SUCCESS; +#if CONFIG_IS_ENABLED(COROUTINES) + struct co_stack *stk = NULL; + struct co *main_co = NULL; + struct co *co1 = NULL; + struct co *co2 = NULL; +#endif /* Initialize once only */ if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) @@ -224,6 +272,53 @@ efi_status_t efi_init_obj_list(void) /* Set up console modes */ efi_setup_console_size(); +#if CONFIG_IS_ENABLED(COROUTINES) + main_co = co_create(NULL, NULL, 0, NULL, NULL); + if (!main_co) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + stk = co_stack_new(8192); + if (!stk) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + co1 = co_create(main_co, stk, 0, efi_disks_register_co, NULL); + if (!co1) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + co2 = co_create(main_co, stk, 0, efi_tcg2_register_co, NULL); + if (!co2) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + udelay_yield = 0xCAFEDECA; + do { + if (!co1->done) + co_resume(co1); + if (!co2->done) + co_resume(co2); + } while (!(co1->done && co2->done)); + udelay_yield = 0; + + co_stack_destroy(stk); + co_destroy(main_co); + co_destroy(co1); + co_destroy(co2); + stk = NULL; + main_co = co1 = co2 = NULL; + + if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) { + /* Some kind of error was saved by a coroutine */ + ret = efi_obj_list_initialized; + goto out; + } +#else /* * Probe block devices to find the ESP. * efi_disks_register() must be called before efi_init_variables(). @@ -232,6 +327,13 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { + ret = efi_tcg2_register(); + if (ret != EFI_SUCCESS) + efi_obj_list_initialized = ret; + } +#endif + /* Initialize variable services */ ret = efi_init_variables(); if (ret != EFI_SUCCESS) @@ -272,10 +374,6 @@ efi_status_t efi_init_obj_list(void) } if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { - ret = efi_tcg2_register(); - if (ret != EFI_SUCCESS) - goto out; - ret = efi_tcg2_do_initial_measurement(); if (ret == EFI_SECURITY_VIOLATION) goto out; @@ -350,6 +448,13 @@ efi_status_t efi_init_obj_list(void) !IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) ret = efi_launch_capsules(); out: +#if CONFIG_IS_ENABLED(COROUTINES) + co_stack_destroy(stk); + co_destroy(main_co); + co_destroy(co1); + co_destroy(co2); efi_obj_list_initialized = ret; +#endif + return ret; } diff --git a/lib/time.c b/lib/time.c index d88edafb196..c11288102fe 100644 --- a/lib/time.c +++ b/lib/time.c @@ -17,6 +17,7 @@ #include #include #include +#include #ifndef CFG_WD_PERIOD # define CFG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default */ @@ -190,6 +191,8 @@ void __weak __udelay(unsigned long usec) /* ------------------------------------------------------------------------- */ +int udelay_yield; + void udelay(unsigned long usec) { ulong kv; @@ -197,7 +200,16 @@ void udelay(unsigned long usec) do { schedule(); kv = usec > CFG_WD_PERIOD ? CFG_WD_PERIOD : usec; - __udelay(kv); + if (CONFIG_IS_ENABLED(COROUTINES) && + udelay_yield == 0xCAFEDECA) { + ulong t0 = timer_get_us(); + do { + co_yield(); + __udelay(10); + } while (timer_get_us() < t0 + kv); + } else { + __udelay(kv); + } usec -= kv; } while(usec); }