From patchwork Tue Feb 25 16:34:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 868113 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388583wrb; Tue, 25 Feb 2025 08:35:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVveaoyOEtWawOPs5eaf5kI2B5AEvbRgm8zidvJYW6asrDcUkCtU8x6zDf1L+iIYPMp4Tn/XQ==@linaro.org X-Google-Smtp-Source: AGHT+IFxqTnM2rMV5041jPmYypHpjAg4Vpj8kbI99pD3ycNRDJVyfN01jVLRixX7k+ykZlPY6p7D X-Received: by 2002:a5d:6d82:0:b0:38f:2b49:7bfe with SMTP id ffacd0b85a97d-38f6f0ae7eamr17381554f8f.47.1740501321444; Tue, 25 Feb 2025 08:35:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501321; cv=none; d=google.com; s=arc-20240605; b=LqRSn6+9FK2ZpDkhHB4lEFxh73zoj7EYUltoth+pOww973593Dld6GIbjPYNACLyeu 0v4ZOJo9s5Pr4YSvakFACuqNkc0mLoPrNrqjNCJluUz6dflzL9nYMykNZvbKT0a/QOoI vRPvina+c93J0+tCKzPNnOJwSwOgfocAp6c/09S9RQVYCRu1UzgxgYK5CttAlNcnWDyQ lrymGk/MQ7HMtC1uWL27MmaaQz/1uTtRNbpryy+jWR2LWN3kRqj00tjanNg8lMwsrfSu pgTLxqcFtEL31iVXHcp0iP/TcWd0eY2Kiw1lDwxR7C2GrP3P9csUQwL9iM4WKghgMcL4 ouXA== 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=RDfKby4rgYi6Um9EPDrRuQexeymWhXMTc0fOwNjxpFM=; fh=KelW0js8qhC0fZluMhUfWO7EM7IB2Cgo58iKBMeAelo=; b=Z5Odw/DzrJz2Grrsi/k3u+ZGBni2Z+VoRZYVjOGMmD9Jr8SsPkvEPxvKn2tHx3bowg F07bbH2GbEuZZ7oOnQBg+a0DVdFrjzaphcqhA9EUJjNWst3xEIvsTduZHxNG48sQ+Bcb 6gSls7Ujr6NIC9xLWPI8aUmzxmKEcQkOzS/Ch3hrXNN684hZ8RYjRxkbRNG8NL49D/Gh H2DL1fFemefAxk/PpECFmz0VjBiwnFgNHyry9lG+fSBAiwGa1ZOY70JknzKypTQjZRhC g5jKWXgV9IBfWPwcdDNpRP878fYV04e9t4Eu+lwZjv6jfOR2aLPqYW+iGEaDPRSNogcA IddA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pAA9Ar0/"; 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-390cd8fba05si1347278f8f.697.2025.02.25.08.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:21 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pAA9Ar0/"; 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 6492680FAA; Tue, 25 Feb 2025 17:35:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pAA9Ar0/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AEF28807EE; Tue, 25 Feb 2025 17:35:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B1A7880F53 for ; Tue, 25 Feb 2025 17:35:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43aac0390e8so14719395e9.2 for ; Tue, 25 Feb 2025 08:35:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501311; x=1741106111; 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=RDfKby4rgYi6Um9EPDrRuQexeymWhXMTc0fOwNjxpFM=; b=pAA9Ar0/fRT1rsQNw7zZvbcG0yFCSMz4FwZF9LKCDElHHJ+H5ZJBFI4xEoCbni9NkD oOonTriCNoP0LdkicVvoprW+BQxo9/hbdqasBpXicL7NSL8MwTAmPnsgsDex3NlACkq7 +AgCYyB83Khk2+sIuqLBZf39/yGV+IU21X7fgpvukzEXDUnQs8pcrzdmQuh48j7V0gJJ dTxpgrC1BxlOU9WMhAyYumjQwFx7HPdxfZH6ZmZwZ2UAY2eCDXGWSOU+KuDo8reDT1yv j1hcIgBO/OoZBN8ah6jzjHlUte8Pny9D22c9Tg2KF4USOgAR/42M9GtQl0s4IMbekqMB /Usw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501311; x=1741106111; 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=RDfKby4rgYi6Um9EPDrRuQexeymWhXMTc0fOwNjxpFM=; b=AMJ+dLqetYx1Ra/u+0YqYqa5oFQl8eJn3YBQmMTUnsZuBvUi3GcfHemErf0+UiHATn l8XIR5YCDa1mucmjOzLRZikJtkwMmuX47Y649sM2bS02DDc6emce0XL387QCDckNY9Tp TxEXqj7BuFr0kDTFlqC4oL1f/aFmms0YLoQxakydx8uPZDqF0dzFXw8tn2PXqHHScDO+ ZNDP8xachzQTvewgA77SQ0fhsM8vEszyP5iIcMAgO912t8Km+tkY1dJBOIAbpPsy+izP 5Bu2lVaKiMvFZ37hmDR/Cu2IQGLGNfJyuLg5AMNOb3zvpfRaZbIjX6fWTQQIyWRbxhs8 qJUA== X-Gm-Message-State: AOJu0YwYNErabx/aDsV6b4yBTX7e57cMSYXq6qhIIWGD+6oc71UtdZ5+ EjmY/XsLhC2YqxcdBRgNYn/yBr8DvvjNbCkVjrDL455sbUCTGf5Ra9JZEF1pnE3kKVCSQS1okK0 EsQkYQQ== X-Gm-Gg: ASbGncss8yJDVDfzQ6I/8MuBVNgY4l3ykOplgCMvuk3+z+bUD2+9HpFnb3y2vuGj4mT np8Vck6VPQialuLfcuGKGrD9LDyUHFeQMPGfw9AH045FTMHk7yRwVOsAbUNKpc/f7m1c9EYnTYA +77RNDDKBsfwcl93lA3Ew9kifJwGDBX9Kg/mUVXh0f5zugk9aVf/U1uOmPIQm+RkWGFjQsX+BnO d4YFXiDYmsEVNx0sNKYmKEWwonXOz7Ng+3PafIvM2rqSRlwp/3xMApJPsgx98TZA7lRy3eqc4X7 HEqIvaW2M0At3u0DRgWLQX34z5Uvmpo07ds= X-Received: by 2002:a05:600c:3150:b0:439:955d:7adb with SMTP id 5b1f17b1804b1-439ae222a7amr192159345e9.30.1740501310945; Tue, 25 Feb 2025 08:35:10 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:10 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Heinrich Schuchardt , Dan Carpenter , Simon Glass , Leo Yu-Chi Liang , Andrew Goodbody , Jiaxun Yang , Yu-Chien Peter Lin Subject: [PATCH v2 01/14] arch: introduce symbol HAVE_INITJMP Date: Tue, 25 Feb 2025 17:34:27 +0100 Message-ID: <2589612a53a9e9feb67b8e8286e87893359676d1.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean HAVE_INIJMP will 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. Signed-off-by: Jerome Forissier --- arch/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 35b19f9bfdc..8d5b54031b3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -13,6 +13,12 @@ config HAVE_SETJMP help The architecture supports setjmp() and longjmp(). +config HAVE_INITJMP + bool + help + The architecture supports initjmp(), a non-standard companion to + setjmp() and longjmp(). + config SUPPORT_BIG_ENDIAN bool From patchwork Tue Feb 25 16:34:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 868114 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388639wrb; Tue, 25 Feb 2025 08:35:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXThVQrs5ik7wvucueKgqvrcM7LK7XsckJJp/TJhwSAxjS3zYpMtprOR/DHR4f72trq7iwFZA==@linaro.org X-Google-Smtp-Source: AGHT+IHXPtAuam28gPSaCcMhpgUJTmsfvtaGDhvrCuGyQHq/qMP5LA5TUfQX3zW9tYSZ+hX+8Ajv X-Received: by 2002:a5d:6c6f:0:b0:38d:df15:2770 with SMTP id ffacd0b85a97d-38f613fa36emr18665660f8f.0.1740501329403; Tue, 25 Feb 2025 08:35:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501329; cv=none; d=google.com; s=arc-20240605; b=RY7BkwX1cDqCP7g0pjH5Id8u0TnQfhe4CDAPwEa/+50hOuLYqkFGwWk1l6EJqi80kV UHHyj9JKSrL4OG8m9zWkD/FQSHGI4/gJH+dI4BxlFGlsH5h0iTfNBOghiEPlOmpzz8nr IbqNvEjGGCu9pT4wTl3B7Micyu8XBxVRhUMzG0jUAU+/2sQn2aSHfQtW8G3KKlS5pdSJ YbyI3WQFBgGKf095qElBCjuB5slocFOkb2MaaWGGcX1EgSGjgvRbVtsME2TJK8qyP/E9 YFdzsUUnl+TCr6deF18ifw5ak+DAGnyWPOI5w1/1ckMjhuZs7FFMbTWPtZaorLz8gUbI r9Aw== 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=UCu7qj8HR3Py0+iZlP/oCbK1XsWURJ6VtwUuKp1Xrk8=; fh=oZqyBsuX1Ie+m/KVsQrOduEXnjDCb6On/wM0tZ0589U=; b=HsDMPFaAraRVa7INtM1k/sb9JyoxSRcxPe7fXfRJoVhswvsxKaJAnkZsWPhDLLiB22 WTAQZNqzB9mKh/CqBJKKk3O1biJfFUIlmIzmVP/IvhI/mmq2tqQFGJ1mCqdBwS0kaaz0 MvAXc9rpp0lUP3K8hoNRxXWZ6CUow+pSO3dOZXg52+u72o/TT0NI/+rsC9N73Z/isxZF 7RFW9K970tS4awDxpZdYNwBLThL6LKKFVyhiu6OoprtqzROXzkIuVb+PFZ+OiVZJCU9D 4HK5eY3+awQfVIcynRMxvnXS71RnrCEBl5HFNjbL/RmeEQbMYkenAYhopcyHM1gBhLrC ZLcQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="O/qsy75H"; 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-390cd8e6862si1321698f8f.544.2025.02.25.08.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:29 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="O/qsy75H"; 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 AE5D480FD1; Tue, 25 Feb 2025 17:35:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="O/qsy75H"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5690580FB9; Tue, 25 Feb 2025 17:35:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BCB2B80F7B for ; Tue, 25 Feb 2025 17:35:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4399ee18a57so35129165e9.1 for ; Tue, 25 Feb 2025 08:35:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501312; x=1741106112; 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=UCu7qj8HR3Py0+iZlP/oCbK1XsWURJ6VtwUuKp1Xrk8=; b=O/qsy75H64tBbgFjUojdulw5J1pG5Eu8MKiTn2JxWdJoozHrbuMHLwFg3OWuG+5J9m OnxkmnHrbQmP4uIxKKKDebz8QTyxvxtkV86x6Ho58Kqi3ryVADfwc50e7KpQw4Efqaua XJD3ILJ55KBnmVpnv1IlMPaH2uSMCYzp8Z6BTfvUj/wQx8GtuUzYvV7/WyEab51b6IOX PPCE+RJwI0+8js3XnRWasnLqGHbUjEz839ch48hBS98JkCVJ3ZD1L3UTB8oFGaHRD77D MFGGGL9Y9grwiO3sXjsH8X1UkIdTzpNEIrkzLJOw1+5dG7RXYFmUmftnKRZ+EInGqaiN rmfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501312; x=1741106112; 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=UCu7qj8HR3Py0+iZlP/oCbK1XsWURJ6VtwUuKp1Xrk8=; b=uMumCFFTbst7Pi16HvyjlKLnk132xOSGOs0eNB2F/Hlumrzcd8Snicn1thBIa9q5CM +h770hfWRve47sUZuVLfKdI2s31PeJmmiRRVK4/c3NHkJIzvOD+ymTIta59HPn1kJNs+ hWUEGJjd1/qaaF1X14sz3zI7zKHBm5GBMh4+I3JLvdUxTkUauTpvQapvzSb6s7ZwQaAx UUYo8f/aCJYLF7F1ve81HCp98eUmFPv7+dYugUULk+pxdSePQq+LS8u9lPoRPN7EHFFC zuriuWGRlBtLhftvsDDDD+92QHfrMxPMhyGiLBdiJnVsZGE34cmJeQijLRE15IvBaqGt 6GFg== X-Gm-Message-State: AOJu0Yy2ah/6DDmW65q/DgZ9VEEbwguDWkQ2uuQqQsavaO4y+n4v32aX OK+yL0nxUukBnTBQEVkc+LFDZVQazhKr9f2PRD077YQ9GqWvnIUA0/Jh6qLMOMy6OTn21zMQvQV gJpDuoQ== X-Gm-Gg: ASbGncuqmTf3ClB9eT1DqhW5QRmWVX5TbOk/a46JJSiu1CYFX1iW0W5JcGNbvRaUCp2 iKBCDU7CcXI4IuUKarsZKJ2l8ZbbidaT0TSwpjr5nMwDrrWWMtKUSsa3y3su07wVvAF8VIL4xrk /D72ZjRtOxsiTSj2hlvJIN1hlKU8MePoTS4siN0wtETPWd904urSQgXCo3xsg6WbS0Y0uGldvry IzwekRmLoGUw+B1S+GVZ91oZWZJfdOkTPtWf+iveVPxRHy3Cl9rajw6FHN5dCbZAxqPjI1/58YS wNK80W2XqZuccxguRSjDYFVZzpQA43MVqwQ= X-Received: by 2002:a05:600c:4511:b0:439:5f04:4f8d with SMTP id 5b1f17b1804b1-439ae320687mr127688625e9.12.1740501312043; Tue, 25 Feb 2025 08:35:12 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:11 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Heinrich Schuchardt , Simon Glass , Dan Carpenter , Andrew Goodbody , Jiaxun Yang , Yu-Chien Peter Lin Subject: [PATCH v2 02/14] arm: add initjmp() Date: Tue, 25 Feb 2025 17:34:28 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement initjmp() for Arm. Signed-off-by: Jerome Forissier --- arch/Kconfig | 1 + arch/arm/include/asm/setjmp.h | 1 + arch/arm/lib/setjmp.S | 11 +++++++++++ arch/arm/lib/setjmp_aarch64.S | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 8d5b54031b3..57695fada8d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -94,6 +94,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/include/asm/setjmp.h b/arch/arm/include/asm/setjmp.h index 662bec86321..1ad5b500f2a 100644 --- a/arch/arm/include/asm/setjmp.h +++ b/arch/arm/include/asm/setjmp.h @@ -23,5 +23,6 @@ typedef struct jmp_buf_data jmp_buf[1]; int setjmp(jmp_buf jmp); void longjmp(jmp_buf jmp, int ret); +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); #endif /* _SETJMP_H_ */ diff --git a/arch/arm/lib/setjmp.S b/arch/arm/lib/setjmp.S index 2f041aeef01..320ddea85f9 100644 --- a/arch/arm/lib/setjmp.S +++ b/arch/arm/lib/setjmp.S @@ -34,3 +34,14 @@ ENTRY(longjmp) ret lr ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + stm a1, {v1-v8} + /* a2: entry point address, a3: stack top */ + str a3, [a1, #32] /* where setjmp would save sp */ + str a2, [a1, #36] /* where setjmp would save lr */ + mov a1, #0 + ret lr +ENDPROC(initjmp) +.popsection diff --git a/arch/arm/lib/setjmp_aarch64.S b/arch/arm/lib/setjmp_aarch64.S index 1b8d000eb48..074320d25fb 100644 --- a/arch/arm/lib/setjmp_aarch64.S +++ b/arch/arm/lib/setjmp_aarch64.S @@ -39,3 +39,12 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* x1: entry point address, x2: stack top */ + stp x1, x2, [x0,#88] + mov x0, #0 + ret +ENDPROC(initjmp) +.popsection From patchwork Tue Feb 25 16:34: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: 868115 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388713wrb; Tue, 25 Feb 2025 08:35:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU5hA/it54nFZkCs8A0Hdgippy2vOFPXbGoWWsOEy+chNUUoaguik3fh7xDTsys9AlgjH/r/A==@linaro.org X-Google-Smtp-Source: AGHT+IFVjZLYUDGr+74cCTf4LSXBRh56MPL5fOvW6HpYNBsYxHt2GtRfDk9L8WEfzgeZ9qomeUn9 X-Received: by 2002:a5d:6d84:0:b0:38f:34a7:ebfb with SMTP id ffacd0b85a97d-38f6f0b7344mr14047798f8f.55.1740501337160; Tue, 25 Feb 2025 08:35:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501337; cv=none; d=google.com; s=arc-20240605; b=RIndzDAFV4QszcAU0gAK3WtLtkUu0g3vMJA/XILovOijAjxOG9s/YN2zJ04Q7mIWVV belZyDnoJ6Lokd5KKCu//v3I9XTmxa3V6cRFbrudna4aY4jKEgIYcbuXBl1n8gnSlirI yyvnlGteVEHCFtHz+I42ijNZv4bOvKZvir5rO9Hq8Apso/b9DEUcSMn78sP2iQiVi/5+ SqLPIJEZ9OibkHFmP9zR3HwvAmtoljFv7HEfT/SznYxgEbO5Zv5fsjpKwsw/MYWfC5tn HD9buYdqKKcu8O/SZO3DyIfLFUtMr4qbszBnwajINnvVD+h35j9nEwTMbFz10mUbW4lM thqg== 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=FNw2IjE2pzkh8kOG8gbCKeyHG7nPC9wPKaPR6juqTg0=; fh=VT4NZvbs6JSRJgFq629DWEjP1Ykvv/xWeKwNnZX1Oxk=; b=Zse52M4ZdP8pXFEHwgyZ4g/bweNO06USkUiQqMZke4WkQJsjtQd62Dos8iZ4zoRIIz JF1QMupCsLAW64dFux0RAVEqxQc7LzjwlC0Fci64BDN9YGw9aWxMc/esxpbKMhW3ZU++ O5OTG37BPcezIMmvczSuSLddJgijsvJWlV8Heq/nbEZOpksWBuuxqH+JCbvQAGMmbhyx 1YCJxH/Wy5xknijWDNOhU3/5HIlBfNW8Xk+/E7KwAH3nl0u40Do711x5FSkocZ4Z0i9u 2hu0f776ZwiCgl7xtmLVnQ9/w5+aqWtSq/lP5FFifvHcV1kI45Eo6LnQ3sd65yuXHfSe WncQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dGG5pYTU; 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-439b02cf73asi66273945e9.47.2025.02.25.08.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:37 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dGG5pYTU; 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 066D980FE1; Tue, 25 Feb 2025 17:35:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="dGG5pYTU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C521B80F7B; Tue, 25 Feb 2025 17:35:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CA04A807EE for ; Tue, 25 Feb 2025 17:35:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43aac0390e8so14719715e9.2 for ; Tue, 25 Feb 2025 08:35:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501313; x=1741106113; 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=FNw2IjE2pzkh8kOG8gbCKeyHG7nPC9wPKaPR6juqTg0=; b=dGG5pYTUnI9S9aeX/yOXlFBuBqrscI3j/fJSowSKrk2sZJ14AAq8k94n8kI9UjF/Ds 173g8+aeRhCjjkpBj9oYW9C8jP5yKoQKYeqdXyoDMLDSAIhBHO91UIlwZQyNd1M4mwzz FidIXEjXqcJt1T/I+pUMaIqAka8FJTSLkrUaFYhPbXVvYawZ2peVbm648cRqV3gKQSSb 4Cz1LV3LlyFteWYZElbUKXSRnoVcPnWlUtQrerEc74LrXQvuipOXCPcE3KAP7gRBiBa+ Npv+x0TJ9jA97E/TImtcK9Vt+6gX+lWAQhwawdqaL4BmJNHVrsUEFL+GHDufcOXtsJKl BXKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501313; x=1741106113; 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=FNw2IjE2pzkh8kOG8gbCKeyHG7nPC9wPKaPR6juqTg0=; b=qjR1vy71y8aeQ7Hjqg0OueAmMQ72KF5M4wSzfs/v9iNTi+q2hJB9oXt6Xa/y6PqrgG Mi3azDZPEdN3aSIa9LEzzGGH/nAgSMV+cX8AJl8u6YNLRUdB1Xzr9FyuhnDmVoiKcKc3 R7NuGpBenUOWMZOX8JqodbxxGHuhMjv/NXgeDJkIEaMk7gG1wqkfEne9cEk1i76J2axx 1DITMf9D6QLjTGHkw5UgpkfGOx8+UVFz9SFo9EnrO7kvIUQirfQcdJ1O1rtaLGmpt+lw +GoF8QKF+ZX53kIFiysoIbwRdBKEC9w1wxad+hgjNsjBj7rOraxiZTLScO2Dgsn7zvd9 QgIw== X-Gm-Message-State: AOJu0YzzR/20nVr22rqXaH/iMA94ZwXpZf8QJPYHx7/R2E4HDY3P0PsO GxiJrDO7rddxKUctkfxYfVewEfGHA3bL2FUNhzmQQM9yPqCT9righh0COzuMLrvobXE5NrpiZ2M +qQ8eVA== X-Gm-Gg: ASbGncuHQ2TIECNPJoF+a0hSkblOoiiDpXq9C0WdZ7YtAAeKE+bIGtbX+Oc2ST6C3Gt 9vz0PIZnTSoeYdhm91tuD/vEP0blDw60p/anvUunc6z+Rys2mj8v1hOXHGq5EGir603hna0LyxO IZBm99qL0Kj4PjZhKRYPfz28dpCl5I3ri2b4m7LZv74yc6GPP5wjKCd39whIqAGFRfcfwIG4GiU fmUFjAcOrX2nsc8b6KSNnNcpGWLm6fUZKQVjhd7UonSUe1YFP4ar/vOwN4EDi1CAFRO4WTY2kx9 zdZ+PeUBfvdy11yYk2kfXe8Za22gI9VKX68= X-Received: by 2002:a05:600c:3582:b0:434:f131:1e64 with SMTP id 5b1f17b1804b1-439ae1e960dmr140911985e9.9.1740501313059; Tue, 25 Feb 2025 08:35:13 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:12 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Rick Chen , Leo , Dan Carpenter , Simon Glass , Heinrich Schuchardt , Yu-Chien Peter Lin , Jiaxun Yang , Andrew Goodbody Subject: [PATCH v2 03/14] riscv: add initjmp() Date: Tue, 25 Feb 2025 17:34:29 +0100 Message-ID: <16aa0caab1aa196bb19e5e9b1c837b873e1beadb.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement initjmp() for RISC-V. Signed-off-by: Jerome Forissier --- arch/Kconfig | 1 + arch/riscv/include/asm/setjmp.h | 1 + arch/riscv/lib/setjmp.S | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 57695fada8d..b745222bfbe 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -152,6 +152,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/include/asm/setjmp.h b/arch/riscv/include/asm/setjmp.h index 72383d43303..98ea157eb3b 100644 --- a/arch/riscv/include/asm/setjmp.h +++ b/arch/riscv/include/asm/setjmp.h @@ -21,5 +21,6 @@ typedef struct jmp_buf_data jmp_buf[1]; int setjmp(jmp_buf jmp); void longjmp(jmp_buf jmp, int ret); +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); #endif /* _SETJMP_H_ */ diff --git a/arch/riscv/lib/setjmp.S b/arch/riscv/lib/setjmp.S index 99d6195827e..6f952a16eee 100644 --- a/arch/riscv/lib/setjmp.S +++ b/arch/riscv/lib/setjmp.S @@ -59,3 +59,13 @@ ENTRY(longjmp) ret ENDPROC(longjmp) .popsection + +.pushsection .text.initjmp, "ax" +ENTRY(initjmp) + /* a1: entry point address, a2: stack top */ + STORE_IDX(a1, 12) + STORE_IDX(a2, 13) + li a0, 0 + ret +ENDPROC(initjmp) +.popsection From patchwork Tue Feb 25 16:34: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: 868116 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388772wrb; Tue, 25 Feb 2025 08:35:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUuiQWRcLnUotfo6xr0OxiNxhs0sdhE/2LG0SVJmMrC6gVEfSXYmmRhIs/q4bGvdtVCEW5CWw==@linaro.org X-Google-Smtp-Source: AGHT+IHKRvj3rGiKSnaROv4VJX+5I/i1ou+gcSqQYcJyyhD9UQzm7tZa+knF4zL2KdC1+g3rTf1+ X-Received: by 2002:a5d:5846:0:b0:38d:dc4d:3473 with SMTP id ffacd0b85a97d-390cc63e06dmr3396402f8f.51.1740501345306; Tue, 25 Feb 2025 08:35:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501345; cv=none; d=google.com; s=arc-20240605; b=iiCi5kfVI5X05mBdnK0eY+Ky3ebLYk+7oYEPCcBbBboBqochCavvXR/6GK0+fPIU7Y Gyx+R2jETNHoUNYej5qY39Vw+hzyHfC76vRJZNwevfWMt4xsO4a+VP/F0FuODvjVExHG ZyWFprYNrJDX5OsMUgJXq9JwvwjEMNfEhh0Kvz7ozoRVxbiZ2+yr2A24esAsdqHyKiqI DJ0IjVfX1WeffnNA49iaxn+QlCuGy64f6+f3LUMwcFWKh2B83GRZK2GjzO6y5BFduiSp N0PVQNVtPK+s46G0FMlv3gMtdx6bAtnC58X62I83lcc+oR6Az6kybRxanVJJ3QcTPpOQ 6/fA== 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=zc5YqeOWjVFGOI9lQwk18URjr1oDar0gNQj5WjUOp00=; fh=HaKHCOHL46OAAPpM3W6HDLkDmJxXWc+qggc/xnkS9u8=; b=V+9239BW+Ht+IjN4F0wXvy4ycbvosLM5uzAQpQT0Hveqe0skj1XzoyN1ZKtyhj84I0 UHElAslC/N9uzm2DiZRLWf8+XUkakh2cLXGr5GlUZWrpKb98qy9rFonCqnVSo/AGyAgn e4Jks46ptukr3tkJT/eOVSlr3yc3D/x+TyFn/T5wbo8E1UE4wIjb1rMyaEHEG/Wz6yRo 5VNXzOxCqEQ5XXqPC7kGDhoBfR8FnT1VrmyzWUiRedWntWayfc3U80QTb02w9ln7JgV6 dPcLLhoBxlkExeyPF4F4yAGr4rAq6iLhltZLUo3LcirB71Gflt67DijcUAKslSUVjvDW C3ug==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=titERvgy; 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-390cd8d7ff2si1334016f8f.346.2025.02.25.08.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:45 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=titERvgy; 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 4B5B880F88; Tue, 25 Feb 2025 17:35:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="titERvgy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5A73480FED; Tue, 25 Feb 2025 17:35:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C8017807EE for ; Tue, 25 Feb 2025 17:35:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-38f2b7ce2e5so3432196f8f.2 for ; Tue, 25 Feb 2025 08:35:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501315; x=1741106115; 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=zc5YqeOWjVFGOI9lQwk18URjr1oDar0gNQj5WjUOp00=; b=titERvgyTSNDs3dFoZ1T/kFjS6pRHC3vkh3NEEMeRF/BRH3ZbkSPXErUktAV2PXgHc nUY5U3Nh58dZk/qbJZkmCI+XE53QnpPYdhAkmjMAd/o5Cqc3VV8p1byUhaoXZEyjX6pI S4AyPb35RKa3ZHRGYJMDYGQ8t9umjK5F19RF8iOI/lXPR0R3iO2WFknOAE5AOphUAM2Z dTLyiHYyfVpe9axEz4SsKK6mX6QlkWiHzGQdV9n/bD9Wc+ErBTEgQaYimT3PA1w9W7+c hIO+bROv8yPNMJJsJaRg+4jQHiF/bCqHnQvfAQul+89W+1vRAqKlrKVR11FK0NSCKs7Y /McA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501315; x=1741106115; 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=zc5YqeOWjVFGOI9lQwk18URjr1oDar0gNQj5WjUOp00=; b=ISmr/z9KGR7E+JGVcjNPD7rQZeXwl2whwxwlNyRhOqJx2C9EfRmJ/RIvW+ssdhbeKU 67dNrvdNlIQ7fYxepr/CXHUjh55wMB3O+snA2BH7UUEnXK7LU4FVzRP6lqqzaIgvp7dZ A3FYWfhsdzl+wEk6nRH+JZ6xz4L8yO5OkMrVV7dJTF2lnSTIOaheGEqq0ktx7pV5Ju3R 2m6rzU+a2mFP/KyxXrOY/I5DW/tCsVUr+3TyMKn2IUaC5Hc3L384s6RCtGflYFQL67x3 WRnQ3iYhGCYxn+K25DllPmIvVKHwaZbXymnyJM210atyMVR0pA7ydRLktcQ/3rYrYBnK BVtw== X-Gm-Message-State: AOJu0YzAsUmRFioOALeh04RurWHzN+FnBVsKOh9LB9TpwXNV9jQwW6fD Xa8Y+7UpWGM9KCA8z7P/0Q3gtcRq8PrvOBL8MD4Os1jlSMyW10AkYaM/nl+xBidYmv78y6I15f0 ttUvD7g== X-Gm-Gg: ASbGnctCEhx7ZQylmnQNZ00gh4ZkulG7RESEY0TprYmQ+hlWDAr1ipLBym3HtoRMn0w JOYg6Ik5v3eyahmxriEaQOoe3kwII6MYrJQ9mUE/RXGwXYq+CvleEw4HidCjgbnUq9RziTrxsAk kYOdtCNnI85tCE5vwl6glNFRMGJreATD8MOXw/WzQ1sBN2YvCrnCrDkR4na+Td528HaTf6dlsBl YexNBvey13CHGX7Zl/tzSYdOxqlEUR+J0JSs0ILq7l2neXJ0mhU0091LlgUZxj7osFX5y28e008 mXcdQzKjp+imyP90QD+6nQwDZI0tJkRSsmE= X-Received: by 2002:a05:6000:402b:b0:38f:4531:3973 with SMTP id ffacd0b85a97d-390cc5f7094mr3141387f8f.4.1740501314532; Tue, 25 Feb 2025 08:35:14 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:14 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Simon Glass , Tom Rini Subject: [PATCH v2 04/14] sandbox: add initjmp() Date: Tue, 25 Feb 2025 17:34:30 +0100 Message-ID: <37f445441e199d9689ae00a386b06dd8a4ebce56.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add ininijmp() to sandbox. The implementation is taken verbatim from barebox [1]. It is quite complex because contrary to U-Boot platform code we don't know how the system's C library implements the jump buffer, so we can't just write the function and stack pointers into it. FIXME: this patch should make SANDBOX select HAVE_INITJMP (in arch/Kconfig). It does not due to the following error detected by CI: _________________________ test_ut[ut_lib_lib_initjmp] __________________________ test/py/tests/test_ut.py:608: in test_ut output = u_boot_console.run_command('ut ' + ut_subtest) test/py/u_boot_console_base.py:334: in run_command m = self.p.expect([self.prompt_compiled] + self.bad_patterns) test/py/u_boot_spawn.py:296: in expect c = self.receive(1024) test/py/u_boot_spawn.py:235: in receive raise err test/py/u_boot_spawn.py:227: in receive c = os.read(self.fd, num_bytes).decode(errors='replace') E OSError: [Errno 5] Input/output error ----------------------------- Captured stdout call ----------------------------- => ut lib lib_initjmp Test: lib_initjmp: initjmp.c Failures: 0 common/dlmalloc.c:796: do_check_free_chunk: Assertion `next == top || inuse(next)' failed.common/dlmalloc.c:796: do_check_free_chunk: Assertion `next == top || inuse(next)' failed. ---------------- generated xml file: /tmp/sandbox64/results.xml ---------------- On x86 the dmalloc error is not printed but the I/O error is still there. [1] https://github.com/barebox/barebox/blob/b2a15c383ddc/arch/sandbox/os/setjmp.c Signed-off-by: Jerome Forissier --- arch/sandbox/cpu/Makefile | 11 +- arch/sandbox/cpu/initjmp.c | 172 ++++++++++++++++++++++++++++++ arch/sandbox/include/asm/setjmp.h | 5 + 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/cpu/initjmp.c diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile index bfcdc335d32..038ad78accc 100644 --- a/arch/sandbox/cpu/Makefile +++ b/arch/sandbox/cpu/Makefile @@ -5,7 +5,7 @@ # (C) Copyright 2000-2003 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. -obj-y := cache.o cpu.o state.o +obj-y := cache.o cpu.o state.o initjmp.o extra-y := start.o os.o extra-$(CONFIG_SANDBOX_SDL) += sdl.o obj-$(CONFIG_XPL_BUILD) += spl.o @@ -29,6 +29,15 @@ cmd_cc_eth-raw-os.o = $(CC) $(filter-out -nostdinc, \ $(obj)/eth-raw-os.o: $(src)/eth-raw-os.c FORCE $(call if_changed_dep,cc_eth-raw-os.o) +# initjmp.c is build in the system environment, so needs standard includes +# CFLAGS_REMOVE_initjmp.o cannot be used to drop header include path +quiet_cmd_cc_initjmp.o = CC $(quiet_modtag) $@ +cmd_cc_initjmp.o = $(CC) $(filter-out -nostdinc, \ + $(patsubst -I%,-idirafter%,$(c_flags))) -c -o $@ $< + +$(obj)/initjmp.o: $(src)/initjmp.c FORCE + $(call if_changed_dep,cc_initjmp.o) + # sdl.c fails to build with -fshort-wchar using musl cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \ $(patsubst -I%,-idirafter%,$(c_flags))) -fno-lto -c -o $@ $< diff --git a/arch/sandbox/cpu/initjmp.c b/arch/sandbox/cpu/initjmp.c new file mode 100644 index 00000000000..c99721423c5 --- /dev/null +++ b/arch/sandbox/cpu/initjmp.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * An implementation of initjmp() in C, that plays well with the system's + * setjmp() and longjmp() functions. + * Taken verbatim from arch/sandbox/os/setjmp.c in the barebox project. + * + * Copyright (C) 2006 Anthony Liguori + * Copyright (C) 2011 Kevin Wolf + * Copyright (C) 2012 Alex Barcelo + * Copyright (C) 2021 Ahmad Fatoum, Pengutronix + * This file is partly based on pth_mctx.c, from the GNU Portable Threads + * Copyright (c) 1999-2006 Ralf S. Engelschall + */ + +/* XXX Is there a nicer way to disable glibc's stack check for longjmp? */ +#ifdef _FORTIFY_SOURCE +#undef _FORTIFY_SOURCE +#endif + +#include +#include +#include +#include +#include + +typedef sigjmp_buf _jmp_buf __attribute__((aligned((16)))); +_Static_assert(sizeof(_jmp_buf) <= 512, "sigjmp_buf size exceeds expectation"); + +/* + * Information for the signal handler (trampoline) + */ +static struct { + _jmp_buf *reenter; + void (*entry)(void); + volatile sig_atomic_t called; +} tr_state; + +/* + * "boot" function + * This is what starts the coroutine, is called from the trampoline + * (from the signal handler when it is not signal handling, read ahead + * for more information). + */ +static void __attribute__((noinline, noreturn)) +coroutine_bootstrap(void (*entry)(void)) +{ + for (;;) + entry(); +} + +/* + * This is used as the signal handler. This is called with the brand new stack + * (thanks to sigaltstack). We have to return, given that this is a signal + * handler and the sigmask and some other things are changed. + */ +static void coroutine_trampoline(int signal) +{ + /* Get the thread specific information */ + tr_state.called = 1; + + /* + * Here we have to do a bit of a ping pong between the caller, given that + * this is a signal handler and we have to do a return "soon". Then the + * caller can reestablish everything and do a siglongjmp here again. + */ + if (!sigsetjmp(*tr_state.reenter, 0)) { + return; + } + + /* + * Ok, the caller has siglongjmp'ed back to us, so now prepare + * us for the real machine state switching. We have to jump + * into another function here to get a new stack context for + * the auto variables (which have to be auto-variables + * because the start of the thread happens later). Else with + * PIC (i.e. Position Independent Code which is used when PTH + * is built as a shared library) most platforms would + * horrible core dump as experience showed. + */ + coroutine_bootstrap(tr_state.entry); +} + +int __attribute__((weak)) initjmp(_jmp_buf jmp, void (*func)(void), void *stack_top) +{ + struct sigaction sa; + struct sigaction osa; + stack_t ss; + stack_t oss; + sigset_t sigs; + sigset_t osigs; + + /* The way to manipulate stack is with the sigaltstack function. We + * prepare a stack, with it delivering a signal to ourselves and then + * put sigsetjmp/siglongjmp where needed. + * This has been done keeping coroutine-ucontext (from the QEMU project) + * as a model and with the pth ideas (GNU Portable Threads). + * See coroutine-ucontext for the basics of the coroutines and see + * pth_mctx.c (from the pth project) for the + * sigaltstack way of manipulating stacks. + */ + + tr_state.entry = func; + tr_state.reenter = (void *)jmp; + + /* + * Preserve the SIGUSR2 signal state, block SIGUSR2, + * and establish our signal handler. The signal will + * later transfer control onto the signal stack. + */ + sigemptyset(&sigs); + sigaddset(&sigs, SIGUSR2); + pthread_sigmask(SIG_BLOCK, &sigs, &osigs); + sa.sa_handler = coroutine_trampoline; + sigfillset(&sa.sa_mask); + sa.sa_flags = SA_ONSTACK; + if (sigaction(SIGUSR2, &sa, &osa) != 0) { + return -1; + } + + /* + * Set the new stack. + */ + ss.ss_sp = stack_top - CONFIG_STACK_SIZE; + ss.ss_size = CONFIG_STACK_SIZE; + ss.ss_flags = 0; + if (sigaltstack(&ss, &oss) < 0) { + return -1; + } + + /* + * Now transfer control onto the signal stack and set it up. + * It will return immediately via "return" after the sigsetjmp() + * was performed. Be careful here with race conditions. The + * signal can be delivered the first time sigsuspend() is + * called. + */ + tr_state.called = 0; + pthread_kill(pthread_self(), SIGUSR2); + sigfillset(&sigs); + sigdelset(&sigs, SIGUSR2); + while (!tr_state.called) { + sigsuspend(&sigs); + } + + /* + * Inform the system that we are back off the signal stack by + * removing the alternative signal stack. Be careful here: It + * first has to be disabled, before it can be removed. + */ + sigaltstack(NULL, &ss); + ss.ss_flags = SS_DISABLE; + if (sigaltstack(&ss, NULL) < 0) { + return -1; + } + sigaltstack(NULL, &ss); + if (!(oss.ss_flags & SS_DISABLE)) { + sigaltstack(&oss, NULL); + } + + /* + * Restore the old SIGUSR2 signal handler and mask + */ + sigaction(SIGUSR2, &osa, NULL); + pthread_sigmask(SIG_SETMASK, &osigs, NULL); + + /* + * jmp can now be used to enter the trampoline again, but not as a + * signal handler. Instead it's longjmp'd to directly. + */ + return 0; +} + diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h index 001c7ea322d..d708e6da3fc 100644 --- a/arch/sandbox/include/asm/setjmp.h +++ b/arch/sandbox/include/asm/setjmp.h @@ -31,5 +31,10 @@ typedef struct jmp_buf_data jmp_buf[1]; */ int setjmp(jmp_buf jmp); __noreturn void longjmp(jmp_buf jmp, int ret); +/* + * initjmp() is non-standard, still it has to play well with the system versions + * of setjmp()/longjmp(). + */ +int initjmp(jmp_buf jmp, void __noreturn (*func)(void), void *stack_top); #endif /* _SETJMP_H_ */ From patchwork Tue Feb 25 16:34: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: 868117 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388839wrb; Tue, 25 Feb 2025 08:35:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhp4FiBkr+36FYTqFotlZxqCnNzXmWKoCNIOD4aqrwTKg6SajakzI4iurKXUsvH7frfJ93AQ==@linaro.org X-Google-Smtp-Source: AGHT+IEyQ8IKGDAGhrOPPv0rARR1NVhQ4GwXTDYoaCbT2HwKcgJBvgsGFrXvA/OpZwMCgGfc4w8C X-Received: by 2002:a5d:64e6:0:b0:38d:e411:7dcc with SMTP id ffacd0b85a97d-38f6f0b06a7mr14312710f8f.37.1740501353635; Tue, 25 Feb 2025 08:35:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501353; cv=none; d=google.com; s=arc-20240605; b=gFNA183Oq7v96YJYWxwAi+Bvv3hx2vXTg0fO6z+ZKxMSWMhV5xsHWYR1O7Cp3WENoX RAYI3EtsYzUwmbd67j03dhqDLC24EOW5x/fbIR0CcLg3BeMcRAVNhLCtuJRKyuPTvdEd x6f5LRow4wVXeZRA4yk/XeDtFwRwIyO9BysUk+abpZHSGA8Sr/IT/hTfvtdo/vrni+I8 btU8PYjxUSkFzOt2RNLBGBmCnqZQw6mYyfGetFjk6yF8iZ+bx/XbEn2YbBqfMjSey/Rt HHAGjIn9v1MWk4pKg/z31p+PQksdxiD009pQvxceTjwT/zSMPht6UaL+dHAkz2HVRkSs QocQ== 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=IJNaNPY3czlLhhfrH4SNPdHcNteu2M3lW9KGA73kCRE=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=LpMvBNM5k82lTqv1UC40gxzHMFNSBmab72pT5EveelzJwRjVv+tidzWc9mkqFWc5pW t5dTVv+EPzCrNBle3KrBAzUiK4JkYmL8N/bW/WXHq0I6+4elwGbJ/ZKFZ0Snxlr3zaUu InhCsFHn5/177iy9YGvE0X88OeAo138w3x+VkwWwQYTqOxgWAhlvXIklUOCr+C7QnbSd 2g/eAx0+XFKCVLxL/eJ/cvlnLauM0yQyY2xW0uLWsnKtWbmIR1IyriOx8x91pxl6JgVA CPNayyxWu40XfI/jzgMT49cO2O7oRrdvJ/v+2P2o27lzcKoT3QOPZCfbQEbjoINJ5vWS AbdA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ln7d8vjs; 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-390cd8e68casi1331296f8f.519.2025.02.25.08.35.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:53 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ln7d8vjs; 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 939C380FC2; Tue, 25 Feb 2025 17:35:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="ln7d8vjs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A9C1480FF4; Tue, 25 Feb 2025 17:35:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (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 A482280F53 for ; Tue, 25 Feb 2025 17:35:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4398e3dfc66so51333925e9.0 for ; Tue, 25 Feb 2025 08:35:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501316; x=1741106116; 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=IJNaNPY3czlLhhfrH4SNPdHcNteu2M3lW9KGA73kCRE=; b=ln7d8vjscWbTOUjmrFjZ5J0j7fnPRNIGllKD1kYO9zuIgfdFb16bDSuxyLWgsMZUqR aHb8xRQw3u7IDFrXNT/S1QqMXAXAUGgAlCk9eOFDapLpV+NKtiuwQnQkr7FSJB1eQcGw yj8iRZCa+S3VcXqjAmMT1tcehjXpbnnSIyOpwfW+pnrIHsXWxrcyQAoGxytZ98mp1oJB IqmL0zj3uavJzdp91LI3S+FPC65oXVlfvZaUxjYOclwzOlDE5Jqgq8jQT+hguO5wU8DB ZC4WYx8B4RmPE9G2aO7xlWag4306EBIrqCKZ11DPcmSqun0SPdfO359p8nU6edBMiCH1 mozw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501316; x=1741106116; 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=IJNaNPY3czlLhhfrH4SNPdHcNteu2M3lW9KGA73kCRE=; b=OTFjbIAz/StS2hCyQS/AG1/D1HhdanUmjqBKtPCg1bbQCpN6lFBupMTpj1YBvBiHaX E7KFHSzQELPbQ/kL1ll65hSGwSqHo7OyFithutHrFU0d/cpZxsnvGFnyXkAkHwiZdy4g 2ag8ztRqgE8evvs5X7cQXEWwG/xDu1j3StEztrbnLOyWmvoUj/PyfXDlmqk4rPjnKKYN UM4oG2asnxKmLk3YpQIs6vg4EZAQSZuCvAcA/ZXE01TnAbLqUrwdFkQDIgdDbwPc3KqT bRDSo3fAFEXZ0UGXzBbRTqAUsOx4Q/G/U1tPC+3LD1gwTWb5YzoKIRDIebQjLEgU1ETy 3VLA== X-Gm-Message-State: AOJu0YxL2aA5dJf9Zowp2uWvqf8B3T4bdaReE6iTHXK0S9B3APTrETDO qu157Xehlj37JWThMWpx+UuYiAwgxcfD/Z4OBQC+tBzTPHGHs3CcjbBiIJ/Ejje3Tt7m6EQINIU tZeKVFw== X-Gm-Gg: ASbGncsRsA6yhWFhPxLNavV0PBm2gIPW7ZuI7L3iSmyMeyuUVKqh/O6HIrAM8YxgzJZ BnL+U3cEjrDozE1U4JKyViEPIizyd7aLEG40MdA+mbGpBhv8Uw3Ub2GhRV95zXsRuKRsOQA/yqD isMCX/C5iSPk/uo+WAlmuiPCqSCYU4AVuAsw0/1PrXbOJdLZhosjadEO5u4SHXLQZqHHrR3QAwy 2tbjedF9rU1UGauyucM7z3NVhDjz18TwC4Q3ZH3F0ivfdWdtBa+pZtbDh3nFFjF9wfs4GbZdphv BphkTVkQtFvNo+/Iw/LIi/IeUzy8NeQAQuM= X-Received: by 2002:a05:600c:4fc8:b0:439:9496:17df with SMTP id 5b1f17b1804b1-43ab8fe76d2mr1789755e9.13.1740501315966; Tue, 25 Feb 2025 08:35:15 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:15 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Raymond Mao , Philippe Reynes Subject: [PATCH v2 05/14] test: lib: add initjmp() test Date: Tue, 25 Feb 2025 17:34:31 +0100 Message-ID: <6eb03993def0d868874fa3fca05e1d08ddc6afd6.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Test the initjmp() function when HAVE_INITJMP is set. Signed-off-by: Jerome Forissier --- test/lib/Makefile | 1 + test/lib/initjmp.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/lib/initjmp.c diff --git a/test/lib/Makefile b/test/lib/Makefile index 0e4cb8e3dfd..bf04685dae1 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -14,6 +14,7 @@ obj-y += hexdump.o obj-$(CONFIG_SANDBOX) += kconfig.o obj-y += lmb.o obj-$(CONFIG_HAVE_SETJMP) += longjmp.o +obj-$(CONFIG_HAVE_INITJMP) += initjmp.o obj-$(CONFIG_CONSOLE_RECORD) += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-$(CONFIG_$(PHASE_)STRTO) += str.o diff --git a/test/lib/initjmp.c b/test/lib/initjmp.c new file mode 100644 index 00000000000..52bbda8cc60 --- /dev/null +++ b/test/lib/initjmp.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for initjmp() + */ + +#include +#include +#include +#include +#include +#include + +static bool ep_entered; +static jmp_buf return_buf; + +static void __noreturn entrypoint(void) +{ + ep_entered = true; + + /* Jump back to the main routine */ + longjmp(return_buf, 1); + + /* Not reached */ + panic("longjmp failed\n"); +} + +static int lib_initjmp(struct unit_test_state *uts) +{ + int ret; + void *stack; + jmp_buf buf; + int stack_sz = 1024; + + ep_entered = false; + + stack = malloc(stack_sz); + ut_assertnonnull(stack); + + ut_assert(!ep_entered); + + /* + * Prepare return_buf so that entrypoint may jump back just after the + * if() + */ + if (!setjmp(return_buf)) { + /* return_buf initialized, entrypoint not yet called */ + + /* + * Prepare another jump buffer to jump into entrypoint with the + * given stack + */ + ret = initjmp(buf, entrypoint, stack + stack_sz); + ut_assertok(ret); + + /* Jump into entrypoint */ + longjmp(buf, 1); + /* + * Not reached since entrypoint is expected to branch after + * the if() + */ + ut_assert(false); + } + + ut_assert(ep_entered); + + free(stack); + + return 0; +} +LIB_TEST(lib_initjmp, 0); From patchwork Tue Feb 25 16:34: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: 868118 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388895wrb; Tue, 25 Feb 2025 08:36:02 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXFWSo+NYrsVzsK+vvJ3NB2mBvXJgik0Ambh5OQ4u9nbDb29ROkFM3VG1DLpddOb80p/63HNQ==@linaro.org X-Google-Smtp-Source: AGHT+IHjYHIMzG7q1B4ZqBTbGjbaTRfyxtP3EQUZzsMHRxuEqvSoZFKVEyQfo78q3OPW9gcjWnMc X-Received: by 2002:a05:6000:2ac:b0:38f:221c:2c8e with SMTP id ffacd0b85a97d-38f6f3c506fmr14854182f8f.6.1740501361989; Tue, 25 Feb 2025 08:36:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501361; cv=none; d=google.com; s=arc-20240605; b=Eu2iIYDDEf/P1TSuCYHAznA5sqmgxvvRt8TpdDFriRP8C14qCjPwkaywDePQkUnold 6Dbeew5tLFu5iaxY0888lVqu9pWo/TP0UQIUOX35g6DbvW8NQI6BHsXz3yXE4cMa+Qcd Gs1zg/WqBNOghU6Osp0od6mm034CAKKLxcTshQIncITT4pf+AkmCPxVtneWbN+1OCxj1 fSzAOqasawtodr3WEX/u86znXMGGTLHJif1wrcrjC9J1VcnDx4ul5NvYz+JawlBlPwnO g4SF4Rr8N4mSphvjEnMUDdx21RkjjEZFy0lWAW7xZ3RUTT0UeKt8l5I2w437BwzbDQYK vmFw== 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=D6Dmo3k63v8InZm1ge4XlbDH+XbCJvJuN1AGsB+nbZ8=; fh=nrOpUoarlg/n/UHeystM/GDRJZjEfu6HZg2N4nTDlw4=; b=MNnIqqJfzmBSkvF6SzwPwv1boh/LO0OYvUhqCyvy9c64NcWagXhqwnARAesh8yOAPY HsoXPM/5qWIHJGhqIxfNju3eSFWIVfxL8KtbqwPUDr4ikSNL/dpUNrSBCryTngkJmBRa rW9IetLUrdnQnPo2clxzfXX9YEXfFpPV9ONLvRmZGa/EjOe/WKY7jN/Es75MY6wLZZjz WgY5mR5GzOeQRByp5ZazL9XtAPOkTpHDyW4rQGUfpcloAPhByQOwO83ZZ815yDtYQxZ5 um2Wvmq9ES5Hyz0vJBJlmo9N2uW1ctBLIF8hTekbfPdJcmChZvwyAcAqoBTXE/Qw/L3J w/mw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZoN8PFRf; 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-390cd910fd7si1310342f8f.907.2025.02.25.08.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:01 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZoN8PFRf; 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 E06A480F53; Tue, 25 Feb 2025 17:35:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZoN8PFRf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F3171807EE; Tue, 25 Feb 2025 17:35:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-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 79B7480FED for ; Tue, 25 Feb 2025 17:35:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-38f5fc33602so3387808f8f.0 for ; Tue, 25 Feb 2025 08:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501318; x=1741106118; 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=D6Dmo3k63v8InZm1ge4XlbDH+XbCJvJuN1AGsB+nbZ8=; b=ZoN8PFRflyj4Vd/nqE17Xqk7dJXKehuyGx1GULnhM/tl0G0gwjYYOzBCJcuBNXoPXs RPNwWIoZIYDk+Hkj7EMKZxW9IhknZctM8HX3PGg3h7a/oIS22SCUyphcckE3rZPZMSzP VEeYmses3TiatrS36IKd76l9pymihXKXiu/WdZfuHDiJ/H7h//0RKyIbLPdAuRQ54iXw 3AG//V8QWiPiNMIj8jom4KrHy+1enfMXGUycc2C+kL7OqQIjW5rntnOfXnI4/FQ46GoT YYxGwL9zJi9ADlIWbXZ1rdBDLfWry4wENmmeUGbLarqzWrKjiI5DMgBtxCDDn3oCdLnA xM/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501318; x=1741106118; 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=D6Dmo3k63v8InZm1ge4XlbDH+XbCJvJuN1AGsB+nbZ8=; b=THNE+OpEA1G5V1TMFzOvtXIH+NrsvvtdCgMKWHHrUa0YVBV+NsbYvEDk2JKbt7c1G2 8gDsXEqQfntVO+ont7h3gZqZDY28t/K8OA7DSxi9MNOprcOIBudogWDP85+9bbBEkMcx bJKDJTFKQfdpYuGrxnSBYczxHKfhHIbSeghXKuJGClcrWfbfjaRoTADfclk+WuLxcbES 7RqNoshx2Mai+bfxJy9V1iOgf4NVYl0pEmPELkUn/TTstaj8zZKsBpgeYOIWjR8pCwmf 4Dgwo583TBvT4wjAzOwlSfU7RZPJnpmLxKlIA/YsX92/iRI6QoJKAIvb0JuNS0Vrz5dg zhSw== X-Gm-Message-State: AOJu0YypiYhxB+EU6svmfSA2aODZO2zGTbmFtPVGGp9EZewx1tyNh1lc 5PO9AoniQCWLA2NSgImmbOY9RkrZuNtGe5QDdPvtWcf2EKDj9cAXXYTNdyXM87D2fxaGqjTFGjh rz4ntSw== X-Gm-Gg: ASbGnctomwBEGhZjrXiC83GpfDzXG3ulY6VZC7JyQb8xUvhnKnxYOjf943s8e4MI1G5 Lr0C5+SpP5inJMBM3SItzBkhvQbk/B/Nt9Re0VU2cPlZqV1AkuCirfE8w77muVKJjJWP2SGiX2Y NM29IX4OVD8nWutXwEEiwQ8vW9W3q1t1761bo6gxxSTKHGzVYt5O6CgWoZ4v/RPLQhWqkEC6sc3 WLo9CfCYyCdsUKWjOGDruPDeolwM5BF9XUL/cbcbP1mryXJ1gulY16kA9PKyhPpYYhgcekyoqGF UEE1A372aIuxvuATM8Uih9u+oabgSbgl/rY= X-Received: by 2002:a5d:6d09:0:b0:38f:4f37:7504 with SMTP id ffacd0b85a97d-38f615be1c7mr18930983f8f.16.1740501317686; Tue, 25 Feb 2025 08:35:17 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:17 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Sughosh Ganu , Raymond Mao , Patrick Rudolph , Michal Simek , Heinrich Schuchardt Subject: [PATCH v2 06/14] uthread: add cooperative multi-tasking interface Date: Tue, 25 Feb 2025 17:34:32 +0100 Message-ID: <0b793a3251dbd9cf41066e3e358269fdb1aac3f8.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add an 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 --- include/uthread.h | 44 ++++++++++++ lib/Kconfig | 21 ++++++ lib/Makefile | 2 + lib/uthread.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 include/uthread.h create mode 100644 lib/uthread.c diff --git a/include/uthread.h b/include/uthread.h new file mode 100644 index 00000000000..f1f86d210d5 --- /dev/null +++ b/include/uthread.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2025 Linaro Limited + */ + +#include + +#ifndef _UTHREAD_H_ +#define _UTHREAD_H_ + +#ifdef CONFIG_UTHREAD + +int uthread_create(void (*fn)(void *), void *arg, size_t stack_sz, + unsigned int grp_id); +bool uthread_schedule(void); +unsigned int uthread_grp_new_id(void); +bool uthread_grp_done(unsigned int grp_id); + +#else + +static inline int uthread_create(void (*fn)(void *), void *arg, size_t stack_sz, + unsigned int grp_id) +{ + fn(arg); + return 0; +} + +static inline bool uthread_schedule(void) +{ + return false; +} + +static inline unsigned int uthread_grp_new_id(void) +{ + return 0; +} + +static inline bool uthread_grp_done(unsigned int grp_id) +{ + return true; +} + +#endif /* CONFIG_UTHREAD */ +#endif /* _UTHREAD_H_ */ diff --git a/lib/Kconfig b/lib/Kconfig index 1a683dea670..b32740ecbcc 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1255,6 +1255,27 @@ config PHANDLE_CHECK_SEQ enable this config option to distinguish them using phandles in fdtdec_get_alias_seq() function. +config UTHREAD + bool "Enable thread support" + depends on HAVE_INITJMP + help + Implement a simple form of cooperative multi-tasking based on + context-switching via initjmp(), setjmp() and longjmp(). The + uthread_ interface enables the main thread of execution to create + one or more secondary threads and schedule them until they all have + returned. At any point a thread may suspend its execution and + schedule another thread, which allows for the efficient multiplexing + of leghthy operations. + +config UTHREAD_STACK_SIZE + int "Default uthread stack size" + depends on UTHREAD + default 32768 + help + The default stak size for uthreads. Each uthread has its own stack. + When the stack_sz argument to uthread_create() is zero then this + value is used. + endmenu source "lib/fwu_updates/Kconfig" diff --git a/lib/Makefile b/lib/Makefile index a7bc2f3134a..3610694de7a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -164,6 +164,8 @@ obj-$(CONFIG_LIB_ELF) += elf.o obj-$(CONFIG_$(PHASE_)SEMIHOSTING) += semihosting.o +obj-$(CONFIG_UTHREAD) += uthread.o + # # Build a fast OID lookup registry from include/linux/oid_registry.h # diff --git a/lib/uthread.c b/lib/uthread.c new file mode 100644 index 00000000000..430d1c0de32 --- /dev/null +++ b/lib/uthread.c @@ -0,0 +1,178 @@ +// 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 { + void (*fn)(void *); + void *arg; + jmp_buf ctx; + void *stack; + bool done; + unsigned int grp_id; + struct list_head list; +} 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 inijmp() + * 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); +} + +/** + * uthread_create() - Create a uthread object and make it ready for execution + * + * Threads are automatically deleted when then return from their entry point. + * + * @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(void (*fn)(void *), void *arg, size_t stack_sz, + unsigned int grp_id) +{ + struct uthread *uthread; + + if (!stack_sz) + stack_sz = CONFIG_UTHREAD_STACK_SIZE; + + uthread = calloc(1, sizeof(*uthread)); + if (!uthread) + return -1; + + uthread->stack = memalign(16, stack_sz); + if (!uthread->stack) + goto err; + + uthread->fn = fn; + uthread->arg = arg; + uthread->grp_id = grp_id; + + list_add_tail(&uthread->list, ¤t->list); + + initjmp(uthread->ctx, uthread_trampoline, uthread->stack + stack_sz); + + return 0; +err: + uthread_free(uthread); + 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); + } +} + +/** + * 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) +{ + struct uthread *next; + struct uthread *tmp; + + if (list_empty(¤t->list)) + return false; + + list_for_each_entry_safe(next, tmp, ¤t->list, list) { + if (!next->done) { + uthread_resume(next); + return true; + } else { + /* Found a 'done' thread, free its resources */ + list_del(&next->list); + uthread_free(next); + } + } + return false; +} + +/** + * 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) +{ + static unsigned int id = 0; + + return ++id; +} + +/** + * uthread_grp_done() - test if all threads in a group are done + * + * @grp: 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) +{ + struct uthread *next; + + list_for_each_entry(next, &main_thread.list, list) { + if (next->grp_id == grp_id && !next->done) + return false; + } + + return true; +} From patchwork Tue Feb 25 16:34: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: 868119 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp388958wrb; Tue, 25 Feb 2025 08:36:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWdL5pPqY+YEwFpEUUkyg+RZJsDjaXQspS0uEP8RxK4fgq82Ku2iyvEoImnw4fc4j33jZAydA==@linaro.org X-Google-Smtp-Source: AGHT+IGGz43d7Q80u/R5t1U7/0FgN7e2k/7VbyWwLxN7s2QQ8+uzdX/FD+9vEbgw99Si9MrDPkws X-Received: by 2002:a5d:64e5:0:b0:38d:e3fd:1990 with SMTP id ffacd0b85a97d-38f6e4b223bmr16279667f8f.0.1740501371488; Tue, 25 Feb 2025 08:36:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501371; cv=none; d=google.com; s=arc-20240605; b=WN9a7q9co7potV32XOK0Mt/iKHYSzVJFHWKgj9h5grYFg6Fv1mn8oAE51CFs+pBXMe U24cAx3PvTv5NIMxFzFttEnU3TxYL2dq3jYdNsT8JY5OvJQpm9cuE+XmcSeMTAr90eKf BV/qrwnQE04DuiA/pT+2YeCez8dAOfQI8GhjWZWz2ZgYq5vgWazTlRTIgsrDqF1qJqXQ vEP6Q+EOAuDwL2c7hC67IaXaPJzxZm5pG5gE0/9YSNh9TZ99q7hxYYZMGs3saH3L1Dq2 Jt+l1T/3s+gOXRU7lkKwzD4Umhqmhd3o/b86Q3Foubs62Xr+9qibQWDyny0W3iNNqrzx JH2Q== 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=TsjgCMtdoqYaj9xbsmREk63vgEQC+6G2vC6Ad1A5Aec=; fh=FcJrLuOZm3DOgvhNhuu9RcOXf23qDSxE2e4MWRi7Xy0=; b=Uw/qaLUzbSGYBM0XvkBwxxv6WcVIXziRyR16lOeo9IH1tyDxYTTzMmYpn5pO+fCMbo Gci3OxEVY4pvEaFCA+QT3d5fGOrGlgxj023v+lpxEtMEIraXzXVHcyCIoxD643SDtbwo l9YEonni9uEeP6iNNvJGZOlbduYYpuJBLukuyKOH8LNmRRnZLZVw/RNjST7DNJ/Q6Nl5 4PjehJd4vzn+785v9tGEwv0WhrHdvAc/Tg0uLI1GLuzFUvTe/0l87Kf0KrMuqdJNkjz8 JFWPZ8Pyxi40uoJFmE+X9QSm/FmcUNzg5spg3+T+Qaju4ec8WeNgGI5Iy/SPuC+cK64l yN4w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GeX7AS60; 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-390cd8678bbsi1308249f8f.36.2025.02.25.08.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:11 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GeX7AS60; 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 3B8C480FF0; Tue, 25 Feb 2025 17:35:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="GeX7AS60"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DDE6E80FF2; Tue, 25 Feb 2025 17:35:22 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-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 79A3F80F7B for ; Tue, 25 Feb 2025 17:35:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43aac0390e8so14720365e9.2 for ; Tue, 25 Feb 2025 08:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501319; x=1741106119; 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=TsjgCMtdoqYaj9xbsmREk63vgEQC+6G2vC6Ad1A5Aec=; b=GeX7AS60jqowMLihZiqK1C7RBdeT56cFQLjHFJs4KEXoUwYZQrJkdDXXibIFPEWhJx zLvDvaXYuIY5QYxUslfN7SCRjb4+KfDV2kxXTxRzJiG6dph8Yq8KSCrKj+XZXM/6GC2I BtoiyJWVGTXKUw6vs+TfCi9nKd/yobywI0wgQys+BnUvZdnPNurVfYviRswfC3N1oxgW 4YoXtAiVabo/dElxYxfaZD1Bb+ncbZzrcziyzhAhZeaKWXBrDfYQKkt9jw+raKPp7Ijg TUMetvOIDta2sV7ewbQUfQ919kbbuvpGuRkWsDuh82++XoCRAHkik+cBOWQg+LUwKLBc JGEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501319; x=1741106119; 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=TsjgCMtdoqYaj9xbsmREk63vgEQC+6G2vC6Ad1A5Aec=; b=EvrB/zUwFxnY5bwSyI1o8Ty/OsKEJ92JCf5Y1PvoOYG6PusvjX+Y0GZTqZG2D3XX7R 5gptC78oVSJLDdiDgsMF2y0Hizx2LkhPhBjHWPbx8JjZhXyyxoO65t6s6CRKLqOd/3r2 IdIzvCJQNUmSEkV0Z/y77IyApiMSAe2iIL/FQXa32stdKRnYdEyCd/IgWVf179qsV4SF 3TE1pkOWNxHxobDlK4S9QwrnEFcPYrEN/4tSM9U8SL8yQFhXA0rBvqKnKM0xyHLgVeTF Gnvx9E91xBAWeRZlEAemhvTRGSnMCZ8v1qiEevZx9Lnhrx4wqt2yo3IjTTwQ3Af/rPy1 8mXQ== X-Gm-Message-State: AOJu0YxEevxihKDhAooTpJhh5eyURVrYarQyfumc9T0CMUUTXNw7ZqHX Pth9dXIQYw5kgdb/q2H/pRltqlnMKpm4rCJlZ1wdv6hEIzp5l1dnsKIYYIrveyZhG7gBRwKdiV4 ZF4pvkQ== X-Gm-Gg: ASbGncsO3tynY1f3I5ZtxUKEwY1ihPV/VqoTsszxrjwRYkIvaM8S/MfuVLPXk2XEmtP E/uFMUA6Wbaa1OAF1wMHULnQM7qoBcCyFKIjAKSjvpR69Fw1Lk549HpY5ROu6YCtaEuM7fN1EMp wrkBkO9YeLLYd5OwoSrMzx5LEO/+ZWqOTnChPOGMqLbB5qcBMnryiHyC51gIIFquFBfkrroQlkZ AXxg3p8WtiWA3ALximCsUvViiclJvZbRxUM0Al3IdVGGrrPTes1+L4q6wuEXtxCju4mpgDzNECs /WTi5y3EtpjEE+OiKoDDx42rjS7lhiw5qrU= X-Received: by 2002:a05:600c:3b08:b0:439:90f5:3942 with SMTP id 5b1f17b1804b1-439ae221b60mr138981935e9.25.1740501318765; Tue, 25 Feb 2025 08:35:18 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:18 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Stefan Roese , Tom Rini , Rasmus Villemoes , Simon Glass , Patrice Chotard Subject: [PATCH v2 07/14] cyclic: invoke uthread_schedule() from schedule() Date: Tue, 25 Feb 2025 17:34:33 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 --- common/cyclic.c | 3 +++ include/u-boot/schedule.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/common/cyclic.c b/common/cyclic.c index fad071a39c6..b695f092f52 100644 --- a/common/cyclic.c +++ b/common/cyclic.c @@ -16,6 +16,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -100,6 +101,8 @@ void schedule(void) */ if (gd) cyclic_run(); + + uthread_schedule(); } int cyclic_unregister_all(void) diff --git a/include/u-boot/schedule.h b/include/u-boot/schedule.h index 4fd34c41229..4605971fdcb 100644 --- a/include/u-boot/schedule.h +++ b/include/u-boot/schedule.h @@ -3,6 +3,8 @@ #ifndef _U_BOOT_SCHEDULE_H #define _U_BOOT_SCHEDULE_H +#include + #if CONFIG_IS_ENABLED(CYCLIC) /** * schedule() - Schedule all potentially waiting tasks @@ -17,6 +19,7 @@ void schedule(void); static inline void schedule(void) { + uthread_schedule(); } #endif From patchwork Tue Feb 25 16:34: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: 868120 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389024wrb; Tue, 25 Feb 2025 08:36:19 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXJpXIe+qgHf0gNM7TtsMFyMYuDuagMpra0McI7dZ+HEpbRDtVoxlIZHx28yOWsh1yv1kHLJg==@linaro.org X-Google-Smtp-Source: AGHT+IFj1MJEdi1W0C0/6yCmEBdFm8rnw7jB5mDdEEmOBSxwmHMwqweXGhEhZPOsS0PEUVbHZ+RQ X-Received: by 2002:a5d:6da5:0:b0:38d:df70:23cf with SMTP id ffacd0b85a97d-38f6e9470ebmr13888784f8f.16.1740501378801; Tue, 25 Feb 2025 08:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501378; cv=none; d=google.com; s=arc-20240605; b=UnEm/TJoLPeV48DnvVl/O9Uo8bz3jni3tdqG4yX2hRwIMJUYJbUvId0fSV5RvC3s3I NjZAkOYnFT6JteDGKfL9MmxC77Pg3LBqVLQLrPm091LhgUHK3HzzsSFhl68m2SKt0e9I 02e06kkqNFppLkEthUeJHgzP+M1Fmr7R3pQSuOhbQr4D3jWS8dP8f0sYJQsnwi9xjGwm E8gUfTRp1e1ji6HTIAXHOVUglTbFqek6v/TUyiMy1r47xN3WvURP/mSpZzE6WDSNl3Oc ipwjSwyJ9JJFRuvN6xD1Bi+Uta1t19KLF80T4/txCYRumrbnpq2QYrer4e6jVPT1lI7z d2og== 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=EF92eobcYswzOnj0cBEmpbroxKPlBmAfMb0V/T0t6pI=; fh=WSXgq+dxaJSHadwMDVBKq11PIkESctA8ND/ZfWAV8a0=; b=IbqpKa2GtMOq5qVVGlkfzp7y+5ILHxFWFm6BHfmc6Q5mEnLmdgQ5fl7htF5LvL3/Fi F1y5xMpDXYbI/Tl1okgj5yE0/onwdBXzLXrcfqi72NVLE0q/7RwO2DZs4uYXlmRZXij1 jsmaVqmcYnusFBacmIdmeCoDOO0DBBQV82v3D688kKCzvCNMhkHdd6Mn/8AMQEppc2Dj MHba9sJdecSQNFhWFuQFiKSoHw/ORLwz7J5t1WUbsvr0egjJyDmypbM6pJm/WAj30F5F RB8TGdS0KT55WcqDASxMUwRKzchgh600JaYSny+QJTulF2rHNpuWmiZKMg9yXWQUBG8J HD5Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p/+dm8m+"; 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-43ab2c44001si8730405e9.0.2025.02.25.08.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:18 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p/+dm8m+"; 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 8A2CF810F6; Tue, 25 Feb 2025 17:35:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="p/+dm8m+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8E7BC807EE; Tue, 25 Feb 2025 17:35:23 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-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 45F2980FC9 for ; Tue, 25 Feb 2025 17:35:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-38f1e8efe84so2214033f8f.1 for ; Tue, 25 Feb 2025 08:35:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501319; x=1741106119; 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=EF92eobcYswzOnj0cBEmpbroxKPlBmAfMb0V/T0t6pI=; b=p/+dm8m+sJiG7ZMXycbLsSgQeYZfw5boU0LTemW94YWzUbBpiDcDXFROqC5qmz12M/ WN4LD/Q7ASrPQjWL4/huenOynq1p+kJNWQYMmi4csbeLTfwwsQtFOfO6C542X/pX/bkz 1ADe2JRkyBvhJkZiVGLNjtNT9cPWZAveFfGfNjtQi/bkF+yVQQLsslhOZRwCJBfRek6k KMEnZztmE5/IXl2UNL5rj2tbgMXYkX2+GMHT7+eR3ZX3O+tTZn7Ab0Cj9fhbXU2nWUvM itLoRkhML6ZzYvhi/3oe8yQiiqNi+BOD6MTi02ieaAwP4HuDsNN+b5Rn4FNXCRJF0YB6 /NTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501319; x=1741106119; 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=EF92eobcYswzOnj0cBEmpbroxKPlBmAfMb0V/T0t6pI=; b=ioOCpl88CdMwKzzz2p7I2ILgqHtjj07dnflLZYk7ruvdxFDl107HipoQPEmqkPEnm6 1uXsFinFq78Wmiolx7fU9rboIFMG8z0Equ2nX7C2x8uNXs/DCCwvPgVIg/+8jPwouFG0 8K20UpE+diOouMF87sRvf/BwvWxsLs46MxE6NS09wxkD9pAVipNf5t1IJHkhGNLxzY7q Ol/pLiGyaXEIM4x53/7YlZd2DECOKU8P8pIIs3gaB3Ten2aCC3SgNjOF9xSaXN0h1ed3 tgQSvR1gGeyMPLWXG4sQPi22dMmqoRoA1TeRRcbhwg8E6frlkocmhWvis4ssNwk4gjAx d1KQ== X-Gm-Message-State: AOJu0YyXDCyja51dxMwUtz8w2FnpqZLZHA+T9SdR6JBF0XmTU1m0cbJV r7WunQ2vBjUew54pkLthI+GBy/8AQMK94Pdb3N85XJCXXtYiTGmuY0kztxJHsetUI5NzOoZ270d nWi9i7A== X-Gm-Gg: ASbGncvT+CMY4LkRNOL7JfIy7GYGac2cjdjumhezt57vvckTvfFj6XbGCLqlEdR+X/T 2s7wjcUlEDufjQXfgc/olcd5srT/FOWbnLkXuN9erKGnqmnmpPzfiK3HuhG6asqaupDbsbreASC cgl+Zvj9mojGjownYnKpztd1fFI1rPa15CxJ6IftDWJLIZ53jflpG0Igl248wlTIF8Sv+TMtXQ9 +8kSpMEHTR3gvko0LjBwQzauEudEMHFgkUHJJPkriUP/FUFkS7Ewr5za8KNZmcuDI9YNrkz8kAF Jriu+xKrSeoEvkNZ8LFXemqZ1xPJH6jHe3U= X-Received: by 2002:a5d:64ec:0:b0:38f:277a:4eb3 with SMTP id ffacd0b85a97d-38f6e74f38amr13406975f8f.8.1740501319496; Tue, 25 Feb 2025 08:35:19 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:19 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass Subject: [PATCH v2 08/14] lib: time: hook uthread_schedule() into udelay() Date: Tue, 25 Feb 2025 17:34:34 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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. While not strictly necessary since uthread_schedule() is already called by schedule(), tests show that it is desirable to call it in a tight loop instead of calling __usleep(). It gives more opportunities for other threads to make progress and results in better performances. Signed-off-by: Jerome Forissier --- lib/time.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/time.c b/lib/time.c index d88edafb196..d1a1a66f301 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,14 @@ void udelay(unsigned long usec) do { schedule(); kv = usec > CFG_WD_PERIOD ? CFG_WD_PERIOD : usec; - __udelay(kv); + if (CONFIG_IS_ENABLED(UTHREAD)) { + ulong t0 = timer_get_us(); + while (timer_get_us() < t0 + kv) + uthread_schedule(); + } else { + __udelay(kv); + } usec -= kv; } while(usec); + } From patchwork Tue Feb 25 16:34: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: 868121 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389081wrb; Tue, 25 Feb 2025 08:36:27 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVmr0BKGMFR1Cz+93e/Jt28wlNngE4Z0d7Okmskk+OhUa8a6l+vdGqsE4ztccsQ515E/1Sc2Q==@linaro.org X-Google-Smtp-Source: AGHT+IGK2SSBzoJrlxL+/slLaPDlKXbYnZWV904XQt3FzyA4tOpAfC7diXM7MbkWxgWf5WYOP8Ej X-Received: by 2002:a5d:5f53:0:b0:38f:2a99:b8e with SMTP id ffacd0b85a97d-38f6f3c50c8mr15004447f8f.4.1740501386907; Tue, 25 Feb 2025 08:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501386; cv=none; d=google.com; s=arc-20240605; b=Zw4yObiVsjD3TeW5jOPr4/mfQUGXNXdCMvt4vak1ZLzXErA8cXMD8XAQGQqq29eVo1 FIKjcA/5yDh+E5GtY/id8OYk1LQDQT94FSTJNloBENRODFLX2wHKzAm2t07/RZa4Tr/y jaZF11w5nc/uFyJKlvNGPliz9swVqdrO4UrL/SX/ZxsaBjUbRJzgyD6wxE28kAw3EIWs IWlrH3p9U3tQeOHaelEIhughJlEWG0cJKJ8hYMm8URoXyLP/WK+aGCEdxK/RMvbj0sWD BhOaaSJm+B9UN0ugNJ4LGM7sEfva1TS0uCs+u+vM6kdgTQPMWRjaiIDrOi4XvVmPpKDX QC+g== 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=g32Gn3NGNQSm88vcGRaPIMIYwfFfaWb2XPLHqfXE5po=; fh=rD2WloF8lyqDScUwGJNm6hnABsYqqpI5VuhdKoaStfw=; b=SZmhEXB3U67UORqLTbY0dl2vwro0MVX+/upNLVLdUQ1GJ6sBt6+z+cPlofsgGlzGDe LYDFmHO1k5vJVTpHI7ijot+XnktQGM2wN4FpFfKQ3ltqdcX6NmErGgzsOxc5EuhzsVxF PK0RgZaYQmGR//52SyVbWwzK/0xnsCoYTHO+HtGj63DEOvVevePkdIXJErKy6+1aj8Px 26d8gg5cYrusdGVWnFonQ5KBybd3KZD/CUo1e+seh1JyNjR4TzbHj8NgK6T9hgEkG5hG A8awKjnALnVdVW306KuKKc4UNJSoHF5Cva1y6/Ugqhm54pKlYO6UN8yDUFuFy/gYfG37 CkyA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F2cUOsGB; 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-390cd8fb411si1315154f8f.719.2025.02.25.08.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:26 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F2cUOsGB; 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 D9F5E810E5; Tue, 25 Feb 2025 17:35:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="F2cUOsGB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31BEE80FDE; Tue, 25 Feb 2025 17:35:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-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 0E54A80FED for ; Tue, 25 Feb 2025 17:35:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-439350f1a0bso35279225e9.0 for ; Tue, 25 Feb 2025 08:35:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501321; x=1741106121; 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=g32Gn3NGNQSm88vcGRaPIMIYwfFfaWb2XPLHqfXE5po=; b=F2cUOsGBmOvFwJebDSXU4UVT9hoAHY48+VZmpNMS+Q+cJdIiuG4N43Po6h1IvyfuY1 AWgmxoCa2Rc/1nVTbt+kSAsqzvFAryAE05G3BpAZSCjm/AqWwHBMlwfXZimsEq9wkKni SIMT/VVOchfARKPUqYKipDtbU6WQoHDGgzzkfTRr6W0YZVQ4NJ1Ry2mrRm7tSfdqCPPT Z5ZWTrd9QTLI9okJtVV4Hs0RPmzW1CcceqZrOyj8FgpNDCe7+2Cy299KFjFo80FgwpBm h9pUc0IkXi43TnXij1r0jKLNO3ShIHGSsPCoIBb8eTYHqBAed+yBbGE81VLb4o5u45gi odsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501321; x=1741106121; 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=g32Gn3NGNQSm88vcGRaPIMIYwfFfaWb2XPLHqfXE5po=; b=DrXY8KpsYYY5UqnSYqGAom8PcJckpTFQRjWnP8CZmEpXXK9TfWBjhaBJBvWHEfhx7d uR+pvEW+B9EVZdXe3juCMk9xwHdfQDnjO4fa2nYPKgpaPe/fp5QCWpp6wiun2JHnjLme me/Bq83LZzxgvgQrKmgfxYwTwi2sTV2YAvAEqm87LEn1Tqxjisbjiqr0eLK/EAVxa8QG ohwYMCNoei/GdjDNNj5JDjBp5wAabZr3re5aoGNT/8OBlbep5wFJ6PU/Lb2YxocvT02N fuyYvH2IVm79Bo6zDya32DU+BrE/TyQus92rQryr8RZeF3GYk6890OK5N84hQPRcGtQW u4qw== X-Gm-Message-State: AOJu0YyTotT0PQv2axuUBQ2VAJ5jcQkOsndclLiyIvd4K12Ci5wG1+yA P0VMJSI1fKWPt3I6fKuGRi6sx28g1wrzQo5fugKbTsplPk1AmnHxJveDAZPevm9ug3anHphA7CM CYjMGhg== X-Gm-Gg: ASbGnctWjru9ejt651KJ/qdf72LkgCEqtEmt6Cf6qPLjmF5Cu+3EdEBy0+pSXLJpvKl vpFoH5hs+zjnPf3HzstPwXTXpVMHrGPEoutleNRW32ODXrornLRcfgiGRDuWMNlWkzk17RPdbbs luvm9+FloUdhCKhHXqXqAe/c7cxJbK+hg2vaWUDbYoA+/qutf28xedQpHh8JiBrA+qTogUQ2PWX eIZq4LuUTewAnFsT32b+3HXksGI+oXdMwLx3W6ox+zCPrrkS7leuPT/QxWRGFh5YkIVMAo3n7nl huKSWeNqgnMaCN5uKadpsWtBGI2XTC2nXNU= X-Received: by 2002:a05:600c:6b66:b0:439:96a4:d2a8 with SMTP id 5b1f17b1804b1-439a2fb2c41mr162929195e9.5.1740501320917; Tue, 25 Feb 2025 08:35:20 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:20 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Mattijs Korpershoek , Alexander Dahl , Quentin Schulz Subject: [PATCH v2 09/14] doc: develop: add documentation for uthreads Date: Tue, 25 Feb 2025 17:34:35 +0100 Message-ID: <3160c00fe82fc3e627c5c03456f55501ad1ca111.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add documentation for the uthread framework. Signed-off-by: Jerome Forissier --- doc/develop/index.rst | 1 + doc/develop/uthread.rst | 136 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 doc/develop/uthread.rst diff --git a/doc/develop/index.rst b/doc/develop/index.rst index d9f2a838207..89c171c2089 100644 --- a/doc/develop/index.rst +++ b/doc/develop/index.rst @@ -53,6 +53,7 @@ Implementation spl falcon uefi/index + uthread vbe version diff --git a/doc/develop/uthread.rst b/doc/develop/uthread.rst new file mode 100644 index 00000000000..a7dc48ebc9c --- /dev/null +++ b/doc/develop/uthread.rst @@ -0,0 +1,136 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. (C) Copyright 2025 Linaro Limited + +Uthread Framework +================= + +Introduction +------------ + +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. See details below. + +Function description +-------------------- + +See `lib/uthread.c`. + +Usage +----- + +This section shows how uthreads may be used to convert sequential code +into parallel code. Error handling is omitted for brevity. +Consider the following: + +.. code-block:: C + + static void init_foo(void) + { + start_foo(); + while (!foo_is_ready()) + udelay(10); + } + + static void init_bar(void) + { + start_bar(); + while (!bar_is_ready()) + udelay(10); + } + + void init_foo_bar(void) + { + init_foo(); + init_bar(); + } + +This example is a simplified version of typical device initialization, where +some commands are sent to a device and the CPU needs to wait for the device +to reply or change state after wich the device is known to be ready. +Assuming devices 'foo' and 'bar' are independant, and assuming they both take +some significant amount of time to initialize, then the above code is clearly +suboptimal because device 'bar' is started only after 'foo' is ready, although +it could have been started at the same time. Therefore a better version would +be: + +.. code-block:: C + + void init_foo_bar(void) + { + start_foo(); + start_bar(); + while (!foo_is_ready() || !bar_is_ready()) + udelay(10); + } + + +Unfortunately, refactoring the code like that is rarely so easy because +init_foo() and init_bar() would in reality involve dozens of functions +and result in deep call stacks. This is where uthreads are helpful. Here is +how. + +.. code-block:: C + + /* Unchanged */ + static void init_foo(void) + { + start_foo(); + while (!foo_is_ready()) + udelay(10); + } + + /* Unchanged */ + static void init_bar(void) + { + start_bar(); + while (!bar_is_ready()) + udelay(10); + } + + /* Added only because init_foo() does not take a (void *) */ + static void do_init_foo(void *arg) + { + init_foo(); + } + + /* Added only because init_bar() does not take a (void *) */ + static void do_init_bar(void *arg) + { + init_bar(); + } + + void init_foo_bar(void) + { + int id; + + /* Allocate a thread group ID (optional) */ + id = uthread_grp_new_id(); + /* Create and start two threads */ + uthread_create(do_init_foo, NULL, 0, id); + uthread_create(do_init_bar, NULL, 0, id); + /* Wait until both threads are done */ + while (!uthread_grp_done(id)) + uthread_schedule(); + } + +When `CONFIG_UTHREAD` is enabled, do_init_foo() is started and quickly yields +the CPU back to the main thread due to udelay() calling uthread_schedule(). +Then do_init_bar() is started and it also calls udelay(), which in turn calls +uthread_schedule(). With the main thread entering the scheduling loop, we +effectively have three tasks scheduled in a round-robin fashion until +do_init_foo() and do_init_bar() are both done. + +when `CONFIG_UTHREAD` is disabled, uthread_grp_new_id() always returns 0, +uthread_create() simply calls its first argument, uthread_grp_done() always +returns true and uthread_schedule() does nothing. In this case, the code is +functionally equivalent to the sequential version. From patchwork Tue Feb 25 16:34: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: 868122 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389140wrb; Tue, 25 Feb 2025 08:36:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVsDctE8f34LNgrwh/vVlzEB994p+/oQ4HZuL5aMxLuuGfn5pUBYhtf6oiJiJmWc6+hB0qacg==@linaro.org X-Google-Smtp-Source: AGHT+IHSBZEuDVns9VEhQiPOB650MV9kDGDyLQn8h89NuoAVMZX70KJcMtLw3iVDdDxY1vWqffN6 X-Received: by 2002:a5d:47a6:0:b0:38f:3a89:fdae with SMTP id ffacd0b85a97d-38f70859ee3mr13622636f8f.46.1740501395441; Tue, 25 Feb 2025 08:36:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501395; cv=none; d=google.com; s=arc-20240605; b=Wbi/42hww4AjG2V8N7wpVn8xtSwfgndlLhrCQRZZzTKRQzKubnFV/S5Q+xY74usiib 03mhkUgMaHTpbBdUhB1YUTPqMFpmkGU3V7Uz02sCfmI4jvL9ynjskim8CZ7KsvkTao0H eYyI6abUnEjC8jzHNZd+oBzfz7OLWatbSSYO9+wVlXgBD/IlmG6fAZu1Y6aeoqGg2k6j nPI5F0FHmwCZky9VHtFLOm8eBvC8NbslfTtmF7b4IPt067QVARSxD8O80yA9hgwyJIWD RwQRc+iUBNea9cQab57JuoHhc3mbrAl2h6otT1CyUe0d3QAmGbeynlzcPtln6lB15E6J DuiQ== 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=MSvBrHsgKEvlZcp51TYx/CfxU1FN8m2sCk/LzFjOfQg=; fh=Jew6Njx5SZzV76Z+XfelCXw/h2sdJWu6FVVJm8KM3pI=; b=QYWoN9iTth0GmhEwCvvUxY91BaLJyfvZA4d6KKqMzmqQXTIwfyL56Ud5iy9XOaZ8E+ p8fQ7WHWoN25ZFt8yY5unGslEndkcH1ZGm/OvQwMkWZDiRXlbX5lz26Kb5Jp+8zpnAxt FsCFDaTXluRrEMs5e19I5WDi2Uhd3KqZTwYnlVDGTJNvA06emtJut+iOR7qMqSGhifa/ OyoKPeVG6Lq2Z8ZbRdzHDI4x0iG/gdvkDFepxRif+BHhK2oRrqFSk39dVGFkm7MPCgV+ puHKapPcpHLoCOaV8JFlw/yN0Gd/qe/lWGxS9tQLEIOJgUkt04r9bfeOiUfSSHv8dLzN T1yQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JUBnXKQg; 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-390cd8e6521si1302593f8f.510.2025.02.25.08.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JUBnXKQg; 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 3A8698104B; Tue, 25 Feb 2025 17:35:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JUBnXKQg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D98FA810F1; Tue, 25 Feb 2025 17:35:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-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 D8DA78104B for ; Tue, 25 Feb 2025 17:35:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-439ac3216dcso34660075e9.1 for ; Tue, 25 Feb 2025 08:35:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501322; x=1741106122; 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=MSvBrHsgKEvlZcp51TYx/CfxU1FN8m2sCk/LzFjOfQg=; b=JUBnXKQgFO6E6wE2S5QBrGSEtwdEVCxPDY4m/xZzTnCZ4Ix4/2XDJKvp9V0E3p1dhR 3rPVLa2m/FVacw0p9o1/1T4/pIizJhMfSXtlBSIIGJ1pLDwP/HkGvyrP+sLsLOfXPLba czFRSN4YuTbIYT9vQwKQ79fZ3IuhNPzwqlzs2OGJEW6wbwSJY7H0I21KWsViFwVQro14 sQ/YM8kIZqwVtY09yvYAOLWOzkzN9tfWHaKNe9pFqYZatJ1oEAHzsVOCch9A06W+8SgC pR3aI8roXWQ6v8awtVmpIzr/DhOVSrVJOkp3wHG4rFjTLU1izaFWkd62boAlQo67FcK8 rjtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501322; x=1741106122; 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=MSvBrHsgKEvlZcp51TYx/CfxU1FN8m2sCk/LzFjOfQg=; b=rkAdu1WpcpAnrPLhTtu8BrPDo6+vTuLxrvjHKGVqktuyFyKBdLTMM6UpNTM6lz++Pa D8QdQL8k1xT9a3rWwhiinuN6pwDvKsjOqOxs//jgPPyW1Fj/jA3EMslnPIH5/TKMYT3Q 2l/QRZgIaAby1OUZOU6vz1P/79q2BoQaQ3K4bQMd1Im+r93ST+iPFmLR7/Z6BuWhq+RX cw6MO7w5tknPILvTot2QnUzGksNnTWPwe12kD51DdrlaHQBUs1AbOyhj1SjEKA+bHAmG WO7BghuiUnBheEVTm4ODZOfyQB+ylPygceViUes9Kb8cXesaaqTSD9NrOBS44nz6j4hA TWQw== X-Gm-Message-State: AOJu0Ywcw6/KfHcODZGXeWh4qmxXsXQPKKaLL1SGWdkYQb/VQke7HOy+ y7BZjkGg/XizVOlH+AsAlX4+6SK6bJTd7emhmOixCeS98OoXIFHtukH/FGElydCWPt7HaNxMZgk 6crCIqA== X-Gm-Gg: ASbGncv6i2+PL07hFw5lASxOG8rNYnFo/k0o3JNxbmJuDRNpeFazTVGgj5SP2W1Rqwk CCxbw2jIzwf1YdLioV445emcBFkEVd2ZrK1+9k53WRwqdQjpdVJdd0audkG2QSoPoR0WiGUNzGv HCbXVdwx12Z2hXEIKuGyF7B0I5SLBtqtAjYFlzCP1iNT9GGM4TSqWRcH7fSqKupefdboz/IGzt2 +aTyC5ZgvFaP53VfKWjBU2fpdtZx0Fe2PC5Y3rHuqAzAEvYvunJGSKyU2fI54m1lheQfk/4i9vi +5w+d7F03LfivcPf+iUif6A7oLmM+xnRm6g= X-Received: by 2002:a05:600c:1906:b0:439:9c0e:3709 with SMTP id 5b1f17b1804b1-439aeafab74mr127407795e9.8.1740501322187; Tue, 25 Feb 2025 08:35:22 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:21 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Raymond Mao , Philippe Reynes Subject: [PATCH v2 10/14] test: lib: add uthread test Date: Tue, 25 Feb 2025 17:34:36 +0100 Message-ID: <17ec7e3f553fa8c36c19d2cbf4cc0e6d03c7e443.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add a uhread framework test to the lib tests. Signed-off-by: Jerome Forissier --- test/lib/Makefile | 1 + test/lib/uthread.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 test/lib/uthread.c diff --git a/test/lib/Makefile b/test/lib/Makefile index bf04685dae1..c991dff1c63 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_CRC8) += test_crc8.o obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o obj-$(CONFIG_UT_TIME) += time.o obj-$(CONFIG_$(XPL_)UT_UNICODE) += unicode.o +obj-$(CONFIG_UTHREAD) += uthread.o obj-$(CONFIG_LIB_UUID) += uuid.o else obj-$(CONFIG_SANDBOX) += kconfig_spl.o diff --git a/test/lib/uthread.c b/test/lib/uthread.c new file mode 100644 index 00000000000..84c41d35875 --- /dev/null +++ b/test/lib/uthread.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2025 Linaro Limited + * + * Unit test for uthread + */ + +#include +#include +#include +#include + +static int count; + +static void worker(void *arg) +{ + int loops = (int)(unsigned long)arg; + int i; + + for (i = 0; i < loops; i++) { + count++; + uthread_schedule(); + } +} + +static int lib_uthread(struct unit_test_state *uts) +{ + int i; + int id1, id2; + + count = 0; + id1 = uthread_grp_new_id(); + ut_assert(id1 != 0); + id2 = uthread_grp_new_id(); + ut_assert(id2 != 0); + ut_assert(id1 != id2); + ut_assertok(uthread_create(worker, (void *)5, 0, id1)); + ut_assertok(uthread_create(worker, (void *)10, 0, 0)); + /* + * The first call is expected to schedule the first worker, which will + * schedule the second one, which will schedule back to the main thread + * (here). Therefore count should be 2. + */ + ut_assert(uthread_schedule()); + ut_asserteq(2, count); + ut_assert(!uthread_grp_done(id1)); + /* Four more calls should bring the count to 10 */ + for (i = 0; i < 4; i++) { + ut_assert(!uthread_grp_done(id1)); + ut_assert(uthread_schedule()); + } + ut_asserteq(10, count); + /* This one allows the first worker to exit */ + ut_assert(uthread_schedule()); + /* At this point there should be no runnable thread in group 'id1' */ + ut_assert(uthread_grp_done(id1)); + /* Five more calls for the second worker to finish incrementing */ + for (i = 0; i < 5; i++) + ut_assert(uthread_schedule()); + ut_asserteq(15, count); + /* Plus one call to let the second worker return from its entry point */ + ut_assert(uthread_schedule()); + /* Now both tasks should be done, schedule should return false */ + ut_assert(!uthread_schedule()); + + return 0; +} +LIB_TEST(lib_uthread, 0); From patchwork Tue Feb 25 16:34: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: 868123 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389195wrb; Tue, 25 Feb 2025 08:36:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWWTIZwWeTNU+pnGF1yWCZXQP1hspmrMUchmjvnNc2hbBD5UtJBlmQkhzZoGnhwvzX/FcahCA==@linaro.org X-Google-Smtp-Source: AGHT+IHxyxCbJjihyKN7kmN4h/bNJ8o3nV/m1N04s4NzjllNmnbxboEyL3ZrABwrKS+oyhLIsR5j X-Received: by 2002:a05:6000:1a85:b0:38d:d759:3dea with SMTP id ffacd0b85a97d-38f707a6294mr12529948f8f.26.1740501403571; Tue, 25 Feb 2025 08:36:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501403; cv=none; d=google.com; s=arc-20240605; b=VYIgWBkpFP+JQvpdILshsn3EFi6jLg2bHECqC7dRbosXcXLkh5JefO4H9Eeq1YgakW 0cuRpwuqZfNlzelSkZyO74QSK0PxJ7Po8yJBa6msoWpalstory5yh3SJGU8ZZgrY4kC0 wv8zDGyBnX9cpMcZMe3QdYtoFVd7CLj/CxUy8zss3L/zJJ8Q6Q6IYqVKn5W0Y2NspUmC 31LIwZ8r2VKiVdbM8SEJYwuXG/nhvj2t7hds74woYU0NjITYjSNBu0eOYsU28RIw0tpb JCOvgCJFkrPeMu07e1uqWfPk340mUfk13TUK5oAIzD9VPEnkP0vehQImtLcIG8WOfem/ 6Xzw== 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=Utnn1RiTgA8y5KAA6XU2ZUyWE7GhPINWCZVBuQFSuLE=; fh=FmJyaWVIWZ4tSwb3Wmmxs1hTruvF06+FB0F30LttTwA=; b=inKKkLDkEEOvsNHEOmNoUdYPbDfZ61kCLGcvuVEhG01ddsnVei5oByZonqNYqn77q6 1X+tGkRqiWlRwTULqX+Z0UeFMOtUV1CSxIBXfEZkYMCdQR6x2azdcyn89DYz1lmyid/O T4BqS+VPzgQA+fwMKYOuic95uqI/B2uq0jwWBbQX7UDaowm5rlPxP+EXt34XaK5GTM+u umy1XHHJ9S1PJwcSxPyGqiYlxQFiv45ihOWU/3535phVtqLqq/Y6EdWc1UJKwCZRcm75 9BfrG4oHmRlSWSHYgIERUTTRI5oxwXxzGKwYSY4QQxtD44GgqvLaKEzO3iBpzb8pnD0T 9PxA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PFuV/IRL"; 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-390cd867330si1396579f8f.1.2025.02.25.08.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:43 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PFuV/IRL"; 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 90F77810E6; Tue, 25 Feb 2025 17:35:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="PFuV/IRL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3CAC7810E6; Tue, 25 Feb 2025 17:35:28 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-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 8FA40810F1 for ; Tue, 25 Feb 2025 17:35:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43996e95114so38765405e9.3 for ; Tue, 25 Feb 2025 08:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501323; x=1741106123; 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=Utnn1RiTgA8y5KAA6XU2ZUyWE7GhPINWCZVBuQFSuLE=; b=PFuV/IRLkPmJFjMsiRwGj2Wy13Imtxgn7p5bFel0H56TSUF+CUPzPIUq1mtVTQ69Rq LERyLT9zIPh/ektjAXPmGiOUURt6oA9NogvziweE8CkiR2U4jluU2q4+1cUIAbPOiyrG 4hix4ra1UE6xUQYsqiLM5BlzRvDi0URmLzxyKwDBuS01NtZSEvu6jxsOnUyXwnS5SnrW IYXGM0iIXVdMAQq2SUfq9e7dMBFsNhEhzKuAOfgY/Ymis43WrioQu72mxrvLAVkScf2s ht+1NyR4qs3QQzHRyAp5yR87OXQr2oIkCmw/N2pfEAr98uZZzIbIjNBr3zC4Xo5xv4hj LpYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501323; x=1741106123; 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=Utnn1RiTgA8y5KAA6XU2ZUyWE7GhPINWCZVBuQFSuLE=; b=RW1Fz5NhHig2tHv00BeiHTCtvPOkNLY9eeEg4FaiPdDGk+0TtJFMyqTNuDwAOuIhLG Alv48e5STX0babt0gpSx1ZNZ403uZqtUXvs4ztIFPLvMrg3aKz+ArR1gbDJKWGzPbFHv 9LvzkDOlDzxkLLhfT0dw/hBbxNWBt3Q/Qn1f9cG3ZL80pLVDPNtpldZhIJEKxr+am+YN YenM6RF0+n/dgptZc4HXuBqpsleKl4IBe/XP8mykQoJDruUT2uK6m1s0oydCne63xFJJ DJ4VBHe0f7ZvHhNd69p+YmRV0s5ivC7KsoYJ0Suk1qhJXhGGXAZ6rgYxGF6xRnKdRg6/ mGNA== X-Gm-Message-State: AOJu0Yyq1IBU9lGj8BIaHg4/CP+PgyLQKuGag49h9j/iuGZ/ksB+19Zr zEgjB3/goSeTMNHMa+H0pHKpUWSO9Qhe7uE5Gvg4kFDnN4EkOkgCJT0Fmglpq3XvTqNtxeg84Jg TLD3b2w== X-Gm-Gg: ASbGnctABmyknsX2G7h3lGDnutv9lHwo2V0ttPA7GzbuK6ysgDkCHAW+h7OKQoabRNA OD9XDnBO04OsA7lD4tu6lGTOT5HtAohWkmSemu313eqfwPxv+cz5cjPWF761e6wcvuvIINmMaMq Q99RAwYGR62+wAEFjWKsJ62aVu+OGVOd7N4x8YEcRfCK2DiTcUAf8L0O+2X+MPBOpUO/ZEsiSt4 Ib8RpBtwjT+k6FWvQNWYFHafArUncykzgdueeiu+b9xFnTfJ3hQfA8mxVM44Abt+NthB+2vqVEN ka7KrvzrPvj7cgpWRsvtMqDWKZgLCH2o4D8= X-Received: by 2002:a05:600c:4fcf:b0:439:5a37:8157 with SMTP id 5b1f17b1804b1-439aebf3613mr182200815e9.30.1740501323014; Tue, 25 Feb 2025 08:35:23 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:22 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Mattijs Korpershoek , Heinrich Schuchardt , Caleb Connolly , Dragan Simic Subject: [PATCH v2 11/14] dm: usb: move bus initialization into new static function usb_init_bus() Date: Tue, 25 Feb 2025 17:34:37 +0100 Message-ID: <251fb41d13189f475f606a6fdffc764997ee8d61.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean To prepare for the introduction of coroutines in the USB initialization sequence, move code out of usb_init() into a new helper function: usb_init_bus(). No functional change. Signed-off-by: Jerome Forissier --- drivers/usb/host/usb-uclass.c | 88 +++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..cc803241461 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -287,9 +287,55 @@ static int usb_probe_companion(struct udevice *bus) return 0; } +static int controllers_initialized; + +static void usb_init_bus(struct udevice *bus) +{ + int ret; + + /* init low_level USB */ + printf("Bus %s: ", bus->name); + + /* + * For Sandbox, we need scan the device tree each time when we + * start the USB stack, in order to re-create the emulated USB + * devices and bind drivers for them before we actually do the + * driver probe. + * + * For USB onboard HUB, we need to do some non-trivial init + * like enabling a power regulator, before enumeration. + */ + if (IS_ENABLED(CONFIG_SANDBOX) || + IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { + ret = dm_scan_fdt_dev(bus); + if (ret) { + printf("USB device scan from fdt failed (%d)", ret); + return; + } + } + + ret = device_probe(bus); + if (ret == -ENODEV) { /* No such device. */ + puts("Port not available.\n"); + controllers_initialized++; + return; + } + + if (ret) { /* Other error. */ + printf("probe failed, error %d\n", ret); + return; + } + + ret = usb_probe_companion(bus); + if (ret) + return; + + controllers_initialized++; + usb_started = true; +} + int usb_init(void) { - int controllers_initialized = 0; struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -305,45 +351,7 @@ int usb_init(void) uc_priv = uclass_get_priv(uc); uclass_foreach_dev(bus, uc) { - /* init low_level USB */ - printf("Bus %s: ", bus->name); - - /* - * For Sandbox, we need scan the device tree each time when we - * start the USB stack, in order to re-create the emulated USB - * devices and bind drivers for them before we actually do the - * driver probe. - * - * For USB onboard HUB, we need to do some non-trivial init - * like enabling a power regulator, before enumeration. - */ - if (IS_ENABLED(CONFIG_SANDBOX) || - IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { - ret = dm_scan_fdt_dev(bus); - if (ret) { - printf("USB device scan from fdt failed (%d)", ret); - continue; - } - } - - ret = device_probe(bus); - if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); - controllers_initialized++; - continue; - } - - if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); - continue; - } - - ret = usb_probe_companion(bus); - if (ret) - continue; - - controllers_initialized++; - usb_started = true; + usb_init_bus(bus); } /* From patchwork Tue Feb 25 16:34: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: 868124 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389244wrb; Tue, 25 Feb 2025 08:36:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCURXAmtq89P703gPHrVmvPGnOQKdbzHqOqJSJunbHCfd93EXwy4Z3UeB//TLt7bTaf/S70JQQ==@linaro.org X-Google-Smtp-Source: AGHT+IG4bNXEo4Up/oZL1Bwr2bPgHjmSjvq1yS9VW2PImrokMp0pvXDEXI0hJHf5iuS4xj+7ObiE X-Received: by 2002:a05:6000:178e:b0:38f:3ee0:7026 with SMTP id ffacd0b85a97d-390cc605060mr3863758f8f.22.1740501411897; Tue, 25 Feb 2025 08:36:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501411; cv=none; d=google.com; s=arc-20240605; b=I4QKs81pba1oBTLw0Mh/2riqfyqPT8AjEMs4xhUydJK7IJO86E24M6Ph44Js2sR0Os wsm8fowauEl9gSAt7RWmOxtcBmALSerU7qAN7pv1GkGdCfzh5cZKFKrHAlLUN8HW5WAY Zfcy0WKC8Zcxm9kqSP2kspvApt6t0POrKOBJWFMewFNTGfj7EgYJ7ET/HvHJitg3Z2PV JnOdYQhWeXPu8nbadxv7QfKJIgYnMBfK4y4Iq/4p2yN7Efp83N/S/BbR3NjvjM+s1mgk FJrB24K4mgQdqMNy5SA5yd4UosVUhPE22p+pFIAuBvuwJyysEMZM/8LGMhB+NZPm6ug4 HX1Q== 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=lKi5CiaP4bYuxUMWeEgSFr2W4q8ZWngEoO4IH1DIzEY=; fh=Xs0fewSlue7xKmVnt+Oj13Za3tqIWt1LKA/DWV0de2M=; b=hDaBxEneiv2P8VcSTZ/1wHyppi/zsda0evMOhII5K5TFn6fl+pG3+2KIt1YLGvIjol UZilYFjimS4ezYkM15dQBgD+7rXk4NHsPol03aJLOdF4/MnBRJY2v+08nVglAgoQzlLA XF5l7fPqei9WpHRe5to1EjT/UXKsbWG6Jly8rEmO0JPQg3SoqfEsyt5hXeILVk5sLUMu dXekw7yXpqtcK6vLwUijU2ZcZDyY7k/HaPCp9nis22PrHh4bTOYzXSqBVgT0cSFSvRWe JwtKkDSK1RcAEBjPH/cqh8Iqxmam5bN7uL55gfDmYalGHHs4rSMmgYBYxXNozv2B4PJm 4aHQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y43jElFD; 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-43ab14fb464si14337595e9.33.2025.02.25.08.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:36:51 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y43jElFD; 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 DD65D810F1; Tue, 25 Feb 2025 17:35:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=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="y43jElFD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 51F53810F2; Tue, 25 Feb 2025 17:35:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (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 7DC74807EE for ; Tue, 25 Feb 2025 17:35:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4394a0c65fcso59247345e9.1 for ; Tue, 25 Feb 2025 08:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501326; x=1741106126; 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=lKi5CiaP4bYuxUMWeEgSFr2W4q8ZWngEoO4IH1DIzEY=; b=y43jElFDMUkDEFvgsKjTW40XP7RvjMlkHGQzmXnldirySeoV6k0JBo1EdptsjO3NE/ FGCARtPpWKHl0daG8U8Vl4hRcPhGgfs9eUt6yRk6JXWhlmHRyCU1lyKnqnFoaXjhGYSx IMVyqglH1AQfWPEUU0QxoEYyRDjxRY4z1jByBBKSIGSaZB5LYkRWhiDVEfXL8HgcN5Z5 inVkbukWkDcijJoDUKdmrgKumU+sRdeCI6ZYufRRokPtk19yWR7KBf7qNipjBJ2NiYL1 1Lt4USNikWPwIn1N+BDglKs2blmtFqVAlE0T1v93FN2VuM8r9TWArjvkltPnrAKGwagn YLyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501326; x=1741106126; 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=lKi5CiaP4bYuxUMWeEgSFr2W4q8ZWngEoO4IH1DIzEY=; b=o4BbiCbNNvy59dI4/8JRb9ctYyCargA4I/POo7h971LTLC8fo2OcY4sGEPr/CgaqUg MkJEmOXOMDQWtliixgEP4/+NRtFLQrBiu1fJJmuvQ7gUE8pITbGNJCmfVUMdAcVlgOR0 0tZz3CLkcrO188bMopx808Yrxn0agGVhydtKdjwBC2OMek63sjLVBoomLu+vnnm6U+aW Ridcaf6XIhDoanCtg7tMXW/1bjJtrpRrknlc1hWQDmSt1nA8olh2PAczPTu/o189VjAf ow/CL8uGGfncSQSv/etibvqbQ/tn2b5SK9bgSJNzAZ4n0DvI9S996IGW4XDPuMLIUKh6 cdLQ== X-Gm-Message-State: AOJu0Yzflv6wWw7bwzBCOWgLu+Rx4YvSLneYH07KuP1OyADrzH0QUgF0 gvOwipD988grY2IstDGubAPgsIfuNuwDceBmlPppKXxjaWahXFTRzibJXRiKe2ZtS2AWxLMp7ji Rj7Hveg== X-Gm-Gg: ASbGncsGV1jKDh42cX9xQYt1o/1EDCsMVNtI1hiSoL59NoSiK/mxCz4JF+vd+GkOtIt dT/3f4mSBh0sYaOYnYxtxo9mTMo2UXmDrOhuQsETp9Sxfzjnit4KSL+v84I2bCsVBeBeNPh/9Vu ttJZ2K6wtn1hpWNi6/eqKSSG4ZwjOlaeYt3mG7M9+fI6N2DyQLqIBunLRYipsdOi8GS7WK0gUdV OkJLb62oljtyJdj38c3aCnGxAYpJIVPUVoaIfCkUS+Y6nCr3QAXJXs5ZZqxIjpLaY6kjhtYwXfh aFMHvKLYV68YY/xjyN3b+RwcQERtDZzu0z4= X-Received: by 2002:a05:600c:a01:b0:439:9424:1b70 with SMTP id 5b1f17b1804b1-43ab0f6fd2amr51634915e9.30.1740501325641; Tue, 25 Feb 2025 08:35:25 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:23 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Marek Vasut , Tom Rini , Simon Glass , Mattijs Korpershoek , Heinrich Schuchardt , Caleb Connolly , Julius Lehmann , Guillaume La Roque Subject: [PATCH v2 12/14] dm: usb: initialize and scan multiple buses simultaneously with uthread Date: Tue, 25 Feb 2025 17:34:38 +0100 Message-ID: <03a5c263b0449b397ca280d5d22bebf1d5496687.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Use the uthread framework to initialize and scan USB buses in parallel for better performance. The console output is slightly modified with a final per-bus report of the number of devices found, common to UTHREAD and !UTHREAD. The USB tests are updated accordingly. Tested on two platforms: 1. arm64 QEMU on a somewhat contrived example (4 USB buses, each with one audio device, one keyboard, one mouse and one tablet) $ make qemu_arm64_defconfig $ make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-" $ qemu-system-aarch64 -M virt -nographic -cpu max -bios u-boot.bin \ $(for i in {1..4}; do echo -device qemu-xhci,id=xhci$i \ -device\ usb-{audio,kbd,mouse,tablet},bus=xhci$i.0; \ done) 2. i.MX93 EVK (imx93_11x11_evk_defconfig) with two USB hubs, each with one webcam and one ethernet adapter, resulting in the following device tree: USB device tree: 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 100mA) | GenesysLogic USB2.1 Hub | +-3 Vendor specific (480 Mb/s, 350mA) | Realtek USB 10/100/1000 LAN 001000001 | +-4 (480 Mb/s, 500mA) HD Pro Webcam C920 8F7CD51F 1 Hub (480 Mb/s, 0mA) | u-boot EHCI Host Controller | +-2 Hub (480 Mb/s, 100mA) | USB 2.0 Hub | +-3 Vendor specific (480 Mb/s, 200mA) | Realtek USB 10/100/1000 LAN 000001 | +-4 (480 Mb/s, 500mA) Generic OnLan-CS30 201801010008 Note that i.MX was tested on top of the downstream repository [1] since USB doesn't work in the upstream master branch. [1] https://github.com/nxp-imx/uboot-imx/tree/lf-6.6.52-2.2.0 commit 6c4545203d12 ("LF-13928 update key for capsule") The time spent in usb_init() ("usb start" command) is reported on the console. Here are the results: | CONFIG_UTHREAD=n | CONFIG_UTHREAD=y --------+------------------+----------------- QEMU | 5628 ms | 2212 ms i.MX93 | 4591 ms | 2441 ms Signed-off-by: Jerome Forissier --- drivers/usb/host/usb-uclass.c | 92 ++++++++++++++++++++++++++++------- test/boot/bootdev.c | 14 +++--- test/boot/bootflow.c | 2 +- 3 files changed, 83 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index cc803241461..27c7aaee2b4 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -9,6 +9,7 @@ #define LOG_CATEGORY UCLASS_USB #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include static bool asynch_allowed; @@ -221,25 +223,18 @@ int usb_stop(void) return err; } -static void usb_scan_bus(struct udevice *bus, bool recurse) +static void _usb_scan_bus(void *arg) { + struct udevice *bus = (struct udevice *)arg; struct usb_bus_priv *priv; struct udevice *dev; int ret; priv = dev_get_uclass_priv(bus); - assert(recurse); /* TODO: Support non-recusive */ - - printf("scanning bus %s for devices... ", bus->name); - debug("\n"); ret = usb_scan_device(bus, 0, USB_SPEED_FULL, &dev); if (ret) - printf("failed, error %d\n", ret); - else if (priv->next_addr == 0) - printf("No USB Device found\n"); - else - printf("%d USB Device(s) found\n", priv->next_addr); + printf("Scanning bus %s failed, error %d\n", bus->name, ret); } static void remove_inactive_children(struct uclass *uc, struct udevice *bus) @@ -289,12 +284,12 @@ static int usb_probe_companion(struct udevice *bus) static int controllers_initialized; -static void usb_init_bus(struct udevice *bus) +static void _usb_init_bus(void *arg) { + struct udevice *bus = (struct udevice *)arg; int ret; /* init low_level USB */ - printf("Bus %s: ", bus->name); /* * For Sandbox, we need scan the device tree each time when we @@ -309,33 +304,84 @@ static void usb_init_bus(struct udevice *bus) IS_ENABLED(CONFIG_USB_ONBOARD_HUB)) { ret = dm_scan_fdt_dev(bus); if (ret) { - printf("USB device scan from fdt failed (%d)", ret); + printf("Bus %s: USB device scan from fdt failed (%d)\n", + bus->name, ret); return; } } ret = device_probe(bus); if (ret == -ENODEV) { /* No such device. */ - puts("Port not available.\n"); + printf("Bus %s: Port not available.\n", bus->name); controllers_initialized++; return; } if (ret) { /* Other error. */ - printf("probe failed, error %d\n", ret); + printf("Bus %s: probe failed, error %d\n", bus->name, ret); return; } ret = usb_probe_companion(bus); - if (ret) + if (ret) { return; + } controllers_initialized++; usb_started = true; } +static int nthr; +static int grp_id; + +static void usb_init_bus(struct udevice *bus) +{ + if (!grp_id) + grp_id = uthread_grp_new_id(); + if (!uthread_create(_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(_usb_scan_bus, (void *)bus, 0, grp_id)) + nthr++; +} + +static void usb_report_devices(struct uclass *uc) +{ + struct usb_bus_priv *priv; + struct udevice *bus; + + uclass_foreach_dev(bus, uc) { + if (!device_active(bus)) + continue; + priv = dev_get_uclass_priv(bus); + printf("Bus %s: ", bus->name); + if (priv->next_addr == 0) + printf("No USB Device found\n"); + else + printf("%d USB Device(s) found\n", priv->next_addr); + } +} + +static void run_threads(void) +{ +#if CONFIG_IS_ENABLED(UTHREAD) + if (!nthr) + return; + while (!uthread_grp_done(grp_id)) + uthread_schedule(); + nthr = 0; + grp_id = 0; +#endif +} + int usb_init(void) { + unsigned long t0 = timer_get_us(); struct usb_uclass_priv *uc_priv; struct usb_bus_priv *priv; struct udevice *bus; @@ -354,6 +400,9 @@ int usb_init(void) usb_init_bus(bus); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + /* * lowlevel init done, now scan the bus for devices i.e. search HUBs * and configure them, first scan primary controllers. @@ -367,6 +416,9 @@ int usb_init(void) usb_scan_bus(bus, true); } + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + /* * Now that the primary controllers have been scanned and have handed * over any devices they do not understand to their companions, scan @@ -383,7 +435,10 @@ int usb_init(void) } } - debug("scan end\n"); + if (CONFIG_IS_ENABLED(UTHREAD)) + run_threads(); + + usb_report_devices(uc); /* Remove any devices that were not found on this scan */ remove_inactive_children(uc, bus); @@ -397,6 +452,9 @@ int usb_init(void) if (controllers_initialized == 0) printf("No USB controllers found\n"); + debug("USB initialized in %ld ms\n", + (timer_get_us() - t0) / 1000); + return usb_started ? 0 : -ENOENT; } diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 5f07430714e..70a1d868de8 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -392,8 +392,8 @@ static int bootdev_test_hunter(struct unit_test_state *uts) ut_assert_console_end(); ut_assertok(bootdev_hunt("usb1", false)); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); /* USB is 7th in the list, so bit 8 */ @@ -448,8 +448,8 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextline("scanning bus for devices..."); ut_assert_skip_to_line("Hunting with: spi_flash"); ut_assert_nextline("Hunting with: usb"); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_nextline("Hunting with: virtio"); ut_assert_console_end(); @@ -550,8 +550,8 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts) ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); ut_assert_nextline("Hunting with: ide"); ut_assert_nextline("Hunting with: usb"); - ut_assert_nextline( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + ut_assert_skip_to_line( + "Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); return 0; @@ -603,7 +603,7 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts) ut_assertnonnull(dev); ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); - ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); + ut_assert_nextline("Bus usb@1: 5 USB Device(s) found"); ut_assert_console_end(); return 0; diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index eb7f00af39a..699ba0edaaf 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1289,7 +1289,7 @@ static int bootflow_efi(struct unit_test_state *uts) ut_assertok(run_command("bootflow scan", 0)); ut_assert_skip_to_line( - "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); + "Bus usb@1: 5 USB Device(s) found"); ut_assertok(run_command("bootflow list", 0)); From patchwork Tue Feb 25 16:34: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: 868125 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389303wrb; Tue, 25 Feb 2025 08:37:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUUl5kpUPXmEWI+DDrGSWZatCP9GeljV7F/zN6x/IdzOv1llu5/zm01odxQLXGhgoJ+vCEIYw==@linaro.org X-Google-Smtp-Source: AGHT+IF4Iz5R+kmJnoPiHiRphBpDudMBuC1CisJv885JJSZQ5xzeX2Y4lzB50076vv8ylFZSv0no X-Received: by 2002:a05:6000:18a9:b0:38f:30a3:51fe with SMTP id ffacd0b85a97d-38f6f09c087mr16722359f8f.42.1740501420857; Tue, 25 Feb 2025 08:37:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501420; cv=none; d=google.com; s=arc-20240605; b=CVFaiO6cP+ux/HzObceNJOHrqunsOI9DuQLe9EyRu/tFf8pORx8SNww+lFh6UbRQPu 109DIIomHyjsjWhcP3H0SFwhTnBOPspeU67g1svu0bFzfGMYz2LksDwZXG+bGRC8G0Dl JPamrDf1b9Po9Px4DSW8AJM7oamlRxrTeMM+GMXYGX8FZA6h762k3G22LFHWCZecstoT iK/zMyfC78lICjWNygJuqThlNQUUVMtJtJEaCWbXYagZ3RNVfNnBExDF9SBbzLJGD4+D B7y3PAzm0C6sikyWiwq7kuqca5TEBerxZ8HDRrx9gguLSZujaz/u83XI6OT9f9CCm/Ge 6Mrg== 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=OthUcvUIuZBCEF+aN20wP8+dBhQiAg81fe/EO+MQUZs=; fh=jxOSU3gOAidAW6etqGEwo7ZeAc8Dy6LDKIggnRQjnIA=; b=Bqe2eQM5Iw6gBQ8RIl7e8EMREQBFzT1jqIiYuPV/4+dJL4qJc2y8ppfSwBDNxb+SZ/ 8O6ZLg/WR+7MYAcD1eNTL4mAknWwkGHdxrphdIasBeqVlVxrDpnq5tk8bqYaxvnR7ck4 84iHUN54c0JLsrOesdhsC0I6Kq+vEofbqS0BHndpGSdNArR5Z7KB7Qb0HDbqZqQsGQx4 GZ0EtALW2ZzoVxJqD9ZqNw2id5CQMb8rSzHfxcJGc3bhmzlsGpYDWQm0QGL3WcIxQdky nRE9DiIjWYYOgTxxY/awAgcw8+rXQ0I1Jbf+k1ORY9IGa2ycL1MuhJPNLLtddOMz7g58 swLQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uXsJLFLm; 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-390cd86cea4si1294934f8f.195.2025.02.25.08.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:37:00 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uXsJLFLm; 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 3BD5181110; Tue, 25 Feb 2025 17:35:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="uXsJLFLm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B118807EE; Tue, 25 Feb 2025 17:35:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-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 46D48810ED for ; Tue, 25 Feb 2025 17:35:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-38f2b7ce319so4855259f8f.2 for ; Tue, 25 Feb 2025 08:35:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501327; x=1741106127; 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=OthUcvUIuZBCEF+aN20wP8+dBhQiAg81fe/EO+MQUZs=; b=uXsJLFLmAAJ/iM17We/XoNGzAgdxwd38NbAr8GeXTifc/SR7ofV1PkO6RWNSFpxQJB k1V5s/F7+wW6t9pTnLA9sdQkMyiJNVOz8ZtE0d3yEnzDpbkEyZt/zpO29l38oZ9ZvQKI PLyM6zL87/L34bnZ4hJIrz+X705fwpvD86GCI5J+5kLr5AJ978FhirHYGWbMDDfVhyM3 CsduFGumbx83jPjqdHXxVoS6VRxcb2fCnVYqg5AcB8ncYRHeZKzZPdXGJ6T5QWqgT7mz BU3uQ924ueJCaZdpmDGLP2IHSuIf0Io922x6lAuIGe9CdLOl5F8KGGAToW8WGR4YYWT8 3+ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501327; x=1741106127; 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=OthUcvUIuZBCEF+aN20wP8+dBhQiAg81fe/EO+MQUZs=; b=hzJW/oXS/81vlISmzwQervBPatdO0VUsSjsgR3V5tJscD43HvhZjLHX6gb5U5fjlnY T+HY+xD5HklnowhvJkPqcp84rP3RHVl9nUZFBBxGLqxbp4x36EiwsGXmD24GVVpf2cw4 fhr8tG8vOeOT79JZkN4on51ttoPgTlnTx/naReOz/9sxdzJSW7YUeHqecpk6Bfcy/Pyj 55giIiB1UCjCRKmUASmSJxnNU6y1vuvVFJPiaP1s2obqqAyumumsPA23eaegJ7jbN2bW PQ+fc8NFpfp7miVyLGnwiVK4ZmEEsjeey1YPYaxU2OGS/kO7gfqEbg24q+ZK5zovZrPi haFQ== X-Gm-Message-State: AOJu0YzocVsdrpV/CtMJia4XVm/6JLfLHYxdEY+F9WpyQ0pPccuQjLie 0kDDUz5VhkAVvK7mhVzuB0pzax7tmxrObZVIdxT1Bj2E3GKM6SkggR7NkqbABErdgnKUwkqHZUX BWnT6XQ== X-Gm-Gg: ASbGnctdw5p0X8lAZuzmPIbjEgFgAn6yIR27cL/ki76wdbnDffF5JKPboWcRvCfkdb/ BiiUKpM7/+OpTmqjlnSGxd5OeaXo9o/WJyoAucUWlgOd1QnkV9NXbboMxtC6YQ3GaAX4PBO+Xy6 QHxaU0Gm0PB/skMaUXUKXtAg1u6V8m0EpSgiY18xX7IDw5goeJGozj5ST6UT7HBz1XIToOpahAi efsmOsSsMt9adpFymdMTM4/HBM7GfON6V1e7uP+kBOVbDsdrc2GXT9mPwvcJKBkr3FvEcYzHPXz cOJ68Mf/i7nA74NUlq6egXpH2CTDw5l9tU4= X-Received: by 2002:a05:6000:4026:b0:38f:2856:7d9a with SMTP id ffacd0b85a97d-38f6e7563cfmr16711102f8f.3.1740501327365; Tue, 25 Feb 2025 08:35:27 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:27 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt , Mattijs Korpershoek , Ibai Erkiaga , Michal Simek , Venkatesh Yadav Abbarapu , Sebastian Reichel , Dmitry Rokosov , Alexander Sverdlin , Kever Yang Subject: [PATCH v2 13/14] cmd: add spawn and wait commands Date: Tue, 25 Feb 2025 17:34:39 +0100 Message-ID: <0c5c69d56b8505d2e678de96d07ea066f3459ccc.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add a spawn command which runs another command in the background, as well as a wait command to suspend the shell until one or more background jobs have completed. The job_id environment variable is set by spawn and wait accepts optional job ids, so that one can selectively wait on any job. Example: => date; spawn sleep 5; spawn sleep 3; date; echo "waiting..."; wait; date Date: 2025-02-21 (Friday) Time: 17:04:52 Date: 2025-02-21 (Friday) Time: 17:04:52 waiting... Date: 2025-02-21 (Friday) Time: 17:04:57 => Another example showing how background jobs can make initlizations faster. The board is i.MX93 EVK, with one spinning HDD connected to USB1 via a hub, and a network cable plugged into ENET1. # From power up / reset u-boot=> setenv autoload 0 u-boot=> setenv ud "usb start; dhcp" u-boot=> time run ud [...] time: 8.058 seconds # From power up / reset u-boot=> setenv autoload 0 u-boot=> setenv ud "spawn usb start; spawn dhcp; wait" u-boot=> time run ud [...] time: 4.475 seconds Signed-off-by: Jerome Forissier --- cmd/Kconfig | 17 +++++ cmd/Makefile | 2 + cmd/spawn.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++ common/console.c | 2 + 4 files changed, 197 insertions(+) create mode 100644 cmd/spawn.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 8dd42571abc..209ca365f4c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -3058,4 +3058,21 @@ config CMD_MESON help Enable useful commands for the Meson Soc family developed by Amlogic Inc. +config CMD_SPAWN + bool "spawn and wait commands" + depends on UTHREAD + help + spawn runs a command in the background and sets the job_id environment + variable. wait is used to suspend the shell execution until one or more + jobs are complete. + +config CMD_SPAWN_NUM_JOBS + int "Maximum number of simultaneous jobs for spawn" + default 16 + help + Job identifiers are in the range 1..CMD_SPAWN_NUM_JOBS. In other words + there can be no more that CMD_SPAWN_NUM_JOBS running simultaneously. + When a jobs exits, its identifier is available to be re-used by the next + spawn command. + endif diff --git a/cmd/Makefile b/cmd/Makefile index 8410be576bb..eeda40855bf 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -240,6 +240,8 @@ obj-$(CONFIG_CMD_SCP03) += scp03.o obj-$(CONFIG_HUSH_SELECTABLE) += cli.o +obj-$(CONFIG_CMD_SPAWN) += spawn.o + obj-$(CONFIG_ARM) += arm/ obj-$(CONFIG_RISCV) += riscv/ obj-$(CONFIG_SANDBOX) += sandbox/ diff --git a/cmd/spawn.c b/cmd/spawn.c new file mode 100644 index 00000000000..26532a30087 --- /dev/null +++ b/cmd/spawn.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#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(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) +{ + while (!uthread_grp_done(job[idx])) + uthread_schedule(); + job[idx] = 0; + return job_ret[idx]; +} + +static int do_wait(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + enum command_ret_t ret = CMD_RET_SUCCESS; + unsigned long id; + unsigned int idx; + int i; + + if (argc == 1) { + for (i = 0; i < CONFIG_CMD_SPAWN_NUM_JOBS; i++) + if (job[idx]) + ret = wait_job(i); + } else { + for (i = 1; i < argc; i++) { + id = dectoul(argv[i], NULL); + if (id < 0 || id > CONFIG_CMD_SPAWN_NUM_JOBS) + return CMD_RET_USAGE; + idx = (int)id - 1; + ret = wait_job(idx); + } + } + + return ret; +} + +U_BOOT_CMD(wait, CONFIG_SYS_MAXARGS, 0, do_wait, + "wait for one or more jobs to complete", + "[job_id ...]\n" + " - Wait until all specified jobs have exited and return the\n" + " exit status of the last job waited for. When no job_id is\n" + " given, wait for all the background jobs.\n"); diff --git a/common/console.c b/common/console.c index 863ac6aa9dc..2c8eaa37ad7 100644 --- a/common/console.c +++ b/common/console.c @@ -24,6 +24,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -508,6 +509,7 @@ int fgetc(int file) */ for (;;) { schedule(); + uthread_schedule(); if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { /* * Upper layer may have already called tstc() so From patchwork Tue Feb 25 16:34: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: 868126 Delivered-To: patch@linaro.org Received: by 2002:a5d:5f56:0:b0:38f:210b:807b with SMTP id cm22csp389358wrb; Tue, 25 Feb 2025 08:37:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXE0K8SDWQDbK+Kci8ZxZJ+13PwzUjWddrV1u1sEfYOYPkB6GHNlLmoE7TfLmxMMTWSJVKxqw==@linaro.org X-Google-Smtp-Source: AGHT+IGqMw8KCIWFWF6yQO0DCkYpAYGzvVjBwrvub24gbGxXuGp4FlVAdDH2rETsT99+9BPX3nAG X-Received: by 2002:a05:6000:4021:b0:38d:d0ca:fbad with SMTP id ffacd0b85a97d-38f70799a67mr17255753f8f.14.1740501429485; Tue, 25 Feb 2025 08:37:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740501429; cv=none; d=google.com; s=arc-20240605; b=eXrI3Bk33VO8kzw+5D0VkvaTvbchhtd0BxkttwTb55ruVfYx0Kw9R5RJ4Dhhxk+ohX oZ4Lb0i7syBb9uQZCiM5vJj0WbPC/b7CPHLgQTWoAlCwncXR6LcJC7GBJeypPXYhZNLj qaERcR1gkRv8nrJn9Dfu5DtUTwREInjhloaXVGE+IEpMC/wPJhUxtG21k+nd3yLGSBRE YaOhCTJnoYiEC5ROTUUzglw6o8TJaFpF/9+rLNwStHetkCIRUyhIeo/FM+kBvyuJijq9 oS1lpW9SbOAcMDNAFNxV3PXeblRz6miOc5El9jNlfzAMzrwJAF7l6ZugNMwOwnjgoizk VZCg== 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=TgqKz0JnkEMJXv2dl1r5sJ8K6KK0LVfIjcCRnaqavds=; fh=UXi5gUnwqAkJNiukY9dZPo8O1bj7wfbxhZ7gyd0YbGk=; b=NtHYaIvGl1tpVaQj7jz65Hg+Nvrt3u3WEjNWv4M4sY1cLcUC7nd1JtcchTAY8fcJbT boQbir970brLCg0MqCdbGYry4q3uDpxWkFkrv6rAb2To4uy0jbcvkrWpNsXzD0dBJLd8 sR4fDyhsEmQGjZs54aY4UTAAIS8KtI08zAM2PZArlp4+geoidGLhzqzQtOdwnUc4tbxM 3EZmEfN3UYbZsNd4wdZKBpd75Pt4jvfikooHvgzpVcMa9yRDWwHrWB8R2BEkS6LDmlsU LBNlh/0eQtY+ENVbUEyf8ft5SMrU5188CnKlLLkIYKT0CVBiblbb+dE5kq2XsNjd/X8r HxWg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yNFg9R6d; 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-390cd8e70ebsi1301710f8f.583.2025.02.25.08.37.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:37:09 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yNFg9R6d; 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 8577381113; Tue, 25 Feb 2025 17:35:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="yNFg9R6d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5B89D810F5; Tue, 25 Feb 2025 17:35:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-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 1FCF080FED for ; Tue, 25 Feb 2025 17:35:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-43998deed24so55550485e9.2 for ; Tue, 25 Feb 2025 08:35:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740501328; x=1741106128; 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=TgqKz0JnkEMJXv2dl1r5sJ8K6KK0LVfIjcCRnaqavds=; b=yNFg9R6dvkTBzUlJS/VmE27ik17qunBPKGbFXqFOAGN2fwdp5vjzzRUW/mb+QyYdgP YU0eSfqVpFeHAxR4glHU/7kNI0leOVYrW+exvvlTfsN4eWEpDc52MmgntZY/oUzjO2aa BoRHKPII+jmM3d7qb6ZVWr2JqB/Ix3YfsvuwHAWhMD3nGLkN5ivHvPalSdTgDgLhiVN3 0Ji1QMoyA5ZFjzIn+FikkeRJpwNaUEMrePMuZ5sYBDOBXcvYb93ikd5GGJN2aorb7ttG r+TwAevUMYjLMleTcJRj1eTX1HwuPWY+oxxeqAczb4E6MmN9oWsusKP79f+Q0wFA6A5G WNhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740501328; x=1741106128; 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=TgqKz0JnkEMJXv2dl1r5sJ8K6KK0LVfIjcCRnaqavds=; b=aeoAuWOe1WUKzUT8s589qC6wQNese605afizc2PSoboHQfGRPBxU4XoZMDuyApUuiU AFpMdkw58YX71hSbdf/L2UQSJl959rGIF5YYxO7H50KYomI6yaPjkPf4bvRs2e9WYh8C utFq1VoO/41cKGuYiW9GqJe3FcG0Bmd+3q8rvy2lUq1QLKWHQwLXZuyEp7z+QsHYQi71 vNuJFeVDY8xqLHiiHTzfjyCIuOANw5iBnkxiF/z6RcKCPcdguscEb6E4rBmB4I4Us82N y0oErxfTco9JNI8u92JwqHDjum4JA51Xi3TInj2nGLwcSNX/hI1iXNvSyQjcWd2JNKbC t5Ag== X-Gm-Message-State: AOJu0YxmSVysqaueYaqu5EdAJ3E8PNEr0icZV0CjwNqSRcd+9sJxnz/c C7J+DKEQJJaL/cGuVNhh/niR3SEJmVxGmvmSno0aYTQ8dQ7/j1/enCndN7MkpHE1iPtpjRk11Lg HHyCSOw== X-Gm-Gg: ASbGncsFybhG2KAProLkAkWeYxT+w14YkeClTqkLnBlQ2Iwm7m5YCT8+QbYEZpMnwYf Q/VOr2r02Ci5Ws6TPz9US2gc6AA5GWtyXu+7TlBe6aEQ/CUXiRsPwB2/OxQs7mksCI/uzeaZw1X UKXYDW3GDGttWxOwXuhCm7XyrNmeA5NNVNo/7qeOmW7EGMhqeKNmKCQMktzj1hVvudz5V0qPj01 1TTXnHH0oYmTRgDKYiyQrQOa42Fhz3FGvaSsPZzGj2yfi5xzKZzom0SUlGil1etKkjAFg+7xUnd PON9nQa/rQqixjbB9KJv72LnouF3wquv/yg= X-Received: by 2002:a05:6000:1a85:b0:38d:ba81:b5c2 with SMTP id ffacd0b85a97d-38f70854e1amr14897628f8f.47.1740501328441; Tue, 25 Feb 2025 08:35:28 -0800 (PST) Received: from builder.. ([2a01:e0a:3cb:7bb0:af71:dfb2:66ef:80c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-439b02ce735sm146356195e9.3.2025.02.25.08.35.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 08:35:28 -0800 (PST) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Jerome Forissier , Tom Rini , Simon Glass , Heinrich Schuchardt Subject: [PATCH v2 14/14] test: dm: add test for spawn and wait commands Date: Tue, 25 Feb 2025 17:34:40 +0100 Message-ID: <2f17fd7ec21b59218d5bf88f045c13db08f906ca.1740499185.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Test the spawn and wait commands. Signed-off-by: Jerome Forissier --- test/cmd/Makefile | 1 + test/cmd/spawn.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/cmd/spawn.c diff --git a/test/cmd/Makefile b/test/cmd/Makefile index d8a5e77402d..cf47f04851c 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -39,3 +39,4 @@ obj-$(CONFIG_CMD_WGET) += wget.o endif obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o endif +obj-$(CONFIG_CMD_SPAWN) += spawn.o diff --git a/test/cmd/spawn.c b/test/cmd/spawn.c new file mode 100644 index 00000000000..5e0770858c0 --- /dev/null +++ b/test/cmd/spawn.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Tests for spawn and wait commands + * + * Copyright 2025, Linaro Ltd. + */ + +#include +#include +#include +#include +#include + +static int dm_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; +} +DM_TEST(dm_test_cmd_spawn, UTF_CONSOLE);