Commit c52478f4 authored by Yuyang Du's avatar Yuyang Du Committed by Ingo Molnar

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: default avatarYuyang Du <duyuyang@gmail.com>
Signed-off-by: default avatarPeter 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.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent c01fbbc8
...@@ -500,15 +500,26 @@ static inline unsigned long lock_flag(enum lock_usage_bit bit) ...@@ -500,15 +500,26 @@ static inline unsigned long lock_flag(enum lock_usage_bit bit)
static char get_usage_char(struct lock_class *class, enum lock_usage_bit bit) static char get_usage_char(struct lock_class *class, enum lock_usage_bit bit)
{ {
/*
* The usage character defaults to '.' (i.e., irqs disabled and not in
* irq context), which is the safest usage category.
*/
char c = '.'; char c = '.';
if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) /*
* The order of the following usage checks matters, which will
* result in the outcome character as follows:
*
* - '+': irq is enabled and not in irq context
* - '-': in irq context and irq is disabled
* - '?': in irq context and irq is enabled
*/
if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK)) {
c = '+'; c = '+';
if (class->usage_mask & lock_flag(bit)) { if (class->usage_mask & lock_flag(bit))
c = '-';
if (class->usage_mask & lock_flag(bit + LOCK_USAGE_DIR_MASK))
c = '?'; c = '?';
} } else if (class->usage_mask & lock_flag(bit))
c = '-';
return c; return c;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment