From: Song Liu Date: Mon, 13 Mar 2023 17:16:08 +0000 (-0700) Subject: perf: fix perf_event_context->time X-Git-Tag: v6.1.37~2843 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d496185c25a600f4e6059fea105f5eca2ab79440;p=platform%2Fkernel%2Flinux-starfive.git perf: fix perf_event_context->time [ Upstream commit baf1b12a67f5b24f395baca03e442ce27cab0c18 ] Time readers rely on perf_event_context->[time|timestamp|timeoffset] to get accurate time_enabled and time_running for an event. The difference between ctx->timestamp and ctx->time is the among of time when the context is not enabled. __update_context_time(ctx, false) is used to increase timestamp, but not time. Therefore, it should only be called in ctx_sched_in() when EVENT_TIME was not enabled. Fixes: 09f5e7dc7ad7 ("perf: Fix perf_event_read_local() time") Signed-off-by: Song Liu Signed-off-by: Peter Zijlstra (Intel) Acked-by: Namhyung Kim Link: https://lkml.kernel.org/r/20230313171608.298734-1-song@kernel.org Signed-off-by: Sasha Levin --- diff --git a/kernel/events/core.c b/kernel/events/core.c index 6c4e78cd7a8b..2aa286b4151b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3830,7 +3830,7 @@ ctx_sched_in(struct perf_event_context *ctx, if (likely(!ctx->nr_events)) return; - if (is_active ^ EVENT_TIME) { + if (!(is_active & EVENT_TIME)) { /* start ctx time */ __update_context_time(ctx, false); perf_cgroup_set_timestamp(cpuctx);