From patchwork Tue Aug 20 18:47:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 13770536 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 64E01C3DA4A for ; Tue, 20 Aug 2024 18:51:34 +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=zfGU9gNbzO+7lK9BLPD2yFSmqj+paWh5V5SkAiLRhO8=; b=IZkNvih7BNT1yx0Hr5cFb0OxUt WGUjfczjdbH0bDPHhOy38ifthuuGCubixhJas8ACcNgtT81EPnpOVKhVG2o4AJO30FEwCHaahO91k 7Hqtg16PwdEgE8gFZyscsK0f8eokgfNVrLb0MLZdF8czozsE5nZdSQw+LkCXLyPWJnmFxfPKd1Jc5 7AIyvS6RJ1g3ZPH65sDEJLLTAxxIRCmEri6teDJ+bNB/B3o59BH/KWD2Y3aVPEJiRFoA99MwtI1Oq w8oAB8cVNbW3VSJ9GMlu8x2WezoeghFFqDH5AGTp9uAWsr4KMFJo9CsDXzrK38lI81zlFYNrgDbKX 3fPYd6zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgTww-00000006NFd-1ZoE; Tue, 20 Aug 2024 18:51:22 +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 1sgTtf-00000006MBJ-1YTy for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2024 18:48:00 +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 B6C09FEC; Tue, 20 Aug 2024 11:48:24 -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 DA1EB3F58B; Tue, 20 Aug 2024 11:47:55 -0700 (PDT) From: Leo Yan To: Peter Zijlstra , Adrian Hunter , Arnaldo Carvalho de Melo , Namhyung Kim , Ian Rogers , Jiri Olsa , "Liang, Kan" , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Mark Rutland , Will Deacon , Besar Wicaksono , Jonathan Cameron , 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 v5 4/8] perf auxtrace: Introduce auxtrace_record__validate_events() Date: Tue, 20 Aug 2024 19:47:27 +0100 Message-Id: <20240820184731.2937551-5-leo.yan@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240820184731.2937551-1-leo.yan@arm.com> References: <20240820184731.2937551-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-20240820_114759_535105_C470AB08 X-CRM114-Status: GOOD ( 16.30 ) 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 A prerequisite for multiple AUX events is that the AUX events cannot overlap CPU maps. The reason is that every CPU has only one AUX trace buffer and maps it to an unique buffer index for CPU and system tracing mode. To prevent the case of CPU maps overlapping occurring within multiple AUX events, the auxtrace_record__validate_events() function is introduced. It iterates through all AUX events and returns failure if it detects CPU maps overlapping. Signed-off-by: Leo Yan --- tools/perf/builtin-record.c | 4 +++ tools/perf/util/auxtrace.c | 64 +++++++++++++++++++++++++++++++++++++ tools/perf/util/auxtrace.h | 7 ++++ 3 files changed, 75 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index adbaf80b398c..2c618efba97d 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -862,6 +862,10 @@ static int record__auxtrace_init(struct record *rec) auxtrace_regroup_aux_output(rec->evlist); + err = auxtrace_validate_events(rec->evlist); + if (err) + return err; + return auxtrace_parse_filters(rec->evlist); } diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index ca8682966fae..87e4f21b6edf 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -2828,6 +2828,70 @@ int auxtrace_parse_filters(struct evlist *evlist) return 0; } +int auxtrace_validate_events(struct evlist *evlist) +{ + struct evsel *evsel; + struct perf_cpu_map *cpu_map = NULL; + struct perf_cpu_map *cpu_map_intersect = NULL; + struct perf_cpu_map *cpu_map_merged = NULL; + int ret = 0; + + if (!evlist) + return 0; + + /* + * Currently the tool only supports multiple AUX events without + * overlapping CPU maps and every CPU has its unique AUX buffer + * for CPU or system mode tracing. + * + * Returns failure if detects CPU maps overlapping. + */ + evlist__for_each_entry(evlist, evsel) { + if (!evsel__is_aux_event(evsel)) + continue; + + if (perf_cpu_map__is_empty(evsel->pmu->cpus)) + continue; + + cpu_map_intersect = perf_cpu_map__intersect(cpu_map, evsel->pmu->cpus); + if (cpu_map_intersect) { + perf_cpu_map__put(cpu_map_intersect); + pr_err("Doesn't support AUX events with overlapping CPU masks\n"); + ret = -EINVAL; + break; + } + perf_cpu_map__put(cpu_map_intersect); + + cpu_map_merged = perf_cpu_map__merge(cpu_map, evsel->pmu->cpus); + if (!cpu_map_merged) { + ret = -ENOMEM; + break; + } + + /* Update the CPU maps after merging */ + perf_cpu_map__put(cpu_map); + cpu_map = cpu_map_merged; + } + + if (!ret) + goto out; + + /* If fails, dump CPU maps for debugging */ + evlist__for_each_entry(evlist, evsel) { + char buf[200]; + + if (!evsel__is_aux_event(evsel)) + continue; + + cpu_map__snprint(evsel->pmu->cpus, buf, sizeof(buf)); + pr_debug("AUX event [%s]'s cpu map is: %s\n", evsel->pmu->name, buf); + } + +out: + perf_cpu_map__put(cpu_map); + return ret; +} + int auxtrace__process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, const struct perf_tool *tool) { diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index a1895a4f530b..67a74ad0c383 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -636,6 +636,7 @@ void addr_filters__exit(struct addr_filters *filts); int addr_filters__parse_bare_filter(struct addr_filters *filts, const char *filter); int auxtrace_parse_filters(struct evlist *evlist); +int auxtrace_validate_events(struct evlist *evlist); int auxtrace__process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, const struct perf_tool *tool); @@ -875,6 +876,12 @@ int auxtrace_parse_filters(struct evlist *evlist __maybe_unused) return 0; } +static inline +int auxtrace_validate_events(struct evlist *evlist __maybe_unused) +{ + return 0; +} + int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, struct auxtrace_mmap_params *mp, void *userpg, int fd);