From patchwork Tue Mar 18 10:46:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874395 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2442772wrq; Tue, 18 Mar 2025 03:47:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWcS9GejKhV1GE8hYg3XKYlI2d/2UY61qneg2oCnnOSFxmCTBzmvgOFkzTCQISBFT9CqIABLA==@linaro.org X-Google-Smtp-Source: AGHT+IELAKS/+ZYtIOtlBbu31aoJYv1cOIxuRW8mWNa4YLD7D6X4+hEykkrJ6Pdn+i5bKo3UmT7z X-Received: by 2002:a05:6902:dc9:b0:e63:d36f:9674 with SMTP id 3f1490d57ef6-e64af0ed6cdmr3249878276.1.1742294857468; Tue, 18 Mar 2025 03:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294857; cv=none; d=google.com; s=arc-20240605; b=UMXw62A7RZMpv73kkmdnHAbR5qBFRlFRaBJ9gqhFasIWHekxl3Dd+VRdBjwzf9thRh DTtrXnxxIBY0eQOvQXB1HFPKS2YK6Ppl8G2sBxIMqf3dqdvO07ZIb+xRae3gGZjTgNCO yApVorHLwlE7xaq5hJmegesU29N66E17mIh+P+yopQ/Oyzs7yfjWrHbD9D1Cbb+CCbQX NOBdLMZvGrbulKCURhr1hmUg8jfsCogTDBgogpsJwj7p+fE9+gr2rBalOONISvkNVtdk g8a/XPWAVCrDAIlpYe59ZXPiQu8r6XBoCgbUvN76VzAS21phM9PKRAuwDhlpsp7Qz8s7 zKZw== 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=eUVHl6Za6D6pDyge7r7bRk6nRvr2lGPQEthV8hlLudM=; fh=/A/7HXOc/6c6CcouLvhpR6G9BDK71gJ3BxLHRy92LCw=; b=JJYPzpiCmYZ9E8Uw8wfghNDd2c2fRThQlq9wmV7Ei2lkg1q4STbEeq6z5g46wdNm03 MwWx8ibYieb43nbSxshn9bkP9HGXqdxxaf1XyYFHwXcFqVIJiJtj7wCALfhWUaiFKF/8 QBi5g3mCv8xpDSRWkR9+9jZ/4ZDKwkdfeS62KX9DvJCtPclgEHBHtC5+xRsbaO8lff2m H0RGLvjtwQHHrljhjJsRrdr0j4vC9eCl0fkG3JSy0O3UZqoX3WBlMYgrIdvYiD8AxkrY XtTyXZB9iyiziXY8hBxhEW4yoiOC1q0gVDSZ7QjBeR+h+KKKJgWGstK+oI5RU4fnRsQ1 NiOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pV1o8aeV; 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 3f1490d57ef6-e64092dc0e1si6189586276.359.2025.03.18.03.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:37 -0700 (PDT) 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=pV1o8aeV; 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 1F3E18186D; Tue, 18 Mar 2025 11:47:25 +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="pV1o8aeV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E5B398186D; Tue, 18 Mar 2025 11:47:23 +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-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5ECD3805D7 for ; Tue, 18 Mar 2025 11:47:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43cf0d787eeso33328365e9.3 for ; Tue, 18 Mar 2025 03:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294840; x=1742899640; 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=eUVHl6Za6D6pDyge7r7bRk6nRvr2lGPQEthV8hlLudM=; b=pV1o8aeVGNvSL+EcEUa18EkzdpcFL5ixW+wzTCiyzkuWazmgGxFxvSu+HEbvYRrXdR 3+/wDgk9En9k/n/1LVWDLNZ4exXeh/Ij8Sk+eqTitKRbnUf+GzSSIDbHXfqcP59cu7Wa 9cR9sbXbWH07HN7WSl0SRCwiFdNQlRiRKjLq9Y2VY2gbSmP7/LxvudPj7ywU96wsmcJF lYPt9bbPGuLKlIRJcdNmgfwb1Q9cngnW4svoC5L0KMTNR/uJ1IbtZmRDztDsu7dJ1nRX Z5b45rtBO6B54LwYNqRhH18i6QoLWIt9wtLr08pBUHCRtLGtpqFUeSyBgyeTRQxR2pgf JCGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294840; x=1742899640; 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=eUVHl6Za6D6pDyge7r7bRk6nRvr2lGPQEthV8hlLudM=; b=MNv3D9hfRFkV6PFbXo9PyHA3dk4OPIoluk/Io8UpJl4GNOrFFt1te+P36gHCTjM2QW +oCyZ3DdXB0HSsVQ+aJ2YNBwSI2odS7xL0XFhr5z9zj8Fk7Eqske9skRyhPb235vmq2w tz5ZE4snShgpJPOT5EKp7v9qkwoFXKapCPaQ7Cf++V3e09ZEZS/rrfz0vkun2bIM9ijk S2/HyqxZJ2/Qq5jEptBAefns+o/6bVdVHwVI1CJYPJvuxv3Q2d865PINu5VfHOJrcRC5 P9/r0A8gYH6xmVuO3+gFKUUo2/OofOrMyjUXHIi+63WM+1yclGq1ChK8j+u1qj397etP ktHA== X-Gm-Message-State: AOJu0YxCPzQP6QWEV+QQrVTn/cmthJFoZ4q1W+l/lsw8Uw5PGLzt/Cyb GSF5tbjgBRIz0H93DGZyWg1AIzroYc1YUURIAK1JwS018xYOGwo64/RsAQI+cHgdW7/WDbZSEVP vez4= X-Gm-Gg: ASbGnctzrado2FC9pIwIE15b70SacLlI9+z+JHYLxEF/7pWpzXtE6tQYDW7UfxKiw4M PBFzQSczSCza0KoqNgbhiM3O6BXXr6zNhi84+oY4UDRQniwc6dNOYeUF9vqgKpMCnDFua/SB0IJ RJdsBZ6g27WHaTw+bjkw+Fw0lkCeSad+0wP93KrgYB2iWuXO+rg+zH60nrn3C4dG3SdK2IFBkzF pfeaJCW2/jjkXZAu0SNaRVVP/OxQXxIZq3TGMrRkN6VKs0bzC7Kf+WZu19LnkAfwnojcwLwid5N m9Y0Haij7xgtbT+sO2cMsfC1w+Tf8g9k5kolxWSJzUMSpIGSgRbp3QyfTE0nKYgz X-Received: by 2002:a05:600c:19d4:b0:43c:f44c:72a6 with SMTP id 5b1f17b1804b1-43d3b951a04mr15716535e9.2.1742294840522; Tue, 18 Mar 2025 03:47:20 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:20 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Yu-Chien Peter Lin , Leo Yu-Chi Liang , Jiaxun Yang , Andrew Goodbody , Vasileios Amoiridis , Christian Marangi Subject: [PATCH v4 01/14] arch: introduce initjmp() and Kconfig symbol HAVE_INITJMP Date: Tue, 18 Mar 2025 11:46:37 +0100 Message-ID: <20250318104659.1114340-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 50 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..32dd48803e9 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -3,12 +3,27 @@ #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 +#include /** * typedef jmp_buf - information needed to restore a calling environment @@ -37,4 +52,21 @@ 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_base: the stack to be used by @func (lower address) + * @stack_sz: the stack size in bytes + */ +int initjmp(jmp_buf env, void __noreturn (*func)(void), void *stack_base, + size_t stack_sz); + #endif /* _SETJMP_H_ */ From patchwork Tue Mar 18 10:46:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874396 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2442813wrq; Tue, 18 Mar 2025 03:47:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUiwzrICJj1ou7TQZD5i30P3zJUmdC4xa4E7y3D1RPR/3IcLVWwa00cbvdEpCEsF5DqISL1fA==@linaro.org X-Google-Smtp-Source: AGHT+IFGKhoDjJhEaTq8mDSxGYksUX3r0aZsD9WsxwxXcyl+0YzpOY9tqzSAJpivZieA1WQtYVJn X-Received: by 2002:a05:6902:2385:b0:e60:a3f1:b13b with SMTP id 3f1490d57ef6-e63f64f76a7mr20749119276.18.1742294867612; Tue, 18 Mar 2025 03:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294867; cv=none; d=google.com; s=arc-20240605; b=ab4Tg1C+G4N1MTKDrspcdsRT4dEXZ7GUMD72cun8DWoa3LcKbXVWCfVLyrujaud6CE AqK8RgRZbQiQ2JmZZSoPOsoLFuC23qdvb9AppfObCjVhFcubDJurnirPm54Z2w5tjAS7 Fk85weLsKnrvl2+uTzbL8aBxdcI2jbyjcGonLcnOkKsFAkLD/YH4HBvFE5DzY3gr15DY 5AfFQUyuiXTMuYxpbVjsSg9lZ1Siwv6Ur5M7GhMSUvpRRWl/RFkWjiWbhMQPP2PnBGMv ZxFjY2wLLnMeNuVKOqQqufVhJi9Ny/B4+LUr9F5bKnPs/yqdrHfyf+oaGm0ICVhhCUlF 2Rsw== 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=u9Aws54lCojzlmAYh4hyQ7NAp3mGWeR2F4tRNwvQTfE=; fh=gtP8kJx/P35XCrkWM91u1cdiiGS07FIWecfo4yVax7o=; b=kA/+2Qbb9FgGDRC7189lZLX4KbiQcYh49wFkR6jP8ODznDRo94O/C3nak+tRckaMSX 5y1q5HhSIkPfRveZlWtRX1d0NBddmRV2h5ivohzDbBePu2nkIuWBziqwvZPoinfgD70g DiDzJxDGXy91e2OLwNBeSw1fvsP7wtxrCySkh2eEeHNjbUQdG4VknXWxjzpOheaCdSAD 6LO/ceTpnNXarRZ+/6sP+Arz8bY2jT1reQ1qGdp76oMOmb2qAu9YlDYs3d3if5PMeEuf 2wthjpB+g2X0aeqRy0AQYs5iLdDZrxdGtDOViwR5qDM8RqtTTwRw4z/Uwv5ydVplhQ1E VoBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xPFzPUDv; 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 3f1490d57ef6-e63f1b4ef52si6691691276.240.2025.03.18.03.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:47 -0700 (PDT) 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=xPFzPUDv; 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 63BD481951; Tue, 18 Mar 2025 11:47:25 +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="xPFzPUDv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4A23180F4C; Tue, 18 Mar 2025 11:47:24 +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-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 3C92D800B3 for ; Tue, 18 Mar 2025 11:47: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=jerome.forissier@linaro.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-39129fc51f8so4786694f8f.0 for ; Tue, 18 Mar 2025 03:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294841; x=1742899641; 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=u9Aws54lCojzlmAYh4hyQ7NAp3mGWeR2F4tRNwvQTfE=; b=xPFzPUDvk1beKQPtZWO1+ufYwM6ny0hNOFUOUVkZ75aHE8dVwTut4uAgHfnPmRt3hV eS+mQf5OErC5aAsLbWP/kDEuzHpE2+8tHtXiLasdM5faFKslyQhBE8elWgpXT3LHosBh eOx7XO4+9q9vuDokiMWNz3X7r7x3KItzeSUyy54ULFfAiY8jaou3+YWXcoJW+0O5yrNT cVVBcv8KAccvI39D+kLF5xYAYFHiHzj6rNNYdsFLfxrPUUXKnS6pWK0FFM01RzasCitk Pz/oUgDFwMX6KKfR09prQSTlg3xPHGaSegACn4CP5Ox/QV7+XEV6l9AdSoGcBQBq/Wtv jhSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294841; x=1742899641; 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=u9Aws54lCojzlmAYh4hyQ7NAp3mGWeR2F4tRNwvQTfE=; b=HEUWmOdleCOkAc0Z1ZQaO2zwoHqp+SeDERK6D3wXsmumKpkbA/KY+B3soHKeIxWc9m FVE6gCNVZYbi+Yfp1899d7y/9ki7Jz/hOcyV3KbtLovxqpXtr74euZmWBwt1kDxGmTxW XFv2QmhW6nCU3lPDcedyP/ZG/30xWPaHbjJq6+UoApC37Gebzpg/MPq4ISZZ/sQwow0v LV+lPXFlQDmHsbEx12L6kMNZXD0/aNrRYHJwcYCVz+7aIU5i9HiwTh1lAKVkn7aZe7eE fqrqRn3X5I1M2wsPmOyxarxSw6xVrTqneYRjd7P3mxaRY2C+it4SyZ/7fcH3zeAqDaUu rl5w== X-Gm-Message-State: AOJu0YyWa3UZYvYmmzPDmqETt3o0hhhgqk4PaEu0JMwFAVRdocrq3Mdn vu3uOxRrDdhZhSVsVzXPNn8+QbZXTECYwfOikEA0QScyZkjuWesiB9oXDt7Q8nzWGpd6fJt5Rb0 oFCM= X-Gm-Gg: ASbGncvDEJxT6NzKB8c6OQxDJGjEvcQRiG6fZ/QKqUHkVvzTEUHJCPmDgB+DoKL6SBb /3dhcdkVWmVMQ6XPAnauJ+4I+Lwp5G4rNAsb2m/2i6dhwoH2Y+kb4O/8jfV1gKaNs611d/Dlfyz 8FUzrwAFXqQonJq8Py1oKZp4QwzN+5wffETqkQEbC5o91nUugjlLSoIDBZqfvlzqJltU/3e2iLt cXZ3Kxxwe72Wm9dovtp7x7/ieSTzt56mRF/goyG3uKHl8H+tBlYId3Y5k73oHtfcfDkkVB8K+30 veL0/wx7LmedlOJJhdQRsJH1SUXbePTCZCwNKrmvh3LOB47ji/72SQ== X-Received: by 2002:a5d:47cc:0:b0:391:3f4f:a17f with SMTP id ffacd0b85a97d-3971ee43fc3mr18049663f8f.42.1742294841472; Tue, 18 Mar 2025 03:47:21 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:21 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Andrew Goodbody , Yu-Chien Peter Lin , Jiaxun Yang Subject: [PATCH v4 02/14] arm: add initjmp() Date: Tue, 18 Mar 2025 11:46:38 +0100 Message-ID: <20250318104659.1114340-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 Acked-by: Ilias Apalodimas --- arch/Kconfig | 1 + arch/arm/lib/setjmp.S | 12 ++++++++++++ arch/arm/lib/setjmp_aarch64.S | 10 ++++++++++ 3 files changed, 23 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..81bef578719 100644 --- a/arch/arm/lib/setjmp.S +++ b/arch/arm/lib/setjmp.S @@ -34,3 +34,15 @@ ENTRY(longjmp) ret lr ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + stm a1, {v1-v8} + /* a2: entry point address, a3: stack base, a4: stack size */ + add a3, a3, a4 + 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..01193ccc426 100644 --- a/arch/arm/lib/setjmp_aarch64.S +++ b/arch/arm/lib/setjmp_aarch64.S @@ -39,3 +39,13 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* x1: entry point address, x2: stack base, x3: stack size */ + add x2, x2, x3 + stp x1, x2, [x0,#88] + mov x0, #0 + ret +ENDPROC(initjmp) +.popsection From patchwork Tue Mar 18 10:46:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874397 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2442853wrq; Tue, 18 Mar 2025 03:47:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUSRxORzd/8pNzRBpfUQvFrevgEhyF7+LkWENbbOi+qHS8I5X6g158oVROau3qpS7y9fzgIzQ==@linaro.org X-Google-Smtp-Source: AGHT+IE5zKQwyE+Ih/FAZIlCS+/Gbfxop8iPkz1XdlBQOxskinV5XY+4/Iahc52BH/3pM0keAWJs X-Received: by 2002:a05:6902:114a:b0:e5e:1034:db93 with SMTP id 3f1490d57ef6-e63f65b50b4mr21315753276.34.1742294877454; Tue, 18 Mar 2025 03:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294877; cv=none; d=google.com; s=arc-20240605; b=Phy0O8C3cQBD8lKsCheM2s2QmvXcDm88+EaNdlzI1MdbMb6ADOtfsFgUEOh+KnodRS HdiERYmItZSBM6vyvTzQ0okU4NYNLA9Hho/UYSJWsbEmwEfrfsfoC0n0WSuYHFC3t2Nm H7l0O0FEdRydVY2kD7ejzPTGd4WDL0FlWfAnCTIvDX/7ZmgpSb6S235R4TaDKVK14HYs rHOuCkauz/gJqY/+vjfpyALCi5dfn09oGNSJ7LFEw/aslIQmXbuxlC+aGhgGa1j8VAo3 l9KoeOlK2sImzEALPWkAJUU4PD3wb4wvIG2M+iz4BLmyeOeB0CGaD5vGxeyvqiZquYJL o/EA== 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=91CQhKc+LooEbAiV6R/y6WtHZQNtg2VBXsL24g8RQuw=; fh=IocgoaOXRz58DyN4egcnVrwQQi33ckQfWMi+mIprZ6U=; b=iEfJtixYBeUWOHWHiJts0K9GG5A3ZlpmBnGD/aN9cb0thZbOJWAQzpem7p3Qlgx4Bp jzCttE8FM2PXUZkzPxMru6yKnrMpjal/mFh5Wd6LqHxdaEohoJlRzKHdAWTRvWDfUBaN GALBXjADyANwqcDj49X9Qka+MmFG+gpHKDJCvW/JaB5C/AbAZKxd7adT1FHZlFkC7ORk rKCPFGxJuaW52EEMuUaklwAINNxvDXmuEmaVmZjKwc714bWinqcp04ZLJ9BCXytas5nr GYYA0/AsPiSVq08q0JOEDBKLW74c2dD4hFGg+trzmjhkV3NCW7irPRNOoNkzIsZWRKLV duqg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="qZt/PKBr"; 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 3f1490d57ef6-e63e552a2f3si9684987276.268.2025.03.18.03.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:57 -0700 (PDT) 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="qZt/PKBr"; 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 AB72C800B6; Tue, 18 Mar 2025 11:47:27 +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="qZt/PKBr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2EFDF80548; Tue, 18 Mar 2025 11:47:26 +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-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (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 3A10A80F70 for ; Tue, 18 Mar 2025 11:47: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=jerome.forissier@linaro.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43cf3192f3bso33199325e9.1 for ; Tue, 18 Mar 2025 03:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294842; x=1742899642; 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=91CQhKc+LooEbAiV6R/y6WtHZQNtg2VBXsL24g8RQuw=; b=qZt/PKBr1LodvLSd/OcBtYrNaX9nmnN7vbRBodCp3nSGXudeZHy1Naf45o781Rkiqd u8nmOtNLxgUkLnJ59n3ECxMQpgdl1c/KR4CcrSwcGTg8umPF6l82gzi8+TYxB1GbxQuK Xp1y/l4mYdUU0ICE3Z1E8fe4xxcYRsZyc+Y41Ozct3wHiAniV7j6DnRvA33I/aI3Jwei U9QzeQ4RF8GALU8pF5eCcn3AZdbQnp76ZasHlHl41INeK6x1XsTBt9BkMFmjJF9tTdwQ CdzzOdcGWV1u3gqdiJYr5WJHCziOu2fpdfz5RSxaZ9ro/x7ryJJA48BQ4TOqCHDkUCqq hgIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294842; x=1742899642; 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=91CQhKc+LooEbAiV6R/y6WtHZQNtg2VBXsL24g8RQuw=; b=GxWTn0V642GJNJ6K2jm3JqSLnb9AGu+P5UL+fflXDwvZdXl8xZTs3QkjEmzA07fDXG FrQ2Pfv3BgnqHrp9LCthdAymQIctrNKNKOwiVppaff3QNPkEx92D4upuF0IRJYvVr/kI 0wAdtaIGCbN1CU4bZ/SjHwIVfYcCcCHl0RroZQ9T8GeL8ITxvRJaoeyPR0mA4tGjl1PT F4DCFKlkwl3aZ6PWIB1BCIVU351DdVmJGdMNbSGNn6YpPLDsUw0aERL1IuOl0yxoaFy0 o0s5fxkQGw3mLg1c4PGH2/Y5L9pT1SRyHwURCMc3AaLXkxgkU8rC8rhmTcDV8uqAuYb1 pDfw== X-Gm-Message-State: AOJu0YzNeTNGsH1e/1hnJVUIZ+0TlNLM2nsNW8LKCu8FTe0XT3K620LI a9aCPL3Yv7Fp8TveQC3l4lz1LobPk6aUUeSAb1OVQQJFuDItyn8a2eV251IXq5G+xNqt/s0ts1I w3YU= X-Gm-Gg: ASbGncsnqUJWxMdzpDnO61BuL92hrFfP1Py0UO/O0X8ZED70gcqruq6CswQwygENEL8 Si/f2UcC5Esq2r+mz9F+m2HlIxL/d7dmfGawla4cAmPwNFyhMCW9UOQ71c2aqwNkPk5Zl7jwcMO k5vObkfyCsKgwiGbRnbf+FUksm+wHw7aBwn5TO3OLCfstOr/hFr5qS6uqb3uxVKA4p3EAxYKKQk Qk3oc3w4te9NY+U7E2fZa3mqVJt43AZJMbBIWC1EhPo2HRtgKwvQ5e/w+ktn+tRMFAvUfNF/0k8 ibsTmUpM00Bumc+n9p7d2CMy+qcPrfrmUaB+K5GGmbFulTP5z1iWSg== X-Received: by 2002:a7b:c00f:0:b0:43c:fe85:e4ba with SMTP id 5b1f17b1804b1-43d3c953a27mr14313365e9.15.1742294842416; Tue, 18 Mar 2025 03:47:22 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:22 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Rick Chen , Leo , Simon Glass , Heinrich Schuchardt , Jiaxun Yang , Yu-Chien Peter Lin , Andrew Goodbody Subject: [PATCH v4 03/14] riscv: add initjmp() Date: Tue, 18 Mar 2025 11:46:39 +0100 Message-ID: <20250318104659.1114340-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 | 11 +++++++++++ 2 files changed, 12 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..9e1f3d5749b 100644 --- a/arch/riscv/lib/setjmp.S +++ b/arch/riscv/lib/setjmp.S @@ -59,3 +59,14 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* a1: entry point address, a2: stack base, a3: stack size */ + add a2, a2, a3 + STORE_IDX(a1, 12) + STORE_IDX(a2, 13) + li a0, 0 + ret +ENDPROC(initjmp) +.popsection From patchwork Tue Mar 18 10:46:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874398 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2442904wrq; Tue, 18 Mar 2025 03:48:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXKgN1tBOdNLytNri6YQe5Hxc+XbZLXv6LkIFFo4K6hTmEaRfO5hefFY4/ZJpCcpAxWugiRjg==@linaro.org X-Google-Smtp-Source: AGHT+IFnSXDXyEMwOPQNJyuUYoI+JlOLVu+H8h7QyVn8c7llQtqlOff0lQ4Jd59sgcJAeNp6T7d0 X-Received: by 2002:a05:690c:6081:b0:6ef:8e4c:65ea with SMTP id 00721157ae682-6ff45ef7195mr193207017b3.5.1742294886046; Tue, 18 Mar 2025 03:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294886; cv=none; d=google.com; s=arc-20240605; b=OINf6G6Vfy/Y0ALVL/9nEIrKqoewbbQBUEeFNGp8iVOahIyQzObZGYkPR8D1hAXRQx JP5LuPYDcWOpdhPSdkaF4rRUX4i1AfN9I8tVMR9pfe9ENyjKxA2DbQI/AcEKTVTtDo5S WQ+3lq8QXLY+Dm5uSgd/g4R2hCSAEqMp4YjNPpPs6UR/0jo6LKHLq19RBQ6OwBv3T80F 7rmbiNnQWm0mvLiRE4rn2KUwv6z6eOIi9FiwXS3PNOPhJrPErGitnEA9yUBfoUCH7RSX UzZ6HxR8RQDWWfnWHvqHJ2wmM9VinbSLMCE+UShtfhmpqAnVYeXx3UBOgHHTIi5Vssfw u7pA== 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=TUPMXX+5sSwyIqdYqFFgUpRfjoD0n8qbhqt4q3YOLUA=; fh=HaKHCOHL46OAAPpM3W6HDLkDmJxXWc+qggc/xnkS9u8=; b=b8ukp+/SGX/7M09EoX+xGFCCv39fXpdUraNaQgM8zUxdzf9GOsJHcd4LFIaiB44sTi 6qkteERMzocc1+G/jfDkHZ4CQcyJIYWGdwgaJmxQheItmmpM0PQPrSoBJZ00CJL/p6B7 IrVzRk/9HGpAGCzt1CIdwcVMZXTyVPDknC6WRAk+s+bvC1bkDXCI1DOZ144Rx2IN98mL Sjd9AOFnC7ps9nLsFf4xjQOlNiVGyZUpLDrVSA2tlaHYzAqESC5DAYkD5jOTdi+DK/Li Az6l4WMdOaYIwMRlXlAz66xA0sNr2kDeVY92MIeN/WRu306/NozEDKUpJ3xHecHG7i/W hhDw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QZ0OQDGg; 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 00721157ae682-6ff32857a24si88492667b3.96.2025.03.18.03.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:06 -0700 (PDT) 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=QZ0OQDGg; 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 00E658129F; Tue, 18 Mar 2025 11:47:29 +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="QZ0OQDGg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 185CB80548; Tue, 18 Mar 2025 11:47:27 +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-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 9D1AB800B3 for ; Tue, 18 Mar 2025 11:47:24 +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-x344.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so31940785e9.3 for ; Tue, 18 Mar 2025 03:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294844; x=1742899644; 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=TUPMXX+5sSwyIqdYqFFgUpRfjoD0n8qbhqt4q3YOLUA=; b=QZ0OQDGgOaMsA+X34dChb2rn3VTbAXHRPktikZCn2IymknNPJhk+xHujju6z/z0Jto pCF2DqZF56JRsmL+Jz/lqXPzR61D/QkIYOy8QMz4OAMU5QJJS+4ggb1wgWgBq4fTY+nl x5TLHoqORUYXEzeLOVCY0Z67lmZ0mwHRM0iCVW4QvzwZmH4s2r4IibTXQk9UXvUgN16X TJFFktA+RrDvUMJHIWzXV19wfeMdCd89KAbP5iG/8rG/iGjso34xvrruR3Sq0PaTej2v cg9WgGARLMLY4pk46B3gMF64JMOlPrp5xIdPicHs62pnqSb/4vcZOhpBMStASyg3Lzi6 HHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294844; x=1742899644; 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=TUPMXX+5sSwyIqdYqFFgUpRfjoD0n8qbhqt4q3YOLUA=; b=k0PP9y2eXcKUoyPCDXG2eD8AV3US5eMjD4XS3GWzi/gUhstNEhHgozrb8Lpnbc5LPC IbwXPpAcThIEPIHwEPnT7eVlwXUlMGU+za80BmLfhTsfaZrSlrQjYIoWYkNVpEioRISk KjkqrFikukG6IV+UodSSBWxXUbZg3rRM+IdEBTCrZxOi6D1TlHnZMV2BfJffIju1CnYx Fz94KNsQiQEZo6OKL07dDBbxNhMPHtWhf+IqxZJNn5yvD+/RV5uARt0XMFndMrSEOSKa Ee3LTa/yTHMBu9WPn+9eB83cq/7z4YFS4uxHBlxXD8WvXyl961R2IzXKNwOQtwPfeuqW grzA== X-Gm-Message-State: AOJu0YyJUE0MFCMzumyhraPCfclhn3HHyketo3XSVScyeg3oThdDYm3G BaOHFLMrh1rX0RQrG7Wd2mOqCrILBzsHB7awzol3hcPEZTzQeaDDajdyxICHcsMnb51S62kcOjp YHHrHsQ== X-Gm-Gg: ASbGncvH08sVOgxWW7Zv/epdAAA3yCHq9pKXuYcL902SQRt/PP3FPE4rB8z4iLFc5Tn d3D3iSq7veNPzAWriGbELp2wUMZ8u+ny9EsaZUaFhLqeKcto1M7cQsrvam52hDatNuOiMCPMXVp WfIIp/ZyinG0c/v9mJPvUXcAaFVGvfk7POlojqiMvPE3SET2T8+ej6FY2OLsMUunef/hkZD+fBl x25UznycKNfk0L9EMonLQEOMPLjsZXg01P14o3yb8X1xXi2OTZfoTHBJAwVkrvqngafZsdWO041 M5ZzDdnsm7PNp1+aHYgt763BpaGhLplv3hZsZj2Datqw1wFOYw2nKA== X-Received: by 2002:a05:600c:138b:b0:439:9424:1b70 with SMTP id 5b1f17b1804b1-43d3ba2962emr19332985e9.30.1742294843741; Tue, 18 Mar 2025 03:47:23 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:23 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Simon Glass , Tom Rini Subject: [PATCH v4 04/14] sandbox: add initjmp() Date: Tue, 18 Mar 2025 11:46:40 +0100 Message-ID: <20250318104659.1114340-5-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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] with the exception of the additional stack_sz argument. 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. [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 | 175 +++++++++++++++++++++++++++++++++++++ 2 files changed, 185 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..6e72d32cb4b --- /dev/null +++ b/arch/sandbox/cpu/initjmp.c @@ -0,0 +1,175 @@ +// 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. + * Modified so that initjmp() accepts a stack_size argument. + * + * Copyright (C) 2006 Anthony Liguori + * Copyright (C) 2011 Kevin Wolf + * Copyright (C) 2012 Alex Barcelo + * Copyright (C) 2021 Ahmad Fatoum, Pengutronix + * Copyright (C) 2025 Linaro Ltd. + * 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_base, size_t stack_size) +{ + 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_base; + ss.ss_size = 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 18 10:46:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874399 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2442953wrq; Tue, 18 Mar 2025 03:48:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXywfwuqSLM2LXQgI8KLOcMhFM/gehlmm4eS/qlGLcEl5uv1WJhSYua+6bogSp7AUiDv7z/GQ==@linaro.org X-Google-Smtp-Source: AGHT+IGM371aIuoV/b8KYQV7XNA/L/ExRG1/RUXtbYe3s/fg6t9SKCzNIC8ZzPYz9rrPUh+SXImp X-Received: by 2002:a05:690c:4b93:b0:6fd:42ed:c90 with SMTP id 00721157ae682-6ffd74abce8mr43937857b3.16.1742294895836; Tue, 18 Mar 2025 03:48:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294895; cv=none; d=google.com; s=arc-20240605; b=Cu3dmds3tAuBQIF8IB5opCENIr5atwGs0zfJOCs9wGmOEhpJZDpUX/l+sRDfxjpQY0 du7bGKg8VkMgrS9Pb2MBul8Ee+leffgi5qAApsKcXm0mO4iXGT0LhS40Uoz+n4+FP7PT N1OtIbiozK7H1CVF+UcStDFlw9uvnU+ao74rfjLZiOXUk5qQoI8eX93kyeFeuGRZR4Or QT+AZ2l2cT2feP3ysbCxx6WrgVhqoRcev1eOarA5g3LAb18NLpQLJRScJaZnsuR9xcgB j/gOKXZ9xvkML6fv51yr9BP16rifu7WNxZ0t16zui5rJ96iNori+XtCrwHQUkZvTZR5k cltA== 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=9Wr0962nKSa8gzKuTD03RUSdUdB+lmJXD5dXPdk4D/w=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=e1wD7GfNW67qZRdMfvieu4JK/iNnI8/jZA7k7W3GA4R6qRc2AwDNmydhMQk9FWUvrr BXw6Mh0nfllXuEG/3mGjJ4xzYRGoS/fhWjP6bssfjx3QV2LchEDKb6XtK1xPXTO8eQ8B xHpRA+b/tPf5ve+wKpo/JXVQGYlFF+5F2qGk9d6SB4KzA3AjnISKP/TfpLsfDg7nUR+u Umk67rBZvxc329YkoK3Bkg+Fyf7TAMU2jEebOX6I2GOsTLLWS+CsDNE9NZ7g2vx+A5um pzeDlwlK0MODxjasIpYFP6K4MNhyrXBzFGEB/qfPp9Aur80b7If92POebeqM6fHZElaR gPwQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fhPxw+e7; 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 00721157ae682-6ff32b46219si100837117b3.295.2025.03.18.03.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:15 -0700 (PDT) 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=fhPxw+e7; 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 4D72181B42; Tue, 18 Mar 2025 11:47:29 +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="fhPxw+e7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF1AA80F70; Tue, 18 Mar 2025 11:47:27 +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 CF34180107 for ; Tue, 18 Mar 2025 11:47:25 +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-43948f77f1aso22251905e9.0 for ; Tue, 18 Mar 2025 03:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294845; x=1742899645; 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=9Wr0962nKSa8gzKuTD03RUSdUdB+lmJXD5dXPdk4D/w=; b=fhPxw+e7TOmpH8m4wzpKcMAkQIuMKmk31km8J9qGgbKmjkp75XKPbxBTwjBuP1IMPM AuQSeDrz36rgbWNS/YdqZJzHT5u6gZ1YlUq9r9MBUZJ2dZYbVXWunLcKfhAdS3S7mC89 Vjbi+1WyGFxnJgJg6xUIsH8TzW0XzhXygVF90Quwa4syxD/17t65ekOqRVydesu+nToR 8OblGiyyOXKt4X6XAQsU/8rI6DhtNwr/5w11kHaCNkiYVdW4WbryX+QYiSEE1+deo3dI 4DmKJfAGo4EeOy3G4NRwRMX6dNEaQS5sxpEBxiHee9fZZY2f6mYJ7QnYIdmyRzggIqR5 1lKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294845; x=1742899645; 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=9Wr0962nKSa8gzKuTD03RUSdUdB+lmJXD5dXPdk4D/w=; b=LUE8cyUUqC9YpTeRFp/z7i5EWgruVkJXVb2qJrGDdO8OU5RRXZUTlGbkIzFV9sDv6i DIxl9m/jjANPxoPji+/RhBt0VqIYn4kXCj2qn0YdlXodv+sVDse+Lwes4m4SWDbMLfKt z9cgy2UJUkUaL1KioQ59Kc2exdXbIeRVkQj8QKliyPha8da4Ua0IFw9S0nGNampm3HjS rGB+vbPZfHMig/v+EztY9dTBFdr00Zd78aXmrpKy5y6MN+9+i5osSk/T6Ag9Zc3OjzOk nFy445WVV84t5htCNecCvq1K/O0CP/B4LZx1Xx8pLrOkpSSieSEjo9eR6lj1B1gzhm+W jTvA== X-Gm-Message-State: AOJu0YwMItV7ZFidYTAH7TnG8igqNKC3Uv97lrrQ0YmcTatZuqUpxZzm zgoc5bcerJR/xCQaJ2X+ffPKwfl1jPapaAjcJmqcCQftq6Lyn/AkCEJ+vaBshhDTwVSNus7nUGp SyJg= X-Gm-Gg: ASbGncvhOlWJMGFrx1x4OzAt5ZlcP9aaSltT9LSbKy9tjwMYKq/+fNXioYZsdaijGLJ iXbrxP/DlQ0ht/qYi9FG/jhaK0J2CBzW6FfxFHtO8gGq+es7GjVNmleBw1+S5+ntf2GE5tNRe1b vfNHPoh7IwfG5002s5dFLUJm4mXBPWx6mtkNY0ng3EszCh4VRFT1MOXtnIf1fSf3Wia3LF0xok4 E6u23FHpvB5tFbypb2Ob1jyWW2cm700jPx3xolQemzYq74dx1ClTTYzPAUSrbTMcKnlQ5qMntJ+ +QyhehdE7dm8j4H1gPDGSQjHUEPYdw8l2T5ISG0+H/uAyuSL9KZhAg== X-Received: by 2002:a05:600c:1c2a:b0:43b:ca39:6c7d with SMTP id 5b1f17b1804b1-43d3b95013amr13736045e9.3.1742294845108; Tue, 18 Mar 2025 03:47:25 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:24 -0700 (PDT) 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 v4 05/14] test: lib: add initjmp() test Date: Tue, 18 Mar 2025 11:46:41 +0100 Message-ID: <20250318104659.1114340-6-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 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..5b4b50b3f0f --- /dev/null +++ b/test/lib/initjmp.c @@ -0,0 +1,73 @@ +// 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; + /* Arbitrary but smaller values (< page size?) fail on SANDBOX */ + size_t stack_sz = 8192; + + (void)entrypoint; + + ep_entered = false; + + stack = malloc(stack_sz); + ut_assertnonnull(stack); + + /* + * 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 18 10:46:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874400 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443002wrq; Tue, 18 Mar 2025 03:48:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWFSqHQ+gH5TM27f7k69PdXWiwVcwdFIE/5H2cr5BTWYGqJYh4ftu7+DpUWfT43IBT51HI7mw==@linaro.org X-Google-Smtp-Source: AGHT+IFY0W67Qk9c5zhX1Fu18n9n11jIyZhlrLhA7i1dIEiSHXDVYnPLULrgtqHw6CnMnLYInnQi X-Received: by 2002:a05:6902:208a:b0:e63:3e41:6582 with SMTP id 3f1490d57ef6-e63f650dc78mr18508267276.14.1742294905868; Tue, 18 Mar 2025 03:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294905; cv=none; d=google.com; s=arc-20240605; b=h8D8oYl4IzINQsJvEtycVkuClIhFwOy5LtXTxdixNrWT5pskBYRqtLzHPOv3F0Ye/Z APaf1bLnjAlxY+CRC8V7UpGbWpP4DrjYHj9SjXWiq3hlkUmkRfN0tDAYGipvG+gFovwu l98u+Puz1CFVggrT2rPhA318YnLqNm+tlghGY3o9Ml4FNswWBsom+GZrgXdUmtGAOWGl +qK0eYgYk0Bjn+QIy6MeaY2fVaLxtd0QlGbR+R22yR834rx9SwsN3UGsWi6ImbtiOXI2 8fRbG+PduGbIYzAcnAIQQOZHB4YuDiYCWs84s522s/vfCIHM1N3DNzHosEL5g1jW1XQr 46zg== 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=+tmM38K8tIdiO7TPc0HndOjbZ2fOYyIuvmRuc6vMa/c=; fh=r0kKPF/5+kOtJIdssgiBs6nhQ4F6LOarMEJPzzFOGy4=; b=PpWrptMi3nWQUpY5jRe6qq92R4bIQ0ncw6oIV6Y+dwNr3vZIhABmLBMIYmDvk9dE8J Ud6tOrbTuenZgrshVddknp3GHFjNl375QBfGMLSWu6GHfl5XBYN3b6y0Y9VE9+HnsYhb Xsyl7RTyhz9BQAW3OVml1Yskt11XRzI+B/YGuy9omyEGdDlBCKCoP/fP7tDOUlLREZIC Aw1JGVkixU9n9hW3QNwYWRmoRJBC4XCMTsYFzBViskuuFZvFZ4CY9oT6pP8Foa4fUU6V r/T5GPM80Yf83woNenLC1Ibs19nO7fI5HxC3wCIlONGU//JCyKCuF+bqY9Lz2idy+IVA 8Pew==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xKbX+ArU; 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 3f1490d57ef6-e640cc8835asi5761185276.12.2025.03.18.03.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:25 -0700 (PDT) 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=xKbX+ArU; 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 9FA3581CC5; Tue, 18 Mar 2025 11:47:31 +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="xKbX+ArU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D1C46800B3; Tue, 18 Mar 2025 11:47:30 +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-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (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 4F9BB80107 for ; Tue, 18 Mar 2025 11:47:28 +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-x341.google.com with SMTP id 5b1f17b1804b1-43cfdc2c8c9so18215055e9.2 for ; Tue, 18 Mar 2025 03:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294847; x=1742899647; 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=+tmM38K8tIdiO7TPc0HndOjbZ2fOYyIuvmRuc6vMa/c=; b=xKbX+ArU+SUK4Dj8gA5g+l714CHLGOAh5Mnpcluv3xWD045OEv1aCqHbB10b6CYRdv cUeQxtGguF7Vy2EZ5PhXwUmX1RyGFNVKtH+4upO2UfVjelj0MEPz/nIE3kp+JdfEzIun UzaCRSACCLefh5lzfjBMEAXXk+gpYaLz9OtfikMZUKzcw7LipL04Z6ACxWbZWLwprdfD 2NHiuM7W4tGUOQJxDNFCV7aP8NZbfoF/s0Nc17/+H3uatLmTdoDEhQqsJkCiwhpRSW+y fgopSpGlCVRGI7g7sDApLi6Je5e2DE+pjrcyq+6OXdrLnPjmG1Q9SbJZJwJ8D4XrBmN1 eyig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294847; x=1742899647; 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=+tmM38K8tIdiO7TPc0HndOjbZ2fOYyIuvmRuc6vMa/c=; b=QQmUGCo3Gp/46Qe0RSuip3qu7dyC+I5gwXnyG3fI6lsguqzJy94Z2fT1bG32lJ1F4E hqCaKyQ8sDFb1TpocW96QjdXJD18jQykvwa6owiNuupjfNT9PALpWSdyMqjtXWZ2LdOv HLkcq9sD4TXt+rhwL9diK5lHB8wnk0AgHERRp7U21wz7SQoC+PFJ98FgYulJcA642o3P y3oAzIkrgfVQYkXynQoDH35SP1Rmzh66/2S9N1hfottg+j2ls4Fiw6+OS8JHQtwSQWxa K6few93bE37OMPzgepoTdB3ySlOCIZu6atU4cY5imhhpGHEij/EGp335WDy+VljcEvjT qHKw== X-Gm-Message-State: AOJu0YwNZZ56AoslTsR8JRNzDCy8abKgZvZwwowtpOIO61SLOgGr2s+S GaovSEHQt3k5lYJ3rja3s/6yabKs0y23dmVMqld/rbkvuDj6jPV8yVorhrbpo7lBm131MLt2Gyz 8ry9SpA== X-Gm-Gg: ASbGncsLQ7E8Vu5HefVe6qNHVGOh3MpK05Acd9IXHlx9I2xA8gd4zOAGbzXHeT8gbx6 BR+VrOEDXo4UWpc5ONz8XWj682mF/VyBfHIkGpKtGbkiwp225AWQnVRfxw7asWJjnv0fIxxzd4s KNomHBamQ5WhHNmvoOoFA5uP+sviSEaNDyqTqKQyspbcxpUv+kZpSNDZtqM09fOw2pnvb1hnzDh jrPghOQ8q0zR4gNGenqjpZbKX9fdWqkwB3jFcS2iwNHuDiGtZyzv/LaA0BEts4lP3k4inEk1u8U RGAqpfsnPCPUO1eMrqYUZh64Prh4c0xHCsnmgDARjcnJRXmPnI1Qsg== X-Received: by 2002:a05:600c:354d:b0:43c:ea40:ae4a with SMTP id 5b1f17b1804b1-43d3ba14c74mr14023785e9.31.1742294847342; Tue, 18 Mar 2025 03:47:27 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:27 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Christian Marangi , Heinrich Schuchardt , Vasileios Amoiridis , Simon Glass , Sughosh Ganu , Raymond Mao , Patrick Rudolph , Michal Simek , Mattijs Korpershoek Subject: [PATCH v4 06/14] uthread: add cooperative multi-tasking interface Date: Tue, 18 Mar 2025 11:46:42 +0100 Message-ID: <20250318104659.1114340-7-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 Reviewed-by: Ilias Apalodimas --- 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 a21b3378fa7..db9debaaeeb 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 a30ce1595d5..cd7d04528c6 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -160,6 +160,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..c3f6c84c234 --- /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 18 10:46:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874401 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443061wrq; Tue, 18 Mar 2025 03:48:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWpTHlc56Wc0g8NdWWOWoWj8D/3hWschWyyYufwhcr5vlFfy8k0WVibc4iwNrwhbjaCf9xbZQ==@linaro.org X-Google-Smtp-Source: AGHT+IF7Yasg2Po7nRtJbtIqvv+rlSTCv5e5SkhF/5YB/JdS9vgPA+ZKrBuRGVL7eGn1gGEww0Uh X-Received: by 2002:a05:690c:620a:b0:6ee:8363:96d3 with SMTP id 00721157ae682-6ff46090484mr219908417b3.27.1742294915885; Tue, 18 Mar 2025 03:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294915; cv=none; d=google.com; s=arc-20240605; b=hWvtYo8rJozQyjtH71G7tbrO41aKacgb1RVjGAlU/IBGvsondcCQ3nGdTpGrGB8CPA iOepTgTb7r4UHxFqvFvGxeon+c7HkP4FVks+vOA5XFYQk/juTYPRCWa5pgyYATyEJU38 i7Ifd9O+GzzUAIgp8XSaZ5o7K5f7ShoWckdqJlIR6mtTuB29kKgzODBsvlZVqIrKCixx QJMizNLSaB7OCFkL3POLJH9IOqtJ3KvgVpQb6orOk0tPtSQLPGNUtldzjJbs6ghcDBA0 UkRMc1rwpvJCBqjvw9n/Q92h9toVFIjAlLHi9dS8aUm+GdXrHCLjrcoJ76s9PjQNfL0f 4S1g== 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=y421ZCXdbIuk+CO6p9JQkLRemHxOxOFsYoJqtKMt0Rc=; fh=FcJrLuOZm3DOgvhNhuu9RcOXf23qDSxE2e4MWRi7Xy0=; b=Fnfd5Q0VXQx6IWTSCL+YT7ed/yetAyEbnd6clNVVnreYH7AqpCnIhcJQCfMes4nHSl tqVX3pn2TPg/JUD1gT0JiTi+aQiYMsjKGdCVMn8W7fIt0iRqBNRyRPxMfIlrv/eFddg6 f267Y15n1vQ5/VLMRkswD9WyGRGivgJroXZxLCQuzijy0C1uhbcj1FJnpRGp36PdsWWD g1tlLM+myHOBCGPEsw2kxVEvIlnFyYAP8oFcqQ76xJ19PxGUod7ePs7gt3csBxQ737vO zoAPMyYa5Ss667hZKy+8qykRt1a0CL6czHcLpq8Ue+OnTz4bZ5+9lvBWHQhz8ac70+d/ hcIw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zkTcUXit; 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 00721157ae682-6ff32866c73si90255097b3.149.2025.03.18.03.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:35 -0700 (PDT) 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=zkTcUXit; 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 EE4C3819B1; Tue, 18 Mar 2025 11:47:33 +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="zkTcUXit"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 43339800B3; Tue, 18 Mar 2025 11:47:31 +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 3EC0C81A0E for ; Tue, 18 Mar 2025 11:47:29 +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-43cf0d787eeso33329685e9.3 for ; Tue, 18 Mar 2025 03:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294848; x=1742899648; 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=y421ZCXdbIuk+CO6p9JQkLRemHxOxOFsYoJqtKMt0Rc=; b=zkTcUXitod9HvRA2DSxUSlhFPSR+Dwn7REvAa6cvwlSKTDrv4Kf3FtSg3lMpm/iCv/ 8zQN2YIhuLQNPzSo0kYizU8YJXX5OYAsHl4m0E9G9MYM5IpR0H8Tri7U5iufhCRly6L7 G06QRqHwJbjPouatkeeg8UsnIR8Oho4Uzci1E3mXroGwvXCrrqi1Foz0S9Uno5xpuM/u ZcW0u+xzf245b+6BOjHPxVNOmUSgDIm35MFpllqqkXWx4AmfBTX3vZmLUW21HHFj8GNI b+7bKS4xFEKT9vwitF0NdLlcXAepTww2dsPkEUeYKIWIK2ogTL8DXxPIwOcprnp2Spex I05w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294848; x=1742899648; 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=y421ZCXdbIuk+CO6p9JQkLRemHxOxOFsYoJqtKMt0Rc=; b=l7MPM4moDm6nydjYqZo7ACYOf3kMEPuLErkGzgJ5uYb77Hs8oXBxGeau1mixSmyNze YEqyYr5GpC6yksUZHt84CqLHBV9n5pzpiEXr5CVMOHl3p474FNZWyakXxiVBv3W2xNdw fO0zmX4RTLZ0WJ4rQZl+Ch6nuoaBxB2aSxgaBVGKAxZIfRIxvzZWEjLxgbnR1wwKz+ox EWbCjiVkgi+J7Hacc44zs+0eONjg5TZKbUU5a+PlST0nP8fLp4xWD8psMLc+00lSXNrn QoEZKJf96gNTcpymTsSp+L2hJK1ZV2pAmykm9wt7iPiOplhcAhy0mYLEuzHJA95l5bJG AYXw== X-Gm-Message-State: AOJu0Yy/cZ+lCYPdzHx/uiFubTwERm+jAQ3WIUFf7jCtEjG2lchUk/g8 vOtGcsvJMW42Mdym0FniReUlLZAQRm0KqWGej6KLbzdaXoHf4XUcSvuG0Y7233CoKCQRWhgO60E iCKg= X-Gm-Gg: ASbGncuOqLZXYUrghu+7ps9r10S5khKvXVIF5DT23gNXBkkQiYvQwLQfc7dx7n+OHQP UseNlhpnY3nGOLw0GVVw6oxNSHPaTSxLml29nN7cARcqoHbReSC/KjmXDb4SccQ50AvY9A6WJwF Q4/PiRSzRx+s2VSu/zWKUUmmg+CSiimxWnYmSNioyw6eGMO77vtliuFEVQP2RSd8E7yPX2gDKgg qDGgB1dmZp/ORhkVZOwr3laA4QDOfNEPuFBeu/Q7dSZaivG064C+cdKhLoxr2z5CifBeeXDjBQQ mlYyg4xXECK92NbLJ8x3CyjqLorkWSlf+Lz0kakV1jy2vKZsBhGyuw== X-Received: by 2002:a05:600c:34c1:b0:43d:22d9:4b8e with SMTP id 5b1f17b1804b1-43d3b98e5d7mr19413185e9.10.1742294848466; Tue, 18 Mar 2025 03:47:28 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:28 -0700 (PDT) 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 v4 07/14] cyclic: invoke uthread_schedule() from schedule() Date: Tue, 18 Mar 2025 11:46:43 +0100 Message-ID: <20250318104659.1114340-8-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 Reviewed-by: Stefan Roese --- 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 18 10:46:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874402 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443126wrq; Tue, 18 Mar 2025 03:48:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWJZmLqYfKrgcc5pJeFWI3Ab/ud6X5IZJt+JwpuwvzD/45UP3lDYyMY4G0e6q/IPvuJC6uJYw==@linaro.org X-Google-Smtp-Source: AGHT+IHCUGfTWR1WSH9JyA/vE8PCPVCHUdyH55Ig3BONybp3+zoVhBu4FSpGeM9o0naqWxDSPvQy X-Received: by 2002:a05:6902:18cb:b0:e63:f12d:9103 with SMTP id 3f1490d57ef6-e63f65ccdbbmr20096300276.45.1742294926929; Tue, 18 Mar 2025 03:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294926; cv=none; d=google.com; s=arc-20240605; b=Cv/uOBVg6ofU54Rnbwphq6gQFS6lWW2lBwg7Qt/gpg+WSaz3yii2o1M469nnArew/w iILNchVrgHrWceGUZeP7kyjrsWRhiCQmS6dsQ/OkAgWnEdg76WHy97r0nhOd994rbj84 4xp09BPTM3On+I4C24YrQSljkjP1D7ICb80s2C0TDtXAvro1Mkg1B+Qzjr42Uh7oHw0d HomBlIdk9RC/ZROgdjeLtk8nvsOSckESDB8YTJlrW8wLqR2AJ/KkTsaHWsSRWEELvvTf dk9u97o+VTrShShyrqWepIKDnBMZUwUwZPv6g3otVyvEMG3mQ/hzFom5MU3uyLjI0UeL e/Ng== 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=DqA1qiEwfsjB6jI0ugIZhb0BBPHUo15b9Aaz2SzVmLo=; fh=WSXgq+dxaJSHadwMDVBKq11PIkESctA8ND/ZfWAV8a0=; b=AMNTpaEopFDIAXWo9xhMvl7b15zmq3KSi7N3oydUvrI3IUBZZU9Ddx5wZItpnT33a3 JgXrox27sWBaPSuuePI1jNkdrCGSlFPWMeMqJ+uPDOJ1AlsY31108Dervkoc6AnwsmBZ G+/a9BDawBV/Irl+4B8SnUhjS3wU90sW/A0CX1oi9JG8hNXUNWgC36uHOPc0ZzG6cxDF iOQMN4f9iE3Xb58wVRwL5pBwpsAQaBUBlhMvfGEEulhRTtmyds427UmFdaxe4sXpuN2Y QI/eUAs1MRJ3lWPGwGBEC7yHb9/QD7JM8uTlQ4nZ9eHY03qnu07YbiFSWx0VRRS21aBO /FLA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ArGiOnOZ; 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 3f1490d57ef6-e63e5772836si10082793276.453.2025.03.18.03.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:46 -0700 (PDT) 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=ArGiOnOZ; 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 40BD281C64; Tue, 18 Mar 2025 11:47:34 +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="ArGiOnOZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D94D881B5C; Tue, 18 Mar 2025 11:47:32 +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 1E65C81C67 for ; Tue, 18 Mar 2025 11:47:30 +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-43cf3192f3bso33200375e9.1 for ; Tue, 18 Mar 2025 03:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294849; x=1742899649; 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=DqA1qiEwfsjB6jI0ugIZhb0BBPHUo15b9Aaz2SzVmLo=; b=ArGiOnOZgOyDPCGGYCBmInDVGiFvUxyntun0W7q5bQVXXKcC7Bfv/uZLrh/XPTpxxt Waq1wJ4i4K5tIVE5T5HlVfF7tUHY92gR9zECBPjNv0C1+s1VdHkGZBreW1AAv5Vox5hc IzQixoOTEgg7ZtUGCQPBK/Q3FthoglRahD86MScpM90hcpH6oLFLY/l6U5NAefqoWuBE UvRyjHXO47gFAz7k/Q/Lqzu47A4eO8zUkZ4BA6G7f4AUDcaDUOpavAZcAR96zeknNea2 FLBboWwSc0PzYH7kc4R8szbh3RbAOyrttlsGsXfuRygnNPqEPXDP6f5w3wCnHo2I5OG+ F66g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294849; x=1742899649; 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=DqA1qiEwfsjB6jI0ugIZhb0BBPHUo15b9Aaz2SzVmLo=; b=WjzwBm0kviXGHirrLfoUJb1dywoM0buhqVRP7Mr5f5z8ADpb7ezOl7jyBYw4uWtt1M FMV0OmeEcKCNv7usnQ8hqrfGLr5H/XiW2wDw0cKBmSbDRPIj2b6Znf9FmwdcI8Mc1bL8 ThjrvOpQ68+zaXah+MvSTeRNkvj1Y5E3Ohos7i1HE9m/6V5RkGr+yp/HLQ4hWodfHZ2Z SXFXdrjToTNyyALGREJ6wL3cvLjgKAbn2inkgBHZEducZuweTNnxVphzD65Kh/XPApzI urVVFeLRQpFJ7Z+9Wq97+O+ERQyPfnJhmB3pooJiLfVtDRVHvYVcJ5NBBWqTRbdI8tKF 7L7w== X-Gm-Message-State: AOJu0YxJ00wmqPOVFasC1D2YPkPj6kmrFw/hVCRTGjOSHk7IAQ8zLWxT bzA3Um8hgaXE4vsbkzAC0Or9C+zZgKTMnGUAgAYvFKe1dFTzHh4doi2RG8dLDo8/wcXAcl/2A5S P7Wo= X-Gm-Gg: ASbGncuhMLdpjUcdubVxuVdrzJnGJKclMzkgDmhvekfeVRZd4ob+I16gG6wIUrUuiru jJ8OhYUJBlJHxREaXnbFW4exs6n79egjl1YxkZoP8dPoQejz7RL295LMFF1Vs7IlNzuLBy2Y5aG cdt+XigxRJE7ZvWicxEEzxBJmviq/ZuR4Hh1Az0OFo+XBa1pDWhyNuZn27eHGCDibKoGgv/zizq KntGYacM5rPfR0RwDdQTEQW4avMGGFHUeFlF2rXPpok21npPVmOkLRDDgp+0GUxFTSwtLo41+Yo ER03vvTWrEyl2qzsErzFLKDOSLFCedS4EEd5QLOh6fJIaCZgZKMLZg== X-Received: by 2002:a05:600c:3492:b0:439:643a:c8d5 with SMTP id 5b1f17b1804b1-43d3b7cc0bemr18722545e9.0.1742294849252; Tue, 18 Mar 2025 03:47:29 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:29 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass Subject: [PATCH v4 08/14] lib: time: hook uthread_schedule() into udelay() Date: Tue, 18 Mar 2025 11:46:44 +0100 Message-ID: <20250318104659.1114340-9-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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. There is no delay in the scheduling loop because tests have shown that such a delay can have a detrimental effect on the console (input drops characters). Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- lib/time.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/time.c b/lib/time.c index d88edafb196..0e9b079f9cf 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 */ @@ -197,7 +198,13 @@ void udelay(unsigned long usec) do { schedule(); kv = usec > CFG_WD_PERIOD ? CFG_WD_PERIOD : usec; - __udelay(kv); + if (CONFIG_IS_ENABLED(UTHREAD)) { + ulong t0 = timer_get_us(); + while (timer_get_us() - t0 < kv) + uthread_schedule(); + } else { + __udelay(kv); + } usec -= kv; } while(usec); } From patchwork Tue Mar 18 10:46:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874403 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443176wrq; Tue, 18 Mar 2025 03:48:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVMY3JUe2Shbf5i4iwbt6IrwYU/3RtYlpuuf9pkHMRMFSEN1z7/VUYGFsSrNFcDoqZyTWep1g==@linaro.org X-Google-Smtp-Source: AGHT+IH01E050d81X68rTzueWxrCU170IULg6m3+YZ5MdoE4l208juScrRph+JBlruZzqpsM629D X-Received: by 2002:a05:6902:10c4:b0:e5d:bcc5:c33a with SMTP id 3f1490d57ef6-e63f65c36b7mr20915100276.43.1742294936682; Tue, 18 Mar 2025 03:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294936; cv=none; d=google.com; s=arc-20240605; b=DAL1QFDW8fYRQAu8wt2QLyHSg0XTfomclZ7UsDY1FjmP4MlorwfUa84C7EMVWw1lV8 ymuw8n7u64iL2inzeAEJGoIqE1asawH5VWDDNGCylY4CCqhTQUp06N7RrOTZhbApNxR6 iaSf3DvB3+2bYuNp87DFIJMyj/syNpvS5VT/A3VbNE6pgfcQOOsY5vo2vEU4gSEeBAlo IAJyBfbVf39vyh1EiDuv36BjozkokxHHd6vM9H7MwwDDzMjS6U7UeVS2bqmNUfy0vOKy MXLF4K1LhWhTs6RnwY0nacGNF6x4bh7s1Ml8x29CWkiIdeZMZRaHVcz/dUZQCrs7mczO Q9tw== 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=qkBJkl3WKwaUf5l3xYynOeT0PQynHCpYMM2dqIakoiU=; fh=ATEKTwuGlHmACWEz1TtgegbEaoD3a+YxOtr+MGaIXcg=; b=gVSs+JAjlbxPrjWcHj75l2YOFS7C+O2wrUgDfXD6DRZmi3y1PUkqsYZ9/pB1KDEIqy 7fwCOwH/CQZCpnymtWe2O4KxxeETMdAnvopu8aajvFVeKsF3wiQ/5ylJ9fzk+tc+5joL mnn4EdXO18wy+BRIXJ3KY+QGQj65PaOlNAbeiDxwkysgON7gvu4K9UU8V3ITdp/tl00h stXguLVnVS/4EabM90zxI+ns+OmmW6rSOw6cGXaXg5T3mB0v33LEEA4bFKyEpsBofUPi SPqyqHyyEShD6tvpUn3c//eww/QYo/Z9IFyj9uUsmGb47Kk3hpMEE6e/JAvyjQsPDkXW wt4Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aDbXa91m; 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 3f1490d57ef6-e63f1b4ef81si7860449276.223.2025.03.18.03.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:48:56 -0700 (PDT) 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=aDbXa91m; 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 8C6C981A10; Tue, 18 Mar 2025 11:47:35 +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="aDbXa91m"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E82DD81D3B; Tue, 18 Mar 2025 11:47:34 +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 B102281D0B for ; Tue, 18 Mar 2025 11:47:31 +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-43cf257158fso20743855e9.2 for ; Tue, 18 Mar 2025 03:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294851; x=1742899651; 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=qkBJkl3WKwaUf5l3xYynOeT0PQynHCpYMM2dqIakoiU=; b=aDbXa91mU6b97ldxHVzwZ5ejlaKHYjWkhAi1FgVYrgsodyhL9LY9JLghcjXjRAkAmD ZD0fwDmjl22/qc2sbm7CdyXwly22yCSAm3KMpKwoiBS0mGujT3mIDwtyVPXMnE9ilSBX NRnZZ02BtG0P+a9/iq1peH1NOVfn9FJAXlZ6vc1Bk2TtUwaixgkV8EDre+QlWLk7j8yQ V8n1gndoRYAoTLcrB10yaifY64D6akO50fwboNIuOkk+6gCv5ATPI8mSbX1L/WIRoQfe ymr/DrrJfVKUJIb5QKviIPB6xa9Y8oJeCQ0fWthkKGW0MtyI9M3devWL0bPPXZtKquq7 YPKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294851; x=1742899651; 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=qkBJkl3WKwaUf5l3xYynOeT0PQynHCpYMM2dqIakoiU=; b=oy29zapS9if8nY6da3DiO7JEn1/+MMRzxs0nRXY7gxYL6vzYudz/wzFf53zDWA8Q7u xWRcSfSVjYadI73JROYiro5+vML4jXIMGesmxioQZV3klNVvHZ0rxZN1FuPi09hVhHAj D+LlNjLx9ZbaFrv4s17MsFvG1i5VJ/zYML5dmzK7qWGVUx2j6I4Yi+BBLZoaT9tStTkT agkMm2mK8UnSSVHXqa+V3s5lJCJc4ZTPHHqyzvZ4BRnIuWDI2LHuDbTvsEtdX+1pSOsx UA6EPKaGXggm06nAHMGd/2BDdhmwDji7JgLMU0ahYt2vQWAxl03ZcoKxd1i86xEKMAc2 qirw== X-Gm-Message-State: AOJu0YwjrYikwk+IYQMRjTdMs9LkaFc8c+r2ylqB98Py+O5u3y0SnE1u 4KkSBkZZKhATdcEHDm6rsn3RNzBP94Uq8ckLuNJbJHTPfJ2VTF78Pjh+yha6tEZ2eq/8qq9kIYr ccQY= X-Gm-Gg: ASbGncs5KUlMNZLeVGjz1qhS88Ek/UljD0gAYK1Zvp1Jfc4ZLJOapklQLU8kB6rdriY nxjetlU6skNEtZF8g7jmiI35PCSWTrh0JFqi+K0ncPqFzc2Yn4Ymqjoj8JQl8C1eU61Q0HesuXx S57xOOajnTXN7xBwWu0y5hDzY+3uYI12N02dWSLNG7qgw8KeYc+JwMXthRBM8QFST6QCJG3ROM8 DA8bKOSY/n9v6nthSBpUUPIvGVY8ks3k5PYo/JOCj98WotkCZByKeSHTwQbqZuEf4QldjBGZq32 VDFlk8sKRNfgK0z9vjH5+leBiUkaWI/rcTYiTTBdgSxA1gVvHBbfXZk3fxTTartR X-Received: by 2002:a05:600c:4f49:b0:43c:ea1a:720a with SMTP id 5b1f17b1804b1-43d3b9502e0mr9047155e9.1.1742294850765; Tue, 18 Mar 2025 03:47:30 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:30 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Heinrich Schuchardt , Simon Glass , Philippe Reynes Subject: [PATCH v4 09/14] test: lib: add uthread test Date: Tue, 18 Mar 2025 11:46:45 +0100 Message-ID: <20250318104659.1114340-10-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 thread 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 18 10:46:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874404 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443236wrq; Tue, 18 Mar 2025 03:49:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWF8Nx2vTAcSu43y4fJaAzs8vpCkTtbLGRrPwHu7CVXGWTF5+U5p+WXEyiu04uIIn9Tt6j1og==@linaro.org X-Google-Smtp-Source: AGHT+IEEfX2Ra3XWHErS8fydxbuV/79TAZeO3KjPDL/gTisLCxzBmyf5geslGH9REmYz6BhYcf3Q X-Received: by 2002:a05:690c:6d13:b0:6fd:97a7:1474 with SMTP id 00721157ae682-6ffd748aa7fmr49453897b3.11.1742294946228; Tue, 18 Mar 2025 03:49:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294946; cv=none; d=google.com; s=arc-20240605; b=liN2L4JKnaiup4ZYAtJ9WYV7p43sPmRWrLW5sPMUqQ0AY2lAcuoXmkzbtG4X3/IUV2 BnGZ++nUG1jzncAdqAwd6cWo62WcLZSzapnSGYA8s9BWK7Tq22Wca2oJVfXT+9lQttd0 ARQW6iugeHGycat9Hl0QicQQ3hhyLJ8PSAYwDB1sHWyb7cGVvKhcVoTDNKeEdjokQ750 TK3MmS6++lpDVm0IzNS4NUTc65SuOQb4XtieGC0jzHaWo8Ly6wJqPfJ035itz61RWPRP TH3tzaK8KHXwaAFWYGACs/kfDH+9VFgoRETaPpe9lRh4UctjkvtsDhsn6BvNQmjAIOOk dL5w== 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=aOwEPxvaoWHr66xPkiSDm/VL7CWIUInUohTOmW+osfU=; fh=fR0UVWovEQaeizUbW6NYRhJaKj1baCbm+MM7JESBVRo=; b=ONCD2sC5W3E7bojT5HPfeAOhoiTyJk0fwBMPKg7aBnzrmBxleHm2SG/VuVL+ixvxBY UylLBti6I1H0B+iYifSk9TxDJDr08+jBTT149Up5y9VGd2Q3aTypM/8Ifj14XPAc56GD vnXPJK7H0uGwMY0iC+ybdRr5q8vI0Sh5+3gNxz43wRwsa2fYVZ0c6CHHRsmCHHbV8e3S 2yowP/drd0qARNay2qd9jP4GCZTXhp4XQE8FhdCLBsnuJy82HrbB6LiUW81IUEDH9MzE s4RRVUHvPH3j8GN0J2Z74rqQz5BtgUcjO8yahQWqqSwB4Gr9AoRGtoRsracZBcZA7NOE fMUA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vFN+EihI; 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 00721157ae682-6ff32b42002si92131467b3.265.2025.03.18.03.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:49:06 -0700 (PDT) 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=vFN+EihI; 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 D1837819AA; Tue, 18 Mar 2025 11:47:37 +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="vFN+EihI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 198D281D1F; Tue, 18 Mar 2025 11:47:35 +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-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7321E8122F for ; Tue, 18 Mar 2025 11:47:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-43690d4605dso21748355e9.0 for ; Tue, 18 Mar 2025 03:47:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294852; x=1742899652; 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=aOwEPxvaoWHr66xPkiSDm/VL7CWIUInUohTOmW+osfU=; b=vFN+EihIE1hjAryWK8QhNaBsUwX8vRj1nx568xOYLGRa7h+s3twDimyzMlAoLAmJQr QIa5GguBlN1P8i/sE0i4kUhD0/qHf2hcN2e7Z7wkcGBO0WLPYerJRk4cz1KD322S+WTA rbqdj3igsyyUZWGe9JakDHV6gp+3YyzOzPFTGRBghGCKbEIWJjWNjPLQH3EWmKxPpPPJ mSk9ruHlyb8uvl29TIyYsKFCTtE60uDId/N3AeXDcN/KND4ShpANvU3EV45RGouZQrNe UHhFYXVcgx+sbqSuVKUQQPk2lWj4aSP5AXabKaHxHvVN0K00bz3QTHWYFeI4bseGtWD0 4AGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294852; x=1742899652; 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=aOwEPxvaoWHr66xPkiSDm/VL7CWIUInUohTOmW+osfU=; b=jb39+cJfPehwfw2eQfTjTKGfTR+DPUlj+9ZTMHWFGTWO82Bl2ojJxEipi8Ujhhzlm9 fmSHSqgKEom+mzur0bhrKd5zobaA065MidMLfLeP3zD939xdr6B6WPH0MwQy3iPA6fng KR2FweBpiOPHImQ8p6omUbUZYE+HXBwPLHl7zWVaT10ALhoJvID3HwI3sm+/ansts9ap KESwJxms1XKDsM7SMxm+1DMwiraRf4PmzD1Oz6BO4cS9/LF7xTIHbO8fnYyZ4Z0j9MGN UFDz4tufV1jOGwz8MzGdo0Hy3wYPiRNFzBbEzwfX0fSOuvABhRtWdoRLnTGHg69ggUvU j/ng== X-Gm-Message-State: AOJu0YyJQkZBrIhmzdMrwwhAShkWCjqNu706VCBdDysTq0m8++oCOyXb 20NFJnQJwaSx7e0tmBVAl8ygCN/KwxoU+QjzjJBvFsBnS4/6tjUc5tPNjTmnzJxWFft2uhoe4Rd UdBs= X-Gm-Gg: ASbGncsR5hKjrXVnQq++/6Jk4VPdjLg1fRFUz9VJQDNhWV+D1Aoj6BmwwlKHmixxApf l7vom2IernKLjkg9Bw+GffKmosraXkk4sW+8z30+Ta/lb9g/pNGfORqhHkKuLC2VqUMgqUt9gns iLrXK/rjP9dZRPD21v7UAw8zfHrj2IiZg2C8t9El2rPBi7wceccrNgqJ1eQ8VLRrZNVCWPWmw9E kMyLIq6JDKD84yqp1/GV6cj4mm58f5jI053oDLKsPjEzogHmcVW0Gtg/Cs1ESqEJC93jebhMkOQ 6fVxbucxh7dUBKg+Uo/j/YUdpts55h6kNIvCECEqp99vJ/iJElbIxw== X-Received: by 2002:a05:600c:4295:b0:43c:f513:958a with SMTP id 5b1f17b1804b1-43d3e14fa65mr8428375e9.13.1742294851611; Tue, 18 Mar 2025 03:47:31 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:31 -0700 (PDT) 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 v4 10/14] dm: usb: move bus initialization into new static function usb_init_bus() Date: Tue, 18 Mar 2025 11:46:46 +0100 Message-ID: <20250318104659.1114340-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 threads 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 18 10:46:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874405 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443270wrq; Tue, 18 Mar 2025 03:49:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWI0VMIezJBHv0sqXSdAikAAsIvLqKyDgCFPejDPCrWKNsdgkitVKbxRU56nqYlQcHOyw+mkg==@linaro.org X-Google-Smtp-Source: AGHT+IGN1zpACbxqDPgitKR/RxYUK9u1TxxNuPMjwEdzSUw9/hkLSGVFdK2Aq14LauE91jcBLqyQ X-Received: by 2002:a05:690c:4c0d:b0:6f7:56f7:2398 with SMTP id 00721157ae682-6ff45e4bb43mr182036337b3.7.1742294955897; Tue, 18 Mar 2025 03:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294955; cv=none; d=google.com; s=arc-20240605; b=AV01bTUSH+N31r1z98lRBwSf7rraeTxpb+F5U0OfUzytWQoXNYuILoH8WWdAtLUhJO PHSAQc6iDTeIRz0pev1QY1AaU/pr2fdtiq5HuCFI2EoMolUB59DM2kiSuf0XXFCTgEiu 6/lY0uA+WNQ3mR52sJCRKfnRLcUdlg8QdPGkhgBVatXBsJ4CMM8pRHdCWA38mfo8P45k qMXATOIv/2UbEDo5OJEpP9sKZjA/O9MLrBXz/an9XpdqpxKIg4bYSd1WM9ufuJ7GweDw VOQGxnbMndCp/s4azH2+NUww1stb/sovwE4QISffAqGJ/gQxyLfUHDTh515YyznIWji2 3qGQ== 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=Xs0fewSlue7xKmVnt+Oj13Za3tqIWt1LKA/DWV0de2M=; b=kUqA+SoC0QIAnqS2opCZF1522N9WrCjy6jyh8wKKocsMrlEiaYkfeo8U6ZaYwPIyMW V6eZKx36M68u7JeIeyfhFczjgv4Afhd7bi6PrALQKKcCWtuEwu18XINK3IseA6zyU3b7 NeTaepcsjI+59nxP1T2tNkpT7mBw6TMCjMNUvnFq1857qaEVxq2QmQ0qvtVQ3ylnw3b4 GXH0VuzkC6HM8Q++zDJyV/6Rfw6x73XStq8ODFWhxZZMdpCd25IL8iQ+TPhvyh/Nswd0 uNCQRf1Lp3Jzlm7YU/035gvN0j+JztWypxCbiZu82S+avWmHnbAKYDb/AcdTA33xQNHS rMEQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jqnoxXiS; 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 00721157ae682-6ff328375d4si92743157b3.67.2025.03.18.03.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:49:15 -0700 (PDT) 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=jqnoxXiS; 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 2670281D3B; Tue, 18 Mar 2025 11:47:38 +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="jqnoxXiS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 28D8D81D3B; Tue, 18 Mar 2025 11:47:36 +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-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (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 916BC80F70 for ; Tue, 18 Mar 2025 11:47:33 +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-x442.google.com with SMTP id ffacd0b85a97d-39133f709f5so3323879f8f.0 for ; Tue, 18 Mar 2025 03:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294853; x=1742899653; 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=jqnoxXiSuttHbEo1yTcrh4WAWEKQPa5icp8cUgJm9KZmUe+hMQM/PQv0GmoyK5v2sA HEgo4/IlQcPL9NxBFwW0PtYClqvw7l86VeSuVhJShGfKNZAcSG3EG+2LoOmaOLKEIoyx hylWX6e1TaLiKby2UN1XbkwM3qnEZ+KtHU+76QbY051nsDWq60YjbHxva/JuUqE6lPIz 55PEdNZ05Wf9a+z+vM3sZyBS3GjROXHa2fO3GbTiBpJ8QiFtKcL454AXg7MNhfudA66r OcUmlsh2dMZs7NrPLQxjuHeH6iQmD2rIVMxoRyjgkEuu9r4vFmVKYB64KVsRYC5l3WGt Woyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294853; x=1742899653; 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=GlIP3UJYfRRgJQ0Voo2feko5LVEg4TlrMTRFdIbndq4lylqA1qjs85B/VUi8rNZqOY WX6jsB1uVGkddQb5Q/ZGGnOK2OLWGsVnF6awEZ73iaCn1HNazT4Ytz8QdbZFEw09v6aX zyTiP4a4XZ8kf/gbCFgsdqe/bKaZGFaTwTP+RqI2Kj8T3aSy8RJSDL4LEGJIL51zpZSd r3BBINMV6TuBPL03Ac6h0rPyQ4sF7pAmIZ9licNizGsBe9Z1XHu4Finmj5mv9gAbZlgr kChDuiDI0DzzyXy0ZPREafXZe05tmuwjzV91aNqo8jYSZCFx5QYUBMoEN9n3P6x+3mH8 fs8Q== X-Gm-Message-State: AOJu0Yw9Gj3ZkIVqMW2HNYql/PmKg8tf2sGSRZKt9c6ew8Mq2ONPVmVy OWpRfobLqieb+rS39uJ06qZELUz/NdDFOqZgMbXK/B+iG/XhtXlzxn16nKKivWu92JjMFqkoIbE SS98N/A== X-Gm-Gg: ASbGnctdYQtZuOqCT8XNZ0j4YHkiXBV0IyuRGJRv4gGL7vU/Lzomxv2AiQ29JofpfG1 868/7mr6oJbhtvBMJS2uzaGEhEfY7oYSm9GoQNxojKrH2fq+DbSeMSuCTsgnpJ9cQZojC51C1kr 67/B9Ap89QTjIzErkLJejNoJsXOLEdrzL2Sgu6IGFg0HqM3Dbil/uosKRPB1XKw9BP9Qg0ldsze mE+HxC2paWeUt0oJy3J9OvfL0A9wRe6R+Vx1xdxtlSE3JR9wOoutecFeJoww6KvFisf2Kl39wIK fdXH0FMWjzRcH70NdZ7BDOsxDZElZi9hHvGZJtyHyicy657Tf1YReg== X-Received: by 2002:a5d:64c4:0:b0:391:4608:e7be with SMTP id ffacd0b85a97d-3971d333c30mr12565850f8f.14.1742294852673; Tue, 18 Mar 2025 03:47:32 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:32 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Simon Glass , Mattijs Korpershoek , Heinrich Schuchardt , Caleb Connolly , Julius Lehmann , Guillaume La Roque Subject: [PATCH v4 11/14] dm: usb: initialize and scan multiple buses simultaneously with uthread Date: Tue, 18 Mar 2025 11:46:47 +0100 Message-ID: <20250318104659.1114340-12-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 18 10:46:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 874406 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443313wrq; Tue, 18 Mar 2025 03:49:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHqVaMShy1LQzPUwBek6qG18BEaXcSE1L/dWmDM9xkbx6Xn0sdSL13mMXb09DKVCTlmNMuhw==@linaro.org X-Google-Smtp-Source: AGHT+IGcFiCm2JA/+FL84IrCmLZXzHxRSKOsOQjY35HnDm1QYTjb7NS8d5uAvOIa/WSWWE1Ntfow X-Received: by 2002:a05:6902:2807:b0:e5d:aeb7:6e62 with SMTP id 3f1490d57ef6-e63f64d236emr19194049276.7.1742294966274; Tue, 18 Mar 2025 03:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294966; cv=none; d=google.com; s=arc-20240605; b=BJQN9GDp8/VNnO0iYrcagEuNncCC8F6lzoDkBY1LokWMxfEoXDK0+07GWXxN2CGh0G vN/wpQdYzLbPEwZ7jta9rOYUGin2YL3xog6uXrNiN99bMXguafU1YOZv2Wo6oa3IIz7J zko0F/ZW15SihOrBOfS9p801ivmb661la2p7RtU+psdFl0cIXaZDeMXQfxbQs84ia7KG hq8EN72HXRsdPbEOkEt0sZJ03FzbZ1v7ZnBdeI7JT2Luv/8DI5nPrjXOHHltKVdH5DUB q/kAlk3P7tEdUUa4h9cSVynKtOXJgVmabYHSSqOGmYau6SqCTIWEu70P5HyR0RK8tUgT OMsQ== 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=2sekQU63kloVru5EHGh5HfRGGGGNQWsXJL/Sb3hAiTA=; fh=I5he9Y7EQQX6uRc4Yt2A9rvi4ldTIf2iXCc4eQP+Pnw=; b=fGTqmSMoGyAxaTf59Az+fZBy+X+IRYuhxlAnDx8UWJ9yeeakd0ixjyPdb+AxmIYBnf lV3NIDVoGn9++MuzflUzWYTHUktFmQ1OOSOobDoU4rRc8HHj4+veMR5ho20y3Tescv+u Xx+G0dQpYu859RV3OzAHGaa7PkcXKxGlOD5yZjH4UWpO84e48zqyMhX1F2bhwKDGc1H2 tLukZHw1j8eL9k48Jgb8bkkNr0bTMxIEiTcgr1Y+scB6ZxveZllnA1AtAJV5JRtrPdrb RCxdaTBUpu4xUTH3PymesHiSfaAqqMrBW5tBGpXclmSdeoZ3AIZ05E60cjBN3ox/UMEZ syJA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mTlabkeR; 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 3f1490d57ef6-e63e57b3a79si9444725276.615.2025.03.18.03.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:49:26 -0700 (PDT) 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=mTlabkeR; 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 7004181D5D; Tue, 18 Mar 2025 11:47:38 +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="mTlabkeR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 275A9819AA; Tue, 18 Mar 2025 11:47:37 +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-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 08F3A81D0B for ; Tue, 18 Mar 2025 11:47:35 +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-x430.google.com with SMTP id ffacd0b85a97d-3912baafc58so4678801f8f.1 for ; Tue, 18 Mar 2025 03:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294854; x=1742899654; 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=2sekQU63kloVru5EHGh5HfRGGGGNQWsXJL/Sb3hAiTA=; b=mTlabkeRYM/en4JrYvTj7Ctx7GVzEP7NETGbg2R5WdBHb9r2DhEyA6kj0qBLZ1CrBg otEgwdYGOhzcPASvNHNk9LYiXeEvCDDOcavlLU6zbpCrtShys6uDvTc3trfXgu398mJl AGqGxMDB8+IuenCExI100SuZLyCKyh4c6JQ5RE81L/LlEiPOt0hgK+QRY7fyh+rj8wKb ijtb18R/bio4fCUCVpbV+QN1ftFXHhGk5N3geb3aEJNFRn0G+5MD21cevBtg23CRc4fP l3ZTs1wPTQmdUeeQlDOMb90jJlHAtpr/GGeP1Ows37b5T+nnVduHJ0XJt0lUHkkrCH/1 hj4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294854; x=1742899654; 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=2sekQU63kloVru5EHGh5HfRGGGGNQWsXJL/Sb3hAiTA=; b=Xbze2qJ8A6M72VJJK2lqDxQEk99UYlLkRhcVkZo9lHxbJoou2hlX+pEurViB0caGI6 xKpqAAEzgC210o+c6byVvNCANZgBeTJILfKrCOQqrDuMlVHNkk+Dz5QlUWTmY1q0xP3B A9wyKRykiyliPttfTTZ4vd011nYPiiz+bRA9xcH4wYj0xHhx9K/wx0DLdepwuRsulW51 +jnVpNvrn4DM6OyGK4kvaBa5t5i987MpPoCoBPRYlnJ2b7IwiGsCvR28X1u9/BsA0lt6 6/VSzFIbmGA7HJHQnlfATtAMRF3mpr5xxRh8CPwl+x9Nzrdblt/DtLh1dOH4HhH83DV0 8wgw== X-Gm-Message-State: AOJu0Yzpk1ZZD9DIaAoErzT7nAMOk9blsONZ46zkkiHg5DJ4DKqyiKIy 13Jo6RX7df3GFLNL2cSGcLjvbOccS4CJ34FpUY5vw3cIGWHIQz7x4EZ5m/NIanidhbgZqyYpK4o Vajg= X-Gm-Gg: ASbGnctKDG5dcYz/ie1YXZv05W+WLtVkMcYpkxmfiAIARy3QmOzS7JnUDzTNKBwQp8q YaHCfmCL5xa+DrtPPWKf5rZbYNWFlgphYUe235R+5NUIl+9qitbslVF+B/AZn80JY66TtQY/heJ mgErM+p1aiAvqiIibSdGtNI6H/LHJ1tvnhl8RwLLxSExQE/ROtlBKhaRHEGgH7hTKkNPCCbhOlQ d/sbYt43nyui93IgHgJKIwI2cmZ+Dngbca3aCG1bdDmd2BswJhjnVz74Es7zmJNHgIh19liuYIl Rntc1DZMvazTJIAGWRx9h0QBhPGDjOemcnhX5zfW6MRt74QNOd750w== X-Received: by 2002:a05:6000:1ace:b0:391:41c9:7a87 with SMTP id ffacd0b85a97d-3971fdc6db1mr17812194f8f.51.1742294854184; Tue, 18 Mar 2025 03:47:34 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:33 -0700 (PDT) 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 , Caleb Connolly , Sebastian Reichel , Dmitry Rokosov Subject: [PATCH v4 12/14] cmd: add spawn and wait commands Date: Tue, 18 Mar 2025 11:46:48 +0100 Message-ID: <20250318104659.1114340-13-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 Acked-by: Ilias Apalodimas --- 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 cd391d422ae..0cbb75edfbe 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -3079,4 +3079,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 c1275d466c8..b61f6586157 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -239,6 +239,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 18 10:46: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: 874407 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443364wrq; Tue, 18 Mar 2025 03:49:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVdO7/UGYJyzT2hH/oxn90CC/8saN7RWfyF4uvC/ChTZq0q8EPixcmpadZ7QBYwV3dCDRiy8A==@linaro.org X-Google-Smtp-Source: AGHT+IGfNy/zXhjm/z6V2nD+OMYLDcBCFtkSlZj/Ndw5tL3omG92s69ORnpbrk5IjMYLIep4L8q8 X-Received: by 2002:a05:690c:4c06:b0:6fb:b2c0:71da with SMTP id 00721157ae682-6ff460fc2d6mr205898347b3.36.1742294976562; Tue, 18 Mar 2025 03:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294976; cv=none; d=google.com; s=arc-20240605; b=d/kTE2TOEPjyW5aIltVI7RcEd10wQPAuqPc8HZfbUpQohV7pB5xB1mNU32iWd+/93d n+Z1pntJCK4wJSSliIzvBq3SvknRDCTiqIcG5iXtCjcHcUI/mP5m9EEaDHbmkcJvvBlR Z6Im9qfZ7tQdP3zpUqD0Ut8ITbVfkwahRC4x9R6UqTO0TroCQupfhdCS/IBCO6Vn6aX2 qkpaMa+TK2fSlofQ0+7EvTrvCPJZnTO41dbs9PuroQ6fs1rfL7RYNP6MfHmpmDsC5z9+ WcwzZSIQClVnyUSBQ8/tgbmyKEZHtWjsSJhhnswLPryekz0AvwK5aP2z0a5njww5HjFZ BIqQ== 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=oFltWPALYkQiMDNUmSg+en3vLnxEiJ0+n8F2dvwsl/U=; fh=UXi5gUnwqAkJNiukY9dZPo8O1bj7wfbxhZ7gyd0YbGk=; b=kRSFY2qbeJh0yunrJG8OLjx3d28mQeIpCFrZz+gGHz/p5JQYpxGNuXjXmoPltltSS2 pZH9HPtC7+RyaJJdDD5eRr6JDARSLKMKimuMEgRFo+MSwRaBUs3vEtO/M/m+IC+r0fLY wRd6zJULZ/gfUznCKtCVCAfEoPJRnUpH+OKDqRkmJSndDcRxL1ERPwsi1Vqxc2zyk9UG eAzgs0YKBr8tWa7/6fPtaM35Y5MGXcKb7lpKwoL+ZjMe9BOZmfaCSsUQlw3ipn/Y387c 4RTPXNSb0qg8cWAksKUFcaUK8BzqiAcnKcgVh5nbCNFRNaJ90oPixUCuWd4MZz4gq4bn KWlw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cB0sX2l0; 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 00721157ae682-6ff32b49b8bsi90282167b3.327.2025.03.18.03.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:49:36 -0700 (PDT) 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=cB0sX2l0; 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 B058381DF6; Tue, 18 Mar 2025 11:47:41 +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="cB0sX2l0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 16C0A81CAF; Tue, 18 Mar 2025 11:47:38 +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-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 136CE81D42 for ; Tue, 18 Mar 2025 11:47:36 +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-x32f.google.com with SMTP id 5b1f17b1804b1-43690d4605dso21748785e9.0 for ; Tue, 18 Mar 2025 03:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294855; x=1742899655; 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=oFltWPALYkQiMDNUmSg+en3vLnxEiJ0+n8F2dvwsl/U=; b=cB0sX2l0ahGWOIdKHbXSf+mahpHwC3JaN3OnW89eVaEXwQYzM1WCumiou2/EFQXNN/ TCBYJW6EB/jKK3QNVW2Nb2ik98X3rzkdCviht4hMSLh/dO3RVwJYNbPA1oqNrOpOxP36 dIi2x/baVnjonDdOG0mJSeT0MyrrNAyFnkhUht25bdPDQewuAeNBPEThVHdwaxqJhnmM LpcZv0WISGWDa323vNfwFlfdGHa9U78NFNQH1U4rxwnfRtjiBS1+DTPGhLChdIxzoYEz KUl0VWPvp0nbyQUPff/AYJMU3eZx19T5SQaU5ScbS+2ELZ2wswxIkRU563XcjgCkfwtS BNBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294855; x=1742899655; 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=oFltWPALYkQiMDNUmSg+en3vLnxEiJ0+n8F2dvwsl/U=; b=gZW9dgUfBmGl3BwbSNMK3T+9BU2f5zE5QJ8zgplNarKoTV4XoSLSkT6uDoJ5pTtpqD lxZKyuQZFBvdwt4KuEGB8udr6N+Ft1RlvQsRxf70YxCwzP+fz1vM0KZr75zmwFj4aTE6 RXk0en/N7a1M2d3q1wUb8MBpRDzgG8Ql8k774Siii6dkZalVWT0X3/fzPHhOZ6t7i4tM 2Af+f4MFcbBHMsHIruG53onss1r0HOeBr6jdbCA6V2WD52GyxElwznR7jFLcqBu4js5T AYDoP3Zj9pBBf+G3GRdwTGnS8U0bjXrwjfKaUuiTd0UZBCeiufWkSK3IWKFE6gTCXWNq stmg== X-Gm-Message-State: AOJu0YxgpcGt6PqI2GQ7+iYLszFB1oMM6kBbNJzLrQsTmRtCFJOR2c7j GoXOZVklsKPz0aZCa/UekeG0VrtMzX7djEQ19gnJtt3DIMKSD8VDly2Nce4vJx+2dl8HL1UatSf B3q4= X-Gm-Gg: ASbGnctMvPb2tG64i8v3gHdehBOjxvw/kO6Pt/ONhI3pfEnrJhgOizhlvJD6oF2pmy2 jE3ay5u9XHznLV4u1hvu0nih3f79VMFj4myfYgeXCNzOJJ9f5V4CkvctIOoWqhRLn1CgctL+BBh u/cXN/dzNF4E0EP2wpXct8M0k9++RzDWsBizn+N4I/whITIpbXweI90DbvA0PlEDA4aEqqY1jMX TFitqhLcVqmg+XoLQlKQBTr7Qnl2w23NNBYob6ISD5M5XMMxJ4i8GgeRZU18dkT+0+ADoUPAvJJ 2Pu6X5iAx3CVm+zHJct+kypgqAZXKmn+WUm/PnbSSc+kfkYCmSVGbw== X-Received: by 2002:a05:600c:4f92:b0:43d:9d5:474d with SMTP id 5b1f17b1804b1-43d3b7cc234mr16180105e9.0.1742294855289; Tue, 18 Mar 2025 03:47:35 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:35 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt Subject: [PATCH v4 13/14] test: cmd: add test for spawn and wait commands Date: Tue, 18 Mar 2025 11:46:49 +0100 Message-ID: <20250318104659.1114340-14-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 Acked-by: Ilias Apalodimas --- 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 18 10:46: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: 874408 Delivered-To: patch@linaro.org Received: by 2002:a5d:4308:0:b0:38f:210b:807b with SMTP id h8csp2443422wrq; Tue, 18 Mar 2025 03:49:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUqp3aBHvBLSQQJtTEQFGsXeAbxLeKkGi904gYCyHcuYV1n4NWdNfxS28T9yRsmTn+dVK+ZgA==@linaro.org X-Google-Smtp-Source: AGHT+IFN9p/mWawRZj+q6sI7CcFzqVGBnqbBFWRw+VOPMtGIzuNiFNjXks1Y8xX2fNnIKKI+7bjn X-Received: by 2002:a05:6902:2807:b0:e60:a1fc:1229 with SMTP id 3f1490d57ef6-e63f64d0651mr20152105276.7.1742294987120; Tue, 18 Mar 2025 03:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1742294987; cv=none; d=google.com; s=arc-20240605; b=HD+7LOuR+OWZiti1ODiW57xTaCZ0S54WKZs+UIq1PcAIGxh6EeuZxOACtleWL9u2Cn /McLkBTts6kYB1AWPmSKG9QMO40g62XnHljgv1q+VkA4rtQgZwJMwzd6y8rp4cmUAr+F CUkOdNySljt9nrKW7o5jVMgfYbKovFPBdbjtwZcF1/vOCvl5CTYjz0Y4mpfdI+OHROpd xiEYbQ80psMpZwYDTIpB8pzZcoUtUbHYYl9jvpz3np04AgWCvSbaT6kMJVlAhmFUqTzw 9EOpoi/YQPWfh4BLuKgEdOyxUj43Xy8WU16H5endCdXXmGuu14M8UGDPRclILrWPrX1c EcwA== 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=Iz+pWSRan5RcbHuOAmgsyvPmB2L2wa+fNWwBN2HgjWU=; fh=xNN7bnxUgrTrxlPgIs75/UrgX/l5yitpr2TwPzmP0Qk=; b=Vl9rjRGLaofHvDKDKOOQfw9df57LCTgM9LUCX9jApXXz6g5GhcHGjJ6Wx6FlRC4q2R okZTdfxrWrIkXFGO4FWRsakrdTvpgALAB7GGrQkiiuohNs/fLPgzPqI51VWS0j9ZhvJl EDfpMD5GbFkbspw8cATNSW9FDUphtDOkoS0sF1j/ardOl4aFK1pEeRXodkE9gMgpqfgS RpMn+YbhyCxVCsvS/6iWFXyrYVgYev84iRbZeFEJDXb2NoAATGR01K4Q8FpPSfzYRFya CB6MgZTM5Htgrw2JsdzGshisybN62+63EHXCI7xcbo9OQrAANIpIxTkzxFrf1zfFm5Xx 4jnw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rXhj62GU; 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 3f1490d57ef6-e63e5425ba1si9701824276.134.2025.03.18.03.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:49:47 -0700 (PDT) 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=rXhj62GU; 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 1FCF581E0F; Tue, 18 Mar 2025 11:47:42 +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="rXhj62GU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42CEF81DCC; Tue, 18 Mar 2025 11:47:39 +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-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 0153B80F70 for ; Tue, 18 Mar 2025 11:47:37 +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-x343.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so31942825e9.3 for ; Tue, 18 Mar 2025 03:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742294856; x=1742899656; 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=Iz+pWSRan5RcbHuOAmgsyvPmB2L2wa+fNWwBN2HgjWU=; b=rXhj62GUnZI3xliqAtn+DqXZdKNCYGhm1AEB+1dHsiX9YfjOMngYsM8aB/W5dZmoQE CYrQJpf5GbWKowcAoCzIt7GlYVupOF5qzXDj3unNgHS4khs5s31SGymR3RXYMo9w47Sl 4OZCJ6MGSKxcL1sHUChnoLJ+zxeYTawfFWo82FBZZwhSmsO9yY4dkSW/Yuzq7MFC09Jj F/M2iCH+6H9FRUcru0pA/4zo3cTVlh/bqwk+xR0Q3tZ/u7Js6NXHxdA2uhT+pr1pN1vA KLDLvCEARzz1v4QdEayXUkj0ldDc9NC/IvpJ247yndobR8Kj7UAZGpPZW63NkP9gSQqN eOvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742294856; x=1742899656; 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=Iz+pWSRan5RcbHuOAmgsyvPmB2L2wa+fNWwBN2HgjWU=; b=UFmzAultk3HRx03Fnumt0bNtl3R+YOC9Bdrmx7pZ3tfBc4tLQk75r/K68pdOXyGBAk RtRNrdDFvjyrnBnehQ6nBeNErUP+UixnDLUl3gI10vt0bTjsFKmOQTDYhT29KU8t46UJ Kea9dqZ7BtRp3ECXOuihhVbSU/9aNTML0mg/OahsCcCF9gyGRr6dHsXofSWLP0KPe6RH fqWfUIsGEDEf2GZb/R4YAAxDzguMusexKBABmDx27i7hCSbG5MwA5N2x5/Gya5QOUfvz X3DJ/QamxPx91G5ZGjfyWgdPH2La5d5PHdXnOpazV4kZ7PHLaBYnBnOrOHAbr3SkwyIw nQiA== X-Gm-Message-State: AOJu0YxPIXPCmCzYmNC3t2b8OscjqZBsDFEykXPuGe2j07WboM6q5bJm w2xAmxChji5mWTYLHj5tnICU7hE8ol6bBcydpVC3tBROvofiFOn04VLmjFtbbdKSjfEADQi9XVx IOjMbmA== X-Gm-Gg: ASbGnctgUxhw6vqiWsnkEXvKpTFjhCj8vcyFH9VFnQ1yaFRfQY0+14cEau5EXWRnra7 qkBvEVNrIEDpXiyH7eKyqBTiHQJ4cYxST2EJx2s2Ymp5PPxqjO1b9dBzj1A8WRS3h/DCnS3xLjo EB1bNE6oB+d75MMq/wExayO+JzZE+ZnV57T6KZ8ZEAKvJ9al9lCfRhX6B3/GXKkXZA3twpvSakH luDR00XBRDdjxpwuMA//PaAhF3hGLazpCnIBJhEFtnn/j3wisGoHZsUvQGJAlAXrjnLYxvE7JPn Ub2DAEfonsy16oE9TYecczhfIJZY9+ZRFuoZdXrXZskFYxABmo6Wew== X-Received: by 2002:a05:600c:1da4:b0:43d:3df:42d8 with SMTP id 5b1f17b1804b1-43d3b962508mr15307565e9.6.1742294856282; Tue, 18 Mar 2025 03:47:36 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:78bd:2e7e:120c:26bb]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43d1fdda2dbsm131788185e9.2.2025.03.18.03.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 03:47:36 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Greg Malysa , Nathan Barrett-Morrison , Simon Glass , Oliver Gaskell , Mattijs Korpershoek , Caleb Connolly , Sam Protsenko , Robert Marko , Sumit Garg Subject: [PATCH v4 14/14] MAINTAINERS: add UTHREAD Date: Tue, 18 Mar 2025 11:46:50 +0100 Message-ID: <20250318104659.1114340-15-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250318104659.1114340-1-jerome.forissier@linaro.org> References: <20250318104659.1114340-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 Acked-by: Ilias Apalodimas --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 92d4a158fd0..4b6bb7dfcd7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1817,6 +1817,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