From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81B05C76196 for ; Tue, 28 Mar 2023 15:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjC1PLD (ORCPT ); Tue, 28 Mar 2023 11:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbjC1PK4 (ORCPT ); Tue, 28 Mar 2023 11:10:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E59C6E3BE for ; Tue, 28 Mar 2023 08:10:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4FD7CB81D89 for ; Tue, 28 Mar 2023 15:06:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B93CC433D2; Tue, 28 Mar 2023 15:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680016002; bh=uTkH6Wq9aoPkG777WnB+l5KX57dNAwOM//6bcukBN/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xq2iStdEee380VGaNcb1eUeBbXD3VHeEp5BZ580nl91GOCrenBnLbMIN0cVm1HJRr yQzIQG/q3DJElWlqlwf5Ais0ZBY34owX9xtib30aYf4AWv0pv8r5LUcYNMs9RbSgJQ g3sHtfTohUDrHy+cS5xN4ZAYkJPXfYxb4+yY2cuQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Song Liu , "Peter Zijlstra (Intel)" , Namhyung Kim , Sasha Levin Subject: [PATCH 5.15 003/146] perf: fix perf_event_context->time Date: Tue, 28 Mar 2023 16:41:32 +0200 Message-Id: <20230328142602.810101611@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230328142602.660084725@linuxfoundation.org> References: <20230328142602.660084725@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Song Liu [ 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 --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 3a17a68cf41ad..2cdee62c3de73 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3909,7 +3909,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(task, ctx); -- 2.39.2