Re: III.1 - Sampling period randomization

From: Ingo Molnar
Date: Mon Jun 22 2009 - 07:59:06 EST


> III/ Requests
>
> 1/ Sampling period randomization
>
> It is our experience (on Itanium, for instance), that for certain
> sampling measurements, it is beneficial to randomize the sampling
> period a bit. This is in particular the case when sampling on an
> event that happens very frequently and which is not related to
> timing, e.g., branch_instructions_retired. Randomization helps
> mitigate the bias. You do not need something sophisticated. But
> when you are using a kernel-level sampling buffer, you need to
> have the kernel randomize. Randomization needs to be supported per
> event.

This is on the todo list, it should be pretty straight forward to
implement. Basically add a u64 randomize:1 flag and a u64 rand_size,
and add some noise to hwc->sample_period in perf_counter_overflow(),
just like the .freq path does.

In fact the auto-freq sampling counters effectively randomize
already, as the path of stabilization/convergence is never exactly
the same. We could add a little bit of constant noise to the freq
counter and it would auto-correct automatically.

Since you seem to care abut this sub-feature, would you be
interested in sending a patch for that? The essential steps are:

- Take a new bit off perf_counter_attr::__reserved_1 and name
it attr.randomize.

- Inject a few bits of trivial noise into the period calculated
in kernel/perf_counter.c:perf_adjust_period(). The best place
would be to add it right before this line:

hwc->sample_period = sample_period;

If you add a small relative fuzz of below 1% to sample_period
then the code will auto-correct.

- All the tools deal just fine with variable periods already, so
there's no tooling updates needed, beyond adding a --randomize
flag to tools/perf/builtin-record.c.

Let us know if you need any help with any of this!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/