Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2202399yba; Mon, 6 May 2019 01:23:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdxJvpFCk/jUGKSTXgRqkh2hG2po129psc2Mgj8tjHaVrRS/G9VjADRUwdsyeQlQJHUMWA X-Received: by 2002:aa7:99dd:: with SMTP id v29mr32615449pfi.252.1557131012092; Mon, 06 May 2019 01:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557131012; cv=none; d=google.com; s=arc-20160816; b=VuPukD9/Ivjpwaq0Qhn/HP+L8wohJYc5yiiOyGnpaQUQsKa/SYt2AZt2tx/DLmcOgH 0S7U4TL1kmgEizBh0+0zPpBWseslREqPTyXxhZpZ5TWyt/26nt+LC0zg7WxEewx2yVlt 97tDsBw5CqjJxdYcVdjoTtxqjskI+XGTpaawSvfHoKQOaAlh/6VjHEz+txli++RfYRRe du4O8a5P9DOHrsdHvj6wLv7WltSGS+kQC75tD2/IGXuSUZOCWMQI7SOhzlXuoBUsrDlv JKSbqTEHt43CcRlLAUftGN0XnUhpSbXL+Tuy2UNnOnyj+Hc84Afo5uMC0SXU12ddWBTN 38OQ== 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=YR1uPUJkVk7yfuNsYEGBjpJtJTSenXj3xCLi83CgQCQ=; b=ghO1aQzmbM4/Ua3X8FiZc+XZR6Ig8+EyjsNAAd1NoNY2Wh5WU8+rfjEwkFw2+ooWg2 f5i+CJ5NeDQupxe1hNAtgzNvzVI52OHtxDLjXmZ5pliJmoFkWSe58+ceVCFGT4g9aju0 tSVMnn+dbh+VfDaRO49ccV+A+5kSA6kiHVRkVfzaLiVJyuqcIGOWy9PXhfpzAnHqDVvq FI0zfQ2OGEJ2WuO3H4KUADmOAH3Ymw+NynzIB0PxVlKw8avD+vfAMb2YI/lHJJjnemgf fwwlWJMu+MU55pdHdCqA924zAkuv6KHoch7+l3kSLBdpPn8UGwHaotS4NKNJ0xPm5IwM 8uwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mCNkBV4I; 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 ce12si15823903plb.46.2019.05.06.01.23.16; Mon, 06 May 2019 01:23:32 -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=mCNkBV4I; 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 S1726791AbfEFIVu (ORCPT + 99 others); Mon, 6 May 2019 04:21:50 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34435 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbfEFIUe (ORCPT ); Mon, 6 May 2019 04:20:34 -0400 Received: by mail-pf1-f196.google.com with SMTP id b3so6362782pfd.1 for ; Mon, 06 May 2019 01:20:34 -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=YR1uPUJkVk7yfuNsYEGBjpJtJTSenXj3xCLi83CgQCQ=; b=mCNkBV4IgMyS5Odt2U30IIR20STOIrsRBiSP0iAHuqTxsIitdfPIOvgCVw3f0iThNg xvF5SQslWgY7IEa8zcRl4Wo29ldvHS1Dx9QY6MLj3ZonHU10yagK+aTXNKOSIU33KJ3B flLwkk8+h+BR3GN6GP2LrefuRfiK1Q/ZbksdJ7iTod7YYEZROV+ABgrS2JZYK1SvQwxB WxvoEUq/v+BTwsEt/rcgpO/AeEjMQ1yQXEfcbtbSUpnhH8Wu6wBetMWlkQ9BJBgCzxlH uA/1qJkYdiZlLiAaf+ApQDAooKfoda2a/wqoKcEsC6iucVOXkNS7g2Oxpr6t/MmhMn7G lQsg== 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=YR1uPUJkVk7yfuNsYEGBjpJtJTSenXj3xCLi83CgQCQ=; b=aTCMPwI5+Tp+5+6t3ooK9Ja3SFDZtOdL7wdbBoyV0HWBdGyfADhQsG40+e4e+fgZEz vChaqIkqltIl9nlTmPx9EbL/4XurJJRJQNuTnbr4q1PjDJpjfJkG8qFTNHxwfXaEi+rB pkmredy4zcWTIqYfgsVcBuF3io2lX3es7Oex11bo4C4tDQT52pRvxnF85/5fynx5n4v8 Rr5B3GGKKXzow9JpeNa/KeFik7Ng0fHTTfjuSLqd8NUIv9+bTvDegQW/dr+OOYBNzJod BYA7QsZWdr4u/8m5N8D9GUemkRhgzJBqy9Q30GlywHxlTvTgkjmLsXWiHVXYTBh86tT/ BNtg== X-Gm-Message-State: APjAAAViRUbvGPIZ3oKGLBr3FmNOMU16TLIagJcxJzZSOBaZq3eLGcS1 lEVmezxxGUoJmm5/+ID+HiQ= X-Received: by 2002:a63:7982:: with SMTP id u124mr30041388pgc.352.1557130833910; Mon, 06 May 2019 01:20:33 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm20958013pfa.138.2019.05.06.01.20.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 01:20:33 -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, Yuyang Du Subject: [PATCH v2 14/23] locking/lockdep: Avoid constant checks in __bfs by using offset reference Date: Mon, 6 May 2019 16:19:30 +0800 Message-Id: <20190506081939.74287-15-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190506081939.74287-1-duyuyang@gmail.com> References: <20190506081939.74287-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 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 --- 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 5a0c908f..15cf2ac 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1362,11 +1362,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; @@ -1380,11 +1394,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; @@ -1398,10 +1408,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()); @@ -1434,7 +1441,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)); } @@ -1443,7 +1451,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)); } -- 1.8.3.1