Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp235547lqp; Thu, 4 Apr 2024 11:32:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYNGVqsW74aO0nA+FmvbvK5L8i95H7rCXLtDcJuR+mDcsBO+9+rS8ddmhpv4K5sGvZcBHGGxfhWrP+fzwawAGBlS1qlkwkifdH19HK4A== X-Google-Smtp-Source: AGHT+IEHXwSzRqeoMr6nm1LHBYzU8htuCq+TPL4OO4p8tdjpKgHIvZwDllInEV+tL279En3MRuj3 X-Received: by 2002:a17:90a:6984:b0:2a2:6d9a:7062 with SMTP id s4-20020a17090a698400b002a26d9a7062mr3522548pjj.9.1712255579647; Thu, 04 Apr 2024 11:32:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712255579; cv=pass; d=google.com; s=arc-20160816; b=gJuSVqSDYct5bKErksoEJSgunW/ztdBK1aT5Lf4uz3B4jB+KgtPG+a2M6t7mkLZlyO wO8nu6n0ydk7Hdnq6uSwnQbVXfYeAYOo6sZwGNgGidbHcRUZjjnfa0lVvc86PAUYtD7E od7e2FLBDz0jQC1OAKPkN/b1iRj8vAEmyKWadHuhyJ0rcHH13iHjfOpDPwwCtGBoD63E xZ5PLvLhO6kWLyEiuJttmt6VOhdu5YYQYnP1GIwwo+IRty++62jfa3OCxBUhV5uaNTf4 HdDqnSZXxkdVcqr9nSwg3CCSGmvk0rJ4SgKqSw6pX403+XekuJ/vXrCaJJX5FVweNuv5 4ONQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bs9rzbl/ZJsjnoCm4UWhViM7erxeHXkxZ5PmGyvl0I8=; fh=PqXpWe7EfrLfiIG/5hPM4SSIgpFovi4EiZFCGKPNlaQ=; b=wAUlpSAy8w1HxF2ITaBu+4itx4wj7ApeSSc9abfojlc5ZL+0TayiBaTHAL4mQeYQrj ss4TnJ+QkEAywk4MzWlMRgONm2BML5bEc0KT8zFerMGHlY27QD+wvPLsb2x05OuXuJSy 1DT6pF252yoNwgrZYDDANYkf6et5iPZYKdTDjFkrBL7fJpW6uWTIZ1H47CxiuUtTN1dV llyoUJWQrLgji8RLkgnHQ89HswY7Y1yD10YLc+HbTcxE0t7Ni52VrE1TjNV3aLNANTwg 2l9LbT5rks5HZRArLupc09jVsm8jCMNRwK0wZdMXRKoIvJHuju2OmI61a/z866x1nRMV iFDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=aXjO9lqD; arc=pass (i=1 spf=pass spfdomain=marvell.com dkim=pass dkdomain=marvell.com dmarc=pass fromdomain=marvell.com); spf=pass (google.com: domain of linux-kernel+bounces-131944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id gm22-20020a17090b101600b002a2adb8af86si2134323pjb.86.2024.04.04.11.32.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 11:32:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=aXjO9lqD; arc=pass (i=1 spf=pass spfdomain=marvell.com dkim=pass dkdomain=marvell.com dmarc=pass fromdomain=marvell.com); spf=pass (google.com: domain of linux-kernel+bounces-131944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=marvell.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 25255B2A0BB for ; Thu, 4 Apr 2024 18:10:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E3971311A1; Thu, 4 Apr 2024 18:09:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="aXjO9lqD" Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B7812D770; Thu, 4 Apr 2024 18:09:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.156.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712254167; cv=none; b=V7NCC9WuQhSHgV00Fbu8+jkmwzBlTZURgE1Kyza01mXhDRX2EX9FYSE2yGeYJ0b8KTpPwQ/Gi0Q68KH/9mn8Rd7pJZoTviGp8PEo6fD0J+ZBMgnSbnRGcgcfNbdx9RDF7T7tPJfs9qrjYfR2pzSNCGLeOTxkTQadEw7VN4rSiDw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712254167; c=relaxed/simple; bh=x4eAu7x6Idzvlda3hIQDcIF+4wKEpZYKt9rgpsoqlDo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jGanmn0Oja3tAD4vJdcFY7PEHaLOWMCPEVQXoAbqznOsQG8+OjH0z7wqH/0QMXVuLG/Rx00y9ZuU5MYl04pibwclTO4O3FaFvle4Y+/b8Zs/sBg2+Rod17pP2SWFEHymXrWKdegshTEBd9GUX1zUy6071bsdSGAFDAwfzVWbTOI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com; spf=pass smtp.mailfrom=marvell.com; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b=aXjO9lqD; arc=none smtp.client-ip=67.231.156.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marvell.com Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 434GsQgH030426; Thu, 4 Apr 2024 11:08:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= pfpt0220; bh=bs9rzbl/ZJsjnoCm4UWhViM7erxeHXkxZ5PmGyvl0I8=; b=aXj O9lqDdd0wiA3CPbcfwE1zgxKibz9wZCAF45eIvd6vtwgycbwtv7lyv0QGFfE4DJr vw6m0jYaUkAsg2lrBlnV6ycIPOy+/MeOs6X1R+oTIUBgSn7P0rhDlMsNlod9S3Lb GU1rtGlIZ6RPInEFZV06FZGsyN1kMGQJiomt5g1zll68zJ72lRV2SDHCyrv4o9b9 kHJfrhiIWvvGjtsZ4bArg1J5EFSvit2gZBDosRmXMLDknWv2oq0UCqvRfpQKcJH9 JpHbTbLU/SrQpC252FmyTSnOBjog5E1lUIN4DE6+IyYAdHquRnMlQ8LCBDZj+mw8 sKf3BAOpyK1EO2G153g== Received: from dc6wp-exch02.marvell.com ([4.21.29.225]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3x9em6kka2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Apr 2024 11:08:52 -0700 (PDT) Received: from DC6WP-EXCH02.marvell.com (10.76.176.209) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 4 Apr 2024 11:08:52 -0700 Received: from maili.marvell.com (10.69.176.80) by DC6WP-EXCH02.marvell.com (10.76.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 4 Apr 2024 11:08:51 -0700 Received: from POWEREDGE.marvell.com (POWEREDGE.marvell.com [10.28.8.3]) by maili.marvell.com (Postfix) with ESMTP id 32F4D3F7076; Thu, 4 Apr 2024 11:08:45 -0700 (PDT) From: Tanmay Jagdale To: , , , , , , , , , , , CC: , , , , , , , Tanmay Jagdale Subject: [PATCH V2 2/2] perf: cs-etm: Store previous timestamp in packet queue Date: Thu, 4 Apr 2024 23:37:31 +0530 Message-ID: <20240404180731.7006-3-tanmay@marvell.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240404180731.7006-1-tanmay@marvell.com> References: <20240404180731.7006-1-tanmay@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: nkJzkpKjPUXW5Ol3SCC4ytqvRjEW0W77 X-Proofpoint-GUID: nkJzkpKjPUXW5Ol3SCC4ytqvRjEW0W77 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-04_14,2024-04-04_01,2023-05-22_02 Since logic in cs_etm__sample is changed to synthesizing the previous packet (tidq->prev_packet) instead of current packet (tidq->packet), the first time this function is called, tidq->prev_packet is NULL and we return without processing anything. This is as expected but, in the first call, we would have a valid timestamp (stored in tidq->packet_queue.cs_timestamp) which belongs to tidq->packet. This would be lost due to no processing. Losing this timestamp results in all the synthesized packets being associated with the next timestamp and not their corresponding one. To fix this, introduce a new variable (prev_cs_timestamp) to store the queue's timestamp in cs_etm__sample(). When we start synthesizing the prev_packet, use this cached value instead of the current timestamp (cs_timestamp). Signed-off-by: Tanmay Jagdale --- tools/perf/util/cs-etm.c | 17 +++++++++++++---- tools/perf/util/cs-etm.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 55db1932f785..d5072c16fcd8 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1459,13 +1459,15 @@ u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp) } static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq, - struct cs_etm_traceid_queue *tidq) + struct cs_etm_traceid_queue *tidq, + bool instruction_sample) { struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue; if (!etm->timeless_decoding && etm->has_virtual_ts) - return packet_queue->cs_timestamp; + return instruction_sample ? packet_queue->prev_cs_timestamp : + packet_queue->cs_timestamp; else return etm->latest_kernel_timestamp; } @@ -1484,7 +1486,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, event->sample.header.size = sizeof(struct perf_event_header); /* Set time field based on etm auxtrace config. */ - sample.time = cs_etm__resolve_sample_time(etmq, tidq); + sample.time = cs_etm__resolve_sample_time(etmq, tidq, true); sample.ip = addr; sample.pid = thread__pid(tidq->thread); @@ -1560,7 +1562,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, event->sample.header.size = sizeof(struct perf_event_header); /* Set time field based on etm auxtrace config. */ - sample.time = cs_etm__resolve_sample_time(etmq, tidq); + sample.time = cs_etm__resolve_sample_time(etmq, tidq, false); sample.ip = ip; sample.pid = thread__pid(tidq->prev_packet_thread); @@ -1849,6 +1851,13 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, } } + /* + * Since we synthesize the prev_packet, store the current timestamp + * here in prev_cs_timestamp so that when we *actually* synthesize + * the prev_packet, we use this timestamp and not the future one. + */ + tidq->packet_queue.prev_cs_timestamp = tidq->packet_queue.cs_timestamp; + cs_etm__packet_swap(etm, tidq); return 0; diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 4696267a32f0..333eeb2c06a0 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -205,6 +205,7 @@ struct cs_etm_packet_queue { u32 instr_count; u64 cs_timestamp; /* Timestamp from trace data, converted to ns if possible */ u64 next_cs_timestamp; + u64 prev_cs_timestamp; struct cs_etm_packet packet_buffer[CS_ETM_PACKET_MAX_BUFFER]; }; -- 2.34.1