diff options
author | Allan Stephens <allan.stephens@windriver.com> | 2008-04-16 21:21:16 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-04-16 21:21:16 -0400 |
commit | 4784b7c348779e957c82ba638ba2ada5ad8502d8 (patch) | |
tree | 635e99ff046b7f9519c515ee7e6edc844dced058 /net/tipc/ref.c | |
parent | dd9e0dda66ba38a2ddd1405ac279894260dc5c36 (diff) |
[TIPC]: Remove inlining of reference table locking routines
This patch converts the TIPC reference table locking routines
into non-inlined routines, since they are mainly called from
non-performance critical areas of TIPC and the added code
footprint incurred through inlining can no longer be justified.
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/ref.c')
-rw-r--r-- | net/tipc/ref.c | 91 |
1 files changed, 87 insertions, 4 deletions
diff --git a/net/tipc/ref.c b/net/tipc/ref.c index c38744c96ed1..d0b240e86ccd 100644 --- a/net/tipc/ref.c +++ b/net/tipc/ref.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/ref.c: TIPC object registry code | 2 | * net/tipc/ref.c: TIPC object registry code |
3 | * | 3 | * |
4 | * Copyright (c) 1991-2006, Ericsson AB | 4 | * Copyright (c) 1991-2006, Ericsson AB |
5 | * Copyright (c) 2004-2005, Wind River Systems | 5 | * Copyright (c) 2004-2007, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -46,6 +46,37 @@ | |||
46 | #include "node.h" | 46 | #include "node.h" |
47 | #include "bcast.h" | 47 | #include "bcast.h" |
48 | 48 | ||
49 | /** | ||
50 | * struct reference - TIPC object reference entry | ||
51 | * @object: pointer to object associated with reference entry | ||
52 | * @lock: spinlock controlling access to object | ||
53 | * @data: reference value associated with object (or link to next unused entry) | ||
54 | */ | ||
55 | |||
56 | struct reference { | ||
57 | void *object; | ||
58 | spinlock_t lock; | ||
59 | union { | ||
60 | u32 next_plus_upper; | ||
61 | u32 reference; | ||
62 | } data; | ||
63 | }; | ||
64 | |||
65 | /** | ||
66 | * struct tipc_ref_table - table of TIPC object reference entries | ||
67 | * @entries: pointer to array of reference entries | ||
68 | * @index_mask: bitmask for array index portion of reference values | ||
69 | * @first_free: array index of first unused object reference entry | ||
70 | * @last_free: array index of last unused object reference entry | ||
71 | */ | ||
72 | |||
73 | struct ref_table { | ||
74 | struct reference *entries; | ||
75 | u32 index_mask; | ||
76 | u32 first_free; | ||
77 | u32 last_free; | ||
78 | }; | ||
79 | |||
49 | /* | 80 | /* |
50 | * Object reference table consists of 2**N entries. | 81 | * Object reference table consists of 2**N entries. |
51 | * | 82 | * |
@@ -61,7 +92,7 @@ | |||
61 | * because entry 0's reference field has the form XXXX|1--1. | 92 | * because entry 0's reference field has the form XXXX|1--1. |
62 | */ | 93 | */ |
63 | 94 | ||
64 | struct ref_table tipc_ref_table = { NULL }; | 95 | static struct ref_table tipc_ref_table = { NULL }; |
65 | 96 | ||
66 | static DEFINE_RWLOCK(ref_table_lock); | 97 | static DEFINE_RWLOCK(ref_table_lock); |
67 | 98 | ||
@@ -198,8 +229,8 @@ void tipc_ref_discard(u32 ref) | |||
198 | tipc_ref_table.first_free = index; | 229 | tipc_ref_table.first_free = index; |
199 | else | 230 | else |
200 | /* next_plus_upper is always XXXX|0--0 for last free entry */ | 231 | /* next_plus_upper is always XXXX|0--0 for last free entry */ |
201 | tipc_ref_table.entries[tipc_ref_table.last_free].data.next_plus_upper | 232 | tipc_ref_table.entries[tipc_ref_table.last_free]. |
202 | |= index; | 233 | data.next_plus_upper |= index; |
203 | tipc_ref_table.last_free = index; | 234 | tipc_ref_table.last_free = index; |
204 | 235 | ||
205 | /* increment upper bits of entry to invalidate subsequent references */ | 236 | /* increment upper bits of entry to invalidate subsequent references */ |
@@ -208,3 +239,55 @@ exit: | |||
208 | write_unlock_bh(&ref_table_lock); | 239 | write_unlock_bh(&ref_table_lock); |
209 | } | 240 | } |
210 | 241 | ||
242 | /** | ||
243 | * tipc_ref_lock - lock referenced object and return pointer to it | ||
244 | */ | ||
245 | |||
246 | void *tipc_ref_lock(u32 ref) | ||
247 | { | ||
248 | if (likely(tipc_ref_table.entries)) { | ||
249 | struct reference *r; | ||
250 | |||
251 | r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; | ||
252 | spin_lock_bh(&r->lock); | ||
253 | if (likely(r->data.reference == ref)) | ||
254 | return r->object; | ||
255 | spin_unlock_bh(&r->lock); | ||
256 | } | ||
257 | return NULL; | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * tipc_ref_unlock - unlock referenced object | ||
262 | */ | ||
263 | |||
264 | void tipc_ref_unlock(u32 ref) | ||
265 | { | ||
266 | if (likely(tipc_ref_table.entries)) { | ||
267 | struct reference *r; | ||
268 | |||
269 | r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; | ||
270 | if (likely(r->data.reference == ref)) | ||
271 | spin_unlock_bh(&r->lock); | ||
272 | else | ||
273 | err("tipc_ref_unlock() invoked using " | ||
274 | "obsolete reference\n"); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * tipc_ref_deref - return pointer referenced object (without locking it) | ||
280 | */ | ||
281 | |||
282 | void *tipc_ref_deref(u32 ref) | ||
283 | { | ||
284 | if (likely(tipc_ref_table.entries)) { | ||
285 | struct reference *r; | ||
286 | |||
287 | r = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; | ||
288 | if (likely(r->data.reference == ref)) | ||
289 | return r->object; | ||
290 | } | ||
291 | return NULL; | ||
292 | } | ||
293 | |||