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));