Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4969291rdb; Tue, 12 Dec 2023 15:04:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFRS17UdOoM9/5hKp5BTxWuM5tUQJB/b05Nn/q9JwSk4//SvZoPAGBL6rpLCzhL68RL5jq X-Received: by 2002:a17:902:d54c:b0:1d3:3952:8885 with SMTP id z12-20020a170902d54c00b001d339528885mr2078234plf.11.1702422269111; Tue, 12 Dec 2023 15:04:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702422269; cv=none; d=google.com; s=arc-20160816; b=psptw3l4uVVjFByNnHeFlqCbhX2vOUf6ZiUav5WLXbue1159WCRD0ZoVoiZB3SGyC3 VTPKapEeCMBX59mFisZcctQzw0dk9BTUSGNXcfQWKT8UkGVGP5BbmvBnmRnKPiN+H1gD GknrWcTJUpnv2OH+c+t3TEhWeEU0n9JnqRs7a66eqvYlXMf3ER+qkTGoEJ0ruxcta3Qy Y5tVZBCtNbo+wvtkSIGAfIFOEzDUDLlYcLXtx2y9NYpWpEUoBVjSGzEoPX2QWngBqbdv lhhyHr631jsjjbsPEW1BfBhNgeu3Uv1lRq72WfdTLln4PRYZl3QJ+uWPI36VDqUuaDvE 7fIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rEEHjc33CG/euuo6kEv/QG6vs24kl7IOrA4iEVVyvaw=; fh=fjecWn2tsXHKF5pPtw+gI2dQE/iSXdFsWSc8KUP/zmc=; b=yDRH7HNu9yRZp90fF6TKjfQd/SP+43wXLqZVnWtCO1GY1mylv5Ak9EgYYtKeZ1CgU7 ZA1t0sudmoMKq2DTdD0uVc4ImoiEIN9lmMDory2tN9SZV0vY8dVkkp9qGRPkAMI6x++R zCDcxKhdWSVJ85a53Qy4tD7TQFG5/rTHv/5kX4wqw7kmdYeMw8Z0rGCpAAyqLoLAvOHC geVi8DEP/uy5u2x5nCSxYHlkx0rWHw8yOYRb9VErNd1BP3QkSR/JWvrmefCHJNingxR5 rfKdZD5ePuT3f5iU64ZWBjcUTyeJHeWN75/eg8O4b/If4DXw5pTbcRe67gYiRw1mwR6x l6+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HnWGJ+eL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ng10-20020a17090b1a8a00b00280479459f7si10058501pjb.50.2023.12.12.15.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 15:04:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HnWGJ+eL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 040188042590; Tue, 12 Dec 2023 15:04:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377965AbjLLXEP (ORCPT + 99 others); Tue, 12 Dec 2023 18:04:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377958AbjLLXDo (ORCPT ); Tue, 12 Dec 2023 18:03:44 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3752D101; Tue, 12 Dec 2023 15:03:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702422213; x=1733958213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qnCrj0BETPuHi8W8gnPanU69Q8x6K39Z1fpI00xOF3g=; b=HnWGJ+eLjBl8B9j2kU0+hIeTqpEybKIlMrhta1gLTv427Lb6Pu7EHE9m SZ17o1jlzL9wfrDNrZaGOrgqn172xEtkBKTil13ZBmhvc+5LkViZzRsJ0 FTyPHDVXPI6Godj/MHrvpLu6GY5I7a94M8I9cd4v8ph3plPydLh1N6aT0 iK5Sm+nYZW286d44j1elYcNVeB/cBfHNy0j57zOlEk76Fxir1zqrYCGZj Xq+KCp4iR8+LyDaJIynmHSPaln1ijpAQLdY3Q9Can4F5kb72eVzdmVNdU /z3CLkkySOYHFc8C/FtLAChYELeV/Qnua01xN0OWrTImeBlHLWqvdbLP+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="392055993" X-IronPort-AV: E=Sophos;i="6.04,271,1695711600"; d="scan'208";a="392055993" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 15:02:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="864392020" X-IronPort-AV: E=Sophos;i="6.04,271,1695711600"; d="scan'208";a="864392020" Received: from node-10329.jf.intel.com ([10.54.34.22]) by FMSMGA003.fm.intel.com with ESMTP; 12 Dec 2023 15:02:54 -0800 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland , Yang Jihong Subject: [RFC PATCH v3 11/18] perf stat: Add function to handle special events in hardware-grouping Date: Tue, 12 Dec 2023 15:02:17 -0800 Message-Id: <20231212230224.1473300-13-weilin.wang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231212230224.1473300-1-weilin.wang@intel.com> References: <20231212230224.1473300-1-weilin.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 15:04:28 -0800 (PST) From: Weilin Wang There are some special events like topdown events and TSC that are not decribed in pmu-event JSON files. Add support to handle this type of events. This should be considered as a temporary solution because including these events in JSON files would be a better solution. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 25 +++++++++++++++++++++++-- tools/perf/util/metricgroup.h | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 5d9ed22963be..03383f820e06 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -2023,6 +2023,15 @@ static int create_grouping(struct list_head *pmu_info_list, return ret; }; +static bool is_special_event(const char *id) +{ + for (int i = 0; i < SPECIAL_EVENT_MAX; i++) { + if (!strncmp(id, special_event_names[i], strlen(special_event_names[i]))) + return true; + } + return false; +} + /** * hw_aware_build_grouping - Build event groupings by reading counter * requirement of the events and counter available on the system from @@ -2047,7 +2056,17 @@ static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused, hashmap__for_each_entry(ctx->ids, cur, bkt) { const char *id = cur->pkey; - pr_debug("found event %s\n", id); + if (is_special_event(id)) { + struct metricgroup__event_info *event; + + event = event_info__new(id, "default_core", "0", + /*free_counter=*/true); + if (!event) + goto err_out; + + list_add(&event->nd, &event_info_list); + continue; + } ret = get_metricgroup_events(id, etable, &event_info_list); if (ret) goto err_out; @@ -2519,8 +2538,10 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, ret = hw_aware_parse_groups(perf_evlist, pmu, str, metric_no_threshold, user_requested_cpu_list, system_wide, /*fake_pmu=*/NULL, metric_events, table); - if (!ret) + if (!ret) { + pr_info("Hardware aware grouping completed\n"); return 0; + } } return parse_groups(perf_evlist, pmu, str, metric_no_group, metric_no_merge, diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 51596e4b4341..37fdf8c5ba77 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -79,6 +79,21 @@ struct metric_expr { #define TRANSFER_FIRST_BYTE(pos) (7 - pos) #define TRANSFER_SEC_BYTE(pos) (23 - pos) +/* Special events that are not described in pmu-event JSON files. + * topdown-* and TSC use dedicated registers, set as free + * counter for grouping purpose + */ +enum special_events { + TOPDOWN = 0, + TSC = 1, + SPECIAL_EVENT_MAX, +}; + +static const char *const special_event_names[SPECIAL_EVENT_MAX] = { + "topdown-", + "TSC", +}; + /** * An event used in a metric. This info is for metric grouping. */ -- 2.39.3