Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
6434c041
Commit
6434c041
authored
Feb 05, 2004
by
Stephen Hemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NET]: Hash netdevices by ifindex for faster lookup.
parent
fa13a7b8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
include/linux/netdevice.h
include/linux/netdevice.h
+2
-0
net/core/dev.c
net/core/dev.c
+18
-4
No files found.
include/linux/netdevice.h
View file @
6434c041
...
...
@@ -377,6 +377,8 @@ struct net_device
struct
list_head
todo_list
;
/* device name hash chain */
struct
hlist_node
name_hlist
;
/* device index hash chain */
struct
hlist_node
index_hlist
;
/* register/unregister state machine */
enum
{
NETREG_UNINITIALIZED
=
0
,
...
...
net/core/dev.c
View file @
6434c041
...
...
@@ -188,6 +188,7 @@ EXPORT_SYMBOL(dev_base_lock);
#define NETDEV_HASHBITS 8
static
struct
hlist_head
dev_name_head
[
1
<<
NETDEV_HASHBITS
];
static
struct
hlist_head
dev_index_head
[
1
<<
NETDEV_HASHBITS
];
static
inline
struct
hlist_head
*
dev_name_hash
(
const
char
*
name
)
{
...
...
@@ -195,6 +196,11 @@ static inline struct hlist_head *dev_name_hash(const char *name)
return
&
dev_name_head
[
hash
&
((
1
<<
NETDEV_HASHBITS
)
-
1
)];
}
static
inline
struct
hlist_head
*
dev_index_hash
(
int
ifindex
)
{
return
&
dev_index_head
[
ifindex
&
((
1
<<
NETDEV_HASHBITS
)
-
1
)];
}
/*
* Our notifier list
*/
...
...
@@ -554,12 +560,15 @@ int __dev_get(const char *name)
struct
net_device
*
__dev_get_by_index
(
int
ifindex
)
{
struct
net_device
*
dev
;
struct
hlist_node
*
p
;
for
(
dev
=
dev_base
;
dev
;
dev
=
dev
->
next
)
hlist_for_each
(
p
,
dev_index_hash
(
ifindex
))
{
struct
net_device
*
dev
=
hlist_entry
(
p
,
struct
net_device
,
index_hlist
);
if
(
dev
->
ifindex
==
ifindex
)
break
;
return
dev
;
}
return
NULL
;
}
...
...
@@ -2842,6 +2851,7 @@ int register_netdevice(struct net_device *dev)
*
dev_tail
=
dev
;
dev_tail
=
&
dev
->
next
;
hlist_add_head
(
&
dev
->
name_hlist
,
head
);
hlist_add_head
(
&
dev
->
index_hlist
,
dev_index_hash
(
dev
->
ifindex
));
dev_hold
(
dev
);
dev
->
reg_state
=
NETREG_REGISTERING
;
write_unlock_bh
(
&
dev_base_lock
);
...
...
@@ -3064,6 +3074,7 @@ int unregister_netdevice(struct net_device *dev)
if
(
d
==
dev
)
{
write_lock_bh
(
&
dev_base_lock
);
hlist_del
(
&
dev
->
name_hlist
);
hlist_del
(
&
dev
->
index_hlist
);
if
(
dev_tail
==
&
dev
->
next
)
dev_tail
=
dp
;
*
dp
=
d
->
next
;
...
...
@@ -3145,6 +3156,9 @@ static int __init net_dev_init(void)
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
dev_name_head
);
i
++
)
INIT_HLIST_HEAD
(
&
dev_name_head
[
i
]);
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
dev_index_head
);
i
++
)
INIT_HLIST_HEAD
(
&
dev_index_head
[
i
]);
/*
* Initialise the packet receive queues.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment