public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Walker <dwalker@mvista.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, johnstul@us.ibm.com
Subject: [PATCH 9/9] clocksource: refactor duplicate registration checking
Date: Fri, 30 Mar 2007 11:45:50 -0700	[thread overview]
Message-ID: <20070330184616.429016225@mvista.com> (raw)
In-Reply-To: 20070330184541.583153763@mvista.com

[-- Attachment #1: clocksource_use_inited_lists.patch --]
[-- Type: text/plain, Size: 3444 bytes --]

Refactors the duplicate registration checking. This makes it based on the
clocksource structure list state. I was able to drop some if statements
making the registration code path slightly smaller and faster, and remove
some looping which was endemic of the first version of this check.

Signed-Off-By: Daniel Walker <dwalker@mvista.com>

---
 include/linux/clocksource.h |    2 +-
 kernel/time/clocksource.c   |   30 ++++++++++++++++++------------
 kernel/time/jiffies.c       |    1 +
 3 files changed, 20 insertions(+), 13 deletions(-)

Index: linux-2.6.20/include/linux/clocksource.h
===================================================================
--- linux-2.6.20.orig/include/linux/clocksource.h
+++ linux-2.6.20/include/linux/clocksource.h
@@ -26,7 +26,7 @@ struct clocksource;
  *	Provides mostly state-free accessors to the underlying hardware.
  *
  * @name:		ptr to clocksource name
- * @list:		list head for registration
+ * @list:		list head for registration, must be initialized.
  * @rating:		rating value for selection (higher is better)
  *			To avoid rating inflation the following
  *			list should give you a guide as to how
Index: linux-2.6.20/kernel/time/clocksource.c
===================================================================
--- linux-2.6.20.orig/kernel/time/clocksource.c
+++ linux-2.6.20/kernel/time/clocksource.c
@@ -232,7 +232,7 @@ static struct clocksource *select_clocks
 /*
  * Enqueue the clocksource sorted by rating
  */
-static int clocksource_enqueue(struct clocksource *c)
+static void clocksource_enqueue(struct clocksource *c)
 {
 	struct list_head *tmp, *entry = &clocksource_list;
 
@@ -240,8 +240,7 @@ static int clocksource_enqueue(struct cl
 		struct clocksource *cs;
 
 		cs = list_entry(tmp, struct clocksource, list);
-		if (cs == c)
-			return -EBUSY;
+
 		/* Keep track of the place, where to insert */
 		if (cs->rating >= c->rating)
 			entry = tmp;
@@ -252,28 +251,35 @@ static int clocksource_enqueue(struct cl
 	    !strcmp(c->name, override_name))
 		clocksource_override = c;
 
-	return 0;
 }
 
 /**
  * clocksource_register - Used to install new clocksources
  * @t:		clocksource to be registered
  *
- * Returns -EBUSY if registration fails, zero otherwise.
+ * Always returns zero.
  */
 int clocksource_register(struct clocksource *c)
 {
 	unsigned long flags;
-	int ret;
+
+	/*
+	 * This BUGON indicates that either the clocksource has been
+	 * registered already, or the list element hasn't been properly
+	 * initialized.
+	 */
+	BUG_ON(!list_empty(&c->list));
 
 	spin_lock_irqsave(&clocksource_lock, flags);
-	ret = clocksource_enqueue(c);
-	if (!ret)
-		next_clocksource = select_clocksource();
+
+	clocksource_enqueue(c);
+	next_clocksource = select_clocksource();
+
 	spin_unlock_irqrestore(&clocksource_lock, flags);
-	if (!ret)
-		clocksource_check_watchdog(c);
-	return ret;
+
+	clocksource_check_watchdog(c);
+
+	return 0;
 }
 EXPORT_SYMBOL(clocksource_register);
 
Index: linux-2.6.20/kernel/time/jiffies.c
===================================================================
--- linux-2.6.20.orig/kernel/time/jiffies.c
+++ linux-2.6.20/kernel/time/jiffies.c
@@ -62,6 +62,7 @@ struct clocksource clocksource_jiffies =
 	.mask		= 0xffffffff, /*32bits*/
 	.mult		= NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
 	.shift		= JIFFIES_SHIFT,
+	.list		= LIST_HEAD_INIT(clocksource_jiffies.list),
 };
 
 static int __init init_jiffies_clocksource(void)

-- 

  parent reply	other threads:[~2007-03-30 18:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-30 18:45 [PATCH 1/9] clocksource: arm initialize list value Daniel Walker
2007-03-30 18:45 ` [PATCH 2/9] clocksource: parisc " Daniel Walker
2007-03-30 18:45 ` [PATCH 3/9] clocksource: avr32 " Daniel Walker
2007-03-30 18:45 ` [PATCH 4/9] clocksource: mips " Daniel Walker
2007-03-30 18:45 ` [PATCH 5/9] clocksource: i386 " Daniel Walker
2007-03-30 18:45 ` [PATCH 6/9] clocksource: x86_64 " Daniel Walker
2007-03-30 18:45 ` [PATCH 7/9] clocksource: driver " Daniel Walker
2007-03-30 18:45 ` [PATCH 8/9] clocksource: s390 " Daniel Walker
2007-03-30 19:09   ` Heiko Carstens
2007-03-30 19:19     ` Daniel Walker
2007-03-30 19:36       ` Heiko Carstens
2007-03-30 18:45 ` Daniel Walker [this message]
2007-03-31  1:59   ` [PATCH 9/9] clocksource: refactor duplicate registration checking James Morris
2007-03-31  2:47     ` Daniel Walker

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=20070330184616.429016225@mvista.com \
    --to=dwalker@mvista.com \
    --cc=akpm@linux-foundation.org \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /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