linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alessio Igor Bogani <abogani@kernel.org>
To: Rusty Russell <rusty@rustcorp.com.au>,
	Tim Abbott <tabbott@ksplice.com>,
	Anders Kaseorg <andersk@ksplice.com>,
	Jason Wessel <jason.wessel@windriver.com>,
	Tim Bird <tim.bird@am.sony.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux Embedded <linux-embedded@vger.kernel.org>,
	Alessio Igor Bogani <abogani@kernel.org>
Subject: [PATCH 1/4] module: Restructure each_symbol() code
Date: Sat, 16 Apr 2011 15:26:10 +0200	[thread overview]
Message-ID: <1302960373-5309-2-git-send-email-abogani@kernel.org> (raw)
In-Reply-To: <1302960373-5309-1-git-send-email-abogani@kernel.org>

Restructure code to better integrate future improvements.

This work was supported by a hardware donation from the CE Linux Forum.

Signed-off-by: Alessio Igor Bogani <abogani@kernel.org>
Signed-off-by: Anders Kaseorg <andersk@ksplice.com>
---
 kernel/module.c |   75 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index d5938a5..b438b25 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -235,28 +235,28 @@ extern const unsigned long __start___kcrctab_unused_gpl[];
 #define symversion(base, idx) ((base != NULL) ? ((base) + (idx)) : NULL)
 #endif
 
-static bool each_symbol_in_section(const struct symsearch *arr,
-				   unsigned int arrsize,
-				   struct module *owner,
-				   bool (*fn)(const struct symsearch *syms,
-					      struct module *owner,
-					      unsigned int symnum, void *data),
-				   void *data)
+static bool each_symsearch_in_section(const struct symsearch *arr,
+				      unsigned int arrsize,
+				      struct module *owner,
+				      bool (*fn)(const struct symsearch *syms,
+						 struct module *owner,
+						 void *data),
+				      void *data)
 {
-	unsigned int i, j;
+	unsigned int j;
 
 	for (j = 0; j < arrsize; j++) {
-		for (i = 0; i < arr[j].stop - arr[j].start; i++)
-			if (fn(&arr[j], owner, i, data))
-				return true;
+		if (fn(&arr[j], owner, data))
+			return true;
 	}
 
 	return false;
 }
 
 /* Returns true as soon as fn returns true, otherwise false. */
-bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
-			    unsigned int symnum, void *data), void *data)
+static bool each_symsearch(bool (*fn)(const struct symsearch *syms,
+				      struct module *owner, void *data),
+			   void *data)
 {
 	struct module *mod;
 	static const struct symsearch arr[] = {
@@ -278,7 +278,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
 #endif
 	};
 
-	if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
+	if (each_symsearch_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
 		return true;
 
 	list_for_each_entry_rcu(mod, &modules, list) {
@@ -304,11 +304,39 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
 #endif
 		};
 
-		if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
+		if (each_symsearch_in_section(arr, ARRAY_SIZE(arr), mod, fn,
+					      data))
 			return true;
 	}
 	return false;
 }
+
+struct each_symbol_arg {
+	bool (*fn)(const struct symsearch *arr, struct module *owner,
+		   unsigned int symnum, void *data);
+	void *data;
+};
+
+static bool each_symbol_in_symsearch(const struct symsearch *syms,
+				     struct module *owner, void *data)
+{
+	struct each_symbol_arg *esa = data;
+	unsigned int i;
+
+	for (i = 0; i < syms->stop - syms->start; i++) {
+		if (esa->fn(syms, owner, i, esa->data))
+			return true;
+	}
+	return false;
+}
+
+/* Returns true as soon as fn returns true, otherwise false. */
+bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
+			    unsigned int symnum, void *data), void *data)
+{
+	struct each_symbol_arg esa = {fn, data};
+	return each_symsearch(each_symbol_in_symsearch, &esa);
+}
 EXPORT_SYMBOL_GPL(each_symbol);
 
 struct find_symbol_arg {
@@ -323,13 +351,20 @@ struct find_symbol_arg {
 	const struct kernel_symbol *sym;
 };
 
-static bool find_symbol_in_section(const struct symsearch *syms,
-				   struct module *owner,
-				   unsigned int symnum, void *data)
+static bool find_symbol_in_symsearch(const struct symsearch *syms,
+				     struct module *owner,
+				     void *data)
 {
 	struct find_symbol_arg *fsa = data;
+	unsigned int symnum;
+	int result;
 
-	if (strcmp(syms->start[symnum].name, fsa->name) != 0)
+	for (symnum = 0; symnum < syms->stop - syms->start; symnum++) {
+		result = strcmp(fsa->name, syms->start[symnum].name);
+		if (result == 0)
+			break;
+	}
+	if (symnum >= syms->stop - syms->start)
 		return false;
 
 	if (!fsa->gplok) {
@@ -379,7 +414,7 @@ const struct kernel_symbol *find_symbol(const char *name,
 	fsa.gplok = gplok;
 	fsa.warn = warn;
 
-	if (each_symbol(find_symbol_in_section, &fsa)) {
+	if (each_symsearch(find_symbol_in_symsearch, &fsa)) {
 		if (owner)
 			*owner = fsa.owner;
 		if (crc)
-- 
1.7.4.1


  reply	other threads:[~2011-04-16 13:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-16 13:26 [PATCH 0/4] Speed up the symbols' resolution process V4 Alessio Igor Bogani
2011-04-16 13:26 ` Alessio Igor Bogani [this message]
2011-04-19  1:31   ` [PATCH 1/4] module: Restructure each_symbol() code Rusty Russell
2011-04-16 13:26 ` [PATCH 2/4] module: Sort exported symbols Alessio Igor Bogani
2011-04-16 13:26 ` [PATCH 3/4] lib: Add generic binary search function to the kernel Alessio Igor Bogani
2011-04-16 13:26 ` [PATCH 4/4] module: Use the binary search for symbols resolution Alessio Igor Bogani
2011-04-16 14:08   ` Wanlong Gao
2011-04-16 14:32   ` Wanlong Gao
2011-04-19  1:37     ` Rusty Russell
2011-04-19  1:44       ` Wanlong Gao
2011-04-19 11:35         ` Rusty Russell
2011-04-19 12:46           ` Wanlong Gao
2011-04-27 15:31 ` [PATCH 0/4] Speed up the symbols' resolution process V4 Dirk Behme
2011-05-11  3:32 ` Mike Frysinger
2011-05-11  7:04   ` Alessio Igor Bogani
2011-05-11  9:19     ` Alessio Igor Bogani
2011-05-11 13:44       ` Alessio Igor Bogani
2011-05-11 14:47       ` Mike Frysinger
2011-05-11 15:25         ` Alessio Igor Bogani
2011-05-11 15:52           ` Mike Frysinger
2011-05-12  9:10             ` Alessio Igor Bogani
2011-05-12 14:30               ` Mike Frysinger
2011-05-13  7:01                 ` Alessio Igor Bogani
2011-05-14 17:32                   ` Mike Frysinger
2011-05-15  8:28                     ` Alessio Igor Bogani

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=1302960373-5309-2-git-send-email-abogani@kernel.org \
    --to=abogani@kernel.org \
    --cc=andersk@ksplice.com \
    --cc=jason.wessel@windriver.com \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tabbott@ksplice.com \
    --cc=tim.bird@am.sony.com \
    /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;
as well as URLs for NNTP newsgroup(s).