Re: [PATCH v2 3/3] X86: Add a thread cpu time implementation to vDSO

From: Shaohua Li
Date: Tue Jan 06 2015 - 12:00:22 EST


On Tue, Jan 06, 2015 at 11:18:39AM +0100, Peter Zijlstra wrote:
> On Mon, Jan 05, 2015 at 03:23:38PM -0800, Shaohua Li wrote:
> > Good, it works. But the timestamp (.time_running and friends) only gets
> > updated for real hardware event between context switches. For software
> > event, the timestamp is initialized once, then never updated. If I use
> > it to get time, I actually get CLOCK_MONOTONIC. Hardware events work
> > well here, but depending on hardware event is too tricky, which I'd like
> > to avoid.
>
> Hmm, that's an unfortunate difference in behaviour, does something like
> the below cure that for you?

Yes, I tried similar here, it works perfectly. Is this a bug we will
eventually fix? If yes, we will very happy to use perf for the
clock_gettime things. I had some initial benchmarks which show this
doesn't have noticeable performance issue. I'll do more benchamrks and
report back if there are any issues.

Thanks,
Shaohua

>
> ---
> kernel/events/core.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4c1ee7f2bebc..0feb4e039359 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -5965,11 +5965,13 @@ static void perf_swevent_del(struct perf_event *event, int flags)
> static void perf_swevent_start(struct perf_event *event, int flags)
> {
> event->hw.state = 0;
> + perf_event_update_userpage(event);
> }
>
> static void perf_swevent_stop(struct perf_event *event, int flags)
> {
> event->hw.state = PERF_HES_STOPPED;
> + perf_event_update_userpage(event);
> }
>
> /* Deref the hlist from the update side */
> @@ -6410,12 +6412,14 @@ static void cpu_clock_event_start(struct perf_event *event, int flags)
> {
> local64_set(&event->hw.prev_count, local_clock());
> perf_swevent_start_hrtimer(event);
> + perf_event_update_userpage(event);
> }
>
> static void cpu_clock_event_stop(struct perf_event *event, int flags)
> {
> perf_swevent_cancel_hrtimer(event);
> cpu_clock_event_update(event);
> + perf_event_update_userpage(event);
> }
>
> static int cpu_clock_event_add(struct perf_event *event, int flags)
> @@ -6484,12 +6488,14 @@ static void task_clock_event_start(struct perf_event *event, int flags)
> {
> local64_set(&event->hw.prev_count, event->ctx->time);
> perf_swevent_start_hrtimer(event);
> + perf_event_update_userpage(event);
> }
>
> static void task_clock_event_stop(struct perf_event *event, int flags)
> {
> perf_swevent_cancel_hrtimer(event);
> task_clock_event_update(event, event->ctx->time);
> + perf_event_update_userpage(event);
> }
>
> static int task_clock_event_add(struct perf_event *event, int flags)
--
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/