Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4136039ybi; Mon, 3 Jun 2019 06:19:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqx642RZNbpepKrFKhcOFpzaFr4+MlutPAzZF/X0Ai99n7UY2b0JVrIvCrYD2MCAvJiF4OQ/ X-Received: by 2002:a63:dc09:: with SMTP id s9mr28793875pgg.425.1559567941852; Mon, 03 Jun 2019 06:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559567941; cv=none; d=google.com; s=arc-20160816; b=s2LgGF0jFjsV6qCXWeV3a0hfjVclS//ALKH7dYfjeG18OfwJGYxH2vAimnj5Htpe6y TNXP2immlgpKhhYO02G44vryvbrpP3n7hOBAd5qlHV1b+zeprvNkUyqZzjojzzip065C Jz+C2TciVfXky9mOCQgB9XZk/Zmlncr4o/6G5Qe99wbpG43tJLYPe/XBMjGCPVmDdHtK nYYjUiXyIETrkp2oQSetmsYvIn19RggVk6j8ZrqVmBIjtyQTAacXEDTpbH9MhFPJS7eX k9mixcALHu3SzlG/QLDJtw1PCVldknriepDcMhlm81D/z1TvUP4f2wUzW/Tu2hWYY7M7 d0wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=N3GCtG4qp2uKDPSsWJs9UNW4xxGQ68oAJubnT5rBU1k=; b=FicEwgcpyj3iURKtr/zLOlyuGrlf0r9y3Ry+5P6IZMvhWbhLBADKH68voA0BUM1Tx/ DiiDI2uZqOfvr6hdKGJJF4XF/S5ko+TDxyqFSM6jHbJywLZQ6XiY9dHpKaYVkGUdC1Xj nNWvt8pShR4kVYFRaLF4vXiQJX2GiXsTMramdFm5DUlxrvRK6q0wevgD5jLF9Vtz+qHe C7QXT111NDey321ERzGNC5BpFtV9jMX5J38ufDHz9sOb+YdbnE8HjsC531yDHxnANrYY 2x0s9ypOawnlC6ARNysRbpF2urM31XIYmxoOHGpq2Q6Gyob2IYPIjFHaww348mP8v+ZD AJmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=ZQaR6WML; 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=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h2si7063031plh.368.2019.06.03.06.18.44; Mon, 03 Jun 2019 06:19:01 -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=@zytor.com header.s=2019051801 header.b=ZQaR6WML; 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=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbfFCNQC (ORCPT + 99 others); Mon, 3 Jun 2019 09:16:02 -0400 Received: from terminus.zytor.com ([198.137.202.136]:38933 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726516AbfFCNQC (ORCPT ); Mon, 3 Jun 2019 09:16:02 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x53DFps2606105 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 3 Jun 2019 06:15:51 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x53DFps2606105 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559567752; bh=N3GCtG4qp2uKDPSsWJs9UNW4xxGQ68oAJubnT5rBU1k=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=ZQaR6WMLWFQ40j3DCxflUQF+zLpWSp9+kwjxfRLLWF4MkjnmX6cHAjH4jNwyq8GFA oCm/aNJzDhJjWBAWC+DMQpaERMXxoBjPz+IQAd7vPzA9Pp4RT4bN6R4s1KIBHC5LFB BIejbm+vpSJeMjvMvh0m++3FWhkeVhxm+TAsCgyNTZ1LDZaG+3ZzgEl7meeAWe2xu6 rOaf/sFvIK+OUcWBS95ufAbPIBO8r/PM0mRkCjmLLz/hOMPRD5GQuy8jmSCgU3OZAN n5JMlYVZLXJ+GEHhwuwaFbLeRwPM243poJHJPDBARqNhYUxPIbNh1QnjTMH6nIjBEn ps123GpLRyJPQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x53DFoeF606102; Mon, 3 Jun 2019 06:15:50 -0700 Date: Mon, 3 Jun 2019 06:15:50 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Yuyang Du Message-ID: Cc: mingo@kernel.org, torvalds@linux-foundation.org, tglx@linutronix.de, hpa@zytor.com, duyuyang@gmail.com, linux-kernel@vger.kernel.org, peterz@infradead.org Reply-To: peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, hpa@zytor.com, duyuyang@gmail.com, mingo@kernel.org, torvalds@linux-foundation.org In-Reply-To: <20190506081939.74287-15-duyuyang@gmail.com> References: <20190506081939.74287-15-duyuyang@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/lockdep: Avoid constant checks in __bfs by using offset reference Git-Commit-ID: 77a806922cfdebcf3ae89d31a8b592a7f7fbe537 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.3 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 77a806922cfdebcf3ae89d31a8b592a7f7fbe537 Gitweb: https://git.kernel.org/tip/77a806922cfdebcf3ae89d31a8b592a7f7fbe537 Author: Yuyang Du AuthorDate: Mon, 6 May 2019 16:19:30 +0800 Committer: Ingo Molnar CommitDate: Mon, 3 Jun 2019 11:55:46 +0200 locking/lockdep: Avoid constant checks in __bfs by using offset reference In search of a dependency in the lock graph, there is contant checks for forward or backward search. Directly reference the field offset of the struct that differentiates the type of search to avoid those checks. No functional change. Signed-off-by: Yuyang Du Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: bvanassche@acm.org Cc: frederic@kernel.org Cc: ming.lei@redhat.com Cc: will.deacon@arm.com Link: https://lkml.kernel.org/r/20190506081939.74287-15-duyuyang@gmail.com Signed-off-by: Ingo Molnar --- kernel/locking/lockdep.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index d23dcb47389e..2e8ef6082f72 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1367,11 +1367,25 @@ static inline int get_lock_depth(struct lock_list *child) return depth; } +/* + * Return the forward or backward dependency list. + * + * @lock: the lock_list to get its class's dependency list + * @offset: the offset to struct lock_class to determine whether it is + * locks_after or locks_before + */ +static inline struct list_head *get_dep_list(struct lock_list *lock, int offset) +{ + void *lock_class = lock->class; + + return lock_class + offset; +} + static int __bfs(struct lock_list *source_entry, void *data, int (*match)(struct lock_list *entry, void *data), struct lock_list **target_entry, - int forward) + int offset) { struct lock_list *entry; struct lock_list *lock; @@ -1385,11 +1399,7 @@ static int __bfs(struct lock_list *source_entry, goto exit; } - if (forward) - head = &source_entry->class->locks_after; - else - head = &source_entry->class->locks_before; - + head = get_dep_list(source_entry, offset); if (list_empty(head)) goto exit; @@ -1403,10 +1413,7 @@ static int __bfs(struct lock_list *source_entry, goto exit; } - if (forward) - head = &lock->class->locks_after; - else - head = &lock->class->locks_before; + head = get_dep_list(lock, offset); DEBUG_LOCKS_WARN_ON(!irqs_disabled()); @@ -1439,7 +1446,8 @@ static inline int __bfs_forwards(struct lock_list *src_entry, int (*match)(struct lock_list *entry, void *data), struct lock_list **target_entry) { - return __bfs(src_entry, data, match, target_entry, 1); + return __bfs(src_entry, data, match, target_entry, + offsetof(struct lock_class, locks_after)); } @@ -1448,7 +1456,8 @@ static inline int __bfs_backwards(struct lock_list *src_entry, int (*match)(struct lock_list *entry, void *data), struct lock_list **target_entry) { - return __bfs(src_entry, data, match, target_entry, 0); + return __bfs(src_entry, data, match, target_entry, + offsetof(struct lock_class, locks_before)); }