Skip to contentSkip to conversation

(4/4) Support for lots of netdev's -- faster dev_alloc_name

PATCH In review Stephen Hemminger 2 participants 2 messages Feb 6, 2004

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
diff -Nru a/include/linux/string.h b/include/linux/string.h
@@ -52,6 +52,9 @@
 #ifndef __HAVE_ARCH_STRCHR
 extern char * strchr(const char *,int);
 #endif
+#ifndef __HAVE_ARCH_STRNCHR
+extern char * strnchr(const char *, size_t, int);
+#endif
 #ifndef __HAVE_ARCH_STRRCHR
 extern char * strrchr(const char *,int);
 #endif
lib/string.c +16 -0
diff -Nru a/lib/string.c b/lib/string.c
@@ -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

#1 lore raw
Quoted 8 lines · On Fri, 6 Feb 2004 10:12:32 -0800 Stephen Hemminger <[email protected]> wrote:

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.

Ok, applied, thanks Stephen.