From patchwork Sun Sep 10 09:24:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13378504 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E027EC8748 for ; Sun, 10 Sep 2023 09:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=HhzIFOvAr7SbunxTozRgc90kGTtGp9hhnUHueHjVMow=; b=veAAMFlb2iNJem qpbOr4ldyJrtYbiXNCkLztAFgKVUfx57rGRkIIL+4lLZjoBFRzIQrpYD1KWkb/CnK0J+tRL2Ha9EW vft1OGFjY5PjqH1X0SHkaI/E2kIHN+EVEjMCaaAiRJVaxV2uDsQ6MT6hy5KBVBG0JCLKVsMcfxb5W ieavnLliIeTspH2pdWmjNZ4ZixC/ku5FZKKtKhSIlJIF68sncbqVXUE+B0HDdyn7WHhFrxdEj8w0P Iw/QOdqqY3T9gbRmGdNz+wrzibWSfFQSDQ1+AZjdLFK5TxmNBrZQgxB9n3CA+CR2Z55d0nvmRCTTZ WJZwoXys7bgXUiKehXig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qfGg8-00GLHq-0M; Sun, 10 Sep 2023 09:24:28 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qfGg5-00GLGd-2K for linux-arm-kernel@lists.infradead.org; Sun, 10 Sep 2023 09:24:27 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c39f2b4f5aso1868015ad.0 for ; Sun, 10 Sep 2023 02:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694337864; x=1694942664; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NLQPk6FltGaHVPo2bO4DwKNnQF8PfaGK7XRuh8Wc2/U=; b=zJHzacAGVQI4cLWSEn64t67DYM8ssH2O0nkxayiy/qxSbY3EetrDUcVRF97Xs7offy QQWx8pk/pv9tXslf3I8Zpsm/3EKhqWhUcpqd4xMux2gPHhWw5xsTQTaU9nrZ7eF5aujz B6qDxYy1cCdZxDpXFiK3SWHmIs//Y+sppHqMT94Kl/kizEMchnA3v6CdTWyZrzGdMzqn SaXvWMBW+SLpPQR5BLT1/C0zs6vPtzeb4rAXHNonamjuYdyr2QeqBOt8npWqM+xJa9Nr hSEXFU6vKEUirx3ayLfsLK1gMA3jIbh6XJ4dOF/4rLRBdhc71ONMpQem3jlm1us7dnTO iMow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694337864; x=1694942664; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NLQPk6FltGaHVPo2bO4DwKNnQF8PfaGK7XRuh8Wc2/U=; b=p99CiurvjGF0McXBq079YpZRB10HH/HCcc88GSieZ37mu9Sef5UaJG9F2eLdCreoum /VpdUqWCdClDsX1O3U2cbl6Qaiwr2Nkn+SLfzMSQM4KhU7eTmYMF110TuHYAOlh9qfPk oTWsYIFd1mJZ2dGUlMJ4uMtJAbQCAD6Z9MHOJj8t1hKTg+EITS21wBLU65tPfcDVk5pt 7GlWhhJKf6OC7yHw2cBkKj1v8GCllvHwDyhYgD1BUiyBPpTXv79jDaMerjELEXb5pilU 5xTZcZvOhTDGdlnwrPJGV2+er0WuJEYb2nEQA5Lcrkw75iUNo4OjgbJ6TA11DH4QpkH1 k2wQ== X-Gm-Message-State: AOJu0YxaiGo2xKrQxB+CT5NHmOHsppYFaFyvUl/2cga8wGVtszf3h7Q5 /P4V/bIcvAKCSupTX+RqrgqNAA== X-Google-Smtp-Source: AGHT+IGCCcoeUP2HGmYk3TwhuPFHuXcfUcwQPz61CbwiEjsQdsu/MqgjxzdXJsJiDQakWbIukYhqig== X-Received: by 2002:a17:903:1208:b0:1c1:f27e:a55a with SMTP id l8-20020a170903120800b001c1f27ea55amr6642658plh.46.1694337864333; Sun, 10 Sep 2023 02:24:24 -0700 (PDT) Received: from leoy-huanghe.lan ([98.98.49.29]) by smtp.gmail.com with ESMTPSA id e4-20020a170902d38400b001b05e96d859sm4350982pld.135.2023.09.10.02.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Sep 2023 02:24:23 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH] perf cs-etm: Fix kernel timestamp handling Date: Sun, 10 Sep 2023 17:24:13 +0800 Message-Id: <20230910092413.53538-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230910_022425_768379_2FC82FE5 X-CRM114-Status: GOOD ( 19.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The timestamp can originate from two sources: the kernel timestamp, which is recorded in the event PERF_RECORD_AUX, and the Arm CoreSight hardware trace data. On some Arm platforms, CoreSight trace data fails to support timestamp tracing. This can be due to either a missed connection between the timer counter and Arm CoreSight or the absence of support for the virtual timestamp. If Arm CoreSight fails to support hardware timestamp tracing, we need to fall back on using the kernel timestamp. The current code can support both timestamp sources when synthesizing samples. However, the decoding flow only relies on the hardware timestamp. If the hardware timestamp is zero, it becomes impossible to decode the trace data. Consequently, in this case, the commands below won't output any samples: perf record -e cs_etm// --per-thread --timestamp -- ls perf script To fix this issue, this patch unifies the method of resolving time: 1) It renames cs_etm__resolve_sample_time() to the more general name cs_etm__resolve_time(); 2) It changes the function argument type from 'cs_etm_traceid_queue' to 'cs_etm_packet_queue'; 3) In the end, both the decoding flow and the assignment of timestamps to samples call cs_etm__resolve_time() to obtain timestamp. Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 9729d006550d..fa88e731933d 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -400,6 +400,17 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, etmq->pending_timestamp_chan_id = trace_chan_id; } +static u64 cs_etm__resolve_time(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *packet_queue) +{ + struct cs_etm_auxtrace *etm = etmq->etm; + + if (!etm->timeless_decoding && etm->has_virtual_ts) + return packet_queue->cs_timestamp; + else + return etm->latest_kernel_timestamp; +} + static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq, u8 *trace_chan_id) { @@ -419,8 +430,7 @@ static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq, /* Acknowledge pending status */ etmq->pending_timestamp_chan_id = 0; - /* See function cs_etm_decoder__do_{hard|soft}_timestamp() */ - return packet_queue->cs_timestamp; + return cs_etm__resolve_time(etmq, packet_queue); } static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) @@ -1434,18 +1444,6 @@ u64 cs_etm__convert_sample_time(struct cs_etm_queue *etmq, u64 cs_timestamp) return cs_timestamp; } -static inline u64 cs_etm__resolve_sample_time(struct cs_etm_queue *etmq, - struct cs_etm_traceid_queue *tidq) -{ - 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; - else - return etm->latest_kernel_timestamp; -} - static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 addr, u64 period) @@ -1454,13 +1452,14 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, struct cs_etm_auxtrace *etm = etmq->etm; union perf_event *event = tidq->event_buf; struct perf_sample sample = {.ip = 0,}; + struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue; event->sample.header.type = PERF_RECORD_SAMPLE; event->sample.header.misc = cs_etm__cpu_mode(etmq, addr, tidq->el); 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_time(etmq, packet_queue); sample.ip = addr; sample.pid = thread__pid(tidq->thread); @@ -1505,6 +1504,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, struct cs_etm_auxtrace *etm = etmq->etm; struct perf_sample sample = {.ip = 0,}; union perf_event *event = tidq->event_buf; + struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue; struct dummy_branch_stack { u64 nr; u64 hw_idx; @@ -1520,7 +1520,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_time(etmq, packet_queue); sample.ip = ip; sample.pid = thread__pid(tidq->prev_packet_thread);