aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/locking
diff options
context:
space:
mode:
authorYuyang Du <duyuyang@gmail.com>2019-05-06 04:19:19 -0400
committerIngo Molnar <mingo@kernel.org>2019-06-03 05:55:35 -0400
commitc52478f4f38ace598475413a08dba9b9fd827eaf (patch)
tree7218b89f958ba7d764a6de1f3b81b43bfa6d75bd /kernel/locking
parentc01fbbc83f42748b3ed094497933601e6c9e0a03 (diff)
locking/lockdep: Adjust lock usage bit character checks
The lock usage bit characters are defined and determined with tricks. Add some explanation to make it a bit clearer, then adjust the logic to check the usage, which optimizes the code a bit. 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-4-duyuyang@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/locking')
-rw-r--r--kernel/locking/lockdep.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 109b56267c8f..a033df00fd1d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -500,15 +500,26 @@ static inline unsigned long lock_flag(enum lock_usage_bit bit)
500 500
501static char get_usage_char(struct lock_class *class, enum lock_usage_bit bit) 501static char get_usage_char(struct lock_class *class, enum lock_usage_bit bit)
502{ 502{
503 /*
504 * The usage character defaults to '.' (i.e., irqs disabled and not in
505 * irq context), which is the safest usage category.
506 */
503 char c = '.'; 507 char c = '.';
504 508
505 if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) 509 /*
510 * The order of the following usage checks matters, which will
511 * result in the outcome character as follows:
512 *
513 * - '+': irq is enabled and not in irq context
514 * - '-': in irq context and irq is disabled
515 * - '?': in irq context and irq is enabled
516 */
517 if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) {
506 c = '+'; 518 c = '+';
507 if (class->usage_mask & lock_flag(bit)) { 519 if (class->usage_mask & lock_flag(bit))
508 c = '-';
509 if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK))
510 c = '?'; 520 c = '?';
511 } 521 } else if (class->usage_mask & lock_flag(bit))
522 c = '-';
512 523
513 return c; 524 return c;
514} 525}