(4/4) Support for lots of netdev's -- faster dev_alloc_name
Subsystems (4)
PATCH 1/1 (4/4) Support for lots of netdev's -- faster dev_alloc_name
Convert dev_alloc_name from O(n^2) lookup to O(n) by using a page as bitmap to figure out how many devices of that pattern have been allocated. This works for up to 32k devices (PAGE_SIZE*8) on i386, more on other platforms. Correctly handles the boundary cases where number of devices won't fit because name length is limited.
Adds strnchr to the string libraries since we need to find the % format character, but only care if it is in the first 15 bytes.
include/linux/string.h +3 -0
@@ -52,6 +52,9 @@#ifndef __HAVE_ARCH_STRCHRextern char *strchr (const char *,int );#endif +#ifndef __HAVE_ARCH_STRNCHR +extern char *strnchr (const char *,size_t ,int ); +#endif #ifndef __HAVE_ARCH_STRRCHRextern char *strrchr (const char *,int );#endif
lib/string.c +16 -0
@@ -273,6 +273,22 @@ }#endif +#ifndef __HAVE_ARCH_STRNCHR +/** +* strnchr - Find a character in a length limited string +* @s: The string to be searched +* @count: The number of characters to be searched +* @c: The character to search for +*/ +char *strnchr (const char *s,size_t count,int c) +{ +for (; count-- && *s !='\0' ; ++s) +if (*s == (char ) c) +return (char *) s; +return NULL ; +} +#endif +#ifndef __HAVE_ARCH_STRLEN/** * strlen - Find the length of a string
net/core/dev.c +46 -21
76 lines not on this page · raw message
Quoted 8 lines · On Fri, 6 Feb 2004 10:12:32 -0800 Stephen Hemminger <[email protected]> wrote:
Convert
dev_alloc_namefrom O(n^2) lookup to O(n) by using a page as bitmap to figure out how many devices of that pattern have been allocated. This works for up to 32k devices (PAGE_SIZE*8) on i386, more on other platforms. Correctly handles the boundary cases where number of devices won't fit because name length is limited.Adds strnchr to the string libraries since we need to find the % format character, but only care if it is in the first 15 bytes.
Ok, applied, thanks Stephen.