Skip to contentSkip to conversation

High-res-timers part 2 (x86 platform code) take 5.1

PATCH In review george anzinger 10 participants 17 messages Oct 9, 2002 – Oct 18, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 High-res-timers part 2 (x86 platform code) take 5.1

(Sigh) For some reason the earlier version of this message was truncated near the end of the patch. Lets try again.

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms. The high-res-timers use the periodic interrupt to "remind" the system to look at the clock. The clock should be relatively high resolution (1 micro second or better). This patch allows configuring of three possible clocks, the TSC, the ACPI pm timer, or the Programmable interrupt timer (PIT). Most of the changes in this patch are in the arch/i386/time.c code.

This patch uses (if available) the APIC timer(s) to generate 1/HZ ticks and sub 1/HZ ticks as needed. The PIT still interrupts, but if the APIC timer is available, just causes the wall clock update. No attempt is made to make this interrupt happen on jiffie boundaries, however, the APIC timers are disciplined to expire on 1/HZ boundaries to give consistent timer latencies WRT to the system time.

With this patch applied and enabled (at config time in the processor feature section), the system clock will be the specified clock. The PIT is not used to keep track of time, but only to remind the system to look at the clock. Sub jiffies are kept and available for code that knows how to use them.

Patch is against 2.5.41-bk2

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
arch/i386/Config.help +69 -0
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.41-bk2-core/arch/i386/Config.help linux/arch/i386/Config.help
@@ -52,6 +52,75 @@
   Say Y here if you are building a kernel for a desktop, embedded
   or real-time system.  Say N if you are unsure.
 
+High-res-timers
+CONFIG_HIGH_RES_TIMERS
+  POSIX timers are available by default.  This option enables high
+  resolution POSIX timers.  With this option the resolution is at
+  least 1 micro second.  High resolution is not free.  If enabled this
+  option will add a small overhead each time a timer expires that is
+  not on a 1/HZ tick boundry.  If no such timers are used the overhead
+  is nil.
+
+  This option enables two additional POSIX CLOCKS, CLOCK_REALTIME_HR
+  and CLOCK_MONOTONIC_HR.  Note that this option does not change the
+  resolution of CLOCK_REALTIME or CLOCK_MONOTONIC which remain at 1/HZ
+  resolution.
+
+High-res-timers clock
+CONFIG_HIGH_RES_TIMER_ACPI_PM 
+  This option allows you to choose the wall clock timer for your system.
+  With high resolution timers on the x86 platforms it is best to keep
+  the interrupt generating timer separate from the time keeping timer.
+  On x86 platforms there are three possible sources implemented for the
+  wall clock.  These are:
+ 
+  <timer>				<resolution>
+  ACPI power management (pm) timer	~280 nano seconds
+  TSC (Time Stamp Counter)		1/CPU clock
+  PIT (Programmable Interrupt Timer)	~838 nano seconds
+
+  The PIT is used to generate interrupts and at any given time will be
+  programmed to interrupt when the next timer is to expire or on the
+  next 1/HZ tick.  For this reason it is best to not use this timer as
+  the wall clock timer.  This timer has a resolution of 838 nano
+  seconds.  THIS OPTION SHOULD ONLY BE USED IF BOTH ACPI AND TSC ARE
+  NOT AVAILABLE.
+
+  The TSC runs at the cpu clock rate (i.e. its resolution is 1/CPU
+  clock) and it has a very low access time.  However, it is subject,
+  in some (incorrect) processors, to throttling to cool the cpu, and
+  to other slow downs during power management.  If your cpu is correct
+  and does not change the TSC frequency for throttling or power
+  management this is the best clock timer.
+
+  The ACPI pm timer is available on systems with Advanced Configuration
+  and Power Interface support.  The pm timer is available on these
+  systems even if you don't use or enable ACPI in the software or the
+  BIOS (but see Default ACPI pm timer address).  The timer has a
+  resolution of about 280 nanoseconds, however, the access time is a bit
+  higher that that of the TSC.  Since it is part of ACPI it is intended
+  to keep track of time while the system is under power management, thus
+  it is not subject to the problems of the TSC.
+
+  If you enable the ACPI pm timer and it can not be found, it is
+  possible that your BIOS is not producing the ACPI table or that your
+  machine does not support ACPI.  In the former case, see "Default ACPI
+  pm timer address".  If the timer is not found the boot will fail when
+  trying to calibrate the delay timer.
+
+Default ACPI pm timer address
+CONFIG_HIGH_RES_TIMER_ACPI_PM_ADD
+  This option is available for use on systems where the BIOS does not
+  generate the ACPI tables if ACPI is not enabled.  For example some
+  BIOSes will not generate the ACPI tables if APM is enabled.  The ACPI
+  pm timer is still available but can not be found by the software.
+  This option allows you to supply the needed address.  When the high
+  resolution timers code finds a valid ACPI pm timer address it reports
+  it in the boot messages log (look for lines that begin with
+  "High-res-timers:").  You can turn on the ACPI support in the BIOS,
+  boot the system and find this value.  You can then enter it at
+  configure time.  Both the report and the entry are in decimal.
+
 CONFIG_X86
   This is Linux's home port.  Linux was originally native to the Intel
   386, and runs on all the later x86 processors including the Intel
