From patchwork Tue Mar 4 15:24:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870119 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp314483wrg; Tue, 4 Mar 2025 07:34:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW5Ci9NUeBClTDv1quiW7uQq+Rgg0ChJWuz3oyca63fRFn8Al39y0LmVjvFN9AVp2VQy03jcA==@linaro.org X-Google-Smtp-Source: AGHT+IEnU+4DysGe1UGBgR6XveO4+FcdXvyUd41cc0oeVXu7Ur70XHE3irJC2dxxVszTr40c5pso X-Received: by 2002:a05:6a00:140c:b0:734:ded8:77aa with SMTP id d2e1a72fcca58-7366e5f4856mr5508365b3a.9.1741102493402; Tue, 04 Mar 2025 07:34:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102493; cv=none; d=google.com; s=arc-20240605; b=JhUL38zxq3dtFMbvyYnVqaJreXLmDCAwlOD/v2gqHo5Fgo+0altZwvBR1YdviX782b Z+HjkGdHqvMcUEWfCl4L8jTwsJbLbVVZr/uxA1Jm+lDS2KHPuAJcq8nuoUByMrd8qnKx WQbYwxvbg0k2vfOPuMOiCiUXG3VulTJH7oTfN8ZBD6o6NholUa1gRtUKdGYjzONW7xvg d3iHxuOTsRF4DVeRBDAWfC8Q1fwN95GsSAqKSkcjBIh2b+4dJLyw0oWx/l65IB2pv/gf 0h1LwuRjHAY/Qg9j7moqrtO9lYdpY3tyXE+zoWnTIa0kapi9hIbWzLEM4Kffckpu2SXd yjNA== 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=s6HQ7yLaCV2yD73oy4V3ghzdBT7DFF+iSIvgXL8Pym0=; fh=IO8hkgkniZEwXxFcjyCBO6jjqgrOtIELw0Al2vZcVv8=; b=IE/n6xf4fOOOLpFd4S6khjIuJfx3CV/IfcULH/scSdFErtL8SikKZOX22cXU17ldlj buvN6PgGIg5y9kOCGEubh31amSQNrX2yKM7w1eGMkcNBAY1QxvVNnUwXWWAIz+/NGcYf mqwTIWvV9FWvLkl62jGG+n2zLIlqU1ikiD043Td+ThYWBp/LWIOQeAu/67075v9BnWhM fbrcd6Qt/ZeIupYOePXpsm2jp+Kskfaysj1WJbjGnjMiZCzPBvXLETU4zEK2egJTV/eM DzW5WJj45SsQlrDZFCzipPDOjIKh4bw9jjaNyxdtJyl2Uqe2VPuv3RpoTcw9TsW727wu 57Aw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZZGeq4m; 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 d2e1a72fcca58-7349fe50ff5si17754564b3a.98.2025.03.04.07.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:34:53 -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=IZZGeq4m; 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 D69CC81253; Tue, 4 Mar 2025 16:32:22 +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="IZZGeq4m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7CDAC81433; Tue, 4 Mar 2025 16:32:21 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 21B698142E for ; Tue, 4 Mar 2025 16:32:18 +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-wr1-x435.google.com with SMTP id ffacd0b85a97d-390dd362848so4517591f8f.3 for ; Tue, 04 Mar 2025 07:32:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102286; x=1741707086; 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=s6HQ7yLaCV2yD73oy4V3ghzdBT7DFF+iSIvgXL8Pym0=; b=IZZGeq4mZxis+YdSrAUVbL5gmsDjlhWRt2H0gZ1rzcamhRi/LgvvXskMMVGpDRgb2x MTF7gkj4OBcEa1vS8GcEusJs094W7i6VR/D427aU8/dfhPcdoIzJU3AflZ9A+hAEup12 UGW94dXEUmI/mXo773J5t8yxFLVjogZjZlkx9RVADuuxNjqDj31c5GgEH8hIgZIPbr+1 RE04f0yTr6MjEBxsOeE1AmMy4e2M7Ngcshx74BQzOTmbMV2KSXa4ZQTZD02NHp/dL+Rg B0EKDF5i97H+4/T5/Oak6UlaEzTqR9eM6DcSbjcGFpdTwWnW+DOWWT+UvcyzZHBlIdT8 YOYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102286; x=1741707086; 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=s6HQ7yLaCV2yD73oy4V3ghzdBT7DFF+iSIvgXL8Pym0=; b=qu1XEXea5V3tvJ9fIjVWZ2eMogAYWbObkGvs4KaQ7oxCDn9AbZsZNTYRDorC3SRHEZ WY5Q3+YnWGDSa7/115YFR70oQWh+iPbBX6a1LKKp09aULIbai5pipBnHH/eHZu1znR4u yeQnGxIEoJF1+PNykMJsEy0TCSg9cHrwLb+g4fNpeM2IxwziFdYXvf0h0zgTZdXjdBY5 HpIaT/4bjCaFYJwAVR0m1U129bMjkjJeQHxzShtnMquBmrEaAOTZCuY4Pxzb1ErnBou4 gzVnini0Hd5tnhAZkb1fXJbtK/Wyb4ooSuJu6nU3D9qyHo0dLDTim7P5llqDwJgLCA5T V72g== X-Gm-Message-State: AOJu0Yx9zF3ZnrRnxUois32Y+Dc7Hv2/O8D2cHf6zF8yix1qFhKXKmQ3 rxEhoS2sCxmfI5yNh/8KIw8WndAFaXKZOoILf0Iuusn1JYS7iXnygnN9SGI9b51TIAiDzO12343 v X-Gm-Gg: ASbGncuq0zL4bb6fFHxC3bSoYdWpzfI65m90qU6Lmglq2Dt5KgylzhyE4/FI7tN/sMJ Mk/HsVCqn3ervL0WElyTX66VPLxxpHS0735+so2WM1OVIpM/2C3nFRA4juI2n2aRJWBC7CLwP58 MITk1yA3gSLd9r1fd9pUkwPwGcAhmU0LewmT9P34iMR3WXM9Nv86f2ffJUTitVHLJionurgOV3i dmqPTCDXHfRI+8GzgdMgz/b1VN2vDIPltE1jzN9IfIAMUWzLNJI7N5UmpqyfUe/AwcVl2Xglv+H PAd7FVDtOMe68auwfowU6WCm6ycNcUC6D+I0pji4Df348CcrC4TGyQ== X-Received: by 2002:a5d:5889:0:b0:391:1222:b459 with SMTP id ffacd0b85a97d-3911222b5fdmr5267410f8f.49.1741102285576; Tue, 04 Mar 2025 07:31:25 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:25 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Dan Carpenter , Simon Glass , Heinrich Schuchardt , Yu-Chien Peter Lin , Andrew Goodbody , Jiaxun Yang , Christian Marangi , Vasileios Amoiridis Subject: [PATCH v3 01/14] arch: introduce initjmp() and Kconfig symbol HAVE_INITJMP Date: Tue, 4 Mar 2025 16:24:49 +0100 Message-ID: <20250304152510.2832340-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Add the HAVE_INIJMP symbol to be set by architectures that support initjmp(), a non-standard extension to setjmp()/longjmp() allowing to initialize a jump buffer with a function pointer and a stack pointer. This will be useful to later introduce threads. With this new function it becomes possible to longjmp() to a particular function pointer (rather than to a point previously reached during program execution as is the case with setjmp()), and with a custom stack. Both things are needed to spin off a new thread. Then the usual setjmp()/longjmp() pair is enough to save and restore a context, i.e., switch thread. Add the initjmp() prototype to since it is common to all architectures. Add an entry to the API documentation: doc/api/setjmp.rst. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- arch/Kconfig | 7 +++++++ doc/api/index.rst | 1 + doc/api/setjmp.rst | 10 ++++++++++ include/setjmp.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 doc/api/setjmp.rst diff --git a/arch/Kconfig b/arch/Kconfig index 35b19f9bfdc..14111ca14fb 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -13,6 +13,13 @@ config HAVE_SETJMP help The architecture supports setjmp() and longjmp(). +config HAVE_INITJMP + bool + depends on HAVE_SETJMP + help + The architecture supports initjmp(), a non-standard companion to + setjmp() and longjmp(). + config SUPPORT_BIG_ENDIAN bool diff --git a/doc/api/index.rst b/doc/api/index.rst index a108718ea99..0dc9ad45d41 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -25,6 +25,7 @@ U-Boot API documentation rng sandbox serial + setjmp sysreset timer unicode diff --git a/doc/api/setjmp.rst b/doc/api/setjmp.rst new file mode 100644 index 00000000000..7718047085c --- /dev/null +++ b/doc/api/setjmp.rst @@ -0,0 +1,10 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Long jump API +============= + +.. kernel-doc:: include/setjmp.h + :doc: Overview + +.. kernel-doc:: include/setjmp.h + :internal: diff --git a/include/setjmp.h b/include/setjmp.h index 37d3a8af85d..8b2ff66a4c2 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -3,12 +3,26 @@ #ifndef _SETJMP_H_ #define _SETJMP_H_ 1 +/** + * DOC: Overview + * + * The long jump API allows to perform nonlocal gotos, that is jump from one + * function to another typically further down in the stack, while properly + * restoring the stack's state (unwinding). The two functions needed to do this + * are setjmp() and longjmp(). + * + * In addition to these two standard POSIX.1-2001/C89 functions, a third one is + * present in U-Boot: initjmp(). It is an extension which allows to implement + * user-mode threads. + */ + #ifdef CONFIG_HAVE_SETJMP #include #else struct jmp_buf_data { }; #endif +#include /** * typedef jmp_buf - information needed to restore a calling environment @@ -37,4 +51,19 @@ int setjmp(jmp_buf env); */ void longjmp(jmp_buf env, int val); +/** + * initjmp() - prepare for a long jump to a given function with a given stack + * + * This function sets up a jump buffer for later use with longjmp(). It allows + * to branch to a specific function with a specific stack. Please note that + * @func MUST NOT return. It shall typically restore the main stack and resume + * execution by doing a long jump to a jump buffer initialized by setjmp() + * before the long jump. initjmp() allows to implement multithreading. + * + * @env: jump buffer + * @func: function to be called on longjmp(), MUST NOT RETURN + * @stack: the stack to be used by @func + */ +int initjmp(jmp_buf env, void __noreturn (*func)(void), void *stack); + #endif /* _SETJMP_H_ */ From patchwork Tue Mar 4 15:24:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870120 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp314581wrg; Tue, 4 Mar 2025 07:35:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUAG3Vu4IKdSrECR73Yh5kqYQg+1dyy0nMPaqiqk3mJlbBE0NIMB8QkviliZWGIx/jNG3Fa0A==@linaro.org X-Google-Smtp-Source: AGHT+IFocrX11fi9xgyn4VMLd8bfiwWDDIDBsyAeBJyP5SQnybauVG7BEjOYjTeyC1rzEzizk/dV X-Received: by 2002:a17:90b:5745:b0:2ee:8430:b831 with SMTP id 98e67ed59e1d1-2febab2eaffmr29064859a91.2.1741102506139; Tue, 04 Mar 2025 07:35:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102506; cv=none; d=google.com; s=arc-20240605; b=URpXP3pyhOeTTgzHzfMRfsNSrjD4lzL9xO7AlMfR99ecXuo9uBUcHcwJAHwueJZsVm O36XNaMeeIGBDcGKFcPevgjlcwLBmdOstbDkxHxzXRg2T43Lz5qeVjyootPgKqgtLeNz RBiGKct8pCnQbUPHANWoDPpXWnSdyHmnVvDPFNnCS3AZ1xx9hQgZyO15EI2/TjYh4e7+ 8USvEWT/cU4pVxrmjt85mLfmSLTBwkEB0zt/kx/BEMt3ryAOa7a9jpKB9SqM2kmZ5VMT 63BWqz2dnrHPD7i2wcB3xFRjnVA2jsFn5VnVVOvpaDE71PD+c7i6g1xeujwCJXNVtu0F 0w3A== 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=DpPsgcrT0/Z4oAyeFytZ0N3HH8jEv4dIyLAVNWv2CKY=; fh=+waTJno/rU49iczqt4D1sPRPkTdldG7IJg1quBhfNhk=; b=GvYgcsPmZ9KdCQg9ZPRd92/yUxnzH20AnVNH2Ty/eR0R7cqa94DW2lnFJX41rRjZTs +crVznRV1HhHc7cwG5H2aGx5c85gj8TgzdG4GA0Q/V544xWzQhKd7p7R+b26Hc/I1QR5 15l0G7WqzhJWJ4GoDu6T3us6Pumxv6oEAKkCAmEo4oBDsL+Xu3styOFbyU1Z3o5NM4k/ dm+9x83mhLZYZseeKigkkqkNy896jbzQDvnk4+/o0p5JM935sUBYwnDcLfKXeTtaEIt1 DPYGZAnjVO9S/s3bSMb02S4AclKmeg6+1OW2eR3CaO2+syBZg1N1Y2UmRielPn2zgcdk jcZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vaaot1e/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2fe825cc821si20613856a91.6.2025.03.04.07.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:35:06 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vaaot1e/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 3089F81433; Tue, 4 Mar 2025 16:32:23 +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="Vaaot1e/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD5828142E; Tue, 4 Mar 2025 16:32:21 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 BB0E281253 for ; Tue, 4 Mar 2025 16:32:19 +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-wr1-x429.google.com with SMTP id ffacd0b85a97d-390f5f48eafso1895443f8f.0 for ; Tue, 04 Mar 2025 07:32:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102287; x=1741707087; 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=DpPsgcrT0/Z4oAyeFytZ0N3HH8jEv4dIyLAVNWv2CKY=; b=Vaaot1e/Gpt1LgucX6ZkXJt+HqkwrqIhkyaqw9VxtdcvUh5YgFUycco32T6ESMcgcO H/ulJvWC87KVSh0AH0k05R/32GnQZUqgEgNBGvAhmDcSwHtCzgk4u/kbXkwy0po1POp/ aXaHIULKPEY2qd3uXf78yOVrvSWW+EY1NHK13UXZde6kVqBcInxKK4byi2zVlzofAHLZ P1s37GRh4AbVURWCakS+Xui8zovliLBU7kTlp2QTNKYkMbEu8wY+FT1FS4G96wxxzKPE HBlkJQUZRywBryvIlj2ZUl30vrAg7X8zLskwfVad5gz2VII+QeYB7AK2Y1FO55iWII2U tPOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102287; x=1741707087; 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=DpPsgcrT0/Z4oAyeFytZ0N3HH8jEv4dIyLAVNWv2CKY=; b=H7q9RdqWpUbz7JrhbqnpWRrFGjG+zTcLnQqcBughr2NrLKNMfBTm3jl+WZfSVxTj9C mLaZ/uX+HKiHkvE7kJi8V/Is880XnjG99qp2vf1Qa0l+DU1o7MVw8AMp5+1nRQlFzuVA l2YSreuwRHxA/UfGnKnI4H7BoOJzwc8/XjhfaCZFjdimjn50ZViLBqzBx9NQJMe10aiN 7knOlK+kpasyDUj7UR7Mv1ewZGNfxD1vJK0CArndEhEzgWgzL69hzUDVmPMkpNz6BFDH x0kMaMmpx3gh+lrrG7GLk2rsKdJ720S9JFFWdfBoqzDPIkRWp/91aDKZwvMxoAg1lBbx or8A== X-Gm-Message-State: AOJu0Yy9o9q0RwvJG2/flRsRbVFRFoO83utJKTA5g16nv/SzLIBb/PtM eueyQLKqzOzf/z3vR5JGH9Mcv5gyvkchunJbUmu8ce1Ck/dEHzyUoyBNGae+2swJ3pUydA5pyL/ w X-Gm-Gg: ASbGncvGag2cGDdEJYOFeoehB6d3MPz5zJyUkR2x9K1NXo/Y78huOQKUNj8xgK+q0sq jLxHw1bicu2zyBlGdXZl4uQK4qqkMK0bXtJUV4I2hT1L+6WtbmEgvG99nqd5I2EMg0KjkdadpNx CVInkBSeSpmOdjyb0YOIfQwHRKemCRvL2nKz5+H8Q3yPTx6B6DnEZALklfrpiPjeYvyuNyaZ+ev VNgvxpV/t0ZA7Hx0cj/HylNi5SaTjfOAjOg/z6dpgzVQAdpq20hrZ8SmvBnd58moVCelslb7Dmw TqFOY+7WplhoWR/jHVvV0yOSEvRKKuqfIKDR1ms7eoKmYEaBv9NzAw== X-Received: by 2002:a5d:6da5:0:b0:390:f0f3:1396 with SMTP id ffacd0b85a97d-390f0f3186amr14253434f8f.15.1741102286821; Tue, 04 Mar 2025 07:31:26 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:26 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Dan Carpenter , Heinrich Schuchardt , Yu-Chien Peter Lin , Andrew Goodbody , Jiaxun Yang Subject: [PATCH v3 02/14] arm: add initjmp() Date: Tue, 4 Mar 2025 16:24:50 +0100 Message-ID: <20250304152510.2832340-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Implement initjmp() for Arm. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- arch/Kconfig | 1 + arch/arm/lib/setjmp.S | 11 +++++++++++ arch/arm/lib/setjmp_aarch64.S | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 14111ca14fb..7a3141e92b3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -95,6 +95,7 @@ config ARC config ARM bool "ARM architecture" select HAVE_SETJMP + select HAVE_INITJMP select ARCH_SUPPORTS_LTO select CREATE_ARCH_SYMLINK select HAVE_PRIVATE_LIBGCC if !ARM64 diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S index 2f041aeef01..320ddea85f9 100644 --- a/arch/arm/lib/setjmp.S +++ b/arch/arm/lib/setjmp.S @@ -34,3 +34,14 @@ ENTRY(longjmp) ret lr ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + stm a1, {v1-v8} + /* a2: entry point address, a3: stack top */ + str a3, [a1, #32] /* where setjmp would save sp */ + str a2, [a1, #36] /* where setjmp would save lr */ + mov a1, #0 + ret lr +ENDPROC(initjmp) +.popsection diff --git a/arch/arm/lib/setjmp_aarch64.S b/arch/arm/lib/setjmp_aarch64.S index 1b8d000eb48..074320d25fb 100644 --- a/arch/arm/lib/setjmp_aarch64.S +++ b/arch/arm/lib/setjmp_aarch64.S @@ -39,3 +39,12 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* x1: entry point address, x2: stack top */ + stp x1, x2, [x0,#88] + mov x0, #0 + ret +ENDPROC(initjmp) +.popsection From patchwork Tue Mar 4 15:24:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870107 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313069wrg; Tue, 4 Mar 2025 07:32:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVQjAlM8FBSBC+PjD8KF6rBOGuJXAbLG9z3vu6uzoFNYjOR2wjCtYTpBBI6N2tOEnBldRQUFg==@linaro.org X-Google-Smtp-Source: AGHT+IFKRRZ34QNHucYTA0TZNPE6HBz9kDADkxSdutbntJS05pA5VUqkI6P8dQ8RWz4esph88Xpa X-Received: by 2002:a05:6a21:700b:b0:1f3:21a2:cf4a with SMTP id adf61e73a8af0-1f321a2ee2amr17783407637.40.1741102343338; Tue, 04 Mar 2025 07:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102343; cv=none; d=google.com; s=arc-20240605; b=DXgJrSPjkTvS/Z1o2lZGe4Vgkbz9edbd5WJ9UkHAuM2XO1snUrwXXxC2tbERFiKxvD ctqp+iawMlLhu2TWjsIeKH9MC4d2izA1K73f35xLm5HONntPc3eQz6SxKGOyL5A61P1F K9KJMazW+axYPuPeSZLP56kqHwxe9KCPysLYefmBgWjUj8cG6S1tJRlfY3AGvTorcLtO O/MXfT0Y7qTOQnPbs6GZc8eJ6TJkqCMbmeQXfsML72RP8WI9LRBOcz8+Scdi1sScaFva CHOI9X+XsDdmNIHw9ld6s9TPq3JjPlOCajcVLHdcN4E7cKkRs0PfE+IoEu0Q563eP0hw B5MA== 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=bfoPMUhxDr7WVVhzIFejOsPgoKBM+OEDuQ7e7suLhUg=; fh=j62wFZir5PRwma18sT4D74CqZ/5S535HAImprwjz4yM=; b=EPvWB8cFBpLN+xYZIR8TupqUSv0w+/5RS3IKWxVTQKWNR0WIVK9M1eZkJGX2sWYvtX bZXT0HeZXtsMlcG0w+ZLweP8I5LozxXjwwKLP+CaF3ogwcrCBabxK5i9D7hyHo4lKu8E VGvJUzG1dPvusQZJSSsJjz9Od7tj/A7O6suUmsi2FWijeZDJjshYzUSFSNkJX+5nde/p w21MThU7ZN0cPpK/cTwqAR+l02/DFy3Py1thBs9qsQogEkoaPvG+fp2KpDaMab/jJfob ZaeY7dCbEIMnwDQJrkS7gcxdtHzV+njt6R2rq+EFmMRaNmvTdwANW3iOsAhZEbSLcj0g NIFQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gv74MB6U; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id 41be03b00d2f7-aee7de22a93si18387575a12.210.2025.03.04.07.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:32:23 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Gv74MB6U; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 59B6D812BB; Tue, 4 Mar 2025 16:32:08 +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="Gv74MB6U"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B2D36811B3; Tue, 4 Mar 2025 16:32:06 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 AD55E80842 for ; Tue, 4 Mar 2025 16:32:04 +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-x32b.google.com with SMTP id 5b1f17b1804b1-43bbb440520so27250695e9.2 for ; Tue, 04 Mar 2025 07:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102288; x=1741707088; 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=bfoPMUhxDr7WVVhzIFejOsPgoKBM+OEDuQ7e7suLhUg=; b=Gv74MB6UN+fRVXGH671QPFO7hHvEyQPvJxU7RwLhTRKZPczaj+CxaHSa6DkgqQW1X7 tP/AfGtCjDEUL9GGlQsp7Fwj+C5XA0SZWwkwB2EGScQlZGN9jo/URKGr+gOJhK1RpQHP jF+0t8rc9HR86aQjaKpcv3DnT9cSeLVfyg4PN2BOgRM49kziYKv9lM2T6rek9mXfdkAr 4PVT1jksf7B/PlzSU8EJKhitzv7NO39xp2wNHOYjLd8RJY6BFOPsoCjKgQuSNXyh4sQu IO5s32t9abRymYZf7aJd5ySKD8+5AE1Vu5qVkNaIOxVa+EvUQA4UXG1i4Ma8B4j3wWe+ I56A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102288; x=1741707088; 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=bfoPMUhxDr7WVVhzIFejOsPgoKBM+OEDuQ7e7suLhUg=; b=lr43KGYI3cFMeq4T0RYXNiHNJyU1YBNb7T1iIA62B6J+OwjS30cbbvFzYbJouPQL7P x6sIKdzPh1q4CnLj1jUqVq4jrZuQwMvBP7yOkqjtUxOZg7gB7i2LVXM04eLPFQtWxz1x 5fpkmg25++a/MSZcWmRml4d+q0Ae7qSOu4tyJ2wuDPElFqHlmCTlQ8cJZCWE8zNuKq4s t2RtKSahBdDHEM40lMai/QwVXlJoe4KVv2R+MElREwmwxfGjN0wMMgFQDAHqYdJcu1rX K72v375uYSzQQ2F1TvvSHpV+ItaC6D446sE+vZTExbRIF1E8O3gQtx/fjsEtLXzcUaNd 6YBA== X-Gm-Message-State: AOJu0YwTS8AFVVU/eKGyDQI2gjYJw4/NC0anG5UJvgIvn8LPIQqZY4LC 7g24sMGtJ3e0x7AqQWw101defkyzTQYhcIJ19Om7kDvHm7Li/Rf756PE9pa64ECsthI47ZLwoZy O X-Gm-Gg: ASbGncsaL6/wMGmK22aqtKWwf3ov8gNBGleS61cm30A3FJm9gNRBhlAUJMH2SceDIv8 iTVTdPJ36NCdxTiWj8XiJlH4i9iRW+mS2erwAj2/9jbO9fWj3sT3yrezfRZ7X01x022CHDPtyos rTcmRNdgxjgW4hc3189CkElu3/g2FqK4PyXAqQ9w/jgX5jzAPGjrmVA++rrzSsISt/TUB93pbzE jODwQNxHLWlB5so5eRGgVuQaiOndwQcgaueUiaZU9L/UbzdSXWSMlr5BojmiODHR0wXafqUDDha +kaql5J54EnMKuEJaQVYXP2HyI6hPnWNAmHPqIOAmGYUKfaR180FCQ== X-Received: by 2002:a05:600c:3513:b0:439:9b39:b31 with SMTP id 5b1f17b1804b1-43ba66e5f2fmr188931145e9.8.1741102288163; Tue, 04 Mar 2025 07:31:28 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:27 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Rick Chen , Leo , Dan Carpenter , Heinrich Schuchardt , Simon Glass , Jiaxun Yang , Andrew Goodbody , Yu-Chien Peter Lin Subject: [PATCH v3 03/14] riscv: add initjmp() Date: Tue, 4 Mar 2025 16:24:51 +0100 Message-ID: <20250304152510.2832340-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Implement initjmp() for RISC-V. Signed-off-by: Jerome Forissier --- arch/Kconfig | 1 + arch/riscv/lib/setjmp.S | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 7a3141e92b3..aa60c5ff03c 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -153,6 +153,7 @@ config RISCV bool "RISC-V architecture" select CREATE_ARCH_SYMLINK select HAVE_SETJMP + select HAVE_INITJMP select SUPPORT_ACPI select SUPPORT_LITTLE_ENDIAN select SUPPORT_OF_CONTROL diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S index 99d6195827e..6f952a16eee 100644 --- a/arch/riscv/lib/setjmp.S +++ b/arch/riscv/lib/setjmp.S @@ -59,3 +59,13 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* a1: entry point address, a2: stack top */ + STORE_IDX(a1, 12) + STORE_IDX(a2, 13) + li a0, 0 + ret +ENDPROC(initjmp) +.popsection From patchwork Tue Mar 4 15:24:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870109 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313300wrg; Tue, 4 Mar 2025 07:32:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWc31ShklT6U0vcVN0eU3h2yNa6SgZqpTBv+XN9Irtnr+TJKlgSNrGro0tO0DNvo854XJu3eg==@linaro.org X-Google-Smtp-Source: AGHT+IFbg2ad7LZstIV5h41Hav5fx8norqQRwP+5SGHFAyjJneXczzozyIZ6S4zlIWFdINLA82jX X-Received: by 2002:a05:6a21:9988:b0:1ee:c89e:1db1 with SMTP id adf61e73a8af0-1f2f4d22408mr27904372637.25.1741102366633; Tue, 04 Mar 2025 07:32:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102366; cv=none; d=google.com; s=arc-20240605; b=d1TrzUgXyM0VCVIpaww/QbdOLgidfqWU18HaqCYGmCXYBDWDnvICqzdm3vIfw9IY+3 bYlsm0PwK9xsB056SoD0bfxuKJHy5N0hgNL8k8pRxgImjOlVSHmB580jlrrkJrHUeMEj HnkRX1MHShh6jEPHFGqn4/u315GNc+dHRs9MSwUhN8MbuK1e4pjBJL86GLaZ14vlofeG k5fJ6yKFHtRt44Uabs1badiFqdjRt5A4dpqrr6yHsfaCKYIu4ReI0T5AESmfKHoD+1Fg kjPHzdehJSy8VJjOgLVczYe2V18yl25xd9zRxXp4rlReqPmiEuvUaCnFraVAeYa//X3i az1g== 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=YFDmGzMpKY+29gEM4ZJhgVMoSZNmh5jXaS5z7DuspBk=; fh=HaKHCOHL46OAAPpM3W6HDLkDmJxXWc+qggc/xnkS9u8=; b=iSGWsE8foKJ+S4T0ym6stfUsiNM1U4CM4w5tj8Ch1bzwAFWcN6on9IwCwCCWXh60bO 5YP6KtsiB+Ktrm2A5/m70oZJDeg35+rkTEaY50GiC5QPKC2M5VBNvmE0wycVQk9rTPo0 r6Ud2e8/hVxfQBgQdo4N5zwCweqV8rkPgjr+lnOd8AM/ZqqNvYg7vPxMRYOeRvECF3hw BHujElPYFvZDE0jCQG7+Dfq4V8ou6xpZ0LuSqLxknmwqbIWChyxUcx+PSPVUvOC7KSsT 7GFi9VqQkSXed1jCqZZ5PMiQ/p1V2ZamsWnr/c3s2wvlB31aGWPpesG+1KEMJtShxTq4 Gu5w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqwrSHac; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id 41be03b00d2f7-af18cdf5a62si12392458a12.403.2025.03.04.07.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:32:46 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hqwrSHac; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 EBF51812D8; Tue, 4 Mar 2025 16:32:10 +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="hqwrSHac"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3FDCC80F96; Tue, 4 Mar 2025 16:32:09 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (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 9AD6E800C1 for ; Tue, 4 Mar 2025 16:32:06 +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-wr1-x42f.google.com with SMTP id ffacd0b85a97d-390df0138beso3044238f8f.0 for ; Tue, 04 Mar 2025 07:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102290; x=1741707090; 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=YFDmGzMpKY+29gEM4ZJhgVMoSZNmh5jXaS5z7DuspBk=; b=hqwrSHacuGnU84kFa6VLmfqxrlrTNbMMCsaXVfoPBjg9SjJiZ9SDPxkiID6BjwzLBz u8nzsfnGQMM9e04swLeOPxp7Md+QBV8nZfdZJ3zP8iEXz0Z4p8tmlbRtGvu8WeBYJzN/ 2u6gpYfAAxhXc+NKQYSRTh3CvpOrO74/sv3PGTW/bERKLtgeFuVvQY5fVdDxr1Jgj9Z+ 9kTOfpgrRv5R6LQH7k6+koqTXErhXtXbD7kpJ5DZoa7RozTLYMhCAaitPzum64e3fZR6 MN3wB6A2q8bot1CNN6qwQ5TQRh4vyRs4LYcWpGZWtx+ADFJlxPfgwdzwX8gmbLodsJf0 jFcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102290; x=1741707090; 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=YFDmGzMpKY+29gEM4ZJhgVMoSZNmh5jXaS5z7DuspBk=; b=CSIPWBBiamQSI+qQvUBuD+UmOvvx7jZq0HzBd2W42LSc7hTi9dWLJx3S3MWVdkjjRy lp4WHO0Cn4Q4ZN+6/j2SDAQ3byUS7bmFapRWzDYvl568byhd0GL6W4cLoClHBshzUUip 7vBa595Ck9WqnCAnHVX0WQyY0l94EZzCNb3rhnGvnoRraPbYaEnUoVV9PXlNk1CUiK8W Y+bSAIdwzZrtE8+FZFRlWUlEXzXwjlusWVd/CteSF8wQ0DBXYqrCOYFGQpswFInrc/y/ NmJxDCSONxJpWyYnJl7/QFqMIMvhpVpyF+62n03bE5ztOyb5Se3895PCpm1MHCk1+PuJ 4TWg== X-Gm-Message-State: AOJu0YwDdBZ0UbYvKDqUJvPMXAymPcmcd4CD8ciHhxArMbZMBXzvmMKe qBXcs+XNVl9fIt7bFhIGEOQaYqq8kWa3hGQ/YrVbJi2APugVAPsBmke8wIY9PKEzP8sQcLfYhO4 s X-Gm-Gg: ASbGncuJFWETrQJ316tWCfKFuTqxRL4Yuk8zm11DMPlJljkemlozwmcTwkBjjVJG/bL +y6U8ID3MNhQvOzQODHP23vE4zVQnfUfc/vAgTjb74ZcC+C9mUnU2Twp7zlW++fS8hrWzvL7nqh 0ylDK5jUuNyzqBJGRzEwTqu+/3KWKz5CFZgfF+VE2VSwWeJVVvjE2ZIhb3EIYda6nc0XYCyluh7 c/L9yDJVrCeMYyBg4ewerLcl3iShi3Eea5nT7CGcsrTMuBbCXo3GcBJiuXufgvI5VsQsdJs12rR W1M3OQPPiJkccc+a7YprQK/TTnuPMZALqQ0CDglAqAUah3EGtyg62w== X-Received: by 2002:a5d:5f81:0:b0:390:f607:9656 with SMTP id ffacd0b85a97d-390f60796f9mr12520106f8f.34.1741102289752; Tue, 04 Mar 2025 07:31:29 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:29 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Simon Glass , Tom Rini Subject: [PATCH v3 04/14] sandbox: add initjmp() Date: Tue, 4 Mar 2025 16:24:52 +0100 Message-ID: <20250304152510.2832340-5-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Add ininijmp() to sandbox. The implementation is taken verbatim from barebox [1]. It is quite complex because contrary to U-Boot platform code we don't know how the system's C library implements the jump buffer, so we can't just write the function and stack pointers into it. FIXME: this patch should make SANDBOX select HAVE_INITJMP (in arch/Kconfig). It does not due to the following error detected by CI: _________________________ test_ut[ut_lib_lib_initjmp] __________________________ test/py/tests/test_ut.py:608: in test_ut output = u_boot_console.run_command('ut ' + ut_subtest) test/py/u_boot_console_base.py:334: in run_command m = self.p.expect([self.prompt_compiled] + self.bad_patterns) test/py/u_boot_spawn.py:296: in expect c = self.receive(1024) test/py/u_boot_spawn.py:235: in receive raise err test/py/u_boot_spawn.py:227: in receive c = os.read(self.fd, num_bytes).decode(errors='replace') E OSError: [Errno 5] Input/output error ----------------------------- Captured stdout call ----------------------------- => ut lib lib_initjmp Test: lib_initjmp: initjmp.c Failures: 0 common/dlmalloc.c:796: do_check_free_chunk: Assertion `next == top || inuse(next)' failed.common/dlmalloc.c:796: do_check_free_chunk: Assertion `next == top || inuse(next)' failed. ---------------- generated xml file: /tmp/sandbox64/results.xml ---------------- On x86 the dmalloc error is not printed but the I/O error is still there. [1] https://github.com/barebox/barebox/blob/b2a15c383ddc/arch/sandbox/os/setjmp.c Signed-off-by: Jerome Forissier --- arch/sandbox/cpu/Makefile | 11 ++- arch/sandbox/cpu/initjmp.c | 172 +++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/cpu/initjmp.c diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile index bfcdc335d32..038ad78accc 100644 --- a/arch/sandbox/cpu/Makefile +++ b/arch/sandbox/cpu/Makefile @@ -5,7 +5,7 @@ # (C) Copyright 2000-2003 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. -obj-y := cache.o cpu.o state.o +obj-y := cache.o cpu.o state.o initjmp.o extra-y := start.o os.o extra-$(CONFIG_SANDBOX_SDL) += sdl.o obj-$(CONFIG_XPL_BUILD) += spl.o @@ -29,6 +29,15 @@ cmd_cc_eth-raw-os.o = $(CC) $(filter-out -nostdinc, \ $(obj)/eth-raw-os.o: $(src)/eth-raw-os.c FORCE $(call if_changed_dep,cc_eth-raw-os.o) +# initjmp.c is build in the system environment, so needs standard includes +# CFLAGS_REMOVE_initjmp.o cannot be used to drop header include path +quiet_cmd_cc_initjmp.o = CC $(quiet_modtag) $@ +cmd_cc_initjmp.o = $(CC) $(filter-out -nostdinc, \ + $(patsubst -I%,-idirafter%,$(c_flags))) -c -o $@ $< + +$(obj)/initjmp.o: $(src)/initjmp.c FORCE + $(call if_changed_dep,cc_initjmp.o) + # sdl.c fails to build with -fshort-wchar using musl cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \ $(patsubst -I%,-idirafter%,$(c_flags))) -fno-lto -c -o $@ $< diff --git a/arch/sandbox/cpu/initjmp.c b/arch/sandbox/cpu/initjmp.c new file mode 100644 index 00000000000..c99721423c5 --- /dev/null +++ b/arch/sandbox/cpu/initjmp.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * An implementation of initjmp() in C, that plays well with the system's + * setjmp() and longjmp() functions. + * Taken verbatim from arch/sandbox/os/setjmp.c in the barebox project. + * + * Copyright (C) 2006 Anthony Liguori + * Copyright (C) 2011 Kevin Wolf + * Copyright (C) 2012 Alex Barcelo + * Copyright (C) 2021 Ahmad Fatoum, Pengutronix + * This file is partly based on pth_mctx.c, from the GNU Portable Threads + * Copyright (c) 1999-2006 Ralf S. Engelschall + */ + +/* XXX Is there a nicer way to disable glibc's stack check for longjmp? */ +#ifdef _FORTIFY_SOURCE +#undef _FORTIFY_SOURCE +#endif + +#include +#include +#include +#include +#include + +typedef sigjmp_buf _jmp_buf __attribute__((aligned((16)))); +_Static_assert(sizeof(_jmp_buf) <= 512, "sigjmp_buf size exceeds expectation"); + +/* + * Information for the signal handler (trampoline) + */ +static struct { + _jmp_buf *reenter; + void (*entry)(void); + volatile sig_atomic_t called; +} tr_state; + +/* + * "boot" function + * This is what starts the coroutine, is called from the trampoline + * (from the signal handler when it is not signal handling, read ahead + * for more information). + */ +static void __attribute__((noinline, noreturn)) +coroutine_bootstrap(void (*entry)(void)) +{ + for (;;) + entry(); +} + +/* + * This is used as the signal handler. This is called with the brand new stack + * (thanks to sigaltstack). We have to return, given that this is a signal + * handler and the sigmask and some other things are changed. + */ +static void coroutine_trampoline(int signal) +{ + /* Get the thread specific information */ + tr_state.called = 1; + + /* + * Here we have to do a bit of a ping pong between the caller, given that + * this is a signal handler and we have to do a return "soon". Then the + * caller can reestablish everything and do a siglongjmp here again. + */ + if (!sigsetjmp(*tr_state.reenter, 0)) { + return; + } + + /* + * Ok, the caller has siglongjmp'ed back to us, so now prepare + * us for the real machine state switching. We have to jump + * into another function here to get a new stack context for + * the auto variables (which have to be auto-variables + * because the start of the thread happens later). Else with + * PIC (i.e. Position Independent Code which is used when PTH + * is built as a shared library) most platforms would + * horrible core dump as experience showed. + */ + coroutine_bootstrap(tr_state.entry); +} + +int __attribute__((weak)) initjmp(_jmp_buf jmp, void (*func)(void), void *stack_top) +{ + struct sigaction sa; + struct sigaction osa; + stack_t ss; + stack_t oss; + sigset_t sigs; + sigset_t osigs; + + /* The way to manipulate stack is with the sigaltstack function. We + * prepare a stack, with it delivering a signal to ourselves and then + * put sigsetjmp/siglongjmp where needed. + * This has been done keeping coroutine-ucontext (from the QEMU project) + * as a model and with the pth ideas (GNU Portable Threads). + * See coroutine-ucontext for the basics of the coroutines and see + * pth_mctx.c (from the pth project) for the + * sigaltstack way of manipulating stacks. + */ + + tr_state.entry = func; + tr_state.reenter = (void *)jmp; + + /* + * Preserve the SIGUSR2 signal state, block SIGUSR2, + * and establish our signal handler. The signal will + * later transfer control onto the signal stack. + */ + sigemptyset(&sigs); + sigaddset(&sigs, SIGUSR2); + pthread_sigmask(SIG_BLOCK, &sigs, &osigs); + sa.sa_handler = coroutine_trampoline; + sigfillset(&sa.sa_mask); + sa.sa_flags = SA_ONSTACK; + if (sigaction(SIGUSR2, &sa, &osa) != 0) { + return -1; + } + + /* + * Set the new stack. + */ + ss.ss_sp = stack_top - CONFIG_STACK_SIZE; + ss.ss_size = CONFIG_STACK_SIZE; + ss.ss_flags = 0; + if (sigaltstack(&ss, &oss) < 0) { + return -1; + } + + /* + * Now transfer control onto the signal stack and set it up. + * It will return immediately via "return" after the sigsetjmp() + * was performed. Be careful here with race conditions. The + * signal can be delivered the first time sigsuspend() is + * called. + */ + tr_state.called = 0; + pthread_kill(pthread_self(), SIGUSR2); + sigfillset(&sigs); + sigdelset(&sigs, SIGUSR2); + while (!tr_state.called) { + sigsuspend(&sigs); + } + + /* + * Inform the system that we are back off the signal stack by + * removing the alternative signal stack. Be careful here: It + * first has to be disabled, before it can be removed. + */ + sigaltstack(NULL, &ss); + ss.ss_flags = SS_DISABLE; + if (sigaltstack(&ss, NULL) < 0) { + return -1; + } + sigaltstack(NULL, &ss); + if (!(oss.ss_flags & SS_DISABLE)) { + sigaltstack(&oss, NULL); + } + + /* + * Restore the old SIGUSR2 signal handler and mask + */ + sigaction(SIGUSR2, &osa, NULL); + pthread_sigmask(SIG_SETMASK, &osigs, NULL); + + /* + * jmp can now be used to enter the trampoline again, but not as a + * signal handler. Instead it's longjmp'd to directly. + */ + return 0; +} + From patchwork Tue Mar 4 15:24:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870112 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313679wrg; Tue, 4 Mar 2025 07:33:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVxzEk/KaxhPEPEftncPOtOi4YSv3CIo/fQSDWmx4YSigaccg4dLeD9shEZ7SWnF15H1+zhEg==@linaro.org X-Google-Smtp-Source: AGHT+IGYRNLbzd6zYFemdLIv7R48xQCcYDdfuPTaSrMhDjnp9/AtZbcgcXD4C0Uiu3k03N6/YXiN X-Received: by 2002:a05:6a00:2e23:b0:736:4cde:5c0e with SMTP id d2e1a72fcca58-7364cde5ec6mr13011036b3a.10.1741102404318; Tue, 04 Mar 2025 07:33:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102404; cv=none; d=google.com; s=arc-20240605; b=WDd4opQ2Aw+DsipxrETxYbPgDmUI3UvG01G4cY9sC8BzBZ8wS0BZKvS4O9YP0do6J7 JpTmQf5oWv0slhLWklD0CW/xxa0+sg1LJ9H+EHyZOdfFUin8i/Y+SSP06LifKn9N4wNc rMRFZLA8hXfE/PeHIOc5wWvZ5MwqdHkfG1/uespfUI4xWM4eV98FrSxWmf82ofxdMbPd CeA/2YyHzeEvB3P8R6hf2uVFzoryElBoYgbj+tUGUeZTPsPnGyMy/VIv5R1YZaF6H0U5 Afe6XikK/MNjjrehSV0gZj9M3wZTBkvnU5VlXwbT2t+PZWYYvUFEPWWOBjSJxJaoZhk+ z9qQ== 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=lZ+vMlEvS8LCYmC7HjtNZdw2xmcTzhjatEcHVTOwFrU=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=JH1Bw3ijH/aFkhMIqG+MmFPIY36T6tjFOBZWuVyxQVk7f7X+V0G9ldsTguJUT6NHgz 97EM3RiJMmJtQVMcj/XlS6QHXkXI/V2+SqFj8dh3yKo6fTFidrZ7+twBZiFyImAfeo2n rr9bxuMlAL/eGeUnfgqmEwLgJ2Hn929hDJ7b4SPZ6gfMfbuRXBswJrikb0Q43GC0606T GVJYNG0Mg2bmLJ4wySiWpQ6RJxbIkHsEcAgb9fd98nITN/eQKHPA8n/6QRPJfmFoC+CE 1QF1r8ArfyhqlVPHBTPR4Bg/TnzFzwm6aXFJxATEZxCt8QGRezQDyBxysVR7/UPfd/t5 yBZg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YFmjfDdK; 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 41be03b00d2f7-aee7deaa67esi18278663a12.269.2025.03.04.07.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:33:24 -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=YFmjfDdK; 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 D5AC7810ED; Tue, 4 Mar 2025 16:32:13 +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="YFmjfDdK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DBE13811B3; Tue, 4 Mar 2025 16:32:11 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 256568128D for ; Tue, 4 Mar 2025 16:32:08 +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-wr1-x42e.google.com with SMTP id ffacd0b85a97d-390f69e71c8so2491680f8f.0 for ; Tue, 04 Mar 2025 07:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102291; x=1741707091; 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=lZ+vMlEvS8LCYmC7HjtNZdw2xmcTzhjatEcHVTOwFrU=; b=YFmjfDdKfqq0uyJXd0wokEDMt86H8dwHOv8l3Y3tq3a1bACcaBewKeQU5X61FVlDXs 6pQ9xuaNwfqBiZ2TZyX+p4wE7J694dXNUiKuOVU0W2+mlNaKwmXdUszPjsfR/wtDR+9L gUH3IaZjX+Ja8HqMBVO32dmqeODIYBL2gl3BnMkjq2J9I65IP+GbGcqnNKDLgCX3wa1m cy8r8BED+mCfbAE9EcwLcHfLJUwsp1TrBIQu0p+LfryWO/v/7kaU4GwcWvV+x9KQbAG/ rHBFnLk6cGvg5Wvtg1B6qO+w9/h66ngraMG+0hwjcgPj8J26PjsuF60X17zudE+j9Twj zznw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102291; x=1741707091; 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=lZ+vMlEvS8LCYmC7HjtNZdw2xmcTzhjatEcHVTOwFrU=; b=lb7YxjZZcUBOdSRcOipVR/+WehUqm/ld6ZuOtescSZ/A+TQgRLTz4sIMvom6wozQx+ +/yUKy4alhpwZH52/+El+ZZmFiOQmLklEiFuE8QMh6NlNoV7Yfl0hDuisSY1Svl40bM9 CWcAiW9C+HOpichevqqktYVHQAJY89mBv+ueqcQ/SXhwz8bJNwQDf/F+21RvyVM4OXQL IApNgkhsIGYqeVsxyMsIYgO7YfTXdNiTvaVnzxQxXlasbInl5p3rDeDyN6X9e4CbDbna jeOxFxYO1Wehs5QHcIMIVrVbMpy9rn8x4Uuk1zyBMPDnj6SR1OrQGFEbdPskdox5Icer hNXQ== X-Gm-Message-State: AOJu0YzkWvLp/hJYmhAgAP55s1HFaQDhCqURVB+rC6zGTzz6EPKBGgZM kBoyr+diPGSt6ByTErt8hfAeYaNYEOL6MI1xxm1VVaac3katkGKN+1sLkmVtIddzBZBGZdtAfIH E X-Gm-Gg: ASbGncumr5FBF4h9DfX+O2TNbhstdvJJvJvdZZ587TrtH9vvqvMBfqNoGlGpkeh0dQW 99Yq/jT0JrPPuQn0wDV1UNcyDfh97iRjFFqrcNdiHJk0ngiTzOqpGOtfqH/JEG0ADvKeOG0aDRZ WURTRuQVVRSHTujyi6oa630XnlSK4/JBxmutM/5JJjBX8jh/Vt/jvBMgURFoW2QsnhacyQjyhUS G5vvRZ6YLZiokYw45CQ8wGQ39Gm4V4mq4DTUl0ci+gm6Tc5yDsGtsHF3oCdauP1XoLVZ884CBEl X3ho9JwZw+WTjwzLcyo4JuHKg8x35AerXKl12m6R0ASLzcGszaqH2g== X-Received: by 2002:a5d:47af:0:b0:390:df83:1f22 with SMTP id ffacd0b85a97d-39115627f82mr3511321f8f.25.1741102291408; Tue, 04 Mar 2025 07:31:31 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:31 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Raymond Mao , Philippe Reynes Subject: [PATCH v3 05/14] test: lib: add initjmp() test Date: Tue, 4 Mar 2025 16:24:53 +0100 Message-ID: <20250304152510.2832340-6-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Test the initjmp() function when HAVE_INITJMP is set. Use the test as an example in the API documentation. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- doc/api/setjmp.rst | 10 +++++++ test/lib/Makefile | 1 + test/lib/initjmp.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 test/lib/initjmp.c diff --git a/doc/api/setjmp.rst b/doc/api/setjmp.rst index 7718047085c..c48b2e3e096 100644 --- a/doc/api/setjmp.rst +++ b/doc/api/setjmp.rst @@ -8,3 +8,13 @@ Long jump API .. kernel-doc:: include/setjmp.h :internal: + +Example +------- + +Here is an example showing how to use the a long jump functions and +initjmp() in particular: + +.. literalinclude:: ../../test/lib/initjmp.c + :language: c + :linenos: diff --git a/test/lib/Makefile b/test/lib/Makefile index 0e4cb8e3dfd..bf04685dae1 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -14,6 +14,7 @@ obj-y += hexdump.o obj-$(CONFIG_SANDBOX) += kconfig.o obj-y += lmb.o obj-$(CONFIG_HAVE_SETJMP) += longjmp.o +obj-$(CONFIG_HAVE_INITJMP) += initjmp.o obj-$(CONFIG_CONSOLE_RECORD) += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-$(CONFIG_$(PHASE_)STRTO) += str.o diff --git a/test/lib/initjmp.c b/test/lib/initjmp.c new file mode 100644 index 00000000000..3f11c5b42de --- /dev/null +++ b/test/lib/initjmp.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright 2025 Linaro Limited + * + * Unit test for initjmp() + */ + +#include +#include +#include +#include +#include +#include + +static bool ep_entered; +static jmp_buf return_buf; + +static void __noreturn entrypoint(void) +{ + ep_entered = true; + + /* Jump back to the main routine */ + longjmp(return_buf, 1); + + /* Not reached */ + panic("longjmp failed\n"); +} + +static int lib_initjmp(struct unit_test_state *uts) +{ + int ret; + void *stack; + jmp_buf buf; + int stack_sz = 1024; + + ep_entered = false; + + stack = malloc(stack_sz); + ut_assertnonnull(stack); + + ut_assert(!ep_entered); + + /* + * Prepare return_buf so that entrypoint may jump back just after the + * if() + */ + if (!setjmp(return_buf)) { + /* return_buf initialized, entrypoint not yet called */ + + /* + * Prepare another jump buffer to jump into entrypoint with the + * given stack + */ + ret = initjmp(buf, entrypoint, stack + stack_sz); + ut_assertok(ret); + + /* Jump into entrypoint */ + longjmp(buf, 1); + /* + * Not reached since entrypoint is expected to branch after + * the if() + */ + ut_assert(false); + } + + ut_assert(ep_entered); + + free(stack); + + return 0; +} +LIB_TEST(lib_initjmp, 0); From patchwork Tue Mar 4 15:24:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870116 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp314160wrg; Tue, 4 Mar 2025 07:34:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUOcS86x8ZXR/4rX2Uf8SUxqDsatsrGzMNlo4Rp6BBI7VPNBMbIVzaP6KTcQxyy7xxSg4c5PQ==@linaro.org X-Google-Smtp-Source: AGHT+IHgjUxbUkuR7GZiiXsakjEFkjSqblnNfjkXOJwXGlilf6qgQFhTPwfvmS6lEAbG3D/I6MJ+ X-Received: by 2002:a05:6e02:3893:b0:3d2:c9e0:de42 with SMTP id e9e14a558f8ab-3d3e6e74babmr178834695ab.7.1741102455762; Tue, 04 Mar 2025 07:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102455; cv=none; d=google.com; s=arc-20240605; b=IrVnRm46ZQarhW22LayFloTclfe2fMA6Cz/8TlXjcCRUNC9+rAolkgQ+VreDrutCX+ BJW9b38pS46OPDFyR7if4erh7B3QwMy8BZapJJneD84Oi2b9SLFrC9l68/rXr1vXkM28 MGNWUkI/oeixTGvG/cqtXcmJVM1rdoAYwd2WclsDEVj30T/e8Etgq2s7vFIeN7qIGRFk X1G4pf59QGIrlGoAbqJJZ7O1mlDB0s3LC5VhKbAYXMSNP+LrNlwr7K/nF7rFAzpwk6y/ EXw0Nz34KX6OC4UkeXrhJjW/oL3iRHEUNhAH/lvjW89UldwWEMlKEo8boVRtRRiipVUZ 9PTw== 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=y5+FHnnKlOsm/zGfnc1QpeuPrzdz/XlW9L07/HBqKxg=; fh=WQZowlqeSpAW84E5XszMsMqfBER27bVv7qnGxOI6gzg=; b=hnMK8zPtmaLp7sZrHU5HKC/Hmoo0N+powg5jUGWEt66Dk3KFG8kcZj124ZHOE3iVfb J/N8+hu2+BHn+d+PWdQAgIVLbYBjPKltijKzWkYRcVbFXAlxvuzbuMiZRfbzBB3vyNjX kuTkbemLekDtV22fnLCoC9aEc+wXMWLEYt6mRSrRQ7XuVHX0Y6qs8ct96NWXE35HqGcq 490DHjQgpYhDXSCljDr5bx00PwqJlBJ64JYElpIGyqyBlWVndJMww1WAPk6Q/Rw079I8 P/0znKKSrqTkATclXR7zUfFtDYRSVxFmjiGKoFM5C3boFFg/J1TnYh5CCwkQBptnhITJ 4lEw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=frS0SB5X; 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 e9e14a558f8ab-3d3dee5dcffsi93858955ab.16.2025.03.04.07.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:34:15 -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=frS0SB5X; 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 0923F814A4; Tue, 4 Mar 2025 16:32:16 +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="frS0SB5X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF955811B3; Tue, 4 Mar 2025 16:32:13 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 705B180F56 for ; Tue, 4 Mar 2025 16:32:10 +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-x32d.google.com with SMTP id 5b1f17b1804b1-43bcc02ca41so7917765e9.0 for ; Tue, 04 Mar 2025 07:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102294; x=1741707094; 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=y5+FHnnKlOsm/zGfnc1QpeuPrzdz/XlW9L07/HBqKxg=; b=frS0SB5X1xOxxhqk5uxiQgmErVfsXlja0EWVsXSaIRZyOt10axj197Q6mGWv09XuwZ S39YQvya+f1+L80jSfcoHoeIW5hL/sjhyvmMBTsKUacx2+Fi9xHsK90rM9iJBtUEpd22 rqXPsxTD9z/GdQTnck41mst3HUF6P9uGCUPYfQ0Q8XCtWz8VLh36k40CzFwvhdylt5rF 4ER9On0KC+3YHTvza2fTESr1g+HGSnPmx6ZzQQPQKoUdjCk3eZIx5ShXhIHBQ9MTkdHh csHjAUubj6ncRu8Gnz+Vq6ne1AiyCpWYD+h74CZo0pUOvkqv3Mn5o2G26fwB/QAgBXd2 SOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102294; x=1741707094; 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=y5+FHnnKlOsm/zGfnc1QpeuPrzdz/XlW9L07/HBqKxg=; b=wGyQGbm31GTbGb9SZD81VSrVXt8A3C1YB4sN3/WEB8TZ81spjIHJPsAGOVITyR3+Df jqeXizGOjxkekftQ1JAs21wWf2bIAskcVZC/spzOT1+s4QQ7QK5MRTSocS/Lwly3nJZ1 xIyXwURTuDSbxSo5clNX+lGHaiQgQ/KTUOnsuYB5wiTT/EPTQjhj2FE/Cw7aA/hJlpBG m1j2TFUnHQUItSNzHK0/+l81I6VFpBjEbY/xXerc/0w6aT6mT6Ktrc+j6p1CQ0K7Y/AX fs34duMZrOMhH8fzRUR3M1iHkF8EpFJSI30IrEjshil/jinA2daZNvV5Azl1yp5L9Jp6 qPLg== X-Gm-Message-State: AOJu0YxGzBQZqLxNn3Vb0KXjPPWekf1Jsyyr/aUPfI+i7H4dE9SITje1 jQpLrXFWZI8BOisP60YI4Qvnnbv6SI59/KnSaOiN7srrAenO9YynXDOAovk1i13PeqUR/3zOUIO d X-Gm-Gg: ASbGncvQxhaw5iVqt+/gVKl004w8KuJa7ZwckZXyvfV+ZCIq8RisRfhfQ/epKhjLMRQ Z3unf9Ej54kGLTBqwc5iHM+JGeV9bunX/Y1OvycWSOH1b9n7SQmjpurcIs2Kr1xHSWXYpfNqfMU PhBGKURuN6QoeTg88dDX4V7ZEtB1TxCDD2uBpb0XlPHT+AzV/4Blcp2j4QTV/AzRPmtrOuJp65D HwYKTE17JafUV5nhvoO9qGzvgF9Z0EpIG93FoEu3K/T4SMKPHVyUg5Oa7rzqsKAxbylMIkE+riZ 0NohcmpnXOu84EzBUMo3p67Bd2K+5aocQhYkjgU8UrMfPlIynVNBew== X-Received: by 2002:a05:600c:1384:b0:439:8bc3:a698 with SMTP id 5b1f17b1804b1-43ba66e5e9bmr145889065e9.6.1741102293911; Tue, 04 Mar 2025 07:31:33 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:33 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Christian Marangi , Vasileios Amoiridis , Simon Glass , Heinrich Schuchardt , Sughosh Ganu , Raymond Mao , Michal Simek , Patrick Rudolph , Philippe Reynes Subject: [PATCH v3 06/14] uthread: add cooperative multi-tasking interface Date: Tue, 4 Mar 2025 16:24:54 +0100 Message-ID: <20250304152510.2832340-7-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Add a new internal API called uthread (Kconfig symbol: UTHREAD) which provides cooperative multi-tasking. The goal is to be able to improve the performance of some parts of U-Boot by overlapping lengthy operations, and also implement background jobs in the U-Boot shell. Each uthread has its own stack allocated on the heap. The default stack size is defined by the UTHREAD_STACK_SIZE symbol and is used when uthread_create() receives zero for the stack_sz argument. The implementation is based on context-switching via initjmp()/setjmp()/ longjmp() and is inspired from barebox threads [1]. A notion of thread group helps with dependencies, such as when a thread needs to block until a number of other threads have returned. The name "uthread" comes from "user-space threads" because the scheduling happens with no help from a higher privileged mode, contrary to more complex models where kernel threads are defined. But the 'u' may as well stand for 'U-Boot' since the bootloader may actually be running at any privilege level and the notion of user vs. kernel may not make much sense in this context. [1] https://github.com/barebox/barebox/blob/master/common/bthread.c Signed-off-by: Jerome Forissier --- doc/api/index.rst | 1 + doc/api/uthread.rst | 7 +++ include/uthread.h | 123 +++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 21 +++++++ lib/Makefile | 2 + lib/uthread.c | 139 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 293 insertions(+) create mode 100644 doc/api/uthread.rst create mode 100644 include/uthread.h create mode 100644 lib/uthread.c diff --git a/doc/api/index.rst b/doc/api/index.rst index 0dc9ad45d41..506843ed74a 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -29,3 +29,4 @@ U-Boot API documentation sysreset timer unicode + uthread diff --git a/doc/api/uthread.rst b/doc/api/uthread.rst new file mode 100644 index 00000000000..21233ff6b22 --- /dev/null +++ b/doc/api/uthread.rst @@ -0,0 +1,7 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Uthread API +=========== + +.. kernel-doc:: include/uthread.h + :internal: diff --git a/include/uthread.h b/include/uthread.h new file mode 100644 index 00000000000..ec3034c097a --- /dev/null +++ b/include/uthread.h @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2025 Linaro Limited + */ + +#include +#include +#include + +#ifndef _UTHREAD_H_ +#define _UTHREAD_H_ + +/** + * DOC: Overview + * + * The uthread framework is a basic task scheduler that allows to run functions + * "in parallel" on a single CPU core. The scheduling is cooperative, not + * preemptive -- meaning that context switches from one task to another task is + * voluntary, via a call to uthread_schedule(). This characteristic makes thread + * synchronization much easier, because a thread cannot be interrupted in the + * middle of a critical section (reading from or writing to shared state, for + * instance). + * + * CONFIG_UTHREAD in lib/Kconfig enables the uthread framework. When disabled, + * the uthread_create() and uthread_schedule() functions may still be used so + * that code differences between uthreads enabled and disabled can be reduced to + * a minimum. + */ + +/** + * struct uthread - a thread object + * + * @fn: thread entry point + * @arg: argument passed to the entry point when the thread is started + * @ctx: context to resume execution of this thread (via longjmp()) + * @stack: initial stack pointer for the thread + * @done: true once @fn has returned, false otherwise + * @grp_id: user-supplied identifier for this thread and possibly others. A + * thread can belong to zero or one group (not more), and a group may contain + * any number of threads. + * @list: link in the global scheduler list + */ +struct uthread { + void (*fn)(void *); + void *arg; + jmp_buf ctx; + void *stack; + bool done; + unsigned int grp_id; + struct list_head list; +}; + +#ifdef CONFIG_UTHREAD + +/** + * uthread_create() - Create a uthread object and make it ready for execution + * + * Threads are automatically deleted when they return from their entry point. + * + * @uthr: a pointer to a user-allocated uthread structure to store information + * about the new thread, or NULL to let the framework allocate and manage its + * own structure. + * @fn: the thread's entry point + * @arg: argument passed to the thread's entry point + * @stack_sz: stack size for the new thread (in bytes). The stack is allocated + * on the heap. + * @grp_id: an optional thread group ID that the new thread should belong to + * (zero for no group) + */ +int uthread_create(struct uthread *uthr, void (*fn)(void *), void *arg, + size_t stack_sz, unsigned int grp_id); +/** + * uthread_schedule() - yield the CPU to the next runnable thread + * + * This function is called either by the main thread or any secondary thread + * (that is, any thread created via uthread_create()) to switch execution to + * the next runnable thread. + * + * Return: true if a thread was scheduled, false if no runnable thread was found + */ +bool uthread_schedule(void); +/** + * uthread_grp_new_id() - return a new ID for a thread group + * + * Return: the new thread group ID + */ +unsigned int uthread_grp_new_id(void); +/** + * uthread_grp_done() - test if all threads in a group are done + * + * @grp_id: the ID of the thread group that should be considered + * Return: false if the group contains at least one runnable thread (i.e., one + * thread which entry point has not returned yet), true otherwise + */ +bool uthread_grp_done(unsigned int grp_id); + +#else + +static inline int uthread_create(struct uthread *uthr, void (*fn)(void *), + void *arg, size_t stack_sz, + unsigned int grp_id) +{ + fn(arg); + return 0; +} + +static inline bool uthread_schedule(void) +{ + return false; +} + +static inline unsigned int uthread_grp_new_id(void) +{ + return 0; +} + +static inline bool uthread_grp_done(unsigned int grp_id) +{ + return true; +} + +#endif /* CONFIG_UTHREAD */ +#endif /* _UTHREAD_H_ */ diff --git a/lib/Kconfig b/lib/Kconfig index 1a683dea670..8321f20e154 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1255,6 +1255,27 @@ config PHANDLE_CHECK_SEQ enable this config option to distinguish them using phandles in fdtdec_get_alias_seq() function. +config UTHREAD + bool "Enable thread support" + depends on HAVE_INITJMP + help + Implement a simple form of cooperative multi-tasking based on + context-switching via initjmp(), setjmp() and longjmp(). The + uthread_ interface enables the main thread of execution to create + one or more secondary threads and schedule them until they all have + returned. At any point a thread may suspend its execution and + schedule another thread, which allows for the efficient multiplexing + of leghthy operations. + +config UTHREAD_STACK_SIZE + int "Default uthread stack size" + depends on UTHREAD + default 32768 + help + The default stack size for uthreads. Each uthread has its own stack. + When the stack_sz argument to uthread_create() is zero then this + value is used. + endmenu source "lib/fwu_updates/Kconfig" diff --git a/lib/Makefile b/lib/Makefile index a7bc2f3134a..3610694de7a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -164,6 +164,8 @@ obj-$(CONFIG_LIB_ELF) += elf.o obj-$(CONFIG_$(PHASE_)SEMIHOSTING) += semihosting.o +obj-$(CONFIG_UTHREAD) += uthread.o + # # Build a fast OID lookup registry from include/linux/oid_registry.h # diff --git a/lib/uthread.c b/lib/uthread.c new file mode 100644 index 00000000000..3cb25784556 --- /dev/null +++ b/lib/uthread.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 Ahmad Fatoum, Pengutronix + * Copyright (C) 2025 Linaro Limited + * + * An implementation of cooperative multi-tasking inspired from barebox threads + * https://github.com/barebox/barebox/blob/master/common/bthread.c + */ + +#include +#include +#include +#include +#include +#include +#include + +static struct uthread main_thread = { + .list = LIST_HEAD_INIT(main_thread.list), +}; + +static struct uthread *current = &main_thread; + +/** + * uthread_trampoline() - Call the current thread's entry point then resume the + * main thread. + * + * This is a helper function which is used as the @func argument to the + * initjmp() function, and ultimately invoked via setjmp(). It does not return + * but instead longjmp()'s back to the main thread. + */ +static void __noreturn uthread_trampoline(void) +{ + struct uthread *curr = current; + + curr->fn(curr->arg); + curr->done = true; + current = &main_thread; + longjmp(current->ctx, 1); + /* Not reached */ + while (true) + ; +} + +/** + * uthread_free() - Free memory used by a uthread object. + */ +static void uthread_free(struct uthread *uthread) +{ + if (!uthread) + return; + free(uthread->stack); + free(uthread); +} + +int uthread_create(struct uthread *uthr, void (*fn)(void *), void *arg, + size_t stack_sz, unsigned int grp_id) +{ + bool user_allocated = false; + + if (!stack_sz) + stack_sz = CONFIG_UTHREAD_STACK_SIZE; + + if (uthr) { + user_allocated = true; + } else { + uthr = calloc(1, sizeof(*uthr)); + if (!uthr) + return -1; + } + + uthr->stack = memalign(16, stack_sz); + if (!uthr->stack) + goto err; + + uthr->fn = fn; + uthr->arg = arg; + uthr->grp_id = grp_id; + + list_add_tail(&uthr->list, ¤t->list); + + initjmp(uthr->ctx, uthread_trampoline, uthr->stack + stack_sz); + + return 0; +err: + if (!user_allocated) + free(uthr); + return -1; +} + +/** + * uthread_resume() - switch execution to a given thread + * + * @uthread: the thread object that should be resumed + */ +static void uthread_resume(struct uthread *uthread) +{ + if (!setjmp(current->ctx)) { + current = uthread; + longjmp(uthread->ctx, 1); + } +} + +bool uthread_schedule(void) +{ + struct uthread *next; + struct uthread *tmp; + + list_for_each_entry_safe(next, tmp, ¤t->list, list) { + if (!next->done) { + uthread_resume(next); + return true; + } else { + /* Found a 'done' thread, free its resources */ + list_del(&next->list); + uthread_free(next); + } + } + return false; +} + +unsigned int uthread_grp_new_id(void) +{ + static unsigned int id = 0; + + return ++id; +} + +bool uthread_grp_done(unsigned int grp_id) +{ + struct uthread *next; + + list_for_each_entry(next, &main_thread.list, list) { + if (next->grp_id == grp_id && !next->done) + return false; + } + + return true; +} From patchwork Tue Mar 4 15:24:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870117 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp314289wrg; Tue, 4 Mar 2025 07:34:28 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV4oFSFyuQtnFpwQvCTJC8ttmcjimqk+cLR/P9EXpcVLDhWq8omcanU/DIdgSJC62iDlZ4ycQ==@linaro.org X-Google-Smtp-Source: AGHT+IE7aoTYGtq9Nl60koAdvMIlM6XMDWSBcuFjLfPVfk1Oga4X2ZgBwwypBsefffYktmr0/8Aw X-Received: by 2002:a05:6a21:339c:b0:1f3:3916:8722 with SMTP id adf61e73a8af0-1f3391688bbmr6993027637.27.1741102468314; Tue, 04 Mar 2025 07:34:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102468; cv=none; d=google.com; s=arc-20240605; b=OYQ/5ffwnnO4cKG/grl4l25icHxjVpvEH/1Pgb+Cii34bjMl7db4gH7hP4nQc2SECu rBeee2CwiaaL9ZopDhBfwxzz2HAuZ+pUMYwRyd8bUxqZ16UdVMyX83MqM+kobIs5UrV7 Pbzo11+c2XYeepQpRTERMLygaMjkHDxVanUxE74RTcayB5gp4fNY74QSrudbarItTqRZ f0vNPQ85Ixqb8uaoFut1H95zKufA6r3IMz424K6jZ3cxJKE8M0Bgo/myo1qNlvvOfy2y KSyruEGU7AR+TVg+KUs9LCYDOcrtG4DapxO6cGOrwjxxleRVy0dQ+Dz5WeowpnR1S7Kl 1jUQ== 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=W/tQpAU9Ufu4oscV00uBWRYXlYx78X3scV+Lb4K1pCw=; fh=FcJrLuOZm3DOgvhNhuu9RcOXf23qDSxE2e4MWRi7Xy0=; b=cRqymv/d3AOXNv7YRbDq47Tl9oMsbSxoRTQS75W0gmHrgbpNFUYSSon4nz4kvjs2+2 JgAvxdOoqeeQwG6jvdjo2OCIYoDrIIppKAcFk8x3fXwxhcbY4zS5r76l483D17BRx1Xj +fJUFqbf6XDDWw1t9oWLIWUvHJwCoHdpHKzaEDuoDng91R89zh8IUYD7BUiWD8bda5ym Qnd8LKtlPEYAaqbOZuckJmRkkQNOTzZL4GrumIDuMXu9hQCJOgq6k3Nr2fyWes47eQSr Bo9J0b0xV5pmv16orqemSGB/25Le3fZtci3P5T2hbJ+aafS3eak81Q7foZxByVwBPgVW hPQQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mwsRpaAO; 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 41be03b00d2f7-af09abcd41fsi13627908a12.292.2025.03.04.07.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:34:28 -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=mwsRpaAO; 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 4FD0E81658; Tue, 4 Mar 2025 16:32:16 +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="mwsRpaAO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CF1EE80F56; Tue, 4 Mar 2025 16:32:13 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 9E28C8141E for ; Tue, 4 Mar 2025 16:32: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=jerome.forissier@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43bc30adad5so15212475e9.1 for ; Tue, 04 Mar 2025 07:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102295; x=1741707095; 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=W/tQpAU9Ufu4oscV00uBWRYXlYx78X3scV+Lb4K1pCw=; b=mwsRpaAOkgDH8ZyXdV4+5tbNnfQPJgNpBhLhh5cB3gXJHdQPZCYmjSU/qYbCgtMM/A b6rFDoD4y4HmttE0to5OUJKXrWrvsoA/UlcLPh6+11po1jiRM2v1+eTGbpPCBoHGnSE9 U0NvCTF60ciEYSm9PqpqVJ7x4Nw3aGMJednIE4BZVx20D3kN5vvn7FCMkdluXIXSsAOG nipOLUhojmvy49Fs5u/6kztJo0sNuqdOCmrYtIPJzspLY7arqy7XoYkqKV5ruJ4nlaZz Vtui1rx0j3fKWfp/qnf49Xquy28F54sYVBISH8JrQlP17SCCMk2wRpkPXjJ8tpu8+ZPK HLTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102295; x=1741707095; 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=W/tQpAU9Ufu4oscV00uBWRYXlYx78X3scV+Lb4K1pCw=; b=Xd37z5scK0LOcs329ylj2RzByJHVGzL/3IjTfUysymlT7CAl2PNqUZBs4rojs7at96 vj/wRZ2IET9HugH83Hek1ZmFiPYl1XsZpJCH9fK/llgvsajIwOBFVL+Z36wi9aZKUwxR L59DE02EMvGxDpnnUjU30xvzLJalTdToprBJDwgddOW84wqtIU94T0NP7/9atyAs5f0y L2Gqwtx2lUWsD5smIF1V5gVy+eo0L1ALKxrrhXCDn0DXoOZH0ppi8Cvm9AtdnVYc+Sdc kp4RHMCzKEznkx3TNaeOVt9GluBCAicu7Xq+Ozyy2smELS+kjaWbivDcsMjEZIDSqJkV kl3Q== X-Gm-Message-State: AOJu0Yyn63dH16BkGk463svK/9h6+rYB3kKAxjkwAn5pLfn8X7QhIC2m 6gNo536DKpltu1aAgxf5LujeeW4fPwJn1abp59F+ebs2rA0bTw2BVVweDFdKyXMaG1gxMA7xCc5 x X-Gm-Gg: ASbGnctBiLTtFreWCNcOx++h7QiLb7CezgcMk2J8heULJ9tdqkkGdLeMdtW5yRrsRlf ir+Tr2eQMPHHf8T+OeBW+CQdc09mYVdQHpQDz6FfRJJPJjbZc2X263s34Opx30r23dZ2FSlDRiD PV5oVtHXXDNbnOD+pug3CUEjbhzRZoqfzn6WR11TvgqEShC3oShigroE+Zw55plr5d9jqEbeHmN ao7A68qUv53QHUen4WdwdFQAG5tb0m91hzYcH8ZeO/2PWR070tNG1QmTWJEPY+C/pj+XW25KXUv Bg2i1cB69vKe1WqDozg2UVaf0faklBKdJ9XcXWjiJoIOYpcyLGbuxw== X-Received: by 2002:a05:600c:5127:b0:43b:c965:954d with SMTP id 5b1f17b1804b1-43bc96595cdmr37986635e9.1.1741102295016; Tue, 04 Mar 2025 07:31:35 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:34 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Stefan Roese , Tom Rini , Rasmus Villemoes , Simon Glass , Patrice Chotard Subject: [PATCH v3 07/14] cyclic: invoke uthread_schedule() from schedule() Date: Tue, 4 Mar 2025 16:24:55 +0100 Message-ID: <20250304152510.2832340-8-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Make the schedule() call from the CYCLIC framework a uthread scheduling point too. This makes sense since schedule() is called from a lot of places where uthread_schedule() needs to be called. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- common/cyclic.c | 3 +++ include/u-boot/schedule.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/common/cyclic.c b/common/cyclic.c index fad071a39c6..b695f092f52 100644 --- a/common/cyclic.c +++ b/common/cyclic.c @@ -16,6 +16,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -100,6 +101,8 @@ void schedule(void) */ if (gd) cyclic_run(); + + uthread_schedule(); } int cyclic_unregister_all(void) diff --git a/include/u-boot/schedule.h b/include/u-boot/schedule.h index 4fd34c41229..4605971fdcb 100644 --- a/include/u-boot/schedule.h +++ b/include/u-boot/schedule.h @@ -3,6 +3,8 @@ #ifndef _U_BOOT_SCHEDULE_H #define _U_BOOT_SCHEDULE_H +#include + #if CONFIG_IS_ENABLED(CYCLIC) /** * schedule() - Schedule all potentially waiting tasks @@ -17,6 +19,7 @@ void schedule(void); static inline void schedule(void) { + uthread_schedule(); } #endif From patchwork Tue Mar 4 15:24:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870106 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp312939wrg; Tue, 4 Mar 2025 07:32:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW0IkvwUDfPUA03mRIG4y7XmScAWne09I9iLBwqymdQhc6jnOu9ZaqZA5avHTfKdVBGpil4xg==@linaro.org X-Google-Smtp-Source: AGHT+IEMem5A+KCbjoapO956DEMx4nnV9LiAv5Q5EqaEFCKwp9I4e1mKDSJJElmVRh9/N0ce+UnG X-Received: by 2002:a17:903:1790:b0:21f:71b4:d2aa with SMTP id d9443c01a7336-22368fa54b4mr332356895ad.5.1741102331523; Tue, 04 Mar 2025 07:32:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102331; cv=none; d=google.com; s=arc-20240605; b=NqtF4XP1YLuLMoINs3a0PJxQqgh7YiWfCCTjQFDG8JNIQQAFT5EGUIKiJ63r/sajBO VzsuPCXir88Ns94pu3iDEMVhaMrJZkFymkYvvTM+GDEelMi9PZ/4xd2ZZISUNIzWTx0r SREJo5ZV4WlfvAezjYpVfRVpClBpASXWgMnwq1pdjY4X9qld+NrtiuQaEm0K2Ur2s8jK hx+YDKd1+GojtjD0RBvkFSLMbkGnESFXGAZ6K9SnrcfOhFutMVlYwBTsSIDO78QcStMP XKSH7gaFHm3+9gpOFYLMA6HbdURU8Y46J+3yuQPuuSgl/Re9ZevXJAEFENFfiI1TdJSs JaLA== 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=TMtdutuo61S5rVB0PvO6Ee5x2fRltLLt3zobQ6X/nRg=; fh=VpzjETxgoCY2MFzw4LRl+jbqj04pA9Y+coUqSDS+oAQ=; b=BFbF7BYQzOICzVw7OIl2Kk+EJ38NsH49+0PwBt9fYi6y0rRqaLjMbGOl3Rb8aK07Jy zuEIcO1MEmXzxTwrCxESQAN+e4glwZtcKqjJLFBUeQfP359WsEiGpP5zv6rZFlYdauos GGuOiIGKT9QxPvmotWZS9hDBdbn3m4JIMrneawI6BO8k4HSLeM9T7HkX85vF+e+1QPcG HEAc/d/H64l0yuli0wwEQ1Y4eK6U7NG2v7zKQDFGz5DEJB2X4iNh/scPhW6NiQKoY+pl HsnxxmwBsUCGdSM66lj/BwbgyR3JHcKcJXZGAXcx/kbSPGly5aJJMast3bwNhUD0p04F t9Zw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uGiBzCl0; 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 d9443c01a7336-223502b0e2csi183471505ad.330.2025.03.04.07.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:32:11 -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=uGiBzCl0; 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 11D00811E0; Tue, 4 Mar 2025 16:32: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=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="uGiBzCl0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93981811B3; Tue, 4 Mar 2025 16:32:06 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 5FE4B800C1 for ; Tue, 4 Mar 2025 16:32:04 +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-wr1-x42e.google.com with SMTP id ffacd0b85a97d-390e6ac844fso5092174f8f.3 for ; Tue, 04 Mar 2025 07:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102296; x=1741707096; 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=TMtdutuo61S5rVB0PvO6Ee5x2fRltLLt3zobQ6X/nRg=; b=uGiBzCl0+b02XI0hmz0gz8VeXD4SdZll4umAWMK1wx3eiY9hXxHX+Q2LcVObeMtlrW x1CaMYQgtJWChieCr8OmVAo9Nx6RI1k0B8MAGdfdCO2uSuyyv5kuWKemOr1oQOxyAJiK rA6yUkzQIrYQuVRs1O+I7jTykgUftc66tUmqpPOOsJvvwmcY/NakJ7VEio8SbeyQfJ0M nkNr4sjOphQaiBvOXF1qreKd6Yq/d2UvEOhOmIV80OFqXqwaDCQc8xQIWKLOz6rfE2Bz IxsqkdBds5To6zLjy+AiGx9LjotfNUc8bgWZ38hcIrVEZEfD3lbfoX091Rd8LRyCBsqY /3gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102296; x=1741707096; 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=TMtdutuo61S5rVB0PvO6Ee5x2fRltLLt3zobQ6X/nRg=; b=uXYno71MoakyICiMjyuxah0XcqZZCZqFOMkk76RnQ2+mxiuu5qwu9TwAu91kKRuKn7 4/bdzvGjyzBHP4KWIxbK6k9FQFQvRJetCJPj4cLiUzgpNZpXYnNU7pnRbWlUkvrIkqPp mUeNBdND8IulzkE0walRfhkUlRu0Uo565iAYOL6GX4eCvTY1ocoU2MsumDWP2vCjFY2I O06v355DCsMC/y19fScFc1uGpNGdjHSUGF1rfh843pHjnGqzzRpynWKYBchytSvmh7xH yIfnXbjLdaFniTAMFaJ4lAYgKB3IPgPBLhygG4PGCKEHsX/S5bczSFy6W1FFDr1EmfmD SQrQ== X-Gm-Message-State: AOJu0Yzgu14JuDgIL5XuzCBFYQcK+VvbfRbgQOPq8nmIyQGw9ESZnh6T Tv9IAD1y+CL6z1dZ51oAfcyfnWOn/flcnyAuAe7hCzksN0GEeEmI0pHOHkW6JWjquz7TuL9H1Y2 9 X-Gm-Gg: ASbGncuIBzWeXzu82HXoeHG3BZCYKjSKqW/qCRTqCGolde9j5UMHhVYCuntzmmCHnt4 bjoMIU4aHGR5nG+/4sJ4b7VOW7/+dtgdQuJ7CSxy3Z5SIK3DNPtSm7RAw5JfaAcXYSEgxFz83wu 1bMr7R3SJzPzJFYsoQyoLtYFWqi7S7RTTo5V5gXIbZ3VpL3rZmpEWyKWvqpAm8xaadEyVciI50g 6Vox5oRaErU5vhsRTGLXQ7DGMg5gXOLrWPt3UbLCyMY7HRthQ/sZluLIQMqf+cCiTBhftxtvPVm edpDFmbFyp3hN8WdGQL/mvvan63ROoI0HpYNQFpoMO8BdJQlyIJa3A== X-Received: by 2002:a05:6000:1ac9:b0:391:13ef:1af8 with SMTP id ffacd0b85a97d-39113ef1e1cmr4773008f8f.54.1741102296206; Tue, 04 Mar 2025 07:31:36 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:35 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Sughosh Ganu , Raymond Mao , Michal Simek , Patrick Rudolph Subject: [PATCH v3 08/14] lib: time: hook uthread_schedule() into udelay() Date: Tue, 4 Mar 2025 16:24:56 +0100 Message-ID: <20250304152510.2832340-9-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Introduce a uthread scheduling loop into udelay() when CONFIG_UTHREAD is enabled. This means that any uthread calling into udelay() may yield to uthread and be scheduled again later. The granunlarity of the scheduling loop is defined by CONFIG_UTHREAD_GRANULARITY. The lower the value, the tighter the loop. The default value of 10 ms was chosen by testing the concurrent initialization of the two USB busses of an i.MX93 board (introduced in a later commit). The total time is as follows: UTHREAD_GRANULARITY (us) | "usb start" time (s) -------------------------+---------------------- 0 | 2.426 1000 | 2.448 10000 | 2.512 100000 | 2.992 300000 | 3.407 For reference, if uthread_schedule() is not called at all in udelay() except once via schedule(), the "usb start" time is 4.377s and without UTHREAD it is 4.591 s. Signed-off-by: Jerome Forissier --- lib/Kconfig | 8 ++++++++ lib/time.c | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig b/lib/Kconfig index 8321f20e154..40964f5bb4a 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1276,6 +1276,14 @@ config UTHREAD_STACK_SIZE When the stack_sz argument to uthread_create() is zero then this value is used. +config UTHREAD_GRANULARITY + int "Scheduling period for uthreads inside udelay()" + depends on UTHREAD + default 10000 + help + The delay in microseconds between calls to uthread_schedule() inside + the udelay() function. + endmenu source "lib/fwu_updates/Kconfig" diff --git a/lib/time.c b/lib/time.c index d88edafb196..7c34424bf64 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,23 @@ void __weak __udelay(unsigned long usec) /* ------------------------------------------------------------------------- */ +static void do_delay(unsigned long kv) +{ +#if CONFIG_IS_ENABLED(UTHREAD) + ulong t0 = timer_get_us(); + ulong gr = CONFIG_UTHREAD_GRANULARITY; + + if (kv < CONFIG_UTHREAD_GRANULARITY) + gr = kv; + while (timer_get_us() - t0 < kv) { + uthread_schedule(); + __udelay(gr); + } +#else + __udelay(kv); +#endif +} + void udelay(unsigned long usec) { ulong kv; @@ -197,7 +215,8 @@ void udelay(unsigned long usec) do { schedule(); kv = usec > CFG_WD_PERIOD ? CFG_WD_PERIOD : usec; - __udelay(kv); + do_delay(kv); usec -= kv; } while(usec); + } From patchwork Tue Mar 4 15:24:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870108 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313192wrg; Tue, 4 Mar 2025 07:32:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVLoHbr+j5AhB78m972c7TK68sxns7h0AKJ1q2MKSn9mXdLuljeiexuxVSaBx9eeTMEYWu1DQ==@linaro.org X-Google-Smtp-Source: AGHT+IGEI0ZpYvlgnBAnuOHG4vy3WbL5599bX3jk3EB780qmR/3n3/4aR42Gcco21wZUBk3sf48b X-Received: by 2002:a17:902:e851:b0:21f:ba77:c49a with SMTP id d9443c01a7336-223d91344bbmr50641665ad.4.1741102354820; Tue, 04 Mar 2025 07:32:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102354; cv=none; d=google.com; s=arc-20240605; b=OT9DmyM/spVJLCDYLfhnrg0QmLDZzffUEZRh81TP37tKlJZ2WQnQfjcn6vlhmc+jjL +jP7sey7G4XIJXLd3pFnVbdNIirBnPOxY3Vtkv/OQ4n3HY6UfteWP6OGWw1XvHRIaraZ J8woqc7P8RTL2j0EO6h4wuq4bDEtyaEEA5pFUk3pVx++SaqFlyNkhVwwr7BNiaOPLqzj T2XQHLn3opNGcMEMPsEg2jSc8SG/uYOjrhH7eBxvrzSl1WDX+nyassEXIE8fRyIkcqri i0zTB1FURcm5yKUBb44aNxLEtKACYEpdhzGqIVWeOnMfX5Kfjd08czrNs1F0/TvRow4a zNOQ== 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=h+4hVmas2EiPoyJIFhc1fMdsIcMgmXOQv5p+6lZAxr0=; fh=pxkeymicbWSzax63Za9jHWp/6CzGxVjGkJodzxw4Txs=; b=AY+2+CMzKEanxh4BYWB855dyvEz+x3gRiJFdS7/q8UktS0NePf1Stzj3wmSQNiylFW uheqxLE6RAgpRIkUoJCH3ncDPMjcsf5TeZMjjU20871bTY9B4i286J79LhdXN8fhByII SiCbvk0pyXEMrEFo+ywUWV7pKybI3+9Yetk1wJigAfoC2CUWe9XJQaCfblKQ/euTFJst 0aW+iQnSxuCoBvEpmg/d1t5HPLZPTFkB3t6R1zCZjcfd48HWNbHVbXi0c4YkgH5lHWY6 Q+k7Zt2rT8PfmZgAyWY+ZMUIQoKB8jgiVVu+jGsjxFWTV5reEcMRqQ+Xd2IJgd1wxQeT pOdw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b/yD7lXr"; 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 d9443c01a7336-223501d5c71si185554975ad.47.2025.03.04.07.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:32:34 -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="b/yD7lXr"; 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 9F214801CF; Tue, 4 Mar 2025 16:32:09 +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="b/yD7lXr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AE120812C8; Tue, 4 Mar 2025 16:32:08 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 61A8E810DC for ; Tue, 4 Mar 2025 16:32:06 +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-x329.google.com with SMTP id 5b1f17b1804b1-43bcbdf79cdso6278385e9.2 for ; Tue, 04 Mar 2025 07:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102298; x=1741707098; 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=h+4hVmas2EiPoyJIFhc1fMdsIcMgmXOQv5p+6lZAxr0=; b=b/yD7lXr9nWtOomw7XqORBw/onF17c0cAe7KLSIAW3ZHJeoqCtF/np8/4nrZOnW4cj jXoVVWIchxlZZB62UDXD432ZbK1c0e8o4uzPO5eC2WqhKqPIxYzgzyk0W1vH9E23vepN DSqOjBYVcGgTDgwpfmRzCA6ysrRSHZ/H4zk0Gnpmhq1QNwSH1HqjJ7BaTx0MINFBPLKx fv/8wZn26CvFKL/dby4vCeqFNihoI5/NZO92c1jSw5SFr6i9B5GBwh05oZwp1hPf/xCZ XxYGGHo8iEtudo0N8Kdwfx0LjXZmqxe7IbY1WSG5SdA+vS6AywBO1hf7s+VvEoMtNlTL aDVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102298; x=1741707098; 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=h+4hVmas2EiPoyJIFhc1fMdsIcMgmXOQv5p+6lZAxr0=; b=nZ4LHI44eyV+Y0j6p2UnJ2O+KdiyzcsniVmkWZoJwgiz+i8T4jvekwHGhZLO10TuoU RzuUKbxOIAegnd7SjzvHrf4rG6Pq/gF+R3A3h3zeX3I5vTyaiCQaI6J+Vn59dDFdJbV/ 6NW2ykvqzrk2eYR0RI8gDzRcK/+RylwNwXR61IzO+AgkV7W9/Tbvk7sU5ogq9c8Jqpxs 6BxsVR9Iu2aqWy1CH1n1tG3yE7v102QseOSBngX/E+z3yRX41PETPKrTYZ2K/qsFWigP SRH5Tp4bcL2FuXTBbS9bGfUS/QV7LdCVSn1NVlgau2YQ5rqG/TKn3jzQpcucC4KHEafn Ox3w== X-Gm-Message-State: AOJu0YwjB/gz550VUXE2CXOSsl0vIHMODswxBRSO7SV9KMLL8nPPj9pi 29b1Aks/BHOpfsRb6dXIfaf0Bo3Jw5+99s5RIS3dbQHOoyNoP3ucOp45yP3KDmS4NzBN36eDzc+ y X-Gm-Gg: ASbGnct9VeCwQGTj/UlnsGZxR+f8+1XzV51cdOsAXcxEErqrgPHJEciGJ8O00vSzdnA 1DBfRPTfXvuR+jFDAO6iy+MiMeY0hn3XnaebZR7g5/w/4vbI4Z+RorTEnHJRr/KEKzzGMFT10pN wvzJnxwZD1xMc+KcgaFFZaCoDZYCmxv7ED9c59rB+FZEqReLVRYShYHWA1t5uMGWuz87eyg5F+E istpGF6wo6vKg8ouVVZ3S9VS5697f9BTl1OgsT6XsZjDSu1B8PPbBpd1IUKB08LLatutghR+dKp MQLy7Hs1P1pTpY5f+vgtNhSvhYYI/M9kR8kfJv098+I0Ul+WrZA5hg== X-Received: by 2002:a05:600c:4ec8:b0:439:8b19:fa87 with SMTP id 5b1f17b1804b1-43ba66de874mr137013645e9.4.1741102297662; Tue, 04 Mar 2025 07:31:37 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:37 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Heinrich Schuchardt , Simon Glass , Raymond Mao , Philippe Reynes Subject: [PATCH v3 09/14] test: lib: add uthread test Date: Tue, 4 Mar 2025 16:24:57 +0100 Message-ID: <20250304152510.2832340-10-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Add a uhread framework test to the lib tests. Update the API documentation to use the test as an example. Signed-off-by: Jerome Forissier Acked-by: Ilias Apalodimas --- doc/api/uthread.rst | 12 +++++++ test/lib/Makefile | 1 + test/lib/uthread.c | 80 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 test/lib/uthread.c diff --git a/doc/api/uthread.rst b/doc/api/uthread.rst index 21233ff6b22..8b25cc1ff80 100644 --- a/doc/api/uthread.rst +++ b/doc/api/uthread.rst @@ -3,5 +3,17 @@ Uthread API =========== +.. kernel-doc:: include/uthread.h + :doc: Overview + .. kernel-doc:: include/uthread.h :internal: + +Example +------- + +Here is an example of how to use this API: + +.. literalinclude:: ../../test/lib/uthread.c + :language: c + :linenos: diff --git a/test/lib/Makefile b/test/lib/Makefile index bf04685dae1..c991dff1c63 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o obj-$(CONFIG_UT_TIME) += time.o obj-$(CONFIG_$(XPL_)UT_UNICODE) += unicode.o +obj-$(CONFIG_UTHREAD) += uthread.o obj-$(CONFIG_LIB_UUID) += uuid.o else obj-$(CONFIG_SANDBOX) += kconfig_spl.o diff --git a/test/lib/uthread.c b/test/lib/uthread.c new file mode 100644 index 00000000000..0c0540585e7 --- /dev/null +++ b/test/lib/uthread.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for uthread + */ + +#include +#include +#include +#include + +static int count; + +/* A thread entry point */ +static void worker(void *arg) +{ + int loops = (int)(unsigned long)arg; + int i; + + for (i = 0; i < loops; i++) { + count++; + uthread_schedule(); + } +} + +/* + * lib_uthread() - testing the uthread API + * + * This function creates two threads with the same entry point. The first one + * receives 5 as an argument, the second one receives 10. The number indicates + * the number of time the worker thread should loop on uthread_schedule() + * before returning. The workers increment a global counter each time they loop. + * As a result the main thread knows how many times it should call + * uthread_schedule() to let the two threads proceed, and it also knows which + * value the counter should have at any moment. + */ +static int lib_uthread(struct unit_test_state *uts) +{ + int i; + int id1, id2; + + count = 0; + id1 = uthread_grp_new_id(); + ut_assert(id1 != 0); + id2 = uthread_grp_new_id(); + ut_assert(id2 != 0); + ut_assert(id1 != id2); + ut_assertok(uthread_create(NULL, worker, (void *)5, 0, id1)); + ut_assertok(uthread_create(NULL ,worker, (void *)10, 0, 0)); + /* + * The first call is expected to schedule the first worker, which will + * schedule the second one, which will schedule back to the main thread + * (here). Therefore count should be 2. + */ + ut_assert(uthread_schedule()); + ut_asserteq(2, count); + ut_assert(!uthread_grp_done(id1)); + /* Four more calls should bring the count to 10 */ + for (i = 0; i < 4; i++) { + ut_assert(!uthread_grp_done(id1)); + ut_assert(uthread_schedule()); + } + ut_asserteq(10, count); + /* This one allows the first worker to exit */ + ut_assert(uthread_schedule()); + /* At this point there should be no runnable thread in group 'id1' */ + ut_assert(uthread_grp_done(id1)); + /* Five more calls for the second worker to finish incrementing */ + for (i = 0; i < 5; i++) + ut_assert(uthread_schedule()); + ut_asserteq(15, count); + /* Plus one call to let the second worker return from its entry point */ + ut_assert(uthread_schedule()); + /* Now both tasks should be done, schedule should return false */ + ut_assert(!uthread_schedule()); + + return 0; +} +LIB_TEST(lib_uthread, 0); From patchwork Tue Mar 4 15:24:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870111 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313561wrg; Tue, 4 Mar 2025 07:33:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXQPZM4d5RKDwMSNGajBJHKxgyAnNIp8GvHN0PLvHzvcJUA5dvNcHeJGqA/gun17Jdpj5TMOA==@linaro.org X-Google-Smtp-Source: AGHT+IHUhPUtUcuuXw/oya97Q+Yl+tCyzb9k3v/sDoIwzXicZkzpBcG21juFu0J7OwHJnp3T6m2j X-Received: by 2002:a05:6a21:6b0f:b0:1ee:c631:6057 with SMTP id adf61e73a8af0-1f2f4e0ffc7mr33487051637.34.1741102391509; Tue, 04 Mar 2025 07:33:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102391; cv=none; d=google.com; s=arc-20240605; b=HLO9Um+p+B5sPpS1RD0vPU/F7ccpnXcxC1mygSO2Y1stAQaEwJXAnbdf9oU/zD2geT fjS2NWNLKGDT84dG4edDqK9k4UU33XLpFqvvqGS1HvEqyh/mu9qIpr7+OZdNyaJO7r6I O3bZ6gOF2tLpKyIDsnYR+W3+izU4U9oVrWQJHV9ttyrXtlFoWw6l3am8IyHl/T8nvcaH 4htTXPCI0khqjBrWZ7uFBUNLsFVzN2ShG6YkjiS17jhGTnouXFmBEcZcqD1dMLOaWGJ+ SNn+N1TkQl5Lhmqsn3isEpMUYG51QXzDSvpoCUPJCoVImIAKTPuromY1pYcSb/mhMqqU b7Mw== 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=Ce5dvI/5nuqLZMR/lkwnf7B1aBvTQhktpRS0pk/2NjQ=; fh=fR0UVWovEQaeizUbW6NYRhJaKj1baCbm+MM7JESBVRo=; b=U+xuHtky2l3nBpVFKEbQ1Do94vljqgzLsKBPV+PtpJSPBUqasJdGOzuHPconM+1eP/ Evrr2eylLUpIBLD0hoEl+rkW5gMWQNWg4IYby/6vdFL5vYuj3b7bT259kOEDowU/+VBv LJgAMa5GAnDq5w7wLD5nVW39GpcudUc+vMJhTXLRwLXefr2YW6PGPriz0kUmo9/L4s7C h/aON1R6UpOiJaDCBvh/mif4458SLgA3/837arzWc4E1WBWDM9ycxOuuyx/xnnaIBGio 7zuDFPEEFI4YkbDH5QVFj8wKpAxvSXKqTyofnmTCbmRYH0pEEhM8+x70bbeXL2CwDPhA FpJA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kUGBlFOf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id 41be03b00d2f7-aee7df3fabcsi18963693a12.715.2025.03.04.07.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:33:11 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kUGBlFOf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 8E35280BAA; Tue, 4 Mar 2025 16:32:12 +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="kUGBlFOf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 377A88141A; Tue, 4 Mar 2025 16:32:11 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 BA58581273 for ; Tue, 4 Mar 2025 16:32: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-x331.google.com with SMTP id 5b1f17b1804b1-43bc4b1603fso14456755e9.0 for ; Tue, 04 Mar 2025 07:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102299; x=1741707099; 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=Ce5dvI/5nuqLZMR/lkwnf7B1aBvTQhktpRS0pk/2NjQ=; b=kUGBlFOf8w6GCGVWixFZRq65AETKlQdmmoXsl4jFNq8TeFL8ToWBLhkM014ke2Mr6C bpcGIyzcIswn0A3KC1+pL3aRVUHq6ySNKv17eXxIJF3IQVT82KyR3kqlZUAA2FKf+S+A FjCQWi2vLI2LRL5lTG8pOVPeYmLcfjRj2fcOuQGQ/hr7KEfmUZ7MvKwdU+qlqXIBczF3 SkyOxpC2YiOvnNYihBZdxBJJtO0HxfpcUINRjBWPzxSCRdHNsIepZG6udk7FrMQoKo1j wGSxepj/R13pP6iYHkZGsgwhd+L8oAFLf7R0SRub+UoooOL/QcIKhbk9D3cqLThtCt5F KbmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102299; x=1741707099; 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=Ce5dvI/5nuqLZMR/lkwnf7B1aBvTQhktpRS0pk/2NjQ=; b=H6PKYTKj588LgtBnYWBKBb6hH8Qo7LgTQrSK9Q+cTKe/vvuPZuiNhXHqAX3WGuEORd 0cy6M71kohc05QEPtD1+ZZk8vNbE9m6OjBJ5rTaJ8I7zxorCl0Ofs26nQ7E+lVKsj5kF pYBna9XSu4sBSIQBJWAGCwoxbceMHEhWl/efjR4mfBnxuyyyLriMfPj0/CxiwBbdW/HC WcoEQiaFg+qSCxEeiG+mZeRU8CbQMSBfLKBukZoGb5N+9c5RtaTJXOraYtHgdYPS28ld 2QTF1wu9zApZ0n4LY36lCFfev6kzezoiyP+q6sqkjYyJrbTQ0aGwouhJhUwBKMj+IcW8 3tfA== X-Gm-Message-State: AOJu0YxIorEbovM3Gggr1JHILPr+wwBOoxslceIUCSqXeOR5YnoK2p6o UW5EIr2EuuzYUn/D4K6hf8VkNnPD8wlhayjxg7znBzuqq0mKm3rea54BDKtiE/g8ojhTchtLjko i X-Gm-Gg: ASbGnctmaEg9DdN+SSujIS+dE5rqK9/k2reH6KM+UZaBvk8UD2zUKQxoMDn+7kZXdb5 THP7+r27mtU3RwPdHve+8yiz8nbsggvgIk+NABAXIBBLQrJbq0XwGow131Cry7ycel3fEJIPcpX edKX4d9QdNUzAn2XaH2gCZGJqGwb3kBLMCqiNeFdqhkknToJhrDAJ8B1RbQ6DzGdBE+sPueB6fy icOSBNJqy8W4g3Iu9R/nL0XhqnX1Dadn/5qEtQYGeB5vBUhMRavOhuxkjV888KkY4O8cV8CDWiM hCyzoXMgyrpEHqFJ0VVMX7uaqe+ZDTiuz5FVx20iRevsKN+GWDyVmg== X-Received: by 2002:a5d:59a3:0:b0:391:cd7:82f9 with SMTP id ffacd0b85a97d-3910cd7835cmr6134495f8f.27.1741102298755; Tue, 04 Mar 2025 07:31:38 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:38 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Mattijs Korpershoek , Caleb Connolly , Dragan Simic , Heinrich Schuchardt Subject: [PATCH v3 10/14] dm: usb: move bus initialization into new static function usb_init_bus() Date: Tue, 4 Mar 2025 16:24:58 +0100 Message-ID: <20250304152510.2832340-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 To prepare for the introduction of coroutines in the USB initialization sequence, move code out of usb_init() into a new helper function: usb_init_bus(). No functional change. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- drivers/usb/host/usb-uclass.c | 88 +++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..cc803241461 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -287,9 +287,55 @@ static int usb_probe_companion(struct udevice *bus) return 0; } +static int controllers_initialized; + +static void usb_init_bus(struct udevice *bus) +{ + int ret; + + /* init low_level USB */ + printf("Bus %s: ", bus->name); + + /* + * For Sandbox, we need scan the device tree each time when we + * start the USB stack, in order to re-create the emulated USB + * devices and bind drivers for them before we actually do the + * driver probe. + * + * For USB onboard HUB, we need to do some non-trivial init + * like enabling a power regulator, before enumeration. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || + IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { + ret = dm_scan_fdt_dev(bus); + if (ret) { + printf("USB device scan from fdt failed (%d)", ret); + return; + } + } + + ret = device_probe(bus); + if (ret == -ENODEV) { /* No such device. */ + puts("Port not available.\n"); + controllers_initialized++; + return; + } + + if (ret) { /* Other error. */ + printf("probe failed, error %d\n", ret); + return; + } + + ret = usb_probe_companion(bus); + if (ret) + return; + + controllers_initialized++; + usb_started = true; +} + int usb_init(void) { - int controllers_initialized = 0; struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -305,45 +351,7 @@ int usb_init(void) uc_priv = uclass_get_priv(uc); uclass_foreach_dev(bus, uc) { - /* init low_level USB */ - printf("Bus %s: ", bus->name); - - /* - * For Sandbox, we need scan the device tree each time when we - * start the USB stack, in order to re-create the emulated USB - * devices and bind drivers for them before we actually do the - * driver probe. - * - * For USB onboard HUB, we need to do some non-trivial init - * like enabling a power regulator, before enumeration. - */ - if (IS_ENABLED(CONFIG_SANDBOX) || - IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { - ret = dm_scan_fdt_dev(bus); - if (ret) { - printf("USB device scan from fdt failed (%d)", ret); - continue; - } - } - - ret = device_probe(bus); - if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); - controllers_initialized++; - continue; - } - - if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); - continue; - } - - ret = usb_probe_companion(bus); - if (ret) - continue; - - controllers_initialized++; - usb_started = true; + usb_init_bus(bus); } /* From patchwork Tue Mar 4 15:24:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870113 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313841wrg; Tue, 4 Mar 2025 07:33:42 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUIyQvJtI8h4880wSEpr/iNtwczPd9AD96SlVpSEV653tUjzU897dBI1PzJsod787blVugG/A==@linaro.org X-Google-Smtp-Source: AGHT+IFGDXQUeXSo5J3B/zsx5oRQBNtXuOGMnSjaUx8Tdm6J4gEl0skXi9+7oTfeKF3bftxkp8SJ X-Received: by 2002:a05:6602:4818:b0:85a:fd12:9270 with SMTP id ca18e2360f4ac-85afd1292c5mr103583439f.10.1741102421927; Tue, 04 Mar 2025 07:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102421; cv=none; d=google.com; s=arc-20240605; b=KnDdl4eWUxjOYeMnHhnN+haW48mytPKExzRVUACeuQfoGuuO7D0MfkJpYD6wqn9Pza gxj0mL5xYfo4Qa8MK2vCWEBOGAzJnjSM/i2MnKipW+KkedoMrC5DfcKyV6a5HAlP9B5j y1KFKN5ur11N3FhzqyC6iVyeAsHvIPqXdCWrQaWs8amk3KuUeC6uSc6yqUrFSri01JQ3 10nb1eh8xrwW/Iv+S3UhvFnZ2QpU33rMxOO85s4/APd7x2k3xUuhyukTwOaHP/cA36wz UqQmx0vuLZgily//EGQ6hKi6aXWa2uNEBWMYYCCWhOr/e20ma6EMv53ldoZXAJYZrGj+ 922g== 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=sYLKI0SgAc8L11s7PsBzS5Deb1+Xgh8VeZGZG0bFncM=; fh=fg0vD70l6k0HrQ3apjLGMn1ihLBIKe+rbONScfGadOU=; b=PozO7Bt+xPA+UvLpxUBxwr430pGM5FohG7GMQyKXjUjL8aWXFGBvTlAqIuVHgKTt9Q RarfJN+WfM9wTal5AiGpR8MnOaPZIMO4qkEkcu4jY/lnQKnWy9VbFYaycIz6x/6wYSpy r4A4ZtRGabul8r6lEd2guM6tSe/8uBXbJMbmOC8YA4qGzhnwdo47b4zYqp1ga4UCSEx9 8MYo2hQmpmJvHjmbP/ttVLWzCbZPmzWZzW2E5rTCYvHa4jx4loIa1vnL+BzM8cHXh5dk d3tbTFobIF5WVD2k9e6SY4yQ0EvZ4yKM3Nr3S1xYGxpnrz/pPf3eOTgDKnZiLyiaRD8u rkhQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EoYvUboR; 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 8926c6da1cb9f-4f1d23b133asi2431328173.144.2025.03.04.07.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:33:41 -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=EoYvUboR; 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 2910881273; Tue, 4 Mar 2025 16:32:14 +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="EoYvUboR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0B059810DC; Tue, 4 Mar 2025 16:32:12 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 59A428129B for ; Tue, 4 Mar 2025 16:32:08 +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-x32d.google.com with SMTP id 5b1f17b1804b1-43bc63876f1so17468605e9.3 for ; Tue, 04 Mar 2025 07:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102300; x=1741707100; 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=sYLKI0SgAc8L11s7PsBzS5Deb1+Xgh8VeZGZG0bFncM=; b=EoYvUboR8YGQcr3ngNeLtZE6c4GDJbtP5v3QRElAGlFYkvp+ChyH7GN4S8KhrmHMUU XXW6JQ/Tmz15IfjIs33ZtFaWQ6aQ3uLiJygVYeJ3XV0aySkRydfGhUTBqdGQ9LYbkveN fnkQQRLlqj9UWYvRgGKOIAPwWRvHzyN/0GQ+DsdND67Rk1ryOnLa9V5s7NCGvPQBJ3Xv 9QJa3ZPOSwf/blodsoQYYMcUWRum53i6flfAxbm+D9DiUzI4l8D96Wq2kzZstPI2I3eT PPOw3LM1yzxLTvt/JiKosj5na+907TYNsl/PL0bBY9oAT3w9yUBT/m35k2FS3auYyTEC Gu2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102300; x=1741707100; 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=sYLKI0SgAc8L11s7PsBzS5Deb1+Xgh8VeZGZG0bFncM=; b=upHYdosBtr4rwBw4HAN2OizVS7ZPYJvwkjNadZV2AY2xmfVgSjjvOsEd+WfPHfldKR FaplYFaaHmgW0/IyE+6anTv4WKWlC9m8jARF2+iVUU4YDlzyvzhlvNE1D6WPyr77JHNu yiNCODl3dLtPoD5b+WLSulYeMJr9UwLJrxB5t6FeOiY2czFjuByp0yhzlZ910U+OtAbw M3I5s89TaoT3PN5cSbOHun6iMEiPf+4h1L5XN0aZ03PJ/qO6RuTq+YOn2ADnSspV6k9C 8JwzjPZuOlupiEvnwgzap9So/BCxZd5dYD8P5ZZmzlCK9fVGQEllwXTTc9Uh/5GjZidA XV8A== X-Gm-Message-State: AOJu0YwO49Jt/fNyxm+EVx1MOB98gYWgwRGe7WdrkDR6VSySXYtavVeN NhlddD2ZBP4O2tqV18VzIJG0oBWwV/+mL/mF7oYV0qbLmcRtPZQi7BTuZygzUQ6qh4ekrgbfLYf n X-Gm-Gg: ASbGncvrpH5ba7J+7Qq+Ebv3HAgIUqhtyctsP0UpcITiinJFF+y24I5jWu62AV5sgXg /XjEvFMBdirPr4eBpyynd2YSIfJgHoYarsEJRWYBiGqruAV7/lg3bqGq5mNl1VpVLIuhVIAuUg0 +mH9P2kUhZFB5dwTCCXWKie6x1YciBaloRhEg0PA4MF+yBOrSp7yY0tv0FiVLWucHgku0ARKiGJ SiSoBl6l2x194K5uufIwDtb04wJDa9H3n9Kts9/tVPn0jXUZipsrnNjDkoe35IhkWz037D8fg8x 2EAtT4FpwsbzPernhVmG0PGIsZ/XzmjyEGtLWE5v9HRmkBGSFuGNUg== X-Received: by 2002:a5d:5985:0:b0:391:1652:f0bf with SMTP id ffacd0b85a97d-3911652f233mr2306082f8f.33.1741102299907; Tue, 04 Mar 2025 07:31:39 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:39 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Simon Glass , Mattijs Korpershoek , Caleb Connolly , Heinrich Schuchardt , Dragan Simic , Julius Lehmann , Guillaume La Roque Subject: [PATCH v3 11/14] dm: usb: initialize and scan multiple buses simultaneously with uthread Date: Tue, 4 Mar 2025 16:24:59 +0100 Message-ID: <20250304152510.2832340-12-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Use the uthread framework to initialize and scan USB buses in parallel for better performance. The console output is slightly modified with a final per-bus report of the number of devices found, common to UTHREAD and !UTHREAD. The USB tests are updated accordingly. Tested on two platforms: 1. arm64 QEMU on a somewhat contrived example (4 USB buses, each with one audio device, one keyboard, one mouse and one tablet) $ make qemu_arm64_defconfig $ make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-" $ qemu-system-aarch64 -M virt -nographic -cpu max -bios u-boot.bin \ $(for i in {1..4}; do echo -device qemu-xhci,id=xhci$i \ -device\ usb-{audio,kbd,mouse,tablet},bus=xhci$i.0; \ done) 2. i.MX93 EVK (imx93_11x11_evk_defconfig) with two USB hubs, each with one webcam and one ethernet adapter, resulting in the following device tree: USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 100mA) | GenesysLogic USB2.1 Hub | +-3 Vendor specific (480 Mb/s, 350mA) | Realtek USB 10/100/1000 LAN 001000001 | +-4 (480 Mb/s, 500mA) HD Pro Webcam C920 8F7CD51F 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 100mA) | USB 2.0 Hub | +-3 Vendor specific (480 Mb/s, 200mA) | Realtek USB 10/100/1000 LAN 000001 | +-4 (480 Mb/s, 500mA) Generic OnLan-CS30 201801010008 Note that i.MX was tested on top of the downstream repository [1] since USB doesn't work in the upstream master branch. [1] https://github.com/nxp-imx/uboot-imx/tree/lf-6.6.52-2.2.0 commit 6c4545203d12 ("LF-13928 update key for capsule") The time spent in usb_init() ("usb start" command) is reported on the console. Here are the results: | CONFIG_UTHREAD=n | CONFIG_UTHREAD=y --------+------------------+----------------- QEMU | 5628 ms | 2212 ms i.MX93 | 4591 ms | 2441 ms Signed-off-by: Jerome Forissier --- drivers/usb/host/usb-uclass.c | 92 ++++++++++++++++++++++++++++------- test/boot/bootdev.c | 14 +++--- test/boot/bootflow.c | 2 +- 3 files changed, 83 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index cc803241461..7443bcc0e2c 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -9,6 +9,7 @@ #define LOG_CATEGORY UCLASS_USB #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include static bool asynch_allowed; @@ -221,25 +223,18 @@ int usb_stop(void) return err; } -static void usb_scan_bus(struct udevice *bus, bool recurse) +static void _usb_scan_bus(void *arg) { + struct udevice *bus = (struct udevice *)arg; struct usb_bus_priv *priv; struct udevice *dev; int ret; priv = dev_get_uclass_priv(bus); - assert(recurse); /* TODO: Support non-recusive */ - - printf("scanning bus %s for devices... ", bus->name); - debug("\n"); ret = usb_scan_device(bus, 0, USB_SPEED_FULL, &dev); if (ret) - printf("failed, error %d\n", ret); - else if (priv->next_addr == 0) - printf("No USB Device found\n"); - else - printf("%d USB Device(s) found\n", priv->next_addr); + printf("Scanning bus %s failed, error %d\n", bus->name, ret); } static void remove_inactive_children(struct uclass *uc, struct udevice *bus) @@ -289,12 +284,12 @@ static int usb_probe_companion(struct udevice *bus) static int controllers_initialized; -static void usb_init_bus(struct udevice *bus) +static void _usb_init_bus(void *arg) { + struct udevice *bus = (struct udevice *)arg; int ret; /* init low_level USB */ - printf("Bus %s: ", bus->name); /* * For Sandbox, we need scan the device tree each time when we @@ -309,33 +304,84 @@ static void usb_init_bus(struct udevice *bus) IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { ret = dm_scan_fdt_dev(bus); if (ret) { - printf("USB device scan from fdt failed (%d)", ret); + printf("Bus %s: USB device scan from fdt failed (%d)\n", + bus->name, ret); return; } } ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); + printf("Bus %s: Port not available.\n", bus->name); controllers_initialized++; return; } if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); + printf("Bus %s: probe failed, error %d\n", bus->name, ret); return; } ret = usb_probe_companion(bus); - if (ret) + if (ret) { return; + } controllers_initialized++; usb_started = true; } +static int nthr; +static int grp_id; + +static void usb_init_bus(struct udevice *bus) +{ + if (!grp_id) + grp_id = uthread_grp_new_id(); + if (!uthread_create(NULL, _usb_init_bus, (void *)bus, 0, grp_id)) + nthr++; +} + +static void usb_scan_bus(struct udevice *bus, bool recurse) +{ + if (!grp_id) + grp_id = uthread_grp_new_id(); + if (!uthread_create(NULL, _usb_scan_bus, (void *)bus, 0, grp_id)) + nthr++; +} + +static void usb_report_devices(struct uclass *uc) +{ + struct usb_bus_priv *priv; + struct udevice *bus; + + uclass_foreach_dev(bus, uc) { + if (!device_active(bus)) + continue; + priv = dev_get_uclass_priv(bus); + printf("Bus %s: ", bus->name); + if (priv->next_addr == 0) + printf("No USB Device found\n"); + else + printf("%d USB Device(s) found\n", priv->next_addr); + } +} + +static void run_threads(void) +{ +#if CONFIG_IS_ENABLED(UTHREAD) + if (!nthr) + return; + while (!uthread_grp_done(grp_id)) + uthread_schedule(); + nthr = 0; + grp_id = 0; +#endif +} + int usb_init(void) { + unsigned long t0 = timer_get_us(); struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -354,6 +400,9 @@ int usb_init(void) usb_init_bus(bus); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + /* * lowlevel init done, now scan the bus for devices i.e. search HUBs * and configure them, first scan primary controllers. @@ -367,6 +416,9 @@ int usb_init(void) usb_scan_bus(bus, true); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + /* * Now that the primary controllers have been scanned and have handed * over any devices they do not understand to their companions, scan @@ -383,7 +435,10 @@ int usb_init(void) } } - debug("scan end\n"); + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + + usb_report_devices(uc); /* Remove any devices that were not found on this scan */ remove_inactive_children(uc, bus); @@ -397,6 +452,9 @@ int usb_init(void) if (controllers_initialized == 0) printf("No USB controllers found\n"); + debug("USB initialized in %ld ms\n", + (timer_get_us() - t0) / 1000); + return usb_started ? 0 : -ENOENT; } diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 5f07430714e..70a1d868de8 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -392,8 +392,8 @@ static int bootdev_test_hunter(struct unit_test_state *uts) ut_assert_console_end(); ut_assertok(bootdev_hunt("usb1", false)); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); /* USB is 7th in the list, so bit 8 */ @@ -448,8 +448,8 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextline("scanning bus for devices..."); ut_assert_skip_to_line("Hunting with: spi_flash"); ut_assert_nextline("Hunting with: usb"); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_nextline("Hunting with: virtio"); ut_assert_console_end(); @@ -550,8 +550,8 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts) ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); ut_assert_nextline("Hunting with: ide"); ut_assert_nextline("Hunting with: usb"); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); return 0; @@ -603,7 +603,7 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts) ut_assertnonnull(dev); ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); - ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); + ut_assert_nextline("Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); return 0; diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index eb7f00af39a..699ba0edaaf 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1289,7 +1289,7 @@ static int bootflow_efi(struct unit_test_state *uts) ut_assertok(run_command("bootflow scan", 0)); ut_assert_skip_to_line( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + "Bus usb@1: 5 USB Device(s) found"); ut_assertok(run_command("bootflow list", 0)); From patchwork Tue Mar 4 15:25:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870114 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313976wrg; Tue, 4 Mar 2025 07:33:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVVERf7mcJm2mJQBMKnEMPf3/6VX7vg+mQqkrfhIxQ8WiZ6faHoof1R8i1FBSEhFtiCbh49HQ==@linaro.org X-Google-Smtp-Source: AGHT+IFUbrJUjipg4G0CTSeS/+nkEyKuH9pRA1/l9eqQ8HUJNMsz/nqn7WvzQmvXcy9OyUDXdaaF X-Received: by 2002:a05:6e02:19ca:b0:3d1:79ec:bef2 with SMTP id e9e14a558f8ab-3d3e6e73d90mr133651665ab.6.1741102434655; Tue, 04 Mar 2025 07:33:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102434; cv=none; d=google.com; s=arc-20240605; b=c3Ip9KdXdsrF20HROsIFPkbWgDnmkKz44FLtV18m5IDBJbZEf9CB1p4w885GHzWF5E huWlrnYpYCxqSoiNK5VkuHfGIUX8AGAPgSH5gUGdiHlF4p9FmMnMP1y6ZmiSe99LWjPd p6YJ+YArMS6mNpZVYtqICLedwwXsqu3QhyGXPk2GzqD7bm/plSFIXNFFx9rbx3V5XTNp QrjTQHnhb+/gjEO0Fg0qDnobFWvoXZzCRVfJHMZaQSzX5NkgEODTkwi134IXeKwP6AYw rZeZdk02SigSFmYhgddfrM7/pgDiLK1BOytzx5Rr6wuDkbMdIgH1cRsOXNHvMc4vMVPD hfJw== 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=whR7LTiSIxB43IDds0i5AAfD+p805VrqDrPzgi74Fkw=; fh=TvsDrpN0fsDndde3l8ox7JPMpBapobykuFt87ERznIs=; b=hjF/r+zu9P2u8EQPz8GGCvqKbbjGCYAm9TmWHVDawJKwb+Cnm0uIPGUECdHIFXEB8J mbZG950OHbprKw+ICqoBC6WeEDajZxoMwyyTGWemfPpdQtWQo4Vkx9CNHkkw8oeiUNkJ kqHaEJoz4chRjpdsA0RfH6QoLUYHgnTrVdgmg/7Cf7Kft45u0z7iG3SDrk2kiLNoGfT+ W6jFABytOXN/qmSWXdBpHuw9nD9X68r15A3TJXlFaSTmjAltsHE1PNf2fBgOnzQR8hDY 3ojqEu/qleL0THr6dUQRaFm5Hj1whBGANtvQEOIv518aw1RwsOQ5GE2ENbUsoD9Uex9P 9xAg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JqVRhU1k; 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 8926c6da1cb9f-4f0a0848b9fsi2884143173.120.2025.03.04.07.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:33:54 -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=JqVRhU1k; 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 7225A81335; Tue, 4 Mar 2025 16:32:14 +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="JqVRhU1k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4396080FDD; Tue, 4 Mar 2025 16:32:12 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 2320D808A2 for ; Tue, 4 Mar 2025 16:32:10 +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-x329.google.com with SMTP id 5b1f17b1804b1-43bc31227ecso14770665e9.1 for ; Tue, 04 Mar 2025 07:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102302; x=1741707102; 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=whR7LTiSIxB43IDds0i5AAfD+p805VrqDrPzgi74Fkw=; b=JqVRhU1kM0rud0lDFcqOf9C7SvwJNgbEMpTr0s9N+BLiuZajnXJ7wMY1zYLDn2YA8o l7E8E7WFk2OEDBoUisnHowZlQWVzyp7WnjPadcT/Xsd75+fkV3Cf4dtXbJworAgzv6MV kwTB694GDmEK2aXn0JbSTeUswsnW6jObrsD5/wtR5t3+hcGZyjHbGc/gwQo8PnnSthTA MLHP6g3QyxUY9NuaE2YuBL/ZjrHiRneVn45Jfng1NcJ2afkkuJ9SCyasOyjtZ/BwZwxc q+j5boxMjwUxKk8J4rj38LYcPk+29Wndo1ndp5pH+R2q2XatlnGR7VFRGdoDCYF2mjB4 LTnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102302; x=1741707102; 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=whR7LTiSIxB43IDds0i5AAfD+p805VrqDrPzgi74Fkw=; b=ere24GYOQ+vWHeq1h+9TCFdkCE5xnLTm5shuO7IF4mGzD2XJpDH49kIyiGMyq1mLog RxFoZ3+65KM4/IFFAIZZ2DLX+WR4zc9Ojki0pllZEy70swrJ9RpEMAoF9+Mu5N6OEfO/ UT+G0XTNEjijyxwrlGyuLQkAXAaAsyiQD3rfBLb335CDCpSlM+H8Tkupg8nYJnTAa71f uPuY2tJ9VY3wEMmK8WYKI9ddxYRaqubNO07Yo8FOPIFKB5Y8GKxq9dSmqGpaCPnqHVv8 ZYVrf2W7nyuYu2iQwiNdZEUz7ypvfCd3+NxSa4QxLKuHXgQZYn5rfixXleuDKSF3xxte akiA== X-Gm-Message-State: AOJu0YxHEOESOsViBBDbjF3jnKP2UI2MnZPpfIqP3gZj1lLAl072/qGr RxPgP3WnUQHW1LpfC/NqHdu9rqq2j3Qr992LHVPNP0NQam41hOeHEsg89YzcRJp5kDNMgY+gNte r X-Gm-Gg: ASbGnctVbx9VGQe/2n8nvvgy+MmUDBMbi+CSOZLjrFzv2lmciIL7XKIw2PIQAtg9OEn nUThhNJY+hea8d9VTmJP/QDot85+VAPH9yGxj0MNKbdR+CGvTRpp58b7ML9ofeKnxjwYVzCBf6f cjG2tMY0ZL9czm/Wqjrvv4Jo2byQKBubR0FrGEhDwD4VBJ36/hFSKu9zYuSuXfku0E9g11Xhf2Y 6NWIlZHFd4sqaPZFStg7X6ffCy5Atz6ki8hO0jmWdnhiLwmEGnX2MsitWOgErObWty9L0rnjotR VmxMR49HJbezUfmYYJfYg/4WIP96idGraCqEuSbArA8wtFs3xgTQgg== X-Received: by 2002:a05:600c:384b:b0:439:86fb:7340 with SMTP id 5b1f17b1804b1-43ba675ae8emr163928535e9.30.1741102301550; Tue, 04 Mar 2025 07:31:41 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:41 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Mattijs Korpershoek , Ibai Erkiaga , Michal Simek , Dmitry Rokosov , Caleb Connolly Subject: [PATCH v3 12/14] cmd: add spawn and wait commands Date: Tue, 4 Mar 2025 16:25:00 +0100 Message-ID: <20250304152510.2832340-13-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Add a spawn command which runs another command in the background, as well as a wait command to suspend the shell until one or more background jobs have completed. The job_id environment variable is set by spawn and wait accepts optional job ids, so that one can selectively wait on any job. Example: => date; spawn sleep 5; spawn sleep 3; date; echo "waiting..."; wait; date Date: 2025-02-21 (Friday) Time: 17:04:52 Date: 2025-02-21 (Friday) Time: 17:04:52 waiting... Date: 2025-02-21 (Friday) Time: 17:04:57 => Another example showing how background jobs can make initlizations faster. The board is i.MX93 EVK, with one spinning HDD connected to USB1 via a hub, and a network cable plugged into ENET1. # From power up / reset u-boot=> setenv autoload 0 u-boot=> setenv ud "usb start; dhcp" u-boot=> time run ud [...] time: 8.058 seconds # From power up / reset u-boot=> setenv autoload 0 u-boot=> setenv ud "spawn usb start; spawn dhcp; wait" u-boot=> time run ud [...] time: 4.475 seconds Signed-off-by: Jerome Forissier --- cmd/Kconfig | 17 +++++ cmd/Makefile | 2 + cmd/spawn.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 cmd/spawn.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 8dd42571abc..209ca365f4c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -3058,4 +3058,21 @@ config CMD_MESON help Enable useful commands for the Meson Soc family developed by Amlogic Inc. +config CMD_SPAWN + bool "spawn and wait commands" + depends on UTHREAD + help + spawn runs a command in the background and sets the job_id environment + variable. wait is used to suspend the shell execution until one or more + jobs are complete. + +config CMD_SPAWN_NUM_JOBS + int "Maximum number of simultaneous jobs for spawn" + default 16 + help + Job identifiers are in the range 1..CMD_SPAWN_NUM_JOBS. In other words + there can be no more that CMD_SPAWN_NUM_JOBS running simultaneously. + When a jobs exits, its identifier is available to be re-used by the next + spawn command. + endif diff --git a/cmd/Makefile b/cmd/Makefile index 8410be576bb..eeda40855bf 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -240,6 +240,8 @@ obj-$(CONFIG_CMD_SCP03) += scp03.o obj-$(CONFIG_HUSH_SELECTABLE) += cli.o +obj-$(CONFIG_CMD_SPAWN) += spawn.o + obj-$(CONFIG_ARM) += arm/ obj-$(CONFIG_RISCV) += riscv/ obj-$(CONFIG_SANDBOX) += sandbox/ diff --git a/cmd/spawn.c b/cmd/spawn.c new file mode 100644 index 00000000000..f7a9f225f93 --- /dev/null +++ b/cmd/spawn.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#include +#include +#include +#include +#include + +/* Spawn arguments and job index */ +struct spa { + int argc; + char **argv; + unsigned int job_idx; +}; + +/* + * uthread group identifiers for each running job + * 0: job slot available, != 0: uthread group id + * Note that job[0] is job_id 1, job[1] is job_id 2 etc. + */ +static unsigned int job[CONFIG_CMD_SPAWN_NUM_JOBS]; +/* + * Return values of the commands run as jobs */ +static enum command_ret_t job_ret[CONFIG_CMD_SPAWN_NUM_JOBS]; + +static void spa_free(struct spa *spa) +{ + int i; + + if (!spa) + return; + + for (i = 0; i < spa->argc; i++) + free(spa->argv[i]); + free(spa->argv); + free(spa); +} + +static struct spa *spa_create(int argc, char *const argv[]) +{ + struct spa *spa; + int i; + + spa = calloc(1, sizeof(*spa)); + if (!spa) + return NULL; + spa->argc = argc; + spa->argv = malloc(argc * sizeof(char *)); + if (!spa->argv) + goto err; + for (i = 0; i < argc; i++) { + spa->argv[i] = strdup(argv[i]); + if (!spa->argv[i]) + goto err; + } + return spa; +err: + spa_free(spa); + return NULL; +} + +static void spawn_thread(void *arg) +{ + struct spa *spa = (struct spa *)arg; + ulong cycles = 0; + int repeatable = 0; + + job_ret[spa->job_idx] = cmd_process(0, spa->argc, spa->argv, + &repeatable, &cycles); + spa_free(spa); +} + +static unsigned int next_job_id(void) +{ + int i; + + for (i = 0; i < CONFIG_CMD_SPAWN_NUM_JOBS; i++) + if (!job[i]) + return i + 1; + + /* No job available */ + return 0; +} + +static void refresh_jobs(void) +{ + int i; + + for (i = 0; i < CONFIG_CMD_SPAWN_NUM_JOBS; i++) + if (job[i] && uthread_grp_done(job[i])) + job[i] = 0; + +} + +static int do_spawn(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + unsigned int id; + unsigned int idx; + struct spa *spa; + int ret; + + if (argc == 1) + return CMD_RET_USAGE; + + spa = spa_create(argc - 1, argv + 1); + if (!spa) + return CMD_RET_FAILURE; + + refresh_jobs(); + + id = next_job_id(); + if (!id) + return CMD_RET_FAILURE; + idx = id - 1; + + job[idx] = uthread_grp_new_id(); + + ret = uthread_create(NULL, spawn_thread, spa, 0, job[idx]); + if (ret) { + job[idx] = 0; + return CMD_RET_FAILURE; + } + + ret = env_set_ulong("job_id", id); + if (ret) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD(spawn, CONFIG_SYS_MAXARGS, 0, do_spawn, + "run commands and summarize execution time", + "command [args...]\n"); + +static enum command_ret_t wait_job(unsigned int idx) +{ + int prev = disable_ctrlc(false); + + while (!uthread_grp_done(job[idx])) { + if (ctrlc()) { + puts("\n"); + disable_ctrlc(prev); + return CMD_RET_FAILURE; + } + uthread_schedule(); + } + + job[idx] = 0; + disable_ctrlc(prev); + + return job_ret[idx]; +} + +static int do_wait(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + enum command_ret_t ret = CMD_RET_SUCCESS; + unsigned long id; + unsigned int idx; + int i; + + if (argc == 1) { + for (i = 0; i < CONFIG_CMD_SPAWN_NUM_JOBS; i++) + if (job[idx]) + ret = wait_job(i); + } else { + for (i = 1; i < argc; i++) { + id = dectoul(argv[i], NULL); + if (id < 0 || id > CONFIG_CMD_SPAWN_NUM_JOBS) + return CMD_RET_USAGE; + idx = (int)id - 1; + ret = wait_job(idx); + } + } + + return ret; +} + +U_BOOT_CMD(wait, CONFIG_SYS_MAXARGS, 0, do_wait, + "wait for one or more jobs to complete", + "[job_id ...]\n" + " - Wait until all specified jobs have exited and return the\n" + " exit status of the last job waited for. When no job_id is\n" + " given, wait for all the background jobs.\n"); From patchwork Tue Mar 4 15:25:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870115 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp314043wrg; Tue, 4 Mar 2025 07:34:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUhnZS8VCJYgXemlrIOcI4Xy/d+KC9kFYKfQcIv9dGAiuJMasAA2tvp5CYLdy1beY2rGCCYiQ==@linaro.org X-Google-Smtp-Source: AGHT+IHQ0A4BBI7RHDD1tmlgou9nqE+82/c/Sw/Z2ugKTMjU6BlGOxvQk2EWl5YYtkyDytZCodVo X-Received: by 2002:a05:6602:358d:b0:85a:e659:bed2 with SMTP id ca18e2360f4ac-85ae659c08emr725193139f.14.1741102443980; Tue, 04 Mar 2025 07:34:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102443; cv=none; d=google.com; s=arc-20240605; b=RC1H0LDcXCnU8tk4ERTcWkSPRaNa8pg6E8KduS1fRpUeEwyNfBxv/bMdDopIvJHl69 j+6bjkLxs7GRG59wie2vt0SkVB1IwoWwx1KcyjDuZpQXKrruq6HvrWt/6Y4/oM4ww6tU VZJR2YQ6XKLy8+BWo80zSCDQ5hzUKH3iL2WozRNYAGfeymN5ADze0jnBdXcKSw4CVXvX ERpxWmPKv2ZE7JVa/hj+B93G3ESMPqIx8PHn5SmHJRgmI5uOtWnEabzBAEIi7MBWkc48 scKwrH6KjWQqZJYIuoa0W/9uBYWF8cEVerM7mK85GF5dHfActKjoudThsORiWo3peb1J asIQ== 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=2b0elY+BCEMH9XRp7+WKyqFK+JQ8TgjRK/4IpiB+xp8=; fh=UXi5gUnwqAkJNiukY9dZPo8O1bj7wfbxhZ7gyd0YbGk=; b=QkYP7LvtfncJ9XTlG3mPAWFCDmkXmKUX487N5dNwJGhubPbCO7CrlJLq0wAKXRe74G x2v7Uh7ox6UYKvt5rMSux+ZMxYhLlv6A3LJx2er0m9+asVwgJ9AHnIHn9c/T7YZaRR6h MTtYpV2fILVomJFvTQicXL41YpjZroIOJ7dt1taZ76iG+kTDsyj8VO8iIfxgL1tkJpdh 41x6pkCF2Scd8VTsqP3NL9UXTJJj696wcC0yTt3T+ygQjsLmen8EBIGIRj8KTd2l4Ntx cNAl5yuKAFT1lXFxj/aeznKh6wrMTwSEnyDqxL97ypS8FkXc96u2z2dbsakn96vEz+87 ++lA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v920mA2f; 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 ca18e2360f4ac-85af8bd104bsi75406839f.104.2025.03.04.07.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:34:03 -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=v920mA2f; 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 B90F581280; Tue, 4 Mar 2025 16:32:15 +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="v920mA2f"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B4016810ED; Tue, 4 Mar 2025 16:32:13 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (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 26ED781335 for ; Tue, 4 Mar 2025 16:32: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=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4394345e4d5so39849025e9.0 for ; Tue, 04 Mar 2025 07:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102303; x=1741707103; 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=2b0elY+BCEMH9XRp7+WKyqFK+JQ8TgjRK/4IpiB+xp8=; b=v920mA2fE/KflWV4FTWwudoV27G/ep4Q9TwxwhmysRh474uwq4yz5SHbQp/2TwRCxl ussLLhXrDT5+8QyJyHnUFYA+h1XiSdg9zxt6ujlnxiYw/3LQ/b9kselzbn0Ju5AqGT92 37VGQK68A0ehksLA4jSvOxontD0AkY7z1zQrlES0XoO1SDobuoJ8D4jCkUgdGiEKBhC5 ZyEVIW8LymJnwTIpse5ukz82DPtya5/mymwyDwT6tLd370z1S3GWdy0UB0LRxtNDvjXJ XBWZBYOPHJPAlWNOwyOEG1WYWo3Hcdrhbudh651aefs67vQ7upTU1DBWojoKy6Vb6yu+ 3/IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102303; x=1741707103; 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=2b0elY+BCEMH9XRp7+WKyqFK+JQ8TgjRK/4IpiB+xp8=; b=OP+VWb8Xk6ODvvVlGphcnQBjUD7rs8r/0mgsMN9bciDtvGsjOWiizU9edtcJHYynEy XmrcPttuzjMT5iCeYJd7xHRAmZllKW/BlT2RN0tGyyfKAG2X1/q2j/0H9PeuUzpFxqaz JDD2vpBRKVsGjjn+7keZEQj4fLdR6yY/Wx1mky+xpzE7eMaI2YvWL0f7408AxJJgPYeY 5Eo9YFpSnSolJRb2qF/aLnH4f9lh7D+qbElzulr30hjyUUyg569Rxo+vpBoHdgItL0iU wiZ9VBwHZrEL0Rqk3UH1UmlbNiEvcFDkjLYsKpUCWqWIt+AZR3PtWOXQ1QW3+zYOdFb8 3rLQ== X-Gm-Message-State: AOJu0YzM5qLcKn7ddOe7I835gN3Od01VyYZG+qy5sPDPVNItPOv+mvKz LwIHSeJRHqupd6aSw10RZXROxpVS2SQF/8aziYWKLHiIQ1EfapMicipVAhsRMVvAxXkvRHhBcBO f X-Gm-Gg: ASbGncs9UfFYiWOrJ1Uw8d/jbEvNaqtw32dHBZJZ+kwmzoWEajEm2jVw/1pYhhkIX9Z ixpkGny3A5f52TWreyEsq8m4XQPSwGFfPPoQdYxs1pmkV5MI4byw9+6DgaVmk2lE0Gj0j4I08CL FhD4J3HKoCL+NRqVnVUj3/ZKVaCDURIvJW3BL3XltNmwoehiC0UMxTKe3811+r0yUmzOyjKRGnS Mh+q6E3tK+Y0hb+YQEyYGm/V+93855nl2Ju2dK68/AZoPfI0LIbZ7bi9Rxyfh0Hh5PHQwfvtfaH FLGLV1wZ3KOJsC5+VvLCVBEJDYGocukM1R/G+Q0LqfHwyRnFx5pEDQ== X-Received: by 2002:a05:600c:2292:b0:43b:c0fa:f9ce with SMTP id 5b1f17b1804b1-43bc0fafff1mr67444255e9.14.1741102303000; Tue, 04 Mar 2025 07:31:43 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:42 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt Subject: [PATCH v3 13/14] test: cmd: add test for spawn and wait commands Date: Tue, 4 Mar 2025 16:25:01 +0100 Message-ID: <20250304152510.2832340-14-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Test the spawn and wait commands. Signed-off-by: Jerome Forissier --- test/cmd/Makefile | 1 + test/cmd/spawn.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/cmd/spawn.c diff --git a/test/cmd/Makefile b/test/cmd/Makefile index d8a5e77402d..cf47f04851c 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -39,3 +39,4 @@ obj-$(CONFIG_CMD_WGET) += wget.o endif obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o endif +obj-$(CONFIG_CMD_SPAWN) += spawn.o diff --git a/test/cmd/spawn.c b/test/cmd/spawn.c new file mode 100644 index 00000000000..8f48f5ee25c --- /dev/null +++ b/test/cmd/spawn.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Tests for spawn and wait commands + * + * Copyright 2025, Linaro Ltd. + */ + +#include +#include +#include +#include + +static int test_cmd_spawn(struct unit_test_state *uts) +{ + ut_assertok(run_command("wait; spawn sleep 2; setenv j ${job_id}; " + "spawn setenv spawned true; " + "setenv jj ${job_id}; wait; " + "echo ${j} ${jj} ${spawned}", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_ptr(uts->actual_str, + strstr(uts->actual_str, "1 2 true")); + + ut_assertok(run_command("spawn true; wait; setenv t $?; spawn false; " + "wait; setenv f $?; wait; echo $t $f $?", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_ptr(uts->actual_str, + strstr(uts->actual_str, "0 1 0")); + ut_assert_console_end(); + + return 0; +} +CMD_TEST(test_cmd_spawn, UTF_CONSOLE); From patchwork Tue Mar 4 15:25:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 870110 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp313425wrg; Tue, 4 Mar 2025 07:32:59 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVH9fMmOfFqeH+/LB1wzRwWgzKY24cdS3tTif8tyZV/5MDryigvVbbI2p3kL0h16E7r7FerIw==@linaro.org X-Google-Smtp-Source: AGHT+IFlFZSaiV9Mdrru84uZwOR2+1r5r5yphIWJSAxt1ycTGRuOfQporru5mHv4oBqE4XuGaqbz X-Received: by 2002:a05:6a00:10cf:b0:736:520a:58f9 with SMTP id d2e1a72fcca58-736520a5a51mr11672916b3a.17.1741102379045; Tue, 04 Mar 2025 07:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741102379; cv=none; d=google.com; s=arc-20240605; b=c6wqp6cApMIjGMAyI2gJ65V93bgmf68rZ1bwAHz08pfEkCuxFRva93M+Idj3ZJe8O3 YsOmEWzXItj+ZxIIzE8ueBaf5tkgPDWRmR/XwKgyA2/nFcnphBjIjhtf8IuX4CUGlIIw OSsHziGmMtlzyG6jgM5ncBHP88+ZkCF6WhhB7vhiqYW70UciHVwJDX8T8To/c75CHxXy oEWFEdHf5cGPv1b9AESfSAmnvplRhZlvuGpFHmM95cAeudyaRZfBWcZoPVJeADeJH7e/ K/WdUc9QNKyH5zvetiIixq6jDU6vNcjOkLDJg+kdLfIuODDp2NCl4WG8VLg+329ZXZT+ JUWg== 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=rO+IZXT9LKk1KWA6F31yvd9awjDoLLpIxOtHfhwxtmw=; fh=KjOVa6Ph0vI1sgo7Mk3zrS/wkWXM+q+QSNwtkIV0kjo=; b=BgpWp4oPv+nuv8vC7eQdw0cY9OY7EjaQcDunK5ufW32cSIgwUlL7EdMgIjC8GoGkSn 3MQednCroHT27KbwpdzaGMcdanMz8qz4pojgZvLSJM0tSSyPoO0zBNWDhQPzMM/kM2Br IKGL0t9a8bKhkl6FWW5blfWKFRE8Hp+aMEX9JRmf74sQXxEiSF+PxggP6Db231kN3zXb ZIj4szpa+PB0FlwgKrtrZsHld2kEB5+ZLJ5WxpewgHR48moES7YrCM8oj7qlxcAwRUUi c6aLUZVLApX6c7ForkYEmmkXWel+3ofZUDTXR7RmQAemqClx13ZT2TFBkDRwqYB94S3p bmBQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KHeiJV9c; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id d2e1a72fcca58-7366adf3d6fsi4027840b3a.157.2025.03.04.07.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:32:59 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KHeiJV9c; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 45E408141D; Tue, 4 Mar 2025 16:32: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="KHeiJV9c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9B827800C1; Tue, 4 Mar 2025 16:32:09 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (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 C0484808A2 for ; Tue, 4 Mar 2025 16:32:04 +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-wr1-x42e.google.com with SMTP id ffacd0b85a97d-390df942558so4522842f8f.2 for ; Tue, 04 Mar 2025 07:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741102304; x=1741707104; 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=rO+IZXT9LKk1KWA6F31yvd9awjDoLLpIxOtHfhwxtmw=; b=KHeiJV9cVCFui7QH+pEY9+DmL9ot1GpvXh8J44UYv9pcvCtLzi31uXgsb5cIF5cld2 rczuOTqfknBLF31mYFnI7L0rAc5xdPZ7S3DG/aa8PugAjmdPXhWG4Xm1ZU5XuqDA19j9 ta0blnKgWCZ1x9nUJTtZoF0JfKcjhVO5Dt8X8LG8dC5c55mnb+wfWwUk6kCtjDIyeCoZ 6//YYcGU+rvUBax6zNKRljxyHbJWwve358DjnGEW+ag9lAYns8yomozLK7+TurjzOguQ wsQ34gtOpSb38czHuCOtClgddnYw2tpPRxh0d3Z/6lFkiMcaqJjLm/uUaDyxKlR0iP+0 zrvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741102304; x=1741707104; 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=rO+IZXT9LKk1KWA6F31yvd9awjDoLLpIxOtHfhwxtmw=; b=k+xu039PJlU2027VQJZyV9koQHVRDHQfotCmi6W1l7qyNS1B0griIryWrAx4EOkC79 NsKjUKHLzkuvCFHUMkYFuZZpDuNMYQ+0wGh5d52T2us7p52yOydPK5VtppCaWRs4XHx6 y6fFQ3M6IUWDOzDucjloR8I4hvXqXr+v0c3aMOh1LmAGY47SxCBlMZn2jVEb8NWtCcWs AwKmmNAWNOxHukcMlTjHCt3KIbYFWK2vzXWeUw8IMRnZXgTaMCcGhzhXBU9zJSzqjLjj uMW0seWdO5Np56Rs0tdOJKVEwYmsbGZ5++dXeBU5doEdpbs0lmUJiqhplN/W5l+M4dNP 9Xng== X-Gm-Message-State: AOJu0YwM0C9B+fK4nywPsus+BS7TOLcgMgAqIxh44iyWGv+vAgvKi/o2 Mj0T2Kg4O6lH8Ypb/x2UuSKzKRjj85DmE8679EqMo+fhwUFJqShylk8XXEop59neRaxiO5/WtJJ x X-Gm-Gg: ASbGnctUm3bVEomLMSYQjqC0MRevtZzwUXj32JfcD7V6OXnV8B/+nr44+T4uV6bielz H3NnKxC4LioO/0a8fcTCIeFjaX92ivpkFZRtKHIo3R3zIOFdlRQ8wbVibd5dclNEQ3Ds2XshTn+ AZ7Lrai1CUY3ollNV3Pt8m5CGA4eaOicY3vUOaKWaSD3wiQWKsKZpegpVGxgp5BAyWCbWnukHZO /2ZC+qnggD6JsF2crmruMTruZ974fEcGdAVPTwR7G52WMsdveHccbzEiUUvsw02uQJlp+QsjM1H oCKAQ8dl6K2BrpIQ7+5xfl+PqLhByLJPW1cpI0Vq3C9eEO9R2cT02A== X-Received: by 2002:a5d:5f84:0:b0:390:df83:1f5d with SMTP id ffacd0b85a97d-390eca52f6dmr18841852f8f.35.1741102304259; Tue, 04 Mar 2025 07:31:44 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:771e:3d0f:d9c9:2f92]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485db82sm17669254f8f.88.2025.03.04.07.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 07:31:43 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Mattijs Korpershoek , Nathan Barrett-Morrison , Greg Malysa , Oliver Gaskell , Caleb Connolly , Robert Marko , Sam Protsenko Subject: [PATCH v3 14/14] MAINTAINERS: add UTHREAD Date: Tue, 4 Mar 2025 16:25:02 +0100 Message-ID: <20250304152510.2832340-15-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250304152510.2832340-1-jerome.forissier@linaro.org> References: <20250304152510.2832340-1-jerome.forissier@linaro.org> 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 Add myself as the maintainer for the UTHREAD framework, the spawn/wait commands and the associated tests. Signed-off-by: Jerome Forissier --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c1851280e6e..27887bca55d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1800,6 +1800,15 @@ T: git https://source.denx.de/u-boot/custodians/u-boot-usb.git topic-xhci F: drivers/usb/host/xhci* F: include/usb/xhci.h +UTHREAD +M: Jerome Forissier +S: Maintained +F: lib/uthread.c +F: include/uthread.h +F: test/lib/uthread.c +F: cmd/spawn.c +F: test/cmd/spawn.c + UUID testing M: Abdellatif El Khlifi S: Maintained