list.h: improve hlist
Hi Linus,
Please consider pulling from:
bk://kernel.bkbits.net/acme/hlist-2.5
I discussed this with Andi and he gave me an ACK to submit, please
let me know if you don't like anything and I'll be happy to fix it. The hlist_for_each_entry is being used in my current work of converting net/ to use hlist_{head,node}.
Best Regards,
- Arnaldo
You can import this changeset into BK by piping this whole message to:
'| bk receive [path to repository]' or apply the patch as usual.
===================================================================
[email protected], 2003-06-07 14:22:10-03:00, [email protected]
o list.h: improve hlist
This changeset:
1. Implements hlist_add_after
2. uses prefetch in hlist_for_each, using a trick that ends up being equivalent to having the prefetch instruction in the first block of the hlist_for_each for block, the compiler optimizes the second "test" away, as its result is constant
3. implements hlist_for_each_entry and hlist_for_each_entry safe, using a struct hlist_node as iterator to avoid the extra branches a similar implementation to list_for_each_entry would have if used a typed iterator, but while avoiding having to have the explicit hlist_entry as in hlist_for_each.
4. Converts the hlist_for_each users that had explicit prefetches, i.e. removed the explicit prefetch
5. fix a harmless list_entry use in a hlist_for_each in inode.c
fs/dcache.c | 3 --- fs/inode.c | 4 +--- include/linux/list.h | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-)
fs/dcache.c +0 -3
@@ -983,8 +983,6 @@struct dentry *dentry;unsigned long move_count;struct qstr * qstr; - -prefetch (node->next);smp_read_barrier_depends (); dentry = hlist_entry(node, struct dentry, d_hash);
@@ -1072,7 +1070,6 @@spin_lock (&dcache_lock); base =d_hash (dparent, dentry->d_name.hash);hlist_for_each (lhp,base) { -prefetch (lhp->next);/* read_barrier_depends() not required for d_hash list * as it is parsed under dcache_lock */
fs/inode.c +1 -3
@@ -484,7 +484,6 @@ repeat: hlist_for_each (node, head) { -prefetch (node->next); inode = hlist_entry(node, struct inode, i_hash);if (inode->i_sb != sb)continue ;
@@ -510,8 +509,7 @@ repeat: hlist_for_each (node, head) { -prefetch (node->next); - inode = list_entry(node, struct inode, i_hash); + inode = hlist_entry(node, struct inode, i_hash);if (inode->i_ino != ino)continue ;if (inode->i_sb != sb)
include/linux/list.h +34 -1
@@ -443,17 +443,50 @@ *(n->pprev) = n; } +static __inline__void hlist_add_after (struct hlist_node *n, +struct hlist_node *next) +{ + next->next = n->next; + *(next->pprev) = n; + n->next = next; +} +#define hlist_entry (ptr, type, member) container_of(ptr,type,member)/* Cannot easily do prefetch unfortunately */ #define hlist_for_each (pos, head) \ - for (pos = (head)->first; pos; \ + for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ pos = pos->next)#define hlist_for_each_safe (pos, n, head) \ for (pos = (head)->first; n = pos ? pos->next : 0, pos; \ pos = n) +/** +* hlist_for_each_entry - iterate over list of given type +* @tpos: the type * to use as a loop counter. +* @pos: the &struct hlist_node to use as a loop counter. +* @head: the head for your list. +* @member: the name of the hlist_node within the struct. +*/ +#define hlist_for_each_entry (tpos, pos, head, member) \ + for (pos = (head)->first; \ + pos && ({ prefetch(pos->next); 1;}) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = pos->next) +/** +* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry +* @tpos: the type * to use as a loop counter. +* @pos: the &struct hlist_node to use as a loop counter. +* @n: another &struct hlist_node to use as temporary storage +* @head: the head for your list. +* @member: the name of the hlist_node within the struct. +*/ +#define hlist_for_each_entry_safe (tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + pos && ({ n = pos->next; 1; }) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ + pos = n)#else #warning "don't include kernel headers in userspace"#endif /* __KERNEL__ */
===================================================================
This BitKeeper patch contains the following changesets:
1.1320
## Wrapped with gzip_uu ##
M'XL( $<QXCX ^U9;6_;-A#^+/V*0PL4=F;+I%[\%KC(E@Q;L $KNO73.ABT M1$5")-$3*:=9W?^^(VD[MN,F35!L_6#)D&3>\>[XW/$Y.7D)[R2OQPZ+2^Z^ MA)^%5&,G%A6/5;Y@7BQ*;U:CX*T0*.AEHN2]V74O*W*INKX7N2A[PU2<P8+7 M<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