[PATCH v2 09/10] ARM: kprobes: Add some benchmarking to test module

Nicolas Pitre nico at fluxnic.net
Sun Sep 11 22:58:03 EDT 2011


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.


Nicolas



More information about the linux-arm-kernel mailing list