Skip to contentSkip to conversation

-mm: generic clocksource API -v2

PATCH In review Daniel Walker 6 participants 30 messages Oct 6, 2006 – Oct 9, 2006

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

cover -mm: generic clocksource API -v2

Each patch has it's own change log in the patch header, and each patch compiles and boots if applied individually (but in series order).

---- Original release notes below

This patch set is meant to modify the clocksource structure and API so that it can be used by more than just the timekeeping code. My motivation is mainly that I feel the current clocksource interface could be used for much more than just timekeeping. So if we keep the clocksource interface (which I think we should) then we should get everything out of it that we can.

This set modifies the API, then converts the time keeping code over to the new API. I also added a generic sched_clock() which just re-uses the clocksource interface to provide a high quality scheduling clock (assuming a good clocksource). Several ARM board just output nanoseconds based on jiffies which is still possible with the generic sched_clock().

I tested this on SMP and UP x86, and compile tested for ARM.

Daniel

--

#1 lore raw

PATCH 1/10 -mm: clocksource: increase initcall priority

Since it's likely that this interface would get used during bootup I moved all the clocksource registration into the postcore initcall. This also eliminated some clocksource shuffling during bootup.

---
 arch/i386/kernel/hpet.c          |    2 +-
 arch/i386/kernel/i8253.c         |    2 +-
 arch/i386/kernel/tsc.c           |    2 +-
 drivers/clocksource/acpi_pm.c    |    2 +-
 drivers/clocksource/cyclone.c    |    2 +-
 drivers/clocksource/scx200_hrt.c |    2 +-
 kernel/time/clocksource.c        |   15 +--------------
 kernel/time/jiffies.c            |    2 +-
 8 files changed, 8 insertions(+), 21 deletions(-)
arch/i386/kernel/hpet.c +1 -1
Index: linux-2.6.17/arch/i386/kernel/hpet.c
===================================================================
@@ -64,4 +64,4 @@ static int __init init_hpet_clocksource(
 	return clocksource_register(&clocksource_hpet);
 }
 
-module_init(init_hpet_clocksource);
+postcore_initcall(init_hpet_clocksource);
arch/i386/kernel/i8253.c +1 -1
Index: linux-2.6.17/arch/i386/kernel/i8253.c
===================================================================
@@ -115,4 +115,4 @@ static int __init init_pit_clocksource(v
 	clocksource_pit.mult = clocksource_hz2mult(CLOCK_TICK_RATE, 20);
 	return clocksource_register(&clocksource_pit);
 }
-module_init(init_pit_clocksource);
+postcore_initcall(init_pit_clocksource);
arch/i386/kernel/tsc.c +1 -1
Index: linux-2.6.17/arch/i386/kernel/tsc.c
===================================================================
@@ -475,4 +475,4 @@ static int __init init_tsc_clocksource(v
 	return 0;
 }
 
-module_init(init_tsc_clocksource);
+postcore_initcall(init_tsc_clocksource);
drivers/clocksource/acpi_pm.c +1 -1
Index: linux-2.6.17/drivers/clocksource/acpi_pm.c
===================================================================
@@ -174,4 +174,4 @@ pm_good:
 	return clocksource_register(&clocksource_acpi_pm);
 }
 
-module_init(init_acpi_pm_clocksource);
+postcore_initcall(init_acpi_pm_clocksource);
drivers/clocksource/cyclone.c +1 -1
Index: linux-2.6.17/drivers/clocksource/cyclone.c
===================================================================
@@ -116,4 +116,4 @@ static int __init init_cyclone_clocksour
 	return clocksource_register(&clocksource_cyclone);
 }
 
-module_init(init_cyclone_clocksource);
+postcore_initcall(init_cyclone_clocksource);
drivers/clocksource/scx200_hrt.c +1 -1
Index: linux-2.6.17/drivers/clocksource/scx200_hrt.c
===================================================================
@@ -94,7 +94,7 @@ static int __init init_hrt_clocksource(v
 	return clocksource_register(&cs_hrt);
 }
 
-module_init(init_hrt_clocksource);
+postcore_initcall(init_hrt_clocksource);
 
 MODULE_AUTHOR("Jim Cromie <[email protected]>");
 MODULE_DESCRIPTION("clocksource on SCx200 HiRes Timer");
kernel/time/clocksource.c +1 -14
Index: linux-2.6.17/kernel/time/clocksource.c
===================================================================
@@ -50,19 +50,6 @@ static struct clocksource *next_clocksou
 static LIST_HEAD(clocksource_list);
 static DEFINE_SPINLOCK(clocksource_lock);
 static char override_name[32];
