mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Abbott <tabbott@ksplice.com>
To: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	rusty@rustcorp.com.au, linux-kbuild@vger.kernel.org,
	linux-modules@vger.kernel.org, Tim Abbott <tabbott@ksplice.com>
Subject: [PATCH 2/2] module: use bsearch in find_symbol_in_kernel_section.
Date: Wed, 23 Sep 2009 13:28:46 -0400	[thread overview]
Message-ID: <1253726926-5504-3-git-send-email-tabbott@ksplice.com> (raw)
In-Reply-To: <1253626718-18887-5-git-send-email-alan-jenkins@tuffmail.co.uk>

Signed-off-by: Tim Abbott <tabbott@ksplice.com>
---
 kernel/module.c |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 9b19f23..25ff16b 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -55,6 +55,7 @@
 #include <linux/async.h>
 #include <linux/percpu.h>
 #include <linux/kmemleak.h>
+#include <linux/bsearch.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/module.h>
@@ -209,31 +210,26 @@ struct symsearch {
 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
 #endif
 
-/* binary search on sorted symbols */
+static int symbol_compare(const void *key, const void *elt)
+{
+	const char *str = key;
+	const struct kernel_symbol *sym = elt;
+	return strcmp(sym->name, str);
+}
+
 static bool find_symbol_in_kernel_section(const struct symsearch *syms,
 					  const char *name,
 					  unsigned int *symnum)
 {
-	int lo = 0, hi = syms->stop - syms->start - 1;
-	int mid, cmp;
-
-	while (lo <= hi) {
-		mid = (lo + hi) / 2;
-		cmp = strcmp(syms->start[mid].name, name);
-		if (cmp == 0) {
-			*symnum = mid;
-			return true;
-		}
-		else if (cmp < 0)
-			hi = mid - 1;
-		else
-			lo = mid + 1;
-	}
-
-	return false;
+	const struct kernel_symbol *sym =
+	    bsearch(name, syms->start, syms->stop - syms->start,
+		    sizeof(*syms->start), symbol_compare);
+	if (sym == NULL)
+		return false;
+	*symnum = sym - syms->start;
+	return true;
 }
 
-
 static bool find_symbol_in_kernel(const char *name,
 				  struct symsearch *sym,
 				  unsigned int *symnum)
-- 
1.6.3.3


      parent reply	other threads:[~2009-09-23 17:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-22 13:38 module: Speed up symbol resolution during module loading Alan Jenkins
2009-09-22 13:38 ` [PATCH 1/4] module: extract __ExPORT_SYMBOL from module.h into mod_export.h Alan Jenkins
2009-09-22 14:42   ` Sam Ravnborg
2009-09-22 14:45     ` Alan Jenkins
2009-09-22 15:45   ` Daniel Walker
2009-09-22 15:50     ` Alan Jenkins
2009-09-22 15:55       ` Daniel Walker
2009-09-22 13:38 ` [PATCH 2/4] kbuild: sort the list of symbols exported by the kernel (__ksymtab) Alan Jenkins
2009-09-22 14:48   ` Sam Ravnborg
2009-09-22 15:08     ` Alan Jenkins
2009-09-23 17:38       ` Sam Ravnborg
2009-09-22 13:38 ` [PATCH 3/4] module: unexport each_symbol() Alan Jenkins
2009-09-23 17:29   ` Tim Abbott
2009-09-23 18:36     ` Alan Jenkins
2009-09-23 22:00     ` Christoph Hellwig
2009-09-24  0:15       ` Rusty Russell
2009-09-26 12:13       ` Alan Jenkins
2009-09-22 13:38 ` [PATCH 4/4] module: speed up find_symbol() using binary search on the builtin symbol tables Alan Jenkins
2009-09-23 17:28   ` [PATCH 0/2] Use generic binary search function Tim Abbott
2009-09-23 18:08     ` Alan Jenkins
2009-09-23 17:28   ` [PATCH 1/2] lib: Add generic binary search function to the kernel Tim Abbott
2009-09-24  0:11     ` Rusty Russell
2009-09-27 17:05       ` Tim Abbott
2009-11-03 15:14         ` Thiago Farina
2009-11-03 15:34           ` Alan Jenkins
2009-09-23 17:28   ` Tim Abbott [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1253726926-5504-3-git-send-email-tabbott@ksplice.com \
    --to=tabbott@ksplice.com \
    --cc=alan-jenkins@tuffmail.co.uk \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®