Skip to contentSkip to conversation

statistics infrastructure - exploitation prerequisite

RFC PATCH In review Martin Peschke 7 participants 10 messages May 16, 2006 – May 17, 2006

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

RFC PATCH 7/8 statistics infrastructure - exploitation prerequisite

need sched_clock for latency statistics

---

 alpha/kernel/time.c            |    1 +
 arm/kernel/time.c              |    1 +
 arm/mach-omap1/time.c          |    1 +
 arm/mach-realview/core.c       |    1 +
 arm/mach-sa1100/generic.c      |    1 +
 arm/mach-versatile/core.c      |    1 +
 arm/plat-omap/timer32k.c       |    1 +
 arm26/kernel/time.c            |    1 +
 cris/kernel/time.c             |    1 +
 frv/kernel/time.c              |    1 +
 h8300/kernel/time.c            |    3 ++-
 i386/kernel/timers/timer_tsc.c |    1 +
 m32r/kernel/time.c             |    1 +
 m68k/kernel/time.c             |    2 +-
 m68knommu/kernel/time.c        |    4 +++-
 mips/kernel/time.c             |    1 +
 parisc/kernel/time.c           |    1 +
 powerpc/kernel/time.c          |    1 +
 ppc/kernel/time.c              |    1 +
 s390/kernel/time.c             |    1 +
 sh/kernel/time.c               |    1 +
 sh64/kernel/time.c             |    2 +-
 sparc/kernel/time.c            |    1 +
 sparc64/kernel/time.c          |    1 +
 um/kernel/time_kern.c          |    1 +
 v850/kernel/time.c             |    1 +
 x86_64/kernel/time.c           |    1 +
 xtensa/kernel/time.c           |    1 +
 28 files changed, 31 insertions(+), 4 deletions(-)
