From patchwork Fri Aug 9 12:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13758736 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 EEB19C3DA4A for ; Fri, 9 Aug 2024 12:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=m7/ikKb1ghKAkKc7Nt8FkVUDduA3/WXJQAnKSv3NnOM=; b=Bjl/UBvDmrV9n8TII2dnmC0a1g 2U2cP/j41QTY4L+3fft8gZ4KHZqfpgRWJYqQk9IYUqVO2QJ+QvWFpjVcGngIz5yaAxORwFwakmgGk stw4X6GCtJuQ6XleNVPxM8l3hH/XRidV7+IyGe0yn95bY+IyWNd2GXDUF4B5SnMtTAPFWrpABk/nb /bodSKlLQxMnE2szR08cExgE9EDfSHcRK/jTVwSRA+Tnt9fBflSvDmcuo4npHXBU3WcPjfbojwib6 cer7256Yml2K7m+2k3W4nxrxa41SQ4uWx3wkOxeCtYjEyr1m7kBnBmIQ97C4zS0VvmUc65DtGMny6 fmryNuCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1scOaC-0000000BAh8-2vah; Fri, 09 Aug 2024 12:19:00 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1scOWS-0000000BA8n-3nba for linux-arm-kernel@lists.infradead.org; Fri, 09 Aug 2024 12:16:14 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7435A1692; Fri, 9 Aug 2024 05:15:33 -0700 (PDT) Received: from e132581.cambridge.arm.com (e132581.arm.com [10.2.76.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D44953F6A8; Fri, 9 Aug 2024 05:15:05 -0700 (PDT) From: Leo Yan To: Peter Zijlstra , Arnaldo Carvalho de Melo , Ingo Molnar , Namhyung Kim , Ian Rogers , Adrian Hunter , "Liang, Kan" , Suzuki K Poulose , Mike Leach , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v4 5/8] perf auxtrace: Refactor evlist__enable_event_idx() Date: Fri, 9 Aug 2024 13:14:44 +0100 Message-Id: <20240809121447.2078084-6-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809121447.2078084-1-leo.yan@arm.com> References: <20240809121447.2078084-1-leo.yan@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240809_051509_307809_5D454822 X-CRM114-Status: GOOD ( 13.27 ) 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 This commit splits the evlist__enable_event_idx() function into two steps. The first step uses a new function evlist__find_cpu_map_idx() to find the CPU map index, based on the found CPU map index or a thread map index, it continues to call evlist__enable_event_idx() for enabling the corresponding event. Signed-off-by: Leo Yan --- tools/perf/util/auxtrace.c | 42 +++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index b51b98a80acf..c970024f16db 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -651,20 +651,30 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr, return -EINVAL; } -static int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx) +static int evlist__find_cpu_map_idx(struct evlist *evlist, struct evsel *evsel, + int idx) { bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); + struct perf_cpu evlist_cpu; + int cpu_map_idx; - if (per_cpu_mmaps) { - struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); - int cpu_map_idx = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); + if (!per_cpu_mmaps) + return -EINVAL; - if (cpu_map_idx == -1) - return -EINVAL; - return perf_evsel__enable_cpu(&evsel->core, cpu_map_idx); - } + evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); + cpu_map_idx = perf_cpu_map__idx(evsel->core.cpus, evlist_cpu); + if (cpu_map_idx == -1) + return -ENOENT; + + return cpu_map_idx; +} - return perf_evsel__enable_thread(&evsel->core, idx); +static int evlist__enable_event_idx(struct evsel *evsel, int cpu_mode, int idx) +{ + if (cpu_mode) + return perf_evsel__enable_cpu(&evsel->core, idx); + else + return perf_evsel__enable_thread(&evsel->core, idx); } int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) @@ -676,9 +686,21 @@ int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx) evlist__for_each_entry(itr->evlist, evsel) { if (evsel__is_aux_event(evsel)) { + int cpu_map_idx; + if (evsel->disabled) return 0; - return evlist__enable_event_idx(itr->evlist, evsel, idx); + + cpu_map_idx = evlist__find_cpu_map_idx(itr->evlist, + evsel, idx); + /* No map is found in per CPU mmap */ + if (cpu_map_idx == -ENOENT) + return cpu_map_idx; + + if (cpu_map_idx >= 0) + return evlist__enable_event_idx(evsel, 1, cpu_map_idx); + else + return evlist__enable_event_idx(evsel, 0, idx); } } return -EINVAL;