-static int finished_booting;
-
-/* clocksource_done_booting - Called near the end of bootup
- *
- * Hack to avoid lots of clocksource churn at boot time
- */
-static int __init clocksource_done_booting(void)
-{
-	finished_booting = 1;
-	return 0;
-}
-
-late_initcall(clocksource_done_booting);
 
 /**
  * clocksource_get_next - Returns the selected clocksource
@@ -73,7 +60,7 @@ struct clocksource *clocksource_get_next
 	unsigned long flags;
 
 	spin_lock_irqsave(&clocksource_lock, flags);
-	if (next_clocksource && finished_booting) {
+	if (next_clocksource) {
 		curr_clocksource = next_clocksource;
 		next_clocksource = NULL;
 	}
kernel/time/jiffies.c +1 -1
Index: linux-2.6.17/kernel/time/jiffies.c
===================================================================
@@ -70,4 +70,4 @@ static int __init init_jiffies_clocksour
 	return clocksource_register(&clocksource_jiffies);
 }
 
-module_init(init_jiffies_clocksource);
+postcore_initcall(init_jiffies_clocksource);

--

#2 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

drivers/clocksource/acpi_pm.c pm_good: · line 177

Quoted 10 lines · Daniel Walker

Index: linux-2.6.17/drivers/clocksource/acpi_pm.c
===================================================================

drivers/clocksource/acpi_pm.c +1 -1
@@ -174,4 +174,4 @@ pm_good:
 	return clocksource_register(&clocksource_acpi_pm);
 }
 
-module_init(init_acpi_pm_clocksource);
+postcore_initcall(init_acpi_pm_clocksource);

Current code is assumeing DECLARE_PCI_FIXUP_EARLY() is called before init_acpi_pm_clocksource().

We'll need to change it.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 10 lines · OGAWA Hirofumi
Quoted 8 lines · Daniel Walker

Index: linux-2.6.17/drivers/clocksource/acpi_pm.c
===================================================================

drivers/clocksource/acpi_pm.c +0 -0
@@ -174,4 +174,4 @@ pm_good:
 	return clocksource_register(&clocksource_acpi_pm);
 }
 
Quoted 7 lines

drivers/clocksource/acpi_pm.c pm_good: · line 177

Quoted 2 lines
drivers/clocksource/acpi_pm.c +1 -1
-module_init(init_acpi_pm_clocksource);
+postcore_initcall(init_acpi_pm_clocksource);

Current code is assumeing DECLARE_PCI_FIXUP_EARLY() is called before init_acpi_pm_clocksource().

We'll need to change it.

We can add a call to clocksource_rating_change() inside acpi_pm_need_workaround(), are there deeper dependencies?

Daniel

#4 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 17 lines · Daniel Walker
Quoted 16 lines · OGAWA Hirofumi

drivers/clocksource/acpi_pm.c pm_good: · line 177

Quoted 10 lines · Daniel Walker

Index: linux-2.6.17/drivers/clocksource/acpi_pm.c
===================================================================

drivers/clocksource/acpi_pm.c +1 -1
@@ -174,4 +174,4 @@ pm_good:
 	return clocksource_register(&clocksource_acpi_pm);
 }
 
-module_init(init_acpi_pm_clocksource);
+postcore_initcall(init_acpi_pm_clocksource);

Current code is assumeing DECLARE_PCI_FIXUP_EARLY() is called before init_acpi_pm_clocksource().

Quoted 4 lines
Quoted 1 line

We'll need to change it.

We can add a call to clocksource_rating_change() inside acpi_pm_need_workaround(), are there deeper dependencies?

There is no deeper dependencies. If it's meaning clocksource_reselect() in current git, it sounds good to me.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#5 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 19 lines · OGAWA Hirofumi
Quoted 17 lines · Daniel Walker
Quoted 16 lines · OGAWA Hirofumi

drivers/clocksource/acpi_pm.c pm_good: · line 177

Quoted 10 lines · Daniel Walker

Index: linux-2.6.17/drivers/clocksource/acpi_pm.c
===================================================================

drivers/clocksource/acpi_pm.c +1 -1
@@ -174,4 +174,4 @@ pm_good:
 	return clocksource_register(&clocksource_acpi_pm);
 }
 
-module_init(init_acpi_pm_clocksource);
+postcore_initcall(init_acpi_pm_clocksource);

Current code is assumeing DECLARE_PCI_FIXUP_EARLY() is called before init_acpi_pm_clocksource().

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

We'll need to change it.

We can add a call to clocksource_rating_change() inside acpi_pm_need_workaround(), are there deeper dependencies?

There is no deeper dependencies. If it's meaning clocksource_reselect() in current git, it sounds good to me.

Ah, I was forgetting why I didn't before. If it's a buggy pmtmr, we'll get corrupted time until re-selecting the clocksource.

If anybody doesn't care this will be good with it. If not, we would need to back to old one. IIRC, John did it.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#6 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 6 lines · OGAWA Hirofumi
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

We'll need to change it.

We can add a call to clocksource_rating_change() inside acpi_pm_need_workaround(), are there deeper dependencies?

Quoted 8 lines
Quoted 2 lines

There is no deeper dependencies. If it's meaning clocksource_reselect() in current git, it sounds good to me.

Ah, I was forgetting why I didn't before. If it's a buggy pmtmr, we'll get corrupted time until re-selecting the clocksource.

If anybody doesn't care this will be good with it. If not, we would need to back to old one. IIRC, John did it.

We could just reverse it, use the verified read function until we know it's a good PM timer, then switch to the faster read function.

Daniel

#7 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 11 lines · Daniel Walker
Quoted 9 lines · OGAWA Hirofumi
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

We'll need to change it.

We can add a call to clocksource_rating_change() inside acpi_pm_need_workaround(), are there deeper dependencies?

There is no deeper dependencies. If it's meaning clocksource_reselect() in current git, it sounds good to me.

Quoted 8 lines
Quoted 5 lines

Ah, I was forgetting why I didn't before. If it's a buggy pmtmr, we'll get corrupted time until re-selecting the clocksource.

If anybody doesn't care this will be good with it. If not, we would need to back to old one. IIRC, John did it.

We could just reverse it, use the verified read function until we know it's a good PM timer, then switch to the faster read function.

Yes, we did it in old timer code.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#8 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

In reply to Daniel Walker
Quoted 3 lines · Daniel Walker

plain text document attachment (clocksource_init_call.patch) Since it's likely that this interface would get used during bootup I moved all the clocksource registration into the postcore initcall.

So this is still somewhat of an open question: While timekeeping_init runs quite early, and the timekeeping subsystem and its interface is usable early in the boot process, currently not all the clocksources are available as early. This is by design, as there may be clocksource driver modules loaded later on in the boot process, so we don't want to require it early.

So, the question becomes: Do we want to start using arch specific clocksources as early as possible, with the potential that we'll replace it when a better one shows up later? It would allow for finer grained timekeeping early in boot, which sounds nice, but I'm not sure how great the real need is for that.

Quoted 1 line

This also eliminated some clocksource shuffling during bootup.

Actually, I'm not sure I see this. Which shuffling does it avoid?

I suspect it might actually cause more shuffling, as some clocksources (well, just the TSC, really.. its such a pain...) are not disqualified until later because we don't know if the system will enter C3, or change cpufreq, etc.. By waiting longer, we increase the chance that those disqualifying actions will occur before we install it.

thanks
-john

#9 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 12 lines · john stultz
Quoted 3 lines · Daniel Walker

plain text document attachment (clocksource_init_call.patch) Since it's likely that this interface would get used during bootup I moved all the clocksource registration into the postcore initcall.

So this is still somewhat of an open question: While timekeeping_init runs quite early, and the timekeeping subsystem and its interface is usable early in the boot process, currently not all the clocksources are available as early. This is by design, as there may be clocksource driver modules loaded later on in the boot process, so we don't want to require it early.

Quoted 5 lines

So, the question becomes: Do we want to start using arch specific clocksources as early as possible, with the potential that we'll replace it when a better one shows up later? It would allow for finer grained timekeeping early in boot, which sounds nice, but I'm not sure how great the real need is for that.

My main motivation is that I'm assuming other uses of the interface will exist. Then anything that uses the interface after postcore will avoid switching clocks later.

If I for instance, just return clocksource_jiffies until the system is fully booted then any thing that got a clock early, even during part of device_initcall, would end up switching to a new clock when boot up finished. I think that was acceptable when just timekeeping might have been using the interface, but I don't know that it would scale well from 1 to 2 to 5 users of the interface. Then you would have several clock switches happened after boot up .

Quoted 3 lines
Quoted 1 line

This also eliminated some clocksource shuffling during bootup.

Actually, I'm not sure I see this. Which shuffling does it avoid?

The shuffling that you commented about in kernel/time/clocksource.c which was the reason for the "finished_booting" flag, and related code.

Quoted 5 lines

I suspect it might actually cause more shuffling, as some clocksources (well, just the TSC, really.. its such a pain...) are not disqualified until later because we don't know if the system will enter C3, or change cpufreq, etc.. By waiting longer, we increase the chance that those disqualifying actions will occur before we install it.

This is something I've struggled with, but it's still and issue with the current code to a lesser degree. Like cpufreq isn't likely to be used during bootup, but acpi sleep states might be..

The current code can be classified as avoiding shuffle, but not eliminating it. Like with the acpi_pm timer, I was thinking I'd just put it back into device_initcall and assume shuffling might happen in rare cases.

Daniel

#10 lore raw

Re: [PATCH 01/10] -mm: clocksource: increase initcall priority

Quoted 9 lines · Daniel Walker
Quoted 5 lines

So, the question becomes: Do we want to start using arch specific clocksources as early as possible, with the potential that we'll replace it when a better one shows up later? It would allow for finer grained timekeeping early in boot, which sounds nice, but I'm not sure how great the real need is for that.

My main motivation is that I'm assuming other uses of the interface will exist. Then anything that uses the interface after postcore will avoid switching clocks later.

What does it matter, when clocks switch? That's a one time event.

The boot code is different and there is nothing which requires the availability of that interface in the early boot process.

Quoted 7 lines

If I for instance, just return clocksource_jiffies until the system is fully booted then any thing that got a clock early, even during part of device_initcall, would end up switching to a new clock when boot up finished. I think that was acceptable when just timekeeping might have been using the interface, but I don't know that it would scale well from 1 to 2 to 5 users of the interface. Then you would have several clock switches happened after boot up .

What are the 5 users of that interface ?

There is one existing user, one artifical you try to create for sched_clock and some handwaving about instrumentation. Even when we have 5 users, then the switching of clocks does not matter anything. This happens the same way, when I load the highest rated clock source as a module during init.

Quoted 9 lines
Quoted 5 lines

I suspect it might actually cause more shuffling, as some clocksources (well, just the TSC, really.. its such a pain...) are not disqualified until later because we don't know if the system will enter C3, or change cpufreq, etc.. By waiting longer, we increase the chance that those disqualifying actions will occur before we install it.

This is something I've struggled with, but it's still and issue with the current code to a lesser degree. Like cpufreq isn't likely to be used during bootup, but acpi sleep states might be..

Lesser degree ? You have an issue, which was not there before you made the changes. This is simply regression and the ignoring of that regression is wilful breakage.

Quoted 4 lines

The current code can be classified as avoiding shuffle, but not eliminating it. Like with the acpi_pm timer, I was thinking I'd just put it back into device_initcall and assume shuffling might happen in rare cases.

Great. We install TSC in early boot and pmtimer in late boot. Now we have the fun of unsynced TSCs and time going backwards again, until we get pmtimer loaded. I have explained it to you already, but that is the reason why that stuff was moved into late boot.

Also you have not yet once given an explanation other than the "magic churn", why this is necessary. There is no churn. The clocksource layer is designed to allow the replacement of clock sources and it does not hurt at all. It does also not matter if there are 1 ore 100 users.

tglx

#11 lore raw

PATCH 2/10 -mm: clocksource: small cleanup

In reply to Daniel Walker

Mostly changing alignment. Just some general cleanup.

---
 include/linux/clocksource.h |    2 +-
 kernel/time/clocksource.c   |    6 +++---
 kernel/timer.c              |    7 ++++---
 3 files changed, 8 insertions(+), 7 deletions(-)
include/linux/clocksource.h +1 -1
Index: linux-2.6.18/include/linux/clocksource.h
===================================================================
@@ -159,7 +159,7 @@ static inline s64 cyc2ns(struct clocksou
  * Unless you're the timekeeping code, you should not be using this!
  */
 static inline void clocksource_calculate_interval(struct clocksource *c,
-						unsigned long length_nsec)
+					  	  unsigned long length_nsec)
 {
 	u64 tmp;
 
kernel/time/clocksource.c +3 -3
Index: linux-2.6.18/kernel/time/clocksource.c
===================================================================
@@ -143,7 +143,7 @@ int clocksource_register(struct clocksou
 	/* check if clocksource is already registered */
 	if (is_registered_source(c)) {
 		printk("register_clocksource: Cannot register %s. "
-			"Already registered!", c->name);
+		       "Already registered!", c->name);
 		ret = -EBUSY;
 	} else {
 		/* register it */
@@ -262,10 +262,10 @@ sysfs_show_available_clocksources(struct
  * Sysfs setup bits:
  */
 static SYSDEV_ATTR(current_clocksource, 0600, sysfs_show_current_clocksources,
-			sysfs_override_clocksource);
+		   sysfs_override_clocksource);
 
 static SYSDEV_ATTR(available_clocksource, 0600,
-			sysfs_show_available_clocksources, NULL);
+		   sysfs_show_available_clocksources, NULL);
 
 static struct sysdev_class clocksource_sysclass = {
 	set_kset_name("clocksource"),
kernel/timer.c +4 -3
Index: linux-2.6.18/kernel/timer.c
===================================================================
@@ -714,7 +714,7 @@ static int change_clocksource(void)
 		clock = new;
 		clock->cycle_last = now;
 		printk(KERN_INFO "Time: %s clocksource has been installed.\n",
-					clock->name);
+		       clock->name);
 		return 1;
 	} else if (clock->update_callback) {
 		return clock->update_callback();
@@ -722,7 +722,7 @@ static int change_clocksource(void)
 	return 0;
 }
 #else
