From patchwork Thu Feb 2 22:34:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp510637wrn; Thu, 2 Feb 2023 14:36:28 -0800 (PST) X-Google-Smtp-Source: AK7set/zV/TiF/h4lINbBCCrlRIsAG5S6StFLnL3rjxgKt16uHGuAmfP9Qyjtz2YZWj8e5YEFyBY X-Received: by 2002:a05:6a20:8e08:b0:bc:930e:4165 with SMTP id y8-20020a056a208e0800b000bc930e4165mr10253446pzj.15.1675377388594; Thu, 02 Feb 2023 14:36:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675377388; cv=none; d=google.com; s=arc-20160816; b=RqAz/ymm+HF7KCI+U4A6mkl4CN2QrPnnA26PPcOZL+J28enwt8lcOUmPtFfPPiCBjy ovjcrnV7aIRSdUZ6wEN9Ej3bpuleS/kpPimYYJJ2ZTrkDnNyThF0ekCyCX53ScIvot17 /tp4lHlNbQyVmCMpb80sBiuLw3XaRLbP0XKrXfcPiuMvUEX/KbVtWYyErKAFhYzyo2Ya 6TF/1TlIC/mg+e/PinuP0B2uVQQhVrvxyduejsmn7CR2iNEchW+3ONl/sWt9OB28Utj/ 1FL89h2ILoRz4xsk5QE1IQscAOosOSizPGc+qc6LhrrGaTUcm3GJegh255d8a0d8Kh63 tatw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Yt4n7TrebHBHw1pv+f/VYH1/nL9tMmkgabnkwlM1MoM=; b=rervy7bZXemf7arcz9qZRnEYt5+eU6Y+4e/kImNnUIIxzsNDyfNP0COQuoDC/YgTTe bk6OeWKQDPBOIgFNOr7oIeeVTxu1w87oDWXZc/Xz9IDuOSFoJJ9w45EtVoBRgWyeGoAu htzOuuduJYCGgLF5VD40JgCDo1Nz7h+29egK7Ar1zR+YfKlvTzdo2iZbkHoAWRPXOjSP MOo/Oy2HVscdD3VKirUqfJ48J78gowcwmQsBJC0F10qsartG7/R7I8IXYzE1y7AXgGWK V8G4X5biDlQksPwg7Rb+Cef8DhFNpU8a0B4apBxI4fgMkzE/jEej0r/ifkpt4iTuLA0S TqWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lkvfRnCR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a17090aa59300b0022711011581si5544628pjq.175.2023.02.02.14.36.11; Thu, 02 Feb 2023 14:36:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lkvfRnCR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232736AbjBBWeY (ORCPT + 99 others); Thu, 2 Feb 2023 17:34:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232509AbjBBWeT (ORCPT ); Thu, 2 Feb 2023 17:34:19 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E7786A32A for ; Thu, 2 Feb 2023 14:34:18 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id f15-20020a62380f000000b0058db55a8d7aso1633006pfa.21 for ; Thu, 02 Feb 2023 14:34:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Yt4n7TrebHBHw1pv+f/VYH1/nL9tMmkgabnkwlM1MoM=; b=lkvfRnCR9L4p48JCZwFZKWUKHGN61Q3m0t7AYSHtCynD8fd/3R0LutY7M8PjtUNTAF 75GpSew/2QQYyvsc6dNLfGFaHsNxWUjTbvbWHaFPATihKYBfAoSzg9TsANL2ayno0iFW DQ31W/I3W0ZEpyBr6VhnMbXBU2b44i0YGfsCzylRXeCADASPJJxwtrSsFKLhGEhwLPLP RvHmLd3iUMU5hPOfHF9wp3JwzOML0GCzI9DJkY1X4gTtAX40FiJnjMD/UeQKBD6NMPkA 99baXrHXLS6CEfsAYP7QHJs8HVLMWw7JxF3ekZQE0Rs96QAt2qP570o51O3gKemcHTj+ FPhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yt4n7TrebHBHw1pv+f/VYH1/nL9tMmkgabnkwlM1MoM=; b=3Pt3rSGf3pggcUaUG9dJLUdXD5IMxGaTljuKdCauxBOBPX72QwlCJ5Sbr51vQC78K1 V9gU46BIU/tUF0g/H9gPWykDnDPz+FI4Qlze3MZaTvDS7E7SfBCDXQYEMZUA+QKgP/w3 2JE4rtKkmmYlxKM7uSIY2d8yosZWJ+qnH8jkAd+SzR0yHZW/AOysF8VAw+3G2rbnhtAC a3c0V0otDncHiqPRBJ8PHgYPOP5obgE5SWbZB3gfQwX7kBAVufu4Xxk0JcsXPM+B9cFY 9oKwP3L6Pz+fSK91Xxog0TdC74mUfx0Y/rmYGV8f3PIB2NydQtAQqXpXUqMWCtWff8Dt qfXw== X-Gm-Message-State: AO0yUKXe4Qf1mxaF/oH+4u0ZGuzku9/RHJfph5a7+vaHHpbAXzE+c7Bm yFgUNkzt2m6KM48q9qiqTMManmTZpeEnNozKE9C++4s28UDuuuvwQBqCqHzj0trNW7/P9kEm8vl LGsBZN5G3SfsJ+ZwL3RTIlV1ZLE1U27LMh4YLCoJ16yQZkdb97IwYZgcw7sMyY/IyjTQkSKQ= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:aa7:84c5:0:b0:593:37d6:dcb8 with SMTP id x5-20020aa784c5000000b0059337d6dcb8mr1853562pfn.30.1675377257642; Thu, 02 Feb 2023 14:34:17 -0800 (PST) Date: Thu, 2 Feb 2023 22:34:09 +0000 In-Reply-To: <20230202223409.2812443-1-jstultz@google.com> Mime-Version: 1.0 References: <20230202223409.2812443-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230202223409.2812443-4-jstultz@google.com> Subject: [RFC][PATCH 4/4] locktorture: With nested locks, occasionally skip main lock From: John Stultz To: LKML Cc: John Stultz , Davidlohr Bueso , "Paul E. McKenney" , Josh Triplett , Joel Fernandes , Juri Lelli , Valentin Schneider , Dietmar Eggemann X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756760520901966532?= X-GMAIL-MSGID: =?utf-8?q?1756760520901966532?= If we're using nested locking to stress things, occasionally skip taking the main lock, so that we can get some different contention patterns between the writers (to hopefully get two disjoint blocked trees) This patch was inspired by earlier work by Connor O'Brien. Comments or feedback would be greatly appreciated! Cc: Davidlohr Bueso Cc: "Paul E. McKenney" Cc: Josh Triplett Cc: Joel Fernandes Cc: Juri Lelli Cc: Valentin Schneider Cc: Dietmar Eggemann Signed-off-by: John Stultz --- kernel/locking/locktorture.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 5fb17a5057b5..6f56dcb8a496 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -745,6 +745,7 @@ static int lock_torture_writer(void *arg) int tid = lwsp - cxt.lwsa; DEFINE_TORTURE_RANDOM(rand); u32 lockset_mask; + bool skip_main_lock; VERBOSE_TOROUT_STRING("lock_torture_writer task started"); set_user_nice(current, MAX_NICE); @@ -754,21 +755,28 @@ static int lock_torture_writer(void *arg) schedule_timeout_uninterruptible(1); lockset_mask = torture_random(&rand); + skip_main_lock = nlocks && !(torture_random(&rand) % 100); + cxt.cur_ops->task_boost(&rand); if (cxt.cur_ops->nested_lock) cxt.cur_ops->nested_lock(tid, lockset_mask); - cxt.cur_ops->writelock(tid); - if (WARN_ON_ONCE(lock_is_write_held)) - lwsp->n_lock_fail++; - lock_is_write_held = true; - if (WARN_ON_ONCE(atomic_read(&lock_is_read_held))) - lwsp->n_lock_fail++; /* rare, but... */ - lwsp->n_lock_acquired++; + if (!skip_main_lock) { + cxt.cur_ops->writelock(tid); + if (WARN_ON_ONCE(lock_is_write_held)) + lwsp->n_lock_fail++; + lock_is_write_held = true; + if (WARN_ON_ONCE(atomic_read(&lock_is_read_held))) + lwsp->n_lock_fail++; /* rare, but... */ + + lwsp->n_lock_acquired++; + } cxt.cur_ops->write_delay(&rand); - lock_is_write_held = false; - WRITE_ONCE(last_lock_release, jiffies); - cxt.cur_ops->writeunlock(tid); + if (!skip_main_lock) { + lock_is_write_held = false; + WRITE_ONCE(last_lock_release, jiffies); + cxt.cur_ops->writeunlock(tid); + } if (cxt.cur_ops->nested_unlock) cxt.cur_ops->nested_unlock(tid, lockset_mask);