arch/alpha/kernel/time.c +1 -0
diff -Nurp a/arch/alpha/kernel/time.c b/arch/alpha/kernel/time.c
@@ -101,6 +101,7 @@ unsigned long long sched_clock(void)
 {
         return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 
 /*
arch/arm/kernel/time.c +1 -0
diff -Nurp a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
@@ -84,6 +84,7 @@ unsigned long long __attribute__((weak))
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static unsigned long next_rtc_update;
 
arch/arm/mach-omap1/time.c +1 -0
diff -Nurp a/arch/arm/mach-omap1/time.c b/arch/arm/mach-omap1/time.c
@@ -220,6 +220,7 @@ unsigned long long sched_clock(void)
 
 	return cycles_2_ns(ticks64);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /*
  * ---------------------------------------------------------------------------
arch/arm/mach-realview/core.c +1 -0
diff -Nurp a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
@@ -62,6 +62,7 @@ unsigned long long sched_clock(void)
 
 	return v;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 
 #define REALVIEW_FLASHCTRL    (__io_address(REALVIEW_SYS_BASE) + 

REALVIEW_SYS_FLASH_OFFSET)

arch/arm/mach-sa1100/generic.c +1 -0
diff -Nurp a/arch/arm/mach-sa1100/generic.c b/arch/arm/mach-sa1100/generic.c
@@ -131,6 +131,7 @@ unsigned long long sched_clock(void)
 
 	return v;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /*
  * Default power-off for SA1100
arch/arm/mach-versatile/core.c +1 -0
diff -Nurp a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
@@ -239,6 +239,7 @@ unsigned long long sched_clock(void)
 
 	return v;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 
 #define VERSATILE_FLASHCTRL    (__io_address(VERSATILE_SYS_BASE) + 

VERSATILE_SYS_FLASH_OFFSET)

arch/arm/plat-omap/timer32k.c +1 -0
diff -Nurp a/arch/arm/plat-omap/timer32k.c b/arch/arm/plat-omap/timer32k.c
@@ -188,6 +188,7 @@ unsigned long long sched_clock(void)
 {
 	return omap_32k_ticks_to_nsecs(omap_32k_sync_timer_read());
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /*
  * Timer interrupt for 32KHz timer. When dynamic tick is enabled, this
arch/arm26/kernel/time.c +1 -0
diff -Nurp a/arch/arm26/kernel/time.c b/arch/arm26/kernel/time.c
@@ -99,6 +99,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static unsigned long next_rtc_update;
 
arch/cris/kernel/time.c +1 -0
diff -Nurp a/arch/cris/kernel/time.c b/arch/cris/kernel/time.c
@@ -231,6 +231,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static int
 __init init_udelay(void)
arch/frv/kernel/time.c +1 -0
diff -Nurp a/arch/frv/kernel/time.c b/arch/frv/kernel/time.c
@@ -230,3 +230,4 @@ unsigned long long sched_clock(void)
 {
 	return jiffies_64 * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
arch/h8300/kernel/time.c +2 -1
diff -Nurp a/arch/h8300/kernel/time.c b/arch/h8300/kernel/time.c
@@ -123,5 +123,6 @@ EXPORT_SYMBOL(do_settimeofday);
 unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
-
 }
+
+EXPORT_SYMBOL_GPL(sched_clock);
arch/i386/kernel/timers/timer_tsc.c +1 -0
diff -Nurp a/arch/i386/kernel/timers/timer_tsc.c b/arch/i386/kernel/timers/timer_tsc.c
@@ -167,6 +167,7 @@ unsigned long long sched_clock(void)
 	/* return the value in ns */
 	return cycles_2_ns(this_offset);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static void delay_tsc(unsigned long loops)
 {
arch/m32r/kernel/time.c +1 -0
diff -Nurp a/arch/m32r/kernel/time.c b/arch/m32r/kernel/time.c
@@ -304,3 +304,4 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
arch/m68k/kernel/time.c +1 -1
diff -Nurp a/arch/m68k/kernel/time.c b/arch/m68k/kernel/time.c
@@ -177,4 +177,4 @@ unsigned long long sched_clock(void)
 {
        return (unsigned long long)jiffies*(1000000000/HZ);
 }
-
+EXPORT_SYMBOL_GPL(sched_clock);
arch/m68knommu/kernel/time.c +3 -1
diff -Nurp a/arch/m68knommu/kernel/time.c b/arch/m68knommu/kernel/time.c
@@ -180,6 +180,8 @@ int do_settimeofday(struct timespec *tv)
 	return 0;
 }
 
+EXPORT_SYMBOL(do_settimeofday);
+
 /*
  * Scheduler clock - returns current time in nanosec units.
  */
@@ -188,4 +190,4 @@ unsigned long long sched_clock(void)
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
 
-EXPORT_SYMBOL(do_settimeofday);
+EXPORT_SYMBOL_GPL(sched_clock);
arch/mips/kernel/time.c +1 -0
diff -Nurp a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c
@@ -778,3 +778,4 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies*(1000000000/HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
arch/parisc/kernel/time.c +1 -0
diff -Nurp a/arch/parisc/kernel/time.c b/arch/parisc/kernel/time.c
@@ -211,6 +211,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 
 void __init time_init(void)
arch/powerpc/kernel/time.c +1 -0
diff -Nurp a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
@@ -781,6 +781,7 @@ unsigned long long sched_clock(void)
 		return get_rtc();
 	return mulhdu(get_tb(), tb_to_ns_scale) << tb_to_ns_shift;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 int do_settimeofday(struct timespec *tv)
 {
arch/ppc/kernel/time.c +1 -0
diff -Nurp a/arch/ppc/kernel/time.c b/arch/ppc/kernel/time.c
@@ -445,3 +445,4 @@ unsigned long long sched_clock(void)
 	}
 	return tb;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
arch/s390/kernel/time.c +1 -0
diff -Nurp a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
@@ -63,6 +63,7 @@ unsigned long long sched_clock(void)
 {
 	return ((get_clock() - jiffies_timer_cc) * 125) >> 9;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /*
  * Monotonic_clock - returns # of nanoseconds passed since time_init()
arch/sh/kernel/time.c +1 -0
diff -Nurp a/arch/sh/kernel/time.c b/arch/sh/kernel/time.c
@@ -44,6 +44,7 @@ unsigned long long __attribute__ ((weak)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 void do_gettimeofday(struct timeval *tv)
 {
arch/sh64/kernel/time.c +1 -1
diff -Nurp a/arch/sh64/kernel/time.c b/arch/sh64/kernel/time.c
@@ -598,4 +598,4 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
-
+EXPORT_SYMBOL_GPL(sched_clock);
arch/sparc/kernel/time.c +1 -0
diff -Nurp a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c
@@ -466,6 +466,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /* Ok, my cute asm atomicity trick doesn't work anymore.
  * There are just too many variables that need to be protected
arch/sparc64/kernel/time.c +1 -0
diff -Nurp a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
@@ -1135,6 +1135,7 @@ unsigned long long sched_clock(void)
 	return (ticks * timer_ticks_per_nsec_quotient)
 		>> SPARC64_NSEC_PER_CYC_SHIFT;
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static int set_rtc_mmss(unsigned long nowtime)
 {
arch/um/kernel/time_kern.c +1 -0
diff -Nurp a/arch/um/kernel/time_kern.c b/arch/um/kernel/time_kern.c
@@ -34,6 +34,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies_64 * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /* Changed at early boot */
 int timer_irq_inited = 0;
arch/v850/kernel/time.c +1 -0
diff -Nurp a/arch/v850/kernel/time.c b/arch/v850/kernel/time.c
@@ -35,6 +35,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 /*
  * timer_interrupt() needs to keep up the real-time clock,
arch/x86_64/kernel/time.c +1 -0
diff -Nurp a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
@@ -501,6 +501,7 @@ unsigned long long sched_clock(void)
 	rdtscll(a);
 	return cycles_2_ns(a);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static unsigned long get_cmos_time(void)
 {
arch/xtensa/kernel/time.c +1 -0
diff -Nurp a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
@@ -49,6 +49,7 @@ unsigned long long sched_clock(void)
 {
 	return (unsigned long long)jiffies * (1000000000 / HZ);
 }
+EXPORT_SYMBOL_GPL(sched_clock);
 
 static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 static struct irqaction timer_irqaction = {
#1 lore raw
Quoted 2 lines · Martin Peschke

need sched_clock for latency statistics

sched_clock() probably isn't suitable for this application. It's a scheduler thing and has a number of accuracy problems.

But I thought we discussed this last time around? Maybe not.

Maybe you've considered sched_clock()'s drawbacks and you've decided they're all acceptable. If so, the changelog should have described the reasoning.

But even if so, sched_clock() isn't something we want to be exporting to modules.

#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 1 line · Martin Peschke

need sched_clock for latency statistics

sched_clock() probably isn't suitable for this application. It's a scheduler thing and has a number of accuracy problems.

But I thought we discussed this last time around? Maybe not.

I have been too obsessed with the other issues to remember.

Quoted 2 lines

Maybe you've considered sched_clock()'s drawbacks and you've decided they're all acceptable.

Admittedly, I didn't, but merely believed the comment above the function.

http://marc.theaimsgroup.com/?l=linux-kernel&m=114657675408686&w=2
sheds some light.

I would be happy to exploit an API that may result from that discussion. I would plead for exporting such an API to modules. I don't see how to implement statistics for latencies, otherwise.

Any other hints on how to replace my sched_clock() calls are welcome. (I want to measure elapsed times in units that are understandable to users without hardware manuals and calculator, such as milliseconds.)

Martin

#3 lore raw

Am Wednesday 17 May 2006 00:36 schrieb Martin Peschke:

Quoted 3 lines

Any other hints on how to replace my sched_clock() calls are welcome. (I want to measure elapsed times in units that are understandable to users without hardware manuals and calculator, such as milliseconds.)

There are a number of APIs that allow you to get the time:

- do_gettimeofday
potentially slow, reliable TOD clock, microsecond resolution
- ktime_get_ts
monotonic clock, nanosecond resolution
- getnstimeofday
reliable, nanosecond TOD clock
- xtime
jiffie accurate TOD clock, with fast reads
- xtime + wall_to_monotonic
jiffie accurate monotonic clock, almost as fast
- get_cycles
highest supported resolution and accuracy, highly HW-specific behaviour, may overflow.

	Arnd <><
#8 lore raw
In reply to Martin Peschke
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Martin" == Martin Peschke <[email protected]> writes:

Martin> I would be happy to exploit an API that may result from that Martin> discussion. I would plead for exporting such an API to Martin> modules. I don't see how to implement statistics for Martin> latencies, otherwise.

Martin> Any other hints on how to replace my sched_clock() calls are Martin> welcome. (I want to measure elapsed times in units that are Martin> understandable to users without hardware manuals and Martin> calculator, such as milliseconds.)

You may wish to look at the microstate accounting patches at
http://www.gelato.unsw.edu.au/cgi-bin/viewcvs.cgi/cvs/kernel/microstate/
I made the clock source configurable.

It's acually rather difficult to find a reliable cross-platform monotonic clock with good resolution. And different statistics may want different clocks; for my purposes a cycle counter is best (because I'm running on a machine that varies the clock speed for power management reasons), other people may want nanoseconds.

Signature · 2 lines
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia
#4 lore raw
In reply to Arnd Bergmann

Anrd> Am Wednesday 17 May 2006 00:36 schrieb Martin Peschke:

Quoted 3 lines

Any other hints on how to replace my sched_clock() calls are welcome. (I want to measure elapsed times in units that are understandable to users without hardware manuals and calculator, such as milliseconds.)

Anrd> There are a number of APIs that allow you to get the time:

Anrd> - do_gettimeofday
Anrd> potentially slow, reliable TOD clock, microsecond resolution

Slow, not necessarily safe to call in IRQ context.

Anrd> - ktime_get_ts
Anrd> monotonic clock, nanosecond resolution

Actual resolution varies by platform, it may be as low as jiffy.

Anrd> - getnstimeofday
Anrd> reliable, nanosecond TOD clock

(which is only currently implemented with ns resolution on IA64 and Sparc64, AFAIK)

Anrd> - xtime
Anrd> jiffie accurate TOD clock, with fast reads

Too coarse a resolution.

Anrd> - get_cycles
Anrd> highest supported resolution and accuracy, highly
Anrd> HW-specific behaviour, may overflow.

Not very usable on SMP if you want to measure across migration; may be variable rate.

Signature · 2 lines
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia
#5 lore raw
Quoted 5 lines

Anrd> - do_gettimeofday
Anrd> potentially slow, reliable TOD clock, microsecond resolution

Slow, not necessarily safe to call in IRQ context.

It's only slow if the platform can't do better. On good hardware it is fast. And yes it is safe to call in IRQ context. Networking does that all the time.

If the hardware doesn't have a good working timer for gettimeofday then everything else will be also slow.

-Andi

#6 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Andi" == Andi Kleen <[email protected]> writes:

Anrd> - do_gettimeofday potentially slow, reliable TOD clock, Anrd> microsecond resolution

Quoted 1 line
Quoted 1 line

Slow, not necessarily safe to call in IRQ context.

Andi> It's only slow if the platform can't do better. On good hardware Andi> it is fast. And yes it is safe to call in IRQ
Andi> context. Networking does that all the time.

Thanks for the clarification.

I measured do_gettimeofday on IA64 at around 120 cycles (mind you that was some time ago now, before the last lot of time function revisions in the kernel). Whether that's slow or not depends on your application.

Signature · 2 lines
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia
#7 lore raw
Quoted 3 lines · Peter Chubb

I measured do_gettimeofday on IA64 at around 120 cycles (mind you that was some time ago now, before the last lot of time function revisions in the kernel). Whether that's slow or not depends on your application.

What I did for time critical statistics in core vm paths is to use get_cycles() but associate each cycle value with a processor id when the measurements starts. If the processor id has changed when we end the measurement then discard the measurement and just note that we missed one.

Here is a piece of a description for a patch that I have used in the past for these statistics:

----

The patch puts three performance counters into critical kernel paths to show how its done.

The measurements will show up in /proc/perf/all. Processor specific statistics may be obtained via /proc/perf/<nr-of-processor>. Writing to /proc/perf/reset
will reset all counters. F.e.

echo >/proc/perf/reset

Sample output:

AllocPages               786882 (+  0) 9.9s(223ns/12.6us/48.6us) 12.9gb(16.4kb/16.4kb/32.8kb)
FaultTime                786855 (+192) 10.4s(198ns/13.2us/323.6us)
PrepZeroPage             786765 (+  0) 9.2s(549ns/11.7us/48.1us) 12.9gb(16.4kb/16.4kb/16.4kb)

The first countr is the number of times that the time measurement was performed.(+ xx) is the number of samples that were thrown away since the processor on which the process is running changed. Cycle counters are not consistent across different processors.

Then follows the sum of the time spend in the code segment followed in parenthesesby the minimum / average / maximum time spent there. The second block are the sizes of data processed. In this sample 12.9 GB was allocated via AllocPages. Most allocations were 16k = 1 page although there were also 32K (2 page) allocations.

#9 lore raw
In reply to Andrew Morton
Quoted 5 lines · Andrew Morton
Quoted 2 lines · Martin Peschke

need sched_clock for latency statistics

Quoted 9 lines

sched_clock() probably isn't suitable for this application. It's a scheduler thing and has a number of accuracy problems.

But I thought we discussed this last time around? Maybe not.

Maybe you've considered sched_clock()'s drawbacks and you've decided they're all acceptable. If so, the changelog should have described the reasoning.

Yeah; please, no more users of sched_clock(). Definitely don't export.

Even if it is what you want today (which it probably isn't), the scheduler might want the ability to change it at short notice, depending on new algorithms / new hardware etc. in future.

Make a new function if none of the suggested alternatives work.

--

Send instant messages to your online friends http://au.messenger.yahoo.com