-#define change_clocksource() (0)
+#define change_clocksource()	do { 0; } while(0)
 #endif
 
 /**
@@ -940,7 +940,8 @@ static void update_wall_time(void)
 
 		/* accumulate error between NTP and clock interval */
 		clock->error += current_tick_length();
-		clock->error -= clock->xtime_interval << (TICK_LENGTH_SHIFT - clock->shift);
+		clock->error -= clock->xtime_interval <<
+				(TICK_LENGTH_SHIFT - clock->shift);
 	}
 
 	/* correct the clock when NTP error is too big */

--

#13 lore raw

PATCH 3/10 -mm: clocksource: move old API calls

In reply to Daniel Walker

I added this to make the next few patches cleaner. The mixing of code removal and code addition can make a patchset harder to read.

There's nothing new here from the first patchset, it just moves some code out of the way.

---
 kernel/time/clocksource.c |  120 +++++++++++++++++++++++-----------------------
 1 files changed, 61 insertions(+), 59 deletions(-)
kernel/time/clocksource.c +61 -59
Index: linux-2.6.18/kernel/time/clocksource.c
===================================================================
@@ -31,6 +31,8 @@
 
 /* XXX - Would like a better way for initializing curr_clocksource */
 extern struct clocksource clocksource_jiffies;
+static int is_registered_source(struct clocksource *c);
+static struct clocksource *select_clocksource(void);
 
 /*[Clocksource internal variables]---------
  * curr_clocksource:
@@ -70,65 +72,6 @@ struct clocksource *clocksource_get_next
 }
 
 /**
- * select_clocksource - Finds the best registered clocksource.
- *
- * Private function. Must hold clocksource_lock when called.
- *
- * Looks through the list of registered clocksources, returning
- * the one with the highest rating value. If there is a clocksource
- * name that matches the override string, it returns that clocksource.
- */
-static struct clocksource *select_clocksource(void)
-{
-	struct clocksource *best = NULL;
-	struct list_head *tmp;
-
-	list_for_each(tmp, &clocksource_list) {
-		struct clocksource *src;
-
-		src = list_entry(tmp, struct clocksource, list);
-		if (!best)
-			best = src;
-
-		/* check for override: */
-		if (strlen(src->name) == strlen(override_name) &&
-		    !strcmp(src->name, override_name)) {
-			best = src;
-			break;
-		}
-		/* pick the highest rating: */
-		if (src->rating > best->rating)
-		 	best = src;
-	}
-
-	return best;
-}
-
-/**
- * is_registered_source - Checks if clocksource is registered
- * @c:		pointer to a clocksource
- *
- * Private helper function. Must hold clocksource_lock when called.
- *
- * Returns one if the clocksource is already registered, zero otherwise.
- */
-static int is_registered_source(struct clocksource *c)
-{
-	int len = strlen(c->name);
-	struct list_head *tmp;
-
-	list_for_each(tmp, &clocksource_list) {
-		struct clocksource *src;
-
-		src = list_entry(tmp, struct clocksource, list);
-		if (strlen(src->name) == len &&	!strcmp(src->name, c->name))
-			return 1;
-	}
-
-	return 0;
-}
-
-/**
  * clocksource_register - Used to install new clocksources
  * @t:		clocksource to be registered
  *
@@ -334,3 +277,62 @@ static int __init boot_override_clock(ch
 }
 
 __setup("clock=", boot_override_clock);
+
+/**
+ * select_clocksource - Finds the best registered clocksource.
+ *
+ * Private function. Must hold clocksource_lock when called.
+ *
+ * Looks through the list of registered clocksources, returning
+ * the one with the highest rating value. If there is a clocksource
+ * name that matches the override string, it returns that clocksource.
+ */
+static struct clocksource *select_clocksource(void)
+{
+	struct clocksource *best = NULL;
+	struct list_head *tmp;
+
+	list_for_each(tmp, &clocksource_list) {
+		struct clocksource *src;
+
+		src = list_entry(tmp, struct clocksource, list);
+		if (!best)
+			best = src;
+
+		/* check for override: */
+		if (strlen(src->name) == strlen(override_name) &&
+		    !strcmp(src->name, override_name)) {
+			best = src;
+			break;
+		}
+		/* pick the highest rating: */
+		if (src->rating > best->rating)
+		 	best = src;
+	}
+
+	return best;
+}
+
+/**
+ * is_registered_source - Checks if clocksource is registered
+ * @c:		pointer to a clocksource
+ *
+ * Private helper function. Must hold clocksource_lock when called.
+ *
+ * Returns one if the clocksource is already registered, zero otherwise.
+ */
+static int is_registered_source(struct clocksource *c)
+{
+	int len = strlen(c->name);
+	struct list_head *tmp;
+
+	list_for_each(tmp, &clocksource_list) {
+		struct clocksource *src;
+
+		src = list_entry(tmp, struct clocksource, list);
+		if (strlen(src->name) == len &&	!strcmp(src->name, c->name))
+			return 1;
+	}
+
+	return 0;
+}

--

#14 lore raw

PATCH 4/10 -mm: clocksource: add some new API calls

In reply to Daniel Walker

originally used plist but removed it in this patch, and used a sorted list which is just as fast with a lot less memory overhead.

Introduces some new API calls,

- clocksource_get_clock()
Allows a clock lookup by name.
- clocksource_rating_change()
Used by a clocksource to signal a rating change. Replaces reselect_clocksource()

I also moved the the clock source list to a plist, which removes some lookup overhead in the average case.

---
 arch/i386/kernel/tsc.c      |    2 
 include/linux/clocksource.h |   44 ++++++++-
 kernel/time/clocksource.c   |  213 ++++++++++++++++++++++++++++----------------
 3 files changed, 179 insertions(+), 80 deletions(-)
arch/i386/kernel/tsc.c +1 -1
Index: linux-2.6.18/arch/i386/kernel/tsc.c
===================================================================
@@ -351,7 +351,7 @@ static int tsc_update_callback(void)
 	/* check to see if we should switch to the safe clocksource: */
 	if (clocksource_tsc.rating != 50 && check_tsc_unstable()) {
 		clocksource_tsc.rating = 50;
-		clocksource_reselect();
+		clocksource_rating_change(&clocksource_tsc);
 		change = 1;
 	}
 
include/linux/clocksource.h +41 -3

67 lines not on this page · raw message

kernel/time/clocksource.c +137 -76

273 lines not on this page · raw message

--

Acked-by on v1 4/10
#15 lore raw

Re: [PATCH 04/10] -mm: clocksource: add some new API calls

Quoted 11 lines · Daniel Walker

plain text document attachment (clocksource_user_api.patch) originally used plist but removed it in this patch, and used a sorted list which is just as fast with a lot less memory overhead.

Introduces some new API calls,

- clocksource_get_clock()
Allows a clock lookup by name.
- clocksource_rating_change()
Used by a clocksource to signal a rating change. Replaces reselect_clocksource()