arch/i386/config.in +18 -0
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.41-bk2-core/arch/i386/config.in linux/arch/i386/config.in
@@ -156,6 +156,23 @@
 bool 'Huge TLB Page Support' CONFIG_HUGETLB_PAGE
 
 bool 'Symmetric multi-processing support' CONFIG_SMP
+bool 'Configure High-Resolution-Timers' CONFIG_HIGH_RES_TIMERS
+#
+# We assume that if the box doesn't have a TSC it doesn't have ACPI either.
+#
+if [ "$CONFIG_HIGH_RES_TIMERS" = "y" -a "$CONFIG_X86_TSC" = "y" ]; then
+	choice 'Clock source?' \
+		"ACPI-pm-timer  CONFIG_HIGH_RES_TIMER_ACPI_PM  \
+		Time-stamp-counter/TSC  CONFIG_HIGH_RES_TIMER_TSC \
+		Programable-interrupt-timer/PIT CONFIG_HIGH_RES_TIMER_PIT" Time-stamp-counter/TSC
+else
+	if [ "$CONFIG_HIGH_RES_TIMERS" = "y" ]; then
+		define_bool CONFIG_HIGH_RES_TIMER_PIT y
+        fi
+fi
+if [ "$CONFIG_HIGH_RES_TIMER_ACPI_PM" = "y" ]; then
+	int 'Default ACPI pm timer address' CONFIG_HIGH_RES_TIMER_ACPI_PM_ADD 0
+fi 
 bool 'Preemptible Kernel' CONFIG_PREEMPT
 if [ "$CONFIG_SMP" != "y" ]; then
    bool 'Local APIC support on uniprocessors' CONFIG_X86_UP_APIC
@@ -350,6 +367,7 @@
 else
    define_bool CONFIG_BLK_DEV_HD n
 fi
+
 endmenu
 
 mainmenu_option next_comment
arch/i386/kernel/Makefile +1 -0
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.41-bk2-core/arch/i386/kernel/Makefile linux/arch/i386/kernel/Makefile
@@ -17,6 +17,7 @@
 obj-$(CONFIG_KGDB)		+= kgdb_stub.o 
 obj-$(CONFIG_X86_MSR)		+= msr.o
 obj-$(CONFIG_X86_CPUID)		+= cpuid.o
+obj-$(CONFIG_HIGH_RES_TIMER_ACPI_PM) += high-res-tbxfroot.o
 obj-$(CONFIG_MICROCODE)		+= microcode.o
 obj-$(CONFIG_APM)		+= apm.o
 obj-$(CONFIG_ACPI)		+= acpi.o
arch/i386/kernel/apic.c +13 -3
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.41-bk2-core/arch/i386/kernel/apic.c linux/arch/i386/kernel/apic.c
@@ -801,7 +801,7 @@
  * P5 APIC double write bug.
  */
 
