From patchwork Sun Aug 27 13:35:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13367276 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 CC834C83F11 for ; Sun, 27 Aug 2023 13:37:45 +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=Hkytyrm+kfpDhvzPkSYVTuyZeD3A40+kPlRf8RqCSeA=; b=Gf4fFOlT969Zso ZKgKbp71se5fk91yqtPksb4dTgoFndLIUzf1qjuWi0OYJcJYajqsgx+AzILwX45hc+ecBvYcgfJkP G0irsupzuiQtyMFXgVlAeyRSeeh90EjiWDnaxGub83DHkRUglJCciNkTIb0du8ySrssK6MGr+ZEVa QQtpDqDh2QZpDDxJkpwIXsZLuyDwKQQlzZQ8/7j7b79vEQE833HGcC1q2MkYP8ynu+CELf3EfIrBD A+k+dIVrqKTt8LJ9NV7GmD67HnOr0QTOSBuuOTynFEhnecymfAT4UgA9bF92H0t3OhQ5GVFoyzZev XXqiKbxjUsVv/6TtNEOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qaFxC-0086yL-0D; Sun, 27 Aug 2023 13:37:22 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qaFx4-0086uY-0X for linux-arm-kernel@lists.infradead.org; Sun, 27 Aug 2023 13:37:15 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6bca3311b4fso1805676a34.0 for ; Sun, 27 Aug 2023 06:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693143432; x=1693748232; 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=bLA0Ib5AzCk7ti/k6S86lw9GLjw/BcXDEQAlpgT5UMY=; b=A+OldztKXlooKdJuP3WB5Db5uysvd3ok8mrq9WgoyZG04+06r5yYXDJ66wkM95vZ9L GPHj54kMT7uNFrI3fpv5NpmuuzBd0XFAh+RYEsKz6NuyQ6oX8yDk1vnqNXrPHwRvfzZn YoCDfCAPqi6JnOKrIChPl3o8MRdGOkuquANX0KbvbIr7y1CQGr6JSiqJ3wnW6/YL8UwR +iN5aULN4vnIWw+f6OeIRNYf6T5pkx8HmcwJzhLvzqrKCp3QVXMxfQu/vpkU15np1PDj IrD9EQKShBRCs4xZ1CchqX5Ai+cboDIc83x9COaA1XbZ50BiJhAuBuo7+ksVr5NOg9PE UNlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693143432; x=1693748232; 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=bLA0Ib5AzCk7ti/k6S86lw9GLjw/BcXDEQAlpgT5UMY=; b=GWu0KnXkOi6v6X6Oq3AFROggQIg7AP+nUflfSvG7nGbuhYxMmktUVIkTyVccNDvgbH es2W/wlNt9IaSWOQtX5pVzwIOn85/OaqwBwUoHdb5lkF7e+DblaffL2rB8aSOSFyzHrG crvBb6Zd/WcofjyTw2utXSGz2fORwpYwagvfU+ADKiODDl+blKB8e30H/b1ng/OpyKwl xLxW0gfNQuJ51Pp4qruGsuE3BYcHoBOuEopVuu932cjfaAkoM8Lb5xFV1gGnpEkQrktr mreC1Gcd9ANXa+WhvnymYty6Xs40STvEhSZVW3aKNO3oBOyQEnsv6uHngAMRgvvnd+gS 6hJg== X-Gm-Message-State: AOJu0Yz9wgtDXF9AXwrnvSrs+kw3/S+ruvNaVfaInyg4Yb/wJ7tprU14 UTQPzO4EzRRGikGpwvDuJl+TBA== X-Google-Smtp-Source: AGHT+IHjn1XtKkD4mijnJVL6NgY8vzvVOpyDcVYvx81nneRxIK9gZ/MHZYfAlpmyu+5ADKt0rIuPZQ== X-Received: by 2002:a9d:784f:0:b0:6b9:c869:862c with SMTP id c15-20020a9d784f000000b006b9c869862cmr9871370otm.1.1693143432271; Sun, 27 Aug 2023 06:37:12 -0700 (PDT) Received: from leoy-huanghe.lan (211-75-219-204.hinet-ip.hinet.net. [211.75.219.204]) by smtp.gmail.com with ESMTPSA id e29-20020a63371d000000b00565eb4fa8d1sm5273627pga.16.2023.08.27.06.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 06:37:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , James Clark , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , 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 v1 1/2] perf cs-etm: Validate timestamp tracing in per-thread mode Date: Sun, 27 Aug 2023 21:35:56 +0800 Message-Id: <20230827133557.112494-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230827133557.112494-1-leo.yan@linaro.org> References: <20230827133557.112494-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-20230827_063714_210834_3B86D4AF X-CRM114-Status: GOOD ( 17.83 ) 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 --- 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 Sun Aug 27 13:35:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13367277 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 734C9C83F11 for ; Sun, 27 Aug 2023 13:37:51 +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=CXhemQg3thaeBdOI80yP/r2eh3g7AHahEOSNfFq5S0g=; b=Xu7zcxK2LAeGXH 599JyEQWKDoDRPSjrbnG1SdDxK2JKt4Ewjo7zPWcvxnHQf1X3D3NQcKQzZX7W4siZ7EB94idoMLtd znKLL639VRa7NDjUH3+ViVas/eFfWk9eA9+FKVS8S2Q7wVAi8DMYzyCQ2TX8kexnD/Xm0kc0L3YCj rJZ1ewW355MXj3h4xqDwTs8DkgfzLiRZ71cMsG8gadPYsBeSKZMzxigONXGF5iH+m8rXCpHIo2lcN pNDz78wXCryyslZce+aayqXfz4Hdso1GVZ14UsSBTRjKQ/VUEnZulpF7doGUBihxmyTrrUOIrxpMn B0/EsMhc+vnRL7ANcJHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qaFxC-0086yd-1o; Sun, 27 Aug 2023 13:37:22 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qaFx9-0086vo-2c for linux-arm-kernel@lists.infradead.org; Sun, 27 Aug 2023 13:37:21 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68a3b66f350so2100356b3a.3 for ; Sun, 27 Aug 2023 06:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693143437; x=1693748237; 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=7oz+CZy9YZvIlZYBV1Djf2HNAYZ0qDenfedTgUYUSqU=; b=qKRwvWOY1eyvGUyQ4yR43oXGTcXp51nzbgsPPA3iMBiiNIbINN0whfRO1HWt1N+ST2 CXUB/FYM1uzJMhtRx35JS2MMHN3LLHNzflosP9qzDPpyURf6SjS5cz94G/SCQL2C2JF5 s5DteAYHqf+XtZuDKfn/Kunn0ZI4wCmhzyR3O1r6PQd/YBtFWq8a3XLTyJ2RkSjkxrtW Qh5Uhk9whr6E0cI0QJZL1QQ5/AvzjPuB8zV7a7Rv/mmqOO57A8RNpIjx6ZzEFYlq1+sF n3CrKAYNQ5gGQ1v3jIRqQmUhO2Ii4dmrRp6YwJgFwcVXvfQTgQA6f+8AgMRiVRWbbdwn /iPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693143437; x=1693748237; 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=7oz+CZy9YZvIlZYBV1Djf2HNAYZ0qDenfedTgUYUSqU=; b=PLwSdjus9NgunPuvQwccVM624eYKa6pC7lw4I7/b/gLPCDPN01B6tZrC+yU9E6+Pee PV82VMEOuxLuRC+875Y/OvmbuFHX0Shmb0aHREiiXPc1L7TZqz+EcWNOhkXHxnoqO3/g CG0wt6Y7FkPmbcod5OBBhx7Ai38w4vI34/hmBh6vDM00fnkyHalXKJDN3lrJI3ADTtNE uFFuOqGPnJpaXryPVT9UztIn7meHYk/wE5c7QZVJt4tCzARD7kizvn+ZZ+VSO2q7hwDu c5esdKgyZ3EFlGjD/TLVbPAIkNL06ep0jLjcSDCXBQ1jUmfSK6B4A8qPxGhnDIUAR4Y8 LcGQ== X-Gm-Message-State: AOJu0Yx14tOQZ5/X4OUEuQGDknf7Q3zFPlc6VMA/7zB8b2AhyC2UEkHy T1BJ17zGy1Jgo4RcCCZ70LRYtg== X-Google-Smtp-Source: AGHT+IFM1OLxJh7p3BbZWTvqmLncDv+R+8Ia/nGwyLEZihC31U0cm8ZufuP+x1zTdn2BYzeKF1n0OA== X-Received: by 2002:a05:6a21:7985:b0:14c:ca56:69f7 with SMTP id bh5-20020a056a21798500b0014cca5669f7mr4796294pzc.28.1693143437236; Sun, 27 Aug 2023 06:37:17 -0700 (PDT) Received: from leoy-huanghe.lan (211-75-219-204.hinet-ip.hinet.net. [211.75.219.204]) by smtp.gmail.com with ESMTPSA id e29-20020a63371d000000b00565eb4fa8d1sm5273627pga.16.2023.08.27.06.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 06:37:16 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , James Clark , Suzuki K Poulose , Mike Leach , John Garry , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , 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 v1 2/2] perf cs-etm: Respect timestamp option Date: Sun, 27 Aug 2023 21:35:57 +0800 Message-Id: <20230827133557.112494-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230827133557.112494-1-leo.yan@linaro.org> References: <20230827133557.112494-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-20230827_063719_849727_977B5992 X-CRM114-Status: GOOD ( 14.39 ) 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 --- 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)