diff options
author | Ming Lei <tom.leiming@gmail.com> | 2009-07-16 09:44:29 -0400 |
---|---|---|
committer | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2009-07-24 04:49:46 -0400 |
commit | d588e46155e9c51217b9840db1e94a0f594c1af2 (patch) | |
tree | 0ede7d7d8338f8db15d8c690c46a0173196d7bac | |
parent | c94aa5ca3088018d2a7a9bd3258aefffe29df265 (diff) |
lockdep: Improve implementation of BFS
1,replace %MAX_CIRCULAR_QUE_SIZE with &(MAX_CIRCULAR_QUE_SIZE-1)
since we define MAX_CIRCULAR_QUE_SIZE as power of 2;
2,use bitmap to mark if a lock is accessed in BFS in order to
clear it quickly, because we may search a graph many times.
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1246201486-7308-3-git-send-email-tom.leiming@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | kernel/lockdep.c | 23 | ||||
-rw-r--r-- | kernel/lockdep_internals.h | 35 |
2 files changed, 39 insertions, 19 deletions
diff --git a/kernel/lockdep.c b/kernel/lockdep.c index 93dc70d18cdf..5dcca26a8263 100644 --- a/kernel/lockdep.c +++ b/kernel/lockdep.c | |||
@@ -42,7 +42,7 @@ | |||
42 | #include <linux/hash.h> | 42 | #include <linux/hash.h> |
43 | #include <linux/ftrace.h> | 43 | #include <linux/ftrace.h> |
44 | #include <linux/stringify.h> | 44 | #include <linux/stringify.h> |
45 | 45 | #include <linux/bitops.h> | |
46 | #include <asm/sections.h> | 46 | #include <asm/sections.h> |
47 | 47 | ||
48 | #include "lockdep_internals.h" | 48 | #include "lockdep_internals.h" |
@@ -118,7 +118,7 @@ static inline int debug_locks_off_graph_unlock(void) | |||
118 | static int lockdep_initialized; | 118 | static int lockdep_initialized; |
119 | 119 | ||
120 | unsigned long nr_list_entries; | 120 | unsigned long nr_list_entries; |
121 | static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES]; | 121 | struct lock_list list_entries[MAX_LOCKDEP_ENTRIES]; |
122 | 122 | ||
123 | /* | 123 | /* |
124 | * All data structures here are protected by the global debug_lock. | 124 | * All data structures here are protected by the global debug_lock. |
@@ -897,30 +897,38 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this, | |||
897 | return 1; | 897 | return 1; |
898 | } | 898 | } |
899 | 899 | ||
900 | unsigned long bfs_accessed[BITS_TO_LONGS(MAX_LOCKDEP_ENTRIES)]; | ||
900 | static struct circular_queue lock_cq; | 901 | static struct circular_queue lock_cq; |
902 | |||
901 | static int __search_shortest_path(struct lock_list *source_entry, | 903 | static int __search_shortest_path(struct lock_list *source_entry, |
902 | struct lock_class *target, | 904 | struct lock_class *target, |
903 | struct lock_list **target_entry, | 905 | struct lock_list **target_entry, |
904 | int forward) | 906 | int forward) |
905 | { | 907 | { |
906 | struct lock_list *entry; | 908 | struct lock_list *entry; |
909 | struct list_head *head; | ||
907 | struct circular_queue *cq = &lock_cq; | 910 | struct circular_queue *cq = &lock_cq; |
908 | int ret = 1; | 911 | int ret = 1; |
909 | 912 | ||
910 | __cq_init(cq); | ||
911 | |||
912 | mark_lock_accessed(source_entry, NULL); | ||
913 | if (source_entry->class == target) { | 913 | if (source_entry->class == target) { |
914 | *target_entry = source_entry; | 914 | *target_entry = source_entry; |
915 | ret = 0; | 915 | ret = 0; |
916 | goto exit; | 916 | goto exit; |
917 | } | 917 | } |
918 | 918 | ||
919 | if (forward) | ||
920 | head = &source_entry->class->locks_after; | ||
921 | else | ||
922 | head = &source_entry->class->locks_before; | ||
923 | |||
924 | if (list_empty(head)) | ||
925 | goto exit; | ||
926 | |||
927 | __cq_init(cq); | ||
919 | __cq_enqueue(cq, (unsigned long)source_entry); | 928 | __cq_enqueue(cq, (unsigned long)source_entry); |
920 | 929 | ||
921 | while (!__cq_empty(cq)) { | 930 | while (!__cq_empty(cq)) { |
922 | struct lock_list *lock; | 931 | struct lock_list *lock; |
923 | struct list_head *head; | ||
924 | 932 | ||
925 | __cq_dequeue(cq, (unsigned long *)&lock); | 933 | __cq_dequeue(cq, (unsigned long *)&lock); |
926 | 934 | ||
@@ -1040,6 +1048,7 @@ static noinline int print_circular_bug(void) | |||
1040 | return 0; | 1048 | return 0; |
1041 | 1049 | ||
1042 | this.class = hlock_class(check_source); | 1050 | this.class = hlock_class(check_source); |
1051 | this.parent = NULL; | ||
1043 | if (!save_trace(&this.trace)) | 1052 | if (!save_trace(&this.trace)) |
1044 | return 0; | 1053 | return 0; |
1045 | 1054 | ||
@@ -1580,10 +1589,10 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, | |||
1580 | */ | 1589 | */ |
1581 | check_source = next; | 1590 | check_source = next; |
1582 | check_target = prev; | 1591 | check_target = prev; |
1592 | |||
1583 | if (check_noncircular(hlock_class(next), 0) == 2) | 1593 | if (check_noncircular(hlock_class(next), 0) == 2) |
1584 | return print_circular_bug(); | 1594 | return print_circular_bug(); |
1585 | 1595 | ||
1586 | |||
1587 | if (!check_prev_add_irq(curr, prev, next)) | 1596 | if (!check_prev_add_irq(curr, prev, next)) |
1588 | return 0; | 1597 | return 0; |
1589 | 1598 | ||
diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h index 6f48d37d5be2..c2f6594966f3 100644 --- a/kernel/lockdep_internals.h +++ b/kernel/lockdep_internals.h | |||
@@ -137,23 +137,28 @@ extern atomic_t nr_find_usage_backwards_recursions; | |||
137 | # define debug_atomic_read(ptr) 0 | 137 | # define debug_atomic_read(ptr) 0 |
138 | #endif | 138 | #endif |
139 | 139 | ||
140 | |||
141 | extern unsigned long nr_list_entries; | ||
142 | extern struct lock_list list_entries[MAX_LOCKDEP_ENTRIES]; | ||
143 | extern unsigned long bfs_accessed[]; | ||
144 | |||
145 | /*For good efficiency of modular, we use power of 2*/ | ||
146 | #define MAX_CIRCULAR_QUE_SIZE 4096UL | ||
147 | |||
140 | /* The circular_queue and helpers is used to implement the | 148 | /* The circular_queue and helpers is used to implement the |
141 | * breadth-first search(BFS)algorithem, by which we can build | 149 | * breadth-first search(BFS)algorithem, by which we can build |
142 | * the shortest path from the next lock to be acquired to the | 150 | * the shortest path from the next lock to be acquired to the |
143 | * previous held lock if there is a circular between them. | 151 | * previous held lock if there is a circular between them. |
144 | * */ | 152 | * */ |
145 | #define MAX_CIRCULAR_QUE_SIZE 4096UL | ||
146 | struct circular_queue{ | 153 | struct circular_queue{ |
147 | unsigned long element[MAX_CIRCULAR_QUE_SIZE]; | 154 | unsigned long element[MAX_CIRCULAR_QUE_SIZE]; |
148 | unsigned int front, rear; | 155 | unsigned int front, rear; |
149 | }; | 156 | }; |
150 | 157 | ||
151 | #define LOCK_ACCESSED 1UL | ||
152 | #define LOCK_ACCESSED_MASK (~LOCK_ACCESSED) | ||
153 | |||
154 | static inline void __cq_init(struct circular_queue *cq) | 158 | static inline void __cq_init(struct circular_queue *cq) |
155 | { | 159 | { |
156 | cq->front = cq->rear = 0; | 160 | cq->front = cq->rear = 0; |
161 | bitmap_zero(bfs_accessed, MAX_LOCKDEP_ENTRIES); | ||
157 | } | 162 | } |
158 | 163 | ||
159 | static inline int __cq_empty(struct circular_queue *cq) | 164 | static inline int __cq_empty(struct circular_queue *cq) |
@@ -163,7 +168,7 @@ static inline int __cq_empty(struct circular_queue *cq) | |||
163 | 168 | ||
164 | static inline int __cq_full(struct circular_queue *cq) | 169 | static inline int __cq_full(struct circular_queue *cq) |
165 | { | 170 | { |
166 | return ((cq->rear + 1)%MAX_CIRCULAR_QUE_SIZE) == cq->front; | 171 | return ((cq->rear + 1)&(MAX_CIRCULAR_QUE_SIZE-1)) == cq->front; |
167 | } | 172 | } |
168 | 173 | ||
169 | static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | 174 | static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) |
@@ -172,7 +177,7 @@ static inline int __cq_enqueue(struct circular_queue *cq, unsigned long elem) | |||
172 | return -1; | 177 | return -1; |
173 | 178 | ||
174 | cq->element[cq->rear] = elem; | 179 | cq->element[cq->rear] = elem; |
175 | cq->rear = (cq->rear + 1)%MAX_CIRCULAR_QUE_SIZE; | 180 | cq->rear = (cq->rear + 1)&(MAX_CIRCULAR_QUE_SIZE-1); |
176 | return 0; | 181 | return 0; |
177 | } | 182 | } |
178 | 183 | ||
@@ -182,30 +187,36 @@ static inline int __cq_dequeue(struct circular_queue *cq, unsigned long *elem) | |||
182 | return -1; | 187 | return -1; |
183 | 188 | ||
184 | *elem = cq->element[cq->front]; | 189 | *elem = cq->element[cq->front]; |
185 | cq->front = (cq->front + 1)%MAX_CIRCULAR_QUE_SIZE; | 190 | cq->front = (cq->front + 1)&(MAX_CIRCULAR_QUE_SIZE-1); |
186 | return 0; | 191 | return 0; |
187 | } | 192 | } |
188 | 193 | ||
189 | static inline int __cq_get_elem_count(struct circular_queue *cq) | 194 | static inline int __cq_get_elem_count(struct circular_queue *cq) |
190 | { | 195 | { |
191 | return (cq->rear - cq->front)%MAX_CIRCULAR_QUE_SIZE; | 196 | return (cq->rear - cq->front)&(MAX_CIRCULAR_QUE_SIZE-1); |
192 | } | 197 | } |
193 | 198 | ||
194 | static inline void mark_lock_accessed(struct lock_list *lock, | 199 | static inline void mark_lock_accessed(struct lock_list *lock, |
195 | struct lock_list *parent) | 200 | struct lock_list *parent) |
196 | { | 201 | { |
197 | lock->parent = (void *) parent + LOCK_ACCESSED; | 202 | unsigned long nr; |
203 | nr = lock - list_entries; | ||
204 | WARN_ON(nr >= nr_list_entries); | ||
205 | lock->parent = parent; | ||
206 | set_bit(nr, bfs_accessed); | ||
198 | } | 207 | } |
199 | 208 | ||
200 | static inline unsigned long lock_accessed(struct lock_list *lock) | 209 | static inline unsigned long lock_accessed(struct lock_list *lock) |
201 | { | 210 | { |
202 | return (unsigned long)lock->parent & LOCK_ACCESSED; | 211 | unsigned long nr; |
212 | nr = lock - list_entries; | ||
213 | WARN_ON(nr >= nr_list_entries); | ||
214 | return test_bit(nr, bfs_accessed); | ||
203 | } | 215 | } |
204 | 216 | ||
205 | static inline struct lock_list *get_lock_parent(struct lock_list *child) | 217 | static inline struct lock_list *get_lock_parent(struct lock_list *child) |
206 | { | 218 | { |
207 | return (struct lock_list *) | 219 | return child->parent; |
208 | ((unsigned long)child->parent & LOCK_ACCESSED_MASK); | ||
209 | } | 220 | } |
210 | 221 | ||
211 | static inline unsigned long get_lock_depth(struct lock_list *child) | 222 | static inline unsigned long get_lock_depth(struct lock_list *child) |