-#define APIC_DIVISOR 16
+#define APIC_DIVISOR 1
 
 void __setup_APIC_LVTT(unsigned int clocks)
 {
@@ -812,12 +812,12 @@
 	apic_write_around(APIC_LVTT, lvtt1_value);
 
 	/*
-	 * Divide PICLK by 16
+	 * Divide PICLK by 1
 	 */
 	tmp_value = apic_read(APIC_TDCR);
 	apic_write_around(APIC_TDCR, (tmp_value
 				& ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE))
-				| APIC_TDR_DIV_16);
+				| APIC_TDR_DIV_1);
 
 	apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
 }
@@ -1030,10 +1030,20 @@
 		 * Interrupts are already masked off at this point.
 		 */
 		prof_counter[cpu] = prof_multiplier[cpu];
+		/* 
+		 * deal with profiling later...
+		 */
+#ifndef CONFIG_HIGH_RES_TIMERS
 		if (prof_counter[cpu] != prof_old_multiplier[cpu]) {
 			__setup_APIC_LVTT(calibration_result/prof_counter[cpu]);
 			prof_old_multiplier[cpu] = prof_counter[cpu];
 		}
+#else
+		/*
+		* This is the 1/HZ count, can be changed by HRT code.
+		*/
+		__setup_APIC_LVTT(calibration_result);
+#endif
 
 #ifdef CONFIG_SMP
 		update_process_times(user);
arch/i386/kernel/high-res-tbxfroot.c +272 -0

272 lines not on this page · raw message

arch/i386/kernel/time.c +202 -54

434 lines not on this page · raw message

