From patchwork Mon Feb 6 21:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 53512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2462747wrn; Mon, 6 Feb 2023 13:09:39 -0800 (PST) X-Google-Smtp-Source: AK7set/hFG+TrPETjBE7B3vP0tAytJWO46QyMOLQUbVUnmqw66BRJmuQHBGS3gmV9TfHt1JjDpRh X-Received: by 2002:a05:6a21:3881:b0:c0:af73:be4d with SMTP id yj1-20020a056a21388100b000c0af73be4dmr366776pzb.54.1675717779341; Mon, 06 Feb 2023 13:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675717779; cv=none; d=google.com; s=arc-20160816; b=rcyipUun+ywhP8OQ/SlzTbikfUd79TTayG9of8hrXoSO4cOkH71cfZ4IgfbH+O4UG4 4op5IFgo67TwvT9r7bChJCsZbRIUflnvt0IzryNdWy9o1KBSwkA1+ChTf6JYIOFdM3YQ +GAK/3C5Qg7w8uMJNRbed3dxdQQRoMsn4R96ofB8ynMiwk4MWkkf1poDSkgqLSt4Q9XM NHEuMGzpOCbpL7J0Gqtg8b/FOs6jPKLACElj70p/kA2wSsfYQMklkulyYjFye5kc8Ea8 zDI4VzrwY7pGjvLlESNj/A41/WL+zjNsQD3WeD9TMxvxqnDaXtbMLD5smYlqPAwYHpEc E5hA== 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=I3e/s9avw1m4n0KoQjfHLWE3N93DXhuhhva7XCYBBqk=; b=UFEVsu5iJxj9L7WZ3ZVFrCZMKv8sPGqmsMpUZ42+Itc/3da4jnBY18ky7QHYw4P7gf JVqVo5U+C5OjpTKABKOD+6J57Y/GXiB5xZx9/KL3uIsjaY6GX7k4Fh5CD6wDPRegwFn3 luJ2SCXZOENS0BKCubNUpmHTu9Ax8RSVzQLQkCbdObxC+y0Lil46rwmIhJVuQgJiVCgL xzoKOwE+MVdsY/VcNtEDBIWHamkOHlJA9ueNVg4aoIHTPTRGVfewPymifj0ce3G9nNR3 J0OVyxkilyQgpmHkeJlE7vlfSHgnXcqj+jypLaskhb+t+UvLwkZ2DHefIyAMIYp+hN+N Rbpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HokxCYxl; 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 m8-20020a638c08000000b004915c5ca6b1si11771383pgd.866.2023.02.06.13.09.26; Mon, 06 Feb 2023 13:09:39 -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=HokxCYxl; 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 S229923AbjBFVGT (ORCPT + 99 others); Mon, 6 Feb 2023 16:06:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbjBFVGN (ORCPT ); Mon, 6 Feb 2023 16:06:13 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D40B42C649 for ; Mon, 6 Feb 2023 13:06:12 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id j14-20020aa7928e000000b00593bca77b0dso6953694pfa.9 for ; Mon, 06 Feb 2023 13:06:12 -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=I3e/s9avw1m4n0KoQjfHLWE3N93DXhuhhva7XCYBBqk=; b=HokxCYxl6SUv/u4i1B4MSvdUni65+hHCahZPbRel82LgW2njrOIL7KZFDtMGa2VnyB hjXqVcyejXgPnAaMv1Kw/Lp68BU18saa2DNpXrpbwTGKsIXGJ1m96FQCxVoSPPt7C73m QNRsKo4r3cEHT2TFXE616xDky8i59SO/oncU7xwwfpQf1Wh2BSAluLwHHEuLUBHbZoeP Or6cJNi27gxZtDmrE+saH7xQ+Qp4PHgTwkYow3D8qjAhunNPK8xDXjAnx2LuX2zwwV0N v01sCwU/VwSi8+mkz7wwO/6NK5S8XebVV5Dny08dA4B8VvyiL6TNbKitMq/p2MHkgD30 xX2Q== 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=I3e/s9avw1m4n0KoQjfHLWE3N93DXhuhhva7XCYBBqk=; b=RO6To3HoGfjHsT5//iLr01GsQeXFtfHq3KJ8hHZs1JUZQMKLWvN1WoQ/mTLkdyntLK Wiqmw6b6yt8zh1cL2OhAcMOb1i0UjECDaVgzfumnpoMjdmlks+XbV6FXJegr1K16gtXA c/lsDehbldMSY0WHtj0dZfMmHi1nScNWMlITdf6g9FrKfbnZ5RgWw2Sdr1TwvMK3QGBw migRrAmtkbxVXoe11PK7UhlSbxR+A7CDuKXN1KyP1MddTqilOyB88dIOSDhmQXnMoakC 5FUNnNHXsubjvDsu91aeHDpL2uhbDxerzgKndJw24ytTaljOBYRxNcbpqBPBLWyfUTgq JTGA== X-Gm-Message-State: AO0yUKU/8GE+ef7Ms+Y2WUrArzSoR72fS028GAl1qER32uzApLZDIXFx Ixa5sgiKgJV1GTksmw+ckqDlca5tBt5ucCoFyIdQDFnqjvpdjcCBX0JDGCQ8hRAj2d5M+vMTHeR DjAcpz6jAoHkETWVi8jSDxMDD4aUGI7kee+DF1pl2saOBMbbCQhoYBV89llNYRFOsRTOHHUw= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:90b:e97:b0:22c:5369:8a36 with SMTP id fv23-20020a17090b0e9700b0022c53698a36mr11794pjb.0.1675717571605; Mon, 06 Feb 2023 13:06:11 -0800 (PST) Date: Mon, 6 Feb 2023 21:05:56 +0000 In-Reply-To: <20230206210556.660318-1-jstultz@google.com> Mime-Version: 1.0 References: <20230206210556.660318-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230206210556.660318-4-jstultz@google.com> Subject: [PATCH v3 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?1757117445870215012?= X-GMAIL-MSGID: =?utf-8?q?1757117445870215012?= 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. 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 --- v3: * Minor rework for naming changes suggested by Davidlohr Bueso * Added comment explaining why we skip the main lock, as suggested by Davidlohr Bueso --- kernel/locking/locktorture.c | 37 ++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index fd8b2b007c26..ab896cc42b87 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,37 @@ static int lock_torture_writer(void *arg) schedule_timeout_uninterruptible(1); lockset_mask = torture_random(&rand); + /* + * When using nested_locks, we want to occasionally + * skip the main lock so we can avoid always serializing + * the lock chains on that central lock. By skipping the + * main lock occasionally, we can create different + * contention patterns (allowing for multiple disjoint + * blocked trees) + */ + skip_main_lock = (nested_locks && + !(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);