Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1975113ybl; Thu, 29 Aug 2019 01:33:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdQRA8JzgUSxlfc/G7hMvcK+KpaoRUSxS7cjNImyszZhJJhYXq2gEknyQgj5Y3uZPY0G/s X-Received: by 2002:a17:902:b40e:: with SMTP id x14mr8516475plr.289.1567067636644; Thu, 29 Aug 2019 01:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567067636; cv=none; d=google.com; s=arc-20160816; b=Uf9NPOo1dk6tUq8KbRJfBGfBbs7IluKLGILll2+6TxW3CGpe7/28ln5vWtFDh7wlj5 D+lUPgupJjyc4PwdTyS6dK83CsUsdw+wVvOF9opBFaiVTHYewRZ4QmEsZFX/8kbS5JXF pKyBXNd9+nh4Tn7gNv6O1vtwuIcIbAXSywJA/sRjS1fRZKCrwMPxxOr0r4S2ZlDSc3LH W5L8uzqf1xQ1xkog3NnmALB8aXvtlhDp51GGq84zbMGL8/ak5BvP5Txnk3r2g/W1nKxb Ga2/wcH5Lbx2Ap50AMhgWaYdk5Xnnc93Fz8cr6kaSqUE+Vf42hMf/vZvyIAo3cIlB1M6 ek0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ndYsBqWw3lm9AlRGDvPEbBOKTM9ZoSmwZ9e8SQkG/N0=; b=lxvt6mxtcmLp/HEgUKNuqLSjKaT54ds5ljnYSNlsZ2HHCyIgFi8okSI3aOnIN3Wkmu dlvbnfXmq9QaG2jozmPEw3F7+mRqW0RIhPmOARBMKElrThAVJrtZDB7QLGysGUL5iP2w l+NJkEEZhcEn/wbd+JXW50Upqp47o10Pgz9+4B4OQ0a55DSKJOW/6QZFXAJBABX04ZLL 0VvbQ75BJRyvIUj6vlZmlMa1/IWBgMm3XN0VDXYXLXK/yWhe/gPYJU87FBMoTv4+g0kq RSumg5+faloMPxM5tjJbBMNRnROsUZstrn1DK/c9ZubhMNpaMSfem3s/5c6ybVSCkxLI a+PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DjAtRwjg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si1299306pll.434.2019.08.29.01.33.41; Thu, 29 Aug 2019 01:33:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DjAtRwjg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727252AbfH2IcT (ORCPT + 99 others); Thu, 29 Aug 2019 04:32:19 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37576 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbfH2IcR (ORCPT ); Thu, 29 Aug 2019 04:32:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id y9so1576347pfl.4 for ; Thu, 29 Aug 2019 01:32:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ndYsBqWw3lm9AlRGDvPEbBOKTM9ZoSmwZ9e8SQkG/N0=; b=DjAtRwjg+1iDuOVCiRMy5sYP3FKE2X9YDI0ctZ5u9bmSm/LBFWLNvWwbnu1qZW+ovP l4O2p3VwZvMUq1KxE05BG0B69Oz3ZFKFiHvETpdV/MiWTQccyh43YyjW3cVIR1nzGx9L pU8xtx+Sf5iUBZ8mo1Q82pkFRkqyYoTgUEBe9DmXlDg1HT0xb0Kd7yRJrnxEss1a/nFs a+/a1uDhr6X2n9QE2jJEHkrfmekP+UqiGeOV3eTO3sVymZXzrjPcIcXt4L6mQibmfNEP 1G6b65i0z/p+X631RaB5dgCgqpUZ6yJDEvW+dBs1Jm5AAES6rBolUnmkNbGRW+ehIRF4 QWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ndYsBqWw3lm9AlRGDvPEbBOKTM9ZoSmwZ9e8SQkG/N0=; b=pOWmkE8FSfGrbjEdRupL7SvSfPU7x3oIble5pT4Gf4ZrVKWZ76na3XBTb7nZmhlRxt INl6jQptDpQQLLzMJqV70JG9VFCKXhi9Ku4G4Yyw5z+D0YC2g+Fghii7OTVhLUbWRZzN YtBI+U0BVkBGxexJYHMwnLV9irBEUZo+2R54lIR0KUrfgaFUf7zSUZmPBLbk2fhleavE nk+MAYguVdHEmB3nTEHSycB6aLeJkrEnvtNTkcLnNvJBRshRYJkpviRgZZ/ydByU/cLB 9c/1eQU2NU73UXqQD9xkG8lUwc5qzP6+8Xz/iHdngv50w1VcLc4ICNXJWEsTPCwrX1DZ 1/Iw== X-Gm-Message-State: APjAAAVzmPpfh34qvMkhC/cJxMKrK8mPWMFtXFHom1hTzR0fks8aP/vn 8MN+/ihkQKrIvcu+ePilr7I= X-Received: by 2002:a65:6454:: with SMTP id s20mr7164732pgv.15.1567067536958; Thu, 29 Aug 2019 01:32:16 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v22sm1260155pgk.69.2019.08.29.01.32.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 01:32:16 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, longman@redhat.com, paulmck@linux.vnet.ibm.com, boqun.feng@gmail.com, Yuyang Du Subject: [PATCH v4 08/30] locking/lockdep: Skip checks if direct dependency is already present Date: Thu, 29 Aug 2019 16:31:10 +0800 Message-Id: <20190829083132.22394-9-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190829083132.22394-1-duyuyang@gmail.com> References: <20190829083132.22394-1-duyuyang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Given a dependency -> , two checks are performed: 1. Lock inversion deadlock: We search whether there is a path from to in the dependency graph and if so we have a potential deadlock scenario in check_deadlock_graph(). But if the direct dependency -> is already in the graph, there can't be such a path (i.e., to ) because otherwise this path would have been found when adding the last critical dependency that completes the circle. 2. IRQ usage violation: The IRQ usage check searches whether there is a path through to that connects an irq-safe lock to an irq-unsafe lock in the dependency graph in check_irq_usage(). Similarly, if -> is already in the graph, there can't be such a path either. This check skipping should be able to greatly improve performance by reducing the number of deadlock and IRQ usage checks. This number precisely equals nr_redundant, which actually is not a small number. Signed-off-by: Yuyang Du --- kernel/locking/lockdep.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 4838c99..de088da 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2433,6 +2433,25 @@ static inline void inc_chains(void) } /* + * Is the -> dependency already present? + * + * (this may occur even though this is a new chain: consider + * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3 + * chains - the second one will be new, but L1 already has + * L2 added to its dependency list, due to the first chain.) + */ + list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { + if (entry->class == hlock_class(next)) { + debug_atomic_inc(nr_redundant); + + if (distance == 1) + entry->distance = 1; + + return 1; + } + } + + /* * Prove that the new -> dependency would not * create a deadlock scenario in the graph. (We do this by * a breadth-first search into the graph starting at , @@ -2459,21 +2478,6 @@ static inline void inc_chains(void) */ if (next->read == 2 || prev->read == 2) return 1; - /* - * Is the -> dependency already present? - * - * (this may occur even though this is a new chain: consider - * e.g. the L1 -> L2 -> L3 -> L4 and the L5 -> L1 -> L2 -> L3 - * chains - the second one will be new, but L1 already has - * L2 added to its dependency list, due to the first chain.) - */ - list_for_each_entry(entry, &hlock_class(prev)->locks_after, entry) { - if (entry->class == hlock_class(next)) { - if (distance == 1) - entry->distance = 1; - return 1; - } - } if (!*trace) { *trace = save_trace(); -- 1.8.3.1