Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2617691rdb; Fri, 22 Sep 2023 04:09:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGj8xOr3FzxQ3ly3zTekHIreTbLfgqeBZSTgd1Tyvpv8ehO7XnsypkyCWuVUqMoAgfc9V2t X-Received: by 2002:a17:90b:11d5:b0:274:ac60:1d57 with SMTP id gv21-20020a17090b11d500b00274ac601d57mr3477380pjb.16.1695380984137; Fri, 22 Sep 2023 04:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695380984; cv=none; d=google.com; s=arc-20160816; b=pom8leBahfllHJzHwd6AhRJLXoxvc07neRN6JqdbTXhJO9DCoCBNMs27iSpDWDSXOg 63zcOGMC3CZfFRYo7PSfHLYzg2awd7AE4K3LewKzZcx3a/6eBNHoUCV7ygtBDnawO4IU 0AuEiqgIjOCdJrxRo/0QMstZv+Ns+vstiSCktDCpt3Mxt5RaYBVhr0iJgiuNNCa0846H aaCNU6DOGqPUBrpc+5I5pNnoBR3Be+eDIN0IIWH17KG9Dft+TlmO+IHy9nNYTeEwcKCe zMTqNdrQF/eKWiYdphxZne5uk8hYH1/+fUBB8uMbXL3Sn8XYg0jISGZMevUOFNH/iIpr LpcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=1p8WzcJOAWfYeWI6UQE2QRNFJdJzCKra8K3fwBKeWYE=; fh=IECvZ5LDG1eNYiY0ZEkdAtu3yKdGBaMOXeHl+ptZ6Xg=; b=LVTzGu1A7OTL8mrLWU9pesH9EddgLlaz3c3sEwO5iKtBure3iklj5KugCEIAcG5OFa hmpw/Azx8u4kFnk48mi5D20RRL0XjQazP/RUFrZL0qyXFwaPKsRGk2e/8KuqlrE/G9Lk VBgCN760dOGxdGEMKHvjrCIP1vEltAD5Z3+UAtrHrUeYtdJROlomuaNDUSMdPkWIgeGT esKMh6qKubWs01aN69pJnbLqJucPIIcp0eWmFiHmv9VSrs0Oef3cfar46+Vs+iwumUFZ JzEUxQxYQNZn/bfpKhINnR4uT8HK+Rx+HlwyNbPJI8Cz74eUq4sa8sqUD4UvJajYiYBW qKfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ojpQtcDn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=byVsDRSh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id oj15-20020a17090b4d8f00b00252d84b7af0si3960086pjb.181.2023.09.22.04.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 04:09:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ojpQtcDn; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=byVsDRSh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 44B698328233; Fri, 22 Sep 2023 01:12:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232432AbjIVIML (ORCPT + 99 others); Fri, 22 Sep 2023 04:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232491AbjIVILq (ORCPT ); Fri, 22 Sep 2023 04:11:46 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BA8CE6C; Fri, 22 Sep 2023 01:11:40 -0700 (PDT) Date: Fri, 22 Sep 2023 08:11:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695370298; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1p8WzcJOAWfYeWI6UQE2QRNFJdJzCKra8K3fwBKeWYE=; b=ojpQtcDn+LyAKsQwFJpccq0mc9T+icQ5zwJAy9mD/mDkYxbA1wgwN/MTi/sp3f3UKvGShQ CnMEMhN74yG1GEis2wJtbsKBgeDOB3Qo6cMqfkegHFgQvUc1t3rO+ltXRUzrsr/HdTA+vU paVOSSfPn7n+r0tnYJwEdVsJVcj1DYDLhPt2Jfm+mobAxuZGEziyAfFC0yrSeKjmQRCCeJ DOjfgu1wKEZZUPFTKJck5if23NNo5FF/P3KfwkbDHuyjya2HwJ7wtpCSsAFulB4YbG6jGI /frecf0xMVgafYkAK0CK9y+jDlCE9bPw3hmZXj8DWEnao2E4QICTNNyBZqGHJg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695370298; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1p8WzcJOAWfYeWI6UQE2QRNFJdJzCKra8K3fwBKeWYE=; b=byVsDRShUDXLgoVlAO8FzCm+vF3pcbOix7HsbYe9bdUyp/q4TjX3cegaOVr+lbUErZcrph 0EyvoRTRRiq/72Bw== From: "tip-bot2 for John Stultz" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/ww_mutex/test: Use prng instead of rng to avoid hangs at bootup Cc: John Stultz , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230922043616.19282-2-jstultz@google.com> References: <20230922043616.19282-2-jstultz@google.com> MIME-Version: 1.0 Message-ID: <169537029801.27769.5775811116918279412.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:12:53 -0700 (PDT) The following commit has been merged into the locking/core branch of tip: Commit-ID: 4812c54dc0498c4b757cbc7f41c1999b5a1c9f67 Gitweb: https://git.kernel.org/tip/4812c54dc0498c4b757cbc7f41c1999b5a1c9f67 Author: John Stultz AuthorDate: Fri, 22 Sep 2023 04:35:59 Committer: Ingo Molnar CommitterDate: Fri, 22 Sep 2023 09:43:40 +02:00 locking/ww_mutex/test: Use prng instead of rng to avoid hangs at bootup Booting w/ qemu without kvm, and with 64 cpus, I noticed we'd sometimes hung task watchdog splats in get_random_u32_below() when using the test-ww_mutex stress test. While entropy exhaustion is no longer an issue, the RNG may be slower early in boot. The test-ww_mutex code will spawn off 128 threads (2x cpus) and each thread will call get_random_u32_below() a number of times to generate a random order of the 16 locks. This intense use takes time and without kvm, qemu can be slow enough that we trip the hung task watchdogs. For this test, we don't need true randomness, just mixed up orders for testing ww_mutex lock acquisitions, so it changes the logic to use the prng instead, which takes less time and avoids the watchdgos. Feedback would be appreciated! Signed-off-by: John Stultz Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20230922043616.19282-2-jstultz@google.com --- kernel/locking/test-ww_mutex.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index 93cca6e..9bceba6 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -386,6 +386,19 @@ struct stress { int nlocks; }; +struct rnd_state rng; +DEFINE_SPINLOCK(rng_lock); + +static inline u32 prandom_u32_below(u32 ceil) +{ + u32 ret; + + spin_lock(&rng_lock); + ret = prandom_u32_state(&rng) % ceil; + spin_unlock(&rng_lock); + return ret; +} + static int *get_random_order(int count) { int *order; @@ -399,7 +412,7 @@ static int *get_random_order(int count) order[n] = n; for (n = count - 1; n > 1; n--) { - r = get_random_u32_below(n + 1); + r = prandom_u32_below(n + 1); if (r != n) { tmp = order[n]; order[n] = order[r]; @@ -625,6 +638,8 @@ static int __init test_ww_mutex_init(void) printk(KERN_INFO "Beginning ww mutex selftests\n"); + prandom_seed_state(&rng, get_random_u64()); + wq = alloc_workqueue("test-ww_mutex", WQ_UNBOUND, 0); if (!wq) return -ENOMEM;