Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3069217ybd; Fri, 28 Jun 2019 02:17:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGdUGfR/Vk55Kr2ivoDAJ0u/DAUKOBcwaBXrf3/1Ya4Zw1CR2vhfB/rrjPAE1i8TDRjpXz X-Received: by 2002:a17:90a:cd03:: with SMTP id d3mr11308416pju.127.1561713431541; Fri, 28 Jun 2019 02:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561713431; cv=none; d=google.com; s=arc-20160816; b=M6TjeQcA7H8mAb8f+kegHbVLwnjd6UjkcM3KDm9Gc0sxBvDeLdtaGOODW0bks3D19x 3VzZ8uFPg6Ubi6QHE3ONCjdf/za0MtM6fGrb935MG62z/2nydah1B+9B4cUas2RVqpoc iv1o1qHKRZlO8sUnyIvXFCdgj5QQto95tk5AnRdYOFFNQpTruEOy5IikS69U64AegN19 6L3SYE2djHQozeO/+6CnViswPYaMnxEjC/ZLH037oogIjr603zfE+NHoPyabwzG1+hf9 2fVt29gvSr6AQXyvNPmWyjoHKqnzpx+UcXLCsyLJ1VCmJhwTJXKo2CAB9ZzMic8UnAGA nF1g== 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=xMgzax4HjoaAL0uerD4B+UL3X0tNIUoyb0iGc+fPFY0=; b=ybUipszF4Y7Qg0TRpRaSUJdV1mxWU0r0Bs0mVsBc28/GKdz3PElb2ttJ+S4DmD04Iu fKmUhByatnb03KytN6kYs1nJ0tZzhIVGEtaVhvXalzN9eoWy2GvFePVczUhSyb7Y5P0v 9cGiOhLUTfGLpWdOlTScKGcwPOCuU7S7J6kTfCvlRaXCkvd4FuuZlQtXi7ym8K0EeLg8 gWhHF3LgtaSCw5TYJ2NImVtzQNy5i7EJES5sP/ObfMCQh01xI4eqm4+uXgp5/EBvbhIm HtivAd5bPlcAHvw67KRsacBIHUdRIJLz20ieIMP4ULZ82mLvoi8Hi/vHviLYQLWr0wAx XCqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pkMUEqi2; 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 t8si1681921plr.27.2019.06.28.02.16.55; Fri, 28 Jun 2019 02:17:11 -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=pkMUEqi2; 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 S1726882AbfF1JQU (ORCPT + 99 others); Fri, 28 Jun 2019 05:16:20 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41853 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbfF1JQU (ORCPT ); Fri, 28 Jun 2019 05:16:20 -0400 Received: by mail-pg1-f196.google.com with SMTP id q4so837279pgj.8 for ; Fri, 28 Jun 2019 02:16:19 -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=xMgzax4HjoaAL0uerD4B+UL3X0tNIUoyb0iGc+fPFY0=; b=pkMUEqi2gh11gMyO1DLpyj6T4hT7ZIBs0smgUtCgoKOsFm1XzpuA2s+WwNvnIEyS76 5c4BEyOEwRkuqSsIg0vepw+6AtPOG3kXJyJ2RIQBRzNknEu2wGwRhgGIei+yZ18W5CBj NQL5OWapwBwYNkHS+xngAyqNoyD/GpDeSOJ3aOeANW63Pev8JEDNQtSzloPMnDUIl4C5 o1EvRqAwkmKEet0GLEbCmvadaDFfcc1mGi7mmN16ATrBqkGdpWXTOqAGhK5WTfq6+ZIP Z11o5bPE3hmSyPpwPx6DHuoHfNMvOS36o/kS6NMiQSWWRHJPfqau+uc7PEf+yTiCumKS 9dUg== 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=xMgzax4HjoaAL0uerD4B+UL3X0tNIUoyb0iGc+fPFY0=; b=taQ7s0Smyob8VVz5xSuUn+SqFwgG5pDcezq7XH6ThnBmMNnZkMHj2N08ZvG0fXG9af o5qs9k9mn3vUR5HwFM+xeO93y5NJv6kwuLeQ0x0E+d1igzfBEK4m3gEmPKcZZ5Xb+xWF 4ln4PIcjpGL4TSwD0bs/UAijiE0od48dB++55sxFTl8AyIiedKom7BEd9jG7uT0poNOi VPm4Mhn1Dyfl+OM0FCysjyBgFTq9fFggoeJK30ZwQU3wNlFGou5xfJGcyLt1vWdgMGpk vJ2bTIvWfJ5Y8rLGV37KjUWVHWgHn82h1ApzAm56SjU1Ebydzwjwg4N2wUZ7UykHiEx/ Jr8Q== X-Gm-Message-State: APjAAAWcNemjMUDqyZhAY84POtZHoA6xso70geKqZTJqHmpL2Sna9h3E 3tzITcACMBpDFGT7kMm47T0= X-Received: by 2002:a63:6d8d:: with SMTP id i135mr1290684pgc.303.1561713379501; Fri, 28 Jun 2019 02:16:19 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id x65sm1754521pfd.139.2019.06.28.02.16.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2019 02:16:19 -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 v3 08/30] locking/lockdep: Skip checks if direct dependency is already present Date: Fri, 28 Jun 2019 17:15:06 +0800 Message-Id: <20190628091528.17059-9-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190628091528.17059-1-duyuyang@gmail.com> References: <20190628091528.17059-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 When checking a dependency -> , two checks are performed: 1. Lock inversion deadlock: We search whether there is a path from to in the dependency graph for 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 it. 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. This 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 c61fdef..4ffb4df 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2363,6 +2363,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 , @@ -2389,21 +2408,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->nr_entries && !save_trace(trace)) return 0; -- 1.8.3.1