Adds ns2cyc interface. Just to keep things in logical chunks, maybe would that chunk be better added with the patch that uses it?

Quoted 2 lines

I also moved the the clock source list to a plist, which removes some lookup overhead in the average case.

Probably need to update the header, as you don't use a plist now. :)

Quoted 1 line

Otherwise this patch looks like a good cleanup to me.

thanks
-john

#16 lore raw

PATCH 5/10 -mm: clocksource: convert generic timeofday

In reply to Daniel Walker

Delete alot of remaining code in kernel/time/clocksource.c that is replaced with this patch. Removed the deprecated "clock" kernel parameter.

Shifts some of the code around so that the time of day override happens inside kernel/timer.c.

The biggest timeofday changes are in update_wall_time() and change_clocksource(). I removed the unconditional call to change_clocksource(), and replaced it with a single atomic check. The atomic is asserted only when a clock change is needed. update_callback is no longer driven from update_wall_time().

The fast path is now a single atomic check.

---
 include/linux/clocksource.h |    3 
 kernel/time/clocksource.c   |  216 ++++++--------------------------------------
 kernel/timer.c              |  167 +++++++++++++++++++++++++++++-----
 3 files changed, 178 insertions(+), 208 deletions(-)
include/linux/clocksource.h +2 -1
Index: linux-2.6.18/include/linux/clocksource.h
===================================================================
@@ -205,7 +205,8 @@ static inline void clocksource_calculate
 
 
 /* used to install a new clocksource */
-extern struct clocksource *clocksource_get_next(void);
+extern int clocksource_sysfs_register(struct sysdev_attribute*);
+extern void clocksource_sysfs_unregister(struct sysdev_attribute*);
 extern int clocksource_register(struct clocksource*);
 extern void clocksource_rating_change(struct clocksource*);
 extern struct clocksource * clocksource_get_clock(char*);
kernel/time/clocksource.c +30 -186

292 lines not on this page · raw message

kernel/timer.c +146 -21

213 lines not on this page · raw message

--

#17 lore raw

Re: [PATCH 05/10] -mm: clocksource: convert generic timeofday

Andrew,

On 2006-10-06, Daniel Walker wrote:
[]

Quoted 1 line

+int clocksource_sysfs_register(struct sysdev_attribute * attr)

[]

Quoted 1 line

static int __init init_clocksource_sysfs(void)

it seems kernel/time/clocksource.c doesn't honor CONFIG_SYSFS at all...

Maybe this option isn't needed any more ? It doesn't exist in menuconfig, and i couldn't set in `n' manually.

[]

kernel/timer.c line 22

Quoted 7 lines
kernel/timer.c +2 -0
@@ -17,6 +17,8 @@
  *  2000-10-05  Implemented scalable SMP per-CPU timer handling.
  *                              Copyright (C) 2000, 2001, 2002  Ingo Molnar
  *              Designed by David S. Miller, Alexey Kuznetsov and Ingo Molnar
+ *  2006-08-03  Added usage of the generic clocksource API
+ *				Copyright (C) 2006 MontaVista, Daniel Walker
  */

there are comments about having new source management system, thus, logs on top are not needed any more...

