[PATCH v2 09/10] ARM: kprobes: Add some benchmarking to test module
Tixy
tixy at yxit.co.uk
Mon Sep 12 03:09:13 EDT 2011
On Sun, 2011-09-11 at 22:58 -0400, Nicolas Pitre wrote:
> On Sat, 10 Sep 2011, Tixy wrote:
>
> > From: Jon Medhurst <tixy at yxit.co.uk>
> >
> > These benchmarks show the basic speed of kprobes and verify the success
> > of optimisations done to the emulation of typical function entry
> > instructions (i.e. push/stmdb).
> >
> > Signed-off-by: Jon Medhurst <tixy at yxit.co.uk>
> > ---
>
> [...]
>
> > +#ifdef CONFIG_THUMB2_KERNEL
> > +#define wide ".w"
> > +#else
> > +#define wide
> > +#endif
>
> I suppose you can't reuse the W() macro from arch/arm/include/asm/unified.h
> here...
>
> > +static int benchmark(void(*fn)(void))
> > +{
> > + int t, n;
> > + for (n = 1000; ; n *= 2) {
> > + struct timeval before;
> > + struct timeval after;
> > + int i;
> > +
> > + do_gettimeofday(&before);
> > +
> > + for (i = n; i > 0; --i)
> > + fn();
> > +
> > + do_gettimeofday(&after);
> > + t = after.tv_usec - before.tv_usec;
> > + if (t < 0)
> > + t += 1000000; /* Adjust time if it wrapped */
> > + if (t >= 250000)
> > + break; /* Stop once we took more than 0.25 seconds */
> > + }
> > + return t / (n / 1000); /* Return time in nano-seconds */
> > +};
>
> I think that using sched_clock() here might be a better choice than
> do_gettimeofday(). It is certainly much lower overhead and easier to
> use.
When googling for sched_clock I came across a five year old posting [1]
by Russell saying that uses of sched_clock() for timing intervals is
broken because the range of values it gives doesn't fill all the bits in
the returned integer, leading to a discontinuity when the value wraps.
However, looking at the current implementations of sched_clock() they
seems to have full 64-bit range, and git history shows a new common
infrastructure for sched_clock being added at the end of last year. So
is the full 64-bit range now defined for the sched_clock on API on ARM?
--
Tixy
[1] http://lkml.indiana.edu/hypermail/linux/kernel/0605.0/0425.html
More information about the linux-arm-kernel
mailing list