From patchwork Fri Apr 18 14:09:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882307 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp830919wrs; Fri, 18 Apr 2025 07:11:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUTDddMRvUhYjTZMhliWsGUhQWAczW/9YJYv6LqQOfVtfu9YjY662POLG1WNf+Spo3yKSQ9vg==@linaro.org X-Google-Smtp-Source: AGHT+IGsmIJZCt5HTbQqgMjKA35IX4T5Q8ynGjOF4CYn8ZL6oEq45xVmAHFvbOt+QMMIhh13Jebm X-Received: by 2002:a05:600c:1e15:b0:43d:82c:2b23 with SMTP id 5b1f17b1804b1-4406abfaae3mr20818525e9.23.1744985498140; Fri, 18 Apr 2025 07:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985498; cv=none; d=google.com; s=arc-20240605; b=R4E2u/fi3FddLu/PqZ+fLxriXpLYmqCOIp8ji13d/sKe66iBqG/BhPZ3cUDaMdtKH2 jgH+uaHTOzbTseEUTlLEsHl0dMCgFlrbIQ/R+Ei6oKYJfnvozV5htxJg1O9IQFLS3h0W iJH9QHklSng7IPqJ7S4AdziSzrRLxs66KMNPIr++nJfOH34ZmhVSAypVN7Hkku9ur5a8 NfTnHs93UExhVjpPGtZFGDX+dmMS51gxoN8w+RroFdTiw2ohRBpx830FHMsI7xZ2wufM OE+Bjs3p4X8hmjtvQlLezYJqghuXEbCPum7tviMpfQKaTedyvvibC46G8kH71b1jytlg dYPQ== 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=wE8Fj4ZBUDxONpVurV1GP5HifIm5+3mqTIntosh6lTU=; fh=11DFKthuVrzxAcd3yrfnM+KiMwHAHq9ITS8x1pUQVcA=; b=TL4g/6Pd3NBkoJ7cASTvwqoetDTLk3co9CYyLn5FjKfz/SX/JKbBT/AigK/iROBNXr EbYIa4e4YUuuIJmc28dkRJz4JFYymBGGc3eiuSAHynVkq9bEH234QtO7J7k6FsnzNJiw 1SrfgP+aj2WGFc1iGioy7917g5VUfhQdUeRoJdPRGsSJkD8D+yOcZImlKJviQVVCyrqx EkinS88ETerBQf1D8pDtBFKrKKNQJlHweBcpXXNMx15AocJ2TZeNH06x7U7fGb/nUEp0 aoUlCE9Jc3dqRDxm1iIFw+mu7ny8cChg+Wy5/qhSJBDrcSWpeA7V69dM4wEzA5/eGskO hjMw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wMpmiXWX; 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 5b1f17b1804b1-4406d5672e1si9790405e9.0.2025.04.18.07.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:38 -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=wMpmiXWX; 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 1413E83264; Fri, 18 Apr 2025 16:11:37 +0200 (CEST) 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="wMpmiXWX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A5DBF83249; Fri, 18 Apr 2025 16:11:35 +0200 (CEST) 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 7F01D8324C for ; Fri, 18 Apr 2025 16:11:33 +0200 (CEST) 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-43cf3192f3bso18094815e9.1 for ; Fri, 18 Apr 2025 07:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985493; x=1745590293; 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=wE8Fj4ZBUDxONpVurV1GP5HifIm5+3mqTIntosh6lTU=; b=wMpmiXWXNqc+YEB5ZEj7kWvuELq/OJtGKNuTpd1Qm4KVWMFsKOPXiHnn0KXmAGuC40 5/v88D0JLZNRk+EyY1yRIGt17VMpmSKkPBoB/0Xvvg1/tQJGHkr3VlIH/lhuD2ae/sd+ /zbIA5ecFTjFfaL33l5PtzM6ndDaL6vN4ASlfsMc8QzBj1a5HIMl3y4vQx15Aul7YCoN XHXaBxLk2m5FA6cr079IhaHwdWTTDqurZbDiWs9ANPhhLgUTzU+Kpc69n2OZyoBOJiWE PQDBL2/J4DtZe8bnnAsaGEcKof3pZAdoleEHZIK/ZhtPLcN9mYO6NcRijmE6/Ucn1v8G Iy1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985493; x=1745590293; 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=wE8Fj4ZBUDxONpVurV1GP5HifIm5+3mqTIntosh6lTU=; b=Pi6W2daaHJLqMaid/H8rEaLpPIEveHVFJnjb/R5vRqsIN+Tc56CptRxGFTfEiyt1R6 sYaco+Hj1WdC//hHIsDjFfb7hgbOzQD2wLfcaVWEOu1iOM1Cm+TAxJNNkal726wfd99n Q94lTr+Aci2tMwlRKfUBt83nFFJ8GrcoS90K5b6J2G02tc0jaMel4bBRpcC0sT5qxDM2 gpZOQFbOgC1L28xoY+XGCA9J5fT03tbtMVhpSSUTYMyJzTRCzdQWjUzaJXk75dYW7DAb 3TVGCi075mIYXTnr6tPJSqNIxsI7Q+Jk5KNo47WkyvhhsGNmBO8sDtsYAAuusE30ABAH Tp7A== X-Gm-Message-State: AOJu0Yz263yvbbRHFMsG2MhxIkf/qcz3/AaoAzhlFz9zo+BvkODtl8eC 2lFDUkOEjaYrVxc/cc+8uW0M0Jp40ByS8OO/ise6epgQbG3t0oIDcNS2i8Is2aevhTgZOTpTB0c BLcyjaQ== X-Gm-Gg: ASbGncvLBJJf7X5lMjmaEBbDXpdFrXnvDxTdyGf9jIekvIcS9BuM256EE47yjuQLvTd 8Of8rPLFh6023Pudoi0PDGASjR2uRMskvkKCVue9n64u5doXJdAR2FGchkOEUU29tZWatzgVvys u1oXhbsJ93WYgfMVCHNU5xCjTFnOtWkes7LT+nqF3FnweKbUyhG43pZ25png/sLzPbwCb5XRr4N ATiFjh34o5zXmr1r0gb3MJ8fm3jFalYGwZhpi/JDURHdG4aO0sBTFU2jJYNhR/Dek6R8Com7bdT zy/czXJxLVd+tKE7vCjDEo3C6qAbeNzNXxq6p/3OQIKXefCew26NIsCbcRaz X-Received: by 2002:a05:600c:a06:b0:43c:ea1a:720c with SMTP id 5b1f17b1804b1-4406aba7201mr27027255e9.18.1744985492652; Fri, 18 Apr 2025 07:11:32 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:32 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Alexey Brodkin , Alison Wang , Andrew Goodbody , Andy Fleming , Angelo Dureghello , Bin Meng , Christian Marangi , Daniel Schwierzeck , Heinrich Schuchardt , Jiaxun Yang , Marek Vasut , Mario Six , Michal Simek , Nobuhiro Iwamatsu , Peter Robinson , Priyanka Jain , Scott McNutt , Simon Glass , Stefan Roese , Thomas Chou , Tom Rini , Vasileios Amoiridis , Wolfgang Denk , Yu-Chien Peter Lin Subject: [PATCH v6 01/17] arch: introduce initjmp() and Kconfig symbol HAVE_INITJMP Date: Fri, 18 Apr 2025 16:09:29 +0200 Message-ID: <20250418141114.2056981-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- (no changes since v1) 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 Fri Apr 18 14:09:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882308 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp830988wrs; Fri, 18 Apr 2025 07:11:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUSqS2KhCuoj1JqATBPlVM356SW6svfW5+II8YaF1FrAo029YzX9UahxStbB3bPvQv3Y3mhSA==@linaro.org X-Google-Smtp-Source: AGHT+IGuSH1e0pTW2MdDF4N+gWkaNR2PyXKe6SwiFcNU+TXPzWk/+p31hHHeES3p2d0Zcm/HyFzd X-Received: by 2002:a05:600c:4686:b0:43d:26e3:f2f6 with SMTP id 5b1f17b1804b1-4406ab677aamr21574945e9.5.1744985505306; Fri, 18 Apr 2025 07:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985505; cv=none; d=google.com; s=arc-20240605; b=STJvk3QsoEbLWZQdaJ34kCpjUPMbDDIzfH/PY0OZgoiAWSz3/ajPbBvzdor5mwb5Xn vtNlPX+yogkweFJuj3XTOuAEoAGSXJtxFMlu+AMnIN/vXQFTtzoBtIc8UkpBCAGZ/AMy MbUdgg84pD5ZuNvnudn1wqPW3RnMLklnJiJy2LDu3OW+Clrq3ZyBpIJVc+nHIJATwxo+ pZZS3/P7ruDY78Y6/0s32IZZmerexdP5XBuGr8YXN7tNGktOzGdDHhqFRdxda0W3neOE TR/jivEKH3laVURo82/7zKtJIfN1gQnty8ePdYOPgRzPblMDCnuQdqYaSvw1uX+nQ4ZE jM6g== 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=sWOckKqYXC1BgXfRaZVp2T9Ty29KaBSkqFhmOWssckE=; fh=zw8bH6LgW92eIqpYWFzcCDr4joLclXG5wfVIV4yPYrs=; b=htVNv4hHOA2SnNLb2jNu9xviPkulLXnbreLGtXKgsb2u06aqm2tGSXkdGDXOWTVCiC 4z8qR80Scp5TsIGefaGLBeivDJ/32XFesbyEYUVXgASHYsgz4+TaPNl60L1A9NF3qeGS XGgDy6oPsM0ygoPlhiEeIpeb7Mzpscv3s3GdnW4mxTDcquITD9SCngSvMSS1LQe8Z8GF 76jIKajxFLWstl6EFP7boXNH66hfcrSUDB1IZJ7kOiWzHVqclAf79xH/J+UHzKQCJp+W HTxm9rsHVaC99GlXNbrXntBTg6py5U3KLLClVHsxNwVYuWpvj1onKBEC4ceQmCPT+6eq YpjQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZTyxsf4R; 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 ffacd0b85a97d-39efa494346si1272511f8f.537.2025.04.18.07.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:45 -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=ZTyxsf4R; 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 6012483236; Fri, 18 Apr 2025 16:11:37 +0200 (CEST) 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="ZTyxsf4R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 76E748324C; Fri, 18 Apr 2025 16:11:36 +0200 (CEST) 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-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 7406B83208 for ; Fri, 18 Apr 2025 16:11:34 +0200 (CEST) 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-x433.google.com with SMTP id ffacd0b85a97d-39c13fa05ebso1267221f8f.0 for ; Fri, 18 Apr 2025 07:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985493; x=1745590293; 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=sWOckKqYXC1BgXfRaZVp2T9Ty29KaBSkqFhmOWssckE=; b=ZTyxsf4RdSnxx/4xc4M+UTnXuY/MUjbXdniAMfZ99QNYAbHLM/9pHADAHwn/MyYHOd 0OQ5KtJa8FkYSUx40VPQ4Qse47vYjqVt01VIkJPS95USfE/R+etlMV8DuWNRmLvKrKfq bELo8+80wFxfWoepmEeHcPkXkv+lTn0EbKw3RII/nzlBNm4gbv/shHvSKrvch16qflYo 5sXsnM/8DoOPl/hA8W3EIztidQdKooQcTxbM29CORroehhn/8pwmyF2eTgFtWPzmEh+/ s6GcOWthNI3LUOF7ppJvWHlMqitCEShvSIlr/ny1WDg9i+RpHYObKOfHRXzy8V3rHPWw HPdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985493; x=1745590293; 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=sWOckKqYXC1BgXfRaZVp2T9Ty29KaBSkqFhmOWssckE=; b=G8jMqdOoFPwL1eG7oVhsZe0LIjyKrgN8IhbgcvrSqfxt25A0M6/Pk7BlMEfsR4Glk3 X6lkckWab8iU4wRrDy8A1fkIIzZoW5ytKmEYrf3OhA1MWGq4PEiVZuuY2p6dFA1tWdSo QFJXLloQXSOqEmQyD+OAe4sEQa8gVW3CoGwcC5WNBnD4Qx/NmZuHqJ5ZskjqYTIZZUng r/QBVBDTdSZPZLG5gOzbngbUo4rPmLCFBSGoXAqg2ea8rPWmKz7gzJ7nH7qbeUP7Z4qS YAjWTRab2XH58V3VgbsxSd3NzckpcOje9fErHRAJjIYdHK1PZehKCPY5C06GdhwXPvuO b07A== X-Gm-Message-State: AOJu0Yze6HTm2wFnkOv8pOGDDArPaqIx5J4HF0tu0PLFKfvOI+2exyog J9lJHfSDYAAwaQiAZbRsBUWhcDnIBRVvF7pRwP5/QJotDVsaf+1ZoWACssvro9HFXL2QEWhBIfs 9jtxdUA== X-Gm-Gg: ASbGnct8gYnQHC9DhdVAqVY8/f9Sok+NW21IgbbMhL+CpaLVQ1aMdT/oqABo4XMacns IHWkFWkw+Y8vXfUd4QRH33l9gjQxajgaZmL9eKy4WYwfvQ4AAfxRUqlvkGRGb8nnQ34JQoJawYG jYo7yTDf30840wudXoSIkLZEbjH8I/mAk/ZJbMTKzjTv84prS7BcLoATLhndRfQwljfuihVXt1D I9hQjm/UZbTUb/S/ZsYR1wQCmqAQFKM08fHYJD6G29YWcY1fayc40WZHEVIcHpDpHOjjEG/CJIL L5suRdu2aO1vWtaRJzs4qbPxK+po4YWeQKsCIWz5dcjh3x8KEjnu0+nsgT/u X-Received: by 2002:a05:6000:178a:b0:391:3f4f:a169 with SMTP id ffacd0b85a97d-39efba6da14mr2079290f8f.32.1744985493492; Fri, 18 Apr 2025 07:11:33 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:33 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Andrew Goodbody , Dan Carpenter , Heinrich Schuchardt , Jiaxun Yang , Leo Yu-Chi Liang , Peter Robinson , Simon Glass , Tom Rini , Yu-Chien Peter Lin Subject: [PATCH v6 02/17] arm: add initjmp() Date: Fri, 18 Apr 2025 16:09:30 +0200 Message-ID: <20250418141114.2056981-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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. 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. Signed-off-by: Jerome Forissier --- (no changes since v1) 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 Fri Apr 18 14:09:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882309 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831063wrs; Fri, 18 Apr 2025 07:11:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU9je6YbecfzB9eSU9mAzNMt9Bq9+jiMAEaWS/Vew6ABxvng5L4YxABFtIPwQz/fpJnASsQiQ==@linaro.org X-Google-Smtp-Source: AGHT+IFeOT8N9wzIn3O9ZbYZGCMkIyCkO8fBbKXN+mUFSLfsVoloE37x/q71yEElGsR4h5h2b8Ia X-Received: by 2002:a05:600c:3b8b:b0:43d:4686:5cfb with SMTP id 5b1f17b1804b1-4406ac5fb72mr20056145e9.27.1744985513604; Fri, 18 Apr 2025 07:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985513; cv=none; d=google.com; s=arc-20240605; b=AFgcsb/kTA0APdnWBAyEcMwqxF3prNaojwfPtE9EkbT+F0595gv0Cx1P4LZ2GK2cSz Ydkac0/DmHsX/IP30fbB2STiiMp9+dtTWuxi8GO4FOYoLIh1xwW6fGtmQwPMhVJ485GV bqEX1Ie0cMwTMQOa+GPHxuGWhTH6XEgKWuwNwzeUCLXy7/+rjPVzjnjNzkGlZGdHVwb/ J2z5OFgmyZ0tLK13/bsNmRUQ2FLVsthj9gLk0uAaqtNyA51BdQtQsJyBsNIfbpKKZHVJ WEebnBTzRuX+yEYQ8fgxGosS3spa4wROR4eHfTs/xMGtWQ8VAVndTMWV/2reK0p+siKT K3QA== 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=vjN9f8+RKUCM1bfAsnKFxh2T60ROTFd40n0Hwh5GyX0=; fh=g2milhPmMiAbN8655mDDXVEqK/JqClx9hMe7cuF2lBs=; b=TeiQ0Ttr8+MtutGXt5PiR0QQ69KQcjAmaeyZP8rQhYqh8A8J6mDmyTNBjprkmObDtz S8tum8aa2aumd3NKleF9+itcBwZcCVnqdNW8/e05DcXL/XDYCMv06lWbr7EhFG0iKN6E I5jGl6IBvrMjoXfJYSiIP7J5WoqMOjz8X2/WoaVDjWz1rU5tRMx/ThS1mPtF9Mrp+Y5y m10rqYfQYxM+N2we6lz2xzp3niu5YFic7tgG04sSCf8i51o2jpg20TFjRX72YZ67yuqo g5ydHu6qgIIXaoEQZjhOlpyFvlqfZOzGP1gMBCplfVkQGeBy2mDsWZ0ToToQRU/Vsf+L 9IzQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JimfCtRI; 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 5b1f17b1804b1-4406d5ac022si9713255e9.29.2025.04.18.07.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:53 -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=JimfCtRI; 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 B491C8329B; Fri, 18 Apr 2025 16:11:40 +0200 (CEST) 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="JimfCtRI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 592BC83287; Fri, 18 Apr 2025 16:11:37 +0200 (CEST) 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 5C8C381F45 for ; Fri, 18 Apr 2025 16:11:35 +0200 (CEST) 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-4394a823036so10485375e9.0 for ; Fri, 18 Apr 2025 07:11:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985494; x=1745590294; 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=vjN9f8+RKUCM1bfAsnKFxh2T60ROTFd40n0Hwh5GyX0=; b=JimfCtRIAqWr8buAzsgg3bTcq9AvBdLJezOF/GrX+DoOwfOAH6dbx2yZGPF1gFfONk Cwb7gFi+U15upS8pgwFIOsrr3ReUNfO6fTentcF6u6uDS9PNfSfdOLmi5oNYrkKAqzm5 +qc5GLyzpNJH6ir9CXIA2VzCAsXgklemDTftL7UrUPBkwefYDlZQDE//R9PM0Z2hFNYn 2hgxf0C0tPYhowEh6vNpLOcvs+85xnCNpUuXvGFrMxwwqceeB8iYkIuJIqloKBfT/mGT 7PU5zRGhmFXNy64f0tQDatNnz2yYPAah6uVDE8QkFlmb4xJsSRBNg3SpHvGP0M0GX1bV kN6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985494; x=1745590294; 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=vjN9f8+RKUCM1bfAsnKFxh2T60ROTFd40n0Hwh5GyX0=; b=EOJTUc6V+3kUnyRsK2TP7E4tDh++JbxapZzELDhbxzWLETN7yJxSmQhkRsjQ3NKswi N4X9s+a0sWCMnN3qg/sZ9OXeJzUhFf439fKDv5smwE/fR2MGWOcOPw1dqcWt0NwlBBTF yO6s7Li1KVtr3aez4/h5USr+xqVqV6YMWbcCYZnBs+bsOLbkpaZMKUH6yREtHMMJepTA YGPB8FPLXfgO5Q6KTzUGaChlLNgcn9vUcMIwlr4PSUqMtlZT1Ma3PwEL0oOiZb9SwtW3 YB2SopkW1cG3t0JJ35pD6qpRJEINQhALKuIryh+poqTupAZ76CS3rg64L/UXvpMNEO57 EMSQ== X-Gm-Message-State: AOJu0YxBgmEhZdzLGGj5C41SMDv4imfdEi6++1Ehc0/HTL3BIK0jWmmn JkL43C57j+WXpgYFhVhPto29OjcaPdKytJxoRjVdOwIDSk8NdQzO1j+g0kOZtlNX1dYNPyJcgu8 gm6tFmg== X-Gm-Gg: ASbGncs77+sA7qlbx5FZymvp09qkKqGm6pnIfTNVqtRMvVDbRGNt+kjyiRqwOCCcZG2 dmwZDaPX+ahy6zPNGMz8yRHc4JGbsIBL/LmB1FcmarZSXlgVAJmRaqIkS3BbebjOEmFEOpWBdyG loyblQe2JZC984uBG5iuk5CXGfibneLD5mel+NKxAzE/uvaLZAtU1pURXq3fwehM8Qv9ge8nrH2 I8UQl+acjcItSsCFri1ts2Cf95CHFudqFEgGsJ3++Hf5UnvY1X4U2HndAfbjQEpm3lKN9AAsCsl sYWKCVF5j3Yyh7W0a1Z/jC++M7xKJfXtVhAh/hQuY94OsQUuugprfGiNhG0t X-Received: by 2002:a05:6000:25e6:b0:39e:cbd2:9ad4 with SMTP id ffacd0b85a97d-39efba263e3mr2007719f8f.2.1744985494519; Fri, 18 Apr 2025 07:11:34 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:34 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Andrew Goodbody , Heinrich Schuchardt , Ilias Apalodimas , Jiaxun Yang , Leo , Rick Chen , Simon Glass , Tom Rini , Yu-Chien Peter Lin Subject: [PATCH v6 03/17] riscv: add initjmp() Date: Fri, 18 Apr 2025 16:09:31 +0200 Message-ID: <20250418141114.2056981-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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, 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. Signed-off-by: Jerome Forissier --- (no changes since v1) 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 Fri Apr 18 14:09:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882310 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831120wrs; Fri, 18 Apr 2025 07:12:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXk03SAKh5/vuZ6SGir6RurcbFyNTgL4NrtWdzHR9u6yTugkuKs1UYpsGYb9oyTd5jBsi2puA==@linaro.org X-Google-Smtp-Source: AGHT+IFt44yJeVvMaCwEQp3cwuqDTyh7ZYBLNBT6Mg0htLUiDAJV8ea82v5GanNOJuUm0UVZyVc0 X-Received: by 2002:a05:6000:2405:b0:38f:4d20:4a17 with SMTP id ffacd0b85a97d-39efba3c738mr2320069f8f.13.1744985521364; Fri, 18 Apr 2025 07:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985521; cv=none; d=google.com; s=arc-20240605; b=CMP6v1//ZSz1whBYCJDv6fGB0+m5lTjyKXHoQiHRI7v4Y9h7mbMayiR6cWA8UybS7W Hio+rljyupmarS+WKk1fFWxGGOo4niAvacvdd2zhECvenaIqyx2BrNi0bJhYZluhFUvX ymFdjPnIPfJ3/cX0e7q8iBbdZuqo+LrDbDW5EHI/FRRr4hRmpiR79zKlBkYmrGOI6d+V DIxC36q5KXuQhWGzzGQxzwZvAXbxo9AjWvEkq7zgQR/EsqWqHWhs1d4lu/eNkn8dSZ23 hiUqhTIk/ELNuSosEDjwRFtpbugtNUbIWUA64JZB2CsEqFxSjcmFlJ6pQ3usi7RP41n4 SYdw== 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=dG9VIxAb02a7A/HsEZ7z0UV/5H4lYe3f+d1yazMxX2g=; fh=w5egxv/rjJWUfpqXBAmKVdNcs+spMa03G+DCvIh8Cjs=; b=jaT3t300a34VtFXg1zvfBd2q4rzW2LqlBM0SQxdmORYhM+sV38AO3vth1v5aiH4ZPX hooWUHluVeOfAoLA99AJRX3vvcOYsNAONPHsblHNdWTym2MqwujdhtSrdBrK466BSkms TFkJw+7gUkG0hsFk7p6+CYwdDMCdtSIi5VwlQNL0Mfys3dmy+4mNWLk+V7jcKeh5wxzj mRvxuCF9Q84sSOsC1+n+QFAieXLshiY1ZdRSlYYZ4oBhzwbzkf3LhZjVdyU8jci4fS+1 KbQJrKeY8PLx1gc0dFGBeEu1ib00JBpdp8QZYul5FOowpWPpnQfr/2BPtzkdN5gKsDD0 /Syw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FLiQMJ+h; 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 ffacd0b85a97d-39efa48aa07si1288528f8f.323.2025.04.18.07.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:01 -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=FLiQMJ+h; 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 18E5E832B3; Fri, 18 Apr 2025 16:11:41 +0200 (CEST) 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="FLiQMJ+h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF6678328F; Fri, 18 Apr 2025 16:11:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3F66D8321D for ; Fri, 18 Apr 2025 16:11:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-43cf848528aso14694595e9.2 for ; Fri, 18 Apr 2025 07:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985495; x=1745590295; 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=dG9VIxAb02a7A/HsEZ7z0UV/5H4lYe3f+d1yazMxX2g=; b=FLiQMJ+h+A/1bJXKy9lR1ec7BXO5rCm8O1HHu82kn8PX4tAG2EEum7JInnGJD4MCSg iieUpXhFEw80JegdLylTILEW0ul1suDhaieX3Rl8cr1qguL+cRWRJqmO5Y6JVWkPQGWU cb5oMMokfT1ztVkSDhRMt7s9ajU+l/u0c1QZoEeNJDWdoC/vWcAJ4Qw4gTWnxdertZLd 48Om50LfkvD/fILkILINrJFS7b+9zHlQ5YWKOdmfzQm+fIAZXSNCiioig+K9lMh30M/R WVcON4L69CEi/DsPBtvEcn1Z/BBmTTrP4MStSr2ZMX7sVULGnNzZEO2IHc8w4KJnBZUT xe1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985495; x=1745590295; 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=dG9VIxAb02a7A/HsEZ7z0UV/5H4lYe3f+d1yazMxX2g=; b=xDdogqfZr2kw/2uctLVEmKTpEhBDF1NSfch3TfKFQe6FG041xLDMZMd4h3omgMWS7U 9xkerBdeoe6LYgbYvlpOviN6oqzVIGLOMbzmsHIc900arJAvMZCDHnqcEkuq31mJsWXl jqS1oGy1GziNHjoHAr3pMyytf83fbV+W8Q+vr1dUIi/0kPehonUZATgrsUweU7LAqa2a RdXZ+pw//7EJJFvEsNAWvFbPvtJL3TQWg7Yz0HGXc5G6yB1LK2r8t0iiN1Xav1aqIZbw aQ5CUC+w31idmzzf9dQLdEm5OmJJ41acRNEm94MpMdDO6SmEAd5Pz21fmQDQtw5e4wJS /vSQ== X-Gm-Message-State: AOJu0YxPyKZl/ZsxZ2OI6aYZpUFRk6Fx4QF8q1f4GTAX1e/+gWKMTApU bzg0UjckNsKs8oOVlk4p4CdVznXmUhvGzAe1JwFYPyXDYf6tzXO1LmPaK6EZvXLkMdib1VgZweM Vg3gd8Q== X-Gm-Gg: ASbGncvjIgqxSl36gWVbnRURWGF5hfSdOsfUVMI2yQ0rayubGriQcHnXI6xrVPFOfEy gsegxipaDn/lpgqPhMMP83NoTIu+Nl0Y+LIENA3FcPm4+xnyQGVLa4e/+tM7RDxErXCuVTc7Ksa Ym/D8Nxbabz9l9/cBHp30onb3cyxuWp7fqBV66AqXy9U8QLC+D7OhOFpK2OBPttsDWjoKLBL3L0 17S8Nu9ogNBX/gxSLEqIH3wtfMxiCwff8GVu9sfRkTcvRrYNGdnJL8af2d1TL0moBeO+LF/SPfa pFWC/qrIk9PrHGoRsm1ITdYKgC/zvSKIpCLrBLZqwx8h0jYEnnaOW6angrz/ X-Received: by 2002:a05:600c:138d:b0:440:6852:5b31 with SMTP id 5b1f17b1804b1-4406ab9835bmr26710725e9.10.1744985495424; Fri, 18 Apr 2025 07:11:35 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:35 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Andrew Goodbody , Heinrich Schuchardt , Ilias Apalodimas , Jiaxun Yang , Simon Glass , Tom Rini , Yu-Chien Peter Lin Subject: [PATCH v6 04/17] sandbox: add initjmp() Date: Fri, 18 Apr 2025 16:09:32 +0200 Message-ID: <20250418141114.2056981-5-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 initjm[() to sandbox, 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. 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 --- Changes in v6: - sandbox: select HAVE_INITJMP arch/Kconfig | 1 + arch/sandbox/cpu/Makefile | 11 ++- arch/sandbox/cpu/initjmp.c | 175 +++++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/cpu/initjmp.c diff --git a/arch/Kconfig b/arch/Kconfig index aa60c5ff03c..ea33d07c086 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -180,6 +180,7 @@ config RISCV config SANDBOX bool "Sandbox" select HAVE_SETJMP + select HAVE_INITJMP select ARCH_SUPPORTS_LTO select BOARD_LATE_INIT select BZIP2 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 Fri Apr 18 14:09:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882311 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831198wrs; Fri, 18 Apr 2025 07:12:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVtrDmqcYlsgyDv+mMcM4zMPuQdn3pmJPMsZo/AyQKEi8inEJuIQ+/NLLuWDJAh5mYVaRN1nA==@linaro.org X-Google-Smtp-Source: AGHT+IGHIN+xPWNSyAlvB1l/TpL9CE+3argK4oJdsb+8dcHOZG3Vfq6wKKqbakJjNP9hZ6EQs9hx X-Received: by 2002:a05:600c:3583:b0:43c:f689:dd with SMTP id 5b1f17b1804b1-4406abb3bd9mr22815535e9.19.1744985529837; Fri, 18 Apr 2025 07:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985529; cv=none; d=google.com; s=arc-20240605; b=PMtjiQZDJ0saFaFIvRW9pAefRHEUyj5ejntv0HZI9XQzO6UX/q8KCSzp093PxwRq02 f5WCPct38asKWSZdKukPuCZJU62NdaMx0D0tw83TQWmkO2d3oowkR449jajKD9Vb0H/6 ZsRX5uqVWjPChGYW5kDfiPTj70qdg65xAdBJCMslh78eTUsPJjsjn3ZWX/qY1xnccmfP +Mh7IF8AZAgHBWGq2P7XZ9J4OGvEy2fRvxLB8VYkgRkikrBeE4hr6jKny70xh0NuZjQP nj2Y55HDPdpLP48yj5d3/UVZr4DUpcvk4cF9j9P8MwhYcq3nZ4nHviLp7hpNDfi5mc3l 8r4Q== 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=PoOfi9pwiceoneya8FYrnN0TEP+mOaYHhxlnDpq5h3w=; fh=NtUsnrf9cDVeWxaTnb4FcpB51qmUaJ3A/yfjTVYZytE=; b=aL1/SIot8aQZg3K7ulqJ0aImKLSWlMtd4AXmuFg5QsFzJM/rwOP3gV28LtHHi0vhVc q/W+I3XkR/73QUdLiG6Ujpc5AyysU84YCWqMfLy/iqJBxQqMAg7tbiLbb6bhYyM6NxoS DGNfSesJH0HeDmNguzTUJ+fTgtZTwtd8SUCMCiaTxlRLr4K2FFZU59Rt0KuYqEaHsCEz MPUmIelPkzhMqFzqnoi5mdoeIAelEXMrMCQ0MME2lzJEuj0zOg9wMF2Nmkuf1tVZYYxm JEFdq6MPCTxIlgnUuOiqJQ2aWQN+eAn6h2kxo6+E2dnhxXYffH7GqWuOZG2OyCRCE6Ob pXVw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PwtmQ5OM; 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 ffacd0b85a97d-39efa43626csi1347084f8f.230.2025.04.18.07.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:09 -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=PwtmQ5OM; 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 64567832C0; Fri, 18 Apr 2025 16:11:41 +0200 (CEST) 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="PwtmQ5OM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1759783249; Fri, 18 Apr 2025 16:11:39 +0200 (CEST) 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-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (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 0A8A38327A for ; Fri, 18 Apr 2025 16:11:37 +0200 (CEST) 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-x335.google.com with SMTP id 5b1f17b1804b1-43d04ea9d9aso9116695e9.3 for ; Fri, 18 Apr 2025 07:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985496; x=1745590296; 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=PoOfi9pwiceoneya8FYrnN0TEP+mOaYHhxlnDpq5h3w=; b=PwtmQ5OMgGpk9KW/wck14fOPxvr8v1+4i7Jt3EegJp6m02XpxOes4O3uIASkRWf5Qb tBf5YQlFMp6QlA3BCuH96UKOQ2NLnO1zZg9R1X1L/xPDO7jLs79AbfvC1lrCGN8nsR9I Ww/x2kiEwH0d0BCYbzTKBAB79RkZ67CCOtaFwVpLsGsZOEhu3OWRHO6a+5AQPfmt4pk1 nvuT3J1mUh3hs+f49nkMxsNvzFRDxIvwRUVV9ZAxEDS/GcAPR8n/hlHIAgtrT69UMgsN VbydoILt0RZfVjUSVUJ5SOA2YIfOHa8U078WaUuMjRa/IUv+b+0ayxIOgGX6R3+GOvL0 2yMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985496; x=1745590296; 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=PoOfi9pwiceoneya8FYrnN0TEP+mOaYHhxlnDpq5h3w=; b=jmjicdD+JYGIobMjlMZoTezXfsXaTMzVZO44adpb5DNM+shqcOG0+QPr8Vkx4+LR3M cryhxQ9+/Ag9nCcdOYm+n8zrKfZ2pXWU5phmgWFYTFI4WXTuuJOFsOXt8wqfL5jwWUMR 6XuuMOFVsT19zW59yau4E1q2r81sgTGow/CKIFWFoVzAO47lxT+DR5gDM1SwZoi5nOVF AOW7ZeS1WRBhb3H+8FvVSMIvkt80vyQGFfeUoC2q7Zp9yUWQzaSlC62obqgToykruErr rboWbTuHTUmYIjqX+TgQ/II8yDREoht5FQ+AedKCYI84xyWr4OA6R9AP+J/3vxbth0d9 6ZIw== X-Gm-Message-State: AOJu0YzIQhuTrHrRopZx6IFSaXg5whx1Gjmb4I+1Y/gyRib5212aJW/u ThPVZUbfkeUcFLWzh/Mxrp+7kE8ItPQ3MtOKgDqePvGa1qKo45HAIXu8975lwiKSJbV1V5qa9ex SWVcGMQ== X-Gm-Gg: ASbGnct7YR5U2nnQJrJz48CvgHsUc5VkETowk+Ts9q/YQPb0B1r7TtgEJUFXc2dg7B/ T9sGQMnSzZ2+gzm8BH29OjCMPdOqdqsCs3wZ1mQ0gKkZGxXTsmSQXAvBOT4DMxPWwB6JKPDMAZI 8e/HxH0m39oH1QvEI5UvvmwIHjj3mbPyn8TYpJJOPg+O3F2rm1OFRtMeTiWnT5h99dGDvo/ZK0W erMCA79YYXVsmrLP+/NyHnJxg3RGSWAxZihSU9uL8NEAp+WaRW9Mlv9HBspc3J1ngKBqOICrzQB PoorOcaIsl1mT67n489znT5lyFIMPC5ll7iFvunEsNA9Fj3wJA== X-Received: by 2002:a05:600c:1f1b:b0:43c:f61e:6ea8 with SMTP id 5b1f17b1804b1-4406ab81da2mr26771125e9.2.1744985496288; Fri, 18 Apr 2025 07:11:36 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:35 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Heinrich Schuchardt , Philippe Reynes , Raymond Mao , Simon Glass , Tom Rini Subject: [PATCH v6 05/17] test: lib: add initjmp() test Date: Fri, 18 Apr 2025 16:09:33 +0200 Message-ID: <20250418141114.2056981-6-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- Changes in v6: - Remove trailing whitespace in doc/api/setjmp.rst 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..c30e51c2b55 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 97ab71ba5d1..9db563f7ed1 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_SANDBOX) += kconfig.o obj-y += lmb.o obj-$(CONFIG_HAVE_SETJMP) += longjmp.o obj-$(CONFIG_SANDBOX) += membuf.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 Fri Apr 18 14:09:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882312 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831287wrs; Fri, 18 Apr 2025 07:12:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX8x8zAYe+btiCRDgoe6NNMFD5NWJk7vzJM4yFycm9TOJPCeR+D3NGi5pfHYcg6qt4nQ8abTw==@linaro.org X-Google-Smtp-Source: AGHT+IHanN3fFhncRxbuhkh/aeiLYrZ+i9YclR0YG8e9j6KgXTMTJmSItOG0zVcUFe8heBP9sh+b X-Received: by 2002:a05:600c:a4b:b0:43d:683:8cb2 with SMTP id 5b1f17b1804b1-4406ab96871mr25827225e9.14.1744985537756; Fri, 18 Apr 2025 07:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985537; cv=none; d=google.com; s=arc-20240605; b=eImL2gXtn4rvDxtZE6s3loPFL9OxfY2KBBYb7AZHFgSkFKJJ8hqYjvHVhlXRXzS07W Bgfa5Z5mdie9D6t7or5lqByD3ZO8rJ4U1PWIjX9/D4Jz6HK1t0liVCwO4r08LDgAwWfv zIqAMdRdwB3PDl4fUk0sFpspYkHz0AH7DJuPrMxjb5tBmyXcQK9CL8G6qQOQIwQ8IKqV c0dMEWLoR+c9wJ6+2zPBSiTGAqgJ7HU2nulJnlQvbgA8PNHyMs19LYKDlW+VYmHYydSj pfkUVts056VnFn9x7MOrJ5ED+af2XeSya6a+V/8F5OqeuC+lI04pYyqwMnt21q0S3pW+ KWmw== 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=PCOSivW4G25Wr3pzerYd4MtsXVJwWLTDzqpEif7nwzg=; fh=3ajAWemUpQMUVRY/qfFnQ5/tSrzbdA5mjW8JpOKyVig=; b=b54OHXqFBMshZBPQQUGgbwytGWVnzf5a/1J2ep7OaP3Oqs/G+EmutvsxLQxrR8WQqu x1450WpKjHqdjZtVOpWYoFttRt0A7RSWCyFUtErSfDdpc/1kiJkI7VzGTSUcws2tgTJJ MHOhTJc8FDIdocvXzjaA5rJPQpn1TTCvt/ngKUwDk8noEMQjlAWPQpCG5Ucp34w8mFgu BxMFe3azdjmOfPVY83JmSyaiBi/7U8Ey8wisPWR8fmsaokLwedTst51KzBq7dPkq4REL n7QTM6ZVxM9xnC5durziDpZ09DRLtyMJwaY1nY+qztMO+YtUnl/BCjJzscbAKAi+8y0+ p9XA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m5xEU4Kj; 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 5b1f17b1804b1-4406d6ec1f1si9621325e9.148.2025.04.18.07.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:17 -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=m5xEU4Kj; 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 AF40A83291; Fri, 18 Apr 2025 16:11:43 +0200 (CEST) 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="m5xEU4Kj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D1625832A1; Fri, 18 Apr 2025 16:11:40 +0200 (CEST) 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 45DBB81E72 for ; Fri, 18 Apr 2025 16:11:38 +0200 (CEST) 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-4394a0c65fcso19936525e9.1 for ; Fri, 18 Apr 2025 07:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985497; x=1745590297; 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=PCOSivW4G25Wr3pzerYd4MtsXVJwWLTDzqpEif7nwzg=; b=m5xEU4KjCQK06tvGaaCinQLCGsxW8fIGCj6CQ2IR4gGO/NsFojaRbOFiiNNqJHdrrc KfDm8U18MdiIfQ1JCjDWdKHCxjEb/gmRx9yaEFTSwW2MbTRewyPWZTD3/JEPol0CkVn3 fjqaiSd3OtNs5PLtXaW2DPKSNLw3key287yOIwjb4K3qfJpkRp9kgZrioZrhxEQeB25K vsaTXphyG9WsGh6I4+azp5MvmaPZxVAVoHS4QeD1NjyZJY87TzFmTcNEE6zgB8V/OB7C X3SHAblCGXTOdPExO3HVCnrzlU21pGUHBx01HTZJwXbvWZH+4eKGtCYDD52uARQClodm fi0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985497; x=1745590297; 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=PCOSivW4G25Wr3pzerYd4MtsXVJwWLTDzqpEif7nwzg=; b=pwkE0v5YkCSizTUpQiCHLfwjTKjKQIlLzhRqE08RZ4UpKrnLLPwkVtTZISx4rKAx9c FLtIL5e689IpIvwVjN2NJCuYhggGwN+ofwDrE/nkjnRrIwZRRWuSOUqdx7E0N+eTgram j835XwnCqCcFKqXDvDs+7HxUoFPuL79cEmFM2zgOghBhEyZ662TewyYzkfm/6VtUCGWN CIhot7i7i4S+ExmhhRX7K2ETlZFUW1psz30NbwErEJtcuz0QZFIulVPFb4dXhrwTZqNS pKqgYkAubNI5a4A5G7GEyQn3I9GzzAypv/wqQxDqP/gx9U4WsKwKCNP1BBzmwP5iO+9B PObQ== X-Gm-Message-State: AOJu0Yxq+3PDMBNB6l0E9iB40+LE1+SnuNg/zyjx3ucU+iJslyDgGX0G /p52XfU3O/6TVwiigFY97trrX2nUsiyAfo+zDqr1in3T0Lo1zLJzXkEqQAGj4LdVlT3DUE8s6m8 p2tys6Q== X-Gm-Gg: ASbGncsyaREuv/BkpvymRlYwOYRDkM8bFJOQcoJ0Edh8Iw0mDENeX253Ar0Sl83k+rV vAF/nuTDAncGm5EwA7+HY5waguiD4sM1+u+5nZwFBoapZ3N9v4fMmTaz7ZCC2zdjfJ1YwSeRlQn fIbf52+vCRa2OhelWGrcr/udMvStgXgdyV3E8PZ1rj0lcPepnLJm62EdiPaac+rjnltEsDlkxzK NbuK+Fnka6BdrapHbbnyjGYrba69wUag34Jfs4fWKO18uEwYgsEEcSHkiHZ/mGyAqkOfGeSW1LZ S0s5OlF8lE99yVianLkFV/oYXUho+gzHAvmu/XjqVY5ej8/lag== X-Received: by 2002:a05:600c:4f12:b0:43d:1b74:e89a with SMTP id 5b1f17b1804b1-4406ab964dfmr23736475e9.9.1744985497394; Fri, 18 Apr 2025 07:11:37 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:36 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Christian Marangi , Heinrich Schuchardt , Mattijs Korpershoek , Michal Simek , Patrick Rudolph , Raymond Mao , Simon Glass , Sughosh Ganu , Tom Rini , Vasileios Amoiridis Subject: [PATCH v6 06/17] uthread: add cooperative multi-tasking interface Date: Fri, 18 Apr 2025 16:09:34 +0200 Message-ID: <20250418141114.2056981-7-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- Changes in v6: - struct uthread: give a name to the void * argument of fn() - uthread_schedule(): remove useless else after return statement - Do not initialize static variable 'id' to 0 doc/api/index.rst | 1 + doc/api/uthread.rst | 7 +++ include/uthread.h | 123 +++++++++++++++++++++++++++++++++++++++ lib/Kconfig | 21 +++++++ lib/Makefile | 2 + lib/uthread.c | 138 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 292 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..f796a16f25f --- /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 *arg); + 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 ac34ec45bb1..b2aecd8a49e 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1258,6 +1258,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 7178c5a3e3c..18ae0cd87bf 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -159,6 +159,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..aa264b1d95f --- /dev/null +++ b/lib/uthread.c @@ -0,0 +1,138 @@ +// 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; + } + /* 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; + + 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 Fri Apr 18 14:09:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882313 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831336wrs; Fri, 18 Apr 2025 07:12:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUpFoxjAnjwTkhuXDPRAjJgwztvPGi2kt4jdB+xasuSJGGdPVOHx4A0VfENvqh9Noyw8zkNzg==@linaro.org X-Google-Smtp-Source: AGHT+IH13LNOa/8QHUuKYDhBt9em2ujeThdK38evwESKubcIdxaWho83AqQhctdnBRiLGXsoXyno X-Received: by 2002:a05:6000:18a8:b0:391:1218:d5f7 with SMTP id ffacd0b85a97d-39efbad7d6amr2128605f8f.40.1744985546057; Fri, 18 Apr 2025 07:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985546; cv=none; d=google.com; s=arc-20240605; b=FQTRtrOJAh9URa1K0QtqGE4f0W4QmG0kMGF5Ls4P2dzRoRdFldji1Y8hGCPJ1oHNHl jw9Cuv/OUCzrIWIkzfp5A2jgcdY0q8/LuB9JgL6ncFi3h2K5LVka+8PtDjlI4G9A7Qai EHqrwI528hhRqeXpor5xajxWj2mWrh0VHhQyD7RKpp3FoZG3fdWLkMaEgYTre68hdA7y cpdAdq7BDrOqv/Gnq5op6PlukBaWYcaK8nFMXwT7mroprxV7ToUEBopdL8YHxB5//OfM WGZVfLI1UY/H86B0yyDZ/uim9xgZNJDLf8JlfazcAUo/vsd8ON/hKrO0Aggnbw4XOsz6 E8SQ== 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=30iCggiQxsg+n7n81V9I0g3OaEhSTqDQMaxbYhLD4SI=; fh=mu6nz4wWAs4ff4HfOrQmILvkL7+/OL9o4TpNHf8BG70=; b=cvNO9fvBfBuK3P6lt3IzKi09dodkUqezM96txImOvsPa8lruti5fdMJpMg8UGklLXA XyK4ETBavSIWOYTx/Bw8IeKBQ+3B+1cr3HXQWZkNALQNuVp3S6XCKOwH+6Xs3mTMPx0S cFzqQH4sJhuoI5LRLvM0uYM4biudNk4xZ5i2ntxjwe/jjYQ/nyp1GBcJhzmNxAswSwaI EHp73QeQ3mpR+jjFzsAIg4IGOi8vDzIHOcGic8JNGR8eeB/MeXG90Y2SHn7L6ZodlN1w 1ssB4HvLRGvc2as0zSkHR2fDoPogIg7rF1VQUvgqjgzkqB9hubpYtYxkxmfOGa+Vf/LV RELg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HMeNkWfH; 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 ffacd0b85a97d-39efa48c69bsi1283576f8f.427.2025.04.18.07.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:26 -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=HMeNkWfH; 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 08A66832BC; Fri, 18 Apr 2025 16:11:44 +0200 (CEST) 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="HMeNkWfH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1C26C832AF; Fri, 18 Apr 2025 16:11:41 +0200 (CEST) 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 10B928321D for ; Fri, 18 Apr 2025 16:11:39 +0200 (CEST) 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-43d0782d787so13681395e9.0 for ; Fri, 18 Apr 2025 07:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985498; x=1745590298; 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=30iCggiQxsg+n7n81V9I0g3OaEhSTqDQMaxbYhLD4SI=; b=HMeNkWfHYoMfYnwjXrAgtWXzTI4uI+A9ufD3AgVNAPhH9UX8TYktdvf4Ts1h0F6IBU oCszz05eIuk2/VA8rkGMSAAB6qV3zAlbWHRwESTSC8ogl3Bn7uqpp/JZEe5HAF9ZtxJK jsldiVkB5nvTtHf/j22MAkxCYQv4xgM0dusg0VeYcEdKxx04Qf8sivgP411j6eXCH67P C6ADA4CQ1ADaL+vjnUu9hVqWVCxYg66GmOwWcBcA0Oho406v6ADifGhzbvfU/zEHaWmJ fc/T5AuDcs2h6LLEqzFAas0sr0LgE7pNpsrzJorSsaqiuJbIAzAjxf7X7WiINUo2cnp7 WL8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985498; x=1745590298; 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=30iCggiQxsg+n7n81V9I0g3OaEhSTqDQMaxbYhLD4SI=; b=Cd3XI3l07VeSu0RBHY8gJkuajYDUzx/3cRGe7CzbHSkOQLW29ox/Jz0ExQa5NJwSCd aLWA48pGuxCBIBv9P/LLlZd/QpIQgK6OgE2ca0hKuNIl7ci9+2d8nNgN4acJhztz6Nxh XYmVkx73fmeC7YMYYpedjWPD8L3JM5TStQhS33F/83liNd+NORPPJo1NJGinRy5Kuy3t jYz6GPqGKJa702kGY1F9YXxFNECKsJ8F97cjNTHMxkJuFLEFQRpz67AWdkFbRxPntkHy gNPwILDUETLWzpf1nIBXyIdzVhFfvCFOEyjtIv5fXtLx3/Ln0qGrlg+kKpVQlQ4B6WIz LnhA== X-Gm-Message-State: AOJu0YxZLZUCpxuSLAk9GLg0xaFZ1UZ2qsHGiiNQ9EQAHe1s7MucH4wN Hwc2e8aowlL7iSBcnNT4xMo28MApzlU2veEMTWSSVulMFCcSbKmq3F7DwCWnHtOW8xuaRqDqxyH YxtDZ3w== X-Gm-Gg: ASbGncupkpXVNGpUBKIeHgujA6Zxg4cviDylzqXJr43nFdklSh438Y7sgUR6Jx+gcr2 bHEfKDWOyJZYrj7wbaPD6XRdHYUAmFmuq9Q1ViyNgGuzlVff5PfgVaKAzEcoE2092vbl8g1+jzD zDsc/v1AaUPxE4U2j/vBOqzlGVt4rdOg3dDtva61u2izG45Cpocw0K0up9qEnosVMPuu+cI/3xB 4lz274XPzV3rqqjBmefX9yKxP2Ng8t2MWbtg93TuZ+v/isrdZjzSqNfex+qGUfjVKXbbNRFP7AG BsDdKXLFiRxu03vh9gYbmlBQXyASyM1afBddtAPFjufaIdXGHA== X-Received: by 2002:a05:600c:3b9b:b0:439:643a:c8d5 with SMTP id 5b1f17b1804b1-4406aa872fdmr28696685e9.0.1744985498282; Fri, 18 Apr 2025 07:11:38 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:37 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Tom Rini Subject: [PATCH v6 07/17] uthread: add uthread_mutex Date: Fri, 18 Apr 2025 16:09:35 +0200 Message-ID: <20250418141114.2056981-8-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 struct uthread_mutex and uthread_mutex_lock(), uthread_mutex_trylock(), uthread_mutex_unlock() to protect shared data structures from concurrent modifications. Signed-off-by: Jerome Forissier --- Changes in v6: - uthread_mutex_trylock(): return -EBUSY instead of EBUSY include/uthread.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++ lib/uthread.c | 27 +++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/include/uthread.h b/include/uthread.h index f796a16f25f..89fa552a6f6 100644 --- a/include/uthread.h +++ b/include/uthread.h @@ -50,6 +50,23 @@ struct uthread { struct list_head list; }; +/** + * Internal state of a struct uthread_mutex + */ +enum uthread_mutex_state { + UTHREAD_MUTEX_UNLOCKED = 0, + UTHREAD_MUTEX_LOCKED = 1 +}; + +/** + * Uthread mutex + */ +struct uthread_mutex { + enum uthread_mutex_state state; +}; + +#define UTHREAD_MUTEX_INITIALIZER { .state = UTHREAD_MUTEX_UNLOCKED } + #ifdef CONFIG_UTHREAD /** @@ -94,6 +111,44 @@ unsigned int uthread_grp_new_id(void); */ bool uthread_grp_done(unsigned int grp_id); +/** + * uthread_mutex_lock() - lock a mutex + * + * If the cwmutexlock is available (i.e., not owned by any other thread), then + * it is locked for use by the current thread. Otherwise the current thread + * blocks: it enters a wait loop by scheduling other threads until the mutex + * becomes unlocked. + * + * @mutex: pointer to the mutex to lock + * Return: 0 on success, in which case the lock is owned by the calling thread. + * != 0 otherwise (the lock is not owned by the calling thread). + */ +int uthread_mutex_lock(struct uthread_mutex *mutex); + +/** + * uthread_mutex_trylock() - lock a mutex if not currently locked + * + * Similar to uthread_mutex_lock() except return immediately if the mutex is + * locked already. + * + * @mutex: pointer to the mutex to lock + * Return: 0 on success, in which case the lock is owned by the calling thread. + * EBUSY if the mutex is already locked by another thread. Any other non-zero + * value on error. + */ +int uthread_mutex_trylock(struct uthread_mutex *mutex); + +/** + * uthread_mutex_unlock() - unlock a mutex + * + * The mutex is assumed to be owned by the calling thread on entry. On exit, it + * is unlocked. + * + * @mutex: pointer to the mutex to unlock + * Return: 0 on success, != 0 on error + */ +int uthread_mutex_unlock(struct uthread_mutex *mutex); + #else static inline int uthread_create(struct uthread *uthr, void (*fn)(void *), @@ -119,5 +174,10 @@ static inline bool uthread_grp_done(unsigned int grp_id) return true; } +/* These are macros for convenience on the caller side */ +#define uthread_mutex_lock(_mutex) ({ 0; }) +#define uthread_mutex_trylock(_mutex) ({ 0 }) +#define uthread_mutex_unlock(_mutex) ({ 0; }) + #endif /* CONFIG_UTHREAD */ #endif /* _UTHREAD_H_ */ diff --git a/lib/uthread.c b/lib/uthread.c index aa264b1d95f..062fca7d209 100644 --- a/lib/uthread.c +++ b/lib/uthread.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -136,3 +137,29 @@ bool uthread_grp_done(unsigned int grp_id) return true; } + +int uthread_mutex_lock(struct uthread_mutex *mutex) +{ + while (mutex->state == UTHREAD_MUTEX_LOCKED) + uthread_schedule(); + + mutex->state = UTHREAD_MUTEX_LOCKED; + return 0; +} + +int uthread_mutex_trylock(struct uthread_mutex *mutex) +{ + if (mutex->state == UTHREAD_MUTEX_UNLOCKED) { + mutex->state = UTHREAD_MUTEX_LOCKED; + return 0; + } + + return -EBUSY; +} + +int uthread_mutex_unlock(struct uthread_mutex *mutex) +{ + mutex->state = UTHREAD_MUTEX_UNLOCKED; + + return 0; +} From patchwork Fri Apr 18 14:09:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 882314 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831409wrs; Fri, 18 Apr 2025 07:12:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVB9yao9r7PDi5a+bFm/nwu8zdRZ7fQ9l5QuMZ3qrnnQZo/C7io4Q0Jh4zggTrPtubWs7mx6Q==@linaro.org X-Google-Smtp-Source: AGHT+IFj0NM92wvPa61AMNafSSeyaZCOF1bL4TPDXVKSvcT8ba7sH8QqU6w0xkCPqaKyDg0WdV2s X-Received: by 2002:a05:600c:a088:b0:43c:ec28:d31b with SMTP id 5b1f17b1804b1-4406ab9767bmr33709965e9.10.1744985554627; Fri, 18 Apr 2025 07:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985554; cv=none; d=google.com; s=arc-20240605; b=KYrQ3fEStUsCcCuxvD4K6/YJ4V6Mq0KvcmA3lVT1DaPQqL3ToOqRjfP2xOaK4zttoO QXWd5yzhovtK89KpJ39YvftzUhSS/c8NGMAhCg9u6zUXR0c+J4lc6SGXPXgY1a/BUaFE ycPR468lK12r9TfmuFj3mVDke35h/WpjIcKc9TP0ciTknIK8TMl99CVk0pheVomTkOEJ lKV53Yi/rvPB5DZYTM84YJl8eCR8kdjM6WyPX5Ea+CMmhZ1dAhVUGp9zpZk8ZUklFA9Z hHhumIh05QuWkrBy4Jq5QIiAK6as0XAUryVXC0fsJlx/DsNpNa/egmdv11DKBS3r7UH+ h1AA== 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=T7y64nRkt+jVoLpphpzyDqiLu3YG1kfVphGiAgljCfI=; fh=BSzGCQVn8CiVVMJWIGK329Mh4kQ9EfQx8bctusJF7WQ=; b=RaQk7Slw9gaBSdfUpAvjOChI68zOZVxrd1XRxdcnLSwCwK0x3ZWM4jZ3cn1VVYpGQO cTWVxLfL6aAcU+by6h4Aap49TWp614T13WsIE0NMyHn35wekSfUoHcZuYDQ1RjzE5itX IAzxYr06mjT0hoNWKzIh1Xe9sMLCFlVqKZRNR5E6ssCHJPBtopORwOVuII5i7Y0ZA+cC It+d/6yCNr3N++5B8oTZqT9w5VbdH+iKR9fS9GkN/DoCf9TbS7xdNhnvQ9dJ7RraymyB LFPgRRL0E8/JwieoRcV29lsiETr0TKSLBjA5CZdCfBw4H/rt1i5wXEHSdSe3KNlVfuMH OVmw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gclyxUu0; 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 ffacd0b85a97d-39efa4a5275si1304138f8f.640.2025.04.18.07.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:34 -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=gclyxUu0; 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 51716832FE; Fri, 18 Apr 2025 16:11:44 +0200 (CEST) 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="gclyxUu0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B9098832E6; Fri, 18 Apr 2025 16:11:41 +0200 (CEST) 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 C228E8327A for ; Fri, 18 Apr 2025 16:11:39 +0200 (CEST) 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-4394a0c65fcso19936875e9.1 for ; Fri, 18 Apr 2025 07:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985499; x=1745590299; 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=T7y64nRkt+jVoLpphpzyDqiLu3YG1kfVphGiAgljCfI=; b=gclyxUu0taUX/MCgP7ntmAvHjCDJnk1k7pmiFaTj/+gKwTwm3pya0OJG+viqZbWpGA Qfd4Q2rCb+9DlWrOL58OerwX2GxdeiibbIzWNqsmcoN6MLdfevCNTiojHS3ufU8InnSD 561KgAdjGQEvuXpdnr5jYsLm1epKAJ8+pS+U2sNzZ11VPMQZM6gSDH/6RvkzYvMd4WuS HH8GtMwxzLyNtI9FGrrPxlk4JFPacrgrmU+mr0h8wUUEn7+rlkErMOtxV1N8BN6u+Kxx HKQh/cECPCm9s1kvjYVGvBpWiF3QMIrZ+aeVz1eo82EyR3y0cuGdIWSFCRDuUiVpSvmH zMtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985499; x=1745590299; 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=T7y64nRkt+jVoLpphpzyDqiLu3YG1kfVphGiAgljCfI=; b=bEgSSEN2giCrJ+9H1B0KSaUk6mZvIWOAlXlotNG3x0RV7TdmJbGrjoVGrFi/5Wy4lG q8pSTCX+qPSNdcCkbAtTGZ3Lgfd8LQcpFsJBfeP7lDJ27H5C0iRd53eY9sLh8p4lywaD /oAiMZT26dA9LwGak24SxxW2jdwsXpDhW7WRs3Wg1U4K3R3vhaJZDkreIpSE77KbOPFJ t0vQ/dx9rkUg+hXIRv078ywsN0lopWl79OIrrQnYJMjsDDv+iA6stmzbImx8atgAYaC6 XGhu6+x7I0lKmO82IbBFTIPBV/k3eSlmUTmJr4J+trU27BwPTh+umIKNOaBmG5ge8QKs Lj4Q== X-Gm-Message-State: AOJu0YyF6bfzmmvOaPvMIKrtpIwoBSfiSMR5DALEZxhSOXvY4msGp4/q mMTjn/heAowH8SZ9HCouehDD4AKWZDDnpyt0mJTXkDhJ33tnVVtqSjF/ey/0ayKApAk0ZpYiU5E wRskSIA== X-Gm-Gg: ASbGncvKNw4ETDCfxBErqDV0n8uq5PafJqpUqogqywz8ARz3oZCCPrsZ2iH9YipbHGs Nqvs10nlFoorIWaWcNrAVtFJVojnClJqawL7DPZRI120sYzdERk7nB208fNSbspRYtyIpsI+VNr yRqVfEndVsFUFjcmDq0SVUwEa+tDXV9ADOPYPuZzoik5YzRhCXGAtREaq8iPZ047H9BVCa+ZNfK xB/F7j6rZqDPtGJWWj8QxnTi0Th+nr1VcXYLtj55YAMCOus93ds1oDy4czNnUqKT/UCzFBAyXIG +AZKfb9bUsmBlSfYbhX3nFJNFLaW1fCa7lSLm5BAzYejSjXJtQ== X-Received: by 2002:a05:600c:350a:b0:43c:e7ae:4bc9 with SMTP id 5b1f17b1804b1-4406ab7a56dmr18843825e9.1.1744985499111; Fri, 18 Apr 2025 07:11:39 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:38 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Stefan Roese , Patrice Chotard , Rasmus Villemoes , Simon Glass , Tom Rini Subject: [PATCH v6 08/17] cyclic: invoke uthread_schedule() from schedule() Date: Fri, 18 Apr 2025 16:09:36 +0200 Message-ID: <20250418141114.2056981-9-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- (no changes since v1) 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 Fri Apr 18 14:09: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: 882315 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831479wrs; Fri, 18 Apr 2025 07:12:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVfRm9eiYq21FSILUJ+2/ifRYjBZF5lKGQwnYaxskVQtBLaYD1uT+gPY0Wm9ta0oJ6RQGoGXQ==@linaro.org X-Google-Smtp-Source: AGHT+IF/5bAPmV93if1Oy6PQs5GHwEcTI2eqGHfvwmBA195luKXaFafaVTfus2v6agS63efOtvxf X-Received: by 2002:a05:6000:40dd:b0:391:4674:b10f with SMTP id ffacd0b85a97d-39efbad530bmr2429635f8f.36.1744985563085; Fri, 18 Apr 2025 07:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985563; cv=none; d=google.com; s=arc-20240605; b=gkc0M0X9yBqqvCSZFnRPb85cMZRXrNHEzG9+Fljc6V1484N+AdMczrspPEJzw+STw/ ejwxTZ7zlqGtyHGxBzsOdmX98rQJpcdgQeZNQ7nc68Iro0khMHPxzr5lYxTODmJ3RWQl I79GOn33jfaAqWiKtJJytpYDetDx0hwGk8xTprWrkBxrt0daCe2fvGAaMRT+dImNTJ0b JZt2oO0BNGk4FUKM2v2kh6hFhs0Jpl2pBKz/DlScAqcDibBB2yX5iPsHhADXr6jWmSRn GiR/tPzAMhsQKyqmcfHpXq1w3zfEahd0aViJpz8p9lt1I4Qs1im6zVc9nm21+GXvIyEh HVEw== 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=eWkPJaJUPiBbwy/a8Iueif41WDM+TwEabt66XUA//0g=; fh=NhVI5B199TYN08tSLlofnXu2IV8l3rTSQ2Au7qwsF0c=; b=RWyWHbVf+l+lcfPEye+rUSzDB6hoPtNY1Zqe1MnlH1jOEbGbHTRx+4+jZTFnsIdaXQ KnYsSZ8aMktaiNvhcuCfhkhyBkVxQ3boTm18PaDlgptDzGYNvWxe1VlNeo1S4uTgbZrk GqvAeABd9LKcs3oeTD87KlDcfcnWYF/WC1UHWvc2WtXCXESCHyDkcs7RX1AR/tWTKaSw j7keCzswHjxT7uY8TujNrGJUjGTS3RrJnPlp3wtJtKeP5BALUw9s5EU4HQautG9jsvAe TLJoi0z4XttHpSCjc6gurL9L+kE5JD30fmjNv6Ht+rULQCp6cQ1PXgQ2TFKyRloqOEAE jnlg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ryj+3o/k"; 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 5b1f17b1804b1-4406d5aea58si9625075e9.61.2025.04.18.07.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:43 -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="ryj+3o/k"; 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 9BF5D832BE; Fri, 18 Apr 2025 16:11:44 +0200 (CEST) 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="ryj+3o/k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9510183208; Fri, 18 Apr 2025 16:11:42 +0200 (CEST) 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 7EEBD83285 for ; Fri, 18 Apr 2025 16:11:40 +0200 (CEST) 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-43edecbfb46so13921965e9.0 for ; Fri, 18 Apr 2025 07:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985500; x=1745590300; 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=eWkPJaJUPiBbwy/a8Iueif41WDM+TwEabt66XUA//0g=; b=ryj+3o/kf/vkI6mW9xLuGr09lf48Wr6CEDeaoxzmXF9n1vAG0tZNQrZTDt7F12wYmv n3EFz48qpoPRu/u8uMY2cZVUHjsgB4mgjP2DH27RLTGbbbQzyfK0DLRmU7U/eLu7E2oM eZZfLlZ0v/fwNbzX4+ZpRjjWoAeZD4A7kscp/NBhH8uaztaGnHavaBhPa3Z5tA7dHoHC yIIoxgz9M5CoPIu3Wva3RiVNNphpL8LWoaFLJaD3nEu7VsOCn61uksEHCjOJfK4ejcAM gjsa8EHp6uA+VEfavN6Avq0r7xDnNnN3hN6XiOd7EQe/WKJEdGjgNTZuxHoWHNgsESkn XPMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985500; x=1745590300; 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=eWkPJaJUPiBbwy/a8Iueif41WDM+TwEabt66XUA//0g=; b=hH9gsSfhG6wV0KIzJrzrbzVu1uYDGuBl8PzGUTyNQHCU7OMhEBI1KffhGBSPaTqww+ u7lF3E8NvODVklIOkDJL0xYnL0QFJlUtKmtAvJh295qlOpDG6EGxCC6Q+MMJnjGmcY07 LwsKHyRqmglHaY/haSKtWWXRirUB185t+3+Hz/zMXW0GDz5rFDPGxAi/Z3xC2lxryBe4 2k7Mgz541U7qN1nSLNzlVqLpnIY1Rq6VbJBH2GO20kbL6m1kXxe8Lnd8A2Zxcbj7ln0Y iB1CrQktChHW6dunaYKsAa2zB9SiwFKZ/sd+N2g4cQH55zmLGb33HMHqk0yhbmiM/Clx TUcg== X-Gm-Message-State: AOJu0Yxa9qcDBoBC0DJokg6TKCv6OeaHiPM4q6RR2Vcge8mxTh8p/kyL 24epGqrCB3YdCueRRFun9I6n64/BWuzAb2IR08uTg8muRMl2LyoCoZx68QcQOu7Rw9zpqv8MYhb +IRH9zw== X-Gm-Gg: ASbGnctttR57FsueUteMI7P60mVS7yQWO8QEHQebynsG6fdHsMw9I7dFGqm34fkzb1f uLrqBaEj9+z2sgxjEdJI6j0dDde9MebXqOEAFR6q/SPPLDeSq0+HP0R63Hqr1PvqEDBU+kzhJXW Cny5r/Ph+P61X3YAB+e70subSmn4it0ps52eiUNlKtH/UUTAwRNR/ooVmxmuXpaaxihw2hVOO/6 GfzQrqWgrgRiqZH7habX2HZmM/2jG6vcft4EE1eQM177+NZ5dEF9A6/AL9WJsyuE12WxkKFgf+g cYNWIi1cX4NlICq8Q+XtzCmty/9hWldrqrRuFUCPnieJJohhgvorXc7MlMKO X-Received: by 2002:a05:600c:8711:b0:43d:934:ea97 with SMTP id 5b1f17b1804b1-4406ac0f82bmr24883465e9.27.1744985499762; Fri, 18 Apr 2025 07:11:39 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:39 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Simon Glass , Tom Rini Subject: [PATCH v6 09/17] lib: time: hook uthread_schedule() into udelay() Date: Fri, 18 Apr 2025 16:09:37 +0200 Message-ID: <20250418141114.2056981-10-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- (no changes since v1) 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 Fri Apr 18 14:09: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: 882316 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831574wrs; Fri, 18 Apr 2025 07:12:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWJH7uzKlbEaflX3xPy64MHGuRPHug2GXUi8q/pXqXMt/NkJYcrok1f7Mj96GDQ3AoSG5yY+g==@linaro.org X-Google-Smtp-Source: AGHT+IEY1dhVYZJbwaEqCmdgZwdxtzs3xBXIA2NEJGoambHut/Vdo1uxixx5H5NrHfQ5L3/rTLaR X-Received: by 2002:a05:600c:3b84:b0:43c:ec4c:25b4 with SMTP id 5b1f17b1804b1-4406ab97202mr27713895e9.10.1744985572093; Fri, 18 Apr 2025 07:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985572; cv=none; d=google.com; s=arc-20240605; b=Dy1gVOof7jzAzujMA2PjZdn4zvKmHvGrAvTWQQt/KTCDttJuO3UPmFNgocJZ9u1hWH P6VPOBYOjY/pS5XjDvujQiFGaZ9aMOtnXyQUWDkahtx1She5Rl89NroIhrqPgEtQmYYS csuyRVzp4uqkgazZ4qxzlRiiXnfj5U2SqhHcuGz5agWaSbaF84Qxxsd0T8QXwYw4BrYR wmE6wV3cSel5AgIm4Fe9tm4qQYQKMXqK139XThGJOnm9OHUhAzIl8CX4iSWv/JYFhwtJ +UpaIqldkYEy8LdLVUspe5TwcjLAvdtVFc9Y3brjilavdQfl97xwsemKBYHblzpoNvJv OT1g== 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=BREg6FS3yrP9DH3yBgZFyhDX4rt/L4xfFNZxOwyVTlk=; fh=NtUsnrf9cDVeWxaTnb4FcpB51qmUaJ3A/yfjTVYZytE=; b=T2yoJLaQHQNl3Uj1OAV2u49s8rCHbwZEVe7N/E+brPuhoDzIo0dn3RtKaPTz2kccYG tuLeFlutqAPHW4jitLYtWMmjb1JWbBf3c8KixGc5T3FQu1jDi3M3F5/y1HbTDT1Dpuly xJ200tXoZV6CL8LSwgN7iXYAdFW+XfaryHQTQeGdzLJwkibHCmlSI+BPCdbC3hduT3lM 3Bk9dG0Bo+Vd7Z6nFvcRLnML8qYSwzGO3AF2o4GRjFV/2BO8q4SdKD+SMH4083ftWXIj pOXUmf187jghy9vPPZuXru4vI1NPmSfkLXslR5EZBM6WlPB9yXx8Wv67KV+RFNJLaQSk rDow==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YRuMlo/k"; 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 ffacd0b85a97d-39efa4a50a2si1284921f8f.646.2025.04.18.07.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:12:52 -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="YRuMlo/k"; 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 EBC3A81F45; Fri, 18 Apr 2025 16:11:47 +0200 (CEST) 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="YRuMlo/k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9B3CB8331B; Fri, 18 Apr 2025 16:11:44 +0200 (CEST) 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 5F840832BE for ; Fri, 18 Apr 2025 16:11:41 +0200 (CEST) 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-43cfe574976so13820385e9.1 for ; Fri, 18 Apr 2025 07:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985501; x=1745590301; 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=BREg6FS3yrP9DH3yBgZFyhDX4rt/L4xfFNZxOwyVTlk=; b=YRuMlo/kvAjbiwBJCE6EUiOfjaFyD0Bxx9KJuW4z0K+o6IShVFIS/FyPR+dr26WwR3 QEz7hM9PSmg3r1o7HE4tXwg2y/CEy/54AxVUomJEBAW7Lul4nI3OcCMmx4ggPbVqelZA swTIfpWMx9tUsUHIJTAD4mleE25HgW0RIvxIvyBGgrMcnTl5tXsGCHTNmwPIXagQoVmp nordeJHxhIvrqo6as/b5lyvn9UAqs+K11oD9tEHY9QFjpJbuh4h2Xelyyoxv6icpi1lu P/sP6kIuJ6qjIF/A79VmOKflVRL2yHXhXG6eh+FqGtqaX2Bkqdt1nAtBjZtvGERxz82w YADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985501; x=1745590301; 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=BREg6FS3yrP9DH3yBgZFyhDX4rt/L4xfFNZxOwyVTlk=; b=NnR3tkFa8Zz+tSCH6zEw/UECuGQg2ET4YHmNCktoNf7mNYR5i2UUvBM0HxvlueWttL OTj/ZhDMyri7v5hFHnxdtFB3xxxFWJtqjIRcuBk0PXo1oVzYrvlApj5wfCP1y39ZOROu Nqb23CurwCiAib+bsQ5/glFmFsDNEcWHhKfjbV7C4lcd8/WN5Un8u457wOF+pkc2seJD wI5edDVBF7x1VRz3tFgE2zcj5e1dMDWIp+ualK6Iy2yAtn/goV8ec1oEVN/kVSv8RtfT 5YXX76/vGisncP+10BB7lvxevs68cKntoIEHwK9N0jo5EsJZDs2I2vhK6QBU4vNWxV6G jVjA== X-Gm-Message-State: AOJu0YzJ3bpOT/47KeKvYc0KvkOLCOwA2G/6GNQ6bkHH9FkRWQ3ruw2H V4TRlxvyGGx9qpxbxrBK6Poc57Li8r2jmrAoMDbujEaolJ7vU2S8XmGsl0ewUepPvGX5bgn8Mqo fKP6Xeg== X-Gm-Gg: ASbGncssF3Bj6bc7JRMm0bSdVXzrtG0gGOBYK5obyLQUYMFXvvjtFNo/jPIdnMLJfzv PYTIkcMN3yPZVTfYDF7/nIO+70mb+XUeQZNV6WQvwueqYuSIgbi7JORqkpRwrF7fwTgT9iAxN1S jE/T52t5D+bH8qsz69pqEWyPEyNYKoW1RT4Vtzyn7Hm5kp4GNF1cTHDHrUrLFWbV8TuzGpdk48a OLpqAL0ikYqweqMr8EJn6GCdfjlzwJWUf8v/1w9Gf76tb+F6X7rYmYkl7DhrEP1G9OoMwVj0dOa TtPhEd9xeP5RbzFxLigpO8JrvQxliHVnlX8w0DVM3edjLUNnBQ== X-Received: by 2002:a05:600c:3b0d:b0:43d:7413:cb3e with SMTP id 5b1f17b1804b1-4406ab7f548mr19822575e9.1.1744985500657; Fri, 18 Apr 2025 07:11:40 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:40 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Heinrich Schuchardt , Philippe Reynes , Raymond Mao , Simon Glass , Tom Rini Subject: [PATCH v6 10/17] test: lib: add uthread test Date: Fri, 18 Apr 2025 16:09:38 +0200 Message-ID: <20250418141114.2056981-11-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- Changes in v6: - Rename static function lib_uthread() to uthread() so that the test now shows as ut_lib_uthread in the test log rather than ut_lib_lib_uthread - Fix spacing errors 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 9db563f7ed1..d620510f998 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o obj-$(CONFIG_UT_TIME) += time.o obj-$(CONFIG_$(PHASE_)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..ad0217485dc --- /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(); + } +} + +/* + * 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 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(uthread, 0); From patchwork Fri Apr 18 14:09: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: 882317 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831650wrs; Fri, 18 Apr 2025 07:13:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVTsMcrL5PdGmewn7GN6K19vTdciUoqAb/gJTWG8TJ6c3/vf4nl+mAPmzVVo1MMvtBtv9N3+w==@linaro.org X-Google-Smtp-Source: AGHT+IF9QGpQD67sGYaYsu8VXbfZoGDNsmNScnr5176ekvw9eP3+MyGuYazyl2ZMe62wr86+ICGb X-Received: by 2002:a05:600c:350a:b0:440:66c5:26f4 with SMTP id 5b1f17b1804b1-4406ab703b8mr24116945e9.1.1744985580431; Fri, 18 Apr 2025 07:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985580; cv=none; d=google.com; s=arc-20240605; b=QUUqI4mXz3w16pYcY+qdF7uYqPwqTXetjhtIHPr9V+5UWTOjGB1h2KnGZlh4HV7aHG kkA+yW0W7byNuaC7Rl8j0UDFx05BnjuuVlCndrJE70ivXWzVlB6h8QixdN1jACRVl1fA mEJ0JFQyz0hH0h6QosnSE1C5AyVH1Bfe1Mkh0PzDrCTGlU21bT7Rpm5jVSahN32BoAcE yKDBpRk5D6TN66h1EV5l3rXhWFSTufhW73Kki+gp4jie5S4bmJAXCUI2gVtK54s+ySVk xiqP38S62ZnymaSPN/YG8Hfpyt3jXRaytinsBvPNlAHJshsWWex06DME3GDL0NW6gc+M 3UCg== 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=jkWL1MaiqaXAhXj3hNcPT7tFwLYqRvBzsR/OrfCGyek=; fh=mu6nz4wWAs4ff4HfOrQmILvkL7+/OL9o4TpNHf8BG70=; b=dAJxZ+GJasDgFh6OQrrqrksut917lfziHpvSFqyR9D7u8AE+xxb5n7hwS8vQE6ljJJ zkzJTjW6lKQowS7B90gbfchfxRbZhIB0bcodzIrJIw2UEAXhzqmSQrfmeeV/3sv3f937 ADF7wyPNEVUxToBTjjXWb8owP0tXwYl5cl6W3Za4xOGmPCbt1tU/TSfP6OdDDEp3dsKS HAou3AIdDaxP8TyVWxaVbjcF5ngpzJkRZD8j/c3MXeO1IRLeHaEKgOGghKWRqMpJpihl F0htZh1UMZQPM9S3rEg03+81TkNZ2lQgSBb7+nEcB8W5DOuxg7dy95QeYsoxnsPP4v2r krbQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n2TAe6FM; 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 ffacd0b85a97d-39efa48abf6si1248746f8f.283.2025.04.18.07.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13:00 -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=n2TAe6FM; 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 43CB0832F7; Fri, 18 Apr 2025 16:11:48 +0200 (CEST) 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="n2TAe6FM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4CDBC8331F; Fri, 18 Apr 2025 16:11:45 +0200 (CEST) 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-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 2356A832E6 for ; Fri, 18 Apr 2025 16:11:42 +0200 (CEST) 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-x42d.google.com with SMTP id ffacd0b85a97d-39c1efbefc6so1200973f8f.1 for ; Fri, 18 Apr 2025 07:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985501; x=1745590301; 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=jkWL1MaiqaXAhXj3hNcPT7tFwLYqRvBzsR/OrfCGyek=; b=n2TAe6FMizprySNQzSP0dWNQm2jQ074d4euUjW5aSlc0C31J4dX5qg6eutQ70Zbw7V js/BtI+YZ6T9Jzjq/y3fB66kI4D+eVA/gcRBFWIM4qmgSEAViwU6Wucxfy44g242Rd8U Bo5WwpniRyPqPg8EXc/xQC7AcXTCS4ScMAupd9YnCYxKRgWVBDkFuHhJp0Kc/FgztLJI ZlHZM7G83431qII2obAzLL6xk43FLVw2YtDt3s7bm17yoVHiq3yp96Iqdq68Mx5Od1cK oVN1yp17M73TyFf7G/PPCoaEWkjlCzSarThfbnHISlxHl6xpX3EntlDpKnGfutujl/SY Gj/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985501; x=1745590301; 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=jkWL1MaiqaXAhXj3hNcPT7tFwLYqRvBzsR/OrfCGyek=; b=DYQ6/KFh1opP2GfNZ8jcSV0Eto/JoNiALv0hBNaALiLT5CpirJ80WsBpZ/RnN3tZLn 9hZ463gN/oyJKztzqUAOa2iJz52nY3accEBOCNmGwVLBvLYC99rkfrf/ShLX+Nod86B+ TOVd0wPHzTfz/Gg0QoaZ/54WxMmEpxehhTSqPRaocaapcU3aCsHwqjVhEvGTBE+40u/w lILpI6Vok/o8eQk80Ww90xCx2SNrKljfwDW/Fp9zoGBz2uqcXkSdLHs5xid1Z5Iw6mY3 osLa9crS+0TO72dbLZncmvGENj0y7GREnrSO/Q8TO3Zwdt1REkQU7uRO+7Kbq0uiFRfh GtJg== X-Gm-Message-State: AOJu0YyaM1CpW/tRhSotHlXmKfP7MwV6hToqZajDj+m5BpbGdlUpYTxs z0RSsbXyszWS1UzpqomdsOxELnIgi2T6yXMEoQUVT3IqO1Df6nu2EpHsMwuO+GbPZwFD2f1P2OX GPLVE9w== X-Gm-Gg: ASbGnctbqVRuMoUTZFy8GS92s9pNZpeVc1S/ZpO1mcSYSCKiLFYUaBGK961vo4NFN6Z WZ+Rxdqg/WFUiAVc8EgW1zIlZW13cLH9pxxXlAwUwvNNKRwAVuwXQIMt1i5wIpfdJQDVuoSiKtm Tk2ZuvvlRPYAibhYwoTl6lc9Ls3dL29ORO1x381nAM009f/HnEsA/Fnx8JzwFmCVQ5lVx9pjBms osEKQlCSvfSZgkAteBD0xgFnyqwmjfh834OMGoxgryCNTGwQdN1tCRnOjQQU7kA8fJaekXAlkjF ZK9V0cGrlZjPJ0f0u5mO0SRBsQNIU+3lES6iDq2PUUY6gDqbfw== X-Received: by 2002:a05:6000:1acb:b0:39c:1258:2dc8 with SMTP id ffacd0b85a97d-39efbaf211bmr2256119f8f.57.1744985501438; Fri, 18 Apr 2025 07:11:41 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:41 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Tom Rini Subject: [PATCH v6 11/17] test: lib: add uthread_mutex test Date: Fri, 18 Apr 2025 16:09:39 +0200 Message-ID: <20250418141114.2056981-12-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 test for uthread mutexes. Signed-off-by: Jerome Forissier --- Changes in v6: - Rename static function lib_uthread_mutex() to uthread_mutex() so that the test now shows as ut_lib_uthread_mutex in the test log rather than ut_lib_lib_uthread_mutex. - uthread_mutex_trylock() now returns -EBUSY not EBUSY when mutex is not available test/lib/uthread.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/lib/uthread.c b/test/lib/uthread.c index ad0217485dc..10a94d1c560 100644 --- a/test/lib/uthread.c +++ b/test/lib/uthread.c @@ -78,3 +78,69 @@ static int uthread(struct unit_test_state *uts) return 0; } LIB_TEST(uthread, 0); + +struct mw_args { + struct unit_test_state *uts; + struct uthread_mutex *m; + int flag; +}; + +static int mutex_worker_ret; + +static int _mutex_worker(struct mw_args *args) +{ + struct unit_test_state *uts = args->uts; + + ut_asserteq(-EBUSY, uthread_mutex_trylock(args->m)); + ut_assertok(uthread_mutex_lock(args->m)); + args->flag = 1; + ut_assertok(uthread_mutex_unlock(args->m)); + + return 0; +} + +static void mutex_worker(void *arg) +{ + mutex_worker_ret = _mutex_worker((struct mw_args *)arg); +} + +/* + * thread_mutex() - testing uthread mutex operations + * + */ +static int uthread_mutex(struct unit_test_state *uts) +{ + struct uthread_mutex m = UTHREAD_MUTEX_INITIALIZER; + struct mw_args args = { .uts = uts, .m = &m, .flag = 0 }; + int id; + int i; + + id = uthread_grp_new_id(); + ut_assert(id != 0); + /* Take the mutex */ + ut_assertok(uthread_mutex_lock(&m)); + /* Start a thread */ + ut_assertok(uthread_create(NULL, mutex_worker, (void *)&args, 0, + id)); + /* Let the thread run for a bit */ + for (i = 0; i < 100; i++) + ut_assert(uthread_schedule()); + /* Thread should not have set the flag due to the mutex */ + ut_asserteq(0, args.flag); + /* Release the mutex */ + ut_assertok(uthread_mutex_unlock(&m)); + /* Schedule the thread until it is done */ + while (uthread_schedule()) + ; + /* Now the flag should be set */ + ut_asserteq(1, args.flag); + /* And the mutex should be available */ + ut_assertok(uthread_mutex_trylock(&m)); + ut_assertok(uthread_mutex_unlock(&m)); + + /* Of course no error are expected from the thread routine */ + ut_assertok(mutex_worker_ret); + + return 0; +} +LIB_TEST(uthread_mutex, 0); From patchwork Fri Apr 18 14:09: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: 882318 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831728wrs; Fri, 18 Apr 2025 07:13:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMTqHeOn2cHfT8f7leeFTq/qDpL2NRwdUVXhwUF5UtcUFpML4JIQCjhGJ48ZUGEe1LD8NN2A==@linaro.org X-Google-Smtp-Source: AGHT+IGMlakgARvWaQt4RWU1oJ+eY0vMkwKqSYTEFD9h7LQ3mnkKypensGsSLKGEYTxEjIrBrOMj X-Received: by 2002:a5d:584e:0:b0:391:39fb:59c8 with SMTP id ffacd0b85a97d-39efba5f83dmr2397882f8f.25.1744985588860; Fri, 18 Apr 2025 07:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985588; cv=none; d=google.com; s=arc-20240605; b=BXYEwM0CNBaax9H87mYL6hAJZahAO0B+dvP9adjz2iOlFekFVSGFLPmCv+AMVE9iu4 DiBN87UqHFBwDxx/Y4QKBvwlnMJzZNQ7PRS5h27qdaDIq49qeM4APh5n8mwsVDMbcVEp 3D/OD6PHxdDOkfFguy92e9zTrpBtvElWPoia9GnCgQicXip549LZTyBCdHeUn29fe1K6 w2ZCdx5yoZR7TYFXcVBnQpBtX3qiOXLLX7XHvVXrqBfsAseDcPrVeUxCm9yp25arcco6 FWLp3XNuemnCYqDvHGsZ+fkQFhqVdSdYdvZdNjesAGyrxFN3pNPnH8zOQXY50lCvu2z2 OdVQ== 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=On1IMPWoplq7DV/CKkFuhHU7kI0Fa68u+tVWTz1RtrI=; fh=Xj/IAMEUh+2VRXOGd56GUJcMmA5lvvvngKeuPSdE60I=; b=cex4w78IRzZU9TFASCYwvHwDo1SD2+WaBe4Tsz6kmhSr57ArnG3tJM8gNX8uZBP2/N 0py2CMVPedDZn/0TsGgvESDOTpcxw10I78XDUi6prCUhNCUfcZvATM/W9wpeCr5ZF3yc hAqt/vDFSdivWL5SvgrTK8rflJC5CmR0jKFiRENyZGUZ1YVIs2wJnnOcOxyK1Y5UqaK9 /MdEkAZuL6sNXRYp4maoZcao8ZaDoG8GX4LCqkm5yh2vEtGERXsfHbq6iiYcq/h5Y+Oh 4AXNHnAFJlJ1S/ZC5O1T96rw6zK3k6Rk7INNUytm+S8ezxO/BZmT1mP++h288e9ZBMba SlMA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aXc9psZw; 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 5b1f17b1804b1-4406d5d1e13si9708465e9.118.2025.04.18.07.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13:08 -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=aXc9psZw; 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 964A68333D; Fri, 18 Apr 2025 16:11:48 +0200 (CEST) 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="aXc9psZw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A3E0883208; Fri, 18 Apr 2025 16:11:46 +0200 (CEST) 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 0CD5783253 for ; Fri, 18 Apr 2025 16:11:43 +0200 (CEST) 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-43cfebc343dso15489775e9.2 for ; Fri, 18 Apr 2025 07:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985502; x=1745590302; 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=On1IMPWoplq7DV/CKkFuhHU7kI0Fa68u+tVWTz1RtrI=; b=aXc9psZwWPzGcl/ykxIckXL1ntKWMFcy5HW/XeTg0iiM2055d2S5f81Uv5EMs+IX9g EPRzcpseXHVXiS9ZVzsXpDvnBH+vH8wPSGmTKI7eDwP/gJ5DhmcNtxVsWXI7+lAlIFp9 qfxuvR7+xJSUsz95L/lJ98rHF9if7WTTXlfCOHW4SvbDNPdo4xWN44kV9MknG6H6kRLx 16S7ApsH1a69B7xQ3+NMgrfD+y3mUyFmKcdBL01p6+HLkPJL0in28WrXrpppwEmLkDgA vHHkKKpQWcX68euiO7UtqUe7sNkskXj2UUwxCW4uPbtS0uxKzjxbhPFDgZBBIlNWFpjM KonA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985502; x=1745590302; 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=On1IMPWoplq7DV/CKkFuhHU7kI0Fa68u+tVWTz1RtrI=; b=eZm8MJAb6nUQGPj0WUT+6D26coqe9ogwnQQyStAWeRRaOLmQu9oZ/oZFWC5hEpu8Ww E7jOjZyB0NZopLjIEEulYCUCtI9kHLINKMZ8jo01Cn86UUjr3XvPIVVmBuhhCOyxTcoM JREcM5V+aSnydZT12Kc7F1U+TfUrNV5TE//OAAB/z4V5/HFIZBd76Cw92Fk0B7rclpYB 4udPKha8juZu1XJDp7s+0M10eTe/AUyL+uTCXKwVUIdjHtLCx9x0N0wa34AQFzw6w0Qh 8Wk4Vfrtz084wjP5o1qToxX0a2TAvxxETbmhHJdU1W0F11dtaJ3sc1FBgdQIchKgNjYC ludQ== X-Gm-Message-State: AOJu0YzxKs3+sI16vkL3QVuSg8idlDfLaUefmGYWQRCR0pA8vyUBy1JO czOPuFZ0EppY0aydSPvw5hh1635IjYNklZwr217LotRmQZ/aszki3p8i/2IVk1/Eeait/Tfenv+ fvIh9Jg== X-Gm-Gg: ASbGncsEKFpjtr2/HVjNcPu8tYaki76O17rk5IAC6ics9yb8TqJG41RJB5TVQAFuIO6 la0KjXOfBV0Y4tWQcMxtMB+GVRJ0uEOw5pPzYEbWSC6huXRZoggC55dIw8Dwf/fICdtMASKqLJh h9xqNEf2No1nm5Qy1Ob1/GDFw6EEu9B1HevtNZD14fj3aFoGuHzWwy0a9yqzn8AioON3IkY1n7D 4yHOeJOVdjYq1yP/0wffN307zyhRhNA6bQ95OVIQdSK5Z2b62QVOXTdVhoayQvhKH18x0yd6HGM qnlUgxM5AUlmHR7pNt2H+GSC4A5dHZ+w3KV71J1SWyz1BHG+3g== X-Received: by 2002:a05:600c:34c1:b0:43d:fa58:81d3 with SMTP id 5b1f17b1804b1-4406ac227fbmr21989565e9.32.1744985502215; Fri, 18 Apr 2025 07:11:42 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:41 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Casey Connolly , Dragan Simic , Heinrich Schuchardt , Marek Vasut , Mattijs Korpershoek , Simon Glass , Tom Rini Subject: [PATCH v6 12/17] dm: usb: move bus initialization into new static function usb_init_bus() Date: Fri, 18 Apr 2025 16:09:40 +0200 Message-ID: <20250418141114.2056981-13-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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() and count the number of USB controllers initialized successfully by using the DM device_active() function. Signed-off-by: Jerome Forissier --- (no changes since v1) drivers/usb/host/usb-uclass.c | 83 +++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..fa1af8f555a 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -287,6 +287,45 @@ static int usb_probe_companion(struct udevice *bus) return 0; } +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"); + return; + } + + if (ret) { /* Other error. */ + printf("probe failed, error %d\n", ret); + return; + } + + usb_probe_companion(bus); +} + int usb_init(void) { int controllers_initialized = 0; @@ -305,47 +344,11 @@ 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); } + usb_started = true; + /* * lowlevel init done, now scan the bus for devices i.e. search HUBs * and configure them, first scan primary controllers. @@ -354,6 +357,8 @@ int usb_init(void) if (!device_active(bus)) continue; + controllers_initialized++; + priv = dev_get_uclass_priv(bus); if (!priv->companion) usb_scan_bus(bus, true); From patchwork Fri Apr 18 14:09: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: 882319 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831780wrs; Fri, 18 Apr 2025 07:13:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWo/GTP1pTGplI8G0JaqcijfRpqGu3YYA2xATYVef63/bgYFBCb4mysQcF9tgFWhxHmtA0C9g==@linaro.org X-Google-Smtp-Source: AGHT+IHdtowQUwgGdKQsNzDioOeOwjYH1eYobHeR9l+Bf8vyT9Jcy8RYu8KQFRqTfNzhde1B5smV X-Received: by 2002:a05:6000:2203:b0:39e:e588:6731 with SMTP id ffacd0b85a97d-39efba385d2mr2146121f8f.12.1744985597052; Fri, 18 Apr 2025 07:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985597; cv=none; d=google.com; s=arc-20240605; b=MFU1tsBxpHl7JZG/Ur2/QmFht6m2/CGSgBuGy/hOXOdZoz81Zf3GKqIbF/mkzvp29F 7+QuBibhlGSeK03EtFpNZlwi/Wr4vf0wLiNdDEuenyCvjuSMjs3woTC23JbzNpVAQrCV FK+pngCbCWdcupPIvIPr7e8rqH2npQdtgH1LO84Sb3GmwQJ6RHfuWzNIiF4U+aTJSPCv /J60dQ/TfvKmvWwAD5XMigewhI9anhwq1skfHD2/K0wQnGgtt2NStAgGIIN/l9q+PkjC iem3G9jy0pncwq4Iwznkn2/oxPPSqAM22XZUszBT1Wc8NhxlPQpM+h9J9GcSms43WeMF +Ciw== 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=qtRT87sNx5BNuNHr3YfDDynmpHNga6xvVj7uwGyYQr4=; fh=9y1AeF/3bj+XFSXOcZ85HpXM0iVz5ibbF+VbdgobAo8=; b=IxOG2PgkodR3f8SE6ODTyIBUo6YcK8Q+MvgRLp2/HLfmJrozPwBs9Iq8h9WJDRSYSg CEk452S1MT6NYV7SPIWQnJNbPdbyDXZ0QzJXd7oT31+HJFYb3q5s5YyJ86SBDSLrUhMv uTD2qXyqgUvEpghOalU2qFtoer4wQtVi3FxoPDR25TOMlWqU4PCi4HXrTvENQQ8VfR7V WMJbSu/8SVA5v8ITyElPxmKzh/OOpmSt+Uv3zPUESAK2mAN9x5iAPXheRblPguzcpIek rF5vMVUUjbPvZKo0NeeKi+u0+RN4XlaOzakq8CB6fzctdq7crdjcItjsrae9dPvyGdbt 7ooA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=V2qxCiEa; 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 ffacd0b85a97d-39efa4a580fsi1301620f8f.687.2025.04.18.07.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13:17 -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=V2qxCiEa; 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 E817483212; Fri, 18 Apr 2025 16:11:50 +0200 (CEST) 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="V2qxCiEa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C851481F45; Fri, 18 Apr 2025 16:11:47 +0200 (CEST) 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 037E481E72 for ; Fri, 18 Apr 2025 16:11:44 +0200 (CEST) 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-440685d6afcso14522805e9.0 for ; Fri, 18 Apr 2025 07:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985503; x=1745590303; 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=qtRT87sNx5BNuNHr3YfDDynmpHNga6xvVj7uwGyYQr4=; b=V2qxCiEaGPWP1biV5isFf+8A+5XlCDIqPOmyjGX/mjqVOQqsfOyRnPKuaHYZ8oiX/z cdoNA25kS7crB6cMccG8o9gKwU9bS6cv91LN+Vv4AeEabc1lT5exmYTrBGZL8xnraA7P mU+ZXj8GbLIqXlEzuBzrZggfzhBS0s4zZwJJpr9hj3gk/tZAIc3cEEORHFJJjcpfJHVI ZJAtG0BKDjVSmgGJH1ozO4b8DrHyrw2H3BvRq+nWv2nw5DsfXF1mLLHmnAPzFII/a1Oh mBzXEj6RkWAH9scsx27yrDJq7GGm+XpoRtBhen+rBJ6xFN6X8UFm1VLTq1FIojV/quSg 0NQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985503; x=1745590303; 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=qtRT87sNx5BNuNHr3YfDDynmpHNga6xvVj7uwGyYQr4=; b=tp12cODkqXBiUk9bYnTUFsXjPTq56xNkNR9ZVWDYHenV6y2+ilnfMIFHr2CeWZ1TUQ /leSvXwQXYRqv3VUqrAhxBN2VdsurrZfs2z8JllE4n11dHigj6O1pOgYggvqSlh2DgfH 4hfomhmxPAq5+y5uVT+YwhUWWyahFIlf3TXR6w6lS3htPhhMaN4l05xm0hYN+l6uyGSh 1YCDpqHXQ/7rA2tXAxzgstlmglQvNEdatZU95zj7XpjH7d/MEt6huVFxJ2wol/lQx4uM n3FS3vkmplY0ktQEdFdVOA0E1HY6lqRTVbEhuTP7n8ixXB0+y4EMYUv9LETvwbZWhexQ /vYg== X-Gm-Message-State: AOJu0YxravAHp+g08XToZPbu9APJFiVqKPilZanP0U+6L7szZ1C00m1D MGPfeob2ClTW7m3+VSj60aclsRbYWyiLSgsQioJGRAM3lkuG1Z55wppVfe5leaGMhkWM5IENLcz rI0RoAQ== X-Gm-Gg: ASbGncv5kG2OXKzHf3MCd5TYIdJU3ZoSf7jx7UES2jZLNtf7Dj6STpd9lWAYS8BpfU1 LYBPBoVf+Lm40PFu/oFjHNmCvcDHjc8RI0Yn+A7PK2D7wkBid7iBbKyw/fgi95JWAgNxTlBwLlG 4OVprs7F4+IWzdzzeYLoveJ/+K0RTPi0Aox1gAwQZn0EeT1zMad3am4Cf8xfc5XwJUi7dazKrfa UFpVvCj+ivxraTGR1DX442AehZm6dBK/g2+3dP9nGunqyKR4GfFeJZhIpwD09zlcXEZhfKEoCg+ VHmYBzA3ldzRNwatkPrTWqko1uKpxsLwRmxO3juTFT2qCi4WKQ== X-Received: by 2002:a05:600c:511e:b0:43c:fc00:f94f with SMTP id 5b1f17b1804b1-4406abfa43fmr16935685e9.23.1744985503097; Fri, 18 Apr 2025 07:11:43 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:42 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Casey Connolly , Guillaume La Roque , Heinrich Schuchardt , Julius Lehmann , Marek Vasut , Mattijs Korpershoek , Simon Glass , Tom Rini Subject: [PATCH v6 13/17] dm: usb: initialize and scan multiple buses simultaneously with uthread Date: Fri, 18 Apr 2025 16:09:41 +0200 Message-ID: <20250418141114.2056981-14-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- Changes in v6: - Fix "Alignement should match open parenthesis" - Fix "Lines should not end with a '('" drivers/usb/host/usb-uclass.c | 119 ++++++++++++++++++++++++++++------ test/boot/bootdev.c | 11 ++-- test/boot/bootflow.c | 2 +- 3 files changed, 105 insertions(+), 27 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index fa1af8f555a..7247245a702 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; @@ -172,6 +174,10 @@ int usb_get_max_xfer_size(struct usb_device *udev, size_t *size) return ops->get_max_xfer_size(bus, size); } +#if CONFIG_IS_ENABLED(UTHREAD) +static struct uthread_mutex mutex = UTHREAD_MUTEX_INITIALIZER; +#endif + int usb_stop(void) { struct udevice *bus; @@ -180,10 +186,14 @@ int usb_stop(void) struct usb_uclass_priv *uc_priv; int err = 0, ret; + uthread_mutex_lock(&mutex); + /* De-activate any devices that have been activated */ ret = uclass_get(UCLASS_USB, &uc); - if (ret) + if (ret) { + uthread_mutex_unlock(&mutex); return ret; + } uc_priv = uclass_get_priv(uc); @@ -218,28 +228,23 @@ int usb_stop(void) uc_priv->companion_device_count = 0; usb_started = 0; + uthread_mutex_unlock(&mutex); + 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) @@ -287,12 +292,12 @@ static int usb_probe_companion(struct udevice *bus) return 0; } -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 @@ -307,39 +312,96 @@ 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); return; } if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); + printf("Bus %s: probe failed, error %d\n", bus->name, ret); return; } usb_probe_companion(bus); } +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) { int controllers_initialized = 0; + unsigned long t0 = timer_get_us(); struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; struct uclass *uc; int ret; + uthread_mutex_lock(&mutex); + + if (usb_started) { + ret = 0; + goto out; + } + asynch_allowed = 1; ret = uclass_get(UCLASS_USB, &uc); if (ret) - return ret; + goto out; uc_priv = uclass_get_priv(uc); @@ -347,6 +409,9 @@ int usb_init(void) usb_init_bus(bus); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + usb_started = true; /* @@ -364,6 +429,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 @@ -380,21 +448,34 @@ 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); ret = uclass_get(UCLASS_USB_HUB, &uc); if (ret) - return ret; + goto out; + remove_inactive_children(uc, bus); /* if we were not able to find at least one working bus, bail out */ if (controllers_initialized == 0) printf("No USB controllers found\n"); + debug("USB initialized in %ld ms\n", + (timer_get_us() - t0) / 1000); + + uthread_mutex_unlock(&mutex); + return usb_started ? 0 : -ENOENT; +out: + uthread_mutex_unlock(&mutex); + + return ret; } int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index d5499918249..9af94786870 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -392,8 +392,7 @@ 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 +447,7 @@ 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(); @@ -551,8 +549,7 @@ 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; @@ -604,7 +601,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 5f9c037ff53..b261bd5f620 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1290,7 +1290,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 Fri Apr 18 14:09: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: 882320 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831858wrs; Fri, 18 Apr 2025 07:13:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVWnef3WCni9ZTv3fosj4BNyaTEBbhg227l5SIE1i1bLecd4J6zMyrpqzm/sNZZx6hbP/bYcA==@linaro.org X-Google-Smtp-Source: AGHT+IGuG0nmTCtv6ySdAhvCpezGeqCdjM0stuEIy/bawkbXH5muTie9ze65zh4FoXvGy8lREtzC X-Received: by 2002:a05:600c:154f:b0:43c:fee3:2bce with SMTP id 5b1f17b1804b1-4406abfabe7mr19916415e9.26.1744985605516; Fri, 18 Apr 2025 07:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985605; cv=none; d=google.com; s=arc-20240605; b=FB/HQJn5Sd62AWRR+C+1RftxH3sW6fXWxeQR4m8W3VO6OpIVWy1axKhnU++MY8UKHc /PfEI9UpG9xdW/66yQQ3vCRnC5rEgALi1fIfQVAxjLcY1Wo+u2THYMkdOFEQGSmUan75 V7RR74iTVqnve6/4MLmGxihF8pacjlRPrXX4ZqWl2I5Wou/LF1JmrlW0etzfSbdkyNZb cNV0/bHlXmLXNcIm4kC4FG5SBOYQO7qSHYcrZhzvctQpspBE3pT1xG5ucxY6lGPEMaeB 9BDzJwlnE95LFFT9st2dgi6wSaDqNlpK2NECVp04AZlJ+PV7+/UyCF+HAAqrCxFvdThB rLhA== 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=chWyipr7Iga6dO7xyssNXgSX1qr0xJqct2dEjWcjxNA=; fh=DfMkk4ne2o0keqppMMQ4J9fCWKwys+yRdgrkCzV7IM8=; b=eFgHfyJ9P9n3FqPxvg+YAEMW7J900UXElyX8Ial7xJuI3oAuTmqiN5Q5ApzGjHDDMN 1VJaiPuBsS90phogz/aHymtD5AVvGYGU6PANSV940Cx3KJ2OegbHJlCf8/Ipnq2mmAkU wS6DS5CwcVEJdXSLH23FIFLParVyXgCio73JdBMqz64EEwcGXit+mhZ6l24pYfhld5PH hmMfJ1ABy1vfxeJ8BGRC1re1F7yE6exQQEchdHnJMy7qq9+X5JNC9FeWFbYT+YqxF5Se 8G/DHJsKG9+jm5J+2gUvDIcTvMmEhMSI27yj2i30X5ija/yLeMpbXD/dAxbIN//5tvIX L+8A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O0K5YHxO; 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 5b1f17b1804b1-4406d5d27e0si9509095e9.128.2025.04.18.07.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13: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=O0K5YHxO; 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 4367E832BF; Fri, 18 Apr 2025 16:11:51 +0200 (CEST) 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="O0K5YHxO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9B15483335; Fri, 18 Apr 2025 16:11:48 +0200 (CEST) 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 39F36832A4 for ; Fri, 18 Apr 2025 16:11:45 +0200 (CEST) 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-43ce70f9afbso16513315e9.0 for ; Fri, 18 Apr 2025 07:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985504; x=1745590304; 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=chWyipr7Iga6dO7xyssNXgSX1qr0xJqct2dEjWcjxNA=; b=O0K5YHxOPWvRFFs0UooaMgVYchoTZqu0QqtW3tP3d9d1059yyHWRbVtLijSdYG+9uT D8RYyvJdztI+/YQ7hkvn9GUSwNmuqH2+2xBW/0sVqxJQa1V1X0wwu/4s3xDVeAxZGTMg cZN29LOBFDawz9ECd0We3ChscULz36FPd6q85vr85YfeVSvW/w3p2M4PwQZUnm92bUWa ViEgRgfSyrwQZo1dyNAqa2lUiWp3yUWnUVneH/QtwtY2+Vg4m+vKvwbqGKTDDY+v0ZoQ PUX/M+M1fu0wMtP5jRb+ph7AsAtoBMbQrrG82skDbTIlnrC2XR+ZCq6V2QFLeqlKigiK ZO2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985504; x=1745590304; 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=chWyipr7Iga6dO7xyssNXgSX1qr0xJqct2dEjWcjxNA=; b=bddmH0A8vwvZYAVgvs7nGIvGKRmPSb78TLzBC9gQoufec40fmI3FerOLXPacVx0BIi FvzK4CvM23Mv/EjcLtA6ydHYk6RAqT4FeGeQJBcWR1oI2Wvk+znLwf/QkxzrnXAk9mUv FSefurxOzaxNoxQdzMUG+840SjX/ojLZsIiN+bM5RCueYNKax3NQmQ+eIFNA56igUe2R JVqq0Jeern/BQG6QP2ro/7uxVW/B4UGV30kSBX2KqfjEmi3QaI2ad9lZH55aIo8hyOzz XWA0HKMOWPDpNxJcj4hpFrtRnXE5Q2JedabqcK7ZknVchxsiIcnIaV0+mKzSk9mVVhe5 AVtA== X-Gm-Message-State: AOJu0YxbzBdAy//ArB76X20BGLxXQK5BgUi9VKxmVJZSiiBSnzsro2Rc EcK64gpiocEygJqzEbsusdFDCj12WTxu0izCN3EFL/nrCp5rvKNoH61bviEjQIgQT3/GKceemOV ggZpDvw== X-Gm-Gg: ASbGncutcMI6DysKcOmznWPCP0UCcP1udf4WNJKnLvTCfSUf08f0lByHwHzLG6bbTdT ku99Ixu+og+g4acA3d49QeItI7CjMBdOHH4L84Ittrcw93mIklQy33BEifpeHpwVLAEzex3XtB1 bv66TT25zn9yLnG/q3cqqgD8kIusUrnSijDMo+btqgcgebsBtDfSHEFhPN8NckngdWDqphtcE3a 4fFuMn/BP8loKA6Crl7nuq6f5h8YVKtfhNkF3IzW+VypJ0bP0DRQE14G7MlfkWdW85ELeNYRaqE HzumxxVodCikKmgr8Vfr2dB2sJBHqutcLWCiFBIDW+bQke0GgQ== X-Received: by 2002:a05:600c:1d8a:b0:43d:878c:7c40 with SMTP id 5b1f17b1804b1-4406ab937demr31919145e9.10.1744985504368; Fri, 18 Apr 2025 07:11:44 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:43 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Casey Connolly , Dmitry Rokosov , Heinrich Schuchardt , Ibai Erkiaga , Mattijs Korpershoek , Michal Simek , Simon Glass , Tom Rini Subject: [PATCH v6 14/17] cmd: add spawn and wait commands Date: Fri, 18 Apr 2025 16:09:42 +0200 Message-ID: <20250418141114.2056981-15-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- Changes in v6: - Replace one invalid occurence of idx with i in do_wait() - Fix badly formatted comment block cmd/Kconfig | 17 +++++ cmd/Makefile | 2 + cmd/spawn.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 cmd/spawn.c diff --git a/cmd/Kconfig b/cmd/Kconfig index c2ce519d1e3..2d31abcef73 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -3081,4 +3081,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 8f0cee8d714..80cf70b7fe8 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..eddbcb792b3 --- /dev/null +++ b/cmd/spawn.c @@ -0,0 +1,187 @@ +// 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[i]) + 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 Fri Apr 18 14:09: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: 882321 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831911wrs; Fri, 18 Apr 2025 07:13:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVrP/PII962Ua8d9PI1Fk2nO1FoYPzwLz/Iuo2kcV0mufZzMueG9ze0b8wxPFuHP/1uuVeCuw==@linaro.org X-Google-Smtp-Source: AGHT+IE/ZUh3RWK9UnO1iDaTw+8HfFWEjZeotGjoAzvMHFUYgYnkojFGIKlPIG33dDKEp40QVy8V X-Received: by 2002:a05:600c:1d18:b0:43c:f3e4:d6f6 with SMTP id 5b1f17b1804b1-4406ac27928mr29094175e9.31.1744985613179; Fri, 18 Apr 2025 07:13:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985613; cv=none; d=google.com; s=arc-20240605; b=bult0agVZO3lj69puZKZ7rixoAIbRF1RCwY3XbKOws2ah1mGai7cS5xUZWVnU9D72c V98zcrbAgdRBISpt/nma4xKvugi3gVQx5q66boxQMdyMWOaGWEX4YE+KiekVhzFIjDOP QHVN+a9luAMnCC5iTyowUYkk43IMSR0BKS9WTsks9DTmkKIn76uMru2qlF2bPJA/bfI1 +yCES0g4yuFF+HNV2GdC76zrGzwFrn3U+RyFuq/36AOnrU9rbrihx9St5MGjaVvcnnJW C78ksjDaUo8lwRuKKAvYO7rx/3HeVWw7byYbfbMV21o1SMRp0LVI4B/70b3z29VLJjG6 6Zkw== 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=oV06jOcGhgL3zQiSdJCinxggWnUr0Aa60E9KHFCFYe8=; fh=tm5rISUntxEK2e1cV5c7CmpkxEU0okRirSrF7/b/Bco=; b=a8/XTHEwXFAQzzF4VqnjQ2GWMkbJN4dC5a+YPXPKYn7ulp+gVDbqDMYraLuWQQeNHG SD2VCQoiCr8xLu5b4nd0MKs+B05uR4Y+9q/Tt4cupJoKF7n6dHicuifcptyaftpPL0D2 mFQDV3UNjBEGdiGV1P1LFqqi7mL/PJXKNTsfEhZR3+wCX1w0lR8Swkw3Fvqt8kvyKbz+ DCCRNuwQusZA4tTKiORCX1XluB97bI5O65wRUnbQeCBEXW5Z+n0Rf3WyhFt9XfgJCEP6 gOFNltEntJFSgsQ/GFHKgHdgPJYfoRq9dUq8aq/GQBuIbIqaRv5i6VAnE6woOceXqPHU taTg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SIlE5Qgs; 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 ffacd0b85a97d-39efa42c671si1238395f8f.175.2025.04.18.07.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13:33 -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=SIlE5Qgs; 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 8EF6A83348; Fri, 18 Apr 2025 16:11:51 +0200 (CEST) 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="SIlE5Qgs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BCD268327A; Fri, 18 Apr 2025 16:11:49 +0200 (CEST) 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-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 0249A83290 for ; Fri, 18 Apr 2025 16:11:46 +0200 (CEST) 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-x42c.google.com with SMTP id ffacd0b85a97d-39c31e4c3e5so1296075f8f.0 for ; Fri, 18 Apr 2025 07:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985505; x=1745590305; 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=oV06jOcGhgL3zQiSdJCinxggWnUr0Aa60E9KHFCFYe8=; b=SIlE5Qgs3ximLOVY/U1d1xZMFOQOIYgqYKDPwtiDr/5iYt4n9p3Le+mxGhugtlckKN pe2sl17JG0XgHKyowe0OYvXVwWd7MsBigkyCzV5jcHWAT9u5Qo+cENk1UszHCnXs31Vq WRLDVgdWBFqGduVA/pc+50cicEDbFUQp4I3ol1Cko+/5gF4U4zps1V5MCiUIF3jfGpBv SLm8PxpsaKjqurI02fXQCRv1Q80HWOHZJZ/KmlsVcErmXTVmRZqU/jO8DadmlDV/gu8q WV7u2TtY4WIltewnDZP/n0HHruICGKjuQNYPevLzJ99UvSbIddwyZTpR1OI8+oOq7OJM fVPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985505; x=1745590305; 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=oV06jOcGhgL3zQiSdJCinxggWnUr0Aa60E9KHFCFYe8=; b=ehU5NxToiad1OtV2BGUVdIzbuckyxIGkGVoP7CYSodLNl6b5GVdZcXiv/TnNeY0nuQ EgwGEeRJp41FmPeF3Bn+ABW5CkRBUuJdhn44YUC9qO1jH6qYbuETS8iub3GpsqsObLxu wQiHQ84jqhOerUFiPXAAxyk1eBzDvoEhYXQe/g5k4EmdOeNwThovn+kKoMRNpV6u0jlw O/W+yd4B5o5XnNj8NNYMS2y9kQxz2U0fwiqMGd4Oapidce+mP/BJpdC04k9gEG5zZcgr ebS2lKYSYILEjtd/awWvJwObIAGBbv01s1fbMasVLNYKyV0TYTBVE+nu/fUtIpoAmNnl /BpQ== X-Gm-Message-State: AOJu0YzRaGYqnp6Ko1MuGpYoxM/sGIFzdlfnVctKHvS19tDAlF1DRbsG pqlYOC3yk/qiWfwNNenE5aKkT3FDT47uQC6DpzfxjYV/6nfb7WZLortro8q1K1kVLIPN6M45+Uc kLMO0+Q== X-Gm-Gg: ASbGncvk+H14m72uagxtRWIWy1l8i55sGov32nCqDMyfo0JxWXGzLdeWjCPBQ//gv1Q Y/PDe9TXO3uTNEZGx6V41WzgwILSTXc2imfqk6gMGQVznT7bVe0LfrmlOYvijqCOBSWyx873BPD xWmz1z6PfvxmeHGRPQ3l+5sl7jYsn/C88tStyBsIZDTLRvyZcrMO8lt8TKVk3yOF5cGkeVPujgM i55rH3ijFdtlOAgE0CPlfSaTOpXp+ZeYY1YFuIP56GRMwUNJVCP6XEE+sRbWtTqhrt2bcLCdGwe PvR2UarlAeXy5TvtLQ7FWlvbpP4hnX5bUFQby+KL8Uc3eXNZng== X-Received: by 2002:a05:6000:2281:b0:39c:1257:c7a3 with SMTP id ffacd0b85a97d-39efbb23ac3mr2319711f8f.59.1744985505265; Fri, 18 Apr 2025 07:11:45 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:44 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Tom Rini Subject: [PATCH v6 15/17] test: cmd: add test for spawn and wait commands Date: Fri, 18 Apr 2025 16:09:43 +0200 Message-ID: <20250418141114.2056981-16-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- (no changes since v1) 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 8596c5ad753..595e4cfcada 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 Fri Apr 18 14:09: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: 882322 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp831998wrs; Fri, 18 Apr 2025 07:13:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCULXUDjaixeQ/zXGCD2FnNgk3o88krU5OQfU/vYqAJrYzEdAI+IIk+1c8NblciUpH37KI2Rng==@linaro.org X-Google-Smtp-Source: AGHT+IF+fiTUMByWLD4qxa1KlAXmUD1XIdysVScDDwTJHxKzDoqCPgm875EJ+KLPgzKYD/MJMbCn X-Received: by 2002:a05:6000:470a:b0:391:4231:40a with SMTP id ffacd0b85a97d-39efba81ae4mr2133139f8f.33.1744985620905; Fri, 18 Apr 2025 07:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985620; cv=none; d=google.com; s=arc-20240605; b=B20Uk7F7jjnP7B6B2qWX6zKSrWosciQpXpfxpXJU9SmvhxDWG8LWvN39mxAzNMqVmy o+KHdEC3vYKuNBGARwvii9jPYq2wZ6BqdOJ8eqPcbH8w1rBTp6LbwTHC6UD4aAzWQ5HZ wDcedU56Qe+F3aSZw4c0Lncn+EalJkaY8c8sV35Xh77L0GmSmJDrLzk9NIi3dDCrzPT1 g6/q6oC2mjGYWLuzRCYvC5/WAAWsonsGsr0OmQr1/A5ExhgweZoX+9zl3LEWcLUAxTnS hqN0IDl26ayc476nRfGDy3yRyQp290cypdXA8c5tpgWMf4hbV90prssyVyp6Vh8V+HgD 4hSw== 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=wFdUmEArC4nCIPlZpQ8HD42bJlzOFpeSi8YUEv3cTGU=; fh=WyqUeyw4txKio0iJzZoZhJaoN0DBLWRbp2FSOjHOQNI=; b=KNw/yYvNkCAO31T0gcl5qkR0rw4WKYNDiszQLTEfv52gjC5cfKk3nFwYrm23iFTg6q Tk4m+0HC0mH6FZXIwr4ZxOrGS8RBslfMSlXyj/gdXoqbbj4BeWe6oO9xkZZ7cJW2yeOC 1F1RdOIwBU6OH9jI0lFibM9tgHj5xrQhlIAfGUnsTYX309ZYwth6PlJdCGDDG5+JS657 8POkCdvPQh+ChWaEVipZ4Y3ZVJ+zk202kCSy/WU/X98RlIuon+uQ46+X9KUMn74r6Cf+ /oxgejPiNffrDDsNvqzDr6yKLY7h1KHriSf6X6ig3d+WigwUH2MjsCsGD2URfcH7fEi7 nZUw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nib+BvvV; 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 5b1f17b1804b1-4406d5da3cdsi9489745e9.161.2025.04.18.07.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13:40 -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=Nib+BvvV; 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 DE4928327A; Fri, 18 Apr 2025 16:11:54 +0200 (CEST) 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="Nib+BvvV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E4755832C8; Fri, 18 Apr 2025 16:11:50 +0200 (CEST) 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 E8A5B83212 for ; Fri, 18 Apr 2025 16:11:46 +0200 (CEST) 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-43cfe574976so13822225e9.1 for ; Fri, 18 Apr 2025 07:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985506; x=1745590306; 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=wFdUmEArC4nCIPlZpQ8HD42bJlzOFpeSi8YUEv3cTGU=; b=Nib+BvvVD4M8t3RYAtnEYVyxguDjnuYIYKLuucw1Am2Yfs3TowHDJDvLxeAnKn2bl0 KybF1jRltGw9u5pbza8QIt/aYWmjgYQ3oel714V9Vobcnx0BrrawRe5DRpBMpUirHICL adOL+1n9bosy8z4GpzWhZrmFR/vyWlXfze+9AN2dclxEDnyKhRoIZQHMWhQCUl0O8ExL wFvFzZYwd/oBfCiZ3CebNSntYUjEysizV3rq0d8m0/o72sN7rXm33xj8HHAtI/GjUnHI ASJz3U1+lyeatJ+fJPvxwHDQCbb/F6o75eEdL27Rm0qV2JdupBgNo7j6FaiDQwGe/mw5 tStQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985506; x=1745590306; 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=wFdUmEArC4nCIPlZpQ8HD42bJlzOFpeSi8YUEv3cTGU=; b=iNwCnoS5Xkruc4vfGHU6Pa5kOSKmIPN9K1E5tdE4ym28ZwjhUdDvoHTvPkufySLs3x Tw0OUgG1UXrUjdJPRB658jEvbPzwCb4PppCFgQbb1dr4KWNsWvPwIkPUlzIZ6T+MkyxL yZu2qXwP5nA4au4cdu89xGwZROuWv8qqh15WYYFr9gdlN80AJSa4lvhhWeHmd8FLXwGT xBFuDU2idEw039t29Iu15K264vJWLEb2zBSkeUrO7M1eUdSjM8Vtz+2f74Z2QqOn5TNl Bf0lKDUHw+lMWBwNtnWV+0QAHy18cOfMP0dyNnDnoawwbX7sn26ovewPs9vF1glBNHdD 5QCw== X-Gm-Message-State: AOJu0Yzk3f+vWg8YY28ycP4istcrlcskHgvsWWsd2GwIsaDbRkH15Nqx djqc7yaOTU9rssHCBg+nzTVBIxGMvD5jZw0tQh+z5QkDlHjczdo/3RFJ3eCk/JhOG0i5mtSZnNQ SxqqB9w== X-Gm-Gg: ASbGncu6JmNnXgeohV+sXJtBAWvfHAiQviO0tGmwlmIpdLGs4EGrpb0fXh6rdwCcNDF jhiM21Hv7PAJiDxip2fVXgHa+JBNbTgGWUQ+rzMaEQgNdOXiObaxpsxue2MIHC6D/1w9Tttrugw TF+XMYtIgnd3QP6rPmHcPIzqpXFPVjOJdd0Me38Dokwnk6s+pujQMKEWuZ2C4jRJJTEEGfDPRdN ytiB7i2Ja3mY29AuC5OEB1m/WLfOqDoT3SxF+/zG3d9IeQIVSAWg+xk6nrrlZAghFUJbjwjLvO9 2Kks8rhHl8Z4g7jCddLIrNETnDQqINiVjGFYCkwkKSHVwK25IA== X-Received: by 2002:a05:6000:43d6:20b0:390:e1c5:fe2 with SMTP id ffacd0b85a97d-39efbae068bmr1433143f8f.38.1744985506202; Fri, 18 Apr 2025 07:11:46 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:45 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Ilias Apalodimas , Casey Connolly , Greg Malysa , Mattijs Korpershoek , Nathan Barrett-Morrison , Oliver Gaskell , Robert Marko , Sam Protsenko , Simon Glass , Tom Rini Subject: [PATCH v6 16/17] MAINTAINERS: add UTHREAD Date: Fri, 18 Apr 2025 16:09:44 +0200 Message-ID: <20250418141114.2056981-17-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 --- Changes in v6: - Order files in alphabetical order MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a0b06e9ee24..0d8b58a12ef 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1824,6 +1824,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: cmd/spawn.c +F: include/uthread.h +F: lib/uthread.c +F: test/cmd/spawn.c +F: test/lib/uthread.c + UUID testing M: Abdellatif El Khlifi S: Maintained From patchwork Fri Apr 18 14:09: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: 882323 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp832061wrs; Fri, 18 Apr 2025 07:13:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWU7o2j3vkl7IHxf8HcEKJ6HTJSyHlSgcJKRzS1mDaQ1KXorNUBa9Y2KjglGMfbPLaAL75UZg==@linaro.org X-Google-Smtp-Source: AGHT+IGZwVJOk91Kg/J52Kab2j6On/A1U/c/AHymQXPyfiitZ3csABs2N7dQDjjcoIVH8kWxBIgv X-Received: by 2002:a05:600c:3c8c:b0:43d:3df:42d8 with SMTP id 5b1f17b1804b1-4406ab7f3acmr16985495e9.6.1744985628750; Fri, 18 Apr 2025 07:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744985628; cv=none; d=google.com; s=arc-20240605; b=gexWq3f5ZpeHC1Glb5GGxtq8xgC7lyVQyYJpYv4zz27Q1rf8rsnUurjvP1lmHWO1VE rKcUHqKodgsR+6k76I+Ef92Un8YFz4dWIJA+fUxx1tQvxwbY8cGUxH7ZPmYi/Oop0a6g CV8aFYjt9f9A1MyqbOa/XWQhZZvkF7qmgNnYVX89UZF3CQDBIXx6ivwXOYU2R4Q65QkS ss3un7YW4KgUyvxuxwtl5gZ/neKT+Kg7gYLXcd18ccgrvX2lIVH7m+WuZFrgSRNo6nNP Is7FjjSfz/6KFOS/iFfnJXqNqJylsRxrIcBDiC8RN+lb5OHqtWKhnqjk0iwzthk9lEwu WN4g== 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=OWgPI+Dmjm/1eQXuimg0E37dXNaqzlxa249pBV7ma1s=; fh=H/agYFp5Yqgn4BwqyqVaUcpu8ysr/t3zlAfB8BW+lgI=; b=cpcZ2MP/ujHdH5sIGXegBMRdB1FYJCsUzZrWyNgElMKE8PDWjqRyhp4YnwBUZfdBEY XWewAaVgZ5IausUrmxyotQb6pPPqzCGpKFmyY8Rblpry62SPiNgAtE8SExD+zHnICgBG /K+bjCUH88ToXi+3FBBYPY0+cR+eN+O2f9Sijm9lFesSbhCYn0X0LvNWSxkPOfWge+Sz HbvY05O23J1sh5DqMTwYWbA4VqwuXEahKcLiwh2NV1pZvwegGBZZgbvVERsgAnZ5mSLT WpW4X8OQn0a6oeoQx/Ud/3Vdb2Zvg2fppPbmijxE059848cMqnZ21gKvwFtqULYPiofD lptQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CCjzgXQr; 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 5b1f17b1804b1-4406d5ae893si9538025e9.58.2025.04.18.07.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:13:48 -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=CCjzgXQr; 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 3261A832F9; Fri, 18 Apr 2025 16:11:55 +0200 (CEST) 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="CCjzgXQr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C617832E9; Fri, 18 Apr 2025 16:11:51 +0200 (CEST) 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 063E28328F for ; Fri, 18 Apr 2025 16:11:48 +0200 (CEST) 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-440685d6afcso14523885e9.0 for ; Fri, 18 Apr 2025 07:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744985507; x=1745590307; 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=OWgPI+Dmjm/1eQXuimg0E37dXNaqzlxa249pBV7ma1s=; b=CCjzgXQrG9Vin2VTm4hmmihD5/BOBj8FtCo/AnBPFlPtpnYYo2CPQ1ixviJrp0w3oW YJJSjxjGhQRZnnzKUUADSdvmz8hbSkDiBZgaVQkelRk4lystAYbF4VHiJHJod7nPIDr9 pVYMNGk0dD7LMWpv/R1HcUk9CuSL4Cw7q+HwvgWRfJrt1FILV9mYj6+go+Rf481WRXAQ wQ7DnOYUE4AFxQX+rht/TSPF9EHEgqLbUuqFYY6egYrSzmnIt1j/pLIKZ6+5qaV66ONz KxWvl9U5M0pC+bX0PjnfoU9Z9oACL82Zl6hrTlLbFm03M67aY8gsWblJoIWav1SVOtac MaZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744985507; x=1745590307; 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=OWgPI+Dmjm/1eQXuimg0E37dXNaqzlxa249pBV7ma1s=; b=gDvnBmfeQuElSUTytVN639YwAcxhJE8h6yE2FKxcS4UFZPxBQVAjjiP/iYmxQxw5+R aZp/SjY72tObP49Ie75cC+WRmtBVLclxrksfSvax3InjJ4MNHoyu2mnG1tzt/0K2S8YH codMRy2CijJytYQMINh0KgCI9nRFQF7ydXzde3X6zcDQ+4LBIFmVxQ2vwIB0cgP+L7xq snPVOPPStvaup66k0NmjBWvrgA8PHgTJmjVKbcRLJn14V3MmNts2AyUcO7kPYD1sUXmw QHlxQj7lzcpISIcmkioUmi2wRHmzaRjihPsN3yyqxSltTxvB8n7J/2ch7V9eWGlF8tII UZjA== X-Gm-Message-State: AOJu0Yx0gtBwpQB1BiT0itNsbmK3fGz3OAS4/f1vIHqxNvRnI8AmnrFf J7mZlqnb0RXz1hPTP1D++mtQfit45A52i0T3OTghT+UORkOaApSb2VZTfLqL8p5nZz6fZCWr9Wz kzuQaOw== X-Gm-Gg: ASbGncutTCo2KL+GIi31m2JoB7WhlSIw7c3l3QxpAIWr6y1KIvvqaGSXYXeiOaH8keu C2pfUR4pFvSYzjM99HCzcxcypvOZ+Ip1rWxOCgNDmwCmmit9vpehrOqH2WGJ61xQ0SLe1H09kpy aGxo+wEzDEC4yEc9AvYG/RAV4ff30qXBKcYJ/b2kN4oq0hvhUNtdtmHIPe1C9XdbKF6+3RhCMVE bd8VIR0x92qnLhPSCxzipyuoo7Wc12oslkx+Isd2a3KvcCsK34dcVeXgo/mfxXhhGvcswOH8rvB zLOCgDYFqThC1FkcuUECYjFi8fnwpPoOFNt6C94xBFfPd94U+Q== X-Received: by 2002:a05:600c:1ca0:b0:43c:f87c:24ce with SMTP id 5b1f17b1804b1-4406abf9935mr18507875e9.21.1744985507305; Fri, 18 Apr 2025 07:11:47 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:1526:5ffd:d63c:cc85]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4406d5bbcc3sm23734385e9.19.2025.04.18.07.11.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Apr 2025 07:11:46 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Bin Meng , Dmitry Rokosov , Guillaume La Roque , Heinrich Schuchardt , Hou Zhiqiang , Ilias Apalodimas , Jonathan Humphreys , Marek Vasut , Mario Six , Mattijs Korpershoek , Miquel Raynal , Patrick Delaunay , Peng Fan , Philippe Reynes , Raymond Mao , Simon Glass , Sughosh Ganu , Svyatoslav Ryhel , Tom Rini , Tuomas Tynkkynen Subject: [PATCH v6 17/17] configs: qemu: enable UTHREAD and CMD_SPAWN in various defconfigs Date: Fri, 18 Apr 2025 16:09:45 +0200 Message-ID: <20250418141114.2056981-18-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418141114.2056981-1-jerome.forissier@linaro.org> References: <20250418141114.2056981-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 Enable UTHREAD and CMD_SPAWN on supported QEMU platforms for testing purposes. Signed-off-by: Jerome Forissier --- (no changes since v1) configs/imx93_11x11_evk_defconfig | 2 ++ configs/qemu-riscv32_defconfig | 3 +++ configs/qemu-riscv32_smode_defconfig | 3 +++ configs/qemu-riscv64_defconfig | 3 +++ configs/qemu-riscv64_smode_defconfig | 3 +++ configs/qemu_arm64_defconfig | 3 +++ configs/qemu_arm_defconfig | 2 ++ configs/sandbox64_defconfig | 2 ++ configs/sandbox_defconfig | 2 ++ 9 files changed, 23 insertions(+) diff --git a/configs/imx93_11x11_evk_defconfig b/configs/imx93_11x11_evk_defconfig index 59c4da7fa2b..d03895ed6ea 100644 --- a/configs/imx93_11x11_evk_defconfig +++ b/configs/imx93_11x11_evk_defconfig @@ -129,3 +129,5 @@ CONFIG_ULP_WATCHDOG=y CONFIG_WDT=y CONFIG_LZO=y CONFIG_BZIP2=y +CONFIG_UTHREAD=y +CONFIG_CMD_SPAWN=y diff --git a/configs/qemu-riscv32_defconfig b/configs/qemu-riscv32_defconfig index 1cd80f5769e..b9f28873c15 100644 --- a/configs/qemu-riscv32_defconfig +++ b/configs/qemu-riscv32_defconfig @@ -16,7 +16,10 @@ CONFIG_DISPLAY_BOARDINFO=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_NVEDIT_EFI=y # CONFIG_CMD_MII is not set +CONFIG_CMD_SPAWN=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM_MTD=y CONFIG_FLASH_SHOW_PROGRESS=0 CONFIG_SYS_MAX_FLASH_BANKS=2 +CONFIG_UTHREAD=y +CONFIG_UNIT_TEST=y diff --git a/configs/qemu-riscv32_smode_defconfig b/configs/qemu-riscv32_smode_defconfig index 6f871c83644..cd89571e40c 100644 --- a/configs/qemu-riscv32_smode_defconfig +++ b/configs/qemu-riscv32_smode_defconfig @@ -17,7 +17,10 @@ CONFIG_DISPLAY_BOARDINFO=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_NVEDIT_EFI=y # CONFIG_CMD_MII is not set +CONFIG_CMD_SPAWN=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM_MTD=y CONFIG_FLASH_SHOW_PROGRESS=0 CONFIG_SYS_MAX_FLASH_BANKS=2 +CONFIG_UTHREAD=y +CONFIG_UNIT_TEST=y diff --git a/configs/qemu-riscv64_defconfig b/configs/qemu-riscv64_defconfig index cdd511b0e72..c67fb9a3352 100644 --- a/configs/qemu-riscv64_defconfig +++ b/configs/qemu-riscv64_defconfig @@ -16,7 +16,10 @@ CONFIG_DISPLAY_BOARDINFO=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_NVEDIT_EFI=y # CONFIG_CMD_MII is not set +CONFIG_CMD_SPAWN=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM_MTD=y CONFIG_FLASH_SHOW_PROGRESS=0 CONFIG_SYS_MAX_FLASH_BANKS=2 +CONFIG_UTHREAD=y +CONFIG_UNIT_TEST=y diff --git a/configs/qemu-riscv64_smode_defconfig b/configs/qemu-riscv64_smode_defconfig index 2f62f17bc8c..d28e9fbeceb 100644 --- a/configs/qemu-riscv64_smode_defconfig +++ b/configs/qemu-riscv64_smode_defconfig @@ -19,7 +19,10 @@ CONFIG_DISPLAY_BOARDINFO=y CONFIG_CMD_BOOTEFI_SELFTEST=y CONFIG_CMD_NVEDIT_EFI=y # CONFIG_CMD_MII is not set +CONFIG_CMD_SPAWN=y CONFIG_SYS_RELOC_GD_ENV_ADDR=y CONFIG_DM_MTD=y CONFIG_FLASH_SHOW_PROGRESS=0 CONFIG_SYS_MAX_FLASH_BANKS=2 +CONFIG_UTHREAD=y +CONFIG_UNIT_TEST=y diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig index 6c9d2505a69..b1371d4258f 100644 --- a/configs/qemu_arm64_defconfig +++ b/configs/qemu_arm64_defconfig @@ -37,6 +37,7 @@ CONFIG_CMD_PCI=y CONFIG_CMD_EFIDEBUG=y CONFIG_CMD_TPM=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_SPAWN=y CONFIG_ENV_IS_IN_FLASH=y CONFIG_SCSI_AHCI=y CONFIG_AHCI_PCI=y @@ -75,3 +76,5 @@ CONFIG_MBEDTLS_LIB=y CONFIG_TPM=y CONFIG_TPM_PCR_ALLOCATE=y CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE=y +CONFIG_UTHREAD=y +CONFIG_UNIT_TEST=y diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig index 2d642f86ba6..97d2f2f2e49 100644 --- a/configs/qemu_arm_defconfig +++ b/configs/qemu_arm_defconfig @@ -35,6 +35,7 @@ CONFIG_CMD_MTD=y CONFIG_CMD_PCI=y CONFIG_CMD_TPM=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_SPAWN=y CONFIG_ENV_IS_IN_FLASH=y CONFIG_SCSI_AHCI=y CONFIG_AHCI_PCI=y @@ -67,4 +68,5 @@ CONFIG_TPM2_MMIO=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_PCI=y CONFIG_TPM=y +CONFIG_UTHREAD=y CONFIG_UNIT_TEST=y diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 42c40077823..23df4c3b635 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -99,6 +99,7 @@ CONFIG_CMD_CBFS=y CONFIG_CMD_CRAMFS=y CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_MTDPARTS=y +CONFIG_CMD_SPAWN=y CONFIG_MAC_PARTITION=y CONFIG_AMIGA_PARTITION=y CONFIG_OF_CONTROL=y @@ -275,6 +276,7 @@ CONFIG_TPM=y CONFIG_ERRNO_STR=y CONFIG_GETOPT=y CONFIG_TEST_FDTDEC=y +CONFIG_UTHREAD=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 87f21fdbd12..c4b1b8114d6 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -143,6 +143,7 @@ CONFIG_CMD_EXT4_WRITE=y CONFIG_CMD_SQUASHFS=y CONFIG_CMD_MTDPARTS=y CONFIG_CMD_STACKPROTECTOR_TEST=y +CONFIG_CMD_SPAWN=y CONFIG_MAC_PARTITION=y CONFIG_OF_CONTROL=y CONFIG_OF_LIVE=y @@ -364,6 +365,7 @@ CONFIG_TPM=y CONFIG_ERRNO_STR=y CONFIG_GETOPT=y CONFIG_TEST_FDTDEC=y +CONFIG_UTHREAD=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y