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 /kernel/lockdep_internals.h | |
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>
Diffstat (limited to 'kernel/lockdep_internals.h')
-rw-r--r-- | kernel/lockdep_internals.h | 35 |
1 files changed, 23 insertions, 12 deletions
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) |