From patchwork Fri Sep 22 08:11:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 143747 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:910f:0:b0:403:3b70:6f57 with SMTP id r15csp5758vqg; Fri, 22 Sep 2023 17:33:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMoHAaA6o3I1ezLkLgv5AGbbOPF5VawteDSQEdeQkgpQz+256cbBo32PbVf2cxxma+wW/C X-Received: by 2002:a05:6a00:310b:b0:690:9a5a:e34e with SMTP id bi11-20020a056a00310b00b006909a5ae34emr4687122pfb.12.1695429182266; Fri, 22 Sep 2023 17:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695429182; cv=none; d=google.com; s=arc-20160816; b=iBKdCVK47jhXI8w/CRm5z7mzUyi73brAQUG2FEbQW2/E9FqbYn4xwcgmuPNKW+PsyH kWIWMZmTxf1BUXnamw4fmAZOQIeGl0thlHtT4F6LNyfPPWInYnPnLFS8al/BUOu3hvvW MWF5JX4BTWrUWq6Q1LHKCWwBHa+qa5dZ+R6XZKC8wtHo080gK27za3BcBkwUZH9zHE3a WrtPlSJi43Z8YV2bgT30l7vuPCD341V1JevVZd6dd0lpH50D+IzH3Qvsma8PEPRC5UEM E5c31JaFF25oXUaqLRQNDHlRfFF/efJASYT6Pcl+clNNYNnYp1KMyWDH8wOsquWhnI2w ND1A== 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 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u1-20020a637901000000b0057414fa789fsi4729419pgc.503.2023.09.22.17.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 17:33:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; 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 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 63B3B83BAC83; Fri, 22 Sep 2023 01:12:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232204AbjIVIMM (ORCPT + 30 others); Fri, 22 Sep 2023 04:12:12 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:12:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777786349919320820 X-GMAIL-MSGID: 1777786349919320820 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;