From: Yuyang Du <duyuyang@gmail.com>
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 <duyuyang@gmail.com>
Subject: [PATCH v4 14/30] locking/lockdep: Combine lock_lists in struct lock_class into an array
Date: Thu, 29 Aug 2019 16:31:16 +0800 [thread overview]
Message-ID: <20190829083132.22394-15-duyuyang@gmail.com> (raw)
In-Reply-To: <20190829083132.22394-1-duyuyang@gmail.com>
We are going to combine forward dependency lock_lists and backward
dependency lock_lists. To prepare for that, we combine locks_before and
locks_after lists, which makes the codes a bit clearer after all.
No functional change.
Signed-off-by: Yuyang Du <duyuyang@gmail.com>
---
include/linux/lockdep.h | 6 ++---
kernel/locking/lockdep.c | 63 +++++++++++++++++++------------------------
kernel/locking/lockdep_proc.c | 2 +-
3 files changed, 32 insertions(+), 39 deletions(-)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 0246a70..06b686d 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -89,10 +89,10 @@ struct lock_class {
/*
* These fields represent a directed graph of lock dependencies,
- * to every node we attach a list of "forward" and a list of
- * "backward" graph nodes.
+ * to every node we attach a list of "forward" graph nodes
+ * @dep_list[1] and a list of "backward" graph nodes @dep_list[0].
*/
- struct list_head locks_after, locks_before;
+ struct list_head dep_list[2];
const struct lockdep_subclass_key *key;
unsigned int subclass;
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 21d9e99..8c53b59 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -901,8 +901,7 @@ static bool in_list(struct list_head *e, struct list_head *h)
}
/*
- * Check whether entry @e occurs in any of the locks_after or locks_before
- * lists.
+ * Check whether entry @e occurs in any of the dep lists.
*/
static bool in_any_class_list(struct list_head *e)
{
@@ -911,8 +910,8 @@ static bool in_any_class_list(struct list_head *e)
for (i = 0; i < ARRAY_SIZE(lock_classes); i++) {
class = &lock_classes[i];
- if (in_list(e, &class->locks_after) ||
- in_list(e, &class->locks_before))
+ if (in_list(e, &class->dep_list[0]) ||
+ in_list(e, &class->dep_list[1]))
return true;
}
return false;
@@ -1000,9 +999,9 @@ static bool __check_data_structures(void)
/* Check whether all classes have valid lock lists. */
for (i = 0; i < ARRAY_SIZE(lock_classes); i++) {
class = &lock_classes[i];
- if (!class_lock_list_valid(class, &class->locks_before))
+ if (!class_lock_list_valid(class, &class->dep_list[0]))
return false;
- if (!class_lock_list_valid(class, &class->locks_after))
+ if (!class_lock_list_valid(class, &class->dep_list[1]))
return false;
}
@@ -1098,8 +1097,8 @@ static void init_data_structures_once(void)
for (i = 0; i < ARRAY_SIZE(lock_classes); i++) {
list_add_tail(&lock_classes[i].lock_entry, &free_lock_classes);
- INIT_LIST_HEAD(&lock_classes[i].locks_after);
- INIT_LIST_HEAD(&lock_classes[i].locks_before);
+ INIT_LIST_HEAD(&lock_classes[i].dep_list[0]);
+ INIT_LIST_HEAD(&lock_classes[i].dep_list[1]);
}
}
@@ -1228,8 +1227,8 @@ static bool is_dynamic_key(const struct lock_class_key *key)
class->key = key;
class->name = lock->name;
class->subclass = subclass;
- WARN_ON_ONCE(!list_empty(&class->locks_before));
- WARN_ON_ONCE(!list_empty(&class->locks_after));
+ WARN_ON_ONCE(!list_empty(&class->dep_list[0]));
+ WARN_ON_ONCE(!list_empty(&class->dep_list[1]));
class->name_version = count_matching_names(class);
/*
* We use RCU's safe list-add method to make
@@ -1448,15 +1447,14 @@ static inline int get_lock_depth(struct lock_list *child)
/*
* 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
+ * @lock: the lock_list to get its class's dependency list
+ * @forward: the forward dep list or backward dep list
*/
-static inline struct list_head *get_dep_list(struct lock_list *lock, int offset)
+static inline struct list_head *get_dep_list(struct lock_list *lock, int forward)
{
- void *lock_class = lock->class;
+ struct lock_class *class = lock->class;
- return lock_class + offset;
+ return &class->dep_list[forward];
}
/*
@@ -1466,8 +1464,7 @@ static inline struct list_head *get_dep_list(struct lock_list *lock, int 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 offset)
+ struct lock_list **target_entry, int forward)
{
struct lock_list *entry;
struct lock_list *lock;
@@ -1481,7 +1478,7 @@ static int __bfs(struct lock_list *source_entry,
goto exit;
}
- head = get_dep_list(source_entry, offset);
+ head = get_dep_list(source_entry, forward);
if (list_empty(head))
goto exit;
@@ -1495,7 +1492,7 @@ static int __bfs(struct lock_list *source_entry,
goto exit;
}
- head = get_dep_list(lock, offset);
+ head = get_dep_list(lock, forward);
DEBUG_LOCKS_WARN_ON(!irqs_disabled());
@@ -1528,9 +1525,7 @@ 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,
- offsetof(struct lock_class, locks_after));
-
+ return __bfs(src_entry, data, match, target_entry, 1);
}
static inline int __bfs_backwards(struct lock_list *src_entry,
@@ -1538,9 +1533,7 @@ 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,
- offsetof(struct lock_class, locks_before));
-
+ return __bfs(src_entry, data, match, target_entry, 0);
}
static void print_lock_trace(const struct lock_trace *trace,
@@ -2445,7 +2438,7 @@ static inline void inc_chains(void)
* 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) {
+ list_for_each_entry(entry, &hlock_class(prev)->dep_list[1], entry) {
if (entry->class == hlock_class(next)) {
debug_atomic_inc(nr_redundant);
@@ -2495,14 +2488,14 @@ static inline void inc_chains(void)
* to the previous lock's dependency list:
*/
ret = add_lock_to_list(hlock_class(next), hlock_class(prev),
- &hlock_class(prev)->locks_after,
+ &hlock_class(prev)->dep_list[1],
next->acquire_ip, distance, *trace);
if (!ret)
return 0;
ret = add_lock_to_list(hlock_class(prev), hlock_class(next),
- &hlock_class(next)->locks_before,
+ &hlock_class(next)->dep_list[0],
next->acquire_ip, distance, *trace);
if (!ret)
return 0;
@@ -4811,8 +4804,8 @@ static void zap_class(struct pending_free *pf, struct lock_class *class)
nr_list_entries--;
list_del_rcu(&entry->entry);
}
- if (list_empty(&class->locks_after) &&
- list_empty(&class->locks_before)) {
+ if (list_empty(&class->dep_list[0]) &&
+ list_empty(&class->dep_list[1])) {
list_move_tail(&class->lock_entry, &pf->zapped);
hlist_del_rcu(&class->hash_entry);
WRITE_ONCE(class->key, NULL);
@@ -4833,12 +4826,12 @@ static void reinit_class(struct lock_class *class)
const unsigned int offset = offsetof(struct lock_class, key);
WARN_ON_ONCE(!class->lock_entry.next);
- WARN_ON_ONCE(!list_empty(&class->locks_after));
- WARN_ON_ONCE(!list_empty(&class->locks_before));
+ WARN_ON_ONCE(!list_empty(&class->dep_list[0]));
+ WARN_ON_ONCE(!list_empty(&class->dep_list[1]));
memset(p + offset, 0, sizeof(*class) - offset);
WARN_ON_ONCE(!class->lock_entry.next);
- WARN_ON_ONCE(!list_empty(&class->locks_after));
- WARN_ON_ONCE(!list_empty(&class->locks_before));
+ WARN_ON_ONCE(!list_empty(&class->dep_list[0]));
+ WARN_ON_ONCE(!list_empty(&class->dep_list[1]));
}
static inline int within(const void *addr, void *start, unsigned long size)
diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index edc4a7b..989c27e 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -82,7 +82,7 @@ static int l_show(struct seq_file *m, void *v)
print_name(m, class);
seq_puts(m, "\n");
- list_for_each_entry(entry, &class->locks_after, entry) {
+ list_for_each_entry(entry, &class->dep_list[1], entry) {
if (entry->distance == 1) {
seq_printf(m, " -> [%p] ", entry->class->key);
print_name(m, entry->class);
--
1.8.3.1
next prev parent reply other threads:[~2019-08-29 8:32 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 8:31 [PATCH v4 00/30] Support recursive-read lock deadlock detection Yuyang Du
2019-08-29 8:31 ` [PATCH v4 01/30] locking/lockdep: Rename deadlock check functions Yuyang Du
2019-08-29 8:31 ` [PATCH v4 02/30] locking/lockdep: Change return type of add_chain_cache() Yuyang Du
2019-08-29 8:31 ` [PATCH v4 03/30] locking/lockdep: Change return type of lookup_chain_cache_add() Yuyang Du
2019-08-29 8:31 ` [PATCH v4 04/30] locking/lockdep: Pass lock chain from validate_chain() to check_prev_add() Yuyang Du
2019-08-29 8:31 ` [PATCH v4 05/30] locking/lockdep: Add lock chain list_head field in struct lock_list and lock_chain Yuyang Du
2019-08-29 8:31 ` [PATCH v4 06/30] locking/lockdep: Update comments in struct lock_list and held_lock Yuyang Du
2019-08-29 8:31 ` [PATCH v4 07/30] locking/lockdep: Remove indirect dependency redundancy check Yuyang Du
2019-08-29 8:31 ` [PATCH v4 08/30] locking/lockdep: Skip checks if direct dependency is already present Yuyang Du
2019-08-29 8:31 ` [PATCH v4 09/30] locking/lockdep: Remove chain_head argument in validate_chain() Yuyang Du
2019-08-29 8:31 ` [PATCH v4 10/30] locking/lockdep: Remove useless lock type assignment Yuyang Du
2019-08-29 8:31 ` [PATCH v4 11/30] locking/lockdep: Remove irq-safe to irq-unsafe read check Yuyang Du
2019-08-29 8:31 ` [PATCH v4 12/30] locking/lockdep: Specify the depth of current lock stack in lookup_chain_cache_add() Yuyang Du
2019-08-29 8:31 ` [PATCH v4 13/30] locking/lockdep: Treat every lock dependency as in a new lock chain Yuyang Du
2019-08-29 8:31 ` Yuyang Du [this message]
2019-08-29 8:31 ` [PATCH v4 15/30] locking/lockdep: Consolidate forward and backward lock_lists into one Yuyang Du
2019-08-29 8:31 ` [PATCH v4 16/30] locking/lockdep: Add lock chains to direct lock dependency graph Yuyang Du
2019-08-29 8:31 ` [PATCH v4 17/30] locking/lockdep: Use lock type enum to explicitly specify read or write locks Yuyang Du
2019-08-29 8:31 ` [PATCH v4 18/30] ocking/lockdep: Add read-write type for a lock dependency Yuyang Du
2019-08-29 8:31 ` [PATCH v4 19/30] locking/lockdep: Add helper functions to operate on the searched path Yuyang Du
2019-08-29 8:31 ` [PATCH v4 20/30] locking/lockdep: Update direct dependency's read-write type if it exists Yuyang Du
2019-08-29 8:31 ` [PATCH v4 21/30] locking/lockdep: Introduce chain_hlocks_type for held lock's read-write type Yuyang Du
2019-08-29 8:31 ` [PATCH v4 22/30] locking/lockdep: Hash held lock's read-write type into chain key Yuyang Du
2019-08-29 8:31 ` [PATCH v4 23/30] locking/lockdep: Adjust BFS algorithm to support multiple matches Yuyang Du
2019-08-29 8:31 ` [PATCH v4 24/30] locking/lockdep: Define the two task model for lockdep checks formally Yuyang Du
2019-08-29 8:31 ` [PATCH v4 25/30] locking/lockdep: Introduce mark_lock_unaccessed() Yuyang Du
2019-08-29 8:31 ` [PATCH v4 26/30] locking/lockdep: Add nest lock type Yuyang Du
2019-08-29 8:31 ` [PATCH v4 27/30] locking/lockdep: Add lock exclusiveness table Yuyang Du
2019-08-29 8:31 ` [PATCH v4 28/30] locking/lockdep: Support read-write lock's deadlock detection Yuyang Du
2019-08-29 8:31 ` [PATCH v4 29/30] locking/lockdep: Adjust selftest case for recursive read lock Yuyang Du
2019-08-29 8:31 ` [PATCH v4 30/30] locking/lockdep: Add more lockdep selftest cases Yuyang Du
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190829083132.22394-15-duyuyang@gmail.com \
--to=duyuyang@gmail.com \
--cc=boqun.feng@gmail.com \
--cc=bvanassche@acm.org \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=ming.lei@redhat.com \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®