diff options
author | Yuyang Du <duyuyang@gmail.com> | 2019-05-06 04:19:28 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2019-06-03 05:55:45 -0400 |
commit | aa4807719e076bfb2dee9c96adf2c648e47d472f (patch) | |
tree | 8e370d7c74b894b502d798d529d4ca25e3b80562 | |
parent | 31a490e5c54f5499aa744f8524611e2a4b19f8ba (diff) |
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: Yuyang Du <duyuyang@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Bart 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.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/locking/lockdep.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index a9799f9ed093..d467ba825dca 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c | |||
@@ -1262,13 +1262,17 @@ static int add_lock_to_list(struct lock_class *this, | |||
1262 | #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) | 1262 | #define CQ_MASK (MAX_CIRCULAR_QUEUE_SIZE-1) |
1263 | 1263 | ||
1264 | /* | 1264 | /* |
1265 | * The circular_queue and helpers is used to implement the | 1265 | * The circular_queue and helpers are used to implement graph |
1266 | * breadth-first search(BFS)algorithem, by which we can build | 1266 | * breadth-first search (BFS) algorithm, by which we can determine |
1267 | * the shortest path from the next lock to be acquired to the | 1267 | * whether there is a path from a lock to another. In deadlock checks, |
1268 | * previous held lock if there is a circular between them. | 1268 | * a path from the next lock to be acquired to a previous held lock |
1269 | * indicates that adding the <prev> -> <next> lock dependency will | ||
1270 | * produce a circle in the graph. Breadth-first search instead of | ||
1271 | * depth-first search is used in order to find the shortest (circular) | ||
1272 | * path. | ||
1269 | */ | 1273 | */ |
1270 | struct circular_queue { | 1274 | struct circular_queue { |
1271 | unsigned long element[MAX_CIRCULAR_QUEUE_SIZE]; | 1275 | struct lock_list *element[MAX_CIRCULAR_QUEUE_SIZE]; |
1272 | unsigned int front, rear; | 1276 | unsigned int front, rear; |
1273 | }; | 1277 | }; |
1274 | 1278 | ||
@@ -1294,7 +1298,7 @@ static inline int __cq_full(struct circular_queue *cq) | |||
1294 | return ((cq->rear + 1) & CQ_MASK) == cq->front; | 1298 | return ((cq->rear + 1) & CQ_MASK) == cq->front; |
1295 | } | 1299 | } |
1296 | 1300 | ||
1297 | static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | 1301 | static inline int __cq_enqueue(struct circular_queue *cq, struct lock_list *elem) |
1298 | { | 1302 | { |
1299 | if (__cq_full(cq)) | 1303 | if (__cq_full(cq)) |
1300 | return -1; | 1304 | return -1; |
@@ -1304,7 +1308,7 @@ static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | |||
1304 | return 0; | 1308 | return 0; |
1305 | } | 1309 | } |
1306 | 1310 | ||
1307 | static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) | 1311 | static inline int __cq_dequeue(struct circular_queue *cq, struct lock_list **elem) |
1308 | { | 1312 | { |
1309 | if (__cq_empty(cq)) | 1313 | if (__cq_empty(cq)) |
1310 | return -1; | 1314 | return -1; |
@@ -1382,12 +1386,12 @@ static int __bfs(struct lock_list *source_entry, | |||
1382 | goto exit; | 1386 | goto exit; |
1383 | 1387 | ||
1384 | __cq_init(cq); | 1388 | __cq_init(cq); |
1385 | __cq_enqueue(cq, (unsigned long)source_entry); | 1389 | __cq_enqueue(cq, source_entry); |
1386 | 1390 | ||
1387 | while (!__cq_empty(cq)) { | 1391 | while (!__cq_empty(cq)) { |
1388 | struct lock_list *lock; | 1392 | struct lock_list *lock; |
1389 | 1393 | ||
1390 | __cq_dequeue(cq, (unsigned long *)&lock); | 1394 | __cq_dequeue(cq, &lock); |
1391 | 1395 | ||
1392 | if (!lock->class) { | 1396 | if (!lock->class) { |
1393 | ret = -2; | 1397 | ret = -2; |
@@ -1411,7 +1415,7 @@ static int __bfs(struct lock_list *source_entry, | |||
1411 | goto exit; | 1415 | goto exit; |
1412 | } | 1416 | } |
1413 | 1417 | ||
1414 | if (__cq_enqueue(cq, (unsigned long)entry)) { | 1418 | if (__cq_enqueue(cq, entry)) { |
1415 | ret = -1; | 1419 | ret = -1; |
1416 | goto exit; | 1420 | goto exit; |
1417 | } | 1421 | } |