arch/i386/mach-generic/do_timer.h +5 -0
diff -urP -I \$Id:.*Exp \$ -X /usr/src/patch.exclude linux-2.5.41-bk2-core/arch/i386/mach-generic/do_timer.h linux/arch/i386/mach-generic/do_timer.h
@@ -14,6 +14,11 @@
 static inline void do_timer_interrupt_hook(struct pt_regs *regs)
 {
 	do_timer(regs);
+        IF_HIGH_RES(
+                if (!(new_jiffie() & 1))
+                        return;
+                jiffies_intr = 0;
+                )
 /*
  * In the SMP case we use the local APIC timer interrupt to do the
  * profiling, except when we simulate SMP mode on a uniprocessor
include/asm-i386/hrtime-M386.h +247 -0

247 lines not on this page · raw message

include/asm-i386/hrtime-M586.h +165 -0

165 lines not on this page · raw message

include/asm-i386/hrtime-Macpi.h +214 -0

214 lines not on this page · raw message

include/asm-i386/hrtime.h +482 -0

482 lines not on this page · raw message

include/asm-i386/sc_math.h +143 -0

143 lines not on this page · raw message

include/asm-i386/signal.h +75 -0

90 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Linus

#2 lore raw
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#3 lore raw
Quoted 30 lines · george anzinger
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Quoted 7 lines

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

??? The issue of ticks is separate from the issue of how often timer interrupts fire. Ticks just becomes the maximum resolution you can support/express.

If it makes sense to have two maximum tick resolutions. The normal application maximum tick rate and the special task maximum tick rate it is probably worth making this only available as a capability or an rlimit.

Eric

#4 lore raw
Quoted 41 lines · Eric W. Biederman
Quoted 30 lines · george anzinger
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Quoted 7 lines

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

Quoted 9 lines

??? The issue of ticks is separate from the issue of how often timer interrupts fire. Ticks just becomes the maximum resolution you can support/express.

If it makes sense to have two maximum tick resolutions. The normal application maximum tick rate and the special task maximum tick rate it is probably worth making this only available as a capability or an rlimit.

I could support a notion that to use the high-res clock for a timer the user would need a particular capability. After all we do the same for the real time priority.

Does this get us any closer to acceptance in 2.5?

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#5 lore raw
In reply to george anzinger
Quoted 30 lines · george anzinger
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Quoted 7 lines

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

I think what Linus is getting at is: why not make the units of jiffies microseconds and give it larger increments on clock ticks? Now you don't need any special logic to go to better than HZ resolution. Unfortunately, this means identifying all the things that use HZ as a measure of how often we check for rescheduling.

There's also an issue of dynamic range - if we some day soon decide we want internal timestamps with nanosecond resolution (because units of .1us are annoying, not because we'll actually have ns accuracy), then we're seeing timer wraps every couple seconds on 32bit machines and we're pretty much forced to break into seconds and nanoseconds. This is arguably saner than jiffies and subjiffies, but it forces people who are using long timeouts today to use a new interface.

I don't think he can seriously mean cranking HZ up to match whatever timing requirements we might have - that obviously doesn't scale.

Signature · 1 line
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 
#6 lore raw
Quoted 40 lines · Oliver Xymoron
Quoted 30 lines · george anzinger
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Quoted 7 lines

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

Quoted 5 lines

I think what Linus is getting at is: why not make the units of jiffies microseconds and give it larger increments on clock ticks? Now you don't need any special logic to go to better than HZ resolution. Unfortunately, this means identifying all the things that use HZ as a measure of how often we check for rescheduling.

Well then you are still dealing with two measures, the HZ and the tick rate. One might also argue that the subjiffie should be some "normal" thing like nanosecond or micro second. I went round and round with this in the beginning. What it comes down to it the conversion back and forth is much easier and faster (less overhead) when using the natural units of the underlying clock. This way the interrupt code, for example, does not have to even do a conversion.

Quoted 11 lines

There's also an issue of dynamic range - if we some day soon decide we want internal timestamps with nanosecond resolution (because units of .1us are annoying, not because we'll actually have ns accuracy), then we're seeing timer wraps every couple seconds on 32bit machines and we're pretty much forced to break into seconds and nanoseconds. This is arguably saner than jiffies and subjiffies, but it forces people who are using long timeouts today to use a new interface.

I don't think he can seriously mean cranking HZ up to match whatever timing requirements we might have - that obviously doesn't scale.

This is at least the third "take" on what he means, each of which sends me in a very different direction. Sure would like to know what he really means.

I KNOW there is demand for the high-res timers, else I would not have spent the last year + being funded to do it. It also would not be in the OSDL Carrier Grade system if there was no demand.

What I would really like to do is address the real issue.

Quoted 8 lines

--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#7 lore raw
Quoted 41 lines · george anzinger
Quoted 40 lines · Oliver Xymoron
Quoted 37 lines · george anzinger
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

Quoted 8 lines
Quoted 5 lines

I think what Linus is getting at is: why not make the units of jiffies microseconds and give it larger increments on clock ticks? Now you don't need any special logic to go to better than HZ resolution. Unfortunately, this means identifying all the things that use HZ as a measure of how often we check for rescheduling.

Well then you are still dealing with two measures, the HZ and the tick rate.

Yep, and separating the two breaks a few things. Granted.

Quoted 8 lines

One might also argue that the subjiffie
should be some "normal" thing like nanosecond or micro second. I went round and round with this in the beginning. What it comes down to it the conversion back and forth is much easier and faster (less overhead) when using the natural units of the underlying clock. This way the interrupt code, for example, does not have to even do a conversion.

Then the argument becomes move jiffies to the most convenient unit that encompasses what you want to do with subjiffies. Microseconds was just an example. Most code doesn't really care when ticks happen, except to the extent that they currently trigger timers, so jiffies=tick HZ stops being a meaningful measure once timers are untied from ticks, see?

Quoted 6 lines
Quoted 2 lines

I don't think he can seriously mean cranking HZ up to match whatever timing requirements we might have - that obviously doesn't scale.

This is at least the third "take" on what he means, each of which sends me in a very different direction. Sure would like to know what he really means.

Perhaps if you pose it as a multiple-choice question? I suppose he's almost sure to answer with "none of the above".

Signature · 1 line
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 
#8 lore raw
Quoted 63 lines · Oliver Xymoron
Quoted 41 lines · george anzinger
Quoted 40 lines · Oliver Xymoron
Quoted 37 lines · george anzinger
Quoted 12 lines · Linus Torvalds
Quoted 4 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Well, the notion is to provide timers that have resolution down into the micro seconds. Since this take a bit more overhead, we just set up an interrupt on an as needed basis. This is why we define both a high res and a low res clock. Timers on the low res clock will always use the 1/HZ tick to drive them and thus do not introduce any additional overhead. If this is all that is needed the configure option can be left off and only these timers will be available.

On the other hand, if a user requires better resolution, s/he just turns on the high-res option and incures the overhead only when it is used and then only at timer expire time. Note that the only way to access a high-res timer is via the POSIX clocks and timers API. They are not available to select or any other system call.

Making ticks shorter causes extra overhead ALL the time, even when it is not needed. Higher resolution is not free in any case, but it is much closer to free with this patch than by increasing HZ (which, of course, can still be done). Overhead wise and resolution wise, for timers, we would be better off with a 1/HZ tick and the "on demand" high-res interrupts this patch introduces.

Quoted 8 lines
Quoted 5 lines

I think what Linus is getting at is: why not make the units of jiffies microseconds and give it larger increments on clock ticks? Now you don't need any special logic to go to better than HZ resolution. Unfortunately, this means identifying all the things that use HZ as a measure of how often we check for rescheduling.

Well then you are still dealing with two measures, the HZ and the tick rate.

Yep, and separating the two breaks a few things. Granted.

Quoted 8 lines

One might also argue that the subjiffie
should be some "normal" thing like nanosecond or micro second. I went round and round with this in the beginning. What it comes down to it the conversion back and forth is much easier and faster (less overhead) when using the natural units of the underlying clock. This way the interrupt code, for example, does not have to even do a conversion.

Quoted 6 lines

Then the argument becomes move jiffies to the most convenient unit that encompasses what you want to do with subjiffies. Microseconds was just an example. Most code doesn't really care when ticks happen, except to the extent that they currently trigger timers, so jiffies=tick HZ stops being a meaningful measure once timers are untied from ticks, see?

Hm? Not really sure what this leads to. Right now the timers are organized by "tick". I think this is VERY useful. It makes the timer insert VERY fast and the tick processing equally fast. A regular "tick" also makes the accounting overhead flat WRT load, also a GOOD thing.

One thought I had was to separate out the sub tick events into a different list and come up with a different interrupt source for them. Problem is they MUST stay in sync. This is most easily done when they are in the same list.

What you haven't touched on, is the separation of the "tick" from the clock or time. The patch implements, a separation here. Time is taken from a reliable source (in this patch either TSC or the ACPI pm timer, but others are possible) and the "tick" is just a reminder to look at the clock and update accordingly. This eliminates the issue of choosing a HZ value that is so many PPM close to real time and the NTP issues that causes, such as the current early expiration of timers. Try this:

time sleep 60

on a 2.5.40 system. It will come back with 59.xxx seconds. Clearly the sleep was for less than 60.

Quoted 18 lines
Quoted 7 lines
Quoted 3 lines

I don't think he can seriously mean cranking HZ up to match whatever timing requirements we might have - that obviously doesn't scale.

This is at least the third "take" on what he means, each of which sends me in a very different direction. Sure would like to know what he really means.

Perhaps if you pose it as a multiple-choice question? I suppose he's almost sure to answer with "none of the above".

--
"Love the dolphins," she advised him. "Write by W.A.S.T.E.."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#9 lore raw
In reply to Linus Torvalds
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Linus

In any kind of virtual environment you would rather prefer a completely tickless system alltogether than increased tick rates. In a S/390 virtual machine, running many hundreds of virtual Linux servers the 100Hz timer pops are already considerably painful, and going to a higher tick rate achieving higher timer resolution is completely prohibitive. Similar is true in many embedded systems related to power consumption of high frequency ticks.

However, George has shown that introducing the notion of a completely tickless system is expensive on Intel overhead wise, thus partial ticks seem to be a possibility addressing the needs for embedded and virtual environments, getting decent timer resolution as needed.

Ingo Adlung

#10 lore raw
Quoted 8 lines · Ingo Adlung
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · george anzinger

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

Quoted 4 lines
Quoted 4 lines

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Not speaking for a major distro, just for me writing HPET (high performance event timer ...) support for x86-64 (and it happens to exist on ia64 as well, and possibly might be in new Intel P4 chipsets, too).

It's a very nice piece of hardware that allows very fine granularity aperiodic interrupts (in each interrupt you set when the next one will happen), without much overhead.

It'd be a shame to just set this timer to 1kHz periodic just use that as a base timer, when you can do much better resolution and latency-wise. HPET has a base clock > 10 MHz.

Quoted 10 lines
Quoted 1 line

Linus

In any kind of virtual environment you would rather prefer a completely tickless system alltogether than increased tick rates. In a S/390 virtual machine, running many hundreds of virtual Linux servers the 100Hz timer pops are already considerably painful, and going to a higher tick rate achieving higher timer resolution is completely prohibitive. Similar is true in many embedded systems related to power consumption of high frequency ticks.

Quoted 4 lines

However, George has shown that introducing the notion of a completely tickless system is expensive on Intel overhead wise, thus partial ticks seem to be a possibility addressing the needs for embedded and virtual environments, getting decent timer resolution as needed.

When HPET becomes a standard (yes, it's a MS requirement for new PCs), it won't be expensive on i386 anymore.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs
#11 lore raw

Hi!

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Quoted 7 lines

Not speaking for a major distro, just for me writing HPET (high performance event timer ...) support for x86-64 (and it happens to exist on ia64 as well, and possibly might be in new Intel P4 chipsets, too).

It's a very nice piece of hardware that allows very fine granularity aperiodic interrupts (in each interrupt you set when the next one will happen), without much overhead.

I believe the problem is like this: assume you have three timers, 10msec polling of mouse, 30msec keyboard autorepeat and 50msec cursor blinking. With current approach, you get

10msec userland runs
<enter kernel>
<process mouse>
<process keyboard>
<process cursor>
<exit kernel>

With hires timers, you get:

3msec userland runs
<enter kernel>
<process mouse>
<exit kernel>
2msec userland runs
<enter kernel>
<process keyboard>
<exit kernel>
...

which is not so efficient. I guess rounding could be implemented to preserve this "do-all-together" ability?
Pavel

Signature · 1 line
When do you have heart between your knees?
#12 lore raw
Quoted 43 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Quoted 7 lines

Not speaking for a major distro, just for me writing HPET (high performance event timer ...) support for x86-64 (and it happens to exist on ia64 as well, and possibly might be in new Intel P4 chipsets, too).

It's a very nice piece of hardware that allows very fine granularity aperiodic interrupts (in each interrupt you set when the next one will happen), without much overhead.

I believe the problem is like this: assume you have three timers, 10msec polling of mouse, 30msec keyboard autorepeat and 50msec cursor blinking. With current approach, you get

10msec userland runs
<enter kernel>
<process mouse>
<process keyboard>
<process cursor>
<exit kernel>

With hires timers, you get:

3msec userland runs
<enter kernel>
<process mouse>
<exit kernel>
2msec userland runs
<enter kernel>
<process keyboard>
<exit kernel>
...

Quoted 2 lines

which is not so efficient. I guess rounding could be implemented to preserve this "do-all-together" ability?

Actually that's exactly why you'd want sub-tick timing. For timers where you don't care too much about the timing ;) you could do the rounding, and for those where you need exact timing (sound, video, ...) you could call a different add_timer() which would disable the coalescing.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs
#13 lore raw
Quoted 45 lines · Vojtech Pavlik
Quoted 43 lines · Pavel Machek

Hi!

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

This patch, in conjunction with the "core" high-res-timers patch implements high resolution timers on the i386 platforms.

I really don't get the notion of partial ticks, and quite frankly, this isn't going into my tree until some major distribution kicks me in the head and explains to me why the hell we have partial ticks instead of just making the ticks shorter.

Quoted 7 lines

Not speaking for a major distro, just for me writing HPET (high performance event timer ...) support for x86-64 (and it happens to exist on ia64 as well, and possibly might be in new Intel P4 chipsets, too).

It's a very nice piece of hardware that allows very fine granularity aperiodic interrupts (in each interrupt you set when the next one will happen), without much overhead.

I believe the problem is like this: assume you have three timers, 10msec polling of mouse, 30msec keyboard autorepeat and 50msec cursor blinking. With current approach, you get

10msec userland runs
<enter kernel>
<process mouse>
<process keyboard>
<process cursor>
<exit kernel>

With hires timers, you get:

3msec userland runs
<enter kernel>
<process mouse>
<exit kernel>
2msec userland runs
<enter kernel>
<process keyboard>
<exit kernel>
...

Quoted 7 lines
Quoted 2 lines

which is not so efficient. I guess rounding could be implemented to preserve this "do-all-together" ability?

Actually that's exactly why you'd want sub-tick timing. For timers where you don't care too much about the timing ;) you could do the rounding, and for those where you need exact timing (sound, video, ...) you could call a different add_timer() which would disable the coalescing.

The way you do this with the POSIX interface is to use the low res CLOCKs. Internally one would just set the sub_jiffie in the struct timer_list to zero (as the initialize code does). This way the timer would always be handled on the tick interrupt and would never cause a "special" sub tick interrupt.

As the patch is currently written, it takes extra effort to force a sub tick event (as it should) so one has to "request" it.

Signature · 5 lines
George Anzinger   [email protected]
High-res-timers: 
http://sourceforge.net/projects/high-res-timers/
Preemption patch:
http://www.kernel.org/pub/linux/kernel/people/rml
#14 lore raw
In reply to Linus Torvalds

On Wed, 9 Oct 2002, Linus Torvalds wrote:

| On Wed, 9 Oct 2002, george anzinger wrote:
| >
| > This patch, in conjunction with the "core" high-res-timers
| > patch implements high resolution timers on the i386
| > platforms.
|
| I really don't get the notion of partial ticks, and quite frankly, this
| isn't going into my tree until some major distribution kicks me in the
| head and explains to me why the hell we have partial ticks instead of just
| making the ticks shorter.
| -

Carrier Grade Linux is not a distro, but we do integrate these patches into the CGL patches and will continue to use it.

Please consider adding it to 2.5.

Thanks,

Signature · 1 line
~Randy
#15 lore raw
Quoted 4 lines · Randy.Dunlap

Carrier Grade Linux is not a distro, but we do integrate these patches into the CGL patches and will continue to use it.

Please consider adding it to 2.5.

Indeed. Linus, please consider merging at least George's latest patch set which provides just the new system calls to support POSIX clocks and timers. There is no dependence on the high-resolution bits, so at least Linux can provide the missing POSIX.4 system calls.

George can then provide the high resolution code separately which can be debated and optionally merged.

Robert Love

#16 lore raw
In reply to Randy.Dunlap
Quoted 11 lines · Randy.Dunlap

On Wed, 9 Oct 2002, Linus Torvalds wrote:

| On Wed, 9 Oct 2002, george anzinger wrote:
| > This patch, in conjunction with the "core" high-res-timers
| > patch implements high resolution timers on the i386
| > platforms.
|
| I really don't get the notion of partial ticks, and quite frankly, this
| isn't going into my tree until some major distribution kicks me in the
| head and explains to me why the hell we have partial ticks instead of
| just making the ticks shorter.
| -

because just making ticks shorter/more frequent just increases timer overhead all the time whether you are actually doing anything requiring it or not. this is a big waste of cpu cycles.

using the partial tick method put forward by george, you only pay the price for higher resolution timers WHEN YOU WANT TO.

most things that want say 1usec precision dont want to do something EVERY us, just something every now and then with 1us precision. things like programs that want to block for a 350 usec. but waiting 10 or even 1 msec would be too long.

the timer overhead using fixed interval timers (as you suggest) to support that occaisional 350 usec block would eat too much cpu to be practical.

increasing timer frequency penalizes ALL users/processes with increased timer overhead all the time for the benefit of the small number of tasks that need better resolution. the sub-jiffie/partial tick model only pays that price when there is an actual timed event that needs to occur at that higher resolution and the rest of the time the timer overhead remains as it is today (which to my mind is 10 times what it needs to be, but that is an argument for another day)

embedded systems in particular need higher resolution and these types of systems are precisely the systems that can't afford to multiply their timer overhead by a factor of 10 or more (as increasing HZ to 1000 does).