aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/locking
diff options
context:
space:
mode:
authorYuyang Du <duyuyang@gmail.com>2019-05-06 04:19:30 -0400
committerIngo Molnar <mingo@kernel.org>2019-06-03 05:55:46 -0400
commit77a806922cfdebcf3ae89d31a8b592a7f7fbe537 (patch)
treefd339161dfc2d3078a6827f16dfda8ab5a217621 /kernel/locking
parentc1661325597f68bc9e632c4fa9c86983d56fba4f (diff)
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 <duyuyang@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> 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 <mingo@kernel.org>
Diffstat (limited to 'kernel/locking')
-rw-r--r--kernel/locking/lockdep.c33
1 files 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)
1367 return depth; 1367 return depth;
1368} 1368}
1369 1369
1370/*
1371 * Return the forward or backward dependency list.
1372 *
1373 * @lock: the lock_list to get its class's dependency list
1374 * @offset: the offset to struct lock_class to determine whether it is
1375 * locks_after or locks_before
1376 */
1377static inline struct list_head *get_dep_list(struct lock_list *lock, int offset)
1378{
1379 void *lock_class = lock->class;
1380
1381 return lock_class + offset;
1382}
1383
1370static int __bfs(struct lock_list *source_entry, 1384static int __bfs(struct lock_list *source_entry,
1371 void *data, 1385 void *data,
1372 int (*match)(struct lock_list *entry, void *data), 1386 int (*match)(struct lock_list *entry, void *data),
1373 struct lock_list **target_entry, 1387 struct lock_list **target_entry,
1374 int forward) 1388 int offset)
1375{ 1389{
1376 struct lock_list *entry; 1390 struct lock_list *entry;
1377 struct lock_list *lock; 1391 struct lock_list *lock;
@@ -1385,11 +1399,7 @@ static int __bfs(struct lock_list *source_entry,
1385 goto exit; 1399 goto exit;
1386 } 1400 }
1387 1401
1388 if (forward) 1402 head = get_dep_list(source_entry, offset);
1389 head = &source_entry->class->locks_after;
1390 else
1391 head = &source_entry->class->locks_before;
1392
1393 if (list_empty(head)) 1403 if (list_empty(head))
1394 goto exit; 1404 goto exit;
1395 1405
@@ -1403,10 +1413,7 @@ static int __bfs(struct lock_list *source_entry,
1403 goto exit; 1413 goto exit;
1404 } 1414 }
1405 1415
1406 if (forward) 1416 head = get_dep_list(lock, offset);
1407 head = &lock->class->locks_after;
1408 else
1409 head = &lock->class->locks_before;
1410 1417
1411 DEBUG_LOCKS_WARN_ON(!irqs_disabled()); 1418 DEBUG_LOCKS_WARN_ON(!irqs_disabled());
1412 1419
@@ -1439,7 +1446,8 @@ static inline int __bfs_forwards(struct lock_list *src_entry,
1439 int (*match)(struct lock_list *entry, void *data), 1446 int (*match)(struct lock_list *entry, void *data),
1440 struct lock_list **target_entry) 1447 struct lock_list **target_entry)
1441{ 1448{
1442 return __bfs(src_entry, data, match, target_entry, 1); 1449 return __bfs(src_entry, data, match, target_entry,
1450 offsetof(struct lock_class, locks_after));
1443 1451
1444} 1452}
1445 1453
@@ -1448,7 +1456,8 @@ static inline int __bfs_backwards(struct lock_list *src_entry,
1448 int (*match)(struct lock_list *entry, void *data), 1456 int (*match)(struct lock_list *entry, void *data),
1449 struct lock_list **target_entry) 1457 struct lock_list **target_entry)
1450{ 1458{
1451 return __bfs(src_entry, data, match, target_entry, 0); 1459 return __bfs(src_entry, data, match, target_entry,
1460 offsetof(struct lock_class, locks_before));
1452 1461
1453} 1462}
1454 1463