Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp407569yba; Wed, 24 Apr 2019 03:26:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKPbO7gRlXc7ZHr/YFGDBpyjjJebRBavFF5TOcmzIBB2kf8MjVvBPBQtxO2ox1J6Qpt8xI X-Received: by 2002:a63:6988:: with SMTP id e130mr30227573pgc.150.1556101594290; Wed, 24 Apr 2019 03:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556101594; cv=none; d=google.com; s=arc-20160816; b=wX9NdOo0CLFqt8DeXwodG2AIzem9w80+pgxR5PZ05VHp7RSDpIx8LSqQKSOI7CW7kj gSGiZE6Odjak5kOOYqKOWSDx+lKRQ3T2Mx6wf9ZL5ega8ZgGAdx4ijXKXGVHRLpc/7vw wl5LZpHOOIc1Cvx89JyhrxQpveadiNI+1soDAaDoT8mYi95x5yT6txkPSN6GIZ1Va1sF ah5yhmIVzkhBCAfNNvd2V8FO9JFg4VsgQyGdflegVLdy4+faqbDdBVdCjOXhNkpXDlYd sJU77WtycbALJsPIJM0iW6ky8XYdez30Srnb5I87/SS7KcjB2YJtSAV42uGvQJZeQjZG xiWQ== 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=iDO37esfHaDtszPueRakP7VqmTqFEoXaIhsG37nsoAI=; b=kRrzSxFUkTf+a8MxbtXdUY7B7YqnZED0c1T4YPo121/pnuIzwHQnpNB/SQN6Kg1xgd dM3OHWDqODYqNL8qMymlDvCZSkqq8a64yR3ByG3e6CbIvGcw+8Bdg1EOdBaBm0coFLBl RSt/tUc+UPiMA8bpwRQi3mv4MTRKJDiqjvNVP83qemiiS5qSGjlnF9nb1XeUAN54BT5c bo5IFw1I++8nROyQU0VSsgnFHmdbPHZeZhVH2Obg8aiqMODPlmoUgJ9vtCkLJIaRHrcG g4XA7cg7fvqzXu7xX2xfC4+OWrLW3Xegs7HuQHBJ1dszg6z4gy989sehwNeVX+PnFsu5 D5ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hQEJzMsY; 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 a36si17639665pgb.165.2019.04.24.03.26.19; Wed, 24 Apr 2019 03:26:34 -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=hQEJzMsY; 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 S1729547AbfDXKVO (ORCPT + 99 others); Wed, 24 Apr 2019 06:21:14 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:32928 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729498AbfDXKVL (ORCPT ); Wed, 24 Apr 2019 06:21:11 -0400 Received: by mail-pf1-f193.google.com with SMTP id h5so9088060pfo.0 for ; Wed, 24 Apr 2019 03:21:10 -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=iDO37esfHaDtszPueRakP7VqmTqFEoXaIhsG37nsoAI=; b=hQEJzMsYKZtntAo4S4k8JtJ8uneUYlnpOQmJnEUwS1KyIX+RgEnNREa7ZBGI2jADXO yIEn2yRZkYOsiqyog5F7SINQRXqh+8K3tqPSCq5Yri8W18KpukkLjlVUmO476kOeJSbM m6oJykhYhsOBSkoD16ZkDq+Rk85h6uvfVUNL6MNiZEjb9+KJ4ASdCl0kjMtqMECyu0X0 mSBneySe6rhq5vtU8TA+u6cAD1eDorsuLodK0vIsJrIx4kwau2IgxPuuYhxjhgycSQVB e+BBhVeeZc2wugVffDFmukQ5G1W/zscJlto9WIZObPIzN86v/sfFZjDbtXLDZgiezv9v oxeg== 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=iDO37esfHaDtszPueRakP7VqmTqFEoXaIhsG37nsoAI=; b=Ltz4ZXEthVkJYbIDcJW3xCFszRc25H6qBAp5hEwyUv9Zx12mRH7vgSnE2SfgwI5gD8 4ELmwx9eLexUABWeNznU777a41VYRcm2ATHpsOWlRcPnR1WDSA50OaA7kc+A7xP6xqOd 62d4q517zQ3p1AQxKqx142K8SKW3P+aIfUz/6ctKox99Ww0odMRC49Mz8k0AHsd1srZV mEAizze35JmO1fUGGYcwT+WBUt9FpX/6yr5gv+BznCNNqgX9Tc1kSVXQGlihygu1wYsG d8ZdZruFMzdT44LP8CBbhKs7BJDQBMxcnjYCSwjgAZvOCs1UxsUQEcB2dHkwm4rTn68/ cjLQ== X-Gm-Message-State: APjAAAWNe7zQt+bvmlAPlJAGrdA9LtR+4AeNZtuTnyTGE0fzhN8qPGai TLMy7/uaGx/mbH9y0zuRjIY= X-Received: by 2002:a65:4302:: with SMTP id j2mr29551718pgq.291.1556101270688; Wed, 24 Apr 2019 03:21:10 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm25051604pfn.62.2019.04.24.03.21.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 03:21:10 -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 14/28] locking/lockdep: Avoid constant checks in __bfs by using offset reference Date: Wed, 24 Apr 2019 18:19:20 +0800 Message-Id: <20190424101934.51535-15-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190424101934.51535-1-duyuyang@gmail.com> References: <20190424101934.51535-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 225eeeb..16f524c 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1361,11 +1361,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; @@ -1379,11 +1393,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; @@ -1397,10 +1407,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()); @@ -1433,7 +1440,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)); } @@ -1442,7 +1450,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