From patchwork Sat Oct 14 07:41:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13421932 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 366F6CDB465 for ; Sat, 14 Oct 2023 07:42:49 +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:References:In-Reply-To: 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: List-Owner; bh=COzviP/4q3YPwr7aL7kL0cX++KRSfUK9D7qXtCcanO0=; b=ZX5BKwzl8eTHkP WGQzfGpo2b70Zqr3MynAsxzoKEqfCMQh3p/khbcS5sgbyZE/ssakdhlLFBxkq69/uly6dbLUaf6p1 JnOzCfO/n+yn2SBXsWllSV/0NRSs3McypbsizKQ+GdmdEVHqYUuUoQVuYJ7OKT2xaYWavOUxMw7EO gg4wt6btkAhNsYD/lGIUCJrdSyzKKuyA0lcODUUkI0Lel14Ry+I9fMnhqaSRsFvl8s5x/hnxVAZWO QY8sZs2j+ePw0BVj2xhRPladNvHt4i91WtDj3dnXe8AUA0eQReb5fzuNeV/Jo8qox10sg0OaTsKwN o5HDGVzpSkK675UidkeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qrZHz-004vJk-37; Sat, 14 Oct 2023 07:42:23 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qrZHx-004vIj-0E for linux-arm-kernel@lists.infradead.org; Sat, 14 Oct 2023 07:42:22 +0000 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-578b407045bso2135998a12.0 for ; Sat, 14 Oct 2023 00:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697269338; x=1697874138; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iPjwMRuEKu2fsJk8eO76Y756wMaad6TrvFKtRdmyvgc=; b=b3f72Xj2Ahle7H86S2om/Ktrgvkf1J9adidZZ5Hm1v+XXpPQwLUvzPwniNm8x5Uro4 vUUbhZDx7i7B2Be9ac6kugPC9x3bTYoiIZs3yRbz+ow0mQ/2+DIWRbOtjPamkZaBhrFl fezHm4cHplOCdtdHJ5dEj3W2dZvBc0ojaBoTO2EgufsZtF+a2jyBe7/WpfB7XuHlLP+K ZKMP2TvgLuFuavPmsb//WucV21l0b/NzsFTwTTBMJSYr2ID9buJtmFy016S5WDWCfU+Q EY78fkzC24TgLRNyzpkhqgXY8zy7DVBP3RLDhItRjkqMm4GSxHC8J9K0uO4Eb3XhUizJ Fe/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697269338; x=1697874138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iPjwMRuEKu2fsJk8eO76Y756wMaad6TrvFKtRdmyvgc=; b=lQfrZbRhGPKnKWdh/CVdLyE42kgto22XCn1cq8zTJDuCsQ2E7YrRdFTP6XpKqpv9ye /0d0PT/xb60T3pIaLTql1aNNAD7g82lNaACKFxbUag4LbWdP7bM4B+p9vXwXzYZ5mKLQ 9oue+R5OXP6s0U4H6+6g8ivbG42s0bAM0Is0utDKBtIS5f90YWFFZx4WKvj1Pl+p+puB CmVeZFyEqfVE6O0Jt2SfdQzPEco7qQGiqTjfyswYazxmxUIBcUP25+TRJPBFRLbsHZu+ wb5W2q8/FPuUJVRj0kJ6ssei8CvJYqo7lZqBcD3dF9Wa7nFvOxI3QW7xZFUePlQFTGN6 z5FA== X-Gm-Message-State: AOJu0YyXdLOZOxJoyZtTWi38iloFjIy6QwI6tiegySjLK9H+Y8LDmyU5 ddbvC37ijNEAlQ0iXpHbi5A43g== X-Google-Smtp-Source: AGHT+IECBCN/waMn4CVxWfjTHzRQM0vxC1enXmqkv/HTlH8YN6+Hz/gOIJlqQsRCWAKJZ3FI/AW8xQ== X-Received: by 2002:a17:902:c408:b0:1c5:f0fd:51b5 with SMTP id k8-20020a170902c40800b001c5f0fd51b5mr36509701plk.40.1697269338131; Sat, 14 Oct 2023 00:42:18 -0700 (PDT) Received: from leoy-huanghe.lan ([98.98.49.106]) by smtp.gmail.com with ESMTPSA id e11-20020a170902b78b00b001c5b8087fe5sm4957319pls.94.2023.10.14.00.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 00:42:17 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , James Clark , Suzuki K Poulose , Mike Leach Cc: 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, Leo Yan Subject: [PATCH v1 RESEND 1/2] perf cs-etm: Validate timestamp tracing in per-thread mode Date: Sat, 14 Oct 2023 15:41:58 +0800 Message-Id: <20231014074159.1667880-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231014074159.1667880-1-leo.yan@linaro.org> References: <20231014074159.1667880-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231014_004221_113100_9FCC21C0 X-CRM114-Status: GOOD ( 17.62 ) 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 So far, it's impossible to validate timestamp trace in Arm CoreSight when the perf is in the per-thread mode. E.g. for the command: perf record -e cs_etm/timestamp/ --per-thread -- ls The command enables config 'timestamp' for 'cs_etm' event in the per-thread mode. In this case, the function cs_etm_validate_config() directly bails out and skips validation. Given profiled process can be scheduled on any CPUs in the per-thread mode, this patch validates timestamp tracing for all CPUs when detect the CPU map is empty. Signed-off-by: Leo Yan Reviewed-by: James Clark Acked-by: Suzuki K Poulose --- tools/perf/arch/arm/util/cs-etm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index b8d6a953fd74..cf9ef9ba800b 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -205,8 +205,17 @@ static int cs_etm_validate_config(struct auxtrace_record *itr, for (i = 0; i < cpu__max_cpu().cpu; i++) { struct perf_cpu cpu = { .cpu = i, }; - if (!perf_cpu_map__has(event_cpus, cpu) || - !perf_cpu_map__has(online_cpus, cpu)) + /* + * In per-cpu case, do the validation for CPUs to work with. + * In per-thread case, the CPU map is empty. Since the traced + * program can run on any CPUs in this case, thus don't skip + * validation. + */ + if (!perf_cpu_map__empty(event_cpus) && + !perf_cpu_map__has(event_cpus, cpu)) + continue; + + if (!perf_cpu_map__has(online_cpus, cpu)) continue; err = cs_etm_validate_context_id(itr, evsel, i); From patchwork Sat Oct 14 07:41:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13421934 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 E268ECDB465 for ; Sat, 14 Oct 2023 07:42:54 +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:References:In-Reply-To: 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: List-Owner; bh=N0G1gH2r8/ctNTTJxOpaZWNG09QBfKZfIuddIz4v18M=; b=m2mg5aDQE9Xu2W 91TNLOBw63FHj/3Nlg2vy2Rjt4w2rCZB3xnP+uCT6VfMovQ9dEBfrNxOBOVAgJ5bZa5YoPk7rJXZ4 u5rZIRIT+vGFMeZ4HE+ub6qfe5SAxfN3EIVu+FdO2JZ1+dioQDKYerrd2HpnJSjgFT40/7ggOb+E3 MnQW1zDIbxjRxi/O0D6oFmKPqhBYEilkwsMCqgx3d6TDWypueVrBI2kUggSRIIMYTXqDJI/N/JpAN dGsC8ZTvUOWIMLD5KXo0xu1NVKnIJ2TveVRY2bfSkCgFK8+o5hiFnjCIIyHmy+a1QUYoaG5aRDQ7B w8JRtEIYTLGoroeoRrMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qrZI5-004vLU-0k; Sat, 14 Oct 2023 07:42:29 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qrZI1-004vJh-21 for linux-arm-kernel@lists.infradead.org; Sat, 14 Oct 2023 07:42:26 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c434c33ec0so20736515ad.3 for ; Sat, 14 Oct 2023 00:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697269343; x=1697874143; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MWOAPqRfJlFeGZpcN7zM2S+ByCB4SMNDEstgKNTnaCs=; b=MOb+dhUvdCXYpcuJ540tEa8rLQJmU3rjeXnBdLE0jo3bP7y2ZBuHseNHWDuXY95R2X YZhT2halMbxWrGYjV9pMFHvBxpDjCbxuSKRCDK6kr6mSmXVVwzCiYx44O4Ksa44A27dJ rilgnBp0HpPz2SL3kHhn/JxXWUZEIS8u0iE1zwQegoHsP7r0iAc4WYFZenckHXXirF9V bNH1VtQC4eCKY8DObXxZB4V7uZutmdSBrB/74VOi5Qc+RV9p2nYxAWfHs9fhrfIC4B4u LwFGSrorlWENYsaB2O7qdB60aF7KV091Fpjgkp+JoPflQFdhZm7qkDDR1/il5XshdItg abUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697269343; x=1697874143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MWOAPqRfJlFeGZpcN7zM2S+ByCB4SMNDEstgKNTnaCs=; b=LawunRWz6Nm3QTAggFwymdhXKsGkh++DtCfh65Ag/eG9kB3tnF74tlwOv0C5h4wKdo lJLqCq/etFHVtKvck9m+cXw/eQjp69Lryu/RDujmMvGy8WoO+ksjuWOELLFP5kFEcAFj eDYFMcV/BahvkdHrQEJrljFLrmNPDv+2+ODWFIF5CAuvLc8NxIB3I5lZ+OUWLKKzzeMi N42iL6So7OULehvxAQjkrAhoN4AdpeWDbbEcvfGTidv2i+vp/N9klLnqMvyo/Fqa+tQS gDp8l3qQj8H9pY+qB4169wa/8SlubI6twqwVApZ8Eg7xJ99YL14ZA0hWXrUoSt6xouaT stsA== X-Gm-Message-State: AOJu0Yw+lH6jAqAFK0+Q4dL8zkzS+baUsSL0NPMXgT9wDw/05NgyiuAK Qr37piVr2Iw0C9u+giOfS3/9UA== X-Google-Smtp-Source: AGHT+IE4fFHIwPowtX28NpMjG4rwpVawnPYgQzzkATlSIS071tzOVwmxcTYq9ltdsTO+Ac9Hv4/pXg== X-Received: by 2002:a17:902:e80e:b0:1c6:2b9d:56ce with SMTP id u14-20020a170902e80e00b001c62b9d56cemr28094278plg.21.1697269342540; Sat, 14 Oct 2023 00:42:22 -0700 (PDT) Received: from leoy-huanghe.lan ([98.98.49.106]) by smtp.gmail.com with ESMTPSA id e11-20020a170902b78b00b001c5b8087fe5sm4957319pls.94.2023.10.14.00.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 00:42:22 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , James Clark , Suzuki K Poulose , Mike Leach Cc: 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, Leo Yan Subject: [PATCH v1 RESEND 2/2] perf cs-etm: Respect timestamp option Date: Sat, 14 Oct 2023 15:41:59 +0800 Message-Id: <20231014074159.1667880-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231014074159.1667880-1-leo.yan@linaro.org> References: <20231014074159.1667880-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231014_004225_676159_B1E5C39B X-CRM114-Status: GOOD ( 14.17 ) 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 When users pass the option '--timestamp' or '-T' in the record command, all events will set the PERF_SAMPLE_TIME bit in the attribution. In this case, the AUX event will record the kernel timestamp, but it doesn't mean Arm CoreSight enables timestamp packets in its hardware tracing. If the option '--timestamp' or '-T' is set, this patch always enables Arm CoreSight timestamp, as a result, the bit 28 in event's config is to be set. Before: # perf record -e cs_etm// --per-thread --timestamp -- ls # perf script --header-only ... # event : name = cs_etm//, , id = { 69 }, type = 12, size = 136, config = 0, { sample_period, sample_freq } = 1, sample_type = IP|TID|TIME|CPU|IDENTIFIER, read_format = ID|LOST, disabled = 1, enable_on_exec = 1, sample_id_all = 1, exclude_guest = 1 ... After: # perf record -e cs_etm// --per-thread --timestamp -- ls # perf script --header-only ... # event : name = cs_etm//, , id = { 49 }, type = 12, size = 136, config = 0x10000000, { sample_period, sample_freq } = 1, sample_type = IP|TID|TIME|CPU|IDENTIFIER, read_format = ID|LOST, disabled = 1, enable_on_exec = 1, sample_id_all = 1, exclude_guest = 1 ... Signed-off-by: Leo Yan Reviewed-by: James Clark Acked-by: Suzuki K Poulose --- tools/perf/arch/arm/util/cs-etm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index cf9ef9ba800b..58c506e9788d 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -442,6 +442,15 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, "contextid", 1); } + /* + * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME + * bit is set for all events. In this case, always enable Arm CoreSight + * timestamp tracing. + */ + if (opts->sample_time_set) + evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, + "timestamp", 1); + /* Add dummy event to keep tracking */ err = parse_event(evlist, "dummy:u"); if (err)