Re: [PATCH v4.16-rc4 2/2] x86/vdso: on Intel, VDSO should handle CLOCK_MONOTONIC_RAW

From: Peter Zijlstra
Date: Wed Mar 14 2018 - 09:11:32 EST


On Wed, Mar 14, 2018 at 12:55:20PM +0000, Jason Vas Dias wrote:

> > So you can avoid the whole ioctl(ENABLE), ioctl(DISABLE) nonsense and
> > just let them run and do:
> >
> > read(group_fd, &buf_pre, size);
> > /* your code section */
> > read(group_fd, &buf_post, size);
> >
> > /* compute buf_post - buf_pre */
> >
> > Which is only 2 system calls, not 4.
>
> But I can't, really - I am trying to restrict the
> performance counter measurements
> to only a subset of the code, and exclude
> performance measurement result processing -
> so the timeline is like:

> struct timespec t_start, t_end;
> perf_event_open(...);
> thread_main_loop() { ... do {
> t _ clock_gettime(CLOCK_MONOTONIC_RAW, &t_start);
> t+x _ enable_perf ();
> total_work = do_some_work();
> disable_perf ();
> clock_gettime(CLOCK_MONOTONIC_RAW, &t_end);
> t+y_
> read_perf_counters_and_store_results
> ( perf_grp_fd, &results , total_work,
> TS2T( &t_end ) - TS2T( &t_start)
> );
> } while (.... );
> }
>
> Now. here the bandwidth / performance results recorded by
> my 'read_perf_counters_and_store_results' method
> is very sensitive to the measurement of the OUTER
> elapsed time .

I still don't see why you have to do that enable_perf() / disable_perf()
stuff. What goes wrong if you just let them run and do 2
read_perf*() things?