-o--=O`C
#oo'L O
<___=E M

#18 lore raw

Re: [PATCH 05/10] -mm: clocksource: convert generic timeofday

In reply to Daniel Walker
Quoted 4 lines · Daniel Walker

plain text document attachment (clocksource_more_generic.patch) Delete alot of remaining code in kernel/time/clocksource.c that is replaced with this patch. Removed the deprecated "clock" kernel parameter.

Hmmm. This patch is a bit more confusing. From first glance it looks like a lot of code churn for not a whole lot of benefit. And as Thomas already mentioned, you should probably leave the "clock" bit alone for now.

Quoted 2 lines

Shifts some of the code around so that the time of day override happens inside kernel/timer.c.

Maybe could you explain your rational for this a bit more. I personally prefer the current breakdown, where the clocksource selection and override bits are in the clocksource code.

Currently the layering is like this:
[timekeeping core]
[clocksource core]
[clocksource drivers]

Where timekeeping tries to have as little knowledge as possible of the details of the clocksource drivers (outside of basic knowledge of how to use them). To the timekeeping core, all clocksources are the same. It leaves the selection algorithm and its management up to the clocksource core.

Now if I understand your intent you seem to be splitting it up a bit:

[timekeeping core] [sched_clock code]
[timekeeping clocksource selection] [sched_clock clocksource selection]
[ clocksource core ]
[ clocksource drivers ]

Where the selection code is moved from the clocksource core into the timekeeping code. I can understand some of the rational, as timekeeping and sched_clock have differing selection criteria, so why not have separate logic and share the clocksource core.

So, here's where I'm coming from on this issue: I feel sched_clock to be a unfortunately necessary hack. Ideally timekeeping reads should be fast enough to do from the scheduler, but that just is not the case (just on most arches, some don't have this problem). And since its just scheduler decisions, it does not need the correctness that timekeeping needs, so we have this arch specific hook that does whatever it needs. And since its sorta simple and stupid, the code duplication is pretty minor (no NTP adjustments, etc).

In my mind this reduces the benefit gained from making a generic sched_clock. Currently the clocksource rating logic for timekeeping is pretty simple: "weigh correctness first, then consider performance".

Now to have a generic sched_clock, we're going to have to introduce a new rating scale, which would select a more vague "speed over correctness, as long as its totally not insane" logic. To me, it seems a bit complicated for generic logic.

Thus I prefer having the clocksource core keep the an understanding of the "correctness first, then performance".

Now, I don't want to discourage your efforts here (BTW: I really appreciate them, and I think attempting new users for the clocksource infrastructure will make that infrastructure cleaner and better). It seems perfectly logical to use the clocksource infrastructure in sched_clock, but maybe, since sched_clock is the necessary hack that it is, we can do a more minor cleanup, with less impact to the clocksource infrastructure?

Maybe an idea just to start, would be to have the arch specific sched_clock() code use __get_clock(char* name), with its internal selection logic based on the clocksource names. This will then have minor impact on the current timekeeping/clocksource core code, but still allow for some reduction in code duplication. Then as hardware clocksources are tested for viability (for example, HPET may be a good bet here, but ACPI PM would not), we can add that logic to the arch specific sched_clock code.

Sound reasonable?

Anyway, that was a bit long winded. I apologize. More specific comments below:

Quoted 116 lines

The biggest timeofday changes are in update_wall_time() and change_clocksource(). I removed the unconditional call to change_clocksource(), and replaced it with a single atomic check. The atomic is asserted only when a clock change is needed. update_callback is no longer driven from update_wall_time().

The fast path is now a single atomic check.

---
 include/linux/clocksource.h |    3 
 kernel/time/clocksource.c   |  216 ++++++--------------------------------------
 kernel/timer.c              |  167 +++++++++++++++++++++++++++++-----
 3 files changed, 178 insertions(+), 208 deletions(-)

Index: linux-2.6.18/include/linux/clocksource.h
===================================================================

include/linux/clocksource.h +2 -1
@@ -205,7 +205,8 @@ static inline void clocksource_calculate
 
 
 /* used to install a new clocksource */
-extern struct clocksource *clocksource_get_next(void);
+extern int clocksource_sysfs_register(struct sysdev_attribute*);
+extern void clocksource_sysfs_unregister(struct sysdev_attribute*);
 extern int clocksource_register(struct clocksource*);
 extern void clocksource_rating_change(struct clocksource*);
 extern struct clocksource * clocksource_get_clock(char*);

Index: linux-2.6.18/kernel/time/clocksource.c
===================================================================

kernel/time/clocksource.c +5 -45
@@ -5,6 +5,8 @@
  *
  * Copyright (C) 2004, 2005 IBM, John Stultz ([email protected])
  *
+ * Copyright (C) 2006 MontaVista Daniel Walker ([email protected])
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -21,7 +23,6 @@
  *
  * TODO WishList:
  *   o Allow clocksource drivers to be unregistered
- *   o get rid of clocksource_jiffies extern
  */
 
 #include <linux/clocksource.h>
@@ -29,45 +30,15 @@
 #include <linux/init.h>
 #include <linux/module.h>
 
-/* XXX - Would like a better way for initializing curr_clocksource */
-extern struct clocksource clocksource_jiffies;
-
 /*[Clocksource internal variables]---------
- * curr_clocksource:
- *	currently selected clocksource. Initialized to clocksource_jiffies.
- * next_clocksource:
- *	pending next selected clocksource.
  * clocksource_list:
  *	priority list with the registered clocksources
  * clocksource_lock:
- *	protects manipulations to curr_clocksource and next_clocksource
- *	and the clocksource_list
- * override_name:
- *	Name of the user-specified clocksource.
+ * 	protects manipulations to the clocksource_list
  */
-static struct clocksource *curr_clocksource = &clocksource_jiffies;
-static struct clocksource *next_clocksource;
-static struct list_head clocksource_list = LIST_HEAD_INIT(clocksource_list);
+static __read_mostly
+struct list_head clocksource_list = LIST_HEAD_INIT(clocksource_list);
 static DEFINE_SPINLOCK(clocksource_lock);
-static char override_name[32];
-
-/**
- * clocksource_get_next - Returns the selected clocksource
- *
- */
-struct clocksource *clocksource_get_next(void)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&clocksource_lock, flags);
-	if (next_clocksource) {
-		curr_clocksource = next_clocksource;
-		next_clocksource = NULL;
-	}
-	spin_unlock_irqrestore(&clocksource_lock, flags);
-
-	return curr_clocksource;
-}
 
 /**
  * __is_registered - Returns a clocksource if it's registered
@@ -95,28 +66,6 @@ static struct clocksource * __is_registe
 }
 
 /**
- * __get_clock - Finds a specific clocksource
- * @name:		name of the clocksource to return
- *
- * Private function. Must hold clocksource_lock when called.
- *
- * Returns the clocksource if registered, zero otherwise.
- * If the @name is null the highest rated clock is returned.
- */
-static inline struct clocksource * __get_clock(char * name)
-{
-

kernel/time/clocksource.c static struct clocksource * __is_registe · line 118

Quoted 10 lines
kernel/time/clocksource.c +0 -10
-	if (unlikely(list_empty(&clocksource_list)))
-		return &clocksource_jiffies;
-
-	if (!name)
-		return list_entry(clocksource_list.next,
-				  struct clocksource, list);
-
-	return __is_registered(name);
-}
-

Errr.. Wasn't this function just added in the last patch? Can we reduce the churn here a bit?

Quoted 20 lines
kernel/time/clocksource.c +7 -2
-/**
  * clocksource_get_clock - Finds a specific clocksource
  * @name:		name of the clocksource to return
  *
@@ -128,29 +77,17 @@ struct clocksource * clocksource_get_clo
 	unsigned long flags;
 
 	spin_lock_irqsave(&clocksource_lock, flags);
-	ret = __get_clock(name);
+	if (unlikely(list_empty(&clocksource_list)))
+		ret = &clocksource_jiffies;
+	else if (!name)
+		ret = list_entry(clocksource_list.next,
+				 struct clocksource, list);
+	else
+		ret = __is_registered(name);
 	spin_unlock_irqrestore(&clocksource_lock, flags);
 	return ret;
 }
 

[snip]

Quoted 18 lines
kernel/time/clocksource.c +11 -1
@@ -952,10 +1061,26 @@ static void update_wall_time(void)
 	clock->xtime_nsec -= (s64)xtime.tv_nsec << clock->shift;
 
 	/* check to see if there is a new clocksource to use */
-	if (change_clocksource()) {
+	if (unlikely(atomic_read(&clock_check))) {
+
+		/*
+		 * Switch to the new override clock, or the highest
+		 * rated clock.
+		 */
+		if (*clock_override_name)
+			change_clocksource(clock_override_name);
+		else
+			change_clocksource(NULL);
+
 		clock->error = 0;
 		clock->xtime_nsec = 0;

kernel/time/clocksource.c static void update_wall_time(void) · line 1086

Quoted 10 lines
kernel/time/clocksource.c +6 -0
 		clocksource_calculate_interval(clock, tick_nsec);
+
+		/*
+		 * Remove the change signal
+		 */
+		atomic_dec(&clock_check);
+
 	}
 }
 

I think this last chunk (changing the clocksource switching logic) has some potential. Mind breaking it out into a separate patch?

thanks
-john

#19 lore raw

Re: [PATCH 05/10] -mm: clocksource: convert generic timeofday

Quoted 10 lines · john stultz
Quoted 4 lines · Daniel Walker

plain text document attachment (clocksource_more_generic.patch) Delete alot of remaining code in kernel/time/clocksource.c that is replaced with this patch. Removed the deprecated "clock" kernel parameter.

Hmmm. This patch is a bit more confusing. From first glance it looks like a lot of code churn for not a whole lot of benefit. And as Thomas already mentioned, you should probably leave the "clock" bit alone for now.

The benefits is more in the separation of the two. I'll explain the rational below.

Quoted 20 lines
Quoted 2 lines

Shifts some of the code around so that the time of day override happens inside kernel/timer.c.

Maybe could you explain your rational for this a bit more. I personally prefer the current breakdown, where the clocksource selection and override bits are in the clocksource code.

Currently the layering is like this:
[timekeeping core]
[clocksource core]
[clocksource drivers]

Where timekeeping tries to have as little knowledge as possible of the details of the clocksource drivers (outside of basic knowledge of how to use them). To the timekeeping core, all clocksources are the same. It leaves the selection algorithm and its management up to the clocksource core.

Quoted 7 lines

Now if I understand your intent you seem to be splitting it up a bit:

[timekeeping core] [sched_clock code]
[timekeeping clocksource selection] [sched_clock clocksource selection]
[ clocksource core ]
[ clocksource drivers ]

This is mostly how I see the layers, except after sched_clock I see "..."

Quoted 26 lines

Where the selection code is moved from the clocksource core into the timekeeping code. I can understand some of the rational, as timekeeping and sched_clock have differing selection criteria, so why not have separate logic and share the clocksource core.

So, here's where I'm coming from on this issue: I feel sched_clock to be a unfortunately necessary hack. Ideally timekeeping reads should be fast enough to do from the scheduler, but that just is not the case (just on most arches, some don't have this problem). And since its just scheduler decisions, it does not need the correctness that timekeeping needs, so we have this arch specific hook that does whatever it needs. And since its sorta simple and stupid, the code duplication is pretty minor (no NTP adjustments, etc).

In my mind this reduces the benefit gained from making a generic sched_clock. Currently the clocksource rating logic for timekeeping is pretty simple: "weigh correctness first, then consider performance".

Now to have a generic sched_clock, we're going to have to introduce a new rating scale, which would select a more vague "speed over correctness, as long as its totally not insane" logic. To me, it seems a bit complicated for generic logic.

Thus I prefer having the clocksource core keep the an understanding of the "correctness first, then performance".

Quoted 7 lines

Now, I don't want to discourage your efforts here (BTW: I really appreciate them, and I think attempting new users for the clocksource infrastructure will make that infrastructure cleaner and better). It seems perfectly logical to use the clocksource infrastructure in sched_clock, but maybe, since sched_clock is the necessary hack that it is, we can do a more minor cleanup, with less impact to the clocksource infrastructure?

First, I've not done this clean up specifically for sched_clock. The sched_clock changes are just there as an example of the interface usage.

Quoted 10 lines

Maybe an idea just to start, would be to have the arch specific sched_clock() code use __get_clock(char* name), with its internal selection logic based on the clocksource names. This will then have minor impact on the current timekeeping/clocksource core code, but still allow for some reduction in code duplication. Then as hardware clocksources are tested for viability (for example, HPET may be a good bet here, but ACPI PM would not), we can add that logic to the arch specific sched_clock code.

Sound reasonable?

Yes. We could do this.. It keeps the performance level mostly flat while removing all the cycles to nanosecond shift logic in every architecture.

Quoted 4 lines

Anyway, that was a bit long winded. I apologize. More specific comments below:

ok.

Quoted 18 lines
Quoted 18 lines

/**
- * __get_clock - Finds a specific clocksource
- * @name: name of the clocksource to return
- *
- * Private function. Must hold clocksource_lock when called.
- *
- * Returns the clocksource if registered, zero otherwise.
- * If the @name is null the highest rated clock is returned.
- */

kernel/time/clocksource.c +0 -8
-static inline struct clocksource * __get_clock(char * name)
-{
-
-	if (unlikely(list_empty(&clocksource_list)))
-		return &clocksource_jiffies;
-
-	if (!name)
-		return list_entry(clocksource_list.next,
Quoted 8 lines

kernel/time/clocksource.c static struct clocksource * __is_registe · line 118

Quoted 5 lines
kernel/time/clocksource.c +0 -5
-				  struct clocksource, list);
-
-	return __is_registered(name);
-}
-

Errr.. Wasn't this function just added in the last patch? Can we reduce the churn here a bit?

I tried, but I also have to make each patch compile. So it gets a bit tricky.

Quoted 23 lines
Quoted 23 lines
kernel/timer.c +14 -1
@@ -952,10 +1061,26 @@ static void update_wall_time(void)
 	clock->xtime_nsec -= (s64)xtime.tv_nsec << clock->shift;
 
 	/* check to see if there is a new clocksource to use */
-	if (change_clocksource()) {
+	if (unlikely(atomic_read(&clock_check))) {
+
+		/*
+		 * Switch to the new override clock, or the highest
+		 * rated clock.
+		 */
+		if (*clock_override_name)
+			change_clocksource(clock_override_name);
+		else
+			change_clocksource(NULL);
+
 		clock->error = 0;
 		clock->xtime_nsec = 0;
 		clocksource_calculate_interval(clock, tick_nsec);
+
+		/*
+		 * Remove the change signal
Quoted 8 lines

kernel/timer.c static void update_wall_time(void) · line 1086

Quoted 6 lines
kernel/timer.c +3 -0
+		 */
+		atomic_dec(&clock_check);
+
 	}
 }
 

I think this last chunk (changing the clocksource switching logic) has some potential. Mind breaking it out into a separate patch?

Maybe, but part of this fell out of reorganizing the code.

Daniel

#20 lore raw

PATCH 6/10 -mm: clocksource: add block notifier

In reply to Daniel Walker

Adds a call back interface for register/rating change events.

---
 include/linux/clocksource.h |    8 ++++++++
 kernel/time/clocksource.c   |   19 ++++++++++++++++++-
 kernel/timer.c              |   12 ++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)
include/linux/clocksource.h +8 -0
Index: linux-2.6.18/include/linux/clocksource.h
===================================================================
@@ -14,6 +14,7 @@
 #include <linux/list.h>
 #include <linux/plist.h>
 #include <linux/sysdev.h>
+#include <linux/notifier.h>
 #include <asm/div64.h>
 #include <asm/io.h>
 
@@ -26,6 +27,12 @@ typedef u64 cycle_t;
  */
 extern struct clocksource clocksource_jiffies;
 
+/*
+ * Block notifier flags.
+ */
+#define CLOCKSOURCE_NOTIFY_REGISTER	1
+#define CLOCKSOURCE_NOTIFY_RATING	2
+
 /**
  * struct clocksource - hardware abstraction for a free running counter
  *	Provides mostly state-free accessors to the underlying hardware.
@@ -205,6 +212,7 @@ static inline void clocksource_calculate
 
 
 /* used to install a new clocksource */
+extern int clocksource_notifier_register(struct notifier_block*);
 extern int clocksource_sysfs_register(struct sysdev_attribute*);
 extern void clocksource_sysfs_unregister(struct sysdev_attribute*);
 extern int clocksource_register(struct clocksource*);
kernel/time/clocksource.c +18 -1
Index: linux-2.6.18/kernel/time/clocksource.c
===================================================================
@@ -39,6 +39,18 @@
 static __read_mostly
 struct list_head clocksource_list = LIST_HEAD_INIT(clocksource_list);
 static DEFINE_SPINLOCK(clocksource_lock);
+static ATOMIC_NOTIFIER_HEAD(clocksource_list_notifier);
+
+/**
+ * clocksource_notifier_register - Registers a list change notifier
+ * @nb:		pointer to a notifier block
+ *
+ * Returns zero always.
+ */
+int clocksource_notifier_register(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_register(&clocksource_list_notifier, nb);
+}
 
 /**
  * __is_registered - Returns a clocksource if it's registered
@@ -139,6 +151,9 @@ int clocksource_register(struct clocksou
  		__sorted_list_add(c);
 	}
 	spin_unlock_irqrestore(&clocksource_lock, flags);
+
+	atomic_notifier_call_chain(&clocksource_list_notifier,
+ 				   CLOCKSOURCE_NOTIFY_REGISTER, c);
 	return ret;
 }
 EXPORT_SYMBOL(clocksource_register);
@@ -165,7 +180,9 @@ void clocksource_rating_change(struct cl
 	list_del_init(&c->list);
 	__sorted_list_add(c);
 
-	/* XXX: Add block notifier to signal new rating */
+	atomic_notifier_call_chain(&clocksource_list_notifier,
+				   CLOCKSOURCE_NOTIFY_RATING, c);
+
 	spin_unlock_irqrestore(&clocksource_lock, flags);
 }
 EXPORT_SYMBOL(clocksource_rating_change);
kernel/timer.c +12 -0
Index: linux-2.6.18/kernel/timer.c
===================================================================
@@ -819,6 +819,17 @@ static int __init boot_override_clocksou
 }
 __setup("timeofday_clocksource=", boot_override_clocksource);
 
+static int
+clocksource_callback(struct notifier_block *nb, unsigned long op, void *c)
+{
+	atomic_inc(&clock_check);
+	return 0;
+}
+
+static struct notifier_block clocksource_nb = {
+	.notifier_call = clocksource_callback,
+};
+
 #else
 #define change_clocksource(x)	do { } while(0)
 #endif
@@ -912,6 +923,7 @@ static int __init timekeeping_init_devic
 
 #ifdef CONFIG_GENERIC_TIME
 	clocksource_sysfs_register(&attr_timeofday_clocksource);
+	clocksource_notifier_register(&clocksource_nb);
 
 	/*
 	 * All the clocks should be registered at this point,

--

#21 lore raw

Re: [PATCH 06/10] -mm: clocksource: add block notifier

Quoted 6 lines · Daniel Walker

plain text document attachment (clocksource_add_block_notify_on_new_clock.patch) Adds a call back interface for register/rating change events.

This one looks interesting, but I'm not sure if we yet have the use-case really needed to implement notifier infrastructure (taking the comments from my last discussion). I don't really have any criticism with the code, I just worry it might be over-doing it.

Maybe it would be more persuasive if it went together with the first users of it, rather then as a independent infrastructure buildup patch.

thanks
-john

#22 lore raw

PATCH 7/10 -mm: clocksource: remove update_callback

In reply to Daniel Walker

Inorporated John's comment of moving the rating change code into mark_tsc_unstable() , then I renamed tsc_update_callback() to tsc_update_khz() and added a call to it into places that change the tsc_khz variable.

With the new notifier block the update_callback becomes obsolete.

---
 arch/i386/kernel/tsc.c      |   54 ++++++++++++++++++++++----------------------
 include/linux/clocksource.h |    2 -
 2 files changed, 28 insertions(+), 28 deletions(-)
arch/i386/kernel/tsc.c +28 -26
Index: linux-2.6.18/arch/i386/kernel/tsc.c
===================================================================
@@ -50,8 +50,7 @@ static int __init tsc_setup(char *str)
 __setup("notsc", tsc_setup);
 
 /*
- * code to mark and check if the TSC is unstable
- * due to cpufreq or due to unsynced TSCs
+ * Flag that denotes an unstable tsc and check function.
  */
 static int tsc_unstable;
 
@@ -60,12 +59,6 @@ static inline int check_tsc_unstable(voi
 	return tsc_unstable;
 }
 
-void mark_tsc_unstable(void)
-{
-	tsc_unstable = 1;
-}
-EXPORT_SYMBOL_GPL(mark_tsc_unstable);
-
 /* Accellerators for sched_clock()
  * convert from cycles(64bits) => nanoseconds (64bits)
  *  basic equation:
@@ -171,6 +164,21 @@ err:
 	return 0;
 }
 
+#if !defined(CONFIG_SMP) || defined(CONFIG_CPU_FREQ)
+static struct clocksource clocksource_tsc;
+static unsigned long current_tsc_khz;
+static void tsc_update_khz(void)
+{
+	/* only update if tsc_khz has changed: */
+	if (current_tsc_khz != tsc_khz) {
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+	}
+
+}
+#endif
+
 int recalibrate_cpu_khz(void)
 {
 #ifndef CONFIG_SMP
@@ -179,6 +187,7 @@ int recalibrate_cpu_khz(void)
 	if (cpu_has_tsc) {
 		cpu_khz = calculate_cpu_khz();
 		tsc_khz = cpu_khz;
+		tsc_update_khz();
 		cpu_data[0].loops_per_jiffy =
 			cpufreq_scale(cpu_data[0].loops_per_jiffy,
 					cpu_khz_old, cpu_khz);
@@ -282,6 +291,7 @@ time_cpufreq_notifier(struct notifier_bl
 						ref_freq, freq->new);
 			if (!(freq->flags & CPUFREQ_CONST_LOOPS)) {
 				tsc_khz = cpu_khz;
+				tsc_update_khz();
 				set_cyc2ns_scale(cpu_khz);
 				/*
 				 * TSC based sched_clock turns
@@ -322,7 +332,6 @@ core_initcall(cpufreq_tsc);
 /* clock source code */
 
 static unsigned long current_tsc_khz = 0;
-static int tsc_update_callback(void);
 
 static cycle_t read_tsc(void)
 {
@@ -340,31 +349,24 @@ static struct clocksource clocksource_ts
 	.mask			= CLOCKSOURCE_MASK(64),
 	.mult			= 0, /* to be set */
 	.shift			= 22,
-	.update_callback	= tsc_update_callback,
 	.is_continuous		= 1,
 };
 
-static int tsc_update_callback(void)
-{
-	int change = 0;
 
-	/* check to see if we should switch to the safe clocksource: */
-	if (clocksource_tsc.rating != 50 && check_tsc_unstable()) {
+/*
+ * code to mark if the TSC is unstable
+ * due to cpufreq or due to unsynced TSCs
+ */
+void mark_tsc_unstable(void)
+{
+	if (unlikely(!tsc_unstable)) {
 		clocksource_tsc.rating = 50;
 		clocksource_rating_change(&clocksource_tsc);
-		change = 1;
 	}
-
-	/* only update if tsc_khz has changed: */
-	if (current_tsc_khz != tsc_khz) {
-		current_tsc_khz = tsc_khz;
-		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
-							clocksource_tsc.shift);
-		change = 1;
-	}
-
-	return change;
+	tsc_unstable = 1;
 }
+EXPORT_SYMBOL_GPL(mark_tsc_unstable);
+
 
 static int __init dmi_mark_tsc_unstable(struct dmi_system_id *d)
 {
include/linux/clocksource.h +0 -2
Index: linux-2.6.18/include/linux/clocksource.h
===================================================================
@@ -59,7 +59,6 @@ extern struct clocksource clocksource_ji
  *			subtraction of non 64 bit counters
  * @mult:		cycle to nanosecond multiplier
  * @shift:		cycle to nanosecond divisor (power of two)
- * @update_callback:	called when safe to alter clocksource values
  * @is_continuous:	defines if clocksource is free-running.
  * @cycle_interval:	Used internally by timekeeping core, please ignore.
  * @xtime_interval:	Used internally by timekeeping core, please ignore.
@@ -72,7 +71,6 @@ struct clocksource {
 	cycle_t mask;
 	u32 mult;
 	u32 shift;
-	int (*update_callback)(void);
 	int is_continuous;
 
 	/* timekeeping specific data, ignore */

--

#23 lore raw

Re: [PATCH 07/10] -mm: clocksource: remove update_callback

Quoted 11 lines · Daniel Walker

plain text document attachment (clocksource_remove_update_callback.patch)
Inorporated John's comment of moving the rating change code into mark_tsc_unstable() , then I renamed tsc_update_callback() to tsc_update_khz() and added a call to it into places that change the tsc_khz variable.

With the new notifier block the update_callback becomes obsolete.

This (ie: dropping the update_callback logic) basically looks fine. Although it builds ontop of some of the patches I'm not excited about, so I'd probably want to see it independent of those changes.

On a related note: I take exception (albeit lightheartedly - I think he was painting with a broad brush) to Thomas' comment earlier about "fragile timekeeping". I feel the timekeeping code is really *leaps and bounds* better with regard to correctness and robustness. There have been a few embarrassing flubs, but really I do think we've made improvements.

Now, with that said, I will admit that the TSC code is somewhat fragile (and I believe this is what Thomas was getting at). Its been the real problem causer in most cases, so we need to be careful about changes to its logic that will affect clocksource selection.

So this patch in-particular, however reworked, would need some careful testing.

thanks
-john

Quoted 143 lines
---
 arch/i386/kernel/tsc.c      |   54 ++++++++++++++++++++++----------------------
 include/linux/clocksource.h |    2 -
 2 files changed, 28 insertions(+), 28 deletions(-)

Index: linux-2.6.18/arch/i386/kernel/tsc.c
===================================================================

arch/i386/kernel/tsc.c +28 -26
@@ -50,8 +50,7 @@ static int __init tsc_setup(char *str)
 __setup("notsc", tsc_setup);
 
 /*
- * code to mark and check if the TSC is unstable
- * due to cpufreq or due to unsynced TSCs
+ * Flag that denotes an unstable tsc and check function.
  */
 static int tsc_unstable;
 
@@ -60,12 +59,6 @@ static inline int check_tsc_unstable(voi
 	return tsc_unstable;
 }
 
-void mark_tsc_unstable(void)
-{
-	tsc_unstable = 1;
-}
-EXPORT_SYMBOL_GPL(mark_tsc_unstable);
-
 /* Accellerators for sched_clock()
  * convert from cycles(64bits) => nanoseconds (64bits)
  *  basic equation:
@@ -171,6 +164,21 @@ err:
 	return 0;
 }
 
+#if !defined(CONFIG_SMP) || defined(CONFIG_CPU_FREQ)
+static struct clocksource clocksource_tsc;
+static unsigned long current_tsc_khz;
+static void tsc_update_khz(void)
+{
+	/* only update if tsc_khz has changed: */
+	if (current_tsc_khz != tsc_khz) {
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+	}
+
+}
+#endif
+
 int recalibrate_cpu_khz(void)
 {
 #ifndef CONFIG_SMP
@@ -179,6 +187,7 @@ int recalibrate_cpu_khz(void)
 	if (cpu_has_tsc) {
 		cpu_khz = calculate_cpu_khz();
 		tsc_khz = cpu_khz;
+		tsc_update_khz();
 		cpu_data[0].loops_per_jiffy =
 			cpufreq_scale(cpu_data[0].loops_per_jiffy,
 					cpu_khz_old, cpu_khz);
@@ -282,6 +291,7 @@ time_cpufreq_notifier(struct notifier_bl
 						ref_freq, freq->new);
 			if (!(freq->flags & CPUFREQ_CONST_LOOPS)) {
 				tsc_khz = cpu_khz;
+				tsc_update_khz();
 				set_cyc2ns_scale(cpu_khz);
 				/*
 				 * TSC based sched_clock turns
@@ -322,7 +332,6 @@ core_initcall(cpufreq_tsc);
 /* clock source code */
 
 static unsigned long current_tsc_khz = 0;
-static int tsc_update_callback(void);
 
 static cycle_t read_tsc(void)
 {
@@ -340,31 +349,24 @@ static struct clocksource clocksource_ts
 	.mask			= CLOCKSOURCE_MASK(64),
 	.mult			= 0, /* to be set */
 	.shift			= 22,
-	.update_callback	= tsc_update_callback,
 	.is_continuous		= 1,
 };
 
-static int tsc_update_callback(void)
-{
-	int change = 0;
 
-	/* check to see if we should switch to the safe clocksource: */
-	if (clocksource_tsc.rating != 50 && check_tsc_unstable()) {
+/*
+ * code to mark if the TSC is unstable
+ * due to cpufreq or due to unsynced TSCs
+ */
+void mark_tsc_unstable(void)
+{
+	if (unlikely(!tsc_unstable)) {
 		clocksource_tsc.rating = 50;
 		clocksource_rating_change(&clocksource_tsc);
-		change = 1;
 	}
-
-	/* only update if tsc_khz has changed: */
-	if (current_tsc_khz != tsc_khz) {
-		current_tsc_khz = tsc_khz;
-		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
-							clocksource_tsc.shift);
-		change = 1;
-	}
-
-	return change;
+	tsc_unstable = 1;
 }
+EXPORT_SYMBOL_GPL(mark_tsc_unstable);
+
 
 static int __init dmi_mark_tsc_unstable(struct dmi_system_id *d)
 {

Index: linux-2.6.18/include/linux/clocksource.h
===================================================================

include/linux/clocksource.h +0 -3
@@ -59,7 +59,6 @@ extern struct clocksource clocksource_ji
  *			subtraction of non 64 bit counters
  * @mult:		cycle to nanosecond multiplier
  * @shift:		cycle to nanosecond divisor (power of two)
- * @update_callback:	called when safe to alter clocksource values
  * @is_continuous:	defines if clocksource is free-running.
  * @cycle_interval:	Used internally by timekeeping core, please ignore.
  * @xtime_interval:	Used internally by timekeeping core, please ignore.
@@ -72,7 +71,6 @@ struct clocksource {
 	cycle_t mask;
 	u32 mult;
 	u32 shift;
-	int (*update_callback)(void);
 	int is_continuous;
 
 	/* timekeeping specific data, ignore */
 
--
#24 lore raw

PATCH 8/10 -mm: clocksource: initialize list value

In reply to Daniel Walker

A change to clocksource initialization. It's optional for new clocksources, but prefered. If the list field is initialized it allows clocksource_register to complete faster since it doesn't have the scan the list of clocks doing strcmp on each.

---
 arch/i386/kernel/hpet.c          |    1 +
 arch/i386/kernel/i8253.c         |    1 +
 arch/i386/kernel/tsc.c           |    1 +
 drivers/clocksource/acpi_pm.c    |    1 +
 drivers/clocksource/cyclone.c    |    1 +
 drivers/clocksource/scx200_hrt.c |    1 +
 include/linux/clocksource.h      |    3 +++
 7 files changed, 9 insertions(+)
arch/i386/kernel/hpet.c +1 -0
Index: linux-2.6.18/arch/i386/kernel/hpet.c
===================================================================
@@ -27,6 +27,7 @@ static struct clocksource clocksource_hp
 	.mult		= 0, /* set below */
 	.shift		= HPET_SHIFT,
 	.is_continuous	= 1,
+	.list		= CLOCKSOURCE_LIST_INIT(clocksource_hpet.list),
 };
 
 static int __init init_hpet_clocksource(void)
arch/i386/kernel/i8253.c +1 -0
Index: linux-2.6.18/arch/i386/kernel/i8253.c
===================================================================
@@ -105,6 +105,7 @@ static struct clocksource clocksource_pi
 	.mask	= CLOCKSOURCE_MASK(32),
 	.mult	= 0,
 	.shift	= 20,
+	.list	= CLOCKSOURCE_LIST_INIT(clocksource_pit.list),
 };
 
 static int __init init_pit_clocksource(void)
arch/i386/kernel/tsc.c +1 -0
Index: linux-2.6.18/arch/i386/kernel/tsc.c
===================================================================
@@ -350,6 +350,7 @@ static struct clocksource clocksource_ts
 	.mult			= 0, /* to be set */
 	.shift			= 22,
 	.is_continuous		= 1,
+	.list			= CLOCKSOURCE_LIST_INIT(clocksource_tsc.list),
 };
 
 
drivers/clocksource/acpi_pm.c +1 -0
Index: linux-2.6.18/drivers/clocksource/acpi_pm.c
===================================================================
@@ -73,6 +73,7 @@ static struct clocksource clocksource_ac
 	.mult		= 0, /*to be caluclated*/
 	.shift		= 22,
 	.is_continuous	= 1,
+	.list		= CLOCKSOURCE_LIST_INIT(clocksource_acpi_pm.list),
 };
 
 
drivers/clocksource/cyclone.c +1 -0
Index: linux-2.6.18/drivers/clocksource/cyclone.c
===================================================================
@@ -32,6 +32,7 @@ static struct clocksource clocksource_cy
 	.mult		= 10,
 	.shift		= 0,
 	.is_continuous	= 1,
+	.list		= CLOCKSOURCE_LIST_INIT(clocksource_cyclone.list),
 };
 
 static int __init init_cyclone_clocksource(void)
drivers/clocksource/scx200_hrt.c +1 -0
Index: linux-2.6.18/drivers/clocksource/scx200_hrt.c
===================================================================
@@ -58,6 +58,7 @@ static struct clocksource cs_hrt = {
 	.read		= read_hrt,
 	.mask		= CLOCKSOURCE_MASK(32),
 	.is_continuous	= 1,
+	.list		= CLOCKSOURCE_LIST_INIT(cs_hrt.list),
 	/* mult, shift are set based on mhz27 flag */
 };
 
include/linux/clocksource.h +3 -0
Index: linux-2.6.18/include/linux/clocksource.h
===================================================================
@@ -82,6 +82,9 @@ struct clocksource {
 /* simplify initialization of mask field */
 #define CLOCKSOURCE_MASK(bits) (cycle_t)(bits<64 ? ((1ULL<<bits)-1) : -1)
 
+/* Abstracted list initialization */
+#define CLOCKSOURCE_LIST_INIT(x)	LIST_HEAD_INIT(x)
+
 /**
  * clocksource_khz2mult - calculates mult from khz and shift
  * @khz:		Clocksource frequency in KHz

--

#25 lore raw

Re: [PATCH 08/10] -mm: clocksource: initialize list value

Quoted 7 lines · Daniel Walker

plain text document attachment (clocksouce_list_init.patch)
A change to clocksource initialization. It's optional for new clocksources, but prefered. If the list field is initialized it allows clocksource_register to complete faster since it doesn't have the scan the list of clocks doing strcmp on each.

I dont' have any comments that haven't been said:

Drop the CLOCKSOURCE_LIST_INIT define, and make it required. Its easy enough to add.

thanks
-john

#26 lore raw

PATCH 9/10 -mm: clocksource: add generic sched_clock()

In reply to Daniel Walker

Adds a generic sched_clock, along with a boot time override for the scheduler clocksource (sched_clocksource). Hopefully the config option would eventually be removed.

---
 arch/i386/Kconfig      |    4 +++
 arch/i386/kernel/tsc.c |   61 ------------------------------------------------
 kernel/sched.c         |   62 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 61 deletions(-)
arch/i386/Kconfig +4 -0
Index: linux-2.6.18/arch/i386/Kconfig
===================================================================
@@ -18,6 +18,10 @@ config GENERIC_TIME
 	bool
 	default y
 
+config GENERIC_SCHED_CLOCK
+	bool
+	default y
+
 config LOCKDEP_SUPPORT
 	bool
 	default y
arch/i386/kernel/tsc.c +0 -61

79 lines not on this page · raw message

kernel/sched.c +62 -0

80 lines not on this page · raw message

--

#27 lore raw

PATCH 10/10 -mm: clocksource: update kernel parameters

In reply to Daniel Walker

Documents two new kernel parameters,

timeofday_clocksource
sched_clocksource

Removed old ones,

clocksource
clock

---
 Documentation/kernel-parameters.txt |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)
Documentation/kernel-parameters.txt +7 -10
Index: linux-2.6.18/Documentation/kernel-parameters.txt
===================================================================
@@ -351,13 +351,6 @@ and is between 256 and 4096 characters. 
 			Value can be changed at runtime via
 				/selinux/checkreqprot.
 
-	clock=		[BUGS=IA-32, HW] gettimeofday clocksource override.
-			[Deprecated]
-			Forces specified clocksource (if avaliable) to be used
-			when calculating gettimeofday(). If specified
-			clocksource is not avalible, it defaults to PIT.
-			Format: { pit | tsc | cyclone | pmtmr }
-
 	disable_8254_timer
 	enable_8254_timer
 			[IA32/X86_64] Disable/Enable interrupt 0 timer routing
@@ -1647,9 +1640,13 @@ and is between 256 and 4096 characters. 
 
 	time		Show timing data prefixed to each printk message line
 
-	clocksource=	[GENERIC_TIME] Override the default clocksource
-			Override the default clocksource and use the clocksource
-			with the name specified.
+	timeofday_clocksource=	[GENERIC_TIME]
+			Override the default time of day clocksource and use
+			the clocksource with the name specified.
+
+	sched_clocksource=	[GENERIC_TIME]
+			Override the default scheduler clocksource. Used for
+			timing only inside the scheduler.
 
 	tipar.timeout=	[HW,PPT]
 			Set communications timeout in tenths of a second

--

#28 lore raw
In reply to Daniel Walker
Quoted 11 lines · On Fri, 06 Oct 2006 11:54:39 -0700 Daniel Walker <[email protected]> wrote:

This patch set is meant to modify the clocksource structure and API so that it can be used by more than just the timekeeping code. My motivation is mainly that I feel the current clocksource interface could be used for much more than just timekeeping. So if we keep the clocksource interface (which I think we should) then we should get everything out of it that we can.

This set modifies the API, then converts the time keeping code over to the new API. I also added a generic sched_clock() which just re-uses the clocksource interface to provide a high quality scheduling clock (assuming a good clocksource). Several ARM board just output nanoseconds based on jiffies which is still possible with the generic sched_clock().

Well it all applies on top of the hrtimer/dynticks stuff with only a bit of fixing needed. And then it compiles.

But there's been so much time-related work happening lately that I'm inclined to park this work for a while, give the existing changes time to settle in and get debugged. And to give people time to review this new material. If that review is positive, we can bring this material into -mm in a week or so. OK?

#29 lore raw
Quoted 3 lines · Andrew Morton

Well it all applies on top of the hrtimer/dynticks stuff with only a bit of fixing needed. And then it compiles.

That makes sense, they should be pretty discrete.

Quoted 5 lines

But there's been so much time-related work happening lately that I'm inclined to park this work for a while, give the existing changes time to settle in and get debugged. And to give people time to review this new material. If that review is positive, we can bring this material into -mm in a week or so. OK?

Yeah, I'm not in a rush. Whatever you think is best.

Daniel