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

locking/lockdep: Change type of the element field in circular_queue

The element field is an array in struct circular_queue to keep track of locks
in the search. Making it the same type as the locks avoids type cast. Also
fix a typo and elaborate the comment above struct circular_queue.

No functional change.
Signed-off-by: default avatarYuyang Du <duyuyang@gmail.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: frederic@kernel.org
Cc: ming.lei@redhat.com
Cc: will.deacon@arm.com
Link: https://lkml.kernel.org/r/20190506081939.74287-13-duyuyang@gmail.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 31a490e5
...@@ -1262,13 +1262,17 @@ static int add_lock_to_list(struct lock_class *this, ...@@ -1262,13 +1262,17 @@ static int add_lock_to_list(struct lock_class *this,
#define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1)
/* /*
* The circular_queue and helpers is used to implement the * The circular_queue and helpers are used to implement graph
* breadth-first search(BFS)algorithem, by which we can build * breadth-first search (BFS) algorithm, by which we can determine
* the shortest path from the next lock to be acquired to the * whether there is a path from a lock to another. In deadlock checks,
* previous held lock if there is a circular between them. * a path from the next lock to be acquired to a previous held lock
* indicates that adding the <prev> -> <next> lock dependency will
* produce a circle in the graph. Breadth-first search instead of
* depth-first search is used in order to find the shortest (circular)
* path.
*/ */
struct circular_queue { struct circular_queue {
unsigned long element[MAX_CIRCULAR_QUEUE_SIZE]; struct lock_list *element[MAX_CIRCULAR_QUEUE_SIZE];
unsigned int front, rear; unsigned int front, rear;
}; };
...@@ -1294,7 +1298,7 @@ static inline int __cq_full(struct circular_queue *cq) ...@@ -1294,7 +1298,7 @@ static inline int __cq_full(struct circular_queue *cq)
return ((cq->rear + 1) & CQ_MASK) == cq->front; return ((cq->rear + 1) & CQ_MASK) == cq->front;
} }
static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) static inline int __cq_enqueue(struct circular_queue *cq, struct lock_list *elem)
{ {
if (__cq_full(cq)) if (__cq_full(cq))
return -1; return -1;
...@@ -1304,7 +1308,7 @@ static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) ...@@ -1304,7 +1308,7 @@ static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem)
return 0; return 0;
} }
static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) static inline int __cq_dequeue(struct circular_queue *cq, struct lock_list **elem)
{ {
if (__cq_empty(cq)) if (__cq_empty(cq))
return -1; return -1;
...@@ -1382,12 +1386,12 @@ static int __bfs(struct lock_list *source_entry, ...@@ -1382,12 +1386,12 @@ static int __bfs(struct lock_list *source_entry,
goto exit; goto exit;
__cq_init(cq); __cq_init(cq);
__cq_enqueue(cq, (unsigned long)source_entry); __cq_enqueue(cq, source_entry);
while (!__cq_empty(cq)) { while (!__cq_empty(cq)) {
struct lock_list *lock; struct lock_list *lock;
__cq_dequeue(cq, (unsigned long *)&lock); __cq_dequeue(cq, &lock);
if (!lock->class) { if (!lock->class) {
ret = -2; ret = -2;
...@@ -1411,7 +1415,7 @@ static int __bfs(struct lock_list *source_entry, ...@@ -1411,7 +1415,7 @@ static int __bfs(struct lock_list *source_entry,
goto exit; goto exit;
} }
if (__cq_enqueue(cq, (unsigned long)entry)) { if (__cq_enqueue(cq, entry)) {
ret = -1; ret = -1;
goto exit; goto exit;
} }
......
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